/********************************************************/
/*               Flash Slide Show Feature               */
/*                   © 2011 Ryan Nore                   */
/********************************************************/
function getFlash(flash,width,height,thediv){
        document.getElementById(thediv).innerHTML='<object width="'+width+'" height="'+height+'"><param name="movie" value="'+flash+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+flash+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>';
}

/********************************************************/
/*               Basic Flash No Click Code              */
/*                   © 2011 Ryan Nore                   */
/********************************************************/
function showFlash(flash,width,height,wmode){
        document.write('<object width="'+width+'" height="'+height+'"><param name="movie" value="http://www.artofdesigns.com/clients/frickandfrackmusic/flash/'+flash+'.swf"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="'+wmode+'"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.artofdesigns.com/clients/frickandfrackmusic/flash/'+flash+'.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="'+wmode+'" width="'+width+'" height="'+height+'"></embed></object>');
}

/********************************************************/
/*               Basic Hide/Show Function               */
/*                   © 2011 Ryan Nore                   */
/********************************************************/
function HideShow(hide,show){
        document.getElementById(show).style.display="block";
        document.getElementById(hide).style.display="none";
}

/********************************************************/
/* The "About Neesa" Expanding and Collapsing Functions */
/*                   © 2011 Ryan Nore                   */
/********************************************************/
var AboutNeesaHeight,AboutNeesaStep,AboutNeesaInc,AboutNeesaExpand,AboutNeesaCollapse;
function SetNeesaHeight(){
        AboutNeesaStep=0;
        AboutNeesaHeight=Number(document.getElementById("moreneesa").offsetHeight);
        AboutNeesaInc=Math.floor(AboutNeesaHeight/30);
        document.getElementById("moreneesa").style.overflow="hidden";
        document.getElementById("moreneesa").style.height="0px";
}
function ExpandNeesa(){
        document.getElementById("neesareadmore").style.display="none";
        clearInterval(AboutNeesaCollapse);
        AboutNeesaExpand=setInterval("NeesaExpanding()",5);
}
function CollapseNeesa(){
        clearInterval(AboutNeesaExpand);
        AboutNeesaCollapse=setInterval("NeesaCollapsing()",5);
}
function NeesaExpanding(){
        AboutNeesaStep++;
        if(AboutNeesaStep<=AboutNeesaInc){
                document.getElementById("moreneesa").style.height=(AboutNeesaStep*30)+"px";
        } else {
                document.getElementById("moreneesa").style.height=AboutNeesaHeight+"px";
                clearInterval(AboutNeesaExpand);
        }
}
function NeesaCollapsing(){
        AboutNeesaStep--;
        if(AboutNeesaStep>=0){
                document.getElementById("moreneesa").style.height=(AboutNeesaStep*30)+"px";
        } else {
                AboutNeesaStep=0;
                document.getElementById("neesareadmore").style.display="block";
                document.getElementById("moreneesa").style.height="0px";
                clearInterval(AboutNeesaCollapse);
        }
}

/**********************************************************/
/* The "About Phillip" Expanding and Collapsing Functions */
/*                     © 2011 Ryan Nore                   */
/**********************************************************/
var AboutPhillipHeight,AboutPhillipStep,AboutPhillipInc,AboutPhillipExpand,AboutPhillipCollapse;
function SetPhillipHeight(){
        AboutPhillipStep=0;
        AboutPhillipHeight=Number(document.getElementById("morephillip").offsetHeight);
        AboutPhillipInc=Math.floor(AboutPhillipHeight/30);
        document.getElementById("morephillip").style.overflow="hidden";
        document.getElementById("morephillip").style.height="0px";
}
function ExpandPhillip(){
        document.getElementById("phillipreadmore").style.display="none";
        clearInterval(AboutPhillipCollapse);
        AboutPhillipExpand=setInterval("PhillipExpanding()",5);
}
function CollapsePhillip(){
        clearInterval(AboutPhillipExpand);
        AboutPhillipCollapse=setInterval("PhillipCollapsing()",5);
}
function PhillipExpanding(){
        AboutPhillipStep++;
        if(AboutPhillipStep<=AboutPhillipInc){
                document.getElementById("morephillip").style.height=(AboutPhillipStep*30)+"px";
        } else {
                document.getElementById("morephillip").style.height=AboutPhillipHeight+"px";
                clearInterval(AboutPhillipExpand);
        }
}
function PhillipCollapsing(){
        AboutPhillipStep--;
        if(AboutPhillipStep>=0){
                document.getElementById("morephillip").style.height=(AboutPhillipStep*30)+"px";
        } else {
                AboutPhillipStep=0;
                document.getElementById("phillipreadmore").style.display="block";
                document.getElementById("morephillip").style.height="0px";
                clearInterval(AboutPhillipCollapse);
        }
}

