/*Function that Returns windows width and height*/
function windowSize(dir) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (dir == 'x') return myWidth;
  else return myHeight;
}
/*End Function*/


// JavaScript Document
function buildGrid(){
	//set grid parameters
	var jobFunction = encodeURIComponent(document.getElementById('lstJobF').value); 
	var jobLocation = encodeURIComponent(document.getElementById('lstJobL').value);
	var jobDivision = encodeURIComponent(document.getElementById('lstJobD').value);
	
	var maxGridHeight = 700 + 'px';
	mygrid = new dhtmlXGridObject('gridbox');
	
	mygrid.setImagePath("images/");
	var flds = "Job Code,Job Title,Location,Division,Function,Date Posted";
	mygrid.setHeader(flds);
	mygrid.enableAlterCss('oddrow','evenrow');
	totWidth = "10,25,15,15,20,18.4";
	totWidth = "64,140,120,100,95,78";
	strWidth = totWidth

	mygrid.setInitWidths(strWidth);
	mygrid.setColAlign("center,left,left,left,left,left");
	mygrid.setColTypes("ro,ro,ro,ro,ro,ro");
	mygrid.setColSorting("str,str,str,str,str,str");
	mygrid.setSerializableColumns("false,false,false,false,false,false");
	mygrid.enableAutoHeigth(true,maxGridHeight);
	mygrid.setScrollbarWidthCorrection(17);
	mygrid.setOnLoadingEnd(hideLoad); 
	mygrid.rowsBufferOutSize = 0;
	mygrid.setMultiLine(true);
	mygrid.enableMultiselect(false);
	mygrid.setOnLoadingStart(showLoad);
	mygrid.enableTooltips('true,false,true,true,true,true');
	mygrid.init();
	mygrid.loadXML("index.cfm?event=popsearchresult&jobf="+jobFunction+"&jobl="+jobLocation+"&jobd="+jobDivision+"&nocache=" + Math.floor(Math.random()*100001));
}
function filterJob(){
	var jobFunction = encodeURIComponent(document.getElementById('lstJobF').value); 
	var jobLocation = encodeURIComponent(document.getElementById('lstJobL').value);
	var jobDivision = encodeURIComponent(document.getElementById('lstJobD').value);
	
	mygrid.clearAll(); 
	mygrid.setOnLoadingStart(showLoad);
	mygrid.loadXML("index.cfm?event=popsearchresult&jobf="+jobFunction+"&jobl="+jobLocation+"&jobd="+jobDivision+"&nocache=" + Math.floor(Math.random()*100001));
}
function showLoad(){
	showLoading('loading');
}
function hideLoad(){
	hideLoading('','loading');
}

//check for valid numeric strings	
function checkPhoneNumber(strString){
   var strValidChars = "0123456789 -+()";
   var strChar;
   var blnResult = true;
   //  test strString consists of valid characters listed above
   for (j = 0; j < strString.length && blnResult == true; j++)
	  {
	  strChar = strString.charAt(j);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
 }
 
 //check for valid email address
 function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
	var tempStr = "a";
	var tempReg = new RegExp(tempStr);
	if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

 // Function to validate form fields  
 function validateApplicantDetails(){ 
	 if(Trim(document.getElementById('txtFName').value) == ''){ 
	 alert(invoke_alert('JS0000'));
	 document.getElementById('txtFName').focus();
	 return;	 
	 }
	  else if(Trim(document.getElementById('txtLName').value) == ''){ 
	 alert(invoke_alert('JS0001'));
	 document.getElementById('txtLName').focus();	
	 return; 
	 }
	 else if(Trim(document.getElementById('txtEmail').value) == ''){ 
	  alert(invoke_alert('JS0002'));
	 document.getElementById('txtEmail').focus();	
	 return; 
	 }
	 else if(!isEmail(Trim(document.getElementById('txtEmail').value))){ 
	  alert(invoke_alert('JS0011'));
	 document.getElementById('txtEmail').focus();	
	 return; 
	 }	
	 else if(Trim(document.getElementById('txtAddr1').value) == ''){ 
	 alert(invoke_alert('JS0008'));
	 document.getElementById('txtAddr1').focus();	 
	 return;	 
	 }	 
	 else if(Trim(document.getElementById('txtCity').value) == ''){ 
	 alert(invoke_alert('JS0003'));
	 document.getElementById('txtCity').focus();
	  return; 	 
	 }	 
	 else if(Trim(document.getElementById('txtState').value) == ''){ 
	 alert(invoke_alert('JS0009'));
	 document.getElementById('txtState').focus();	 
	 return;	 
	 }
	 else if(Trim(document.getElementById('txtCountry').value) == ''){ 
	 alert(invoke_alert('JS0010'));
	 document.getElementById('txtCountry').focus();	 
	 return;	 
	 }	 
	 else if(Trim(document.getElementById('txtPhone').value) == ''){ 
	 alert(invoke_alert('JS0004'));
	 document.getElementById('txtPhone').focus();	 
	 return;	 
	 }
	 else if(!checkPhoneNumber(Trim(document.getElementById('txtPhone').value))){ 
	  alert(invoke_alert('JS0005'));
	 document.getElementById('txtPhone').focus();	 
	 return;
	 }
	 else if(Trim(document.getElementById('txtAttachResume').value) == ''){ 
	 alert(invoke_alert('JS0006'));
	 document.getElementById('txtAttachResume').focus();	 
	 return;
	 } 
	 else {
			var filetypearray = new Array("pdf","PDF","doc","DOC","txt","TXT","docx","DOCX");
			if(TestFileType(document.getElementById("txtAttachResume").value, filetypearray)){
				document.frmApplicationForm.submit();
			}
			else{
				alert(invoke_alert('JS0007'));
				document.getElementById("txtAttachResume").focus();
				return;
			}
			
	 }
	  
 }	
// Function to check type of uploaded file
function TestFileType( fileName, fileTypes ) {
if (!fileName) return;	
dots = fileName.split(".")
//get the part AFTER the LAST period.
fileType = dots[dots.length-1];
return (fileTypes.join(".").indexOf(fileType) != -1) ? 1 : 0;
}
