<!--

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);

   return x;
}

function showHideLayers() {
  cancelHide();

  var i,p,v,obj,args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) {
     if ( ( obj = findObj (args[i]) ) != null ) {
        v = args[i+2];
        if (obj.style) {
           obj = obj.style;
           if (v=='show')
              v = 'visible';
           else if (v == 'hide')
              v = 'hidden';
        }
        obj.visibility=v;
     }
  }
}

var hidemenu;

function scheduleMenuHide() {
   hidemenu = true;
   setTimeout("hideMenu()", 3500);
}

function hideMenu() {
   if (hidemenu) {
showHideLayers('home','','hide','aboutus','','hide','ourservices','','hide','ourteam','','hide','press','','hide','contactus','','hide');
   }
}

function cancelHide() {
   hidemenu = false;
}

function isValidCreditCard(number) {
	var total = 0;
	var flag = 0;
	if (number.length > 16 || number.length < 13 ) return false;
	for (var i=(number.length - 1);i>=0; i--) {
		if (flag == 1) {
			var digits = number.charAt(i) * 2;
			if (digits > 9) digits -= 9;
			total += digits;
			flag = 0;
		} else {
			total = total + parseInt(number.charAt(i));
			flag = 1;
		}
	}
	if ((total%10) == 0) {
		return true;
	} else {
		return false;
	}
}

function typeOfCard(number) {
	/* 
	//	Card Prefixes
	//
	//	Mastercard	51-55
	//	Visa		4
	//	AmEx		34,37
	//	Discover	6011
	*/

	var firstNumber = number.substring(0,1);
	var firstThreeNumbers = number.substring(0,3);

	if (firstNumber == 4) {
		return "Visa";
	} 

	if (firstNumber == 5) {
		return "MasterCard";
	} 

	if (firstNumber == 3) {
		return "AmEx";
	} 

	var firstFourNumbers = number.substring(0,4);
	if (firstFourNumbers == 6011) {
		return "Discover";
	}
}

function cc_verification (ctype,cnum,cexpm,cexpy) {
   if (ctype != typeOfCard(cnum)) {
     alert ("The credit card type does not match the number you have entered!\nPlease verify that the information you have provided is correct.\n\nIf you think you are getting this message by mistake, \nplease contact us at register@usachess.com");
     return false;
   }

   if (!isValidCreditCard(cnum)) {
     alert ("The credit card your have provided is invalid or contains extra characters other than digits!\nPlease check the number and make sure it contains numbers only!\n\nExamples:\n   Valid Entry: 4321123443211234\n   Invalid Entry: 4321-1234-4321-1234\n   Invalid Entry: 4321.1234.4321.1234 \n\nIf you think you are getting this message by mistake, \nplease contact us at register@usachess.com");
     return false;
   }

   return true ;
}

