/////////////////////////////////////////////////////////////////////
// Reference this file as '/inc/jsfuncs.asp' in code
// add version to ISAPI rule when changing this script
// version: 25
/////////////////////////////////////////////////////////////////////
function getSpellCheckArray() {
	//language="English (GB)"
	var fieldsToCheck = new Array();
	// make sure to enclose form/field object reference in quotes!
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].jobtitle';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].candidate';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill1';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill2';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill3';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill4';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill5';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill6';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill7';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill8';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill9';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].skill10';
	fieldsToCheck[fieldsToCheck.length]='document.forms["form"].employerdesc';
	return fieldsToCheck;
}

function cjPopUp(url,name)
	{
	var x = (screen.width/2) - 320;
	var y = (screen.height/2) - 240;
	var features = 'location = 0, menubar = 1, toolbar = 0, status = 0, width = 640, height = 480, resizable = 0, scrollbars = 1';
	window.open (url,name,features);
	}


function isEmpty(str)
{
	return ((str == null) || (str.length == 0));
}

function isSpace(str)
{
	var re = /^\s+$/;
	return (re.test(str));
}

function isInteger(str,emptyOK)
{
	if (isInteger.arguments.length == 1)  emptyOK = false;
	if ((emptyOK == true) && isEmpty(str)) return true;
	var re = /^\d+$/;
	return (re.test(str));
}

function emailvalidate(emailad)
{
	//filter change
	var filter= /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

	if (filter.test(emailad))
		return true;

	else
		return false

}

function checkDecimals(fld, lbl, emptyOK)
{

		var re=/^\d*(\.\d{1,2})?$/;
		if (checkDecimals.arguments.length == 2) emptyOK = false;
		if ((emptyOK == true) && isEmpty(fld.value)) return true;
		if (!re.test(fld.value))
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9) and/or a decimal point(.) eg.99999.99');
		}
		return true;
}


function checkEmail(fld,lbl,emptyOK)
{
	if (checkEmail.arguments.length == 2) { emptyOK = false };
	if ((emptyOK == true) && isEmpty(fld.value)) return true;


	 if (! emailvalidate(fld.value) || ! escapecharac(fld.value))
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct email address format, for example:\n\nsomeone@somewhere.co.za');
		}
		else if (! isEmail(fld.value))
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nOnly one email address is allowed.');
		}
		else
		{
			return true
		}
}

function escapecharac(str)
  	{
		if (str.indexOf("/") > 0 || str.indexOf("/") == 0 || str.indexOf("\\") > 0 || str.indexOf("\\") == 0 || str.indexOf(";") > 0 || str.indexOf(";") == 0 || str.indexOf(",") > 0 || str.indexOf(",") == 0 || str.indexOf(" ") > 0 || str.indexOf(" ") == 0)
		{
				return false;
		}
		else
		{
				return true;
		}
  	 
  	}

function isEmail (str)
{
	var pos = 0;
	var iscomma= 0
	var num = -1;
	var i = -1;


	// Search the string and counts the number of @'s
	while (pos != -1) {
    pos = str.indexOf("@", i + 1);

    num += 1;
    i = pos;
	}
		if (num == 1){
			return true;
		}
	else{

		return false;
}
	return true;
}

function checkSunday(dayFld, monthFld, yearFld)
{
	var myDate = new Date(yearFld.value, monthFld.value - 1, dayFld.value);
	if (myDate.getDay() != 0)
	{
		alert("Oops...\r\r" + dayFld.value + "/" + monthFld.value + "/" + yearFld.value + " does not fall on a Sunday.\rAre you sure you want to keep this Print Date?");
		return true;
	}
}

/*function checkYearRange(fld, lbl, minYear, maxYear)
{
	var myDate = new Number();
	myDate = fld.value;
	if ((myDate >= minYear) && (myDate <= maxYear))
	{
		return true;
	}
		fld.focus();
		return warnInvalid("Oops...\r\r" + lbl + " must be within the range" + minYear + " and " + maxYear + ".");
}*/

