var ireallyhaveflash = false;
if (((navigator.appName == "Netscape") && (parseFloat(navigator.appVersion) >= 4) && navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)) {
	if (navigator.plugins['Shockwave Flash'].description.indexOf("6.") != -1) ireallyhaveflash = true;
	if (navigator.plugins['Shockwave Flash'].description.indexOf("7.") != -1) ireallyhaveflash = true;
	if (navigator.plugins['Shockwave Flash'].description.indexOf("8.") != -1) ireallyhaveflash = true;
	if (navigator.plugins['Shockwave Flash'].description.indexOf("9.") != -1) ireallyhaveflash = true;
	if (navigator.plugins['Shockwave Flash'].description.indexOf("10.") != -1) ireallyhaveflash = true;
}
else if ( (navigator.userAgent) && (navigator.userAgent.indexOf("MSIE") >= 0) && (navigator.appVersion.toLowerCase().indexOf("win") != -1) ) {
	document.write('<script language=VBScript>');
	document.write('on error resume next \n');
	document.write('ireallyhaveflash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('ireallyhaveflash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('ireallyhaveflash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	document.write('ireallyhaveflash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
	document.write('ireallyhaveflash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
	document.write('<\/script>');
}



function load_init(){
	//var e = new Effect.Appear('testerbox');
	
	var left = document.getElementById('left_html_content');
	var right = document.getElementById('right_html_content');
	right.style.display = left.style.display = "none";
	Effect.BlindDown('left_html_content');
	Effect.BlindDown('right_html_content');
}

function popscr(page, w, h, name) {
	specs = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,width=" + w + ",height=" + h + ",menubar=no";
	window.open(page, name, specs);
}

function toggle_flash_size(toggle_state){
	return;
	var flash = get_flash_element();
	var height = "355px";
	
	if(!ireallyhaveflash){height="275px";}

	if(toggle_state == "1"){
		document.getElementById("flash_content").style.height = "500px"
		flash.height = "500px";
	}else{
		document.getElementById("flash_content").style.height = "355px"
		flash.height = "355px";
	}
}


/*---------------------------
Flash Control
---------------------*/
function call_flash_section_change(section_index){
	if(ireallyhaveflash){
		var flash = get_flash_element();
		var section_change = flash.js_changeSection(section_index);
	}else{
		html_change(parseInt(section_index)+1);
	}
}


function get_flash_element(){
  if(navigator.appName.indexOf("Microsoft") != -1) {
    flash = window.nav_bar;
  }else {
    flash = window.document.nav_bar;
  }
  return flash
}

/*------------------------------------
HTML Control
---------------------------------*/
function html_change(section_id){
	var xajax_section = "";
	switch(section_id){
			case 1:
				xajax_section ="email"
				break;
			case 2:
				xajax_section ="alerts"
				break;
			case 3:
				xajax_section ="traveler"
				break;
			case 4:
				xajax_section ="mobile"
				break;				
			case 5:
				xajax_section ="team"
				break;
	}
	
	xajax_swap_content(xajax_section, true, section_id);
}


var sections = ["pretrip", "alerts", "traveler", "mobile", "team"];
function html_swap_content(html_section_index){
	var current_section = sections[html_section_index-1]

/*	var width=768; 
	var height=413;
	if(current_section == "team"){
		width=768; 
		height=269;
	}*/
//	document.getElementById("main_image").width = width
//	document.getElementById("main_image").height = height
	document.getElementById("main_image").src = "./html_content/images/main_"+current_section+".jpg";	
	
	document.getElementById("main_image").useMap = ""
	if(current_section =="traveler") document.getElementById("main_image").useMap = "#traveler_map"
	if(current_section =="mobile") document.getElementById("main_image").useMap = "#mobile_map"
	
	update_menu_nav(current_section);
	
	if(current_section == "mobile" || current_section =="traveler"){
		document.getElementById("top_right_ad").style.display = "block";
	}else{
		document.getElementById("top_right_ad").style.display = "none";
	}
	

}

function update_menu_nav(current_section){
//<a href="javascript:{}" onclick="html_change(1);" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('menu_pretrip','','./html_content/images/topnav_pretrip_2.gif',1)">
//	<img src="./html_content/images/topnav_pretrip_1.gif" height="32" name="menu_pretrip" border="0" id="menu_pretrip" />
//</a>

var e = document.getElementById("menu_bar");
var content = "<table cellpadding='0' cellspacing='0' height='32px'>\n<tr>\n";
	for(var x=0;x<sections.length;x++){
		var c_section = sections[x];
		if(c_section == current_section){
			content += "<td width='142' height='32'>";
			content += "<img src='./html_content/images/topnav_"+c_section+"_3.gif' height='32' name='menu_"+c_section+"' border='0' id='menu_"+c_section+"' />";
			content += "</td>";
		}else{
			content += "<td width='142' height='32'>";
			content += "<a href='javascript:{}' onclick='html_change("+(x+1)+");' onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('menu_"+c_section+"','','./html_content/images/topnav_"+c_section+"_2.gif',1)\"><img src='./html_content/images/topnav_"+c_section+"_1.gif' height='32' name='menu_"+c_section+"' border='0' id='menu_"+c_section+"' /></a>";
			content += "</td>";
		}
	}
e.innerHTML = content
}


/*-----------------------------------
Story Control for Team Page
------------------------------------*/
control_max_index = 8
control_max_numbers = 6
function swap_control(ctrl_element, start_index){
	total = start_index > control_max_numbers ? control_max_index : control_max_numbers;

	replace_str = start_index > control_max_numbers ? "<a href='javascript:{}' id='link_back' onclick='swap_control(this.parentNode, 1)'><</a> " : "";
	for(x=start_index;x<=total;x++){
		if(x != current_control_index){
			replace_str +=  "<a href='javascript:{}' id='link_"+x+"' onclick='load_story(this, "+x+")'>"+x+"</a> ";
		}else{
			replace_str +=  "<a href='javascript:{}' style='text-decoration:none' id='link_"+x+"' onclick='load_story(this, "+x+")'>"+x+"</a> ";
		}
	}
	replace_str += start_index < control_max_numbers ? "<a href='javascript:{}' id='link_forward' onclick='swap_control(this.parentNode, "+(start_index+control_max_numbers)+")'>></a> " : "";
	ctrl_element.innerHTML = replace_str;
}


current_selected_control = null
function load_story(ctrl_element, story_id){
	ctrl_element.blur();
	ctrl_element.style.textDecoration = "none";
	current_control_index = ctrl_element.id.split("_")[1];
	for(element_index in ctrl_element.parentNode.childNodes){
		child = ctrl_element.parentNode.childNodes[element_index]
		if(child != null && child.id != undefined){
			if(child.tagName == "A" && child.id != ctrl_element.id){
				child.style.textDecoration = "underline";
			}
		}
	}
		xajax_load_story(story_id);	
}


/*--------------------------------------------------------------------


/*-----------------------------------
ALERT Message Validation and Sending
------------------------------------*/
total_alerts_sent = 0;
function send_tlc_alert(){
	if(validate_phone()){		
		document.getElementById("alert_status").innerHTML = "Sending your Sample TLC Alert";
		//alert(readCookie("total_alerts_sent"));
		if(readCookie("total_alerts_sent") != null) total_alerts_sent = parseInt(readCookie("total_alerts_sent"));
		total_alerts_sent++;
		createCookie("total_alerts_sent", total_alerts_sent, 1);
		send_alert_to_phone();	
		if(document.getElementById("phone_first") != null){
			document.getElementById("tel_area_code").value = document.getElementById("phone_first").value = document.getElementById("phone_last").value = "";
		}
	}else{
		document.getElementById("alert_status").innerHTML = "Please enter a valid U.S. phone number. <br/>Try another phone number.";
	}
}

function validate_phone(entry){
	var phone_number = document.getElementById("tel_area_code").value + "-"+document.getElementById("phone_first").value + "-"+document.getElementById("phone_last").value
	return !(phone_number.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
}

function send_alert_to_phone(){
		var telephone_number = document.getElementById("phone_first").value + document.getElementById("phone_last").value;
		var area_code = document.getElementById("tel_area_code").value
		var text_message = document.getElementById("confirm_text").checked ? "on" : "off";
		var query_string = "tel_area_code="+area_code+"&tel_number="+telephone_number+"&confirm_text="+text_message;
		send_request("php/orbitztlc_php/alerts_proxy.php?"+query_string, handle_response_alerts);	
}



/*--------------------------------------------------------------------


/*-----------------------------------
AJAX Function
------------------------------------*/
function create_request_object() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = create_request_object();
function send_request(url, handler) {
    http.open('get', url);
    http.onreadystatechange = handler;
    http.send(null);
}

function handle_response_alerts(override) {
    if(http.readyState == 4 || override){
		//var response = http.responseText;
		if(total_alerts_sent < 4 && !override){
			document.getElementById("alert_status").innerHTML = "Thank you for trying alerts! You should receive <br/>a call shortly. <br/>Try another phone number:";
		}else{
			document.getElementById("alert_status").innerHTML = "You can only send 4 sample alerts per day. Thank you for trying alerts!";
			document.getElementById("phone_entry").innerHTML = "";
		}
    }
}


/*--------------------------------------------------------------------


/*-----------------------------------
Cookie Functions
------------------------------------*/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/* MM Rollover Functions */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
