
// preload rollover images images for left menu
if (document.images)
{
	pic1= new Image(168,38); 
	pic1.src= siteurl + 'assets/images/btn_construction_on.gif'; 
	pic2= new Image(168,38); 
	pic2.src= siteurl + 'assets/images/btn_admin_on.gif'; 
	pic3= new Image(168,38); 
	pic3.src= siteurl + 'assets/images/btn_medical_on.gif'; 
	pic4= new Image(168,38); 
	pic4.src= siteurl + 'assets/images/btn_homecare_on.gif'; 
	pic5= new Image(111,20); 
	pic5.src= siteurl + 'assets/images/btn_register_on.gif'; 
	pic6= new Image(111,20); 
	pic6.src= siteurl + 'assets/images/btn_downloads_on.gif';
	pic7= new Image(111,20); 
	pic7.src= siteurl + 'assets/images/btn_cv_on.gif';
	pic8= new Image(111,20); 
	pic8.src= siteurl + 'assets/images/btn_faqs_on.gif';
	pic9= new Image(111,20); 
	pic9.src= siteurl + 'assets/images/btn_news_on.gif';
	pic10= new Image(89,20);
	pic10.src= siteurl + 'assets/images/tp_home_on.png';
	pic11= new Image(89,28);
	pic11.src= siteurl + 'assets/images/tp_contact_on.png';
	pic12= new Image(89,28);
	pic12.src= siteurl + 'assets/images/tp_do_on.png';
	pic13= new Image(89,28);
	pic13.src= siteurl + 'assets/images/tp_employer_on.png';
	pic14= new Image(89,28);
	pic14.src= siteurl + 'assets/images/tp_jobseeker_on.png';
}

function imgOn(imgName)
 {
   if (document.images)
    {
  		document.images[imgName].src = siteurl + 'assets/images/' + imgName + '_on.gif';
    }
 }

function imgOff(imgName)
 {
   if (document.images)
    {
      document.images[imgName].src = siteurl + 'assets/images/' + imgName + '_off.gif';
    }
 }
 
function forceDownload(file)
{
	location.href = siteurl + 'download.php?file=' + encodeURIComponent(file);
}

function isEmail(email) {
    invalidChars = " ~\'^\:\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
        return false;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
}

//function to set the word count field
function setCount(enterobj,counterobj,maxnum){
	var text = document.getElementById(enterobj).value;
	text + text + " ";
	text = SearchAndReplace(text, "  ", " ");
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = text.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var splitString = cleanedStr.split(" ");
	var wordCount = splitString.length -1;
	if (text.length < 1) 
	{
	wordCount = 0;
	}
	if (wordCount > maxnum){
		alert(companyname + ' Alert:\n\nYou have exceeded the allowed wordcount');
	}
	document.getElementById(counterobj).value = wordCount;	
}

//search and replace function
function SearchAndReplace(Content, SearchFor, ReplaceWith) {

   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;

   if (SearchFor.length == 0)
      return;


   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
   
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;

      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;


      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);

   }

   return tmpOutput + tmpContent;

}

function isValidDate(day,month,year)
{
/*
Purpose: return true if the date is valid, false otherwise

Arguments: day integer representing day of month
month integer representing month of year
year integer representing year

Variables: dteDate - date object

*/
var dteDate;

//set up a Date object based on the day, month and year arguments
//javascript months start at 0 (0-11 instead of 1-12)
dteDate=new Date(year,month,day);

/*
Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...
*/

//return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
return true;
}

function validateImg(obj)
{
	if (document.getElementById(obj).value != "")
	{
		var myfile = document.getElementById(obj).value.toLowerCase();
		if((myfile.split(".")[1].indexOf("gif")==-1) && (myfile.split(".")[1].indexOf('jpeg') == -1) && (myfile.split(".")[1].indexOf("jpg")==-1) && (myfile.split(".")[1].indexOf("png")==-1))
		{
 			alert(companyname + ' Alert:\n\nIt appears that the file you wish to upload is not in a correct format (GIF, JPG or PNG)\n\nPlease choose another file.')
 			return false;
		}
	}
	
}

function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}

function favourites(){
if (document.all){
window.external.AddFavorite(window.location.href,document.title)
}
else if (window.sidebar){
	window.sidebar.addPanel(document.title,window.location.href,'')
	}
else if (window.opera && window.print){
	return true;
	}
else {
alert(companyname + ' Alert:\n\nIt appears you are using a browser other than MS Internet Explorer, Netscape 6+ or Opera.\n\nPlease consult your browser\'s online help system for instructions on adding this page to your favourites.');

}
}

function stopNav()
	{
		for (i=0;i<document.links.length;i++)
		{
			if ((document.links[i].href.indexOf('javascript') == -1))
			{
				if (document.links[i].href.indexOf('mailto') == -1)
				{
					document.links[i].href="javascript:alert('" + companyname + " Alert:\\n\\nThis page is for printing only.\\n\\nNavigation has been disabled');";
					document.links[i].target = '';
					document.links[i].title = 'Navigation has been disabled as this page is only intended for printing';
				}
			}
			else
			{
				if (document.links[i].href.indexOf('javascript:__doPostBack') != -1) 
				{
					document.links[i].href="javascript:alert('" + companyname + " Alert:\\n\\nThis page is for printing only.\\n\\nNavigation has been disabled');";
					document.links[i].target = '';
					document.links[i].title = 'Navigation has been disabled as this page is only intended for printing';
				}
			}
		}
		var ar_elements = new Array('select', 'radio', 'text', 'checkbox', 'submit', 'reset', 'button')
		for (i=0; i < document.forms[0].elements.length; i++)
		{
			for (j=0; j < ar_elements.length; j++)
			{
				if (document.forms[0].elements[i].type == ar_elements[j])
				{
					
						document.forms[0].elements[i].disabled = true;
						document.forms[0].elements[i].title = 'This form has been disabled as this page is only intended for printing'
				}
				if (document.forms[0].elements[i].value == "Print")
				{
					document.forms[0].elements[i].disabled = false;
					document.forms[0].elements[i].title = "Print this page"
				}
				if (document.forms[0].elements[i].value == "Close")
				{
					document.forms[0].elements[i].disabled = false;
					document.forms[0].elements[i].title = "Close this page"
				}
			
			}
		}
		
	return false;
	}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function loginCheck()
{
	if (document.frm_login.txt_username.value == "")
	{
		alert(companyname + ' Alert:\n\nYou must enter a username to continue.');
		document.frm_login.txt_username.focus();
		return false;
	}
	else
	{
		if (isEmail(document.frm_login.txt_username.value))
		{
			if (document.frm_login.txt_password.value == "")
			{
				alert(companyname + ' Alert:\n\nYou must enter a password to continue');
				document.frm_login.txt_password.focus();
				return false;
			}
		}
		else
		{
			alert(companyname + ' Alert:\n\nYou must enter a valid email address to continue');	
			document.frm_login.txt_username.focus();
			return false;
		}
	}	
}

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}


var callback;
var req;
function ajaxIt(data,url,async)
{
	url = siteurl + url;
	req = getHTTPObject();
	if (req)
	{
		req.onreadystatechange = processReqChange;
    	req.open("POST", url, async);
    	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(data);
	}
}

function processReqChange()
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			eval(callback + '(req.responseText);');
        }
		else
		{
			//eval(callback + '(There was a problem returning data from the server. The specific error was:<br/><br/>' + req.statusText + ');');
		}
	}
}
function doRefresh()
{
	var sURL = unescape(window.location.pathname);
	window.location.replace( window.location.href );
}

//cookie functions
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}