/* ------------------------------------------------------------- 
   Forms  ------------------------------------------ */  
   
  function generateProvinces(prefix){
	if (document.getElementById(prefix + 'country').options.value != ""){
		//remove all options
		the_field_select = document.getElementById(prefix + 'state').options;
		remove_all_options(the_field_select);
		if (document.getElementById(prefix + 'country').value == "United States"){
			the_field_select[the_field_select.length] = new Option('Select...',''); 
			the_field_select[the_field_select.length] = new Option('Alaska','US-AK'); 
			the_field_select[the_field_select.length] = new Option('Alabama','US-AL'); 
			the_field_select[the_field_select.length] = new Option('Arkansas','US-AR'); 
			the_field_select[the_field_select.length] = new Option('Arizona','US-AZ'); 
			the_field_select[the_field_select.length] = new Option('California','US-CA'); 
			the_field_select[the_field_select.length] = new Option('Colorado','US-CO'); 
			the_field_select[the_field_select.length] = new Option('Connecticut','US-CT'); 
			the_field_select[the_field_select.length] = new Option('District of Columbia','US-DC'); 
			the_field_select[the_field_select.length] = new Option('Delaware','US-DE'); 
			the_field_select[the_field_select.length] = new Option('Florida','US-FL'); 
			the_field_select[the_field_select.length] = new Option('Georgia','US-GA'); 
			the_field_select[the_field_select.length] = new Option('Hawaii','US-HI'); 
			the_field_select[the_field_select.length] = new Option('Iowa','US-IA'); 
			the_field_select[the_field_select.length] = new Option('Idaho','US-ID'); 
			the_field_select[the_field_select.length] = new Option('Illinois','US-IL'); 
			the_field_select[the_field_select.length] = new Option('Indiana','US-IN'); 
			the_field_select[the_field_select.length] = new Option('Kansas','US-KS'); 
			the_field_select[the_field_select.length] = new Option('Kentucky','US-KY'); 
			the_field_select[the_field_select.length] = new Option('Louisiana','US-LA'); 
			the_field_select[the_field_select.length] = new Option('Massachusetts','US-MA'); 
			the_field_select[the_field_select.length] = new Option('Maryland','US-MD'); 
			the_field_select[the_field_select.length] = new Option('Maine','US-ME'); 
			the_field_select[the_field_select.length] = new Option('Michigan','US-MI'); 
			the_field_select[the_field_select.length] = new Option('Minnesota','US-MN'); 
			the_field_select[the_field_select.length] = new Option('Missouri','US-MO'); 
			the_field_select[the_field_select.length] = new Option('Mississippi','US-MS'); 
			the_field_select[the_field_select.length] = new Option('Montana','US-MT'); 
			the_field_select[the_field_select.length] = new Option('North Carolina','US-NC'); 
			the_field_select[the_field_select.length] = new Option('North Dakota','US-ND'); 
			the_field_select[the_field_select.length] = new Option('Nebraska','US-NE'); 
			the_field_select[the_field_select.length] = new Option('New Hampshire','US-NH'); 
			the_field_select[the_field_select.length] = new Option('New Jersey','US-NJ'); 
			the_field_select[the_field_select.length] = new Option('New Mexico','US-NM'); 
			the_field_select[the_field_select.length] = new Option('Nevada','US-NV'); 
			the_field_select[the_field_select.length] = new Option('New York','US-NY'); 
			the_field_select[the_field_select.length] = new Option('Ohio','US-OH'); 
			the_field_select[the_field_select.length] = new Option('Oklahoma','US-OK'); 
			the_field_select[the_field_select.length] = new Option('Oregon','US-OR'); 
			the_field_select[the_field_select.length] = new Option('Pennsylvania','US-PA'); 
			the_field_select[the_field_select.length] = new Option('Rhode Island','US-RI'); 
			the_field_select[the_field_select.length] = new Option('South Carolina','US-SC'); 
			the_field_select[the_field_select.length] = new Option('South Dakota','US-SD'); 
			the_field_select[the_field_select.length] = new Option('Tennessee','US-TN'); 
			the_field_select[the_field_select.length] = new Option('Texas','US-TX'); 
			the_field_select[the_field_select.length] = new Option('Utah','US-UT'); 
			the_field_select[the_field_select.length] = new Option('Virginia','US-VA'); 
			the_field_select[the_field_select.length] = new Option('Vermont','US-VT'); 
			the_field_select[the_field_select.length] = new Option('Washington','US-WA'); 
			the_field_select[the_field_select.length] = new Option('Wisconsin','US-WI'); 
			the_field_select[the_field_select.length] = new Option('West Virginia','US-WV'); 
			the_field_select[the_field_select.length] = new Option('Wyoming','US-WY'); 					
			document.getElementById(prefix + 'state').disabled = false;
			
		} else if (document.getElementById(prefix + 'country').value == "Canada") {
			the_field_select[the_field_select.length] = new Option('Select...',''); 
			the_field_select[the_field_select.length] = new Option('Alberta','CA-AB'); 
			the_field_select[the_field_select.length] = new Option('British Columbia','CA-BC'); 
			the_field_select[the_field_select.length] = new Option('Manitoba','CA-MB'); 
			the_field_select[the_field_select.length] = new Option('New Brunswick','CA-NB'); 
			the_field_select[the_field_select.length] = new Option('Newfoundland','CA-NF'); 
			the_field_select[the_field_select.length] = new Option('Nova Scotia','CA-NS'); 
			the_field_select[the_field_select.length] = new Option('Northwest Territories','CA-NT'); 
			the_field_select[the_field_select.length] = new Option('Ontario','CA-ON'); 
			the_field_select[the_field_select.length] = new Option('Prince Edward Island','CA-PE'); 
			the_field_select[the_field_select.length] = new Option('Quebec','CA-QC'); 
			the_field_select[the_field_select.length] = new Option('Saskatchewan','CA-SK'); 
			the_field_select[the_field_select.length] = new Option('Yukon','CA-YK'); 
			document.getElementById(prefix + 'state').disabled = false;
		} else if (document.getElementById(prefix + 'country').value == "Australia") {
			the_field_select[the_field_select.length] = new Option('Select...',''); 
			the_field_select[the_field_select.length] = new Option('Australian Capital Territory','AU-AC'); 
			the_field_select[the_field_select.length] = new Option('New South Wales','AU-NS'); 
			the_field_select[the_field_select.length] = new Option('Northern Territory','AU-NT'); 
			the_field_select[the_field_select.length] = new Option('Queensland','AU-QL'); 
			the_field_select[the_field_select.length] = new Option('South Australia','AU-SA'); 
			the_field_select[the_field_select.length] = new Option('Tasmania','AU-TA'); 
			the_field_select[the_field_select.length] = new Option('Victoria','AU-VI'); 
			the_field_select[the_field_select.length] = new Option('Western Australia','AU-WA');
			document.getElementById(prefix + 'state').disabled = false;
 
		} else {
			the_field_select[the_field_select.length] = new Option('N/A','XX');
			document.getElementById(prefix + 'state').disabled = true;
		}	
	}
}



