/* File: js/script.js, Ratio: 9.6% */

var spinnerDiv='<div style="text-align:center" id="spinnerDiv"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:8px 0 9px 0" /><\/div>';function makeScreenDark(){$('body').prepend('<div id="dark"></div>');$('#dark').css({'left':'0px','right':'0px','opacity':'0.4','background':'#000','width':'100%','height':$(document).height()+'px','z-index':'10','position':'absolute'})}
function createNewModalBox(title,buttons,cssFloat,thiscontent,showCloseBox){if(title=='Changes To Plan'||title=='User Search'){thiswidth='348';}else if((title=='Sign In')){thiswidth='375';}else if((title=='Delete Message')||(title=='Edit Message')){thiswidth='442';}else{thiswidth='528';}
if(title=='Photos'){extraHeight=100;}else{extraHeight=($(window).height()/2-100);}
if(showCloseBox===true){title='<span style="width:'+(thiswidth-44)+'px;float:left;">'+title+'</span><a class="close_message" name=""/></a><div class="clear"></div>';}
var baner='<div id="JSnew_mesage" style="background:url(\''+STATIC_IMG_DIR+'plans/content_message.gif\') repeat-x #000000;left:'+($(window).width()/2-(thiswidth/2))+'px;position:absolute;top:'+($(document).scrollTop()+extraHeight)+'px;width:'+thiswidth+'px;z-index:11">';baner+='<div id="JSnew_mesageTitleArea" style="color:#fff;font-size:16px;font-weight:bold;padding:6px 0 6px 14px;">'+title+'</div>';baner+='<div id="JSnew_mesageWhiteArea" style="background:#fff;margin:2px 12px 12px 12px;padding:19px 10px 21px 15px;width:'+(thiswidth-53)+'px">';baner+='<div id="send_new_mesage_div">';baner+=thiscontent;baner+='</div>';baner+='<div style="float:'+cssFloat+';padding:10px 3px 0 3px;width:116px" id="response_buttons">';for(x in buttons){baner+='<a id="'+buttons[x]+'" href=""></a>';}
baner+='<div class="clear"></div></div><div class="clear"></div></div></div>';$('body').prepend(baner);$('#JSnew_mesage').draggable();}
function createCancelFunction(buttonId){$('#'+buttonId).click(function(e){e.preventDefault();$('#guests_container a,#guests_container input').unbind('click');$('#guests_container').remove();$('#JSnew_mesage *').unbind('click');$('#dark, #JSnew_mesage').remove();});}
function createCloseFunction(buttonId,mainDivId){$(buttonId).click(function(e){e.preventDefault();$('#'+mainDivId+' *').unbind('click');$('#dark, #'+mainDivId).remove();});}
function getSomeAjaxContent(theURL,htmlDiv,dataToSend){$.ajax({type:"POST",url:theURL,data:dataToSend,timeout:15000,beforeSend:function(){$('#'+htmlDiv).html(spinnerDiv);},success:function(msg){$('#'+htmlDiv).html(msg);},error:function(){}});}
function displayLoginForm(displayMessage){makeScreenDark();buttons=new Array();thiscontent=spinnerDiv;if(displayMessage){displayMessage=1;}else{displayMessage=0;}
createNewModalBox('Sign In',buttons,'left',thiscontent,true);createCloseFunction('#JSnew_mesage a.close_message','JSnew_mesage');getSomeAjaxContent(URL+'users/ajax_login_form/'+displayMessage,'send_new_mesage_div','');}
function processLoginForm(formElementRedirectTo){rememberval=$("#loginRemember").is(':checked');if(rememberval==true){ajaxremember=1;}else{ajaxremember=0;}
if(formElementRedirectTo){displayRedirectTo=formElementRedirectTo;}else{displayRedirectTo='';}
$.post(URL+'users/ajaxlogin',{user:$("#loginUser").val(),pword:$("#loginPassword").val(),remember:ajaxremember,redirectTo:displayRedirectTo},function(data)
{if(data!='0')
{window.location=data;}
else
{alert("Wrong username and/or password, or your account has not been activated.\nPlease try again.");}});}
function showFeedback(){makeScreenDark();buttons=new Array();thiscontent=spinnerDiv;createNewModalBox('Feedback & Suggestions',buttons,'left',thiscontent,true);createCloseFunction('#JSnew_mesage a.close_message','JSnew_mesage');getSomeAjaxContent(URL+'users/ajax_feedback/','send_new_mesage_div','');}
function addRule(stringToEvaluate,what,destination_url){makeScreenDark();buttons=new Array();thiscontent=spinnerDiv;createNewModalBox('Add Rule',buttons,'left',thiscontent,true);createCloseFunction('#JSnew_mesage a.close_message','JSnew_mesage');getSomeAjaxContent(URL+'rules/add/','send_new_mesage_div','string='+stringToEvaluate+'&destination_url='+destination_url);}
function addCategory(stringToEvaluate,what){makeScreenDark();buttons=new Array();thiscontent=spinnerDiv;createNewModalBox('Add Category',buttons,'left',thiscontent,true);createCloseFunction('#JSnew_mesage a.close_message','JSnew_mesage');$('#categoryLink'+what).hide();getSomeAjaxContent(URL+'categories/ajax_list/'+stringToEvaluate,'send_new_mesage_div','');}
function over(what){hyperlinkElement='newRule'+what.attr('rel');$('#'+hyperlinkElement).css({'display':'block'});$('#'+hyperlinkElement).show().css({'display':'block'});}
function out(what){hyperlinkElement='newRule'+what.attr('rel');$('#'+hyperlinkElement).hide();}
function leftover(what){hyperlinkElement='categoryLink'+what.attr('rel');$('#'+hyperlinkElement).show();}
function leftout(what){hyperlinkElement='categoryLink'+what.attr('rel');$('#'+hyperlinkElement).hide();}
function gebi(p){return document.getElementById(p);}
function isValidEmail(str){var pattern=new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);return pattern.test(str);}
function signupFormValidate(){if(gebi('email').value==''){alert('Please provide your e-mail address.');return false;}
if(gebi('terms').value=='0'){alert('You must sign up to the terms and conditions.');return false;}
if(!isValidEmail(gebi('email').value)){alert('The e-mail does not seem to be valid.');return false;}
if(gebi('UserPword').value!=gebi('UserPword2').value){alert('The passwords do not match.');return false;}
return true;}