function isURL (str)
{
	var URLPat = /http:\/\/(\w)+\.[\w\?\-=~\:\/]+(\.)*[\w\?\-=~\:\/]*/;
	return (URLPat.test(str));
}

function checkURL(fld, lbl, emptyOK)
{
	if (checkURL.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if ((isURL(fld.value) == false))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct web address format,for example:\n\nhttp://www.somesite.co.za');
	}
		return(true);
}

function checkWebLocation(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9+#&_\?\-=~\:\/\.]|(&#)/;
	if (checkWebLocation.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only letters and numbers (a-z, A-Z, 0-9), as well as:\n\n# & + _ ? - = . ~ : /');
	}
		return true;
}

function isPhone(str)
{
 //var re = /\+\d+ \d+\s?[0-9 ]+$/;
 var re = /^\+{1}\d+\s?\d+\s?[\d\s]+$/;
 return (re.test(str));
}

function isIntegerInRange(str,minval,maxval)
{
	if (!isInteger(str)) return false;
	var num = parseFloat(str);
	return ((num >= minval) && (num <= maxval));
}


function checkRange(fld, lbl, minval, maxval, emptyOK)
{
	if (checkRange.arguments.length == 4) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (isIntegerInRange(fld.value, minval, maxval) == false)
	{
		fld.focus();
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter a value between ' + minval + ' and ' + maxval + '.');
	}
	else return true;
}

function checkSelected(fld, lbl, emptyOK)
{
	if (checkSelected.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && (fld.selectedIndex == 0)) return true;
	if (fld.selectedIndex == 0)
	{
			fld.focus();
			alert('OOPS...\n\nPlease select an item in the ' + lbl.toUpperCase() + ' field.\nThis field is required.');
			return false;
	}
		return true;
}


function checkNoTags(fld, lbl)
{
	var re=/[\<\>]/;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\r' + lbl + ' cannot contain "<" or ">" characters. \rPlease edit your entry.');
	}
	return true;
}

function checkText(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z\-\s]/;
	if (checkText.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field. Enter only spaces and letters, as well as:\n\n-');
	}
	return true;
}

function checkTextNumeric(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z-0-9\s]/;
	if (checkTextNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n-');
	}
		return true;
}

function checkRef(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z-0-9]/;
	if (checkRef.arguments.length == 2) emptyOK = false;

		return true;
}


function checkTextNumericPlus(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9+\-\s]/;
	if (checkTextNumericPlus.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n- +');

	}
		return true;
}

function checkTextNumericComma(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9,\-\*&\s]/; //var re=/[^A-Za-z0-9,\-\s]/;
	if (checkTextNumericComma.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n, -');

	}
		return true;
}

function checkTextNumericCommaPeriod(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9,\.\-\s]/;
	if (checkTextNumericCommaPeriod.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n, . -');

	}
		return true;
}

function checkTextNumericBracket(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9\(\)\-\s]/;
	if (checkTextNumericBracket.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z),\rnumeric (0-9) and space characters, as well as:\n \n- ( )');

	}
		return true;
}

function checkNumeric(fld, lbl, emptyOK)
{
	var re=/[^0-9]/;
	if (checkNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9).');

	}
		return true;
}
//
function checkDecimal(fld, lbl, emptyOK)
{
	var decnum = fld.value;
	decpos = checkDecimalPoint(fld);

	var re = /[^0-9\.\s]/;

	if( (re.test(decnum)) )
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9) and/or a (\".\").');
	}
	/*
	if(decpos > 0)
	{
		//document.form.jbvat.value = decnum.slice(0,decpos + 3);
		var num1 = decnum.substring(0,decpos);
		var num2 = decnum.substring((decpos+1),decnum.length);
		var re = /[^0-9]/;

		if ( (re.test(num1)) || re.test(num2) )
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9) and/or a (\".\").');
		}
	}else{
		 if(!checkNumeric(fld, lbl, emptyOK))
		 {
		 	return false;
		 }
	}*/

	return true;

}
function checkDecimalPoint(fld)
{
	var decnum = fld.value;
	decpos_point = decnum.lastIndexOf(".");
	decpos_comma = decnum.lastIndexOf(",");



	if(decpos_point > 0)
	{
		return decpos_point;
	}else{
		if(decpos_comma > 0)
		{
			return decpos_comma;
		}

	}

	return 0;
}



