function register(){var emOne = document.getElementsByTagName("form")[1].getElementsByTagName("input")[0];validateEmail(emOne,"emailOne");var emTwo = document.getElementsByTagName("form")[1].getElementsByTagName("input")[1];validateEmpty(emTwo,"emailTwo");document.getElementById("errora").innerHTML = "";var Allow = (document.getElementById("emailOne").innerHTML/1)+(document.getElementById("emailTwo").innerHTML/1);if (Allow==0){document.getElementById("errora").innerHTML = "Your quick registeration is under process, please wait....";if (emOne.value==emTwo.value){quickReg(emOne);}else{document.getElementById("errora").innerHTML = "Emails does not match!";
	prog(1,3000,"Emails does not match!");
;} } }

function checkLogin(x){var eAdd = document.getElementsByTagName("form")[0].getElementsByTagName("input")[0];validateEmail(eAdd,"formCheckEm");var pass = document.getElementsByTagName("form")[0].getElementsByTagName("input")[1];validateEmpty(pass);var Allow = (document.getElementById("formCheckE").innerHTML/1)+(document.getElementById("formCheckEm").innerHTML/1);if (Allow==0){document.getElementById("error").innerHTML = "Logging in, please wait...";loginUser(eAdd,pass,x);} }

function validateEmail(x,location){var Allow = document.getElementById(location).innerHTML;var field = x.value;field = field.replace(/^\s\s*/, '').replace(/\s\s*$/, '');var atLoc = field.indexOf("@");atLo = atLoc-1;var beforeAT = field.substr(0,atLo);atLoc++;var afterAt = field.substr(atLoc);var chk = 0;if((afterAt.search('@'))>-1){chk++;}if((field.search(' '))>-1){chk++;}if(field.match(/\.{2,}/gi)){chk++;}if (!isNaN(beforeAT)){chk++;}if(field.match(/\b((\.@.)|(\.@)|(\@.))\b/)){chk++;}if(!field.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/)){chk++;}if (chk>0){document.getElementById(x.name+"msg").innerHTML = "Invalid Entry";if (document.getElementById(location).innerHTML==0){document.getElementById(location).innerHTML=1;}}else{var isEmail = 0;var myArray = field.match(/\W/gi);for (var i=0;i<myArray.length;i++){if (myArray[i]!='@' && myArray[i]!='-' && myArray[i]!='.' && myArray[i]!='_'){isEmail = 1;}}if (isEmail==0){document.getElementById(x.name+"msg").innerHTML = "*";document.getElementById(location).innerHTML = 0;}else{document.getElementById(x.name+"msg").innerHTML = "Invalid Entry";if (document.getElementById(location).innerHTML==0){document.getElementById(location).innerHTML=1;}}}}

function validateEmpty(x){var field = x.value;field = field.replace(/^\s\s*/, '').replace(/\s\s*$/, '');var Allow = document.getElementById("formCheckEm").innerHTML;var pattern = /\s/ig;var fielda = field.replace(pattern,'');if (fielda=="" || fielda==0	) {document.getElementById(x.name+"msg").innerHTML = "Invalid Entry";if (document.getElementById("formCheckEm").innerHTML==0){document.getElementById("formCheckEm").innerHTML=1;}}else{document.getElementById(x.name+"msg").innerHTML = "*";document.getElementById("formCheckEm").innerHTML = 0;}}

function loginUser(eAdd,pass,x){
	var u = eAdd.value;
	var p = pass.value;
	var req = Inint_AJAX();
	req.onreadystatechange = function () {
		if (req.readyState==4) {
			if (req.status==200) {
				var str=req.responseText;
				if (str==0){
					if (x==0){
						window.location	= "accountDetails.php";
					}else{
						window.location = "accountDetails.php";
					}
				}else if(str==1){
					window.location = "cart.php";
				}else if(str==2){
					window.location="accountDetails.php";
				}else{
					document.getElementById("error").innerHTML = str;
				}
			}
		}
	};
	req.open("GET", "codea/loginUser.php?user="+u+"&pass="+p);
	req.send(null);
}

function quickReg(em){
	var email = em.value;
	email = email.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	var req = Inint_AJAX();
	req.onreadystatechange = function () {
		if (req.readyState==4) {
			if (req.status==200) {
				var str=req.responseText;
				if (str==0){
					msgg = "Your password is being sent to "+email+" <br /> You can continue shopping now without loging in";
					prog(1,3000,msgg);
					document.getElementById("errora").innerHTML = msgg;window.location = "cart.php";
				}else{
					prog(1,2000,str);
					document.getElementById("errora").innerHTML = str;
				}
			}
		}
	};
	req.open("GET", "codea/quickReg.php?e="+email);
	req.send(null);}
