// Shadowminds

var request = ajaxapp();
var regcount = 0;
var cntcount = 0;
var discount = 0;
var citcount = 0;
var schcount = 0;
var qnacount = 0;
var basura = "T-", tawag = 0 , ngalan = 0, sex = 0;
var buwan = 0, araw = 0, taon = 0;

function CheckData() {
	var problem = 'No';	
	if (document.frm_frm.frm_last.value.length <= 0) {
		alert("Please provide your last name.");
		document.frm_frm.frm_last.value = "Please type here";
		document.frm_frm.frm_last.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_first.value.length <= 0) {
		alert("Please provide your first name.");
		document.frm_frm.frm_first.value = "Please type here";
		document.frm_frm.frm_first.focus();
		problem = 'Yes';		
	} else if (document.frm_frm.frm_pass.value.length <= 0) {
		alert("Please provide your password.");
		document.frm_frm.frm_pass.value = "";
		document.frm_frm.frm_pass.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_pass2.value.length <= 0) {
		alert("Please confirm your password.");
		document.frm_frm.frm_pass2.value = "";
		document.frm_frm.frm_pass2.focus();
		problem = 'Yes';
	} else if(document.frm_frm.frm_pass.value != document.frm_frm.frm_pass2.value) {
		alert("Passwords should be same on both fields");
		document.frm_frm.frm_pass2.value = "";
		document.frm_frm.frm_pass.value = "";
		document.frm_frm.frm_pass.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_region.value == 0) {
		alert("Please choose your Region.");
		document.frm_frm.frm_region.options[0].selected = "selected";
		document.frm_frm.frm_region.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_cntry0.value < 0) {
		alert("Please choose your Country");
		document.frm_frm.frm_cntry0.options[0].selected = "selected";
		document.frm_frm.frm_cntry0.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_cit0.value < 0) {
		alert("Please choose your City");
		document.frm_frm.frm_cit0.options[0].selected = "selected";
		document.frm_frm.frm_cit0.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_sch0.value < 0) {
		alert("Please choose your School");
		document.frm_frm.frm_sch0.options[0].selected = "selected";
		document.frm_frm.frm_sch0.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_email.value.length <= 0) {
		alert("Please provide your email address.");
		document.frm_frm.frm_email.value = "Please type here";
		document.frm_frm.frm_email.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_email2.value.length <= 0) {
		alert("Please confirm your email address.");
		document.frm_frm.frm_email2.value = "Please type here";
		document.frm_frm.frm_email2.focus();
		problem = 'Yes';
	} else if(document.frm_frm.frm_email.value != document.frm_frm.frm_email2.value) {
		alert("Email addresses should be same on both fields");
		document.frm_frm.frm_email2.value = "";
		document.frm_frm.frm_email.value = "Please type here";
		document.frm_frm.frm_email.focus();
		problem = 'Yes';
	} else if(document.frm_frm.frm_sex[0].checked != true && document.frm_frm.frm_sex[1].checked != true) {
		alert("Please choose your sex/gender");
		document.frm_frm.frm_sex[0].focus();
		problem = 'Yes';		
	} else if (document.frm_frm.frm_qanda.value < 0) {
		alert("Please choose your Security Question.");
		document.frm_frm.frm_qanda.options[0].selected = "selected";
		document.frm_frm.frm_qanda.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_ans.value.length <= 0) {
		alert("Please provide Answer to Question.");
		document.frm_frm.frm_ans.value = "Please type here";
		document.frm_frm.frm_ans.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_captcha.value.length != 4) {
		alert("Please provide 4 Letters from Image.");
		document.frm_frm.frm_captcha.value = "Please type here";
		document.frm_frm.frm_captcha.focus();
		problem = 'Yes';
	} else if (document.frm_frm.frm_read.checked == false) {
		alert("Please read and agree to the Terms of Service and Privacy Policy.");
    	document.frm_frm.frm_read.focus();
		problem = 'Yes';
	}
	
	if(problem == 'No') {
		if (document.frm_frm.frm_title.value <= 5 && document.frm_frm.frm_title.value >= 0) {
			ngalan = parseInt(document.frm_frm.frm_title.value);
		} else { ngalan = 0; }    basura = basura+ngalan+"-"; ///////////////////////
		if (document.frm_frm.frm_tag[0].checked) {
			tawag = 1;
		} else if(document.frm_frm.frm_tag[1].checked) {
			tawag = 2;
		} else if(document.frm_frm.frm_tag[2].checked) {
			tawag = 3;
		} else if(document.frm_frm.frm_tag[3].checked) {
			tawag = 4;
		} else { tawag = 0; }    basura = basura+tawag+"-"; ///////////////////////
		
		if (document.frm_frm.frm_month.value <= 12 && document.frm_frm.frm_month.value >= 0) {
			buwan = parseInt(document.frm_frm.frm_month.value);
		} else { buwan = 0; }    basura = basura+buwan+"-"; ///////////////////////
		
		if (document.frm_frm.frm_date.value <= 31 && document.frm_frm.frm_date.value >= 0) {
			araw = parseInt(document.frm_frm.frm_date.value);
		} else { araw = 0; }     basura = basura+araw+"-"; ///////////////////////

		if (document.frm_frm.frm_year.value.length == 4) {
			if(isNaN(parseInt(document.frm_frm.frm_year.value))) {
				taon = '0000';	  
			} else {
				taon = parseInt(document.frm_frm.frm_year.value);
			}
		} else { taon = '0000'; }  basura = basura+taon+"-"; ///////////////////////
	
		if (document.frm_frm.frm_cbday.checked == false) {
			basura = basura+0+"-"; ///////////////////////
		} else { basura = basura+1+"-"; } ///////////////////////

		basura = basura+document.frm_frm.frm_captcha.value+"-";
		basura = basura+document.frm_frm.frm_region.value+"-"+document.frm_frm.frm_cntry0.value+"-"+document.frm_frm.frm_dis0.value+"-"+document.frm_frm.frm_cit0.value+"-"+document.frm_frm.frm_sch0.value+"-";
		document.frm_frm.frm_basura.value = basura+document.frm_frm.frm_captcha.value;
		basura = ""; regcount = 0; cntcount = 0; discount = 0; citcount = 0; schcount = 0;
		return true;
	} else {
		return false;
	}
}

