/**
 * Collection page scripts
 * @author: Golan Cohen
 * 16 Oct 09
 */
dojo.addOnLoad(function(){dojo.query('.sendLink').onclick(sendLink);});function sendLink(event){dojo.stopEvent(event);var formHTML='<form id="SendLink"></form>';overlay(formHTML);var form=dojo.byId('SendLink');var itemContainer=dojo.doc.createElement('DIV');itemContainer.id = 'ItemContainer';dojo.place(itemContainer, form);var fix = dojo.doc.createElement('DIV');fix.id = 'Fix';dojo.place(fix, itemContainer);var itemTop = dojo.doc.createElement('DIV');itemTop.id = 'ItemTop';itemTop.className = 'nav';dojo.place(itemTop, fix);var a = dojo.doc.createElement('A');a.href = '#';a.innerHTML = 'Close X';dojo.connect(a, 'click', destroyOverlay);dojo.place(a, itemTop);var title = dojo.doc.createElement('DIV');title.innerHTML = 'Send <span class="title">' + dojo.byId('collection_title_parent').innerHTML + '</span> to a friend<br />';title.className = 'title';dojo.style(title,{paddingTop: '30px',marginLeft: '25px',color: 'black'});
dojo.place(title, fix);var formContainer = dojo.doc.createElement('DIV');formContainer.id = 'FormContainer';dojo.style(formContainer, {paddingTop: '5px',marginLeft: '25px'});dojo.place(formContainer, fix);var div = dojo.doc.createElement('DIV');div.className = 'inputDiv';dojo.place(div, formContainer);var span = dojo.doc.createElement('SPAN');span.className = 'inputLabel';span.innerHTML = 'Recipient Name:';dojo.place(span, div);var input = dojo.doc.createElement('INPUT');input.type = 'text';input.name = 'recipient_name';input.className ='inputField';dojo.place(input, div);div.innerHTML += '<span class="inputRequired">&nbsp;required</span>';var div = dojo.doc.createElement('DIV');div.className = 'inputDiv';dojo.place(div, formContainer);var span = dojo.doc.createElement('SPAN');span.className = 'inputLabel';span.innerHTML = 'Recipient Email:';dojo.place(span, div);var input = dojo.doc.createElement('INPUT');input.type = 'text';
input.name = 'recipient_email';input.className ='inputField';dojo.place(input, div);div.innerHTML += '<span class="inputRequired">&nbsp;required</span>';var div = dojo.doc.createElement('DIV');div.className = 'inputDiv';dojo.place(div, formContainer);var span = dojo.doc.createElement('SPAN');span.className = 'inputLabel';span.innerHTML = 'Your Name:';dojo.place(span, div);var input = dojo.doc.createElement('INPUT');input.type = 'text';input.name = 'sender_name';input.className ='inputField';dojo.place(input, div);div.innerHTML += '<span class="inputRequired">&nbsp;required</span>';var div = dojo.doc.createElement('DIV');div.className = 'inputDiv';dojo.place(div, formContainer);var span = dojo.doc.createElement('SPAN');span.className = 'inputLabel';span.innerHTML = 'Your Email:';dojo.place(span, div);var input = dojo.doc.createElement('INPUT');input.type = 'text';input.name = 'sender_email';input.className ='inputField';dojo.place(input, div);
div.innerHTML += '<span class="inputRequired">&nbsp;required</span>';var div = dojo.doc.createElement('DIV');div.className = 'inputDiv';dojo.place(div, formContainer);var span = dojo.doc.createElement('SPAN');span.className = 'inputLabel';span.innerHTML = 'Your message:';dojo.place(span, div);var textarea = dojo.doc.createElement('TEXTAREA');textarea.name = 'sender_message';textarea.className ='inputTextarea';textarea.innerHTML='Hi.\nI thought you might be interested in seeing this collection on Collect and Show:\n' + dojo.byId('collection_title_parent').innerHTML + ' (' + window.location + ')';dojo.place(textarea, div);var input = dojo.doc.createElement('INPUT');input.type = 'hidden';input.name = 'collection_name';input.value = dojo.byId('collection_title_parent').innerHTML;dojo.place(input, div);var input = dojo.doc.createElement('INPUT');input.type = 'hidden';input.name = 'collection_url';input.value = document.URL;dojo.place(input, div);var div = dojo.doc.createElement('DIV');
dojo.style(div, {width: '100%',textAlign: 'center',paddingTop: '50px'});dojo.place(div, formContainer);var a = dojo.doc.createElement('A');a.href='#';a.innerHTML = '<img src="/images/layout/send.png" />';dojo.connect(a, 'click', processSendForm);dojo.place(a, div);
var topFrame = dojo.doc.createElement('DIV');topFrame.id = 'TopFrame';dojo.place(topFrame, fix);var leftFrame = dojo.doc.createElement('DIV');leftFrame.id = 'LeftFrame';dojo.place(leftFrame, fix);var rightFrame = dojo.doc.createElement('DIV');rightFrame.id = 'RightFrame';dojo.place(rightFrame, fix);var bottomFrame = dojo.doc.createElement('DIV');bottomFrame.id = 'BottomFrame';dojo.place(bottomFrame, fix);}function processSendForm(event) {dojo.stopEvent(event);dojo.xhrPost({url: '/api',form: 'SendLink',content: {action: 'sendLink'},handleAs: 'json',load: function(response) {if (response.status == 1) {dojo.byId('FormContainer').innerHTML = '<br /><span class="title" style="color: black;">Thank you.</span><br /><span style="font-size: 1.2em;">Thanks for spreading the word about CollectAndShow.com.<br />As more people visit the site, more collectors will be able to collect and show.</span>';} else {var popupContent = '';dojo.forEach(response.errors, function(error) {popupContent += error + '\n';});alert(popupContent);}
return response;},error: function(response) {alert(response);}});}function displayRank() {var rankDiv = dojo.byId('RankCollection'); rankDiv.style.display = 'block';	var anim = dojo.anim(rankDiv, {height: 143}, 250); anim.play();	dojo.byId('RankCollectionPopUp').innerHTML = '<a href="#" onclick="slideOut(); return false;" id="SearchButton">Close</a>';} function slideOut() {var rankDiv = dojo.byId('RankCollection'); var anim = dojo.anim(rankDiv, {height: 1}, 500); dojo.connect(anim, "onEnd", function() {rankDiv.style.display = 'none';}); anim.play(); dojo.byId('RankCollectionPopUp').innerHTML = '<a href="#" onclick="displayRank(); return false;">Rank the Collection</a>';} function submitRank(type, menuId) {formId = type + 'RankForm'; dojo.xhrPost({url: "/ranks/add/", rankId: type + 'Ranking', form: formId, load: function(response, ioArgs) {dojo.byId(this.rankId).innerHTML = '<b>Viewer Rank:</b> <img src="/images/layout/' + response + 'ant.gif" alt="rank: ' + response + '" class="middle" />'; dojo.byId(menuId + 'PopUp').innerHTML = ""; var node = dojo.byId(menuId); var anim = dojo.anim(node, {height: 1}, 500); dojo.connect(anim, "onEnd", function() {node.style.display = 'none';}); anim.play(); return response;},	error: function(error) {alert(error);}});} function openItem(href) {dojo.xhrGet({url: href,	load: function (response) {overlay(response); return response;}, error: function(response) {alert(response);}});} function closeItem() {destroyOverlay();} function loadItem(href) {dojo.xhrGet({url: href + '/ajax/1',	handleAs: 'text', load: function (response) {dojo.byId('Fix').innerHTML = response;	return (response);}, error: function (response) {alert(response);}});}