/***************************************/
/*  Private Info Construction Function */
/*           © 2011 Ryan Nore          */
/***************************************/
function BuildPrivate(encea,emname){
        var EncKeys=Array("","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",0,1,2,3,4,5,6,7,8,9,".","-","_","@",":");
        var EncPieces=encea.split(",");
        var i,Literal;
        Literal="";
        for(i=0;i<EncPieces.length;i++){
                Literal+=EncKeys[EncPieces[i]];
        }
        var mtlink='<a href="'+Literal+'">'+emname+'</a>';
        document.write(mtlink);
}
function BuildSecure(encrypted){
        var EncKeys=Array(""," ","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","_","-","~",".",":","/");
        var EncPieces=encrypted.split(",");
        var i,Literal;
        Literal="";
        for(i=0;i<EncPieces.length;i++){
                Literal+=EncKeys[EncPieces[i]];
        }
        return Literal;
}
/***************************************/
/*        Front Page Drop Down         */
/*           © 2011 Ryan Nore          */
/***************************************/
var MMOpened,MMHeight,MMStep,MinistryMenu,MMExpanding,MMCollapsing;
function initMM(){
        MMOpened=false;
        MMHeight=228;
        MMStep=0;
        MinistryMenu=document.getElementById("ministry-dropdown");
        MinistryMenu.style.height="0px";
}
function toggleMM(){
        if(!MMOpened){
                MMOpened=true;
                MMOpen();
        } else {
                MMOpened=false;
                MMClose();
        }
}
function MMOpen(){
        clearInterval(MMCollapsing);
        MMExpanding=setInterval("MMExpand()",10);
}
function MMClose(){
        clearInterval(MMExpanding);
        MMCollapsing=setInterval("MMCollapse()",10);
}
function MMExpand(){
        MMStep++;
        if(MMStep<=20){
                MinistryMenu.style.height=(MMStep*10)+"px";
        } else {
                clearInterval(MMExpanding);
                MinistryMenu.style.height=MMHeight+"px";
        }
}
function MMCollapse(){
        MMStep--;
        if(MMStep>=0){
                MinistryMenu.style.height=(MMStep*10)+"px";
        } else {
                MMStep=0;
                clearInterval(MMCollapsing);
                MinistryMenu.style.height="0px";
        }
}
/*----------------------------*/
/*   Contact Form JavaScript  */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
/* Style Variables and Values */
/*----------------------------*/
var ErrorColor="#E95346";
var ErrorLabelColor="#E95346";
var DefaultColor="#A79482";
var DefaultTextStyle="oblique";
var FormFieldTextColor="#000000";
var FormFieldTextStyle="normal";

/*---------------------------*/
/* Contact Thank You Message */
/*---------------------------*/
var ThankYou="Thank You! We will reply to your inquiry as soon as possible.";

/*-----------------*/
/* Form Error Text */
/*-----------------*/
var PersonalRequired="Both personal information fields are required.";
var CommentsRequired="Please write comments concerning why you are contacting us.";
var ValidEmail="Please enter a valid e-mail address.";

