
function testResForm()
{
  if (document.reservation.pid.value == "") {
    alert("You Must Choose A Resort");
  } else {
		if (document.reservation.doa_mm.selectedIndex == document.reservation.dod_mm.selectedIndex && document.reservation.doa_dd.selectedIndex == document.reservation.dod_dd.selectedIndex){
			alert("Your Arrival and Departure dates cannot be the same.")
			}
		else {
	
			//write selections to cookie
			//added by craig mcleod 9_01_02
			var selections=''
	
	
			if (document.reservation.pid.type == "select-one"){
				//SetCookie("pid",document.reservation.pid.selectedIndex);
				selections = "pid##" + document.reservation.pid.selectedIndex;
				}
			selections = selections + "*doa_mm##" + document.reservation.doa_mm.selectedIndex;
			selections = selections + "*doa_dd##" + document.reservation.doa_dd.selectedIndex;
			selections = selections + "*dod_mm##" + document.reservation.dod_mm.selectedIndex;
			selections = selections + "*dod_dd##" + document.reservation.dod_dd.selectedIndex;
			selections = selections + "*num_adults##" + document.reservation.num_adults.selectedIndex;
			selections = selections + "*num_rooms##" + document.reservation.num_rooms.selectedIndex;
	
			SetCookie("rrDateSelections",selections);
	
			//end craig mcleod edit
			querystr="http://www.netbooker.com/booker/AppLogic+booker.hotel.book.AvailResp?iid=OG&brand=RS&availreq=Y"
			for (i=0; i<(document.reservation.length); i++)
				{
				if ( document.reservation[i].name.lastIndexOf('_mm')>0 )
					{
					querystr = querystr + "&" + document.reservation[i].name + "="+ (Number(document.reservation[i].value)-1)
					}
				else
					{
					querystr = querystr + "&" + document.reservation[i].name + "="+ document.reservation[i].value
					}
				}
			peg_window = window.open(querystr,'pegasus_res','width=703,height=462, top=153, left=10, toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes')
			peg_window.focus()
			
			return false
			//document.reservation.submit();
			}
  }
}


function passResAdvOptions() {
	var resort = document.reservation.pid.value;
	var arrmonth = document.reservation.doa_mm.selectedIndex + 1;
	var arrday = document.reservation.doa_dd.selectedIndex + 1;
	var depmonth = document.reservation.dod_mm.selectedIndex + 1;
	var depday = document.reservation.dod_dd.selectedIndex + 1;
	var guests = document.reservation.num_adults.value;
	var rooms = document.reservation.num_rooms.value;
	
	querystr = "/gen.detailedreservations.asp?resort=" + resort + "&arrmonth=" + arrmonth + "&arrday=" + arrday + "&depmonth=" + depmonth + "&depday=" + depday + "&guests=" + guests + "&rooms=" + rooms;
	location.href=querystr;
}

function ChkEmail(theAddress) 
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.@";
  var checkStr = theAddress;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

	if (theAddress == "")
	{	alert("Email is a required field!");
		return false;
	}
	
	if (theAddress.indexOf("@") == -1) 
	{	alert("Sorry, the email address you entered does not contain an '@' symbol.");
		return false;
	}
	
	if (theAddress.indexOf(".") == -1) 
	{	alert("Sorry, the email address you entered does not contain a '.' symbol.");
		return false;
	}	
	
	if (theAddress.indexOf("@.") != -1) 
	{
		alert("Sorry, the email address you entered is missing a valid character after the '@' sign and before the first period.");
		return false;
	}
	
	if (!allValid)
	{
		alert("Sorry, the email address you entered contains invalid characters.");
		return false;
	}
	else
	{  
	return true;
	} 
}

function ChkEmailSpanish(theAddress) 
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.@";
  var checkStr = theAddress;
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

	if (theAddress == "")
	{	alert("El correo electrónico es un campo obligatorio!");
		return false;
	}
	
	if (theAddress.indexOf("@") == -1) 
	{	alert("Lo sentimos, la dirección de correo electrónico que ha introducido no contiene un símbolo '@'.");
		return false;
	}
	
	if (theAddress.indexOf(".") == -1) 
	{	alert("Lo sentimos, la dirección de correo electrónico que ha introducido no contiene un '.' símbolo.");
		return false;
	}	
	
	if (theAddress.indexOf("@.") != -1) 
	{
		alert("Lo sentimos, la dirección de correo electrónico que ha introducido no se encuentra un carácter válido después del símbolo '@' y antes del primer período.");
		return false;
	}
	
	if (!allValid)
	{
		alert("Lo sentimos, la dirección de correo electrónico que ha introducido contiene caracteres no válidos.");
		return false;
	}
	else
	{  
	return true;
	} 
}

function findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function validateForm() { //updated by Andrew F. to capitalize field names
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
	test=args[i+2]; val=findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { 
		p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+pcase(nm)+' must contain an e-mail address.\n';
      } 
      else if (test!='R') {
        if (isNaN(val)) errors+='- '+pcase(nm)+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) {
			p=test.indexOf(':');
			min=test.substring(8,p); max=test.substring(p+1);
			if (val<min || max<val) errors+='- '+pcase(nm)+' must contain a number between '+min+' and '+max+'.\n';
		} 
	  } 
	} 
    else if (test.charAt(0) == 'R') errors += '- '+pcase(nm)+' is required.\n'; }
  }
  // begin: regretfully added by craig mcleod
  
  // if Resort field exisits at all then continue
  if (document.brochure.Resort != null) {
	// if more than 1 resort field then look for checked boxes
	if (document.brochure.Resort.length > 1) {
  
		var bolChooseResort;
		bolChooseResort = false;
	
		// cycle through resort check boxes
		for (i=0; i<(document.brochure.Resort.length); i+=1) {
			bolChooseResort = (bolChooseResort || document.brochure.Resort[i].checked)
			} 
		if (!bolChooseResort) {
			errors+='- At least one resort must be checked.\n';
			}
		}
	}
  // end: regretfully added by craig mcleod
  if (errors) alert('The following error(s) occurred:\n'+errors);
  document.returnValue = (errors == '');
}


function pcase(str) {
	strlen = str.length
	jj = str.substring(0,1).toUpperCase()
	// jj = jj + str.substring(1,strlen).toLowerCase()
	jj = jj + str.substring(1,strlen) // leave rest as is
	for (i = 2; i <= strlen; i++) {
		if (jj.charAt(i)==" ") {
		lefthalf = jj.substring(0,i+1)
		righthalf = jj.substring(i+1,strlen)
		righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
		jj=lefthalf+righthalf
		}
	}
	return jj
}

