// JavaScript Document
var http=getXMLHTTP();

function getXMLHTTP() {
	try {
		req = new XMLHttpRequest();
	} catch(err1) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(err2) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err3) {
				req = false;
			}
		}
	} 
	return req;
}

function CheckAccessPass(Poption) {
	try {
		var myPara = new Array();
		var sConfirm = true;
		var myQuery = '';
		switch (parseInt(Poption)) {
			case 1:
				if (document.formReg.username.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+1;
				myPara[1] = '&param1='	+document.formReg.username.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;
			case 2:
				if (document.formReg.password.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+2;
				myPara[1] = '&param1='	+document.formReg.password.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;
			case 7:
				if (document.formReg.emailadd.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+7;
				myPara[1] = '&param1='	+document.formReg.emailadd.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;
			case 9:
				if (document.formReg.sponsor.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+9;
				myPara[1] = '&param1='	+document.formReg.sponsor.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;
			case 10:
				if (document.formReg.regcode.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+10;
				myPara[1] = '&param1='	+document.formReg.regcode.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;
			case 11:
				if (document.formReg.seccode.value == '') {sConfirm=false;break;}
				myPara[0] = '&param0='	+11;
				myPara[1] = '&param1='	+document.formReg.seccode.value;
				for (index1=0;index1<2;index1++) {myQuery=myQuery+myPara[index1];}
				break;			
		}
		if (sConfirm) {
			myUrl = "main/script/checknewaccess.php";
			myRand = parseInt(Math.random()*999999999999999);
			modUrl = myUrl + '?' + myQuery + '&rand=' + myRand;
			http.open("GET",modUrl,true);
			http.onreadystatechange = function() {myAjaxNewAccess(Poption)};
			http.send(null);
		} else {return false;}
	} catch(err4) {alert("Error encountered while attemping to connect\nto URL: " + 
						 myUrl + ".\nError: " + err1.description + "\n\nPlease try again.");
		return false;} 
}

function myAjaxNewAccess(lOption) {
	var myResponseOutput = '';
	try {
		if (http.readyState == 4) {
			if (http.status == 200) {
				myResponseOutput = http.responseText;
				switch (parseInt(myResponseOutput)) {
					case 0:
						if (lOption==1) {
							document.getElementById('loginmess').innerHTML = 'Username already exist.';
							document.formReg.username.focus();return false;
							break;}
						if (lOption==2) {
							document.getElementById('loginmess').innerHTML = 'Password already exist.';
							document.formReg.password.focus();return false;
							break;}
						if (lOption==7) {
							document.getElementById('infomess').innerHTML = 'Invalid email address.';
							document.formReg.emailadd.focus();return false;
							break;}
						if (lOption==9) {
							document.getElementById('activationmess').innerHTML = 'Sponsor code not exist';
							document.formReg.sponsor.focus();return false;
							break;}
						if (lOption==10) {
							document.getElementById('activationmess').innerHTML = 'Registration code not exist.';
							document.formReg.regcode.focus();return false;
							break;}
						if (lOption==11) {
							document.getElementById('activationmess').innerHTML = 'Security code not exist.';
							document.formReg.seccode.focus();return false;
							break;}
					case 1:	
						if (lOption==1) {
							document.getElementById('loginmess').innerHTML = '';
							break;}
						if (lOption==2) {
							document.getElementById('loginmess').innerHTML = '';
							break;}
						if (lOption==7) {
							document.getElementById('infomess').innerHTML = '';
							break;}
						if (lOption==9) {
							document.getElementById('activationmess').innerHTML = '';
							break;}
						if (lOption==10) {
							document.getElementById('activationmess').innerHTML = '';
							break;}
						if (lOption==11) {
							document.getElementById('activationmess').innerHTML = '';
							break;}
				}
			} else {alert("Error while receiving information\nfrom the server freddie.\n\nPlease try again.");}
		}
	}
	catch(err1) {
		alert("Error while receiving information from the server.\n" +
			  "Error Encountered: " + err1.description + "\n\nPlease try again.");
		return false;}

}
