var bVer = parseInt(navigator.appVersion);
var sOut="";
if (!((navigator.appVersion.indexOf("MSIE") == -1)&&(navigator.appVersion.substring(0,3)-4.8<0))){
	sOut="";
	document.write("<style>");
	if (!(navigator.appVersion.indexOf("MSIE") == -1)) {
		// if this is IE, work around width excluding margin
		document.write("div.midcol {	width:445px; }");
		document.write("div.content {	height:600px;overflow:visible; }");
	}
	document.write("</style>");
} else {
//netscape <4.8 on PC
	sOut="This site works best with modern browsers. Some features may not work properly with Netscape 4.x. ";			
}

function checkemail(email){
	emailpat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i;
	if (!emailpat.test(email)){
		alert("Your Email address does not appear well-formed. Please fill it in then submit again.");
		return false;
	}
	return true;
}
function makenumeric(strIn){
	s="";
	for (i=0;i<strIn.length;i++){
		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;
	}
	return s;
}
function checknumber(sIn,sError){
	//sIn.value=makenumeric(sIn.value);
	phonepat=/^([0-9 +()])+$/i
	if (sIn.value==""){
		alert("Please enter "+sError+" then submit again.");
		return false;
	}
	else if (!phonepat.test(sIn)) {
		alert("Please enter "+sError+" as a number ONLY then click 'Next' again.");
		return false;
	}
	return true;
}
function checkname(sVal) {
	var reg = /^[a-z\-\ \']+$/i;
	return reg.test(sVal);
}
function checkdate(DDMMYYYY) {
	var bOk=false;
	if (DDMMYYYY.length==10) {
		var day = (1*DDMMYYYY.substring(0,2));
		var month = (1*DDMMYYYY.substring(3,5))-1;
		var year = (1*DDMMYYYY.substring(6,10));
		var td = new Date(year,month,day);
		bOk=(yearvalid(td.getYear(),year) && month==td.getMonth() && day==td.getDate());
	}
	return bOk;
}
function yearvalid(yy,yyyy) {
	return (((yy<1000) ? yy+1900 : yy) == yyyy);
}
function confirmdelete(sURL){
	if (confirm("DELETE - are you sure you want to delete this record?")) location.replace(sURL);
}
function confirmremove(sURL){
	if (confirm("REMOVE - are you sure you want to remove this item from the homepage?")) location.replace(sURL);
}
function replaceString(sSrc, sFrom, sTo){
	sReturn=sSrc;
    iFromLen=sFrom.length;
    iToLen=sTo.length;
    iPos=0;
    iEnd=0;
    do {
        iPos=sReturn.indexOf(sFrom,iEnd);
        if (iPos!=-1) {
            sReturn = sReturn.substring(0,iPos)+sTo+sReturn.substring(iPos+iFromLen);
            iEnd=iPos+iToLen;
        }
    } while (iPos!=-1);
	return sReturn;

}
function readCookie(Name) {

var cookies = ' ' + document.cookie;
if (cookies.indexOf(' ' + Name + '=') == -1) return "";

var start = cookies.indexOf(' ' + Name + '=') + (Name.length + 2);
var finish = cookies.substring(start,cookies.length);
finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');

return unescape(cookies.substring(start,finish));
}

function makeCookie(Name,Value,Expiry,Path,Domain,Secure) {
//if you want to save the cookie
if (Expiry != null && !isNaN(Expiry)) {
	var datenow = new Date();
	datenow.setTime(datenow.getTime() + 86400000*Expiry);
	Expiry = datenow.toGMTString();
//	alert(Expiry);
}
Expiry = (Expiry) ? '; expires='+Expiry : '';
Path = (Path)?'; path='+Path:'; path=/';
Domain = (Domain) ? '; domain='+Domain : '';
Secure = (Secure) ? '; secure' : '';

document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure;

}
function lb_add(sID){
	removeFromCookie('lightbox',sID);
	var sTemp="~"+sID+readCookie('lightbox');
	if (sTemp.substring(sTemp.length-1,sTemp.length)!="~") sTemp=sTemp+"~";
	makeCookie('lightbox',sTemp,365,'','',false);
}
function lb_remove(sID){
	removeFromCookie('lightbox',sID);
	location.reload();
}
function removeFromCookie(sName,sID){
	var sFind="~"+sID+"~";
	var sTemp=readCookie(sName)+"";
	sTemp=replaceString(sTemp,sFind,"~");
	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,'','',false);
}

function clearcookies(){
	makeCookie('lightbox','',365,'','',false);
}

function moveCookie(sFrom,sTo){
	var sTemp=readCookie(sFrom);
	if (sTemp==null) sTemp="";
	makeCookie(sFrom,'',365,'','',false);
	makeCookie(sTo,sTemp,365,'','',false);
}
