// ****************************
// * Correct PNG Transparency *
// ****************************
function correctPNG()
{
	if(navigator.userAgent.indexOf("MSIE")!= -1)
	{
		for(var i=0; i<document.images.length; i++)
	    {
			var img = document.images[i]
		  	var imgName = img.src.toUpperCase()
		  		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		     	{
			 		var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 		var imgStyle = "display:inline-block;" + img.style.cssText 
			 			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 			if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle		
			 				var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		     				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 				img.outerHTML = strNewHTML
			 			i = i-1
		     	}
	      }
	  }
}
// Add to window onload method
if (window.addEventListener)      //DOM method for binding an event
	window.addEventListener("load", correctPNG, false)
else if (window.attachEvent)      //IE exclusive method for binding an event
	window.attachEvent("onload", correctPNG)
else if (document.getElementById) //support older modern browsers
	window.onload=correctPNG
// ******* //
// * End * //
// ******* //

// *********************************************** //
// * 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 * //
// ******* //

// ************************************************************* //
// * Open new window function - without toolbars (resizeable ) * //
// ************************************************************* //
var win=null;
function NewWindow2(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=yes';
	win=window.open(mypage,myname,settings);
}
// ******* //
// * 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 * //
// ******* //

// ***************************************************
// * This function validates the Job ID Search form  *
// ***************************************************
function JS_SearchRefJob()
{
	var message = '';	
	vForm       = document.getElementById('frmSearchJobs');
	vJobID      = vForm.JOB_ID.value;
	
	if ((vJobID == '') || (isNaN(vJobID)))
	{
		message += 'Please enter a valid numeric value.\n';
	}
	
	if (message == '')
	{
		// disable all form elements
		document.getElementById('btn_submit').disabled = true;
		return true;
	}
	else
	{
		alert(message);
		return false;
	}
}
// ******* //
// * End * //
// ******* //

// *****************************************************
// * This function validates the Advanced Search form  *
// *****************************************************
function JS_SearchJobs()
{
	vForm        = document.getElementById('frmSearchJobs');
	vFromSalary  = vForm.SALARY_FROM_ID;
	vToSalary    = vForm.SALARY_TO_ID;
	vFromSalary2 = vForm.SALARY_FROM;
	vToSalary2   = vForm.SALARY_TO;
	vKeywords    = vForm.KEYWORDS
	
	var message       = '';	
	var fromSal       = Number.NaN;
	var toSal         = Number.NaN;
		
		// *************************** \\
		// * Validate minimum salary * \\
		// *************************** \\
		if ((vFromSalary.value != '') && (vFromSalary.value != 'Min'))
		{
			fromSal = parseInt(vFromSalary.value);
			if (isNaN(fromSal))
			{
				message += 'Please enter a valid minimum salary.\n';
			}
			else
			{
				vFromSalary.value = fromSal;
				fromSal = parseFloat(fromSal);
				vFromSalary2.value = fromSal;
			}
		}
		// *************************** \\
		// * Validate maximum salary * \\
		// *************************** \\
		if ((vToSalary.value != '') && (vToSalary.value != 'Max'))
		{
			toSal = parseInt(vToSalary.value);
			if (isNaN(toSal))
			{
				message += 'Please enter a valid maximum salary.\n';
			}
			else
			{
				vToSalary.value = toSal;
				toSal = parseFloat(toSal);
				vToSalary2.value = toSal;
			}
		}
		// *************************************************** \\
		// * Minimum salary must be less than maximum salary * \\
		// *************************************************** \\
		if ((!isNaN(fromSal)) && (!isNaN(toSal)))
		{
			if ((fromSal < 0) || (fromSal > toSal))
			{
				message += 'Minimum salary must be less than maximum salary.\n';
				vFromSalary2.value = '0'
				vToSalary2.value = '0'
			}
		}
		// ************************************* \\
		// * Remove extra spaces from KEYWORDS * \\
		// ************************************* \\
		if (typeof vKeywords.value != "string") { return vKeywords.value; }
   			var retValue = vKeywords.value;
   			var ch = retValue.substring(0, 1);
   				while (ch == " ")
				{ // Check for spaces at the beginning of the string
      				retValue = retValue.substring(1, retValue.length);
      				ch = retValue.substring(0, 1);
   				}
   			ch = retValue.substring(retValue.length-1, retValue.length);
   				while (ch == " ")
				{ // Check for spaces at the end of the string
      				retValue = retValue.substring(0, retValue.length-1);
      				ch = retValue.substring(retValue.length-1, retValue.length);
   				}
   				while (retValue.indexOf("  ") != -1)
				{ // Note that there are two spaces in the string - look for multiple spaces within the string
      				retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   				}
			vKeywords.value = retValue; // Return the trimmed string back to the user
		// *************************************************************** \\
		// * Check KEYWORDS for valid characters and no extra AND/OR/NOT * \\
		// *************************************************************** \\
		if (vKeywords.value != '')
		{
			// **************************************************** \\
			// * Check KEYWORDS for valid characters listed above * \\
			// **************************************************** \\
			if ((IsValidChars(vKeywords.value.toUpperCase()) == false))
			{
				message += 'Please enter valid characters in the KEYWORDS field to search.\n';
			}
			// **************************************** \\
			// * Keyword search cannot begin with AND * \\
			// **************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			if (Left(str, 4) == "AND ")
			{
				message += 'Please do not enter AND at the begining of KEYWORDS search.\n';
			}
			// ************************************** \\
			// * Keyword search cannot end with AND * \\
			// ************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			if (Right(str, 4) == " AND")
			{
				message += 'Please do not enter AND at the end of KEYWORDS search.\n';
			}
			// ******************************************************* \\
			// * Restrict to one occurrence of AND in keyword search * \\
			// ******************************************************* \\
			var str = vKeywords.value.toUpperCase(); 
			var ind = 0 
			var found = 0
			if (str != "")
			{
				while (ind != -1) 
				{ 
					ind = str.indexOf(" AND ",ind); 
					if (ind != -1) 
					{ 
						found++; 
						ind++; 
					} 
				}
				if ((found == 0) || (found == 1));
				else
				{
					message += 'Please only enter one AND parameter for KEYWORDS search.\n';
				}
			}
			// *************************************** \\
			// * Keyword search cannot begin with OR * \\
			// *************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			if (Left(str, 3) == "OR ")
			{
				message += 'Please do not enter OR at the begining of KEYWORDS search.\n';
			}
			// ************************************* \\
			// * Keyword search cannot end with OR * \\
			// ************************************* \\
			var str = vKeywords.value.toUpperCase(); 
			if (Right(str, 3) == " OR")
			{
				message += 'Please do not enter OR at the end of KEYWORDS search.\n';
			}
			// ****************************************************** \\
			// * Restrict to one occurrence of OR in keyword search * \\
			// ****************************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			var ind = 0 
			var found = 0
			if (str != "")
			{
				while (ind != -1) 
				{ 
					ind = str.indexOf(" OR ",ind); 
					if (ind != -1) 
					{ 
						found++; 
						ind++; 
					} 
				}
				if ((found == 0) || (found == 1));
				else
				{
					message += 'Please only enter one OR parameter for KEYWORDS search.\n';
				}
			}
			// **************************************** \\
			// * Keyword search cannot begin with NOT * \\
			// **************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			if (Left(str, 4) == "NOT ")
			{
				message += 'Please do not enter NOT at the begining of KEYWORDS search.\n';
			}
			// ************************************** \\
			// * Keyword search cannot end with NOT * \\
			// ************************************** \\
			var str = vKeywords.value.toUpperCase(); 
			if (Right(str, 4) == " NOT")
			{
				message += 'Please do not enter NOT at the end of KEYWORDS search.\n';
			}
			// ******************************************************* \\
			// * Restrict to one occurrence of NOT in keyword search * \\
			// ******************************************************* \\
			var str = vKeywords.value.toUpperCase(); 
			var ind = 0 
			var found = 0
			if (str != "")
			{
				while (ind != -1) 
				{ 
					ind = str.indexOf(" NOT ",ind); 
					if (ind != -1) 
					{ 
						found++; 
						ind++; 
					} 
				}
				if ((found == 0) || (found == 1));
				else
				{
					message += 'Please only enter one NOT parameter for keyword search.\n';
				}
			}
		}
		
		if (message == '')
		{
			// disable all form elements
			document.getElementById('btn_submit').disabled = true;
			return true;
		}
		else
		{
			alert(message);
			return false;
		}
}
// ******* //
// * End * //
// ******* //

