function popup( strURL, intW, intH, strName ) 
{var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=1' );obwindow.focus();obwindow.moveTo(50,50);}

function popup2( strMsg, strURL, intW, intH, strName ) 
{if (confirm(strMsg)) {var obwindow = window.open( strURL, strName, 'width='+intW+',height='+intH+',resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=1' );obwindow.focus();obwindow.moveTo(50,50);}}

 function ValidateForm(TheForm){
	var msg="-----------------------------------------------\n     * Email address validation error\n-----------------------------------------------\n";
	var msg2="\nYou must include an accurate email address for a response.\n\nPlease verify that your email address is valid.";
	var msg3="\n\nEmail address should be in the following format: \nexample@example.com"
	if (EmailCheck(trimString(TheForm.email.value))){
		if ( TheForm.PostCode ) {if ( trimString(TheForm.PostCode.value).length > 0 ) {if ( validPostcode(TheForm.PostCode) ) {return true;} else {return false;}}} else {return true;}
		}else{alert(msg + msg2 + msg3);TheForm.email.value="";TheForm.email.focus();return false;}
 }

function EmailCheck(src) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }

function trimString(strString){
	//trim trailing spaces
	while (strString.charAt(strString.length-1)==' ')
	{strString=strString.substring(0,strString.length-1);}
	//trim leading spaces
	while (strString.charAt(0)==' ')
	{strString=strString.substring(1,strString.length);}
	return strString;
}

function borders ()
{//Temp Fix //Len is too long
var d=document.all;var l=d.length;for ( var i=0; i < l ; i++)if(d[i].tagName=='DIV'){s=d[i].style;if(s.p){void(s.border=s.p);void(s.p=null)}else{void(s.border='0px');}}
}

function validateCheckCalc( frm ){
	if (!validPostcode(frm.postcode)) {return false;}else{
		//check for valid radio selection
		var go = false;
		if (frm.PTID) {	
			var i = 0;
			for (i = 0; i < frm.PTID.length; i++){if (frm.PTID[i].checked) {go = true;}}
		}else{go = true;}
		if (go) {frm.btn_submit.disabled=true; frm.btn_submit.value='wait...';return true;
		}else{alert('Please select an option');return false;}
	}
}

function cOn ( strID ){
	document.getElementById(strID).style.backgroundColor='#f7f7f7';
}

function cOff ( strID ){
	document.getElementById(strID).style.backgroundColor='#fff';
}

function validateEmailFriend(form) {
	var error = "";

			if (form.email1) {
				if (trimString(form.email1.value) == "") {error += "* Please enter an email address in E-mail One. \n";} else {
					if ( EmailCheck( trimString(form.email1.value) ) == false ) {error += "* Please enter a valid email address in E-mail One. \n";}
				}
			}

			if (form.email2) {
				if (trimString(form.email2.value) != "") {
					if ( EmailCheck( trimString(form.email2.value) ) == false ) {error += "* Please enter a valid email address in E-mail Two. \n";}
				}
			}
			
			if (form.email3) {
				if (trimString(form.email3.value) != "") {
					if ( EmailCheck( trimString(form.email3.value) ) == false ) {error += "* Please enter a valid email address in E-mail Three. \n";}
				}
			}

			if (form.yourname) {
				if ( trimString(form.yourname.value) == "" ) {error += "* Please enter your name. \n";} else {
					if ( trimString(form.yourname.value) < 2 ) {error += "* Your name must be at least 2 characters long. \n";} else {
					if ( trimString(form.yourname.value) > 50 ) {error += "* Your name must be no more than 50 characters long. \n";}
				}
				}
			}
			
			if (form.youremail) {
				if (trimString(form.youremail.value) == "") {error += "* Please enter your email address. \n";} else {
					if ( EmailCheck( trimString(form.youremail.value) ) == false ) {error += "* Please enter a valid email address in Your E-mail. \n";}
				}
			}
			
			if (form.yourmessage) {
				if ( trimString(form.yourmessage.value) != "" ) {
					if ( trimString(form.yourmessage.value).length < 10 ) {error += "* Your message must be at least 10 characters long. \n";} else {
					if ( trimString(form.yourmessage.value).length > 300 ) {error += "* Your message must be no more than 300 characters long. \n";}
				}
				}
			}
			

			if (error != "")
			{
				var msg="-------------------------------------------------------------------\n                      Form validation error\n-------------------------------------------------------------------\n";
				alert(msg + error);
				return (false);
			} else {
				return confirm('Are you sure?');
			}

}

