
function getBrowserWindowSize(){var viewportwidth;var viewportheight;if(typeof window.innerWidth!='undefined'){viewportwidth=window.innerWidth,viewportheight=window.innerHeight}
else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0){viewportwidth=document.documentElement.clientWidth,viewportheight=document.documentElement.clientHeight}
else{viewportwidth=document.getElementsByTagName('body')[0].clientWidth,viewportheight=document.getElementsByTagName('body')[0].clientHeight}
var rval={width:viewportwidth,height:viewportheight};return rval;}
function setElementCenter(elem){var wDim=getBrowserWindowSize();var dDim=Element.getDimensions(elem);var top=(wDim.height-dDim.height)/2;var left=(wDim.width-dDim.width)/2;if(top<10)top=10;if(left<10)left=10;elem.style.top=top+'px';elem.style.left=left+'px';}
function getElementPosition(elem){var posX=null;var posY=null;if(elem.offsetParent){for(posX=0,posY=0;elem.offsetParent;elem=elem.offsetParent){posX+=elem.offsetLeft;posY+=elem.offsetTop;}
return[posX,posY];}else{posX=elem.x;posY=elem.y;return[posX,posY];}}
function strip(str){return str.replace(/^\s+|\s+$/g,'');}
function IsNumeric(val){return(val&&/^\d+$/.test(val))?true:false;}
function reloadImage(obj){src=obj.attr('src');var pos=src.indexOf('?');if(pos>=0){src=src.substr(0,pos);}
var date=new Date();obj.attr('src',src+'?v='+date.getTime());}
function postlink(link){var f=document.createElement("form");f.style.display="none";link.parentNode.appendChild(f);f.method="POST";f.action=link.href;var m=document.createElement("input");m.setAttribute('type','hidden');m.setAttribute('name','_method');m.setAttribute('value','post');f.appendChild(m);f.submit();return false;}
function getFirstParentByTagName(e,tagname){while((e=e.parentNode)&&(e.tagName.toLowerCase()!=tagname));return e;}
function createCustomSelect(varname){var lastdispnode=null;var sels=new Array();var closefunc=function(){if(lastdispnode){Element.removeClassName(lastdispnode,"menushow");lastdispnode=null;}}
var genCustomSelStr=function(selobjindex){var sel=sels[selobjindex];var customselstr="<div class='select-cell'><div class='selectinput'><a href='#' onclick='return "+varname+".open(this, event);' class='selecticon'></a><a href='#' onclick='return "+varname+".open(this, event);' class='selecttext'>"+sel.options[sel.options.selectedIndex].text+"</a></div><div class='pulldown-cell'><div class='pulldown-menu'><ul>";for(var i=0;i<sel.options.length;i++){customselstr+="<li";if(i==sel.options.selectedIndex)
customselstr+=" class='selected'";customselstr+="><a href='#' onclick='return "+varname+".update("+selobjindex+", "+i+", this);'>"+sel.options[i].text+"</a></li>";}
customselstr+="</ul></div></div></div>";return customselstr;}
var execScriptAfterRender=function(selobjindex){var sel=sels[selobjindex];var node=jQuery([sel]).parents(".customselect");node.children(".select-cell").children(".pulldown-cell").children(".pulldown-menu").css("width",parseInt(node.css("width"),10)+"px");node.children(".select-cell").children(".selectinput").children(".selecttext").hover(function(){jQuery(this).siblings(".selecticon").addClass("hover");},function(){jQuery(this).siblings(".selecticon").removeClass("hover");});}
return{init:function(){var allsels=jQuery(".customselect");for(var k=0;k<allsels.length;k++){var selouterset=jQuery([allsels[k]]);var sel=selouterset.children("select");sels[k]=sel[0];if(sels[k]==null)
continue;sel.hide();selouterset.append(genCustomSelStr(k));execScriptAfterRender(k);}
Event.observe(document,'click',function(e){closefunc();});},open:function(node,e){var dispnode=jQuery(getFirstParentByTagName(node,"div")).parents(".select-cell").get([0]);if(lastdispnode){Element.removeClassName(lastdispnode,"menushow");}
if(dispnode!=lastdispnode){Element.addClassName(dispnode,"menushow");lastdispnode=dispnode;}
else{lastdispnode=null;}
if(e)
Event.stop(e);return false;},close:function(){closefunc();},update:function(selobjindex,selindex,node){var li_node=getFirstParentByTagName(node,"li");node=jQuery(node);li_node=jQuery(li_node);if(li_node.hasClass("selected"))
return false;var sel=sels[selobjindex];sel.options.selectedIndex=selindex;var cellnode=node.parents(".pulldown-cell");var updatenode=cellnode.siblings(".selectinput").children("a.selecttext");updatenode.html(sel.options[sel.options.selectedIndex].text);updatenode=li_node.siblings(".selected");updatenode.removeClass("selected");li_node.addClass("selected");jQuery([sel]).trigger("change");return false;},refresh:function(selobj){var cellnode=jQuery([selobj]).siblings(".select-cell");for(var i=0;i<sels.length;i++){if(sels[i]==selobj){cellnode.replaceWith(genCustomSelStr(i));execScriptAfterRender(i);return;}}}}}
function input_with_hint(inputField,hintText){inputField.focus(function(){if(hintText==inputField.val()){inputField.val("");inputField.addClass("hint");}});inputField.blur(function(){if(inputField.val()==""){inputField.val(hintText);inputField.addClass("hint");}
else if(inputField.val()==hintText){if(!inputField.hasClass("hint"))
inputField.addClass("hint");}});inputField.blur();}
function showmenu(openbtn,update_disp_elem,update_value_elem,update_callback,autoclose){var menushow=false;var togglefunc=function(){if(!menushow){$(update_disp_elem).addClassName("menushow");menushow=true;}
else if(autoclose){$(update_disp_elem).removeClassName("menushow");menushow=false;}}
Event.observe($(openbtn),'click',togglefunc);return{isshown:function(){return menushow;},open:function(){if(!menushow){togglefunc();}},closemenu:function(value,value_id){if(menushow){if(value!=null&&$(update_value_elem)){if($(update_value_elem).type=="text")
$(update_value_elem).value=value;else
$(update_value_elem).innerHTML=value;}
if(value_id!=null&&update_callback){update_callback(value,value_id);}
$(update_disp_elem).removeClassName("menushow");menushow=false;}}}}
function togglemenu_group(classname,close_on_blur){var nodes=$$('.'+classname);var active_node=null;if(nodes.length>0){for(var i=0;i<nodes.length;i++){var node=nodes[i];var elink=node.getElementsByTagName("a")[0];Event.observe(node,'click',function(e){if(active_node==getFirstParentByTagName(Event.element(e),"div")){Event.stop(e);}});Event.observe(elink,'click',function(e){Event.stop(e);if(active_node)
Element.removeClassName(active_node,"menushow");var dispnode=getFirstParentByTagName(Event.element(e),"div");Element.addClassName(dispnode,"menushow");active_node=dispnode;});}
if(close_on_blur){Event.observe(document,'click',function(e){if(active_node){Element.removeClassName(active_node,"menushow");active_node=null;}});}}}
function toggledisplay(elem,link,show_name,hide_name,callback){if(link.html()==show_name){elem.show();link.html(hide_name);if(callback)
callback(false);}
else{elem.hide();link.html(show_name);if(callback)
callback(true);}
return false;}
function toggledisplay_obj(elem,link,show_name,hide_name,callback){return{onclick:function(){toggledisplay(elem,link,show_name,hide_name,callback)}};}
function swapdisplay(elem1,elem2){return{onclick:function(elem){if(elem==elem1){jQuery("#"+elem1).hide();jQuery("#"+elem2).show();}
else{jQuery("#"+elem1).show();jQuery("#"+elem2).hide();}
return false;}};}
function popupbox(varname,dynbox,width,center,relpos_id){var title=null;var content=null;var elem=null;var opened=false;return{open:function(idstr){var top=10;var left=10;if(relpos_id){pos=getElementPosition(document.getElementById(relpos_id));left=pos[0]+'px';top=(pos[1]+15)+'px';}
else if(center){var coords=document.viewport.getScrollOffsets();var wDim=getBrowserWindowSize();left=(wDim.width-width)/2;left=(((left<10)?10:left)+coords[0])+'px';top=(coords[1]+150)+'px';}
if(opened==false){if(dynbox){elem=document.createElement('div');Element.addClassName(elem,'popupBox');elem.setAttribute('id',idstr);elem.innerHTML=""
if(title)
elem.innerHTML+="<div class='popup-handle clearfix'><h2>"+title+"</h2><a href='javascript:"+varname+".close();' class='close close_black'>[X]</a></div>";elem.innerHTML+=content;}
else{elem=$(idstr);}
elem.style.top=top;elem.style.left=left;elem.style.width=width+'px';if(dynbox){document.body.appendChild(elem);}
else{elem.style.display="block";}
opened=true;if(title)
new Draggable(idstr,{handle:'popup-handle',starteffect:null,endeffect:null,snap:function(x,y){return[(x<0?0:x),(y<0?0:y)];}});}
else{elem.style.top=top;elem.style.left=left;}},close:function(){if(opened==true){if(dynbox)
document.body.removeChild(elem);else
elem.style.display="none";opened=false;}},setTitleContent:function(in_title,in_content){title=in_title
content=in_content;}}}
function modalwindow_show(){if($("modalBackground")&&$("modalWindow")){setElementCenter($("modalWindow"));reloadImage(jQuery("#modalWindow .captcha img"));$("modalBackground").style.display='block';$("modalWindow").style.display='block';return false;}
else{return true;}}
function modalwindow_hide(){$("modalWindow").style.display='none';$("modalBackground").style.display='none';if(Prototype.Browser.Gecko){document.getElementsByTagName("body")[0].style.overflow="auto";}}
function locationupdate(objprefix,initid){var location_id=initid;return{update:function(update_value,update_id){if(location_id!=update_id){if(location_id!=null){$(objprefix+"_"+location_id).style.display="block";}
$(objprefix+"_"+update_id).style.display="none";location_id=update_id;}}};}
function location_clearerror(addressid){$(addressid).className="";$(addressid).onfocus=null;$(addressid+"Err").remove();}
function star_rating(rating_id,rating_cur_id,rating_hint_id,rating_val_id,hints,num_stars){return{showstars:function(val){$(rating_hint_id).innerHTML=hints[val];},clearstars:function(){$(rating_hint_id).innerHTML=($(rating_val_id).value>0)?hints[$(rating_val_id).value]:hints[0];},setstars:function(val){$(rating_cur_id).style.width=val*100/num_stars+"%";$(rating_val_id).value=val;},reset:function(){$(rating_cur_id).style.width="0%";$(rating_val_id).value=0;$(rating_hint_id).innerHTML=hints[0];}}}
function checkboxes_listen(uncheck_all_btn,btns){for(var i=0;i<btns.length&&btns[i]!=0;i++){Event.observe($(btns[i]),'click',function(e){if(Event.element(e).checked)
$(uncheck_all_btn).checked=false;});}
Event.observe($(uncheck_all_btn),'click',function(e){if(Event.element(e).checked){for(var i=0;i<btns.length;i++){$(btns[i]).checked=false;}}});}
function checkboxes_listen_area(uncheck_all_btn,area_id){var objCheckBoxes=document.getElementById(area_id).getElementsByTagName('input');var btns=new Array();for(var i=0;i<objCheckBoxes.length;i++){btns[i]=objCheckBoxes[i].id;}
checkboxes_listen(uncheck_all_btn,btns);}
function selector_template(text_id,refresh){this.textarr=new Array();this.scriptarr=new Array();this.selectedIndex=-1;this.add=function(text,index,selected){this.textarr[index]=text;if(selected)
this.update(index);return index;};this.addjs=function(js,index){if(!this.scriptarr[index])
this.scriptarr[index]="";this.scriptarr[index]+=js;return index;}
this.update=function(select_index){if(this.selectedIndex!=select_index){if(this.selectedIndex>=0&&refresh){this.textarr[this.selectedIndex]=$(text_id).innerHTML;}
this.selectedIndex=select_index;$(text_id).innerHTML=this.textarr[select_index];if(select_index<this.scriptarr.length&&this.scriptarr[select_index])
eval(this.scriptarr[select_index]);}};}
function messagesendform_success(request){jQuery('#msgholder').html('<div class=\'inform_msg inform_successmsg\'><p>'+request.responseText+'</p></div>');}
function messagesendform_failure(request){errors=jQuery.parseJSON(request.responseText);if(errors.base){jQuery('#message_general_err').html('<p>'+errors.base+'</p>');jQuery('#message_general_err').show();}
if(errors.from_name){jQuery("#message_from_name").removeClass("datainput").addClass("errorinput");jQuery("#message_name_err").html(errors.from_name);jQuery("#message_name_err").show();}
if(errors.from_email){jQuery("#message_from_email").removeClass("datainput").addClass("errorinput");jQuery("#message_email_err").html(errors.from_email);jQuery("#message_email_err").show();}
if(errors.subject){jQuery("#message_subject").removeClass("datainput").addClass("errorinput");jQuery("#message_subject_err").html(errors.subject);jQuery("#message_subject_err").show();}
if(errors.body){jQuery("#message_body").removeClass("datainput").addClass("errorinput");jQuery("#message_body_err").html(errors.body);jQuery("#message_body_err").show();}
if(errors.captcha){jQuery("#messageSendForm #captcha").removeClass("datainput").addClass("errorinput");jQuery("#messageSendForm .captchaerr").html(errors.captcha);jQuery("#messageSendForm .captchaerr").show();jQuery("#messageSendForm .captchahint").hide();reloadImage(jQuery("#messageSendForm .captcha img"));}
jQuery('#messageSendForm :input').removeAttr("disabled");jQuery("#messageSendForm .actionbtns").show();jQuery("#messageSendForm .waitSubmit").hide();}
function messagesendform_start(){jQuery('#messageSendForm :input').attr("disabled","disabled");jQuery("#messageSendForm .actionbtns").hide();jQuery("#messageSendForm .waitSubmit").show();}
function validate_messagesendform(theForm){var validform=true;if(theForm.message_from_name){if(!theForm.message_from_name.value){theForm.message_from_name.className="errorinput";jQuery("#message_name_err").html("Please enter your name");jQuery("#message_name_err").show();validform=false;}
else{theForm.message_from_name.className="datainput";jQuery("#message_name_err").hide();}}
if(theForm.message_from_email){if(!theForm.message_from_email.value){theForm.message_from_email.className="errorinput";jQuery("#message_email_err").html("Please enter your email");jQuery("#message_email_err").show();validform=false;}
else{theForm.message_from_email.className="datainput";jQuery("#message_email_err").hide();}}
if(theForm.message_subject){if(!theForm.message_subject.value){theForm.message_subject.className="errorinput";jQuery("#message_subject_err").html("Please enter your subject");jQuery("#message_subject_err").show();validform=false;}
else{theForm.message_subject.className="datainput";jQuery("#message_subject_err").hide();}}
if(theForm.message_body){if(!theForm.message_body.value){theForm.message_body.className="errorinput";jQuery("#message_body_err").html("Please enter your message");jQuery("#message_body_err").show();validform=false;}
else{theForm.message_body.className="datainput";jQuery("#message_body_err").hide();}}
if(theForm.captcha){if(!theForm.captcha.value){theForm.captcha.className="errorinput";jQuery("#messageSendForm .captchaerr").html("Please enter the code shown above");jQuery("#messageSendForm .captchaerr").show();jQuery("#messageSendForm .captchahint").hide();validform=false;}
else{theForm.captcha.className="datainput";jQuery("#messageSendForm .captchahint").show();jQuery("#messageSendForm .captchaerr").hide();}}
return validform;}
function validate_loginform(theForm){var validform=true;if(!theForm.email.value){theForm.email.className="errorinput";$("login_emailerr").innerHTML="Please enter your email address";$("login_emailerr").style.display="block";validform=false;}
else{theForm.email.className="datainput";$("login_emailerr").style.display="none";}
if(!theForm.password.value){theForm.password.className="errorinput";$("login_passworderr").innerHTML="Please enter your password";$("login_passworderr").style.display="block";validform=false;}
else{theForm.password.className="datainput";$("login_passworderr").style.display="none";}
if(validform){theForm.hashed_pwd.value=hex_sha256(theForm.password.value);theForm.password.value="";$('loginSubmit').style.display="none";$('loginSubmitWait').style.display="block";}
return validform;}
function validate_signupform(theForm){var validform=true;if(!theForm.user_firstname.value||!theForm.user_lastname.value){if(!theForm.user_firstname.value)
theForm.user_firstname.className="errorinput";if(!theForm.user_lastname.value)
theForm.user_lastname.className="errorinput";$("nameerr").innerHTML="Please enter your full name";$("nameerr").style.display="block";$("namehint").style.display="none";validform=false;}
else{theForm.user_firstname.className="datainput";theForm.user_lastname.className="datainput";$("nameerr").style.display="none";$("namehint").style.display="block";}
if(!theForm.user_email.value||(theForm.user_email.value.indexOf('@')==-1)){if(!theForm.user_email.value)
$("emailerr").innerHTML="Please enter your email address";else
$("emailerr").innerHTML="Email entered does not appear to be valid";theForm.user_email.className="errorinput";$("emailerr").style.display="block";$("emailhint").style.display="none";validform=false;}
else{theForm.user_email.className="datainput";$("emailerr").style.display="none";$("emailhint").style.display="block";}
if(!theForm.user_password.value||(theForm.user_password.value.match(/.{6,}/)==null)){if(!theForm.user_password.value)
$("passworderr").innerHTML="Please enter your password";else
$("passworderr").innerHTML="Password is too short";theForm.user_password.className="errorinput";$("passworderr").style.display="block";$("passwordhint").style.display="none";validform=false;}
else{theForm.user_password.className="datainput";$("passworderr").style.display="none";$("passwordhint").style.display="block";}
if(!theForm.user_password_confirmation.value||(theForm.user_password.value!=theForm.user_password_confirmation.value)){if(!theForm.user_password_confirmation.value)
$("passwordconfirmationerr").innerHTML="Please re-type your password";else
$("passwordconfirmationerr").innerHTML="Passwords do not match";theForm.user_password_confirmation.className="errorinput";$("passwordconfirmationerr").style.display="block";$("passwordconfirmationhint").style.display="none";validform=false;}
else{theForm.user_password_confirmation.className="datainput";$("passwordconfirmationerr").style.display="none";$("passwordconfirmationhint").style.display="block";}
var locationvalid=true;if(theForm.user_country.value=="US"||theForm.user_country.value=="CA"){if(!theForm.user_postalcode.value){$("locationerr").innerHTML="Please enter your postal code";theForm.user_postalcode.className="errorinput";locationvalid=false;}}
else{if(!theForm.user_city.value){$("locationerr").innerHTML="Please enter your city name";theForm.user_city.className="errorinput";locationvalid=false;}}
if(locationvalid){theForm.user_postalcode.className="datainput";theForm.user_city.className="datainput";$("locationerr").style.display="none";$("locationhint").style.display="block";}
else{$("locationerr").style.display="block";$("locationhint").style.display="none";validform=false;}
if(!theForm.captcha.value){jQuery(".signup .captchaerr").html("Please enter the letters above");theForm.captcha.className="errorinput";jQuery(".signup .captchaerr").show();jQuery(".signup .captchahint").hide();validform=false;}
else{theForm.captcha.className="datainput";jQuery(".signup .captchaerr").hide();jQuery(".signup .captchahint").show();}
if(validform==true){theForm.user_hashed_pwd.value=hex_sha256(theForm.user_password.value);theForm.user_password.value="";theForm.user_password_confirmation.value="";$('signupSubmit').style.display="none";$('signupSubmitWait').style.display="block";}
return validform;}
function toggle_postalcode_city(country){if(country=="US"||country=="CA"){$("postalcodeentry").style.display="block";$("cityentry").style.display="none";}
else{$("postalcodeentry").style.display="none";$("cityentry").style.display="block";}}
function displayerror(err,top){if(err){document.getElementById("errormsgs_body").innerHTML=err;document.getElementById("errormsgs").style.display="block";if(top){if(document.location.href.charAt(document.location.href.length-1)!='#')
document.location=document.location+"#";else
document.location=document.location;}}
else{document.getElementById("errormsgs").style.display="none";}}
var flagPopup=null;function openFlagPopup(flagtype,flagid,parentid,login_uri){if(flagPopup)
flagPopup.close();var link="flag_"+flagtype+"_link"+flagid;var content;if(login_uri==null){var options=(flagtype=="listing")?["Closed","Inappropriate","Spam"]:["Prohibited","Spam","Offensive"];content='<div class=\"flag_cell\">\n\n<form action=\"#URLPLACEHOLDER#\" method=\"post\" onsubmit=\"new Ajax.Request(\'#URLPLACEHOLDER#\', {asynchronous:true, evalScripts:true, onFailure:function(request){flagPopup.close(); jQuery(\'##LINKPLACEHOLDER#\').html(\'Flag Error\');}, onLoading:function(request){jQuery(\'##LINKPLACEHOLDER#\').html(\'Flagging ...\');}, onSuccess:function(request){flagPopup.close(); jQuery(\'##LINKPLACEHOLDER#\').parent().html(\'Flagged\');}, parameters:Form.serialize(this)}); return false;\">\n<span class=\"flag_reason\"><input type=\"radio\" name=\"reason\" value=\"'+options[0]+'\">'+options[0]+'<\/span>\n<span class=\"flag_reason\"><input type=\"radio\" name=\"reason\" value=\"'+options[1]+'\">'+options[1]+'<\/span>\n<span class=\"flag_reason\"><input type=\"radio\" name=\"reason\" value=\"'+options[2]+'\">'+options[2]+'<\/span>\n<span class=\"flag_reason\"><input type=\"radio\" name=\"reason\" value=\"Other\" checked>Other<\/span>\n<textarea class=\"datainput\" id=\"comment\" name=\"comment\"><\/textarea><span class=\"commitbtns\"><input name=\"commit\" type=\"submit\" value=\"Confirm\" /> <input type=\"button\" value=\"Cancel\" onclick=\"javascript:flagPopup.close();\"><\/span>\n<\/form>\n\n\n<\/div>\n';var flagurl="/flag/"+flagtype+"/"+flagid;if(parentid)
flagurl+="/"+parentid;content=content.replace(/#URLPLACEHOLDER#/g,flagurl);content=content.replace(/#LINKPLACEHOLDER#/g,link);}
else{content="Please <a href='\/login?url="+login_uri+"' rel='nofollow'>Login<\/a> to flag this";}
flagPopup=new popupbox("flagPopup",true,180,false,link);flagPopup.setTitleContent(null,content);flagPopup.open('flag_block');if(login_uri==null)
input_with_hint(jQuery("#flag_block form textarea#comment"),"Add your comments");return false;}
