// JavaScript Document
var checkobj;

function agreesubmit(el)
{
	checkobj=el;
	if (document.all||document.getElementById)
	{
		for (i=0;i<checkobj.form.length;i++)
		{  //hunt down submit button
			var tempobj=checkobj.form.elements[i];
			if(tempobj.type.toLowerCase()=="submit")
			{
				tempobj.disabled=!checkobj.checked;
			}
		}
	}
}

function defaultagree(el)
{
	if (!document.all&&!document.getElementById)
	{
		if (window.checkobj&&checkobj.checked)
		return true;
		else
		{
			alert("Please read/accept terms to submit form");
			return false;
		}
	}
	if (document.enableform.box.value == "")
	{
		alert("Please enter a value in the " + document.enableform.box.title);
		return false;
	}
	if (document.enableform.box2.value == "")
	{
		alert("Please enter a value in the " + document.enableform.box2.title);
		return false;
	}
}

/***** CUSTOMIZE THESE VARIABLES *****/

  // width to resize large images to
var maxWidth=100;
  // height to resize large images to
var maxHeight=100;
  // valid file types
var fileTypes=["jpg","jpeg"];
  // the id of the preview image tag
var outImage="previewField";
  // what to display when the image is not valid
var defaultPic="http://admissions.xsignia.com/images/spacer.gif";

/***** DO NOT EDIT BELOW *****/

function preview(what){
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) globalPic.src=source;
  else {
    globalPic.src=defaultPic;
    alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  }
  setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}

function goToForm(formType,mode)
{	
	location.href="http://admissions.xsignia.com/screening/registrationform.php?form="+formType+"&mode="+mode;
}

function login()
{
	for (i=0;i<document.form1.elements.length;i++)
	{
		if (document.form1.elements[i].value=="")
		{
			alert("Please supply your " + document.form1.elements[i].title);
			return false;
		}
		continue;
	}
	return true;
}

function validformA()
{
	for (i=0;i<document.form1.elements.length;i++)
	{
		if ((document.form1.elements[i].value=="")&&(document.form1.elements[i].name!="middlename"))
		{
			alert("Please supply your " + document.form1.elements[i].title);
			return false;
		}
		continue;
	}
	if((document.form1.regNum.value.length < 10)||(document.form1.regNum.value.length > 11))
	{
		alert("Please supply a valid " + document.form1.regNum.title);
		return false;
	}
	return true;
}

function validformB()
{
	if(document.form1.course1.value=="")
	{
		alert("Please select your desired course of study ("+document.form1.course1.title+").");
		return false;
	}
	if(document.form1.course2.value=="")
	{
		alert("Please select your desired course of study ("+document.form1.course2.title+").");
		return false;
	}
	if(document.form1.mode.value=="ume")
	{
		if((document.form1.jScore.value=="")||((document.form1.jScore.value<200)||(document.form1.jScore.value>400)))
		{
			alert("Please enter a valid "+document.form1.jScore.title);
			return false;
		}
		//makes sure jamb score is numeric
		var re = /[0-9]+/;
		var input = document.form1.jScore.value;
		var matchArray = re.exec(input);
		if (!matchArray)
		{
			alert(document.form1.jScore.value + " is not a valid "+document.form1.jScore.title);
			return false;
		}
	}
	if(document.form1.examType1.value=="")
	{
		alert("Please select exam type of your 1st Sitting O'level examination.");
		return false;
	}
	if(document.form1.examNum1.value=="")
	{
		alert("Please supply exam number of your 1st Sitting O'level examination.");
		return false;
	}
	if(document.form1.examYear1.value=="")
	{
		alert("Please select exam year of your 1st Sitting O'level examination.");
		return false;
	}
	//1st sitting
	counterA=0;
	for(i=1;i<=5;i++)
	{
		subjectField = document.getElementById("examSubA"+i);
		gradeField = document.getElementById("examGradeA"+i);
		
		if((subjectField.value!="")&&(gradeField.value!=""))
		{
			counterA++;
		}
	}
	//2nd sitting
	counterB=0;
	for(i=1;i<=5;i++)
	{
		subjectField = document.getElementById("examSubB"+i);
		gradeField = document.getElementById("examGradeB"+i);
		
		if((subjectField.value!="")&&(gradeField.value!=""))
		{
			counterB++;
		}
	}
	
	if((counterA+counterB) > 5)
	{
		alert("Select only '5' best (DISTINCT) relevant subjects, with respective grades.");
		return false;
	}
	else if((counterA+counterB) < 5)
	{
		alert("Please select '5' best (DISTINCT) relevant subjects, with respective grades.");
		return false;
	}
	
	if(counterB>0)
	{
		if(document.form1.examType2.value=="")
		{
			alert("Please select exam type of your 2nd Sitting O'level examination.");
			return false;
		}
		if(document.form1.examNum2.value=="")
		{
			alert("Please supply exam number of your 2nd Sitting O'level examination.");
			return false;
		}
		if(document.form1.examYear2.value=="")
		{
			alert("Please select exam year of your 2nd Sitting O'level examination.");
			return false;
		}
	}
	return true;
}
function validformC()
{
	for (i=0;i<document.form1.elements.length;i++)
	{
		if (document.form1.elements[i].value=="")
		{
			alert("Please supply your " + document.form1.elements[i].title);
			return false;
		}
		continue;
	}
	var re = /[0-9]+/;
	var input = document.form1.phoneNum.value;
	var matchArray = re.exec(input);
	if (!matchArray)
	{
		alert(document.form1.phoneNum.value + " is not a valid "+document.form1.phoneNum.title);
		return false;
	}
	var re = /^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
	var input = document.form1.email.value;
	var matchArray = re.exec(input);
	if (!matchArray)
	{
		alert(document.form1.email.value + " is not a valid email addy");
		return false;
	}
	return true;
}