function checkNumericAndDash(fld, lbl, emptyOK)
{
	var re=/[^0-9\-\s]/;
	if (checkNumericAndDash.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only numbers (0-9) and space characters, as well as:\n \n- ');
	}
		return true;
}

function checkAlpha(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z]/;
	if (checkAlpha.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z).');
	}
		return true;
}

function checkAlphaDash(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z\-]/;
	if (checkAlphaDash.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z), as well as:\n \n-');
	}
		return true;
}



function checkAlphaNumeric(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z0-9]/;
	if (checkAlphaNumeric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only letters and numbers (a-z, A-Z, 0-9).');
	}
		return true;
}


function checkAlphaSpace(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z\s]/;
	if (checkAlphaSpace.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic characters (A-Z and a-z) and space.');
	}
	 	return true;

}

function checkAlphaComma(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z,\s]/;
	if (checkAlphaComma.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rPlease edit your entry. ' + lbl + ' can only contain alphabetic (A-Z and a-z)\rand space characters, as well as:\n\n,');
	}
		return true;
}

function checkName(fld, lbl, emptyOK)
{
	var re=/[^A-Za-z'\-\s]/;
	if (checkName.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter only spaces and letters (a-z, A-Z), as well as:\n\n\' -');
	}
		return true;
}

function checkJobTitle(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkJobTitle.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;
}

function checkSkills(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkSkills.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;
}

function checkCourses(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCourses.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');	}
		return true;
}

function checkCompany(fld, lbl, emptyOK)
{
	var re=/[\"\<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCompany.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < > ');
	}
		 return true;
}

function checkCity(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkCity.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;
}

function checkGeneric(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkGeneric.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\r\rPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;
}


function checkTemplate(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkTemplate.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld) || (emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}
		return true;
}