function remove_all_options(the_field_select){
	while (the_field_select.length > 0){
		the_field_select[0] = null;
	}
 }
 
 /* ------------------------------------------------------------- 
   Add an attendees  ---------------------------------------------- */  
   
   
   
		number_attendees = 1

		function firstAttendees(){

				theHTMLTAG = document.createElement("tr");
				
				theHTMLTAG1 = document.createElement("td");
				theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_"+number_attendees+"' id='attendees_firstname_"+number_attendees+"' style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG1);
				
				theHTMLTAG2 = document.createElement("td");
				theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_"+number_attendees+"' id='attendees_lastname_"+number_attendees+"' style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG2);

				theHTMLTAG3 = document.createElement("td");
				theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_"+number_attendees+"' id='attendees_email_"+number_attendees+"'  style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG3);
				
				theHTMLTAG4 = document.createElement("td");
				theHTMLTAG4.innerHTML = "<input type='text' name='attendees_company_"+number_attendees+"' id='attendees_company_"+number_attendees+"'  style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG4);	
				
				theHTMLTAG5 = document.createElement("td");
				theHTMLTAG5.innerHTML = "<input type='text' name='attendees_title_"+number_attendees+"' id='attendees_title_"+number_attendees+"'  style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG5);
				
				theHTMLTAG6 = document.createElement("td");
				theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees("+number_attendees+"));'  onmouseover='rollOver(\"b_minus"+number_attendees+"\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus"+number_attendees+"' alt='Remove' /></a>"
				theHTMLTAG.appendChild(theHTMLTAG6);				
				
				document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
		}



		function add_attendees(){
			
			
			if (number_attendees <= 8){
				
			
			if(document.getElementById("attendees_firstname_"+ number_attendees).value == "" || document.getElementById("attendees_lastname_"+ number_attendees).value == "" || document.getElementById("attendees_email_"+ number_attendees).value == "" || document.getElementById("attendees_company_"+ number_attendees).value == "" || document.getElementById("attendees_title_"+ number_attendees).value == ""){
				alert("Please fill attendee #" + number_attendees + "'s name before adding another attendee.");
			}else{
				number_attendees += 1;
								
				theHTMLTAG = document.createElement("tr");
				
				theHTMLTAG1 = document.createElement("td");
				theHTMLTAG1.innerHTML = "<input type='text' name='attendees_firstname_"+number_attendees+"' id='attendees_firstname_"+number_attendees+"' style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG1);
				
				theHTMLTAG2 = document.createElement("td");
				theHTMLTAG2.innerHTML = "<input type='text' name='attendees_lastname_"+number_attendees+"' id='attendees_lastname_"+number_attendees+"' style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG2);

				theHTMLTAG3 = document.createElement("td");
				theHTMLTAG3.innerHTML = "<input type='text' name='attendees_email_"+number_attendees+"' id='attendees_email_"+number_attendees+"'  style='display:inline;width:95px;' />"
				theHTMLTAG.appendChild(theHTMLTAG3);				
				
				
			    theHTMLTAG3 = document.createElement("td");
			    theHTMLTAG3.innerHTML = "<input type='text' name='attendees_company_"+number_attendees+"' id='attendees_company_"+number_attendees+"'  style='display:inline;width:95px;' />"
			    theHTMLTAG.appendChild(theHTMLTAG3);	
        				
			    theHTMLTAG3 = document.createElement("td");
			    theHTMLTAG3.innerHTML = "<input type='text' name='attendees_title_"+number_attendees+"' id='attendees_title_"+number_attendees+"'  style='display:inline;width:95px;' />"
			    theHTMLTAG.appendChild(theHTMLTAG3);
				
				theHTMLTAG6 = document.createElement("td");
				theHTMLTAG6.innerHTML = "<a href='Javascript:void(RemoveAttendees("+number_attendees+"));' onmouseover='rollOver(\"b_minus"+number_attendees+"\",\"\",\"images/b_minus_o.gif\",1)' onmouseout='rollOut()'><img src='images/b_minus.gif' id='b_minus"+number_attendees+"' alt='Remove' /></a>"
				theHTMLTAG.appendChild(theHTMLTAG6);	
				
				document.getElementById("tbody_attendees").appendChild(theHTMLTAG);
				document.getElementById("number_attendees").value = number_attendees;
				
				if (number_attendees==8){
					document.getElementById("b_add").style.display='none';
				};
			}
			document.getElementById("attendees_firstname_" + number_attendees).focus();
			};
		}





