// *********************************************** //
// * Open new window function - without toolbars * //
// *********************************************** //
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * End * //
// ******* //

// ******************************************** //
// * Open new window function - with toolbars * //
// ******************************************** //
var win=null;
function NewWindow1(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=yes,toolbar=yes,resizable=yes';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * End * //
// ******* //

// ************************************************ //
// * Update various registration forms validation * //
// ************************************************ //
function JS_Registration()
{
	document.getElementById("Btn_Frm_Registration_Back").disabled = true;
	document.getElementById("Btn_Frm_Registration_Submit").disabled = true;
	document.body.style.cursor = "wait";
}
// ******* //
// * End * //
// ******* //

// ************************************ //
// * Registered Candidate Application * //
// ************************************ //
function JS_Apply(JobID)
{
	// Check if External URL
	if (document.getElementById("External_Application").value != "")
	{
		NewWindow1(document.getElementById("External_Application").value,'Application','800','600','yes','center');
	}
	else
	{
		return (true);
	}
}
// ******* //
// * End * //
// ******* //

// ************************************* //
// * Quick Application form validation * //
// ************************************* //
function JS_Application(JobID)
{
	var error = "";
	// Required
	if (document.getElementById("Title").value == "")
	{
		error += "* Please select your Title   \n";
	}
	if (document.getElementById("Name_First").value == "")
	{
		error += "* Please enter your First Name   \n";
	}
	if (document.getElementById("Name_Last").value == "")
	{
		error += "* Please enter your Last Name   \n";
	}
	if (document.getElementById("Email").value == "")
	{
		error += "* Please enter your E-mail address   \n";
	}
	if ((document.getElementById("Email").value.indexOf ('@',0) == -1 ||
		document.getElementById("Email").value.indexOf ('.',0) == -1) &&
		document.getElementById("Email").value != "")
	{
		error += "* You must include your accurate E-mail address   \n";
		document.getElementById("Email").select();
	}
	if ((document.getElementById("Eligibility").checked == false) && (document.getElementById("Non_Eligibility").checked == false))
	{
		error += "* Please select your Work Eligibility option   \n";
	}
	// Check if required
	if (document.getElementById("External_Application").value == "")
	{
		if (document.getElementById("CVFile").value == "")
		{
			error += "* Please locate and upload your CV file   \n";
		}
		if ((document.getElementById("CVFile").value.toLowerCase().indexOf ('.doc',0) == -1) && document.getElementById("CVFile").value != "")
		{
			error += "* Please only upload a valid MS Word CV file   \n";
		}
	}
	if (error != "")
	{
		alert(error);
		return (false);
	}
	else
	{
		// Check if External URL
		if (document.getElementById("External_Application").value != "")
		{
			NewWindow1(document.getElementById("External_Application").value,'Application','800','600','yes','center');
		}
		else
		{
			//return (true);
			ShowProgress();
		}
	}
}
// ******* //
// * End * //
// ******* //

// ************************* //
// * Login form validation * //
// ************************* //
function JS_Login()
{
	var error = "";
	
	if (document.getElementById("Login").value == "")
	{
		error += "* Please enter your E-mail address   \n";
	}
	if ((document.getElementById("Login").value.indexOf ('@',0) == -1 ||
		document.getElementById("Login").value.indexOf ('.',0) == -1) &&
		document.getElementById("Login").value != "")
	{
		error += "* You must include your accurate E-mail address   \n";
		document.getElementById("Login").select();
	}
	if (document.getElementById("Password").value == "")
	{
		error += "* Please enter your Password   \n";
	}
	if (error != "")
	{
		alert(error);
		return (false);
	}
	else
	{
		return (true);
	}
}
// ******* //
// * End * //
// ******* //

// ************************************** //
// * Forgotten Password form validation * //
// ************************************** //
function JS_ForgottenPassword()
{
	document.getElementById("Btn_ForgottenPassword_Submit").disabled = true;
	document.body.style.cursor = "wait";
}
// ******* //
// * End * //
// ******* //

// ******************************************* //
// * Update various profile forms validation * //
// ******************************************* //
function JS_UpdateProfile()
{
	document.getElementById("Btn_Frm_UpdateProfile_Cancel").disabled = true;
	document.getElementById("Btn_Frm_UpdateProfile_Submit").disabled = true;
	document.body.style.cursor = "wait";
}
// ******* //
// * End * //
// ******* //

// ************************ //
// * Ipod form validation * //
// ************************ //
function JS_Ipod()
{
	var error = "";
	
	if (document.getElementById("Name").value == "")
	{
		error += "* Please fill in your Name   \n";
	}
	if (document.getElementById("Email").value == "")
	{
		error += "* Please fill in your E-mail address   \n\n";
	}
	if ((document.getElementById("Email").value.indexOf ('@',0) == -1 ||
		document.getElementById("Email").value.indexOf ('.',0) == -1) &&
		document.getElementById("Email").value != "")
	{
		error += "* You must include your accurate E-mail address   \n\n";
	}  
	if (error != "")
	{
		alert(error);
		return (false);
	}
	else
	{
		return (true);
	}
}
// ******* //
// * End * //
// ******* //

// ********************************* //
// * E-mail Friend form validation * //
// ********************************* //
function JS_EmailFriend()
{
	var error = "";
	
	if (document.getElementById("friendsname").value == "")
	{
		error += "* Please fill in the recipient's Name   \n";
	}
	if (document.getElementById("friendsemail").value == "")
	{
		error += "* Please fill in the recipient's E-mail address   \n\n";
	}
	if ((document.getElementById("friendsemail").value.indexOf ('@',0) == -1 ||
		document.getElementById("friendsemail").value.indexOf ('.',0) == -1) &&
		document.getElementById("friendsemail").value != "")
	{
		error += "* You must include the recipient's accurate E-mail address   \n\n";
	} 
	if (document.getElementById("name").value == "")
	{
		error += "* Please fill in your Name   \n";
	} 
	if (document.getElementById("email").value == "")
	{
		error += "* Please fill in your E-mail address   \n";
	}
	if ((document.getElementById("email").value.indexOf ('@',0) == -1 ||
		document.getElementById("email").value.indexOf ('.',0) == -1) &&
		document.getElementById("email").value != "")
	{
		error += "* You must include your accurate E-mail address   ";
	} 
	if (error != "")
	{
		alert(error);
		return (false);
	}
	else
	{
		return (true);
	}
}
// ******* //
// * End * //
// ******* //


// CLIENT + ADMIN - This function changes the table row colour according when a checkbox is selected
function getRow(strTabNum){ 
  var el = event.srcElement 
  var rowIdx = 0 
  var tbl = null 
  var oRow = null 
   
   if (el.tagName =="INPUT"){ 
       rowIdx = el.parentElement.parentElement.rowIndex 
       tbl = document.getElementById('Table'+strTabNum) 
       oRow = tbl.rows[rowIdx] 
       if (eval(el.getAttribute("checked"))){ 
         colorCells(oRow, "#A4C1D9") // or whatever color 
       } 
       else{ 
         colorCells(oRow, "#E9E7E3") 
       } 
   } 
} 
function colorCells(oRow, color){ 
  var cell = null 
  for(x=0;x<oRow.cells.length;x++){ 
      cell = oRow.cells[x] 
      cell.bgColor = color 
  } 
}
// End checkbox script

// CLIENT + ADMIN - This function checks if a checkbox is selected before submiting
function checkBox(deleter) {
       
   var checkboxChecked = false;
       
   for (var i=0, j=deleter.elements.length; i<j; i++) {
       myType = deleter.elements[i].type;
       
       if (myType == 'checkbox') {
           if (deleter.elements[i].checked) checkboxChecked = true;
       }
   }

   if (!checkboxChecked)
   	{
       alert('* You must select at least one job record to delete   ');
	   return false;
	}
   		else
	{
   		//return true;
		//If checkbox(es) is selected send confirmation to delete
		sendConfirmation();
		return false;
	}
}

function sendConfirmation()
{
	if (confirm('Are you sure you want to delete the selected job(s)?'))
	{
	deleter.submit();
 	}
}
// End checkbox validation script

// ADMIN - This function confirms before submiting the Jobs Notify email
function sendMailConfirmation(sendMailer)
{
	if (confirm('Are you sure you want to send the Jobs Notify mail?'))
	{
  	sendMailer.submit();
 	}
	else
	{
	return false;
	}
}
// End Jobs Notify email confirmation

//load page in parent via popup window
function loadinparent(url, closeSelf)
{
	self.opener.location = url;
	if(closeSelf) self.close();
}
//end load page in parent via popup window