// JavaScript Document

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function FDK_StripChars(theFilter,theString)
{
	var strOut,i,curChar

	strOut = ""
	for (i=0;i < theString.length; i++)
	{		
		curChar = theString.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}

function FDK_AddToValidateArray(FormName,FormElement,Validation,SetFocus)
{
    var TheRoot=eval("document."+FormName);
 
    if (!TheRoot.ValidateForm) 
    {
        TheRoot.ValidateForm = true;
        eval(FormName+"NameArray = new Array()")
        eval(FormName+"ValidationArray = new Array()")
        eval(FormName+"FocusArray = new Array()")
    }
    var ArrayIndex = eval(FormName+"NameArray.length");
    eval(FormName+"NameArray[ArrayIndex] = FormElement");
    eval(FormName+"ValidationArray[ArrayIndex] = Validation");
    eval(FormName+"FocusArray[ArrayIndex] = SetFocus");
 
}

function FDK_ValidateNonBlank(FormElement,ErrorMsg)
{
  var msg = ErrorMsg;
  var val = FormElement.value;  

  if (!(FDK_StripChars(" \n\t\r",val).length == 0))
  {
     msg="";
  }

  return msg;
}

function FDK_AddNonBlankValidation(FormName,FormElementName,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateNonBlank("+FormElementName+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

function FDK_AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}

function FDK_reformat(s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < FDK_reformat.arguments.length; i++) {
       arg = FDK_reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function FDK_ValidateEmail(FormElement,Required,ErrorMsg)
{
   var msg = "";
   var val = FormElement.value;
   var msgInvalid = ErrorMsg;

   var theLen = FDK_StripChars(" ",val).length
   if (theLen == 0)	     {
     if (!Required) return "";
     else return msgInvalid;
   }

   if (val.indexOf("@",0) < 0 || val.indexOf(".")<0) 
   {
      msg = msgInvalid;
   }
   return msg;
}

function FDK_AddEmailValidation(FormName,FormElementName,Required,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateEmail("+FormElementName+","+Required+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

function FDK_Trim(theString)
{
 var i,firstNonWhite

 if (FDK_StripChars(" \n\r\t",theString).length == 0 ) return ""

	i = -1
	while (1)
	{
		i++
		if (theString.charAt(i) != " ")
			break	
	}
	firstNonWhite = i
	//Count the spaces at the end
	i = theString.length
	while (1)
	{
		i--
		if (theString.charAt(i) != " ")
			break	
	}	

	return theString.substring(firstNonWhite,i + 1)

}

function FDK_ValidateNumChars(FormElement,Required,Minimum,Maximum,StripSpaces,ErrorMsg)     {	
	var theString = FormElement.value;
	var MinLength = Minimum;
	var MaxLength = Maximum;
	var msgInvalid = ErrorMsg;

	if (FDK_StripChars(" \n\r",theString).length == 0 && !Required)	{
       return "";
    }
	
	theString = FDK_Trim(theString);

	if (StripSpaces)      {
		theString = FDK_StripChars(" \n\r",theString);
    }
		
	if (MinLength > 0 && theString.length < MinLength)     {
		return msgInvalid;
    }
		
	if (MaxLength > 0 && theString.length > MaxLength)      {
		return msgInvalid;
	}

	// we passed the tests
	FormElement.value = theString;

	return "";
}

function FDK_AddNumCharsValidation(FormName,FormElementName,Required,Minimum,Maximum,StripSpaces,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateNumChars("+FormElementName+","+Required+","+Minimum+","+Maximum+","+StripSpaces+","+ErrorMsg+")";
  FDK_AddToValidateArray(FormName,eval(FormElementName),ValString,SetFocus)
}

function FDK_ValidateTargetEqualsSource(SourceElement,TargetElement,ClearFields,CaseSensitive,ErrorMsg)
{

	var msg = ""
	var sourceText = SourceElement.value;
	var targetText = TargetElement.value;
	var msgInvalid = ErrorMsg;
    
	if (!CaseSensitive)   {
	  sourceText = sourceText.toUpperCase();
	  targetText = targetText.toUpperCase();
	}
	
	if (sourceText != targetText)
	{
	  msg = msgInvalid
      if (ClearFields)     {
	    TargetElement.value = '';
	    SourceElement.value = '';
	  }
	}
	return msg	
}

function FDK_AddTargetEqualsSourceValidation(FormName,SourceElementName,TargetElementName,ClearFields,CaseSensitive,SetFocus,ErrorMsg)  {
  var ValString = "FDK_ValidateTargetEqualsSource("+SourceElementName+","+TargetElementName+","+ClearFields+","+CaseSensitive+","+ErrorMsg+")"
  FDK_AddToValidateArray(FormName,eval(SourceElementName),ValString,SetFocus)
}

function FDK_Validate(FormName, stopOnFailure, AutoSubmit, ErrorHeader)
{
 var theFormName = FormName;
 var theElementName = "";
 if (theFormName.indexOf(".")>=0)  
 {
   theElementName = theFormName.substring(theFormName.indexOf(".")+1)
   theFormName = theFormName.substring(0,theFormName.indexOf("."))
 }
 var ValidationCheck = eval("document."+theFormName+".ValidateForm")
 if (ValidationCheck)  
 {
  var theNameArray = eval(theFormName+"NameArray")
  var theValidationArray = eval(theFormName+"ValidationArray")
  var theFocusArray = eval(theFormName+"FocusArray")
  var ErrorMsg = "";
  var FocusSet = false;
  var i
  var msg
    
 
        // Go through the Validate Array that may or may not exist
        // and call the Validate function for all elements that have one.
  if (String(theNameArray)!="undefined")
  {
   for (i = 0; i < theNameArray.length; i ++)
   {
    msg="";
    if (theNameArray[i].name == theElementName || theElementName == "")
    {
      msg = eval(theValidationArray[i]);
    }
    if (msg != "")
    {
     ErrorMsg += "\n"+msg;                   
     if (stopOnFailure == "1") 
     {
       if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
      alert(ErrorHeader+ErrorMsg);
      document.MM_returnValue = false; 
      break;
     }
     else  
     {
      if (theFocusArray[i] && !FocusSet)  
      {
       FocusSet=true;
       theNameArray[i].focus();
      }
     }
    }
   }
  }
  if (ErrorMsg!="" && stopOnFailure != "1") 
  {
   alert(ErrorHeader+ErrorMsg);
  }
  document.MM_returnValue = (ErrorMsg==""); 
  if (document.MM_returnValue && AutoSubmit)  
  {
   eval("document."+FormName+".submit()")
  }
 }
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0 modified to check for Credit card info and date
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;   
<!--  alert("validating...");-->
   var now         = new Date();
   var monthnumber = now.getMonth() + 1;
   var monthday    = now.getDate();	
	 var months 		 = new Array("January","February","March","April","May","June","July","August","September","October","November","December")

   
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; 
	 if ((val=val.value)!=0) {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address!\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number!\n';
        if (test.indexOf('inRange') != -1) { p=val.length;
         if (p<16 || 16<p) errors+='- '+nm+' must contain 16 numbers!\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is REQUIRED!\n';
				}
  } 
  
  

if ( document.custFeed.customerName.value == '' ) 
{
errors += '- Name is REQUIRED!\n';

}

if ( document.NewReservation.Number_Females.value == -1 ) 
{
errors += '- Number of Females is REQUIRED!\n';

}

if ( document.NewReservation.Number_Females.value == 0 && document.NewReservation.Number_Males.value == 0)
{
errors += '- Number of Males and Females cannot BOTH be 0!\n';

}

	if (errors) alert('The following error(s) in the form were found:\n'+errors);
	  
	document.MM_returnValue = (errors == '');
}

function submitCustFeedForm()
{
Form=document.forms["custFeed"];
var alertMessage='';
var mstr="The following fields are required:\n"

if(Form.elements['customerName'].value=='')  {
alertMessage+="\n-Name";
}
if(Form.elements['email'].value=='')  {
	alertMessage+="\n-Email";
}
if(Form.elements['issue'].value=='')  {
alertMessage+="\n-Issue";
}
if (alertMessage.length > 3) {
	mstr+=alertMessage;
	alert(mstr);
}
else {Form.submit();}
}  

function submitBKSubscribeForm()
{
Form=document.forms["bookClubSub"];
var alertMessage='';
var mstr="The following fields are required:\n"

if(Form.elements['childName'].value=='')  {
alertMessage+="\n-Child's Name";
}
if(Form.elements['streetAddress'].value=='')  {
	alertMessage+="\n-Street Address";
}
if(Form.elements['city'].value=='')  {
alertMessage+="\n-City/Region";
}
if(Form.elements['postalCode'].value=='')  {
alertMessage+="\n-Postal Code";
}
if(Form.elements['phoneNumber'].value=='')  {
alertMessage+="\n-Phone Number";
}
if(Form.elements['age'].value=='')  {
alertMessage+="\n-Age";
}
if(Form.elements['bkemail'].value=='')  {
alertMessage+="\n-Email";
}
if(Form.elements['sex'].value=='')  {
alertMessage+="\n-Sex";
}
if (alertMessage.length > 3) {
	mstr+=alertMessage;
	alert(mstr);
}
else {Form.submit();}
}  

function submitNewCustomerForm()
{
Form=document.forms["newCustomer"];
var alertMessage='';
var mstr="The following fields are required:\n"

if(Form.elements['firstname'].value=='')  {
alertMessage+="\n-First Name";
}
if(Form.elements['lastname'].value=='')  {
	alertMessage+="\n-Last Name";
}
if(Form.elements['address'].value=='')  {
alertMessage+="\n-Address";
}
if(Form.elements['city'].value=='')  {
alertMessage+="\n-City";
}
if(Form.elements['zip'].value=='')  {
alertMessage+="\n-Postal Code";
}
if(Form.elements['phone'].value=='')  {
alertMessage+="\n-Phone";
}
if(Form.elements['country'].value=='')  {
alertMessage+="\n-Country";
}
if(Form.elements['ship_to_address'].value=='')  {
alertMessage+="\n-Shipping Address";
}
if(Form.elements['ship_to_city'].value=='')  {
alertMessage+="\n-Shipping City";
}
if(Form.elements['ship_to_zip'].value=='')  {
alertMessage+="\n-Shipping Postal Code";
}
if(Form.elements['ship_to_phone'].value=='')  {
alertMessage+="\n-Shipping Phone";
}
if (alertMessage.length > 3) {
	mstr+=alertMessage;
	alert(mstr);
}
else {Form.submit();}
}  