/* ------------------------------------------------------------- 
   Validate Form  ---------------------------------------------- */  
   
   
   
	function validate_checkout() {	
		var msg = "";
		var error = 0;
		
	//Firstname Validation
		if (document.getElementById("first_name").value == ""){
			document.getElementById("l_first_name").className = "error";
			msg = msg + "First name is empty.<br>";
			error = 1;
		} else {document.getElementById("l_first_name").className = "";}
	//lastname Validation
		if (document.getElementById("last_name").value == ""){
			document.getElementById("l_last_name").className = "error";
			msg = msg + "Last Name is empty.<br>";
			error = 1;
		} else {document.getElementById("l_last_name").className = "";}
	//title Validation
		if (document.getElementById("title").value == ""){
			document.getElementById("l_title").className = "error";
			msg = msg + "Title is empty.<br>";
			error = 1;
		} else {document.getElementById("l_title").className = "";}
	//company Validation
		if (document.getElementById("company").value == ""){
			document.getElementById("l_company").className = "error";
			msg = msg + "Company is empty.<br>";
			error = 1;
		} else {document.getElementById("l_company").className = "";}

	//address Validation
		if (document.getElementById("address").value == ""){
			document.getElementById("l_address").className = "error";
			msg = msg + "Address is empty.<br>";
			error = 1;
		} else {document.getElementById("l_address").className = "";}
	//city Validation
		if (document.getElementById("city").value == ""){
			document.getElementById("l_city").className = "error";
			msg = msg + "City is empty.<br>";
			error = 1;
		} else {document.getElementById("l_city").className = "";}
	//zipcode Validation
		if (document.getElementById("zip").value == ""){
			document.getElementById("l_zip").className = "error";
			msg = msg + "ZIP Code / Postal Code is empty.<br>";
			error = 1;
		} else {document.getElementById("l_zip").className = "";}
	//Country Validation
		if (document.getElementById("country").value == ""){
			document.getElementById("l_country").className = "error";
			msg = msg + "Country is empty.<br>";
			error = 1;
		} else {document.getElementById("l_country").className = "";}

	//State Validation
		if (document.getElementById("state").value == ""){
			document.getElementById("l_state").className = "error";
			msg = msg + "State is empty.<br>";
			error = 1;
		} else {document.getElementById("l_state").className = "";}	
		
		
	//Email
		if(!checkEmail(document.getElementById("email").value)){
			error = "1"; document.getElementById("l_email").className="error";
		}else{
			document.getElementById("l_email").className="";
		}
	//phone
		
		if(!checkPhone(document.getElementById("phone").value)){
			error = "1"; document.getElementById("l_phone").className="error";
		}else if(document.getElementById("phone").value.length < 10){
		    error = "1"; document.getElementById("l_phone").className="error";
		}else{
			document.getElementById("l_phone").className="";
		}
	
	
	//Discount Code
		if(document.getElementById("membre3").checked){
			if (document.getElementById("discount_code").value == ""){
				document.getElementById("l_discount_code").className = "error";
				msg = msg + "Discount Code is empty.<br>";
				error = 1;
			} else {document.getElementById("l_discount_code").className = "";}
		}else if(document.getElementById("membre1").checked==false && document.getElementById("membre2").checked==false){
			document.getElementById("l_membre1").className = "error";
			document.getElementById("l_membre2").className = "error";
			document.getElementById("l_membre3").className = "error";
			error = 1;
		}else{
			document.getElementById("l_membre1").className = "";
			document.getElementById("l_membre2").className = "";
			document.getElementById("l_membre3").className = "";
		}
				
	// Event Id
	
	if(document.getElementById("event_id").value==0){
		error = 1;
		document.getElementById("l_event_id").className = "error";
	}else{
		document.getElementById("l_event_id").className = "";
	}



		if (error == 1) {
			//alert("Information is missing or invalid. Please correct the following fields:\n" + msg);
			document.getElementById("validate_checkout").style.display="block";
		} else {
			document.getElementById("checkout_confirm").submit();
		}
	}


