
function popwin(page) {
	windowprops = "width=400,height=400,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes";
	thewin = window.open(page, "popup", windowprops);
}


function popwin2(page) {
	windowprops = "width=800,height=600,location=no,scrollbars=yes,menubars=yes,toolbars=no,resizable=yes";
	thewin = window.open(page, "popup2", windowprops);
}

function popwin3(page) {
	windowprops = "width=350,height=400,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no";
	thewin = window.open(page, "popup3", windowprops);
}

function popwin4(page) {
	windowprops = "width=400,height=400,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no";
	thewin = window.open(page, "popup4", windowprops);
}

function popsch(page) {
	windowprops = "width=350,height=250,location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes";
	thewin = window.open(page, "popup", windowprops);
}

function popwincvv(loc,winname,w,h,scroll,resize) {
	eval('var newwin = window.open("' + loc + '","' + winname + '","width=' + w + ',height=' + h + ',top=' + ',location=no,scrollbars=' + scroll + ',menubar=no,toolbar=no,resizable=' + resize + '")');
}

function printform() {
    popwin('registration-paybymail2.html','printform',610,500,'yes','yes');
}

function popcvv2() {
    popwincvv('cvv2.php','CVV2',650,410,'yes','yes');
}

function cvv() {
    popwincvv('cvv2.php','registrationform',660,500,'yes','yes');
}

function payonline() {
    popwin('registration-payonline.html','registrationform',660,500,'yes','yes');
}

function RideWindow(page) {
	windowprops = "width=760,height=520,location=yes,scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes";
	thewin = window.open(page, "RideWindow", windowprops);
}

// Regform scripts
var totalSale;
totalSale = 0;
var data = new Array();
data = {'init' :0 }; //-- mootools revises Array behavior - this fixes it.

function ChangeQty(myform,name){
	var valueQty;
	var valuePrice;
	valueQty=document.getElementById(name+'Qty').value;
	valuePrice=document.getElementById(name+'Price').value;
//	eval('valueQty=myform.'+name+'Qty.value');
//	eval('valuePrice=myform.'+name+'Price.value');
	data[name] = valueQty * valuePrice;
	eval('myform.'+name+'Total.value=displayMoney('+data[name]+')');
	//document.getElementById(name+'Total').value=displayMoney('+data[name]+');
	myform.FORM_FinalTotal.value=getTotals();
}

function getTotals(){
	var totalSale;
	totalSale = 0;
	for (variable in data) {
		//alert(data[variable]);
   		totalSale += parseFloat(data[variable]);
	}
	return displayMoney(totalSale);
}
function displayMoney(numb){
  if (parseFloat(numb)){
    if (numb== Math.round(numb)){
      return ( numb + ".00")
    }
    else {
      numb=(numb + "0");
      return (numb.substring(0,(numb.indexOf(".")+3)))
    }
  }
  else{
    return "0.00"
  }
}
/*****************************************
 * Form Validation Scripts               *
 * Added BY CLS 20040106                 *
 * Provided BY BW					     *
 *****************************************/

// returns true if a string contains only whitespace characters
function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '')){
			return false;
		}
	}
	return true;
}

function checkForm(f){
	return checkFormWithPreviousErrors(f,false,'',false,'');
//return true;
}

function checkFormOff(f){
//	if (checkQty(f)){
//		return checkFormWithPreviousErrors(f,false,'',false,'');
//	}else{
//		return false;
//	}
if(document.getElementById("hogguest").style.display == 'none'){
document.forms[0].FORM_EXP2_month.value='';
document.forms[0].FORM_EXP2_year.value='';
document.forms[0].FORM_EXP2_life.value='';
document.forms[0].FORM_CHAPTER2.value='';
document.forms[0].FORM_TSHIRT2.value='';
document.forms[0].FORM_HOG2.value='';
}
if(document.getElementById("guest").style.display == 'none'){
document.forms[0].FORM_FNAME2.value='';
document.forms[0].FORM_LNAME2.value='';
document.forms[0].FORM_ADDRESS2.value='';
document.forms[0].FORM_CITY2.value='';
document.forms[0].FORM_STATE2.value='';
document.forms[0].FORM_ZIP2.value='';
document.forms[0].FORM_PROV2.value='';
document.forms[0].FORM_PHONE2.value='';
document.forms[0].FORM_EMAIL2.value='';
document.forms[0].FORM_EXP2_month.value='';
document.forms[0].FORM_EXP2_year.value='';
document.forms[0].FORM_EXP2_life.value='';
document.forms[0].FORM_CHAPTER2.value='';
document.forms[0].FORM_TSHIRT2.value='';
document.forms[0].FORM_HOG2.value='';
}
	return checkFormWithPreviousErrors(f,false,'',false,'');
//return true;
}