function checkKeywords(fld, lbl, emptyOK, nwords)
{
	var re=/[\"<>]|(&#)|(&amp;)|(&quot;)|(&gt;)|(&lt;)/;
	if (checkKeywords.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;

	fld.value = stripSurroundComma(fld.value);

	//ensure no spurious punctuation:
	var puncRe = /[\/;\*&\.:\\\?\|!\+-]+/;
	if (puncRe.test(fld.value))
	{
		if (! confirm('JUST CHECKING...\n\nYou have entered additional punctuation symbols in your list of keywords.\n\nFor more accurate results:\n\n· Ensure that you have separated your keywords with COMMAS ONLY,\neg. Account Manager, Outlook, Access\n· No fullstop at the end of your list of keywords.\n· Do not add unnecessary fullstops and other punctuation symbols,\neg. ; : / + &\n· Database query language syntax is not accommodated.\n\n- Click OK to continue, OR\n- Click CANCEL to edit your keywords for better results.'))
		{
			fld.focus();
			return false;
		}
	}

	var puncStr = "|[/;\*&\.:\\\?\|!\+-]+";
	var nwordsRe = new RegExp("(" + nwords + puncStr + ")", "i");

	var arrayOfKeywords = trim(fld.value).split(' ');
	for (var i=0; i < arrayOfKeywords.length; i++)
	{
		arrayOfKeywords[i] = stripSpace(arrayOfKeywords[i]);
		if (arrayOfKeywords[i] == '')
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an invalid keyword.');
		}

		if ((arrayOfKeywords[i].length == 1 && !(arrayOfKeywords[i] == "c" || arrayOfKeywords[i] == "C")) || arrayOfKeywords[i] == "as")
		{
			return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an invalid keyword.');
		}

		if (nwordsRe.test(arrayOfKeywords[i]))
		{
			if (arrayOfKeywords[i] == RegExp.$1)
			{
				return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered the keyword "' + RegExp.$1 + '", which is not allowed.');
			}
		}

		var thisPhraseArr = arrayOfKeywords[i].split(' ');
		if (thisPhraseArr.length > 1)
		{
			var nwCounter = 0;
			for (var cnt=0; cnt < thisPhraseArr.length; cnt++)
			{
				if (nwordsRe.test(thisPhraseArr[cnt]))
				{
					if (thisPhraseArr[cnt] == RegExp.$1)
					{
						nwCounter++;
					}
				}
			}

			if (nwCounter == thisPhraseArr.length)
			{
				return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered the keyword phrase "' + arrayOfKeywords[i] + '", which is not allowed.');
			}
		}
	}

	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < >');
	}



	return true;

	/*var i = 0;
	var numquotes = 0;

	for (i = 0; i < fld.value.length; i++)
	{
		if (fld.value.charAt(i) == "\"")
		numquotes++;
	}

	if (numquotes % 2 != 0)
	{
		return warnInvalid(fld,'Oops...\r\rIt appears that you have not closed all of your quotes.\rPlease edit your entry.');
	}

	reA = /\"{2,}/;
	reAB = /\"\s+\"/;
	if (reA.test(fld.value) || reAB.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rThis error has arisen due to ANY of the following:\r- You have not separated your keywords using commas, OR\r- There are empty quotes in your search string.\r\rPlease edit your entry.');
	}

 	reB = /[A-Za-z0-9+\-:]\s{0,}"[A-Za-z0-9+\-:\s]/
	if (reB.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rThis error has arisen due to ANY of the following:\r- You have not separated your keywords using commas, OR\r- There are empty quotes in your search string.\r\rPlease edit your entry.');
	}

	reC = /^"([A-Za-z0-9+\-:\s]*,+[A-Za-z0-9+\-:\s]*)+"$/;
	if (reC.test(fld.value))
	{
		return warnInvalid(fld,'Oops...\r\rYou have entered an invalid keyword.\rEnsure that commas do not appear between quotes.\r\rPlease edit your entry.');
	}
	else return true;*/
}

function checkTextArea(fld, lbl, emptyOK)
{
	var re=/[\"<>]|(&gt;)|(&lt;)|(&amp;)|(&quot;)|(&#)/;
	if (checkTextArea.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (re.test(fld.value))
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThe following characters are NOT allowed:\n\n" < > ');
	}
		return true;
}

function checkDayRange(fld, lbl, emptyOK)
{
	if (checkDayRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value > 0 && fld.value <= 31)
	{
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct day (1-31).');
}

function checkMonthRange(fld, lbl, emptyOK)
{
	if (checkMonthRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value > 0 && fld.value <= 12)
	{
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct month (1-12).');
}

function checkYearRange(fld, lbl, emptyOK)
{
	var d = new Date();
	if (checkYearRange.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value >= 1900 && fld.value <= d.getFullYear())
	{
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct year (1900-' + d.getFullYear() + ').');
}

function checkGivenYearRange(fld, lbl, minyear, maxyear, emptyOK)
{
	var d = new Date();
	if (checkGivenYearRange.arguments.length == 4) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (fld.value >= minyear && fld.value <= maxyear)
	{
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct year (' + minyear + '-' + maxyear + ').');
}


function checkDate(fld, myDate, lbl, emptyOK)
{
	if (checkDate.arguments.length == 3) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (isDate(myDate))
	{
		return true;
	}
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered an incorrect date.');
}

function isDate(strDate)
{
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);

	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";

	if (strDate.length < 1) { return(false); }

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3)
			{
				err = 1;
				return(false);
			} else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}

	if (booFound == false)
	{
		if (strDate.length>5)
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
	    }
	}
	if (strYear.length == 2)
	{
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US")
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	intday = parseInt(strDay, 10);

	if (isNaN(intday))
	{
		err = 2;
		return false;
	}

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
		    }
		}
		if (isNaN(intMonth))
		{
			err = 3;
			return false;
        }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear))
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1)
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
	{
		err = 7;
		return false;
	}
	if (intMonth == 2)
	{
		if (intday < 1)
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true)
		{
			if (intday > 29)
			{
				err = 9;
				return false;
			}
		} else
		{
			if (intday > 28)
			{
				err = 10;
				return false;
			}
		}
	}

	return(true);
}
function LeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
		if (intYear % 400 == 0) { return(true); }
	} else {
		if ((intYear % 4) == 0) { return(true); }
	}
	return(false);
}