////////////////////////////////////////// country
function showcntry(txt) {  // region menu action
     var txt = 0+txt;
	 if(txt >= 0) {
	 	var url = "reg.php?region="+txt;
	     request.open("GET", url, true);
	     request.onreadystatechange = function () { mparser("cntry"); }  //drawcntry;
	     request.send(null);
		 regcount = txt;
	 } else {
	 	regcount = 0;
	 }
	
	document.getElementById('divdistrict').style.display = "none";      // hide the district menu and input box
	document.getElementById('dvcntry0').style.display = "inline";       // default show the country menu
	document.getElementById('dvcntry1').style.display = "none";         // default hide the country input
	document.getElementById('dvcity0').style.display = "inline";       // default show the city menu
	document.getElementById('dvcity1').style.display = "none";         // default hide the city input
	document.getElementById('dvschool0').style.display = "inline";       // default show the school menu
	document.getElementById('dvschool1').style.display = "none";         // default hide the school input
	
	with(document.forms['frm_frm']) { // clear input boxes values set to default
		frm_cntry.value = "Please type here.";
		frm_dis.value = "Please type here.";
		frm_cit.value ="Please type here.";
		frm_sch.value ="Please type here.";
	}
	reset_dis();reset_cit();reset_sch();
}

function showdist(txt) {  // country menu action
     var txt = 0+txt;
	var list = document.forms['frm_frm'].frm_cntry0;
	var listItemText = list.options[list.selectedIndex].text;
	if(txt == 0 && listItemText == 'Other, please specify') {
		document.getElementById('dvcntry1').style.display = "inline"; // textbox -- country dvcntry0
		document.getElementById('dvcntry0').style.display = "none";   // menubox -- country dvcntry1
		document.getElementById('dvcity0').style.display = "none";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "inline"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "inline"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "none";   // menubox -- school dvcntry1
		reset_dis();reset_cit();reset_sch();
	} else if(txt > 0) {
	 	var url = "reg.php?bansa="+txt;
	     request.open("GET", url, true);
	     request.onreadystatechange = function () { mparser("dis"); }  //drawdis;
	     request.send(null);
		 cntcount = txt;
		document.getElementById('dvcntry1').style.display = "none"; // textbox -- country dvcntry0
		document.getElementById('dvcntry0').style.display = "inline";   // menubox -- country dvcntry1
		document.getElementById('dvcity0').style.display = "inline";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "none"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "none"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "inline";   // menubox -- school dvcntry1
	 } else {
	 	cntcount = 0;
	 }

	with(document.forms['frm_frm']) { // clear input boxes values set to default
		frm_dis.value = "Please type here.";
		frm_cit.value ="Please type here.";
		frm_sch.value ="Please type here.";
	}

	if(txt == 83) { 
		document.getElementById('divdistrict').style.display = "block"; // div district block
		reset_cit();reset_sch();
	} else if(txt != 83 && txt >= 0) {
		document.getElementById('divdistrict').style.display = "none";  // div district block
		showcit0(cntcount);reset_dis();reset_sch();
	}
	
}
function showcit0(txt) {  
    var txt = 0+txt;	
	if(txt != 83 && txt >0) {
	 	var url = "reg.php?bansa="+txt+"&distrito=0"; //alert(url);
		var request2 = ajaxapp();
		request2.open("GET", url, true);
	    request2.onreadystatechange = function () { 
		if (request2.readyState == 4) {
		if (request2.status == 200) {
			// Parsing RSS
			var node = request2.responseXML.documentElement; 
			var objlength = node.getElementsByTagName('mpamagat').length;
			var objvals = node.getElementsByTagName('mpamagat');
			var objname = node.getElementsByTagName('mbigkis');
			var objpop = document.getElementById('frm_cit0');
			while(objpop.firstChild) {
				objpop.removeChild(objpop.firstChild);
			}		
			for(var i = 0; i < objlength; i++) {
				var objli = document.createElement('option');
				objli.setAttribute('value',objvals[i].firstChild.data);
				var objtxt= document.createTextNode(objname[i].firstChild.data);
				objli.appendChild(objtxt);
				objpop.appendChild(objli);
			}
		} else if (request2.status == 404) {
			alert ("Requested URL is not found.");
		} else if (request2.status == 403) {
			alert("Access denied.");
		} else {
			alert("status is " + request2.status + ": Error, please try again.");
		}
    }
		 }
	     request2.send(null);	
	 }
}
function showcit(txt) {  // district menu action
     var txt = 0+txt;
	var list = document.forms['frm_frm'].frm_cntry0;
	var listItemText = list.options[list.selectedIndex].text;
	if(txt == 0 && listItemText == 'Other, please specify') {
		document.getElementById('dvcity0').style.display = "none";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "inline"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "inline"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "none";   // menubox -- school dvcntry1
		reset_dis();reset_cit();reset_sch();
	} else if(txt > 0) {
	 	var url = "reg.php?bansa="+cntcount+"&distrito="+txt;
	     request.open("GET", url, true);
	     request.onreadystatechange = function () { mparser("cit"); }
	     request.send(null);
		 discount = txt;
		document.getElementById('dvcity0').style.display = "inline";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "none"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "none"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "inline";   // menubox -- school dvcntry1
	 } else {
	 	discount = 0;
	 }
	 
	with(document.forms['frm_frm']) { // clear input boxes values set to default
		frm_dis.value = "Please type here.";
		frm_cit.value ="Please type here.";
		frm_sch.value ="Please type here.";
	}
}