function checkFormWithPreviousErrors(f,havePreviousEmptyFieldsError, previousEmptyFieldsErrorStr,havePreviousError, previousErrorStr){
	if((window.navigator.platform).indexOf("Mac") >= 0){
		if(window.navigator.appName.indexOf("Microsoft Internet Explorer") >= 0){
			var myvarparamarray = f.variableparameters.value.split("\r");
		}else{
			var myvarparamarray = f.variableparameters.value.split("\n");
		}
	}else{
		var myvarparamarray = f.variableparameters.value.split("\n");
	}
	for(var i = 0; i < myvarparamarray.length; i++){
		var e = myvarparamarray[i];
		//set all the variables needed from the variableparameters parameter
		eval("f."+e);
	}
	var empty_fields_msg = "";
	var errors_msg = "";
	var empty_fields_bool = havePreviousEmptyFieldsError;
	var empty_fields = previousEmptyFieldsErrorStr;
	var errors_bool = havePreviousError;
	var errors = previousErrorStr;
	
	for(var i = 0; i < f.length; i++){
		var e = f.elements[i];
		if((e.type == "text") || (e.type == "textarea") || e.type=="radio" || e.type=="select-one" || e.type=="hidden" || e.type=="password"){
			if(e.required){
				if((e.value == null) || isblank(e.value)){
					empty_fields_bool = true;
					empty_fields += "\n"+e.realName;
					//cancels this loop
					continue;
				}
			}
			if(e.numeric){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{ 
					var v = parseFloat(e.value);
					if(e.exclude != null && v == e.exclude){
						errors_bool = true;
						if(e.type=="select-one"){
							errors += "\nYou must chose a "+e.realName;
						}
					}
					if(isNaN(v) || (e.min != null && e.value < e.min) || (e.max != null && e.value > e.max)){
						errors_bool = true;
						if(e.type=="select-one"){
							errors += "\nYou must chose a "+e.realName;
						}else{
							if(e.image){
								errors+="\nYou must select a "+e.realName;
							}else{
								errors += "\n"+e.realName + " must be a number";
								if(e.min != null){
									errors += " that is greater than "+e.min;
								}
								if(e.max != null){
									if(e.min != null){
										errors += " and less than "+e.max;
									}else{
										errors += " that is less than "+e.max;
									}
								}
							}
						}
					}
				}
				continue;
			}
			if(e.date){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{
					//if(!Date.parse(e.value)){
					if(!checkDate(e.value)){
						errors_bool = true;
						errors += "\n"+e.realName + " must be a valid date format.  Must be in form: mm/dd/yy";
					}				
				}
			}
			if(e.smalldate){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{
					//if(!Date.parse(e.value)){
					if(!checkSmallDate(e.value)){
						errors_bool = true;
						errors += "\n"+e.realName + " must be a valid date format.  Must be formatted: mm/yy or LIFE";
					}				
				}
			}
			if(e.hognumber){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{
					//if(!Date.parse(e.value)){
					if(!checkHogNumber(e.value)){
						errors_bool = true;
						errors += "\n H.O.G. number is two letters followed by seven digits.\nFor example, US1234567";
					}				
				}
			}
			if(e.email){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{
					if(!checkEmail(e.value)){
						errors_bool = true;
						errors += "\n"+e.realName + " must be a valid email format";
					}				
				}
			}
			if(e.zip){
				if(!e.required && isblank(e.value)){
					//don't need to check anymore it's blank
				}else{
					/*if(!checkZip(e.value)){
						errors_bool = true;
						errors += "\n"+e.realName + " must be a valid Zip format";
					}	*/			
				}
			}
		}
	}
	
	if(f.dateStart && f.dateEnd){
		if(!isblank(f.dateStart.value) && !isblank(f.dateEnd.value) && checkDate(f.dateEnd.value) && checkDate(f.dateStart.value) && checkDate(f.dateEnd.value) < checkDate(f.dateStart.value)){
			errors_bool = true;
			errors += "\nYour Start Date cannot be greater than your End Date";
		}else if(!isblank(f.dateEnd.value) && checkDate(f.dateEnd.value) && isblank(f.dateStart.value)){
			errors_bool = true;
			errors += "\nYour End Date cannot be set unless Start Date is also";
		}
	}
	
//	if (f.FORM_EXP1_life.checked && (f.FORM_EXP1_month.value!=''||f.FORM_EXP1_year.value!='')){
//		errors_bool = true;
//		errors += "\nOnly lifetime membership or an expiration can be selected.";
//	}

//	if (f.FORM_HOG1 = f.FORM_HOG2){
//		errors_bool = true;
//		errors += "\nH.O.G. numbers must be different.";
//	}
	
	if(empty_fields_bool || errors_bool){
		var empty_fields_msg = "";
		var errors_msg = "";
		if(empty_fields_bool){
			empty_fields_msg = "The following fields cannot be blank: \n";
		}
		if(errors_bool){
			var droplines;
			if(empty_fields_bool){
				droplines = "\n\n";
			}else{
				droplines = "\n";
			}
			errors_msg = droplines+"The following fields contain an error: \n";
		}
		var msg = empty_fields_msg+empty_fields+errors_msg+errors;
		
		//this is so the mac does not have the issue with the scroll bar that does not move in the alert box
		if((window.navigator.platform).indexOf("Mac") >= 0){
			alert(msg +"\r\r\r\r\r\r\r\r\r");
		}else{
			alert(msg);
		}
//alert('*'+empty_fields_msg+'*'+'*'+empty_fields+'*'+errors_msg+errors);

		return false;
	}else{
		f.submit();
		return true;
	}
}