function DaysInMonth(month)
{
	switch (month)
	{
		case 0: return(31); break;
		case 1: return(28); break;
		case 2: return(31); break;
		case 3: return(30); break;
		case 4: return(31); break;
		case 5: return(30); break;
		case 6: return(31); break;
		case 7: return(31); break;
		case 8: return(30); break;
		case 9: return(31); break;
		case 10: return(30); break;
		case 11: return(31); break;
		default: return (28);
	}
}



function checkFromTo(fld, strDateOne, strDateTwo, strFromDateDesc, strToDateDesc)
{
	if (checkFromTo.arguments.length == 3)
	{
		strFromDateDesc = 'FROM DATE';
		strToDateDesc = 'a TO DATE';
	}
	if (Date.parse(strDateOne) <= Date.parse(strDateTwo))
	{
		return true;
	}
		return warnInvalid(fld, 'OOPS...\n\nYou have entered ' + strToDateDesc + ' prior to the ' + strFromDateDesc + '.\nPlease edit your entry in the date field.');
}

function trim(str)
{
	if (! isEmpty(str))
	{
		while(''+str.charAt(0)==' ') str=str.substring(1,str.length);

		while(''+str.charAt(str.length-1)==' ') str=str.substring(0,str.length-1);
	}
	return(str);
}


function checkLength(fld,lbl,maxval,emptyOK)
{
	if (checkLength.arguments.length == 3) { emptyOK = false };
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	fld.value = trim(fld.value);
	fld.value = trim(fld.value);
	if (isSpace(fld.value)) fld.value = "";
	if (isEmpty(fld.value)) return warnEmpty(fld,lbl);
	if (fld.value.length > maxval)
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nYou have entered ' + fld.value.length + ' characters.\nThis field is limited to ' + maxval + ' characters (approx ' + (maxval/50) + ' lines).');
	} else
	{
		return true;
	}
}

function checkMinLength(fld,lbl,minlen,emptyOK)
{
	if (checkMinLength.arguments.length == 3) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	fld.value = trim(fld.value);
	if (isSpace(fld.value)) fld.value = "";
	if (isEmpty(fld.value)) return warnEmpty(fld, lbl);
	if (fld.value.length < minlen)
	{
		return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nThis field must contain at least ' + minlen + ' characters.');
	} else
	{
		return true;
	}
}


function checkPhone(fld,lbl,emptyOK)
{
	if (checkPhone.arguments.length == 2) emptyOK = false;
	if ((emptyOK == true) && isEmpty(fld.value)) return true;
	if (! isPhone(fld.value)) return warnInvalid(fld,'OOPS...\n\nPlease edit your entry in the ' + lbl.toUpperCase() + ' field.\nEnter the correct international format, for example:\n\n+27 12 345 6789');
	return true;
}

//Added to Blacklist emails with postmaster.co.za
function EmailIsNotBlacklisted()
{
	var strEmail = document.form.email.value.toLowerCase();
	if (strEmail.indexOf('postmaster.co.za') == -1)
	{
		return true;
	}
	else
	{
		document.form.email.focus();
		alert('OOPS...\n\nThe EMAIL ADDRESS you supplied is invalid.\nPlease pick another one.');
		return false;
	}
}