function validate_creditcard() {	
	var pattern_email = /([A-Za-z0-9\.\_]{1,})\@([A-Za-z0-9\.\_]{1,})\.([A-Za-z]{2,})/;
	var pattern_phone = /[^\d\s() -]/;
	var pattern_extension = /\d{0,}/;
	var msg = "";
	var error = 0;

	//cc Cardholder
		if (document.getElementById("cardholder").value == ""){
			document.getElementById("l_cardholder").className = "error";
			msg = msg + "Cardholder is empty.<br>";
			error = 1;
		} else {document.getElementById("l_cardholder").className = "";}

	//cc Card Type
		if (document.getElementById("card_type").value == ""){
			document.getElementById("l_card_type").className = "error";
			msg = msg + "Card Type is empty.<br>";
			error = 1;
		} else {document.getElementById("l_card_type").className = "";}

	//cc Validation
		if (document.getElementById("card_num").value == ""){
			document.getElementById("l_card_num").className = "error";
			msg = msg + "Card Number is empty.<br>";
			error = 1;
		} else {document.getElementById("l_card_num").className = "";}
	//expiry Validation
		if (document.getElementById("exp_month").value == "" || document.getElementById("exp_year").value == ""){
			document.getElementById("l_exp_month").className = "error";
			msg = msg + "Credit Card Expiry Date is invalid.<br>";
			error = 1;
		} else {document.getElementById("l_exp_month").className = "";}

		
		if (error == 1) {
			//alert("Information is missing or invalid. Please correct the following fields:\n" + msg)
			document.getElementById("validate_checkout").style.display="block";
		} else {
			document.getElementById("validate_checkout").style.display="none";
			document.getElementById("b_back").style.display="none";
			document.getElementById("b_continue").style.display="none";
			document.getElementById("processing").style.display="block";
					
			//document.getElementById("checkout_confirm").action = SSL_URL + "/socialmedia/4105/confirmation.asp";
			document.getElementById("checkout_confirm").submit();
		}
}