function showsch(txt) {  // city menu action
     var txt = 0+txt;
	 var list = document.forms['frm_frm'].frm_cit0;
	var listItemText = list.options[list.selectedIndex].text;
	if(txt == 0 && listItemText == 'Other, please specify') {
		document.getElementById('dvcity0').style.display = "none";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "inline"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "inline"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "none";   // menubox -- school dvcntry1
		reset_cit();reset_sch();
	} else if(txt > 0) {
	 	var url = "reg.php?sitio="+txt;
	     request.open("GET", url, true);
	     request.onreadystatechange = function () { mparser("sch"); }
	     request.send(null);
		 citcount = txt;
		document.getElementById('dvcity0').style.display = "inline";   // menubox -- city dvcntry1
		document.getElementById('dvcity1').style.display = "none"; // textbox -- city dvcntry0
		document.getElementById('dvschool1').style.display = "none"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "inline";   // menubox -- school dvcntry1
	 } else {
	 	citcount = 0;
	 }
}

function showsch0(txt) {  // school menu action
     var txt = 0+txt;
	 var list = document.forms['frm_frm'].frm_sch0;
	var listItemText = list.options[list.selectedIndex].text;
	if(txt == 0 && listItemText == 'Other, please specify') {
		document.getElementById('dvschool1').style.display = "inline"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "none";   // menubox -- school dvcntry1
		reset_sch();
	} else if(txt > 0) {
		 schcount = txt;
		document.getElementById('dvschool1').style.display = "none"; // textbox -- school dvcntry0
		document.getElementById('dvschool0').style.display = "inline";   // menubox -- school dvcntry1
	 } else {
	 	schcount = 0;
	 }
}
function reset_cit() {
	var objpop = document.getElementById("frm_cit0");
	while(objpop.firstChild) {
		objpop.removeChild(objpop.firstChild);
	}
	var objli = document.createElement('option');
	objli.setAttribute('value',0);
	var objtxt= document.createTextNode('Criteria based above');
	objli.appendChild(objtxt);
	objpop.appendChild(objli);
}
function reset_sch() {
	var objpop = document.getElementById("frm_sch0");
	while(objpop.firstChild) {
		objpop.removeChild(objpop.firstChild);
	}
	var objli = document.createElement('option');
	objli.setAttribute('value',0);
	var objtxt= document.createTextNode('Criteria based above');
	objli.appendChild(objtxt);
	objpop.appendChild(objli);
}
function reset_dis() {
	var objpop = document.getElementById("frm_dis0");
	while(objpop.firstChild) {
		objpop.removeChild(objpop.firstChild);
	}
	var objli = document.createElement('option');
	objli.setAttribute('value',0);
	var objtxt= document.createTextNode('Criteria based above');
	objli.appendChild(objtxt);
	objpop.appendChild(objli);
}
function mparser(procedure) {
	if (request.readyState == 4) {
		if (request.status == 200) {
			// Parsing RSS
			var node = request.responseXML.documentElement; 
			var objlength = node.getElementsByTagName('mpamagat').length;
			var objvals = node.getElementsByTagName('mpamagat');
			var objname = node.getElementsByTagName('mbigkis');
			var objpop = document.getElementById('frm_'+procedure+'0');
			while(objpop.firstChild) {
				objpop.removeChild(objpop.firstChild);
			}		
			for(var i = 0; i < objlength; i++) {
				var objli = document.createElement('option');
				objli.setAttribute('value',objvals[i].firstChild.data);
				var objtxt= document.createTextNode(objname[i].firstChild.data);
				objli.appendChild(objtxt);
				objpop.appendChild(objli);
			}
		} else if (request.status == 404) {
			alert ("Requested URL is not found.");
		} else if (request.status == 403) {
			alert("Access denied.");
		} else {
			alert("status is " + request.status + ": Error, please try again.");
		}
    }
}

