/* File: js/toys.js, Ratio: 22.7% */

function changeprice(costprice,whattofill){price=(costprice/0.4)*1.175;priceinput=document.getElementById(whattofill);priceinput.value=(Math.round(price*100))/100;}
function changesubtotal(costprice,quantity,whattofill){price=(costprice*quantity);priceinput=document.getElementById(whattofill);priceinput.value=(Math.round(price*100))/100;}
var spinnerDiv='<div style="text-align:center" id="spinnerDiv"><img src="'+STATIC_IMG_DIR+'spinner.gif" alt="" style="padding:48px 0 19px 0" /><\/div>';function makeScreenDark(){$('body').prepend('<div id="dark"></div>');$('#dark').css({'left':'0px','right':'0px','opacity':'0.6','background':'#ffffff','width':'100%','height':$(document).height()+'px','z-index':'10','position':'absolute'})}
function createNewModalBox(title,buttons,cssFloat,thiscontent,showCloseBox){if((title=='Sign In')){thiswidth='395';}else{thiswidth='650';}
extraHeight=($(window).height()/2-100);if(showCloseBox===true){title+='<a href="#" id="close_message" style="margin-left:236px;"> close this box<\/a>';}
var baner='<div id="JSnew_mesage" style="left:'+($(window).width()/2-(thiswidth/2))+'px;top:'+($(document).scrollTop()+extraHeight)+'px;">';baner+='<div id="JSnew_mesageWhiteArea">';baner+='<h2 style="margin-bottom:5px;">'+title+'<\/h2>';baner+='<div id="send_new_mesage_div" style="border-top:1px dotted #cccccc;">';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);}
function clearme(fe,txt){if(fe.value==txt){fe.value="";}
return;}
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:300000,beforeSend:function(){$('#'+htmlDiv).html(spinnerDiv);},success:function(msg){$('#'+htmlDiv).html(msg);},error:function(){$('#'+htmlDiv).html('<p style="color:#ff0000;">Whoops..</p>');}});}
function getInfiniteAjaxContent(theURL,htmlDiv,pagenumber){$.ajax({type:"POST",url:theURL,data:'',timeout:15000,beforeSend:function(){$('#'+htmlDiv).html(spinnerDiv);},success:function(msg){$('#'+htmlDiv).html(msg);pagenumber++;thispage=pagenumber;},error:function(){}});}
function isNumber(n){return!isNaN(parseFloat(n))&&isFinite(n);}
var the_URLtoGoTo='';function displayLoginForm(URLtoGoTo){the_URLtoGoTo=URLtoGoTo;makeScreenDark();displayMessage='';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, a#close_message','JSnew_mesage');getSomeAjaxContent(URL+'customers/ajax_login_form/'+displayMessage,'send_new_mesage_div','URLtoGoTo='+the_URLtoGoTo);}
function setUpNewWishlist(){if($('#create_a_wishlist_box.offscreen').length){$('#create_a_wishlist_box').removeClass('offscreen');}else{$('#create_a_wishlist_box').addClass('offscreen');}}
function processLoginForm(formElementRedirectTo){rememberval=$("#loginRemember").is(':checked');if(rememberval==true){ajaxremember=1;}else{ajaxremember=0;}
if(formElementRedirectTo){displayRedirectTo=formElementRedirectTo;}else{displayRedirectTo=the_URLtoGoTo;}
$.post(URL+'customers/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 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 in_array(needle,haystack){var key='';for(key in haystack){if(haystack[key]==needle){return true;}}
return false;}
