
function QS(Fm){
var kw = Fm.Keyword.value;
if (kw==null || kw=='' || kw=='Job title or skills..'){
	Fm.Keyword.value='Job title or skills..';
	sendMessage('Before submitting..','Please enter job title or skills. \n',50); 
	return false;
}
Fm.submit();
}

function processStringJS(inputStr){

if (inputStr.indexOf('\n')==-1){inputStr+='\n';}

var outputStr='';
var stringArray = inputStr.split('\n');

var bTabPresent=0, bLastTabPresent=0, iDWidth=0;

if (stringArray.length > 0){

	var tmpStr, spacePos = 0, baseStr;
	var substringArray = new Array(9);

	for(var i=0; i<stringArray.length-1; i++){
	baseStr = Trim(stringArray[i]);

	bLastTabPresent=bTabPresent;

	bTabPresent=0;

	if (baseStr.indexOf('\t')>=0 && baseStr.indexOf('\t')<4){
		bTabPresent=1;
		iDWidth=50;}
	else{
		iDWidth=70;}
	
	if (baseStr != null && baseStr != ''){
		if (baseStr.length <= iDWidth){
		   outputStr = outputStr + '\n' + baseStr;
		}
		else{
			for (var j=0; j<substringArray.length; j++){
			if (baseStr.charCodeAt(iDWidth)==32){
				tmpStr = getLeft(baseStr, iDWidth);
				spacePos = iDWidth;
				substringArray[j] = tmpStr;
			}
			else{
				if (baseStr.length<iDWidth){
				tmpStr = baseStr;
				baseStr = '';
				spacePos = 0;
				substringArray[j] = tmpStr;
				}
				else{
				tmpStr = getLeft(baseStr, iDWidth);
				spacePos = tmpStr.lastIndexOf(' ');
				substringArray[j] = getLeft(tmpStr, spacePos);
				}
			}

			baseStr = Trim(baseStr);	
			baseStr = Trim(getRight(baseStr, baseStr.length-spacePos));
			}
		} 

		for (var j=0; j<substringArray.length; j++){
		if (substringArray[j] != null && substringArray[j].length > 0)
			if (j>0){
				
				outputStr = outputStr + '\n' ;
				if (bTabPresent==1){outputStr = outputStr + '\t ';}
				outputStr = outputStr + substringArray[j];
			}
			else{
				
				outputStr = outputStr + '\n' + substringArray[j];
			}
		}
		
		tmpStr = '';
		baseStr = '';
		spacePos = 0;	
		substringArray = null;
		substringArray	=	new Array(9);
	}
    }  
    
	outputStr = outputStr + '\n';
	return outputStr;
 }
 else{
	            
	outputStr = inputStr + '\n';
	return outputStr;
}
}

function getLeft(str, n){
if (n <= 0)
    return '';
else if (n > String(str).length)
    return str;
else
    return String(str).substring(0,n);
}

function getRight(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);
}
}

function LTrim(str){
if(str==null){return null;}
for(var i=0;str.charAt(i)==' ';i++);
return str.substring(i,str.length);
}

function RTrim(str){
if(str==null){return null;}
for(var i=str.length-1;str.charAt(i)==' ';i--);
return str.substring(0,i+1);
}

function Trim(str){return RTrim(LTrim(str));}


function sendMessage (title, out, width){

width=50;

var divide = '';
for (i = 0; i < width; i++){divide += '_';}

if (out.length > width){out = processStringJS(out);}

var top = title + '\n' + divide + '\n';

if (out.indexOf('\n')>4){out='\n' + out;}

var bottom = divide + '\n\nClick OK to continue. \n';

alert (top + out + bottom);
return;
}

function emailCheck(emailStr){
var filter  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;

if (filter.test(emailStr)){return 0;}
return -1;
}


function BodyOnLoad(){
var Fid=0, Eid=0;
	

for (Fid=0; Fid <  window.document.forms.length; Fid++){
	
	for (Eid=0; Eid < window.document.forms[Fid].length; Eid++)
	{
		
		el=window.document.forms[Fid].elements[Eid];
		if (el.type=="select-multiple" && el.options.selectedIndex!=-1){el.options[el.options.selectedIndex].selected = true;}
	}
}
}

function writeFlash(iw, ih, ifile){
document.write('<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="'+iw+'" HEIGHT="'+ih+'"  codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0" VIEWASTEXT id=ShockwaveFlash1>');
document.write('<PARAM NAME="allowScriptAccess" VALUE="sameDomain" />');
document.write('<PARAM NAME="movie" VALUE="'+ifile+'">');
document.write('<PARAM NAME="play" VALUE="true">');
document.write('<PARAM NAME="loop" VALUE="true">');
document.write('<PARAM NAME="quality" VALUE="high">');
document.write('<PARAM NAME="wmode" VALUE="transparent">');
document.write('<EMBED WIDTH="'+iw+'" HEIGHT="'+ih+'" src="'+ifile+'" allowScriptAccess="sameDomain" PLAY="true" LOOP="true" QUALITY="high" WMODE="transparent" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"><\/EMBED>');
document.write('<\/OBJECT>');
}

function setVisibility(id, visibility) {
var obj=findObj(id);
if (visibility!=null){
obj.style.display = visibility;}
else{
	if (obj.style.display=='none'){
		obj.style.display = 'block';}
	else {
		obj.style.display = 'none';}
}
}


function IsPhone(thefield){
var checkOK = "0123456789)(+- ", checkStr = thefield, allValid = true;
for (i = 0;  i<checkStr.length;  i++){
	ch = checkStr.charAt(i);
	for (j = 0;  j< checkOK.length;  j++)
		if (ch == checkOK.charAt(j)){break;}
		if (j == checkOK.length){
		allValid = false;
		break;
		}
	}

if (!allValid)
	return false;
return true;
}