// ***************************************************************
// * Function to validate string against valid characters listed *
// ***************************************************************
function IsValidChars(strString)
{
	var strValidChars = "0123456789-'\" ?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   	var strChar;
   	var blnResult = true;
	
	if (strString.length == 0) return false;
   		for (i = 0; i < strString.length && blnResult == true; i++)
      	{
      		strChar = strString.charAt(i);
      			if (strValidChars.indexOf(strChar) == -1)
         		{
         			blnResult = false;
         		}
      	}
   	return blnResult;
}
// ******* //
// * End * //
// ******* //

// ***********************************
// * Function for LEFT in JavaScript *
// ***********************************
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
// ******* //
// * End * //
// ******* //

// ************************************
// * Function for RIGHT in JavaScript *
// ************************************
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// ******* //
// * End * //
// ******* //

// *********************************************
// * Function to allow only NUMERIC keystrokes *
// *********************************************
function giveWarningAndFixValue(field)
{ 
	//removes all non-numeric value and replaces 
	//alert("You can only use whole numeric values. Please don't use comma's."); 
	var value = parseInt(field.value); 
	if(!isNaN(value)) field.value = value; 
	else field.value = ""; 
	//used for NS4.7 because when changing value the cursor is placed in front of the value, instead of behind 
	if(document.layers) field.select(); 
}
// ******* //
// * End * //
// ******* //

// **************************************************
// * Function to check for NUMERIC values in string *
// **************************************************
function isNumericValue(str)
{ 
	var isValid = true; 
	if(str.search(/^[0-9]+$/) == -1)
	{ 
		isValid = false; 
	}
	return isValid;
}
// ******* //
// * End * //
// ******* //

// *********************************************
// * Function to evoke above NUMERIC functions *
// *********************************************
function checkValue(field)
{ 
	if(!isNumericValue(field.value))
	{ 
		giveWarningAndFixValue(field); 
	} 
}
// ******* //
// * End * //
// ******* //

// ********************************************************
// * return the value of the radio button that is checked *
// * return an empty string if none are checked, or       *
// * there are no radio buttons                           *
// ********************************************************
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
// ******* //
// * End * //
// ******* //

// ******************************************
// * Function to set or reset radio buttons *
// ******************************************
function setCheckedValue(radioObj, newValue)
{
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
// ******* //
// * End * //
// ******* //

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