/*--------------------------------------------*/
/* Form Required Field Names and Default Text */
/*--------------------------------------------*/
var Forms= new Array("ffm-contact");
var Fields= new Array("name","email");
var FieldDefault= new Array();
FieldDefault[0]= new Array("Your full name","Valid e-mail address");

function focused(formid,field){
	var FormName=Forms[formid];
	var FieldName=Fields[field];
	var MyForm=document[FormName];
	var MyField=MyForm[FieldName];
	var MyText=MyField.value;
	var MyDefaultText=FieldDefault[formid][field];
	if(MyText==MyDefaultText){
		MyField.value="";
		MyField.style.color=FormFieldTextColor;
		MyField.style.fontStyle=FormFieldTextStyle;
	}
	return true;
}
function unfocused(formid,field){
	var FormName=Forms[formid];
	var FieldName=Fields[field];
	var MyForm=document[FormName];
	var MyField=MyForm[FieldName];
	var MyText=MyField.value;
	var MyDefaultText=FieldDefault[formid][field];
	if(MyText=="" || MyText==undefined){
		MyField.style.color=DefaultColor;
		MyField.style.fontStyle=DefaultTextStyle;
		MyField.value=MyDefaultText;
	}
	return true;
}
function validatemail(email){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(email);
}
function checkcontact(){
	var ContactForm=document["ffm-contact"];
	var cName=ContactForm.name.value;
	var cEmail=ContactForm.email.value;
	var cComments=ContactForm.message.value;
	var error=0;
	document.getElementById("personal").style.backgroundColor="transparent";
	document.getElementById("comments").style.backgroundColor="transparent";
	document.getElementById("personal-label").style.backgroundColor="transparent";
	document.getElementById("comments-label").style.backgroundColor="transparent";
	document.getElementById("thankyou").innerHTML="";
	if(cName=="" || cName==undefined || cName=="Your full name" || cEmail=="" ||cEmail==undefined || cEmail=="Valid e-mail address"){
		error=1;
		document.getElementById("personal").style.backgroundColor=ErrorColor;
		document.getElementById("personal-label").style.backgroundColor=ErrorLabelColor;
		document.getElementById("thankyou").innerHTML=PersonalRequired;
	} else {
		if(!validatemail(cEmail)){
			error=1;
			document.getElementById("personal").style.backgroundColor=ErrorColor;
			document.getElementById("personal-label").style.backgroundColor=ErrorLabelColor;
			document.getElementById("thankyou").innerHTML=ValidEmail;
		}
	}
	if(error==0){
		if(cComments=="" || cComments==undefined){
			error=1;
			document.getElementById("comments").style.backgroundColor=ErrorColor;
			document.getElementById("comments-label").style.backgroundColor=ErrorLabelColor;
			document.getElementById("thankyou").innerHTML=CommentsRequired;
		}
	}
	if(error!=1){
		submitcontact();
	}
	return true;
}
function resetcontactform(){
	var ContactForm=document["ffm-contact"];
	ContactForm.name.value=FieldDefault[0][0];
	ContactForm.name.style.color=DefaultColor;
	ContactForm.name.style.fontStyle=DefaultTextStyle;
	ContactForm.email.value=FieldDefault[0][1];
	ContactForm.email.style.color=DefaultColor;
	ContactForm.email.style.fontStyle=DefaultTextStyle;
	ContactForm.message.value="";
	return true;
}
function submitcontact(){
	var ContactForm=document["ffm-contact"];
	var cName=ContactForm.name.value;
	var cEmail=ContactForm.email.value;
	var cComments=ContactForm.message.value;
	var parameters="action=makecontact&cname="+escape(encodeURI(cName))+"&cemail="+escape(encodeURI(cEmail))+"&ccomments="+escape(encodeURI(cComments));
	var MyConnect= false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		MyConnect= new XMLHttpRequest();
		if (MyConnect.overrideMimeType) {
			MyConnect.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			MyConnect= new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				MyConnect= new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!MyConnect) {
		alert("Your browser does not support AJAX!");
		return false;
	}
	MyConnect.onreadystatechange =function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			document.getElementById("thankyou").innerHTML=ThankYou;
			resetcontactform();
		}
	};
	MyConnect.open('POST','ajaxscript.php', true);
	MyConnect.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	MyConnect.setRequestHeader("Content-length", parameters.length);
	MyConnect.setRequestHeader("Connection", "close");
	MyConnect.send(parameters);
	return true;
}
/*----------------------------*/
/*    Login Form JavaScript   */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
function checklogin(){
	var LoginForm=document["login"];
	var un=LoginForm.ffusername.value;
	var pa=LoginForm.ffpassword.value;
	var gt=LoginForm.curpag.value;
	if(un=="" || un==undefined || pa=="" || pa==undefined){
		document.getElementById("le-title").innerHTML="Required Fields";
		document.getElementById("le-text").innerHTML="Enter both an e-mail and password please.";
		document.getElementById("login-error").style.display="block";
	} else {
		var MyConnect;
		try{
			MyConnect=new XMLHttpRequest();
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
					MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){
					alert("Your browser does not support AJAX!");
				}
			}
		}
		MyConnect.onreadystatechange=function(){
			if(MyConnect.readyState==4){
				var gipResponse=MyConnect.responseText;
				if(gipResponse=="notfound"){
					LoginForm.ffusername.value="";
					LoginForm.ffpassword.value="";
					document.getElementById("le-title").innerHTML="Not Found";
					document.getElementById("le-text").innerHTML="You must register before logging in.";
					document.getElementById("login-error").style.display="block";
				} else if(gipResponse=="nopass"){
					LoginForm.ffpassword.value="";
					document.getElementById("le-title").innerHTML="Incorrect Password";
					document.getElementById("le-text").innerHTML="The password entered was incorrect.";
					document.getElementById("login-error").style.display="block";
				} else if(gipResponse=="nouser"){
					LoginForm.ffusername.value="";
					document.getElementById("le-title").innerHTML="Incorrect E-mail";
					document.getElementById("le-text").innerHTML="The email entered was incorrect.";
					document.getElementById("login-error").style.display="block";
				} else if(gipResponse=="notactive"){
					document.getElementById("le-title").innerHTML="Inactive Account";
					document.getElementById("le-text").innerHTML="You have not confirmed your account yet.";
					document.getElementById("login-error").style.display="block";
				} else if(gipResponse=="error"){
					document.getElementById("le-title").innerHTML="Login Error";
					document.getElementById("le-text").innerHTML="There was and error. Please try again.";
					document.getElementById("login-error").style.display="block";
				} else if(gipResponse=="OK"){
					LoginForm.ffusername.value="";
					LoginForm.ffpassword.value="";
					location.href=gt;
				}
			}
		}
		MyConnect.open("GET","ajaxscript.php?action=checklogin&un="+un+"&pa="+pa);
		MyConnect.send(null);
	}
}
/*----------------------------*/
/*     Log Out JavaScript     */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
function LogOut(){
	var LogOutForm=document["logout"];
	var gt=LogOutForm.curpag.value;
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else {
				location.href=gt;
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=logout");
	MyConnect.send(null);
}
/*----------------------------*/
/*   Registration JavaScript  */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
function CheckReg(){
	document.getElementById("regerror").innerHTML="";
	var RegForm=document["registration"];
	var fname=RegForm.fname.value;
	var email=RegForm.email.value;
	var pass=RegForm.pass.value;
	var cpass=RegForm.cpass.value;
	var rferror=0;
	if(fname=="" || fname==undefined || email=="" || email==undefined || pass=="" || pass==undefined || cpass=="" || cpass==undefined){
		document.getElementById("regerror").innerHTML="All fields are required for registration.";
		rferror=1;
	}
	if(rferror==0 && !validatemail(email)){
		document.getElementById("regerror").innerHTML="Please enter a valid e-mail address.";
		rferror=1;
	}
	if(rferror==0 && pass.length<9){
		document.getElementById("regerror").innerHTML="Your password must be at least 8 characters long.";
		rferror=1;
	}
	if(rferror==0 && !pass.match(/^[a-zA-Z0-9]+$/)){
		document.getElementById("regerror").innerHTML="Your password must be only alphanumeric characters.";
		rferror=1;
	}
	if(rferror==0 && pass!=cpass){
		document.getElementById("regerror").innerHTML="Your password does not match the confirmation password.";
		rferror=1;
	}
	if(rferror==0){
		var MyConnect;
		try{
			MyConnect=new XMLHttpRequest();
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
					MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){
					alert("Your browser does not support AJAX!");
				}
			}
		}
		MyConnect.onreadystatechange=function(){
			if(MyConnect.readyState==4){
				var gipResponse=MyConnect.responseText;
				if(gipResponse=="error"){
					document.getElementById("regerror").innerHTML="An Error occured. Please try again later.";
				} else if(gipResponse==1){
					document.getElementById("regerror").innerHTML="That email address is already associated with an account.";
					rferror=1;
				}
				if(rferror==0){
					ProcessReg(fname,email,pass);
				}
			}
		}
		MyConnect.open("GET","ajaxscript.php?action=regmail&email="+email);
		MyConnect.send(null);
	}
}
function ProcessReg(fname,email,pass){
	var RegForm=document["registration"];
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
				document.getElementById("regerror").innerHTML="An Error occured. Please try again later.";
			} else {
				document.getElementById("regerror").innerHTML="Thank you for registering. A confirmation e-mail has been sent to you. Before using the account please follow the link in the confirmation e-mail to activate your account.";
				RegForm.fname.value="";
				RegForm.email.value="";
				RegForm.pass.value="";
				RegForm.cpass.value="";
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=register&fname="+fname+"&email="+email+"&pass="+pass);
	MyConnect.send(null);
}
/*----------------------------*/
/*     Account JavaScript     */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
function MAEdit(what){
	var nt=document.getElementById('nametext');
	var nf=document.getElementById('namefield');
	var et=document.getElementById('emailtext');
	var ef=document.getElementById('emailfield');
	var pt=document.getElementById('passtext');
	var pf=document.getElementById('passfield');
	nt.style.display="block";
	nf.style.display="none";
	et.style.display="block";
	ef.style.display="none";
	pt.style.display="block";
	pf.style.display="none";
	if(what=="name"){
		nt.style.display="none";
		nf.style.display="block";
	} else if(what=="email"){
		et.style.display="none";
		ef.style.display="block";
	} else if(what=="pass"){
		pt.style.display="none";
		pf.style.display="block";
	}
}
function saveAccount(what,varval,uid){
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
				document.getElementById("regerror").innerHTML="An Error occured. Please try again later.";
			} else {
				var nt=document.getElementById('nametext');
				var nf=document.getElementById('namefield');
				var et=document.getElementById('emailtext');
				var ef=document.getElementById('emailfield');
				var pt=document.getElementById('passtext');
				var pf=document.getElementById('passfield');
				nt.style.display="block";
				nf.style.display="none";
				et.style.display="block";
				ef.style.display="none";
				pt.style.display="block";
				pf.style.display="none";
				location.href="my-account.php";
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=accsave&what="+what+"&varval="+varval+"&uid="+uid);
	MyConnect.send(null);
}
function MASave(what){
	var MyAccount=document["macc"];
	var error=0;
	var varval="";
	var uid=MyAccount.uid.value;
	document.getElementById("formerror").innerHTML="";
	if(what=="name"){
		if(MyAccount.fname.value=="" || MyAccount.fname.value==undefined){
			document.getElementById("formerror").innerHTML="You must enter a name in the field.";
			error=1;
		} else {
			varval=MyAccount.fname.value;
			saveAccount(what,MyAccount.fname.value,uid);
		}
	} else if(what=="email"){
		if(MyAccount.email.value=="" || MyAccount.email.value==undefined || !validatemail(MyAccount.email.value)){
			document.getElementById("formerror").innerHTML="You must enter a valid e-mail address in the field.";
			error=1;
		} else {
			var MyConnect;
			try{
				MyConnect=new XMLHttpRequest();
			}
			catch (e){
				try{
					MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e){
					try{
						MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e){
						alert("Your browser does not support AJAX!");
					}
				}
			}
			MyConnect.onreadystatechange=function(){
				if(MyConnect.readyState==4){
					var gipResponse=MyConnect.responseText;
					if(gipResponse=="error"){
						document.getElementById("formerror").innerHTML="An Error occured. Please try again later.";
					} else if(gipResponse=="taken"){
						document.getElementById("formerror").innerHTML="That email address is already associated with another account.";
						error=1;
					} else if(gipResponse=="OK"){
						saveAccount(what,MyAccount.email.value,uid);
					}
				}
			}
			MyConnect.open("GET","ajaxscript.php?action=accemail&email="+MyAccount.email.value+"&uid="+uid);
			MyConnect.send(null);
		}
	} else if(what=="pass"){
		if(MyAccount.pass.value=="" || MyAccount.pass.value==undefined || MyAccount.cpass.value=="" || MyAccount.cpass.value==undefined || MyAccount.pass.value!=MyAccount.cpass.value){
			document.getElementById("formerror").innerHTML="You must enter the same password in both fields.";
			error=1;
		} else if(MyAccount.pass.value=="" || !MyAccount.pass.value.match(/^[a-zA-Z0-9]+$/)){
			document.getElementById("formerror").innerHTML="You may only use alphanumeric characters in your password.";
			error=1;
		} else {
			varval=MyAccount.pass.value;
			saveAccount(what,MyAccount.pass.value,uid);
		}
	}
}
function ShowHistory(){
	if(document.getElementById("purchasehistory").style.display=="none"){
		document.getElementById("histag").innerHTML="Hide my purchase history";
		document.getElementById("purchasehistory").style.display="block";
	} else {
		document.getElementById("histag").innerHTML="See my purchase history";
		document.getElementById("purchasehistory").style.display="none";
	}
}
/*----------------------------*/
/*  Miscellaneous JavaScript  */
/*      © 2011 Ryan Nore      */
/*----------------------------*/
function AddToCart(pid,uid){
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else {
				document.getElementById('plop').innerHTML='<a href="my-basket.php"><img src="img/fillbasket.gif" width="64" height="64" alt="Shopping Basket" title="Shopping Basket" style="margin:0px 0px 0px 103px;" /></a>';
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=addtocart&pid="+pid+"&uid="+uid);
	MyConnect.send(null);
}
function RemoveFromCart(k,uid){
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else {
				location.href="my-basket.php";
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=removefromcart&k="+k+"&uid="+uid);
	MyConnect.send(null);
}
var quant;
function UpdateCart(uid){
	var pqs="";
	var i;
	quant=new Array();
	quant=document.cart.prodquantity;
	if(document.cart.prodquantity.value!=undefined){
		pqs=document.cart.prodquantity.value;
	} else {
		for(i=0;i<quant.length;i++){
			if(i==0){
				pqs+=quant[i].value;
			} else {
				pqs+="|"+quant[i].value;
			}
		}
	}
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else {
				location.href="my-basket.php";
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=updatecart&pqs="+pqs+"&uid="+uid);
	MyConnect.send(null);
}
function Shipping(uid){
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else if(gipResponse==1){
				location.href="checkout-shipping.php";
			} else if(gipResponse==0){
				location.href="checkout-confirm.php";
			} else if(gipResponse=="none"){
				location.href="my-basket.php";
			} else {
				document.getElementById("basketerror").innerHTML=gipResponse;
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=shipping&uid="+uid);
	MyConnect.send(null);
}
function vAddy(){
	document.getElementById("continue").innerHTML="";
	document.getElementById("shippingquotes").innerHTML="";
}
function ShippingQuotes(service,uid){
	document.getElementById("addresserrors").innerHTML="";
	document.getElementById("continue").innerHTML="";
	var szip=document.address.szip.value;
	var scity=document.address.scity.value;
	var sstate=document.address.sstate.options[document.address.sstate.selectedIndex].value;
	var scountry=document.address.scountry.options[document.address.scountry.selectedIndex].value;
	if(szip=="" || szip==undefined || scity=="" || scity==undefined){
		document.getElementById("addresserrors").innerHTML="All Fields are required...<br/><br/>";
	} else {
		document.getElementById("shippingquotes").innerHTML='<br/><p><em>Your Shipping Quotes...</em></p><hr/><div style="width:200px;margin:0px 0px 0px 100px;"><img src="img/loading.gif" width="200" height="40" title="Please wait while your shipping quotes are retrieved..."/></div>';
		var MyConnect;
		try{
			MyConnect=new XMLHttpRequest();
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
					MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){
					alert("Your browser does not support AJAX!");
				}
			}
		}
		MyConnect.onreadystatechange=function(){
			if(MyConnect.readyState==4){
				var gipResponse=MyConnect.responseText;
				if(gipResponse=="error"){
					document.getElementById("shippingquotes").innerHTML='<br/><p><em>Your Shipping Quotes...</em></p><hr/><div class="formerrors">An error occured, please try another shipping option or try to checkout again in a few minutes.</div>';
				} else {
					document.getElementById("shippingquotes").innerHTML=gipResponse;
					document.getElementById("continue").innerHTML='<img src="img/continue.png" width="200" height="40" alt="Confirm your order..." title="Confirm your order..." style="cursor:pointer;" onclick="GoPay('+uid+');"/>';
				}
			}
		}
		MyConnect.open("GET","ajaxscript.php?action=shippingquotes&service="+service+"&zip="+szip+"&city="+scity+"&state="+sstate+"&country="+scountry);
		MyConnect.send(null);
	}
}
function GoPay(uid){
	document.getElementById("continue").innerHTML='<img src="img/loading.gif" width="200" height="40" title="Please wait..."/>';
	var sstreet=document.address.sstreet.value;
	var scity=document.address.scity.value;
	var sstate=document.address.sstate.options[document.address.sstate.selectedIndex].value;
	var szip=document.address.szip.value;
	var scountry=document.address.scountry.options[document.address.scountry.selectedIndex].value;
	var scost=document.shippingquote.shipping;
	var shipping;
	if(scost.value){
		shipping=scost.value;
	} else {
		var options=scost.length;
		var i;
		for(i=0;i<options;i++){
			if(scost[i].checked){
				shipping=scost[i].value;
			}
		}
	}
	var MyConnect;
	try{
		MyConnect=new XMLHttpRequest();
	}
	catch (e){
		try{
			MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
			}
		}
	}
	MyConnect.onreadystatechange=function(){
		if(MyConnect.readyState==4){
			var gipResponse=MyConnect.responseText;
			if(gipResponse=="error"){
			} else {
				location.href="checkout-confirm.php";
			}
		}
	}
	MyConnect.open("GET","ajaxscript.php?action=gopay&uid="+uid+"&street="+sstreet+"&city="+scity+"&state="+sstate+"&zip="+szip+"&country="+scountry+"&shipping="+shipping);
	MyConnect.send(null);
}
/*
function MakePayment(uid){
	document.getElementById("payerror").innerHTML='';
	var cform=document.order;
	var cc=cform.ccn1.value+cform.ccn2.value+cform.ccn3.value+cform.ccn4.value;
	var xm=cform.expm.value;
	var xy=cform.expy.value;
	var tc=cform.tcc.value;
	var SecureURL=cform.SecureURL.value;
	var PaymentURL=BuildSecure(SecureURL);
	var error;
	
	if(cc.length==16 && xm.length==2 && xy.length==4){
		error=0;
	} else {
		error=1;
		document.getElementById("payerror").innerHTML='Please enter valid and complete credit card information.';
	}
	if(error==0){
		document.getElementById("paybutton").innerHTML='<img src="img/loading.gif" width="200" height="40" title="Please wait..."/>';
		var MyConnect;
		try{
			MyConnect=new XMLHttpRequest();
		}
		catch (e){
			try{
				MyConnect=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
					MyConnect=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){
					alert("Your browser does not support AJAX!");
				}
			}
		}
		MyConnect.onreadystatechange=function(){
			if(MyConnect.readyState==4){
				var gipResponse=MyConnect.responseText;
				var GatewayResponse=gipResponse.split("-");
				if(GatewayResponse[0]=="error"){
					document.getElementById("payerror").innerHTML=GatewayResponse[1];
					document.getElementById("paybutton").innerHTML='<img src="img/pay-now.png" width="200" height="40" title="Pay Now!" style="cursor:pointer;" onclick="MakePayment();"/>';
				} else {
					document.getElementById("payerror").innerHTML='<form name="returnedError" action="checkout-completed.php" method="post"><input type="hidden" name="errorcode" value="'+GatewayResponse[0]+'"/><input type="hidden" name="errorsrc" value="'+uid+'"/></form>';
					document.returnedError.submit();
				}
			}
		}
		MyConnect.open("GET",PaymentURL+"?cc="+cc+"&xm="+xm+"&xy="+xy+"&tc="+tc);
		MyConnect.send(null);
	}
}
*/
function MakePayment(uid){
	document.getElementById("payerror").innerHTML='';
	var cform=document.order;
	var cc=cform.ccn1.value+cform.ccn2.value+cform.ccn3.value+cform.ccn4.value;
	var ccp=cform.ccn1.value+"|"+cform.ccn2.value+"|"+cform.ccn3.value+"|"+cform.ccn4.value;
	var xm=cform.expm.value;
	var xy=cform.expy.value;
	var tc=cform.tcc.value;
	var SecureURL=cform.SecureURL.value;
	var PaymentURL=BuildSecure(SecureURL);
	var error;
	
	if(cc.length>=15 && xm.length==2 && xy.length==4){
		error=0;
	} else {
		error=1;
		document.getElementById("payerror").innerHTML='Please enter valid and complete credit card information.';
	}
	if(error==0){
		document.getElementById("paybutton").innerHTML='<img src="img/loading.gif" width="200" height="40" title="Please wait..."/>';
		document.getElementById("payerror").innerHTML='<form name="returnedError" action="'+PaymentURL+'" method="post"><input type="hidden" name="cc" value="'+cc+'"/><input type="hidden" name="ccp" value="'+ccp+'"/><input type="hidden" name="xm" value="'+xm+'"/><input type="hidden" name="xy" value="'+xy+'"/><input type="hidden" name="tc" value="'+tc+'"/></form>';
		document.returnedError.submit();
	}
}
function AutoTab(tf,nf,nc){
	var theForm=document.order;
	var theField=theForm[tf].value;
	var nextField=theForm[nf];
	var NumChars=Number(nc);
	
	if(theField.length==NumChars){
		nextField.value="";
		nextField.focus();
	}
}
function ShowOrder(which){
	var order="items"+which;
	if(document.getElementById(order).style.display=="none"){
		document.getElementById(order).style.display="block";
	} else {
		document.getElementById(order).style.display="none";
	}
}