function y2k(number){return (number < 1000) ? number + 1900 : number;}

function getDateToday_dd_mm_yyyy(){
var today= new Date(), day=0, month=0, year=0, todayStr;
day= today.getDate();
if (day<10)day='0' + day;
month= today.getMonth()+1;
if (month<10)month='0' + month;
year= today.getFullYear();
todayStr= day + '/' + month + '/' + year;

return todayStr;
}

function getDaysElapsed(dt1,dt2) {

if (dt1==null || dt1==''){
	return '';
}
else if (dt2==null || dt2==''){
	return '';
}

var date1 = new Date(dt1.substring(6,10), dt1.substring(3,5)-1, dt1.substring(0,2));
var date2 = new Date(dt2.substring(6,10), dt2.substring(3,5)-1, dt2.substring(0,2));

var difference =
    Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0)
  - Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0);

if (isNaN(difference))
	return '';
else if ((difference/1000/60/60/24)<0)
	return (difference/1000/60/60/24);
else
	return (difference/1000/60/60/24)+1;
}

function getNextDate(dt1,days) {

if (dt1==null || dt1=='')
	return '';
else if (days=='')
	return '';
else if (days!='' && days==0)
	return '';

days = days-1;

var date1 = new Date(dt1.substring(6,10), dt1.substring(3,5)-1, dt1.substring(0,2));
var theDate = new Date(date1.getTime() + days * 24 * 60 * 60 * 1000);

var theday, theMonth, theYear;

theDay = theDate.getDate()
if (theDay<10)
{
theDay="0"+theDay
}
theMonth = theDate.getMonth()+1
if (theMonth<10)
{
theMonth="0"+theMonth
}
theYear = theDate.getFullYear()
theDate = (theDay + "/" + theMonth + "/" +theYear)
return theDate;
}
			
function checkdate(fieldname, fieldvalue, mode){
var dateStr = fieldvalue;
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); 
var outparam = "";
if (matchArray == null){
	outparam = "Please enter " + fieldname + " in following formats: dd/mm/yyyy or dd-mm-yyyy.";
	return outparam;
}

day = matchArray[1]; 
month = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12){ 
	outparam = fieldname + "- month must be between 1 and 12.";
	return outparam;
}
if (day < 1 || day > 31){
	outparam= fieldname + "- day must be between 1 and 31.";
	return outparam;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31){
	outparam = fieldname + "- month "+month+" doesn't have 31 days!";
	return outparam;
}
if (month == 2){ 
	
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)){
		outparam= fieldname + " - February " + year + " doesn't have " + day + " days!";
		return outparam;
	}
}
if (mode!=0){
	
	var d = new Date();
	var mn = (d.getMonth() + 1);
	var dt = d.getDate();
	var yr = d.getYear();		
	if (mode==1) 
	{
		var dateflag = 0;
		var nextmn = (d.getMonth() + 2);
			
		if (day<dt && month<=mn && year<=yr) {dateflag=-1;}
		else if (day>dt && month<=mn && year<yr) {dateflag=-1;}
		else if (day==dt && month<=mn && year<yr) {dateflag=-1;}
		
		if (day>=dt && month>=nextmn && year==yr) { dateflag=1; }
		if (dateflag==-1){
			outparam = fieldname + " should not be a date from the past.";
			return outparam;
		}
		else if (dateflag==1){
			outparam = fieldname + " should not be beyond one month from current date.";
			return outparam;
		}	
	}
}
return outparam;
}


function confirmDelete(title, label, mode, width){
var out = "", divide = "";
for (i = 0; i < width; i++){divide += "_";}
out += (mode==0)?"This action will permanently delete this " + label + ". Are you sure?\n":"";
out += (mode==1)?"" + label + " \n":"";
if (out.length > 50){out = processStringJS(out);}
var top = title + "\n" + divide + "\n";
var bottom = divide + "\n\n Click OK to continue.\n";
return confirm(top + out + bottom);
}

function setAction(sAction){
var frmSubmit = document.forms['frmUserAccounts'];
frmSubmit.action.value = sAction;
}

function textCounter(field, countfield, maxlimit, fieldlabel, bValidate){

	var fValue=field.value;
	var fLen=fValue.length
	if (fLen > maxlimit && bValidate){
		var sALMsg;
		sALMsg='The ' + fieldlabel + ' text must be ' + maxlimit + ' characters or less.\n\nThe text you have entered is ' + fLen + ' characters and will be \ntruncated.';
		sendMessage ('Before continuing...', sALMsg, 50);
		field.value = fValue.substring(0, maxlimit);
		fLen = maxlimit;
	}
	countfield.value=fLen;

/*
	if(field.setSelectionRange)
	{
		field.focus();
		field.setSelectionRange(fLen,fLen)
	}
	else if (field.createTextRange) {
		var range = field.createTextRange();
		range.collapse(true);
		range.moveEnd('character', fLen);
		range.moveStart('character', fLen);
		range.select();
	}
*/	
	return true;
 }
 
 // fieldname, warningname, remainingname, maxchars
function textCounterSpan(field, countfield, maxlimit, fieldlabel, bValidate) {
  var len = field.value.length;
  if (len > maxlimit && bValidate) {
	var sALMsg;
	sALMsg='The ' + fieldlabel + ' text must be ' + maxlimit + ' characters or less.\n\nThe text you have entered is ' + len + ' characters and will be \ntruncated.';
	sendMessage ('Before continuing...', sALMsg, 50);
    field.value = field.value.substring(0,maxlimit);
    len = maxlimit;
  }
  document.getElementById(countfield).innerHTML = len;
}
 