function checkDiscount(status){
	if(status=="open"){
		document.getElementById("dv_discount_code").style.display="block";
	}else{
		document.getElementById("dv_discount_code").style.display="none";
	}
}



/* ------------------------------------------------------------- 
   AJAX -------------------------------------------------------- */ 

	
	function createRequestObject() {		
		var ro;
		if(browserName == "MSIE"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	var http = createRequestObject();





/* ------------------------------------------------------------- 
   Send to A Friend -------------------------------------------- */ 
   
   
	function sendtoafriend(){
			document.getElementById("popin").style.display = "block";
	}
   
	function closeSend(){
			document.getElementById("popin").style.display = "none";
	}
		   
	function validate_form(){
		Goon = "0";
		var msg = "";
		if(document.getElementById("s_name").value == ""){ Goon = "1"; document.getElementById("t_s_name").className="error"; }else{ document.getElementById("t_s_name").className="text";}
		if(!checkEmail(document.getElementById("s_email").value)){ Goon = "1"; document.getElementById("t_s_email").className="error";	}else{ document.getElementById("t_s_email").className="text";}
		if(document.getElementById("s_friendname").value == ""){ Goon = "1"; document.getElementById("t_s_friendname").className="error"; }else{ document.getElementById("t_s_friendname").className="text";}
		if(!checkEmail(document.getElementById("s_friendemail").value)){	Goon = "1"; document.getElementById("t_s_friendemail").className="error"; }else{ document.getElementById("t_s_friendemail").className="text";}
		if(Goon == "0")	{
			name = document.getElementById("s_name").value;
			email = document.getElementById("s_email").value;
			friendname = document.getElementById("s_friendname").value;
			friendemail = document.getElementById("s_friendemail").value;
			message = document.getElementById("s_message").value;
			path_query_url = document.getElementById("path_query_url").value;
			
			http.open('get', '/socialmedia/4105/db_send.asp?path_query_url='+path_query_url+'&name='+name+'&email='+email+'&friendname='+friendname+'&friendemail='+friendemail+'&message='+escape(message));
			http.onreadystatechange = handleLoginResponse;
			http.send(null);
		}else{	
			document.getElementById("validate_send").style.display = "block";
			document.getElementById("validate_send").innerHTML = "Please fill or correct all the fields in <span class='error'>red</span>, then click send.";
		}
	}
		
		
	function handleLoginResponse(){
		if(http.readyState == 4){			
			if(http.responseText=="good"){			
				document.getElementById("validate_send").style.display = "block";
				document.getElementById("validate_send").innerHTML = "<br /><b>Thank you.</b><br />An email has been sent to your friend.";
				document.getElementById("s_name").value = "";
				document.getElementById("s_email").value = "";
				document.getElementById("s_friendname").value = "";
				document.getElementById("s_friendemail").value = "";
				document.getElementById("s_message").value = "";
			}else{
				document.getElementById("validate_send").style.display = "block";
				document.getElementById("validate_send").innerHTML = "<br /><b>Sorry.</b><br />An error occurred. Please try again.";
			}
		}
	}
	
	
