function formshowhide(id)
{
if(id == "recurring")
{
document.getElementById('recurringdiv').style.display = "block";
document.getElementById('onetimediv').style.display = "none";
}
else
{
document.getElementById('recurringdiv').style.display = "none";
document.getElementById('onetimediv').style.display = "block";
}
}

// TO TOGGLE THE STATE OF HIDDEN DIV'S 

function toggleLayer(whichLayer) {
    if (document.getElementById(whichLayer).style.display=='none') {
         document.getElementById(whichLayer).style.display='block';
    } else {
         document.getElementById(whichLayer).style.display='none';
    }
}

//VALIDATION FUNCTIONS

// EMAIL VALIDATION
function isEmailAddr(email)
{
var result = false;
var theStr = new String(email);
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}

//TEXT FIELD VALIDATION
function validRequired(formField,fieldLabel)
{
  var result = true;
  if (formField.value == "")
  {
    alert('Please enter a value for the "' + fieldLabel +'" field.');
    formField.focus();
    result = false;
  }
return result;
}

// SELECT BOX VALIDATION
function validSelect(formField,fieldLabel)
{
  var result = true;
  if (formField.selectedIndex == 0) 
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
return result;
}

// EMAIL VALIDATION
function validEmail(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    formField.focus();
    result = false;
  }
return result;
}

// NUMBER VALIDATION
function validNum(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var num = parseInt(formField.value);
if (isNaN(num))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();    
result = false;
}
} 
return result;
}

// DATE VALIDATION
function validDate(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var elems = formField.value.split("/");
result = (elems.length == 3); 
if (result)
{
var month = parseInt(elems[0]);
var day = parseInt(elems[1]);
var year = parseInt(elems[2]);
result = !isNaN(month) && (month > 0) && (month < 13) && !isNaN(day) && (day > 0) && (day < 32) && !isNaN(year) && (elems[2].length == 4);
}
if (!result)
{
alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
formField.focus();    
}
} 
return result;
}

// RADIO BUTTON VALIDATION
function validRadio(formField,fieldLabel) 
{
strRadio=formField
for (i=0;i<strRadio.length;i++)
if (strRadio[i].checked)return true
alert('Please select "' + fieldLabel +'".');
formField.focus();
result = false;
}