function fixEmail(fld)
{
	var result = '';
	result = fld.value.replace("hotmail.co.za", "hotmail.com");
	result = fld.value.replace("webmail.com", "webmail.co.za");
	result = fld.value.replace("yahoo.co.za", "yahoo.com");
	result = fld.value.replace("absa.freemail.co.za","freemail.absa.co.za");
	alert(result);
	return(result);
}

function warnEmpty(fld,lbl)
{
	fld.focus();
	alert('OOPS...\n\nPlease add an entry in the ' + lbl.toUpperCase() + ' field.\nThis field is required.');
	return false;
}

function warnInvalid(fld,msg)
{
	alert(msg);
	fld.focus();
	if ((fld.type == 'password') || (fld.type == 'text') || (fld.type == 'textarea')) {
		fld.select();
	}
	return false;
}

/*checks to see if Template Name already contained in Import Template dropdown:*/
/*function checkTemplateExists()
{
	var i;
	for (i = 0; i < document.form.template.length; i++)
	{
		if (document.form.template.options[i].text == document.form.templatename.value)
		{
			document.form.templatename.focus();
			alert("Oops...\nThe template name you have chosen already exists.\nPlease choose another template name or leave the field blank\nif you do not wish to save this as a template.");
			return false;
		}
	}
	return true;
}*/


function openWin (url,name,features)
{
	var mywin = window.open(url,name,features);
}

function closeWin()
{
	var mywin = window.close();
}

function checkDelete()
{
if (confirm('IMPORTANT!\r\rAre you sure you want to permanently delete\rall records of yourself?'))
	{
	document.form.action = "/careerseekers/portfolio/deleteme/deletemefrmupd";
	document.form.submit();
	}
}

function stripComma(str)
{
	var reBegin = /^,+/;
	str = str.replace(reBegin, "");

	var reEnd = /,+$/;
	str = str.replace(reEnd, "");

	var reMid = /,{2,}/;
	str = str.replace(reMid, ",");

	return str;
}

function stripSurroundComma(str)
{
	var reBegin = /^\s*,+/;
	str = str.replace(reBegin, "");

	var reEnd = /,+\s*$/;
	str = str.replace(reEnd, "");

	return str;
}

function stripSpace(str)
{
	var reBegin = /^\s+/;
	str = str.replace(reBegin, "");

	var reEnd = /\s+$/;
	str = str.replace(reEnd, "");

	return str;
}

function getJavaVersion()
{
	var agt=navigator.userAgent.toLowerCase();

     // *** BROWSER VERSION ***
     // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
     var is_major = parseInt(navigator.appVersion);
     var is_minor = parseFloat(navigator.appVersion);

     // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
     // If you want to allow spoofing, take out the tests for opera and webtv.
     var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
     var is_nav2 = (is_nav && (is_major == 2));
     var is_nav3 = (is_nav && (is_major == 3));
     var is_nav4 = (is_nav && (is_major == 4));
     var is_nav4up = (is_nav && (is_major >= 4));
     var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
     var is_nav6 = (is_nav && (is_major == 5));
     var is_nav6up = (is_nav && (is_major >= 5));
     var is_gecko = (agt.indexOf('gecko') != -1);

     var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
     var is_ie3    = (is_ie && (is_major < 4));
     var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
     var is_ie4up  = (is_ie && (is_major >= 4));
     var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
     var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
     var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
     var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

     // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
     // or if this is the first browser window opened.  Thus the
     // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
     var is_aol   = (agt.indexOf("aol") != -1);
     var is_aol3  = (is_aol && is_ie3);
     var is_aol4  = (is_aol && is_ie4);
     var is_aol5  = (agt.indexOf("aol 5") != -1);
     var is_aol6  = (agt.indexOf("aol 6") != -1);

     var is_opera = (agt.indexOf("opera") != -1);
     var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
     var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
     var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
     var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
     var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

     var is_webtv = (agt.indexOf("webtv") != -1);

     var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    var is_AOLTV = is_TVNavigator;

     var is_hotjava = (agt.indexOf("hotjava") != -1);
     var is_hotjava3 = (is_hotjava && (is_major == 3));
     var is_hotjava3up = (is_hotjava && (is_major >= 3));
	 // *** JAVASCRIPT VERSION CHECK ***
     var is_js;
     if (is_nav2 || is_ie3) is_js = 1.0;
     else if (is_nav3) is_js = 1.1;
     else if (is_opera5up) is_js = 1.3;
     else if (is_opera) is_js = 1.1;
     else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
     else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
     else if (is_hotjava3up) is_js = 1.4;
     else if (is_nav6 || is_gecko) is_js = 1.5;
     // NOTE: In the future, update this code when newer versions of JS
     // are released. For now, we try to provide some upward compatibility
     // so that future versions of Nav and IE will show they are at
     // *least* JS 1.x capable. Always check for JS version compatibility
     // with > or >=.
     else if (is_nav6up) is_js = 1.5;
     // NOTE: ie5up on mac is 1.4
     else if (is_ie5up) is_js = 1.3

     // HACK: no idea for other browsers; always check for JS version with > or >=
     else is_js = 0.0;
     return is_js;
}

