<!--// This script opens a small resizeable browser window

var defaultcontactname = "";
var defaultcontactemail = "";

function cb_samesponsor(cb_value,nn)
{
	if (cb_value==true)
	{
		if (defaultcontactname == "")
		{
			defaultcontactname = document.getElementById('sponsorcontact_'+nn).value;
		};
		if (defaultcontactemail == "")
		{
			defaultcontactemail = document.getElementById('sponsoremail_'+nn).value;
		};
		document.getElementById('sponsorcontact_'+nn).value = document.getElementById('C_FirstName').value + " " + document.getElementById('C_LastName').value; 
		document.getElementById('sponsoremail_'+nn).value = document.getElementById('C_Email').value;

		if (document.getElementById('c_companyname') && document.getElementById('c_companyname').selectedIndex)
			document.getElementById('sponsorname_'+nn).value = document.getElementById('c_companyname').options[document.getElementById('c_companyname').selectedIndex].value;

		else if (document.getElementById('c_companyname') && document.getElementById('c_companyname').type != "hidden")
			document.getElementById('sponsorname_'+nn).value = document.getElementById('c_companyname').value;
		
		if (document.getElementById('Title') && document.getElementById('Title').selectedIndex)
			document.getElementById('sponsorTitle_'+nn).value = document.getElementById('Title').options[document.getElementById('Title').selectedIndex].value;
		else if (document.getElementById('Title') && document.getElementById('Title').type != "hidden")
			document.getElementById('sponsorTitle_'+nn).value = document.getElementById('Title').value; 

		if (document.getElementById('C_Phone') && document.getElementById('C_Phone').type != "hidden") 
			document.getElementById('sponsorPhone_'+nn).value = document.getElementById('C_Phone').value; 
	}
}

function WindowOpen(URL,windowName,width,height)
	{
		window.open(URL, windowName, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height)
	}