// CHECKBOX VALIDATION
function validCheckbox(formField,fieldLabel)
{
  var result = true;
  if (formField.checked == 0) 
	{
		alert('Please check the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
return result;
}

// PASSWORD VALIDATION
function validatePwd(formField,formField1) {
var result = true;
var invalid = " ";
var minLength = 8;
var pw1 = formField.value;
var pw2 = formField1.value;
if (pw1 == '') {
alert('Please enter your New Password.');
formField.focus();
result = false;
}
else if (pw2 == '') {
alert('Please Confirm your new Password.');
formField1.focus();
result = false;
}
else if (formField.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
formField.focus();
result = false;
}
else if (formField.value.indexOf(invalid) > -1) {
alert("Please do not use spaces in your password.");
formField.focus();
result = false;
} else if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
formField1.focus();
result = false;
}
return result;
}

// CC EXPIRY VALIDATION

function validate_cc_exp(mo,yr)
{
  var result = true;
  cc_exp = mo + "/" + yr;

 if( (mo < 1) || (mo > 12) ) {
     errmsg  = "Invalid month (" + mo + ") ";
     errmsg += "in credit card expiration date (" + cc_exp + ")";
     alert( errmsg );
     mo.focus();
     result = false;
  }
  
  var now = new Date();
  var curr_mo = now.getMonth() + 2;
  var curr_yr = now.getYear();

  if( yr < curr_yr ) {
     errmsg = "Expired credit card (" + cc_exp + ")";
     alert( errmsg );
     yr.focus();
     result = false;
  }
	

  if( (yr == curr_yr) && (mo < curr_mo) ) {
     errmsg = "Expired credit card (" + cc_exp + ")";
     alert( errmsg );
     mo.focus();
     result = false;
  }
	return result;
}

// SUBSCRIPTION VALIDATION
function validateSubscription(formField) {
var result = true;
var invalid = " ";
var minValue = 12;
var subscription = formField.value;
if (subscription == '') {
alert('Please enter your Donation Amount.');
formField.focus();
result = false;
}
else if (formField.value < minValue) {
alert('Your donation amount must be at least ' + minValue + ' dollars. Try again.');
formField.focus();
result = false;
}
return result;
}

function validateSearch(theForm)
{
// Start ------->
if (!validRequired(theForm.search,"Product Title or Product SKU"))
return false;
// <--------- End
return true;
}

function validateCheckoutlogin(theForm)
{
// Start ------->
if (!validRequired(theForm.login,"Username"))
return false;
if (!validRequired(theForm.pwd,"Password"))
return false;
// <--------- End
return true;
}

function validateSignup(theForm)
{
// Start ------->
if (!validRequired(theForm.login,"Username"))
return false;
if (!validatePwd(theForm.pwd,theForm.pwd1))
return false;
if (!validSelect(theForm.sq,"Secret Question"))
return false;
if (!validRequired(theForm.sa,"Secret Answer"))
return false;
if (!validRequired(theForm.fname,"First Name"))
return false;
if (!validRequired(theForm.lname,"Last Name"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
if (!validCheckbox(theForm.agree,"Privacy Policy and Terms of Use"))
return false;
// <--------- End
return true;
}

function validateResetPwd(theForm)
{
// Start ------->
if (!validRequired(theForm.oldpwd,"Old Password"))
return false;
if (!validatePwd(theForm.pwd,theForm.pwd1))
return false;
// <--------- End
return true;
}

function validateBilling(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Name on the Card"))
return false;
if (!validRequired(theForm.num,"Credit Card Number"))
return false;
if (!validSelect(theForm.type,"Credit Card Type"))
return false;
if (!validSelect(theForm.exp_mo,"Expiration Month"))
return false;
if (!validSelect(theForm.exp_yr,"Expiration Year"))
return false;
if (!validate_cc_exp(theForm.exp_mo,theForm.exp_yr))
return false;
if (!validRequired(theForm.code,"Verification Code"))
return false;
if (!validRequired(theForm.addr1,"Billing Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
// <--------- End
return true;
}

function validateCreditcode(theForm)
{
// Start ------->
if (!validRequired(theForm.code,"Verification Code"))
return false;
// <--------- End
return true;
}

function validateShipping(theForm)
{
// Start ------->
if (!validRequired(theForm.fname,"First Name"))
return false;
if (!validRequired(theForm.lname,"Last Name"))
return false;
if (!validRequired(theForm.addr1,"Shipping Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
// <--------- End
return true;
}

function validateContact(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Name"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
if (!validRequired(theForm.prayer,"Prayer Request"))
return false;
// <--------- End
return true;
}

function registerStepone(theForm,regnum)
{
// Start ------->
var regnum = regnum.options[regnum.selectedIndex].value;
for (var k=1; k<=regnum; k++) {
if (!validRequired(theForm["regname"+k],"Registrant"+k+" Name"))
return false;
if (!validRequired(theForm["regage"+k],"Registrant"+k+" Age"))
return false;
if (!validEmail(theForm["regemail"+k],"Registrant"+k+" Email Address",true))
return false;
}
if (!validRequired(theForm.name,"Name on the Card"))
return false;
if (!validRequired(theForm.num,"Credit Card Number"))
return false;
if (!validSelect(theForm.type,"Credit Card Type"))
return false;
if (!validSelect(theForm.exp_mo,"Expiration Month"))
return false;
if (!validSelect(theForm.exp_yr,"Expiration Year"))
return false;
if (!validate_cc_exp(theForm.exp_mo,theForm.exp_yr))
return false;
if (!validRequired(theForm.code,"Verification Code"))
return false;
if (!validRequired(theForm.addr1,"Billing Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
// <--------- End
return true;
}


function registerBilling(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Name on the Card"))
return false;
if (!validRequired(theForm.num,"Credit Card Number"))
return false;
if (!validSelect(theForm.type,"Credit Card Type"))
return false;
if (!validSelect(theForm.exp_mo,"Expiration Month"))
return false;
if (!validSelect(theForm.exp_yr,"Expiration Year"))
return false;
if (!validate_cc_exp(theForm.exp_mo,theForm.exp_yr))
return false;
if (!validRequired(theForm.code,"Verification Code"))
return false;
if (!validRequired(theForm.addr1,"Billing Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
// <--------- End
return true;
}

function validateComment(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Name"))
return false;
if (!validRequired(theForm.text,"Comment"))
return false;
// <--------- End
return true;
}

function validateClub12(theForm)
{
// Start ------->
if (!validateSubscription(theForm.subscription))
return false;
if (!validRequired(theForm.fname,"Card First Name"))
return false;
if (!validRequired(theForm.lname,"Card Last Name"))
return false;
if (!validRequired(theForm.num,"Credit Card Number"))
return false;
if (!validSelect(theForm.type,"Credit Card Type"))
return false;
if (!validSelect(theForm.exp_mo,"Expiration Month"))
return false;
if (!validSelect(theForm.exp_yr,"Expiration Year"))
return false;
if (!validate_cc_exp(theForm.exp_mo,theForm.exp_yr))
return false;
if (!validRequired(theForm.code,"Verification Code"))
return false;
if (!validRequired(theForm.addr1,"Billing Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
// <--------- End
return true;
}

function validateBooking(theForm)
{
// Start ------->
if (!validRequired(theForm.name,"Name"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
if (!validRequired(theForm.phone,"Phone Number"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zip,"Zip Code"))
return false;
if (!validRequired(theForm.comments,"Request Details/Dates"))
return false;
// <--------- End
return true;
}

function estimateShipping(theForm)
{
// Start ------->
if (!validRequired(theForm.zipcode,"Ship-to Zipcode"))
return false;
// <--------- End
return true;
}

function validateClub12Modal(theForm)
{
// Start ------->
if (!validRequired(theForm.fname,"Card First Name"))
return false;
if (!validRequired(theForm.lname,"Card Last Name"))
return false;
if (!validRequired(theForm.num,"Credit Card Number"))
return false;
if (!validSelect(theForm.type,"Credit Card Type"))
return false;
if (!validSelect(theForm.exp_mo,"Expiration Month"))
return false;
if (!validSelect(theForm.exp_yr,"Expiration Year"))
return false;
if (!validate_cc_exp(theForm.exp_mo,theForm.exp_yr))
return false;
if (!validRequired(theForm.code,"Verification Code"))
return false;
if (!validRequired(theForm.addr1,"Billing Address 1"))
return false;
if (!validRequired(theForm.city,"City"))
return false;
if (!validSelect(theForm.state,"State"))
return false;
if (!validRequired(theForm.zipcode,"Zip Code"))
return false;
if (!validEmail(theForm.email,"Email Address",true))
return false;
// <--------- End
return true;
}