function getElement(sID) {
	return document.getElementById(sID);
}
function showEle(sID) {
	var o=getElement(sID);
	if (o) o.style.visibility="visible";
}
function hideEle(sID) {
	var o=getElement(sID);
	if (o) o.style.visibility="hidden";
}
function openEle(sID) {
	var o=getElement(sID);
	if (o) o.style.display="block";
}
function closeEle(sID) {
	var o=getElement(sID);
	if (o) o.style.display="none";
}
function openclose(sID) {
	var o=getElement(sID);
	if (o) {
		if (o.style.display=='none')
			o.style.display="block";
		else
			o.style.display="none";
	}
}
function swapImg(id,newSrc) {
	var oImg=getElement(id);
	if (oImg!=null) oImg.src=newSrc;
}
function focus(sID) {
	var o=getElement(sID);
	if (o) o.focus();
}
function inFocus(oIn,val) {
	if (oIn!=null && oIn.value.trim()==val) oIn.value='';
}
function inBlur(oIn,val) {
	if (oIn!=null && oIn.value.trim()=='') oIn.value=val;
}

String.prototype.ltrim=new Function("return this.replace(/^\\s+/,'')");
String.prototype.rtrim=new Function("return this.replace(/\\s+$/,'')");
String.prototype.trim=new Function("return this.replace(/^\\s+|\\s+$/g,'')");
String.prototype.nocr=new Function("return this.replace(/(\\r\\n|[\\r\\n])/g,'')");
String.prototype.makeplain=new Function("return this.toLowerCase().replace(/\\s/g,'_')");
String.prototype.endsWith=function(s) {	return(new RegExp(s+"$")).test(this); }