function isBlank(theForm) {
	var tempName;
	var errorMessage = "The information that you just submitted is required or\n incorrect.  Please review the error messages below!\n";
	var alertUser = "good";
	var theValue;
	var textPosition = 0;
	var CheckMoreFlag = "yesPlease";
	var formLength = theForm.length;
	// other good characters such as / \ can't be tested in the string, these escape sequence values are tested below
	var goodCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;&`~!@#$%^&*()-_=+[]{}.<>?,;";
	var goodCharLength = goodCharacters.length;
	var textPosition = 0;
	// IsItRequired is a hidden form field to test if ANSTEXT1 is required
	var IsItRequired = "";
	
	// function to confirm if the entire field is whitespace, returns false if all is well :-D
	function isBlank(s) {
		var valueLength = s.length;		
		for (var h = 0; h < valueLength; h++) {
			var checkForNothing = theValue.charAt(h);
			if (( checkForNothing != " ") && (checkForNothing != '\n') && (checkForNothing != '\t')) { 
				return false;
			}
		}
		return true;
	}
	
	// test for the quantity of form fields and look for only fields with the name anstext1
	for (i=0; i< formLength; i++) {
		tempName = theForm.elements[i].name;
		
		// will only check for field names as in tempName below and that the hidden field following it 
		// called ThisRequired is set to yes
		
		if (( tempName == "anstext1" ) && ( CheckMoreFlag == "yesPlease" )) {
			// get info from hidden field immediately after anstext
			IsItRequired = theForm.elements[i + 1].value;

			if ( IsItRequired == "yes" ){
				theValue = theForm.elements[i].value;
				textPosition = textPosition + 1;	
				
				// check for nulls and add to message if so
				if ((theValue == null) || (theValue == "") || (isBlank(theValue))){
					// errorMessage = errorMessage + '\n- Answer text field ' + textPosition + ' is required  \n';
					errorMessage = errorMessage + '\n- Answer text field is required  \n';
					CheckMoreFlag = "noMore";
					// this is the message that will display in the alert box
					alertUser = "emptyField";
				} else {
					if (CheckMoreFlag == "yesPlease") {
						var valueLength = 0;
						valueLength = theValue.length;
						// check letters a-z and A-Z  0-9 , . ? 
						for (var j = 0; j < valueLength; j++) {      
							var ch = theValue.charAt(j);
							alertUser = "badChars";  //set ahead of time, if loop goes all the way, char never matched
							for (var k=0; k < goodCharLength; k++) {
								var goodCh = goodCharacters.charAt(k);
								// special permitted characters are tested as escape sequences in the line below " ", / \
								if ((ch == goodCh) || (ch == " ") || (ch == '\\') || (ch == '\/')) {
									alertUser = "goodChars";
									break;
								}					
							} // end for k	
							if (alertUser == "badChars") {
								errorMessage = errorMessage + "\n- Valid  characters are:\n   letters 'a - z'  'A - Z'\n   numbers  '0 - 9'\n   characters  .  ,   ?  \\  / \n ";
								CheckMoreFlag = "noMore";
								break;
							}
										  
						}// end for j
					} //end alertUser !=2 
				} // end else for tempName == anstext1
			} // end if IsItRequired is yes
		} // end first check for anstext1
	} // end for loop
	if ((alertUser == "badChars") || (alertUser == "emptyField")) {
	alert(errorMessage);
	return false;
	} 
}
function message(){
 alert("The continue button does not work in the PREVIEW MODE. When your activity is live, the continue button will allow your customers to continue the booking process.")
 }

function ValidateBeforeSubmit(){
	if ((window.document.forms[0].method_of_payment[0] && document.forms[0].method_of_payment[0].checked)
		|| (window.document.forms[0].method_of_payment && !window.document.forms[0].method_of_payment[0])){	
		if ( ( document.forms[0].Cardtype.options[document.forms[0].Cardtype.options.selectedIndex].value == "VISA" ) && 
				(!isVisa(document.forms[0].ccnumbersubmit.value)) ){
			alert("The Visa card number you provided doesn't appear to be valid. \n Please try again");
			return false;
		} else if ((document.forms[0].Cardtype.options[document.forms[0].Cardtype.options.selectedIndex].value == "MC") && (!isMasterCard(document.forms[0].ccnumbersubmit.value))){
			alert("The Master Card number that you provided doesn't appear to be valid. \n Please try again");
			return false;
		} else if ((document.forms[0].Cardtype.options[document.forms[0].Cardtype.options.selectedIndex].value == "Amex") && (!isAmericanExpress(document.forms[0].ccnumbersubmit.value))){
			alert("The American Express number that you provided doesn't appear to be valid. \n Please try again");
			return false;
		} else if ((document.forms[0].Cardtype.options[document.forms[0].Cardtype.options.selectedIndex].value == "Discover") && (!isDiscover(document.forms[0].ccnumbersubmit.value))){
			alert("The Discover Card number that you provided doesn't appear to be valid. \n Please try again");
			return false;
		} else if (document.getElementById('payment_bzip') && document.getElementById('payment_bzip').value == '') {
			alert("Please enter your Billing Zip Code");
			return false;
		} 
		// to prevent double charges.
		// swest 05.14.01
		document.forms[0].submitbutton.onclick = null;
		document.forms[0].submitbutton.onsubmit = null;
		document.forms[0].submitbutton.value = "Processing ...";
		document.forms[0].submitbutton.disabled = true;
	}
	return true;
}

function OrderstoConfirmOneClick(){
	   document.ordform.orderssubmitbutton.onclick = null;
	   document.ordform.orderssubmitbutton.onsubmit = null;
	   document.ordform.orderssubmitbutton.value = "Processing ...";
	   document.ordform.orderssubmitbutton.disabled = true;
return true;
}

function openwindow(url) {
mywin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=550,height=500');
}
function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()

function stringFilter (input) {
s = input;
filteredValues = "1234567890";     // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) != -1) returnString += c;
}
	return returnString;
}

function isVisa(cc)
{
  cc = stringFilter(cc);
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == 4))
    return isCreditCard(cc);
  return false;
}  // END FUNCTION isVisa()




/*  ================================================================
    FUNCTION:  isMasterCard()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid MasterCard
		    number.
		    
	      false, otherwise

    Sample number: 5500 0000 0000 0004 (16 digits)
    ================================================================ */

function isMasterCard(cc)
{
  cc = stringFilter(cc);
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == 5) &&
      ((seconddig >= 1) && (seconddig <= 5)))
    return isCreditCard(cc);
  return false;

} 
function isAmericanExpress(cc)
{
  cc = stringFilter(cc);
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == 3) &&
      ((seconddig == 4) || (seconddig == 7)))
    return isCreditCard(cc);
  return false;

} 

function isDiscover(cc)
{
  cc = stringFilter(cc);
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} 
// STOP HIDING -->