function getBrowserDetails()
{
	document.form.browserClient.value = navigator.appName;
	document.form.browserVersion.value = navigator.appVersion;
	document.form.browserMinorVersion.value = navigator.appMinorVersion;
	document.form.browserVersion.value = navigator.appVersion;
	document.form.browserAgent.value = navigator.userAgent;
	document.form.browserJavaScript.value = getJavaVersion();
}

function IPRangeValid(IPRange)
/*
	IPRangeValid routine

	Input	: IPRange - comma separated list of IP Addreses
			: in format 123.123.123.0-197, 123.123.123.123, 123,123,123,*
			: or *.*.*.* meaning any IP address is valid
	Output	: Boelean, indicating that the IPRange was formatted OK.
			: true means the IPRange is a validly formatted one
			: false means the IPRange is not validly formatted
*/
{
	var anyIPValid = '*.*.*.*';
	// Check to see that we have something in the IPRange to check against
	if (IPRange == '')
	{
		document.form.ipaddresses.focus();
		alert('Oops\r\rYou have entered an invalid IP Address range.');
		return(false);
	}
	//the pattern below is not allowed
	myRe = /(\-\*)|(\*\-)/;
	if (myRe.test(IPRange))
	{
		document.form.ipaddresses.focus();
		alert('Oops\r\rYou have entered an invalid IP Address range.');
		return(false);
	}
	// If the range is any then exit OK.
	if (IPRange == anyIPValid) {return(true);}
	// Check the client IP against the range
	var arr, cnt, i, re, rearr, nextvip;
	// Put the range into an array for easier checking
	arr = IPRange.split(',');
	// Count the number of items in the array
	cnt = arr.length;
	// Set the regular expression to validate the IPRange(s)
	re = /[0-9]{1,3}\.[0-9]{1,3}\.([0-9]{1,3}|\*)\.([0-9]{1,3}|[0-9]{1,3}\-[0-9]{1,3}|\*)/ig
	// For each IP entry in the array, do the check
	for (i=0; i < cnt; i++)
	{
		// Fetch the next valip ip address in the range
		nextvip = arr[i];
		// Try and match to the pattern required
		rearr = nextvip.match(re);
		// If no match found for this IP Address then Range is invalid
		if (rearr == null)
		{
			document.form.ipaddresses.focus();
			alert('Oops\r\rYou have entered an invalid IP Address range.');
			return(false);
		}
	}
	// All IP Addresses in Range passed check then range is valid.
	return(true);
}


function restrictinput(maxlength,e,placeholder)

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

if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(theform,thelimit){
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}