function Fetcher() {
	var me=this;
	this.fnCB=null;
	this.xmlHttp=null;
	try { this.xmlHttp=new XMLHttpRequest(); }
	catch (trymicrosoft) {
		try { this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (othermicrosoft) {
			try { this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (failed) {
				this.xmlHttp=null;
			}  
		}
	}
	this.now=function(sURL) {
		var sRet="";
		if (this.xmlHttp) {
			this.xmlHttp.open("GET",sURL,false);
			this.xmlHttp.send(null);
  			if (this.xmlHttp.readyState==4)
				sRet=this.xmlHttp.responseText.nocr().trim();
		}
		return sRet;
	}	
	this.whenever=function(sURL,fnCB) {
		if (this.xmlHttp) {
			this.fnCB=fnCB;
			this.xmlHttp.open("GET",sURL,true);
			this.xmlHttp.onreadystatechange=this.loader;
			this.xmlHttp.send(null);
		}
	}
	this.loader=function() {
		if (me.xmlHttp) {
			if (me.xmlHttp.readyState==4 && me.xmlHttp.status==200) {
				me.fnCB(me.xmlHttp.responseText.nocr().trim());
			}
		}
	}
	this.stop=function() {
		if (me.xmlHttp) me.xmlHttp.abort();
	}
}
function extractXML(sXML,sTag) {
	var iFrom=sXML.indexOf("<"+sTag+">");
	var iTo=sXML.indexOf("</"+sTag+">",iFrom);
	return (iFrom!=-1 && iTo!=-1 ? sXML.substring(iFrom+(sTag.length+2),iTo) : "");
}
function areYouSure(sURL,sMsg) {
	if (confirm(sMsg)) goURL(sURL);
}
function goURL(sURL) {
	var b=document.getElementsByTagName('base');
	if (b && b[0] && b[0].href) {
		if (b[0].href.substr(b[0].href.length-1)=='/' && sURL.charAt(0)=='index.html') sURL=sURL.substr(1);
		sURL=b[0].href+sURL;
	}
	location.replace(sURL);
}
function doPrint() {
	if (window.print!=undefined)
		window.print();
}
function clean(sIn) {
	var sTemp=sIn.trim();

	sTemp=sTemp.replace(/“/g,"\"")
				.replace(/”/g,"\"")
				.replace(/…/g,"...")
				.replace(/’/g,"'")
				.replace(/‘/g,"'")
				.replace(/–/g,"-")
				.replace(/—/g,"-")
				.replace(/	/g," ")
				.replace(/•/g,"-");
	return sTemp;
}
function mapLineBreaks(txt) {
	return txt.replace(/\r\n/g,"<br />")
				.replace(/\n/g,"<br />")
				.replace(/\r/g,"<br />");
}
function decodeMultiLine(txt) {
	return txt.replace(/<br>/gi,'\n');
}
function wordCount(txt) {
	var arr = txt.trim().split(/\s+/g);
	return arr.length;
}
function daysInMonth(year,month) {
     return 32-new Date(year,month,32).getDate();
}
function validPostcode(pc) {
	var reg=/^[a-z]{1,2}[\da-z]{1,2} \d[a-z][a-z]$/i; 
	return reg.test(pc);
}
function validEmail(email) {
	var reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
	return reg.test(email);
}
function validInt(sVal) {
	var re=/(^\d+$)/;
	return (re.test(sVal));
}
function validNumeric(sVal) {
	var re=/(^\d+$)|(^\d+\.\d+$)/;
	return (re.test(sVal));
}
function isInteger(sName) {
	return validInt(getElement(sName).value);
}
function isNumeric(sName) {
	return validNumeric(getElement(sName).value);
}
function isDate(sNameDD,sNameMM,sNameYYYY,bRequired) {
	var bValid=false;
	var DD=getElement(sNameDD).value;
	var MM=getElement(sNameMM).value;
	var YYYY=getElement(sNameYYYY).value;
	
	if (!bRequired && DD.length==0 && MM.length==0 && YYYY.length==0)
		bValid=true;
	else {
		if (DD.length<=2 && MM.length<=2 && YYYY.length<=4) {
			MM=(1*MM)-1;
			var dateTest=new Date(YYYY,MM,DD);
			if (dateTest.getDate()==DD && dateTest.getMonth()==MM && dateTest.getFullYear()==YYYY)
				bValid=true;
		}
	}
	return bValid;
}
function makenumeric(strIn) {
	var s="";
	for (var i=0 ; i<strIn.length ; i++) {
		var c=strIn.charAt(i);
		if (c=="1" || c=="2" || c=="3" || c=="4" || c=="5" || c=="6" || c=="7" || c=="8" || c=="9" || c=="0" || c=="." )
			s+=c;
	}
	if (s.length==0) s="0";
	return s;
}
function makeCookie(sName,sValue,Expiry,Path,Domain,Secure) {
	if (Expiry!=null && !isNaN(Expiry)) {
		var datenow = new Date();
		datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
		Expiry = datenow.toGMTString();
	}
	Expiry=(Expiry) ? '; expires='+Expiry : '';
	Path=(Path) ? '; path='+Path : '';
	Domain=(Domain) ? '; domain='+Domain : '';
	Secure=(Secure) ? '; secure' : '';

	document.cookie=sName+'='+escape(sValue)+Expiry+Path+Domain+Secure;
}
function updateCookie(sName,sKey,sValue) {
	removeFromCookie(sName,sKey);
	var sTemp=readCookie(sName);
	if (sTemp==null) sTemp="";
	sTemp=sTemp+"~"+sKey+"|"+sValue;
	makeCookie(sName,sTemp,365,'index.html','',false);
}
function removeFromCookie(sName,sKey) {
	var sFind="~"+sKey+"|";
	var sTemp=readCookie(sName)+"";
	var start=sTemp.indexOf(sFind);
	var finish = sTemp.substring(start+1,sTemp.length);

	if (finish.indexOf('~')==-1) {
		if (start!=-1) sTemp=sTemp.substring(0,start);
	}
	else {
		if (start!=-1) sTemp=sTemp.substring(0,start)+sTemp.substring(start + finish.indexOf('~')+1,sTemp.length);
	}
	makeCookie(sName,sTemp,365,'index.html','',false);
}
function readCookie(sName) {
	var cookies=' '+document.cookie;
	
	if (cookies.indexOf(' '+sName+'=')==-1) return null;

	var start=cookies.indexOf(' '+sName+'=')+(sName.length + 2);
	var finish=cookies.substring(start,cookies.length);
	finish=(finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');

	var ret=unescape(cookies.substring(start,finish).trim());
	return (ret=='null' ? null : ret);
}
function clearOption(opts) {
    for (var i=opts.length-1 ; i>=0 ; i--)
        opts.options[i]=null;
}
function doLoad() {
	if (typeof(GLoad)!='undefined') GLoad();
}
function doUnload() {
	if (typeof(GUnload)!='undefined') GUnload();
}
function inputFocus(o) {
	o.value='';
}
function inputBlur(o,def) {
	if (o.value=='') o.value=def;
}