// reflow page for correct cross-browser footer positioning

function reflow() {
    var bodydiv = document.getElementById("body");
    if (bodydiv != null) {
        bodydiv.style.minHeight = "100%";
    }
}



// workaround for absence of target attributes in xhtml strict

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}



// equalize heights of left/right floated divs
// add 20 (px) to compensate for bottom padding

/*
Derived from a script by Alejandro Gervasio.
Modified to work in FireFox by Stefan Mischook for Killersites.com

How it works: just apply the CSS class of 'column' to your pages' main columns.
*/
matchColumns=function(){

     var divs,contDivs,maxHeight,divHeight,d;

     // get all <div> elements in the document
     divs=document.getElementsByTagName('div');
     contDivs=[];

     // initialize maximum height value
     maxHeight=0;

     // iterate over all <div> elements in the document
     for(var i=0;i<divs.length;i++){

          // make collection with <div> elements with class attribute 'container'
          if(/\bcolumn\b/.test(divs[i].className)){
                d=divs[i];
                contDivs[contDivs.length]=d;

                // determine height for <div> element
                if(d.offsetHeight){
                     divHeight=d.offsetHeight;
                }

                else if(d.style.pixelHeight){
                     divHeight=d.style.pixelHeight;
                }

                // calculate maximum height
                maxHeight=Math.max(maxHeight,divHeight);
          }
     }

     // assign maximum height value to all of container <div> elements
     for(var i=0;i<contDivs.length;i++){
          contDivs[i].style.height=(maxHeight) + "px";
     }
}



function toggle(id) {
   var item = document.getElementById(id);

   if (item.style.display == "block")
      item.style.display = "none";
   else
      item.style.display = "block";
}



http = getHTTPObject();

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;
}

function validateAjax(){
  var url = "../script.php?admUsername=" + document.getElementById('admUsername').value;
  url += "&admEmail=" + document.getElementById('admEmail').value;
  //url += "&url=" + document.getElementById('url').value;

  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;

  http.send(null);
  //document.getElementById('loading').style.display = 'block';
}

function handleHttpResponseOld() {
	if (http.readyState == 4 && http.status == 200) {
		//document.getElementById('loading').style.display = 'none';
		document.getElementById('test').innerHTML = http.responseText;
		//if (http.responseText.indexOf('Error') == -1)
		//document.getElementById('text_select').style.display = 'block';
	}
}

