/* Mark Wise : default.js -> * : akextremeadventures.com : 1-29-08 : 3-24-08 -> Mark Wise */

function addtcEvent(){
	var e = arguments[0] || window.event;
	
	if(e.type == "click"){
		var tc = new TravelCompanion("tc");
				
	}

}

function inquiryFormEvent(){
	var err = [];
	var ok = [];

	//::
	// CHECK EACH REQUIRED FIELD
	var f = "pi_first_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "pi_last_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if ( $("pi_birth_month").selectedIndex == 0 || $("pi_birth_day").selectedIndex == 0 || $("pi_birth_year").selectedIndex == 0 ) {
		err.push("pi_birth_month");
	} else {
		ok.push("pi_birth_month");
	}
	
	var f = "ci_email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_telephone";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_address_1";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_country";
	if ( $(f).value == "USA" || $(f).value == "CAN" || $(f).value == "AUS" ) {
		var f = "ci_state_region";
		if ( $(f).selectedIndex == 0 ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	} else {
		var f = "ci_state_region_other";
		if ( $isBlank($(f).value) ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	}
	
	var f = "ci_city";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_postal_code";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_source";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ti_tour_name";
	if ( $(f).selectedIndex == 0 ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}

}

function brochureFormEvent(){
	var err = [];
	var ok = [];
	
	//::
	// CHECK EACH REQUIRED FIELD
	var f = "pi_first_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "pi_last_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if ( $("pi_birth_month").selectedIndex == 0 || $("pi_birth_day").selectedIndex == 0 || $("pi_birth_year").selectedIndex == 0 ) {
		err.push("pi_birth_month");
	} else {
		ok.push("pi_birth_month");
	}
	
	var f = "ci_email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_address_1";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_country";
	if ( $(f).value == "USA" || $(f).value == "CAN" || $(f).value == "AUS" ) {
		var f = "ci_state_region";
		if ( $(f).selectedIndex == 0 ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	} else {
		var f = "ci_state_region_other";
		if ( $isBlank($(f).value) ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	}
	
	var f = "ci_city";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_postal_code";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_source";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}
}

function contactFormEvent(){
	var err = [];
	var ok = [];
	
	//::
	// CHECK EACH REQUIRED FIELD
	var f = "pi_first_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "pi_last_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if ( $("pi_birth_month").selectedIndex == 0 || $("pi_birth_day").selectedIndex == 0 || $("pi_birth_year").selectedIndex == 0 ) {
		err.push("pi_birth_month");
	} else {
		ok.push("pi_birth_month");
	}
	
	var f = "ci_email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_address_1";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_country";
	if ( $(f).value == "USA" || $(f).value == "CAN" || $(f).value == "AUS" ) {
		var f = "ci_state_region";
		if ( $(f).selectedIndex == 0 ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	} else {
		var f = "ci_state_region_other";
		if ( $isBlank($(f).value) ) {
			err.push(f);
		} else {
			ok.push(f);
		}
	}
	
	var f = "ci_city";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_postal_code";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_source";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}
}

function expedition_dates() {
	var xml = arguments[0];
	var package = xml.getElementsByTagName("package")[0];
	
	var select = $('departure_date');
	
	// DELETE EXISTING OPTIONS FROM THE SELECT BOX
	$removeChildNodes('departure_date');
	
	// ADD NEW OPTIONS TO THE SELECT BOX
	for ( var j = 0; j < package.childNodes.length; j++ ) {
		//alert(package.childNodes[j].firstChild.nodeValue);
		var option = document.createElement("option");
		option.appendChild(document.createTextNode(package.childNodes[j].firstChild.nodeValue));
		option.value = package.childNodes[j].attributes[0].nodeValue;
		select.appendChild(option);
	}
	
	// IF NO DEPARTURE DATES WERE RETURNED CREATE A DUMMY OPTION
	if ( package.childNodes.length == 0 ) {
		var option = document.createElement("option");
		option.appendChild(document.createTextNode("Call for departure information."));
		option.value = "0";
		select.appendChild(option);
	}
}

function addFriendEvent(){
	var e = arguments[0] || window.event;
	
	if(e.type == "click"){
		var tc = new Friend("tc");
				
	}

}

function friendFormEvent(){
	var err = [];
	var ok = [];

	//::
	// CHECK EACH REQUIRED FIELD
	var f = "pi_first_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "pi_last_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ci_email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "ti_tour_name";
	if ( $(f).selectedIndex == 0 ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "tc_email_1";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}

}

/*function newsletter_action() {
var successValue = "Thank you for subscribing";
var errValue = "Invalid Email Address";
var xml = arguments[0];
var newsletter = xml.getElementsByTagName("newsletter")[0];
var response = newsletter.childNodes[0].firstChild.nodeValue;
if(response == "Yes"){
	$("email").value = successValue;
	$("email").style.color = "#69d2fe";
	
}
if(response == "No"){
	$("email").value = "An error occurred, Please try subscribing again.";
	
}
if(response == "Invalid Email"){
	$("email").value = errValue;
	
}*/

function optOutFormEvent() {
	var err = [];
	var ok = [];
	
	// CHECK THE EMAIL FIELD
	var f = "email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}
}

function feedbackFormEvent(){
	var err = [];
	var ok = [];
	
	//::
	// CHECK EACH REQUIRED FIELD
	var f = "pi_first_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
	
	var f = "pi_last_name";
	if ( $isBlank($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}
		
	var f = "ci_email";
	if ( !$isEmail($(f).value) ) {
		err.push(f);
	} else {
		ok.push(f);
	}

	if(ok.length > 0) {
		for ( var j=0; j < ok.length; j++ ) {
			document.getElementById(ok[j]).parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
	
	if(err.length > 0){
		for(var i=0; i<err.length; i++){
			document.getElementById(err[i]).parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		$(err[0]).focus();
		return false;
		
	}
	else {
		return true;
	}
}