// JavaScript Document
<!--
function openWindow(thePostcode,theWidth,theHeight,theType){
	if(thePostcode != ''){
		if(theType == '1'){
			theUrl = 'http://maps.google.co.uk/maps?f=q&hl=en&q='+thePostcode+'&ie=UTF8&z=13&om=1&iwloc=addr';
		}else theUrl = thePostcode;
		window.open(theUrl,'MapWindow','width='+theWidth+',height='+theHeight+',scrollbars=1,resizable=1');
	}
	else{
		alert('We don\'t have a Map for this property currently.\nPlease try again later.');
	}
}
function popImage(imageURL,imageTitle,pos,AutoClose,CopyRight){
	//Safari workaround
	if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1){
	var f="top=0, left=0, width="+screen.width+",height="+screen.height+" ,scrollbars=yes";
	imgWin=window.open(imageURL,'im',f);
	}
	else{
	//Based on browser set correct resize mode
	if (parseInt(navigator.appVersion.charAt(0))>=4){
		if (navigator.appName=="Netscape"){
		var f="width="+screen.width+",height="+screen.height;	
		var rs="var iWidth=window.innerWidth;iHeight=window.innerHeight";
		var adj="0";
		}
		if(document.all){
		var f="width=150,height=150";	
		var rs = "var iWidth=document.body.clientWidth;iHeight=document.body.clientHeight;";
			if(typeof window.opera != 'undefined'){ 
			 var adj="window.outerHeight-24";
			 }
			else{
			var adj="32";
			}	 
		} 
	}
	//
	v=pos.substring(0,pos.indexOf("_"));
	h=pos.substring(pos.indexOf("_")+1);
	f+=",left=0,top=0";
	imgWin=window.open('about:blank','',f);
	imDoc=imgWin.document;
	with (imDoc){
		writeln('<html><head><title>Loading...</title>');writeln('<sc'+'ript>');
		writeln('var sdstr=\"\";window.onerror=function(){return true;}');
		writeln('function resizeWin(){');
		//If the image size is bigger then screen resize window to the screen size
		writeln('iW=document.images[0].width;iH=document.images[0].height;sW=screen.availWidth;sH=screen.availHeight;');
		writeln('if(iW>=sW || iH>=sH){window.resizeTo(sW,sH);window.moveTo(0,0)}else{')
		writeln(rs);
		writeln('var v=\"'+v+'\";var h=\"'+h+'\";');
		writeln('switch (v){case \"top\":vPos=0;break;case \"middle\":vPos=(sH-iH-'+adj+')/2;break;case \"bottom\":vPos=sH-'+adj+'-iH;break;default: vPos=0;}');
		writeln('switch (h){case \"left\":hPos=0;break;case \"center\":hPos=(sW-iW)/2;break;case \"right\":hPos=sW-iW;break;default: hPos=0;}');
		writeln('iWidth = document.images[0].width - iWidth;iHeight = document.images[0].height - iHeight;');
		writeln('window.resizeBy(iWidth, iHeight);');
		writeln('window.moveBy(hPos,vPos)}}');
		writeln('function doTitle(){document.title="'+unescape(imageTitle)+'";}'+'</sc'+'ript>');
		var cT=(!AutoClose)?"":"onBlur=\"sdstr=setTimeout('window.close(this)',1000)\"";
		//Prevent closing in IE
		var fL=(!AutoClose)?"":"onfocus=\"clearTimeout(sdstr)\"";
		if(!CopyRight){var cr1="";var cr2=""}else{var cr1=" galleryimg=\"no\" title=\"Copyright Protected\" onmousedown=\"window.close()\" ";var cr2="oncontextmenu=\"return false\" "}
		writeln('</head><body  leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"FFFFFF\" onload="resizeWin();doTitle();self.focus()" '+cT+' '+fL+' '+cr2+'>');
		writeln('<div '+fL+' align=\"center\" style=\"width:100%;height:100%;overflow:auto\"><img src="'+imageURL+'" '+cr1+'></div></body></html>');
		close();
		}
	}
}
function validField(fieldName,fieldDesc,testBlank,typeValid,extraChars,minChars,maxChars) {
// ... test for blank field 
   if (testBlank == "noblank") {
      if (fieldName.value == "") {
         errorFound=true;
         errorMessage=errorMessage+"\n  * "+fieldDesc+" can't be blank";
         if ( firstError ) {
            firstError=false;
            errorField=fieldName;
         }
      }
   }
// ... test each character for numeric or extra list of chars
   if (typeValid=="numeric") {
      invalidChar=false
      testString=fieldName.value      
      for (i=0; i<testString.length; i++) {
         testChar=testString.charAt(i)         
         if (!(testChar>="0" && testChar<="9")) {            
            if (extraChars.indexOf(testChar,0)==-1) {
               invalidChar=true
            }        
         }
      }
      if(invalidChar) {            
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc+" must comprise 0-9"
         addExtras(extraChars)
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }
   }
// ... test each character for alpha or extra list of chars
   if (typeValid=="alpha") {
      invalidChar=false
      testString=fieldName.value      
      for (i=0; i<testString.length; i++) {
         testChar=testString.charAt(i)         
         if (!(testChar>="a" && testChar<="z") && !(testChar>="A" && testChar<="Z")) {            
            if (extraChars.indexOf(testChar,0)==-1) {
               invalidChar=true
            }        
         }
      }
      if(invalidChar) {            
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc+" must comprise a-z"
         addExtras(extraChars)
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }
   }
// ... test each character for alphanumeric or extra list of chars
   if (typeValid=="alphanumeric") {
      invalidChar=false
      testString=fieldName.value      
      for (i=0; i<testString.length; i++) {
         testChar=testString.charAt(i)         
         if (!(testChar>="a" && testChar<="z") && !(testChar>="A" && testChar<="Z") && !(testChar>="0" && testChar<="9")) {            
            if (extraChars.indexOf(testChar,0)==-1) {
               invalidChar=true
            }        
         }
      }
      if(invalidChar) {            
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc+" must comprise a-z or 0-9"
         addExtras(extraChars)
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }
   }  
// ... test each character for email
	if (typeValid=="email") {
      invalidChar=false
      testString=fieldName.value
	  var invalidPatterns = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	  var validPatterns = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 
      	
		if (window.RegExp) { 
	 
		  if (!invalidPatterns.test(testString) && validPatterns.test(testString)) { 
		  } 
		  else {
		   invalidChar = true;
		  }
		  if(testString.indexOf("@") < 0){
			   invalidChar = true; 
		  } 
		 
		}
		  if(invalidChar) {            
			 errorFound=true
			 errorMessage=errorMessage+"\n  * "+fieldDesc+" must be a valid email address"
			 addExtras(extraChars)
			 if (firstError) {
				firstError=false
				errorField=fieldName
			 }
		  }
	   
	}
// ... test for exclusion list of chars
   if(typeValid=="banchars") {
      for (i=0; i<extraChars.length; i++) {
         badChar=extraChars.charAt(i)
         if (fieldName.value.indexOf(badChar,0) > -1) {
            errorFound=true
            if (badChar=="\'"||badChar=="\"") {
               errorMessage=errorMessage+"\n  * "+fieldDesc+ " can not contain the character '"+badChar+"'"
            }
            else {
               errorMessage=errorMessage+"\n  * "+fieldDesc+ " can not contain the character '"+badChar+"'"
            }
            if ( firstError ) {
               firstError=false
               errorField=fieldName
            }         
         }
      }
   }
// ... test for checked box
   if (typeValid=="checked") {      
      if(!fieldName.checked) {            
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc
         addExtras(extraChars)
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }
   } 
// ... test for minimum character length if something entered 
   if (minChars>=1) {
      testString=fieldName.value
      if (testString.length>0 && testString.length<minChars) {
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc+" must be at least "+minChars+" char"
         if (minChars>1) {
            errorMessage=errorMessage+"s"
         }
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }
   }
// ... test for maximum character length
   if (maxChars>=1) {
      testString=fieldName.value
      if (testString.length>maxChars) {
         errorFound=true
         errorMessage=errorMessage+"\n  * "+fieldDesc+" must be no more than "+maxChars+" char"
         if (maxChars>1) {
            errorMessage=errorMessage+"s"
         }
         if (firstError) {
            firstError=false
            errorField=fieldName
         }
      }      
   }
}
// ... routine to add display of extra chars to error message
function addExtras(extraChars) {
   for (i=0; i<extraChars.length; i++) {
      goodChar=extraChars.charAt(i)
      errorMessage=errorMessage+" or "
      if (goodChar==" ") {
         errorMessage=errorMessage+"'space'"
      }
      else {
         errorMessage=errorMessage+"'"+goodChar+"'"
      }
   }
}
// ... special routine to check credit card expiry date
function validExpdate(expMonth,expYear,cardNum,errorText) {
   now=new Date
   currentMonth=now.getMonth()+1
   currentYear=now.getFullYear()-2000   
   currentDate=currentMonth+100*currentYear
   exMonth=parseInt(expMonth.value,10)
   exYear=parseInt(expYear.value,10)
   exDate=exMonth+100*exYear
   if (exDate<currentDate) {
      errorFound=true
      errorMessage=errorMessage+"\n"+errorText
      if (firstError) {
            firstError=false
            errorField=cardNum
      }
   }
}
// ... routine to validate any date, particularly that day of month is valid, leap year every 4 or 400, not 100
function validDate(day,month,year) {
  daysMonth=new Array (31,28,31,30,31,30,31,31,30,31,30,31)
  if( (year%4==0) && ( (year%400==0) || (year%100!=0) ) ) {
     daysMonth[1]=29
  }  
  if((month<13)&&(day<=daysMonth[month-1])) {  
     return true
  } 
  else {
     return false
  }
}   
//-->                             

