bVer = parseInt(navigator.appVersion);
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function checkpostcode(sIn){
	reg=/^[a-z]{1,2}[\da-z]{1,2} \d[a-z][a-z]$/i; 
	if (!reg.test(sIn)){
	    alert("Your postcode does not seem to be well-formed. Remember the space is part of your postcode too.");
		return false;
	}
	return true;
	
}
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 checkemailnd(email){
	emailpat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i;
	if (!emailpat.test(email)){
		return false;
	}
	return true;
}
function checkphone(sIn){
	phonepat=/^([0-9 +()])+$/i
	return phonepat.test(sIn);
}

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 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;

}