function validate (formName) {
   var Name        = "The name is missing!\nPlease make sure to fill out all the required fields." ;
   var School      = "The school name is missing!\nPlease make sure to fill out all the required fields." ;
   var Grade       = "No grade is selected!\nPlease make sure to complete all the required fields." ;
   var Age         = "The age is not selected!\nPlease make sure to complete all the required fields." ;
   var DOB         = "The date of birth is missing!\nPlease make sure to complete all the required fields." ;
   var Rating      = "You've indicated that you are a USCF Member.\nPlease provide your USCF rating.\nIf you do not know your rating, please enter 'UNK'." ;
   var ShirtSize   = "Camper's shirt size is not selected!\nPlease make sure to complete all the required fields." ;

   var Parent_Name = "The name of the parent(s) is missing!\nPlease make sure to fill out all the required fields." ;
   var Address     = "The address is missing!\nPlease make sure to fill out all the required fields." ;
   var City        = "The city is missing!\nPlease make sure to fill out all the required fields." ;
   var State       = "No state is selected!\nPlease make sure to complete all the required fields." ;
   var ZipCode     = "The zip code is missing!\nPlease make sure to fill out all the required fields." ;
   var Phone       = "The phone number is missing!\nPlease make sure to fill out all the required fields." ;
   var Email       = "The email address is missing!\nPlease make sure to fill out all the required fields." ;
   
   var Camp_City   = "No camp city is selected!\nPlease make sure to complete all the required fields." ;
   var Camp_Date   = "No camp date is selected!\nPlease make sure to complete all the required fields." ;
   var Camp_Session= "No camp session is selected!\nPlease make sure to complete all the required fields." ;

   var Number_of_Parents = "You've indicated that you want to register for the Parent-Only Class.\nPlease provide the number of people that want to register for this class (not including the camper)" ;
   var Names_of_Parents  = "You've indicated that you want to register for the Parent-Only Class.\nPlease provide the name (separate multiple names with commas ',') of person that want to register for this class." ;

   var Tournament_City   = "No tournament city is selected!\nPlease make sure to complete all the required fields." ;
   var Tournament_Date   = "No tournament date is selected!\nPlease make sure to complete all the required fields." ;
   var Tournament_School = "No tournament school is selected!\nPlease make sure to complete all the required fields." ;
   var Tournament_Session= "No tournament session is selected!\nPlease make sure to complete all the required fields." ;

   var CC_Number   = "The credit card number is missing!\nPlease make sure to fill out all the required fields." ;
   var CC_Exp      = "No credit card expiration date is selected!\nPlease make sure to complete all the required fields." ;
   var CC_Holder   = "The credit card holder's name is missing!\nPlease make sure to fill out all the required fields." ;

   var USCF_ID       = "You've indicated that you are a USCF Member.\nPlease provide your USCF Member ID." ;
   var USCF_Exp_Date = "You've indicated that you are a USCF Member.\nPlease provide your USCF membership Expiration Date." ;

   for (i = 0; i < document.forms [formName].length; i ++) {
      if ((document.forms [formName][i].value == "")) {

         if (document.forms [formName][i].name == "Name")          alert (Name);
         if (document.forms [formName][i].name == "School")        alert (School);
         if (document.forms [formName][i].name == "Grade")         alert (Grade);
         if (document.forms [formName][i].name == "Age")           alert (Age);
         if (document.forms [formName][i].name == "DOB")           alert (DOB);
         if (document.forms [formName][i].name == "ShirtSize")     alert (ShirtSize);

         if (document.forms [formName][i].name == "Rating") {
           if (document.forms [formName][i-1].value == "No") continue ;
           else alert (Rating);
         }

         if (document.forms [formName][i].name == "USCF_ID") {
           if (document.forms [formName][i-2].value == "No") continue ;
           else alert (USCF_ID);
         }

         if (document.forms [formName][i].name == "USCF_Exp_Month") {
           if (document.forms [formName][i-3].value == "No") continue ;
           else alert (USCF_Exp_Date);
         }

         if (document.forms [formName][i].name == "USCF_Exp_Year") {
           if (document.forms [formName][i-4].value == "No") continue ;
           else alert (USCF_Exp_Date);
         }

         if (document.forms [formName][i].name == "Parent_Name")   alert (Parent_Name);
         if (document.forms [formName][i].name == "Address")       alert (Address);
         if (document.forms [formName][i].name == "City")          alert (City);
         if (document.forms [formName][i].name == "State")         alert (State);
         if (document.forms [formName][i].name == "ZipCode")       alert (ZipCode);
         if (document.forms [formName][i].name == "Phone")         alert (Phone);
         if (document.forms [formName][i].name == "Email")         alert (Email);
         if (document.forms [formName][i].name == "Heard_about_camp") continue;
         if (document.forms [formName][i].name == "Heard_about_tournaments") continue;

         if (document.forms [formName][i].name == "Camp_City")     alert (Camp_City);
         if (document.forms [formName][i].name == "Camp_Date")     alert (Camp_Date);
         if (document.forms [formName][i].name == "Camp_Session")  alert (Camp_Session);

         if (document.forms [formName][i].name == "Number_of_Parents") {
           if (!document.forms [formName][i-1].checked) continue ;
           else alert (Number_of_Parents);
         }

         if (document.forms [formName][i].name == "Names_of_Parents") {
           if (!document.forms [formName][i-2].checked) continue ;
           else alert (Names_of_Parents);
         }

         if (document.forms [formName][i].name == "Tournament_City")  alert (Tournament_City);
         if (document.forms [formName][i].name == "Tournament_Date")  alert (Tournament_Date);
         if (document.forms [formName][i].name == "Tournament_School")alert (Tournament_School);
         if (document.forms [formName][i].name == "Tournament_Session")alert (Tournament_Session);

         if (document.forms [formName][i].name == "CC_Number")     alert (CC_Number);
         if (document.forms [formName][i].name == "CC_Exp_Month")  alert (CC_Exp);
         if (document.forms [formName][i].name == "CC_Exp_Year")   alert (CC_Exp);
         if (document.forms [formName][i].name == "CC_Holder")     alert (CC_Holder);

         document.forms [formName][i].focus ();
         return false;
      }
   }
   
   return cc_verification ( document.forms [formName]["CC_Type"].value,
                            document.forms [formName]["CC_Number"].value,
                            document.forms [formName]["CC_Exp_Month"].value,
                            document.forms [formName]["CC_Exp_Year"].value  ) ;
}


-->