function getTopPos(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
	}
function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
	}
function ajaxapp() {
var request = false;	
	try {
		request = new XMLHttpRequest(); isMos = true;
	} 
	catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");isIE = true;
		} 
		catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");isIE = true;
			} 
			catch (failed) {
				request = false;
			}
		}
	}
	if (!request) {
		alert("Error initializing XMLHttpRequest!");
	}
	return request;
}

function clearforms() {
	with(document.forms['frm_frm']) {
		frm_cntry.value = "Please type here.";
		frm_dis.value = "Please type here.";
		frm_cit.value ="Please type here.";
		frm_sch.value ="Please type here.";
	}
}
function showqna(txt) {  // school menu action
     var txt = 0+txt;
	 var list = document.forms['frm_frm'].frm_qanda;
	var listItemText = list.options[list.selectedIndex].text;
	if(txt == 0 && listItemText == '[Make your own]') {
		document.getElementById('dvqna1').style.display = "inline"; // textbox -- school dvcntry0
		document.getElementById('dvqna0').style.display = "none";   // menubox -- school dvcntry1
		document.forms['frm_frm'].frm_qna.value = "Please type here.";
	} else if(txt > 0) {
		 qnacount = txt;
		document.getElementById('dvqna1').style.display = "none"; // textbox -- school dvcntry0
		document.getElementById('dvqna0').style.display = "inline";   // menubox -- school dvcntry1
	 } else {
	 	qnacount = 0;
	 }
}