//returns a date object with date represented by the date string or false if can't make a date object with it
//had to do it this way because Date.parse needs a 4 digit year, which we were not requiring
function checkDate(dateString){
	//10 is added to parseInt to make number base 10
	var results = dateString.match(/(\d{1,2})\/(\d{1,2})\/(\d{1,4})/);
	if(results != null){
		if(parseInt(results[1],10) < 13 && parseInt(results[1],10) > 0 && parseInt(results[2],10) < 32 && parseInt(results[2],10) > 0 && parseInt(results[3],10) < 3000 && parseInt(results[3],10) > 0){
			var centuryToAdd;
			if(parseInt(results[3],10) < 1000){
				if(parseInt(results[3],10) > 29){
					centuryToAdd = 1900;
				}else{
					centuryToAdd = 2000;
				}
			}else{
				centuryToAdd = 0;
			}
			var parsedDate = new Date(Date.parse(parseInt(results[1],10)+"/"+parseInt(results[2],10)+"/"+(parseInt(results[3],10)+centuryToAdd)));
			//check to see if a date like 2/31/03 was entered, javascript changes it to 4/3/03 instead of giving an error
			if(parsedDate.getMonth()+1 != parseInt(results[1],10)){
				return false;
			}else{
				return Date.parse(parseInt(results[1],10)+"/"+parseInt(results[2],10)+"/"+(parseInt(results[3],10)+centuryToAdd));
			}
		}else{
			return false; 
		}
	}else{
		return false;
	}
}
function checkEmail(emailString){
	var pattern = /^[\w\d\-\.]+@[\w\d\-\.]+[\.][\w]{1,3}$/;
	return pattern.test(emailString);
}
function checkZip(zipString){
	var pattern = /^[\d]{5}([\-]?[\d]{4})?$/;
	return pattern.test(zipString);
}

//this is Specail for Hog rally sites so that you may enet on 1 member and one Guest
function checkQty(f){
	var totalnumberrequested = parseInt(f.FORM_NUMHOGQty.value) +parseInt(f.FORM_NUMGUESTQty.value)
	if (parseInt(totalnumberrequested) >2) {
		alert("You can only register a maximum of 2 people per form - not including children.");
		return false;
	}else{
		return true;
	}
}
function checkSmallDate(dateString){
	var lifeResults = dateString.match(/([Ll][Ii][Ff][Ee])$/);
	if(lifeResults != null){
		return true;
	}
	var results = dateString.match(/(\d{1,2})\/(\d{1,2})$/);
	if(results != null){
		if(parseInt(results[1],10) < 13 && parseInt(results[1],10) > 0 ){
			return true;
		}else{
			return false; 
		}
	}else{
		return false;
	}
}
function checkHogNumber(hogString){
	var results = hogString.match(/([a-zA-Z][a-zA-Z]\d{7})$/);
	if(results != null){
		return true;
	}else{
		return false;
	}
}


				
		