function changeSearchSel(sel) {
	var selID = sel.id;
	var selIndex = sel.selectedIndex;
	var selValue = sel.options[selIndex].value;

	var aSel = new Array('jobName','jobCompany','countryID','yearsID','academicID');
	var currSel = '';
	var url = 'ajax.php?';
	var aUrlVars = new Array('selID=' + selID, 'selValue=' + selValue);

	for (var i = 0; i < aSel.length; i++) {
		currSel = document.getElementById(aSel[i]);
		if (currSel.value != '') {
			aUrlVars[aUrlVars.length] = aSel[i] + '=' + currSel.value;
		}
	}

	url += aUrlVars.join('&');
	//alert(url);

	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

function handleHttpResponse() {
	if (http.readyState == 4 && http.status == 200) {
		var xmlDoc = http.responseXML;
		var aSel = xmlDoc.getElementsByTagName('select');
		var currSel = '';

		for (var i = 0; i < aSel.length; i++) {
			//alert(aSel[i].childNodes[0].childNodes[0].textContent);
			currSel = document.getElementById(aSel[i].childNodes[0].childNodes[0].textContent);
			for (var k = currSel.length-1; k >= 0; k--) {
				currSel.options[k] = null;
			}

			currSel.options[currSel.length] = new Option('Select one', '');

			for (var j = 1; j < aSel[i].childNodes.length; j++) {
				//alert(aSel[i].childNodes[j].childNodes[0].textContent + ':' + aSel[i].childNodes[j].childNodes[1].textContent);
				currSel.options[currSel.length] = new Option(aSel[i].childNodes[j].childNodes[1].textContent, aSel[i].childNodes[j].childNodes[0].textContent);
			}
		}
	}
}



function validateAdmins() {
	var aMsg = new Array();
	var aMandatory = new Array('admUsername','admPassword','admEmail','admFirstName','admLastName');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	var fUsername = document.getElementById('admUsername');
	var sUsername = fUsername.value;
	if (sUsername != '' && (sUsername.length < 4 || sUsername.length > 16)) {
		aMsg[aMsg.length] = 'Username should be between 4 to 16 characters';
		highlightLabel(fUsername.previousSibling);
	}

	var fPassword = document.getElementById('admPassword');
	var sPassword = fPassword.value;
	if (sPassword != '' && (sPassword.length < 8 || sPassword.length > 32)) {
		aMsg[aMsg.length] = 'Password should be between 8 to 32 characters';
		highlightLabel(fPassword.previousSibling);
	}

	var fEmail = document.getElementById('admEmail');
	var sEmail = fEmail.value;
	if (sEmail != '' && sEmail.length > 255) {
		aMsg[aMsg.length] = 'Email should be less than 255 characters';
		highlightLabel(fEmail.previousSibling);
	}
	else if (sEmail != '' && !validateEmail(sEmail)) {
		aMsg[aMsg.length] = 'Email is invalid';
		highlightLabel(fEmail.previousSibling);
	}

	var fFirstName = document.getElementById('admFirstName');
	var sFirstName = fFirstName.value;
	if (sFirstName != '' && sFirstName.length > 64) {
		aMsg[aMsg.length] = 'First name should be less than 64 characters';
		highlightLabel(fFirstName.previousSibling);
	}

	var fLastName = document.getElementById('admLastName');
	var sLastName = fLastName.value;
	if (sLastName != '' && sLastName.length > 64) {
		aMsg[aMsg.length] = 'Last name should be less than 64 characters';
		highlightLabel(fLastName.previousSibling);
	}

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateNews() {
	var aMsg = new Array();
	var aMandatory = new Array('newsText');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateJobs() {
	var aMsg = new Array();
	var aMandatory = new Array('jobName','jobCompany','countryID','yearsID','academicID','jobStatusID','jobCategoryID');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	var fName = document.getElementById('jobName');
	var sName = fName.value;
	if (sName != '' && sName.length > 64) {
		aMsg[aMsg.length] = 'Job Title should be less than 64 characters';
		highlightLabel(fName.previousSibling);
	}

	var fCompany = document.getElementById('jobCompany');
	var sCompany = fCompany.value;
	if (sCompany != '' && sCompany.length > 64) {
		aMsg[aMsg.length] = 'Company Name should be less than 64 characters';
		highlightLabel(fCompany.previousSibling);
	}

	var fStartYear = document.getElementById('jobStartYear');
	var fStartMonth = document.getElementById('jobStartMonth');
	var fStartDay = document.getElementById('jobStartDay');
	var dStart = new Date(fStartYear.value, fStartMonth.value, fStartDay.value, 0,0,0,0);

	var fEndYear = document.getElementById('jobEndYear');
	var fEndMonth = document.getElementById('jobEndMonth');
	var fEndDay = document.getElementById('jobEndDay');
	var dEnd = new Date(fEndYear.value, fEndMonth.value, fEndDay.value, 0,0,0,0);

	if (Date.parse(dStart) > Date.parse(dEnd)) {
		aMsg[aMsg.length] = 'Period End should be after Period Start';
		highlightLabel(fEndDay.previousSibling);
	}

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateUsers(type) {
	var aMsg = new Array();
	if (type == 'all')
		var aMandatory = new Array('userEmail','userPassword1','userPassword2','userFirstName','userLastName','userPriAdd','countryID','userCity','userMobileNo','jobCategoryID','userHistory','relocateID');
	else if (type == 'nopw')
		var aMandatory = new Array('userEmail','userFirstName','userLastName','userPriAdd','countryID','userCity','userMobileNo','jobCategoryID','userHistory','relocateID');
	else
		var aMandatory = new Array('userFirstName','userLastName','userPriAdd','countryID','userCity','userMobileNo','jobCategoryID','userHistory','relocateID');
	var aMandSelMul = new Array('activityID','disciplineID','positionID','langWrittenID','langSpokenID','skillID');
	var aSelMul = new Array('activityID','disciplineID','positionID','expatID','langWrittenID','langSpokenID','skillID','standardID');
	var bMissing = false;
	var currField = '';

	resetLabels();

	var fCvFilename = document.getElementById('userCvFilename');
	var sCvFilename = fCvFilename.value;
	if (type == 'cv' || type == 'nopw') {
		var fCvFilenamePrev = document.getElementById('userCvFilenamePrev');
		var sCvFilenamePrev = fCvFilenamePrev.value;
		if (sCvFilename == '')
			sCvFilename = sCvFilenamePrev;
	}
	if (sCvFilename != '') {
		// if cv is uploaded, other fields are no longer mandatory (except email and password)
		if (type == 'all')
			aMandatory = new Array('userEmail','userPassword1','userPassword2');
		else if (type == 'nopw')
			aMandatory = new Array('userEmail');
		else
			aMandatory = new Array();
		aMandSelMul = new Array();

		if (!validateDocPdfExt(sCvFilename)) {
			aMsg[aMsg.length] = 'CV to be uploaded should be a doc, docx, or pdf file';
			highlightLabel(fCvFilename.previousSibling);
		}
	}

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	for (var i = 0; i < aMandSelMul.length; i++) {
		currField = document.getElementById(aMandSelMul[i]);
		if (currField.options.length == 0) {
			bMissing = true;
			highlightLabel(currField.parentNode.firstChild);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (type == 'all' || type == 'nopw') {
		var fEmail = document.getElementById('userEmail');
		var sEmail = fEmail.value;
		if (sEmail != '' && sEmail.length > 255) {
			aMsg[aMsg.length] = 'Email should be less than 255 characters';
			highlightLabel(fEmail.previousSibling);
		}
		else if (sEmail != '' && !validateEmail(sEmail)) {
			aMsg[aMsg.length] = 'Email is invalid';
			highlightLabel(fEmail.previousSibling);
		}

		var fPassword1 = document.getElementById('userPassword1');
		var sPassword1 = fPassword1.value;
		if (sPassword1 != '' && (sPassword1.length < 8 || sPassword1.length > 32)) {
			aMsg[aMsg.length] = 'Password should be between 8 to 32 characters';
			highlightLabel(fPassword1.previousSibling);
		}

		var fPassword2 = document.getElementById('userPassword2');
		var sPassword2 = fPassword2.value;
		if (sPassword2 != sPassword1) {
			aMsg[aMsg.length] = 'Passwords do not match';
			highlightLabel(fPassword2.previousSibling);
		}
	}

	var fFirstName = document.getElementById('userFirstName');
	var sFirstName = fFirstName.value;
	if (sFirstName != '' && sFirstName.length > 64) {
		aMsg[aMsg.length] = 'First Name should be less than 64 characters';
		highlightLabel(fFirstName.previousSibling);
	}

	var fMidName = document.getElementById('userMidName');
	var sMidName = fMidName.value;
	if (sMidName != '' && sMidName.length > 64) {
		aMsg[aMsg.length] = 'Middle Name(s) should be less than 64 characters';
		highlightLabel(fMidName.previousSibling);
	}

	var fLastName = document.getElementById('userLastName');
	var sLastName = fLastName.value;
	if (sLastName != '' && sLastName.length > 64) {
		aMsg[aMsg.length] = 'Last Name should be less than 64 characters';
		highlightLabel(fLastName.previousSibling);
	}

	var fImg = document.getElementById('userImg');
	var sImg = fImg.value;
	if (sImg != '' && !validateImgExt(sImg)) {
		aMsg[aMsg.length] = 'Photo to be uploaded should be an image file';
		highlightLabel(fImg.previousSibling);
	}

	var fFamDepend = document.getElementById('userFamDepend');
	var sFamDepend = fFamDepend.value;
	if (sFamDepend != '' && sFamDepend.length > 4) {
		aMsg[aMsg.length] = 'Number of Family Dependents should be less than 4 digits';
		highlightLabel(fFamDepend.previousSibling);
	}
	else if (sFamDepend != '' && !validateNumber(sFamDepend)) {
		aMsg[aMsg.length] = 'Number of Family Dependents should contain only numbers';
		highlightLabel(fFamDepend.previousSibling);
	}

	var fPriAdd = document.getElementById('userPriAdd');
	var sPriAdd = fPriAdd.value;
	if (sPriAdd != '' && sPriAdd.length > 255) {
		aMsg[aMsg.length] = 'Primary Address should be less than 255 characters';
		highlightLabel(fPriAdd.previousSibling);
	}

	var fSecAdd = document.getElementById('userSecAdd');
	var sSecAdd = fSecAdd.value;
	if (sSecAdd != '' && sSecAdd.length > 255) {
		aMsg[aMsg.length] = 'Secondary Address should be less than 255 characters';
		highlightLabel(fSecAdd.previousSibling);
	}

	var fCity = document.getElementById('userCity');
	var sCity = fCity.value;
	if (sCity != '' && sCity.length > 64) {
		aMsg[aMsg.length] = 'City should be less than 64 characters';
		highlightLabel(fCity.previousSibling);
	}

	var fState = document.getElementById('userState');
	var sState = fState.value;
	if (sState != '' && sState.length > 64) {
		aMsg[aMsg.length] = 'State / Province should be less than 64 characters';
		highlightLabel(fState.previousSibling);
	}

	var fZipCode = document.getElementById('userZipCode');
	var sZipCode = fZipCode.value;
	if (sZipCode != '' && sZipCode.length > 16) {
		aMsg[aMsg.length] = 'Zip / Postal Code should be less than 16 characters';
		highlightLabel(fZipCode.previousSibling);
	}

	var fMobileNo = document.getElementById('userMobileNo');
	var sMobileNo = fMobileNo.value;
	if (sMobileNo != '' && sMobileNo.length > 16) {
		aMsg[aMsg.length] = 'Mobile Phone should be less than 16 characters';
		highlightLabel(fMobileNo.previousSibling);
	}

	var fHomeNo = document.getElementById('userHomeNo');
	var sHomeNo = fHomeNo.value;
	if (sHomeNo != '' && sHomeNo.length > 16) {
		aMsg[aMsg.length] = 'Home Phone should be less than 16 characters';
		highlightLabel(fHomeNo.previousSibling);
	}

	var fOfficeNo = document.getElementById('userOfficeNo');
	var sOfficeNo = fOfficeNo.value;
	if (sOfficeNo != '' && sOfficeNo.length > 16) {
		aMsg[aMsg.length] = 'Office Phone should be less than 16 characters';
		highlightLabel(fOfficeNo.previousSibling);
	}

	var fLastJob = document.getElementById('userLastJob');
	var sLastJob = fLastJob.value;
	if (sLastJob != '' && sLastJob.length > 64) {
		aMsg[aMsg.length] = 'Title of Current / Last Position should be less than 64 characters';
		highlightLabel(fLastJob.previousSibling);
	}

	var fLastCompany = document.getElementById('userLastCompany');
	var sLastCompany = fLastCompany.value;
	if (sLastCompany != '' && sLastCompany.length > 64) {
		aMsg[aMsg.length] = 'Name of Current / Last Company should be less than 64 characters';
		highlightLabel(fLastCompany.previousSibling);
	}

	var fJobOthers = document.getElementById('userJobOthers');
	var sJobOthers = fJobOthers.value;
	if (sJobOthers != '' && sJobOthers.length > 255) {
		aMsg[aMsg.length] = 'Others should be less than 255 characters';
		highlightLabel(fJobOthers.previousSibling);
	}

	var fCurrSalary = document.getElementById('userCurrSalary');
	var sCurrSalary = fCurrSalary.value;
	if (sCurrSalary != '' && sCurrSalary.length > 16) {
		aMsg[aMsg.length] = 'Current Net Salary should be less than 16 characters';
		highlightLabel(fCurrSalary.previousSibling);
	}

	var fBenefits = document.getElementById('userBenefits');
	var sBenefits = fBenefits.value;
	if (sBenefits != '' && sBenefits.length > 255) {
		aMsg[aMsg.length] = 'Benefits & Facilities should be less than 255 characters';
		highlightLabel(fBenefits.previousSibling);
	}

	var fExpSalary = document.getElementById('userExpSalary');
	var sExpSalary = fExpSalary.value;
	if (sExpSalary != '' && sExpSalary.length > 16) {
		aMsg[aMsg.length] = 'Expected Net Salary should be less than 16 characters';
		highlightLabel(fExpSalary.previousSibling);
	}

	var fDetails = document.getElementById('userDetails');
	var sDetails = fDetails.value;
	if (sDetails != '' && sDetails.length > 255) {
		aMsg[aMsg.length] = 'Please provide details should be less than 255 characters';
		highlightLabel(fDetails.previousSibling);
	}

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else {
		//for selects with multiple options, select all
		for (var i = 0; i < aSelMul.length; i++) {
			var fSelMul = document.getElementById(aSelMul[i]);
			for (var j = 0; j < fSelMul.options.length; j++) {
				fSelMul.options[j].selected = true;
			}
		}
		return true;
	}
}



function validateLoginInfo() {
	var aMsg = new Array();
	var aMandatory = new Array('userEmail','userPassword1','userPassword2');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	var fEmail = document.getElementById('userEmail');
	var sEmail = fEmail.value;
	if (sEmail != '' && sEmail.length > 255) {
		aMsg[aMsg.length] = 'Email should be less than 255 characters';
		highlightLabel(fEmail.previousSibling);
	}
	else if (sEmail != '' && !validateEmail(sEmail)) {
		aMsg[aMsg.length] = 'Email is invalid';
		highlightLabel(fEmail.previousSibling);
	}

	var fPassword1 = document.getElementById('userPassword1');
	var sPassword1 = fPassword1.value;
	if (sPassword1 != '' && (sPassword1.length < 8 || sPassword1.length > 32)) {
		aMsg[aMsg.length] = 'Password should be between 8 to 32 characters';
		highlightLabel(fPassword1.previousSibling);
	}

	var fPassword2 = document.getElementById('userPassword2');
	var sPassword2 = fPassword2.value;
	if (sPassword2 != sPassword1) {
		aMsg[aMsg.length] = 'Passwords do not match';
		highlightLabel(fPassword2.previousSibling);
	}

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateLogin() {
	var aMsg = new Array();
	var aMandatory = new Array('userEmail','userPassword');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateForgotPW() {
	var aMsg = new Array();
	var aMandatory = new Array('userEmail');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateTellAFriend() {
	var aMsg = new Array();
	var aMandatory = new Array('tafFriendName','tafFriendEmail');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	var fEmail = document.getElementById('tafFriendEmail');
	var sEmail = fEmail.value;
	if (sEmail != '' && !validateEmail(sEmail)) {
		aMsg[aMsg.length] = 'Email is invalid';
		highlightLabel(fEmail.previousSibling);
	}

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateInteractions() {
	var aMsg = new Array();
	var aMandatory = new Array('intComments');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateAppStatus() {
	var aMsg = new Array();
	var aMandatory = new Array('appStatusID');
	var bMissing = false;
	var currField = '';

	resetLabels();

	for (var i = 0; i < aMandatory.length; i++) {
		currField = document.getElementById(aMandatory[i]);
		if (currField.value == '') {
			bMissing = true;
			highlightLabel(currField.previousSibling);
		}
	}
	if (bMissing)
		aMsg[aMsg.length] = 'Please fill in all mandatory fields';

	if (aMsg.length > 0) {
		alert(aMsg.join('\n'));
		return false;
	}
	else
		return true;
}



function validateEmail(email) {
	var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (regex.test(email))
		return true;
	else
		return false;
}

function validateDocPdfExt(filename) {
	var dotIndex = filename.lastIndexOf('.');
	var extension = '';

	if (dotIndex != -1) {
		extension = filename.substring(dotIndex+1);
		extension = extension.toLowerCase();
		if (extension == 'doc' || extension == 'docx' || extension == 'pdf')
			return true;
		else
			return false;
	}
	else
		return false;
}

function validateImgExt(filename) {
	var dotIndex = filename.lastIndexOf('.');
	var extension = '';

	if (dotIndex != -1) {
		extension = filename.substring(dotIndex+1);
		extension = extension.toLowerCase();
		if (extension == 'jpg' || extension == 'jpeg' || extension == 'gif' || extension == 'png')
			return true;
		else
			return false;
	}
	else
		return false;
}

function validateNumber(txt) {
	var regex = /^\d+$/;

	if (regex.test(txt))
		return true;
	else
		return false;
}



function resetLabels() {
	var labels = document.getElementsByTagName('label');
	var currLabel = '';

	for (var i = 0; i < labels.length; i++) {
		currLabel = labels[i];
		currLabel.style.color = '';
	}
}

function highlightLabel(label) {
	if (label.nodeName.toLowerCase() == 'label') {
		label.style.color = 'red';
	}
}



function addOption(fromID, toID) {
	var fromSel = document.getElementById(fromID);
	var toSel = document.getElementById(toID);
	var selIndex = fromSel.selectedIndex;
	var selText = fromSel.options[selIndex].text;
	var selValue = fromSel.options[selIndex].value;
	var bExists = false;

	for (var i = 0; i < toSel.length; i++) {
		if (toSel.options[i].value == selValue)
			bExists = true;
	}

	if (!bExists && selValue != '')
		toSel.options[toSel.length] = new Option(selText, selValue);
	else if (bExists)
		alert('This option has already been added');
	else
		alert('Please select an option to add');
}

function add2Option(fromID1, fromID2, toID) {
	var fromSel1 = document.getElementById(fromID1);
	var fromSel2 = document.getElementById(fromID2);
	var toSel = document.getElementById(toID);
	var selIndex1 = fromSel1.selectedIndex;
	var selText1 = fromSel1.options[selIndex1].text;
	var selValue1 = fromSel1.options[selIndex1].value;
	var selIndex2 = fromSel2.selectedIndex;
	var selText2 = fromSel2.options[selIndex2].text;
	var selValue2 = fromSel2.options[selIndex2].value;
	var bExists = false;

	for (var i = 0; i < toSel.length; i++) {
		var values = toSel.options[i].value.split('|');
		if (values[0] == selValue1)
			bExists = true;
	}

	if (!bExists && selValue1 != '' && selValue2 != '')
		toSel.options[toSel.length] = new Option(selText1+', '+selText2, selValue1+'|'+selValue2);
	else if (selValue1 == '' || selValue2 == '')
		alert('Please select an option to add');
	else
		alert('This option has already been added');
}

function delOption(fromID) {
	var fromSel = document.getElementById(fromID);

	for (var i = fromSel.length-1; i >= 0; i--) {
		if (fromSel.options[i].selected)
			fromSel.options[i] = null;
	}
}



function setDiscSel(value) {
	var discSel = document.getElementById('disciplineSel');
	discSel.options.length = null;
	discSel.options[discSel.length] = new Option('Select one', '');

	if (value != '') {
		for (var i = 0; i < activities[value].length; i++) {
			if (activities[value][i] != null) {
				discSel.options[discSel.length] = new Option(activities[value][i][0], i);
				//alert('text: ' + activities[value][i][0] + ' and value: ' + i);
			}
		}
	}
}

function setPosSel(value) {
	var posSel = document.getElementById('positionSel');
	posSel.options.length = null;
	posSel.options[posSel.length] = new Option('Select one', '');

	if (value != '') {
		for (var i = 0; i < activities.length; i++) {
			if (activities[i] != null && activities[i][value] != null) {
				for (var j = 1; j < activities[i][value].length; j++) {
					if (activities[i][value][j] != null) {
						posSel.options[posSel.length] = new Option(activities[i][value][j], j);
						//alert('text: ' + activities[i][value][j] + ' and value: ' + j);
					}
				}
			}
		}
	}
}



/***********************************************
* Pausing up-down scroller- (c) 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
}



/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1
var menu_profile=new Array()
menu_profile[0]='<a href="profile_oilgas.php">Oil, Gas &amp; Petrochemicals</a>'
menu_profile[1]='<a href="profile_services.php">Our Services</a>'
menu_profile[2]='<a href="profile_search.php">Our Search, Selection &amp; Recruitment</a>'
menu_profile[3]='<a href="profile_vision.php">Our Vision, Mission &amp; Core Values</a>'
menu_profile[4]='<a href="profile_management.php">Meet Our Management</a>'
menu_profile[5]='<a href="profile_download.php" class="download">Download Brochure</a>'

var menu_search=new Array()
menu_search[0]='<a href="search_oilgas.php">Oil, Gas &amp; Petrochemicals</a>'
menu_search[1]='<a href="search_civil.php">Civil Construction Projects</a>'

var menu_clients=new Array()
menu_clients[0]='<a href="clients.php">Our Clients</a>'
menu_clients[1]='<a href="partners.php">Our Partners</a>'

var menuwidth='210px' //default menu width
var menubgcolor=''  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="no" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu



/***********************************************
* Ultimate Fade-In Slideshow (v1.51): © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var home_banner=new Array()
home_banner[0]=["pics/home_oilgas.jpg", "profile_oilgas.php", ""]
home_banner[1]=["pics/home_civil.jpg", "profile_civil.php", ""]

var fadebgcolor="white"

////NO need to edit beyond here/////////////

var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers

var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all

function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}

var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2

if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')

if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=2
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}

fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}


fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}

fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}


fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}



// run all necessary functions on page load

function loadAll() {
   //reflow();
   externalLinks();
   matchColumns();
}
window.onload = loadAll;