
//************************* Useful Functions ******************************************
	
	function createGUID(){
		var guid;
		// in IE we can get a real GUID
		if(window.ActiveXObject){
			try{
				guid = new ActiveXObject("Scriptlet.TypeLib");
			}catch(e){}
		}
		// other browsers or if the above failed
		if(!guid){
			guid = (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
		}
		return guid;
	}

	function S4() {
		return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	}

	function encodeURI(s,u) {
		if (typeof(encodeURIComponent) == 'function') {
			if (u) return encodeURI(s); //if a full URL don't enode certain chars such as ? : @ + =
			else return encodeURIComponent(s); //use for encoding URI components eg values in name/value pairs
		} else {
			return escape(s); //bog standard escape
		}
	}
	function decodeURI(s) {
		if (typeof(decodeURIComponent) == 'function') {
			return decodeURIComponent(s);
		} else {
			return unescape(s);
		}
	}

	function doCounter(obj,cn,max,nmsg,lmsg)
	{
		ShowDebug("IN doCounter = " + cn + " max = " + max)
		var sl = 298 //max size for progress bar 100px
		var counter = cn + 'Counter';
		var msg = cn + 'Limit';
		var usl = obj.value.length;
		var p = sl/100 //is the size for 1%
		ShowDebug("in doCounter current len = " + usl + " 1% = " + sl)
		if(usl>=max){
			ShowDebug("too big")
			obj.value = obj.value.substring(0,max);		
			var elC = document.getElementById(counter).style		
			elC.width			= parseInt(sl) + "px";		
			ShowDebug("set width = " + elC.width)
			document.getElementById(msg).innerHTML = lmsg;
			document.getElementById(msg).className=cn + 'LimitReached'
		}else{		
			ShowDebug("not big enough yet")
			//work out percentage of text we have used
			var usP = (usl/max) * 100
			//now work out the size of the progress bar
			var size = usP * p		

			var elC = document.getElementById(counter).style
			elC.width			= parseInt(size) + "px"		
	
			ShowDebug("set width = " + elC.width)
			document.getElementById(msg).innerHTML = nmsg;
			document.getElementById(msg).className=cn + 'AddText'
		}		
	}

	function getCheckboxIDs(frm,elName,OnlyChecked)
	{		
		var a = frm.getElementsByTagName('input');
		var n = a.length;
		var bAdd;

		var Checked = new Array();
		
		for (var i=0;i<n;i++)
		{
			bAdd = false;
			if (a[i].name==elName){
				//if we only want to return items that are actually checked
				if(OnlyChecked){
					if(document.getElementById(a[i].id).checked){
						bAdd = true;
					}
				}else{
					bAdd = true;
				}
				if(bAdd)
					Checked.push(a[i].value);
			}
		}

		return Checked;  //.join(',');
	}

	//convert a string value to a boolean
	function convertToBool(v)
	{	
		v=v.toLowerCase();
		if(v=="true" || v=="on" || v=="yes" || v=="1"){return true;}else{return false;}
	}

	function NewWindow(mypage,myname,w,h,scroll,pos)
	{
		if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
		if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
		settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
		win=window.open(mypage,myname,settings);
		win.focus();
	}

	function OpenCMSWin(url)
	{	
		window.open(url,'cmsedit','scrollbars=1,status=0,resizable=0,width=650,height=600');	
	}


	function CountNo(strIN, pattern)
	{
			
		var NoOfMatches = 0;
	
		re = pattern ;
	
		var arr = strIN.match(re)
		if(arr!=null){
			NoOfMatches = arr.length;
		}
	
		return NoOfMatches;

	}

	/*
		this function turns HTML encoded entities into numeical encoded entities so that JScript can display them
	*/
	function NumericEncodeHTML(strIN)
	{
		var HTMLentities	= new Array('&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&times;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&quot;','&amp;','&lt;','&gt;','&oelig;','&oelig;','&scaron;','&scaron;','&yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;','&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&fnof;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;','&piv;','&bull;','&hellip;','&prime;','&prime;','&oline;','&frasl;','&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&crarr;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;','&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;','&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;','&spades;','&clubs;','&hearts;','&diams;')
		var NUMentities		= new Array('&#160;','&#161;','&#162;','&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;','&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;','&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;','&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;','&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;','&#251;','&#252;','&#253;','&#254;','&#255;','&#34;','&#38;','&#60;','&#62;','&#338;','&#339;','&#352;','&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;','&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;','&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;','&#8240;','&#8249;','&#8250;','&#8364;','&#402;','&#913;','&#914;','&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;','&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;','&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;','&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;','&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;','&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;','&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;','&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;','&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;','&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;','&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;','&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;','&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;','&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;','&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;','&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;','&#9827;','&#9829;','&#9830;')
		var strOUT			= strIN;

		//alert("IN NumericEncodeHTML before change = " + strIN)
		//replace HTML entities with numerical encoding
		for(var x=0;x<HTMLentities.length;x++){
			strOUT = strOUT.replace(HTMLentities[x],NUMentities[x]);
		}
		//alert("replace HTML entities = " + strOUT);

		return strOUT;
	}

	/*
		this function turns Numerical encoded entities back into the correct HTML entities. Use DecodeHTML if you want the actual character instead.
	*/
	function NumericDecodeHTML(strIN)
	{
		var HTMLentities	= new Array('&nbsp;','&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&times;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&quot;','&amp;','&lt;','&gt;','&oelig;','&oelig;','&scaron;','&scaron;','&yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;','&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&fnof;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;','&piv;','&bull;','&hellip;','&prime;','&prime;','&oline;','&frasl;','&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&crarr;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;','&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;','&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;','&spades;','&clubs;','&hearts;','&diams;')
		var NUMentities		= new Array('&#160;','&#161;','&#162;','&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;','&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;','&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;','&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;','&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;','&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;','&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;','&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;','&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;','&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;','&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;','&#251;','&#252;','&#253;','&#254;','&#255;','&#34;','&#38;','&#60;','&#62;','&#338;','&#339;','&#352;','&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;','&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;','&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;','&#8240;','&#8249;','&#8250;','&#8364;','&#402;','&#913;','&#914;','&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;','&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;','&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;','&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;','&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;','&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;','&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;','&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;','&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;','&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;','&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;','&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;','&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;','&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;','&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;','&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;','&#9827;','&#9829;','&#9830;')
		var strOUT			= strIN;
		
		//replace numerically encoded entities with its HTML encoded version
		for(var x=0;x<NUMentities.length;x++){
			strOUT = strOUT.replace(NUMentities[x],HTMLentities[x]);
		}		

		return strOUT;

	}

	/* 
		this function turns HTML encoded entities and Numerical entities back into the character they represent.
	*/	
	function DecodeHTML(strIN)
	{
		
		var strDecoded = strIN //+ '';

		if(strDecoded != "" && strDecoded != " "){
			strDecoded = strDecoded.replace(/&nbsp;/gi, " ");
			strDecoded = strDecoded.replace(/&amp;/gi, String.fromCharCode(38));
			strDecoded = strDecoded.replace(/&quot;/gi, String.fromCharCode(34));
			strDecoded = strDecoded.replace(/&lt;/g, String.fromCharCode(60));
			strDecoded = strDecoded.replace(/&gt;/gi, String.fromCharCode(62));
			strDecoded = strDecoded.replace(/&euro;/gi, String.fromCharCode(128));
			strDecoded = strDecoded.replace(/&lsquo;/gi, String.fromCharCode(145));
			strDecoded = strDecoded.replace(/&rsquo;/gi, String.fromCharCode(146));
			strDecoded = strDecoded.replace(/&ldquo;/gi, String.fromCharCode(147));
			strDecoded = strDecoded.replace(/&rdquo;/gi, String.fromCharCode(148));
			strDecoded = strDecoded.replace(/&pound;/gi, String.fromCharCode(163));	
			strDecoded = strDecoded.replace(/&frac14;/gi, String.fromCharCode(188));	
			strDecoded = strDecoded.replace(/&frac12;/gi, String.fromCharCode(189));
			strDecoded = strDecoded.replace(/&frac34;/gi, String.fromCharCode(190))	;
				
			arr=strDecoded.match(/&#[0-9]{1,5};/g);
		
			if(arr!=null){
				for(var x=0;x<arr.length;x++){
					sMatch = arr[x]
					intChr = sMatch.substring(2,sMatch.length-1)
				
					if(intChr >= -32768 && intChr <= 65535){
						strDecoded = strDecoded.replace(sMatch, String.fromCharCode(intChr))
					}else{
						strDecoded = strDecoded.replace(sMatch, "")
					}
				}			
			}	
		}else{
			strDecoded = "";
		}
				
		return strDecoded;
	}
	
	function getDayCount(UKDate)
	{	
		UKDate = UKDate.split(/\D+/);
		var retVal = -( (-UKDate[2]*20-UKDate[1])*50 - UKDate[0] );
		return retVal;
	}

	//use this to get current date for comparisons
	function getNOW(){
	   var x=new Date();
	   x.setTime(x.getTime());
	   return x;
	}

	//use this for nows date displayed in UK format
	function getUKDate(bShowTime){
		var dtDate, dtTime
		var currentTime = new Date()
		var month		= currentTime.getMonth() + 1
		var day			= currentTime.getDate()
		var year		= currentTime.getFullYear()
		
		dtDate = day + "/" + month + "/" + year

		if (bShowTime)
		{
		
			var hours	= currentTime.getHours()
			var minutes = currentTime.getMinutes()
			var seconds	= currentTime.getSeconds()
			
			dtTime = hours + ":" + minutes + ":" + seconds

			dtDate +=  " " + dtTime
		}

		return dtDate
	}
	

	//use this for a nice display date
	function getDate(bShowTime){
		var dtDate, dtTime
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		
		dtDate = day + "/" + month + "/" + year

		if (bShowTime)
		{
		
			var hours = currentTime.getHours()
			var minutes = currentTime.getMinutes()
			if (minutes < 10)
				minutes = "0" + minutes
			dtTime = hours + ":" + minutes + " "	
			if(hours > 11){
				dtTime += "PM"
			} else {
				dtTime +="AM"	
			}

			dtDate +=  " " + dtTime
		}

		return dtDate
	}
	
	
	function getElementStyle(elemID, IEStyleProp, CSSStyleProp, win) {
		if(!win) win = window;
		doc = win.document;
		var elem = doc.getElementById(elemID);
		if(elem){
			if (elem.currentStyle) {
				return elem.currentStyle[IEStyleProp];
			}else if (win.getComputedStyle) {
				var compStyle = win.getComputedStyle(elem, "");
				return compStyle.getPropertyValue(CSSStyleProp);
			}
		}
		return "";
	}

	
	function RemoveMSWord(strHTML){

		var strCleanHTML = strHTML

		strCleanHTML = strCleanHTML.replace(/\<xml[\s\S]+?\<\/xml\>/gi, "")	
		strCleanHTML = strCleanHTML.replace(/<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>/gi,"<$1$2>")
		strCleanHTML = strCleanHTML.replace(/<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>/gi,"<$1$2>")
		strCleanHTML = strCleanHTML.replace(/\<style[\s\S]+?\<\/style\>/gi, "")
		//remove MS conditionals	
		strCleanHTML = strCleanHTML.replace(/<!\[if !supportEmptyParas\]>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<!\[endif\]>/gi,"")	
		strCleanHTML = strCleanHTML.replace(/<!--\[if gte mso 9\]>/gi,"")
		strCleanHTML = strCleanHTML.replace(/<!\[endif\]-->/gi,"")				
		//Sort out spaces before > tags eg <p >
		strCleanHTML = strCleanHTML.replace(/ >/gi,">")
		//sort out empty lines
		strCleanHTML = strCleanHTML.replace(/[\r\n][\r\n\t]*[\r\n]/gi,"\r\n")			

		return strCleanHTML
	}



	function GetEndNumerics(strIN){
		
		var strOut = strIN.match(/\d*$/)

		return strOut

	}

	function ReplaceEndNumerics(strIN){
		
		var strOut = strIN.replace(/\d*$/, "")

		return strOut

	}


	
	//loop through all elements on form giving name/id/type
	function FormInfo(f, bInOneMsg){
		var e, strMsg, elInfo;
		
		for(var x=0;x<f.elements.length;x++){
			e = f.elements[x];
	
				var id = e.id	
				
				elInfo = "name= " + e.name + " id= " + e.id + " type= " + e.type + " value=" + e.value

				if(bInOneMsg){
					strMsg += elInfo + '\n'
				}else{
					alert(elInfo)			
					}
	
		}
		
		if(bInOneMsg){
			alert(strMsg);
		}
		return false;
	}

	//will return the number of options selected in a multiple select list box
	function NoSelected(obj){
		alert("in NoSelected")
		var nSel = 0;

		if (obj!=null && obj.options!=null){
			for (var i=0; i<obj.options.length; i++) {
				if(obj.options[i].selected == true){
					nSel ++
				}
			}
		}
		alert("return " + nSel)
		return nSel;
	}
	
	// Will deselct all other options in a list if the Any/All selection is chosen
	function selChk(me){
		//alert("in selChk")
		
		var x;
		var bAny = false;
		//if no Any selection then function not needed
		if(me.options[0].value!=""){		
			return
		}
		//option[0] is Any
		//if Any selected then deselect everything else
		if(me.options[0].value=="" && me.options[0].selected==true){
			for(x=1;x<me.length;x++){
				me.options[x].selected=false;
			}	
		}
	}
	
	function checkNumber( e )
	{	//allows 0123456789
		e = GetEvent(e);
		if(!e) return;
		var key = getKeyCode(e);		
		if ((key<48)||(key>57))
		{
			CancelEvent(e);
		}
	}


	function getKeyCode( e ){			
		ShowDebug("In getKeyCode = " + e + " - " + e.type);
		if(e){
			var s = "keycode = " + e.keyCode + " which = " + e.which + " charCode = " + e.charCode;
			ShowDebug(s);
			// In Moz e.keyCode returns 0 so cannot check for == number
			if( e.charCode ){
				//also NS 6+, Mozilla 0.9+
				ShowDebug("MOZ return charCode = " + e.charCode);
				return e.charCode;
			}else if( e.which ) {
				//NS 4 compatible
				ShowDebug("NS4 return which = " + e.which);
				return e.which;
			}else if( e.keyCode ){
				//IE
				ShowDebug("IE return keycode = " + e.keyCode);				
				return e.keyCode;
			}else{
				ShowDebug("TOTAL SHISCHER")
				//total failure, we have no way of obtaining the key code
				return undefined;
			}	
		}else{
			ShowDebug("NO EVENT!!");
		}
		return undefined
	}

	function NumCharMask(e)
	{
		ShowDebug("IN NumCharMask e ="+e)
		var key;
		var evtobj = (e) ? e : GetEvent(e); //will get correct window.event
		
		ShowDebug("Event = " + evtobj +" type =" +evtobj.type);

		if(!evtobj) return false;//no event available

		key = getKeyCode(evtobj);
		if(!key) CancelEvent(evtobj);

		ShowDebug("key " + key + " hit = " + String.fromCharCode(key));

		var bOK = false;
		if (!evtobj.ctrlKey && !evtobj.shiftKey)
		{

			if ( key == 9 ||					// TAB key
				key == 8 ||						// Backspace key
				key == 36 ||					// Home key
				key == 35 ||					// End key
				key == 39 ||					// Right Arrow
				key == 37 ||					// Left Arrow
				key == 189 ||					// minus key
				key == 46 ||					// Delete Key
				key == 109 ||					// minus key
				//i == 190 ||					// Period
				(key >= 48 && key <= 57) ||		// Top row 0 to 9
				(key >= 96 && key <= 105))		// Number pad 0 to 9
				bOK = true;
		}else{
			bOK = false;	
		}

		if(!bOK){
			CancelEvent(evtobj);		
		}
	}

	function isSpecialKey(e){
		e = GetEvent(e);
		var key = getKeyCode(e);
		if(!key) return;
		if ( key == 9 ||					// TAB key
			key == 8 ||						// Backspace key
			key == 36 ||					// Home key
			key == 35 ||					// End key
			key == 39 ||					// Right Arrow
			key == 37 ||					// Left Arrow
			key == 189 ||					// minus key
			key == 46 )	{					// Delete Key
			return true;
		}else{
			return false;
		}
	}

	function SalCharMask(e, v)
	{
		ShowDebug("IN SalCharMask e = " +e+ " - value = "  + v);
		var key;
		var evtobj = (e) ? e : GetEvent(e); //will get correct window.event
		if(!evtobj) return //no event available
		
		key = getKeyCode(evtobj);
		ShowDebug("getKeyCode = " + key);

		if(!key) CancelEvent(evtobj);

		ShowDebug("key " + key + " hit")
		var bOK = false;		
		if(!evtobj.ctrlKey && !evtobj.shiftKey)
		{			
			if( (	key == 9 || 
					key == 8 || 
					key == 36 ||
					key == 35 || 
					key == 39 || 
					key == 37 || 
					key == 189 || 
					key == 46 || 
					((key == 190 || key == 110) && v.indexOf('.')==-1 ) 
				) || 
					(v <9999999 && 
						(
							(key >= 48 && key <= 57) ||	
							(key >= 96 && key <= 105)
						)
					)   
				)
				bOK = true;
			
		}else{
			bOK = false;	
		}

		if (!bOK){
			ShowDebug("NOT OK STOP EVENT");
			CancelEvent(evtobj);		
		}
		
	}

	function Len(str){ 
		
		return String(str).length; 
	
	}

	function Trim(str){
		
		var x;
		x = LTrim(RTrim(str));
		return x;
    
    	}

	
	function LTrim(v){

		while(''+v.charAt(0)==' '){
			v=v.substring(1,v.length);
		}
		
		return v;

	}

	function RTrim(v){
		
		while(''+v.charAt(v.length-1)==' ')
		{
			v= v.substring(0,v.length-1);
		}

		return v;

	}

	function MTrim(v){
	
		//remove all spaces between characters
		string = v;
		var mySeparator = " ";
		var x  = string.split(mySeparator);
		if(x == null){//if no parts then error
			err = 1;
		}
		//regroup no into one string
		tempstring = "";
		for(var i=0; i<x.length; i++){
			if(x[i]!=" ")
				tempstring = tempstring + x[i]
		}
	
		return tempstring;

	}

	function Left(str, n) {
		
		if (n <= 0)    
			return "";
        	else if (n > String(str).length)   
            		return str;               
        	else 
           		return String(str).substring(0,n);
        }

	function Right(str, n) {
		if (n <= 0)    
            		return "";
        	else if (n > String(str).length)  
            		return str;                    
        	else { 
	       		var iLen = String(str).length;
            		return String(str).substring(iLen, iLen - n);
        	}
    	}

	function Mid(str, start, len){
   
		if (start < 0 || len < 0) return "";

       		var iEnd, iLen = String(str).length;
	        if (start + len > iLen)
            	iEnd = iLen;
	        else
				iEnd = start + len;

        	return String(str).substring(start,iEnd);
    	}

	function InStr(strSearch, charSearchFor){
		//searchs for a character within a string
		
		for (x=0; x < Len(strSearch); x++)
		{
		    if (charSearchFor == Mid(strSearch, x, 1))
		    {
				return x;
		    }
		}
		
		return -1;
	
	}


function Find(strSearch, charSearchFor, x){
		//searches for a word within a string
		//x is length of string to find 
		//alert("passed in SearchString=" + strSearch + " SearchFor=" + charSearchFor + " Length=" + x)
		
		for (i=0; i < Len(strSearch); i++)
		{
		    if (charSearchFor == Mid(strSearch, i, x))
		    {				
				return i;				
		    }
		}
	
		return -1;
	
	}
	
	
function Find_Block(strSearch, Block, Block_len)
{
	
	for(i=0;i<Len(strSearch);i++)
	{
		
		result = Mid(strSearch, i, Block_len)
	
		if(result==Block)
		{
			
			var pos = i
			
			if(strSearch.substring((pos-1,pos)==",")||(strSearch.substring(pos-1,pos)==""))
			{
				if(strSearch.substring(pos+Block_len, (pos+Block_len+1))==","||strSearch.substring(pos+Block_len, (pos+Block_len+1))=="")
				return i;			
			}
						
		}
				
	}		
	//could not find block
	return -1;
}



//********************************************************************************************

function Remove(v, r){
	
		//remove all passed in chars from string
		string = v;
		var mySeparator = r;
		var x  = string.split(mySeparator);
		if(x == null){//if no parts then error
			err = 1;
		}
		//regroup no into one string
		tempstring = "";
		for(var i=0; i<x.length; i++){
			if(x[i]!=" ")
				tempstring = tempstring + x[i]
		}
	
		return tempstring;
	
	}

//********************************************************************************************


	function CountNoOf(s, v){
		//counts no of times a char appears in a string
		
		string = s;
		count = 0;
		var a;
		for (var i=0; i< string.length; i++) {
			a = string.substring(i, i+1);
			if(a == v) count ++;
		}
		
		return count;
	
	}

function CheckNumeric(No){

	//checks to see if string is made up from valid numeric characters
		
		var err=0;
		var valid = "0123456789";
		var temp;		
		for (var i=0; i<No.length; i++) {
			temp = "" + No.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") err = 1;
		}
		
		if (err==1) {		
			return false;
		}
		else {
			return true;
			}
}

function CheckText(str){

	//checks to see if string is made up from valid numeric characters
		
		var err=0;
		var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -";
		var temp;		
		for (var i=0; i<str.length; i++) {
			temp = "" + str.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") err = 1;
		}
		
		if (err==1) {		
			return false;
		}
		else {
			return true;
			}
}
//************************ End of Useful Functions *************************************

function highlight(c){	
	eval('document.all.'+c+'.bgColor="LightSteelBlue"');
	//eval('document.all.'+c+'.style.color="blue"');		
}
function highlightoff(c){
	eval('document.all.'+c+'.bgColor="SteelBlue"');	
}
function select(page){
	parent.Main.location.href = page;
}

// mainkey show/hide explanations script for jobmanager.asp
function show_div(div_id) {
   	// hide all the divs
	document.getElementById('editJob').style.display = 'none'; // Searches
	document.getElementById('renewJob').style.display = 'none'; //  Jobseekers
	document.getElementById('copyJob').style.display = 'none'; // Advertisers
	document.getElementById('archiveJob').style.display = 'none'; // Searches
	document.getElementById('deleteJob').style.display = 'none'; // Searches
	document.getElementById('applications').style.display = 'none'; // Searches
	if(document.getElementById('viewHistory'))
		document.getElementById('viewHistory').style.display = 'none'; // Searches
	document.getElementById('key_featured').style.display = 'none'; // Featured
	// show the requested div
	document.getElementById(div_id).style.display = 'block';
}
