/* --------------------------------------------------------------------------------
This file contains javascript functions that are commonly used throughout the 
Bedsearcher application. Coded (often poorly) by S C Turnbull 
s.turnbull@bedsearcher.co.uk
--------------------------------------------------------------------------------- */
var ver = navigator.appName;
var num = parseInt(navigator.appVersion);
//validateMailingListEmail
function validateMailingListEmail(form){
if(!isValidEmailFormat(form.email.value)){
	alert("Please enter a valid E-mail address")
	form.email.focus()
	form.email.select()
	return false;}
return true;}
// bookmarkSite()
function bookmarkSite(){
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
var url = "http://www.bedsearcher.co.uk";var who = "Bedsearcher - UK Accommodation";
window.external.AddFavorite(url,who);}}
// isValidDate() a piss simple function that checks to see if a date is valid;
function isValidDate(DD,YYYYMM){
var day 	= DD
var month 	= (YYYYMM.substring(5,7)-1)
var year 	= YYYYMM.substring(0,4)
var dteDate = new Date(year,month,day);
if((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear())){
return true;}
else{return false;}}
// isAlphaNumeric() 
function isAlphaNumeric(usersinput){
var matchpattern = /\W/;
usersinput2 = new String(usersinput.match(matchpattern));
if(usersinput2.length == 1){return false;}
return true;}
// isGridRef() 
function isGridRef(usersinput){
var matchpattern = /\W/;
var matchpattern2 = /\d/;
var matchpattern3 = /\D/;
var firstChar = usersinput.charAt(0);
var secondChar = usersinput.charAt(1);
if(usersinput.length < 8){return false;}
firstChar1 = new String(firstChar.match(matchpattern));
/* We have a non alphanumeric char at position 1 */
if(firstChar1.length == 1){return false;}
firstChar2 = new String(firstChar.match(matchpattern2));
/* We have a non numeric char at position 1 */
if(firstChar2.length == 1) {return false;}
secondChar1 = new String(secondChar.match(matchpattern));
if(secondChar1.length == 1){return false;}
secondChar2 = new String(secondChar.match(matchpattern2));
if(secondChar2.length == 1) {return false;}
/* Loop through the 6 remaining Chars */
for(i=2; i<8; i++){
	var nthchar = usersinput.charAt(i);
	nthchar2 = new String(nthchar.match(matchpattern3));
	if(nthchar2.length == 1) {return false;}	
	}
return true;
}
// isValidEmailFormat() checks for a valid email address format
function isValidEmailFormat(email){
invalidChars="/:,;!£$%^&*()+={}|?~#\<>[]"
if(email == ""){return false}
for(i=0;i<invalidChars.length;i++){
badChar = invalidChars.charAt(i)
if(email.indexOf(badChar,0) > -1){return false}}
atPos = email.indexOf("@",1)
if(atPos == -1){return false}
if(email.indexOf("@",atPos+1) != -1){return false}
periodPos = email.indexOf(".",atPos)
if(periodPos == -1){return false}
if(periodPos+3 > email.length){return false}
return true}
// dateSelect()
function dateSelect(appliesTo){
var url = '/index.cfm?fuseaction=bedseeker.calendar&appliesTo=' + appliesTo
send = window.open(url,'dateselect','width=310,height=200,toolbar=no,location=no,menubar=no,status=no,resizable=no,title=yes') 
send.focus();}
// changeCursor()
function changeCursor(elm){elm.style.cursor = 'hand';}
// changeDsp()
function changeDsp(arg1){
var thisElem = document.getElementById(arg1)
if(thisElem.style.display==''){thisElem.style.display='none';}
else{thisElem.style.display=''}}
// dspDayOfWeekPattern()
function dspDayOfWeekPattern(yesNo){
if(yesNo == 1){document.getElementById('dayOfWeekPatternTR').style.display='';}
else{document.getElementById('dayOfWeekPatternTR').style.display='none';}}






