function errorMessage(strField, strMessage){
	alert(strMessage);
	strField.focus(); 
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function CheckField (strField, strMessage, strType){
	switch (strType){
		case(n="TEXT"):
			if (strField.value==""){
				errorMessage(strField, strMessage)	
				return false;
			}
			return true;
		break;

		//assumption "non functional" elements will have 0 as element
		case(n="DROPDOWN"):
			if (strField.value=="0"){
				errorMessage(strField, strMessage)	
				return false;
			}
			return true;
		break;

		case(n="CHECKBOX"):
			for (var i = 0; i < strField.length ; i++)
			{
				if (strField[i].checked)
				{
					return true;	
				}
			}
			
			errorMessage(strField[0], strMessage)
			return false;
			break;
				
		
		case(n="NUMERIC"):
			
			/*if (strField.value.length == 0)
			{		
				errorMessage(strField, strMessage)	
				return false;
			}*/
			for (i=0; i < strField.value.length; i++) {
				if (isNaN(strField.value.charAt(i))){
					errorMessage(strField, strMessage)	
					return false;
				}
			}
			return true;
		break;

		case(n="EMAIL"):
			if (strField.value.search(/^[a-z0-9]+((\.|!|_|\+|\-)[a-z0-9]+)*@([a-z0-9]+(\.|\-))+[a-z0-9]{2,}$/i) != -1) {
				return true;
			} else {
				errorMessage(strField, strMessage);	
			return false;
			}
		break;

		case(n="PHONE"):
			if (strField.value==""){
				errorMessage(strField, strMessage)	
				return false;
			}
			for (i=0; i < strField.value.length; i++) {
				ch = strField.value.charAt(i);
				if (ch == ")" || ch == "(" || ch == "-" || ch == " " || ch == " ") continue;
				if (!isDigit(ch)) {
					errorMessage(strField, strMessage)	
					return false;
				}
			}
			return true;
		break;
		
		case(n="DATE"):
			var nMonth
			nMonth = parseInt(strField.value.substring(0,2), 10)
			if (!isDigit(strField.value.charAt(0)) 
				|| !isDigit(strField.value.charAt(1))
			    || strField.value.charAt(2) != "/"
				|| !isDigit(strField.value.charAt(3))
			    || !isDigit(strField.value.charAt(4)) 
				|| nMonth <0 || nMonth >12 )
				{
					errorMessage(strField, strMessage)	
					return false;
				}
				return true;
			break;

	case(n="PASSWORD"):
				if (document.forms[0].elements["password"].value==""){
					return true;
					break;
				}
				
				if  (document.forms[0].elements["password"].value.length < 4){
					alert("If entering a password please ensure that is contains at least 4 characters.");
					document.forms[0].elements["password"].focus();
					return false;
					break;
				}
			   	
				 if (document.forms[0].elements["password"].value.length > 3){
					 if (document.forms[0].elements["password"].value !== document.forms[0].elements["passwordretype"].value){
						alert("Please ensure that your passwords match");
						document.forms[0].elements["passwordretype"].focus();
						return false;
						break;
					 }
					 else {
						return true;
						break;
				     }
				 }
				 break;

		case(n="CHANGEPASSWORD"):

				if  (document.forms[0].elements["OldPassword"].value.length == 0){
					alert("Please enter your old password");
					document.forms[0].elements["OldPassword"].focus();
					return false;
					break;
				}

				
					
				if  (document.forms[0].elements["password"].value.length < 4){
					alert("Your new password must contain at least 4 characters");
					document.forms[0].elements["password"].focus();
					return false;
					break;
				}
			   	
				
				if (document.forms[0].elements["password"].value != document.forms[0].elements["RetypePassword"].value)
				{
					alert("Please ensure that your passwords match");
					document.forms[0].elements["RetypePassword"].focus();
					return false;
					break;
				 }
					
				return true;
				break;

				case(n="CREATEPASSWORD"):
					/*Does not allow empty password - in oppose to (n=PASSWORD)*/
			
				if  (document.forms[0].elements["password"].value.length < 4){
					alert("Your password must contain at least 4 characters");
					document.forms[0].elements["password"].focus();
					return false;
					break;
				}
			   	
				
				if (document.forms[0].elements["password"].value != document.forms[0].elements["RetypePassword"].value)
				{
					alert("Please ensure that your passwords match");
					document.forms[0].elements["RetypePassword"].focus();
					return false;
					break;
				 }
					
				return true;
				break;
				   
				

		case(n="CHANGEEMAIL"):
			if (document.forms[0].elements["email"].value != document.forms[0].elements["RetypeEmail"].value)
			{
				alert("Please ensure that your email addresses match");
				document.forms[0].elements["RetypeEmail"].focus();
				return false;
				break;
			 }
			if (document.forms[0].elements["email"].value.search(/^[a-z0-9]+((\.|!|_|\+|\-)[a-z0-9]+)*@([a-z0-9]+(\.|\-))+[a-z0-9]{2,}$/i) == -1) {
				alert("Please enter valid email addresses")
				document.forms[0].elements["email"].focus();
				return false;
				break;
			}
		
		
			return true;	
			break;
		
		case(n="DD_MMM_YYYY_DATE"):
			if (!Valid_DD_MMM_YYYY_Date(strField.value)){
				errorMessage(strField, strMessage)	
				return false;
			}
			return true;
		break;

		case(n="CARD"):

			if (strField.value=="" || strField.value.length < 14){
					errorMessage(strField, strMessage)	
					return false;
			}

			for (i=0; i < strField.value.length; i++) {
				ch = strField.value.charAt(i);
			
		  	if (ch == " ") continue;
			  if (!isDigit(ch) ) {
				errorMessage(strField, strMessage)	
				return false;
				}
			}
			return true;
		break;
		
		default:
			if (strField.value==""){
				errorMessage(strField, strMessage)	
				return false;
			}
			return true;
			break;
	}//end switch
}//end function


function changeimage(imgname,newimage) {
	if (document.images) {
	document.images[imgname].src= newimage ;
	}
}

function Form_onsubmit(){
	// Validate fields 
	if (CheckForm() ) {
		return true; }
	else {
	return false;
	}
}

function loadimages() {
	myimg = new Array()
	a=loadimages.arguments

	for (i=0;i<a.length;i++) {
		myimg[i] = new Image
		myimg[i].src=a[i]
	}
}

function showhelp(phraseNo, strLang){
	dummy = window.open("/general/help.asp?PhraseNo=" +  phraseNo + "&StrLang=" + strLang,"explain","dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=520,height=300,resizable=yes,scrollbars=yes,screenx=100,left=100,screeny=100,top=100");
	dummy.focus();
}
	

function OpenSpecialOffers(hotelCode, showDisc)
		{
			newwindow = window.open("HotelSpecialOffers.asp?Hotel_Code=" + hotelCode + "&UUID=<%=strUUID%>&showDisc=" + showDisc+"&lang=<%=strLang%>","popup" ,"dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=450,height=350,resizable=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100"); 
			newwindow.focus()
		}

		function OpenHotelRemarks(optionId)
		{
           
			newwindow = window.open("/popups/HotelRemarks.asp?optionid=" + optionId + "&UUID=<%=strUUID%>&lang=<%=strLang%>", "popup", "dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=518,height=350,resizable=yes,scrollbars=yes, screenX=100,screenY=100,top=100,left=100");
			newwindow.focus();
		}

		function OpenPriceBreak(hotelCode, finalAmount, showDisc, specialOffer,optionId)
		{
			newwindow = window.open("/booking/PriceBreak.asp?optionid=" + optionId + "&HotelCode=" +hotelCode + "&UUID=<%=strUUID%>&FinalAmount=" + finalAmount + "&showDisc=" + showDisc+ "&specialOffer=" + specialOffer +"&lang=<%=strLang%>"+"&cur=<%=strCur%>" , "popup", "dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=450,height=350,resizable=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100");
			newwindow.focus();
		}
		
		function OpenPriceSummary(hotelCode, finalAmount, showDisc, specialOffer,optionId, type)
		{
			newwindow = window.open("/booking/PriceBreak.asp?optionid=" + optionId + "&HotelCode=" +hotelCode + "&UUID=<%=strUUID%>&FinalAmount=" + finalAmount + "&showDisc=" + showDisc+ "&specialOffer=" + specialOffer +"&lang=<%=strLang%>"+"&cur=<%=strCur%>" + "&type=" + type , "popup", "dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=450,height=350,resizable=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100");
			newwindow.focus();
		}
		function showbookinfo()
{
	dummy = window.open("common/<%=strLang%>/bookinginfo.htm","explain","dependent=yes,toolbar=no,menubar=no,status=no,directories=no,width=500,height=200,resizable=yes,scrollbars=yes,screenx=100,left=100,screeny=100,top=100");
	dummy.focus()
}

// this function pops open the hotel images
function showpic(theURL,winName,features) { 
		
		//popup = window.open(theURL,winName,features)
		popup = window.open(theURL,"", features);
		popup.focus();
	  
  } 		
//end

// this function prints the correct frame in the destinations section

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(frame, arg) {
  if (frame == window) {
    printThis();
  } else {
    link = arg; // a global variable 
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function Valid_DD_MMM_YYYY_Date(strFullDate)
{
	var iDay, strMonth, iYear;
	var cSeparator1, cSeparator12;
	var iMaxDate
	var d
	
	d = new Date()
	
	if (strFullDate.length != 11)
		return false;
	
	iDay = strFullDate.substring(0,2);
	cSeparator1 = strFullDate.substring(2,3);
	strMonth = strFullDate.substring(3,6).toUpperCase();
	cSeparator12 = strFullDate.substring(6,7);
	iYear = strFullDate.substring(7,11);
	
	if (cSeparator1 != cSeparator12 || (cSeparator1 != "/" && cSeparator1 != " " && cSeparator1 != "-" ))
		return false;
	
	if (strMonth != "JAN" && strMonth != "FEB" && strMonth != "MAR" &&
		strMonth != "APR" && strMonth != "MAY" && strMonth != "JUN" &&
		strMonth != "JUL" && strMonth != "AUG" && strMonth != "SEP" &&
		strMonth != "OCT" && strMonth != "NOV" && strMonth != "DEC")
			return false;
	
	if (iDay.charAt(0).isNaN || iDay.charAt(1).isNaN)
		return false;
	
	if (iYear.charAt(0).isNaN || iYear.charAt(1).isNaN|| 
		iYear.charAt(2).isNaN || iYear.charAt(3).isNaN)
		return false;
	
	if (iYear < 1900 || iYear > d.getFullYear())
		return false;
	
	if (strMonth == "JAN" || strMonth == "MAR" || strMonth == "MAY" ||
		strMonth == "JUL" || strMonth == "AUG" || strMonth == "OCT" || 
		strMonth == "DEC")
			
			iMaxDate = 31
	else
		if (strMonth == "APR" || strMonth == "JUN" || strMonth == "SEP" ||
		    strMonth == "NOV")
			iMaxDate = 30
		else //strMonth = "Feb"
		
			if (iYear % 4 == 0)
				iMaxDate = 29
			else
				iMaxDate = 28
		

	

	if (iDay < 1 || iDay > iMaxDate)
		return false;

	return true;
	
}

//end
