//<!--
var local_server_position = "us";
function ss(w){window.status=w;return true;}
function cs(){window.status='';}
function ga(l){if (l) location.href=l;}
function enabled_searchDateOption(clicked, type)
{
	var f = document.getElementById(type);
	var workRange;
	if (type == "SoldSearch")
	{
		workRange = new Array("FromMonth", "FromDate", "FromYear", "ToMonth", "ToDate", "ToYear");
	}
	else if (type == "BookingSearch")
	{
		workRange = new Array("Month", "Date", "Year");
	}
	if (workRange)
	{
		f['searchByBar'].disabled = !clicked;
		for (i=0; i<workRange.length; i++)
		{
			f[workRange[i]].disabled = clicked;
		}
	}
}	

function Device_OnLoad()
{
	if (navigator.userAgent.indexOf("Windows CE") != -1) 
	{
		window.location="http://www.gotobus.com/palm.html";
	}
}

function Vendor_onLoad(sold, booking)
{
	var s  = document.getElementById('SoldSearch');
	var b = document.getElementById('BookingSearch');
	if (s)
	{
		enabled_searchDateOption(sold, 'SoldSearch');
	}
	if (b)
	{
		enabled_searchDateOption(booking, 'BookingSearch');
	}
}

function opener_url(url)
{
        var target = window;
        if (window.opener != null && window.opener.closed == false)
        {
                target = window.opener;
        }
        target.location.href=url;
        target.focus();
        return false;
}


function open_url_param(url, date)
{
	var lnk = url;
	if (date != "")
	{
		if (lnk.match(/\?/))
		{
			lnk += "&d="+date;
		}
		else
		{
			lnk += "?"+date;
		}
	}
	opener_url(lnk);
}

function set_gid_cookie(value, expires)
{
	var name = "gid";
    var today = new Date();
    today.setTime(today.getTime());
    if (!expires)
    {
    	expires = 7;
    }
    expires = expires * 1000 * 60 * 60 * 24;
    var expires_date = new Date(today.getTime() + expires);
    document.cookie = name + "=" +escape(value) + (expires ? ";expires=" + expires_date.toGMTString() : "") + ";path=/;domain=gotobus.com";
}

function pre_set_data()
{
	var date = null;
	if (window.location.search.length>0)
	{
		data = window.location.search.substring(1);
		if (data.match(/-/))
		{
			var s  = document.getElementById('Date');
			set_tour_date (s, data);
		}
		else
		{
			set_gid_cookie(data);
		}
	}
}


function pre_set_date()
{
	var date = null;
	if (window.location.search.length>0)
	{
		date = window.location.search.substring(1);
		var s  = document.getElementById('Date');
		set_tour_date (s, date);
	}
}

function set_tour_date(obj, selected_date)
{
	if (obj == null || selected_date == null || selected_date == "")
	{
		return;
	}

	var sdate = selected_date.substr(0, 10);
	for (var i=0; i< obj.options.length; i++)
	{
		var val = obj.options[i].value;
		if (val != "")
		{
			val = val.substr(0,10);
			if (sdate.match(val))
			{
				obj.options.selectedIndex = i;
				return;
			}
		}
	}
}

function OnCalendarClick()
{
        window.open("http://www.gotobus.com/calendar/calendar.html", "calendar", 'width=240,height=200');
}

var browser = window.navigator.appName;
var isIE = false;
var Win = navigator.userAgent.indexOf("Win") > -1;
var MSIE = navigator.appName == "Microsoft Internet Explorer";

if (Win && MSIE)
{
    var n = navigator.userAgent;
    var MSIEVer = n.substr(n.indexOf("MSIE ")+("MSIE ").length, 4);
    MSIEVer = parseFloat(MSIEVer); 
    if (MSIEVer > 5.0)
	isIE = true;
}

function addToFavorites(url, title)
{
    if (window.external)
    {
        window.external.AddFavorite(url, title)
    }
    else
    { 
        alert("Sorry! Your browser doesn't support this function.");
    }
}

var d_about_up = "http://www.gotobus.com/images/explore_up.gif";
var d_about_down = "http://www.gotobus.com/images/explore_down.gif";
function changeImage_aboutus()
{
    if (document.images) {
        if (document.myImage_aboutus.src == d_about_up)
            document.myImage_aboutus.src = d_about_down;
        else
            document.myImage_aboutus.src = d_about_up;
    }
}

function SwitchMenu(obj)
{
    if(document.getElementById) {
        var el = document.getElementById(obj);
        if(el.style.display != "block")
            el.style.display = "block";
        else
            el.style.display = "none";
        changeImage_aboutus();
    }
}

function set_selected(obj, v)
{
    for (var i=0; i<obj.options.length; i++)
    {
        if (obj.options[i].value == v)
        {
            obj.options.selectedIndex = i;
            return i;
        }
    }
    return -1;
}

function clear_show_all_text(obj)
{
        if (obj && obj.value == "Show All")
        {
                obj.value = "";
        }
}

function set_cookie(name, value, expires) 
{
    var today = new Date();
    today.setTime(today.getTime());
    if (expires)
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + expires);
    document.cookie = name + "=" +escape(value) + (expires ? ";expires=" + expires_date.toGMTString() : "") + ";path=/;domain=gotobus.com";
}

function get_cookie(name)
{
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
    {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function Trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function viewSavedTrips()
{
	make_unvisible();
    var savedBlock=document.getElementById("savedBlock");
    if(!savedBlock){
        savedBlock = document.createElement("div");
        savedBlock.id = "savedBlock";
    }
    savedBlock.innerHTML="";  
    var light_top = (document.documentElement.clientHeight - 230)/2 + 'px';
	var light_left = document.body.scrollLeft + (document.body.clientWidth - 420)/2 + 'px';
	savedBlock.style.left = light_left;
	savedBlock.style.top = light_top;
	savedBlock.className = "top_div";		
    var param = "type=find_saved_trip";
    var compare_xml;
    if(window.XMLHttpRequest) {
        compare_xml = new XMLHttpRequest();
    } else {
        compare_xml = new ActiveXObject("MSXML2.XMLHTTP");
    }
    url = '/cgi-bin/ajax.cgi?' + param;
    compare_xml.open("GET", url, true);
    compare_xml.onreadystatechange = function show_div()
    {
        if (compare_xml.readyState == 4)
        {
            var showResponseText=compare_xml.responseText;
            savedBlock.innerHTML=showResponseText;   
            savedBlock.style.display='block'; 
        }
    };
    compare_xml.setRequestHeader("If-Modified-Since","0");
    compare_xml.send("");
    document.body.appendChild(savedBlock);
    var fadeBlock=document.getElementById("fadeBlock");
    if(!fadeBlock){
        var fadeBlock = document.createElement("div");
        fadeBlock.id="fadeBlock";
    }
    
    fadeBlock.style.height = $(document).height() + 'px';
	fadeBlock.style.width = document.body.scrollWidth + 'px';
    fadeBlock.className="bg_div";   
    document.body.appendChild(fadeBlock);
    fadeBlock.style.display='block';
}
function hideDiv(tag, fade)
{
	make_visible();
	var light=document.getElementById(tag);
	var fade=document.getElementById(fade);
	light.style.display='none';
	fade.style.display='none';
	if(document.getElementById('compare_page') && document.getElementById('compare_page').value !=get_count())
	{

		pageRefresh();
	}
}

function  make_unvisible(){
	var as = document.getElementsByTagName("select");
	if(as !=null && as.length>0){
		for(var i=0; i < as.length; i++) {
			as[i].style.visibility="hidden";
		}
	}
}
function  make_visible(){
	var as = document.getElementsByTagName("select");
	if(as !=null && as.length>0){
		for(var i=0; i < as.length; i++) {
			as[i].style.visibility="visible";
		}
	}
}

function show_link(value) {
	if(value) {
		var currentValue = get_cookie('SAVED_TRIPS');
		if(!currentValue)
		{
			currentValue="";
		}
		var exists = currentValue.indexOf(value);
		var link_div = document.getElementById(value+'_a');
		if(link_div)
		{
			if(exists == -1){
				link_div.innerHTML="<a href='javascript:void(0)' class='n_savetour' title='Save Tour to Compare' onclick='saveToCookie(" + value+ ");'>Save Tour</a>";
			} else {
				link_div.innerHTML="<a href='javascript:void(0)' class='n_removetour' title='Remove' onclick='removeTrip(" + value+ ");'>Remove</a>" + 
				"<a href='http://www.gotobus.com/cgi-bin/v.cgi?a=product_compare' class='n_statenav_compare' title='Compare Tours' class='link1'>Compare</a>";
			}
		}
		showDetailSaveLink(value);
	}
}

function saveToCookie(value) {
	if(value) {
		var currentValue = get_cookie('SAVED_TRIPS');
		if(!currentValue)
		{
			currentValue = "";
		}
		var exists = currentValue.indexOf(value);
		if(exists == -1) {
			if(currentValue.length == 0) {
				var newValue = value;
			} else {
				var newValue = currentValue + "," + value;
			}				
			set_cookie('SAVED_TRIPS',newValue,7);
		}
	}
	updateSavedTrip(value);
}

function updateSavedTrip(value) {
	show_count();
	show_link(value);
}	

function removeChildNodes() {
	var a = (typeof arguments[0] == "string") ? document.getElementById(arguments[0]) : arguments[0];
	while ( a.hasChildNodes() ) {
		a.removeChild(a.childNodes[0]);
	}
}

function removeSavedTrip(obj,value) {
	if(value) {
		document.body.style.cursor = "wait";
		removeTripFromCookie(value);
		updateRemovedTrip(obj,value);
		document.body.style.cursor = "auto";
	}
}

function removeTripFromCookie(value) {
	if(value) {
		var currentValue = get_cookie('SAVED_TRIPS');
		var exists = currentValue.indexOf(value);			
		if(exists != -1){
			if(currentValue.indexOf("," + value) != -1) {
				var newValue = currentValue.replace("," + value,"");
			} else if(currentValue.indexOf(value + ",") != -1) {
				var newValue = currentValue.replace(value + ",","");
			} else {
				var newValue = currentValue.replace(value,"");
			}
			set_cookie('SAVED_TRIPS',newValue,7);
		} 
	}
}

function removeTrip(value) {
	if(value) {
		removeTripFromCookie(value);
		show_count();
		show_link(value);
	}
}

function updateRemovedTrip(obj,value) {
	var tdParent = obj.parentNode;
	var trParent = tdParent.parentNode;
	var tblParent = trParent.parentNode;		 	
	tblParent.removeChild(trParent);
	show_count();
	show_link(value);
}

function show_count() {
	var count = get_count();
	var stLink = document.getElementById('saved_trip_count');
	if(stLink){
		removeChildNodes(stLink);
		stLink.appendChild(document.createTextNode(count));
	}
	var div_count = document.getElementById('div_saved_trip_count');
	if(div_count){
		removeChildNodes(div_count);
		div_count.appendChild(document.createTextNode(count));
	}
}

function get_count() {
	var currentValue = get_cookie('SAVED_TRIPS');
	var count = 0;
	if(currentValue && currentValue.length != 0)
	{
		count = currentValue.split(',').length;
	}
	return count;
}
function pageRefresh()
{
	window.location.reload();
}

function showDetailSaveLink(value) {
	if(value) {
		var currentValue = get_cookie('SAVED_TRIPS');
		if(!currentValue)
		{
			currentValue="";
		}
		var exists = currentValue.indexOf(value);
		var link_div = document.getElementById("detail_save_link");
		if(link_div)
		{
			if(exists == -1){
				link_div.innerHTML="<a href='javascript:void(0)' class='n_savetour' title='Save Tour to Compare' onclick='saveToCookie(" + value+ ");'>Save this tour</a>";
			} else {
				link_div.innerHTML="<a href='javascript:void(0)' class='n_removetour' title='Remove' onclick='removeTrip(" + value+ ");'>Remove</a>";
			}
		}
	}
}
function setTabInit(name,cursel,n){
}
function product_onload()
{	
}
function show_hide_image_div(obj,nth_day)
{
	var image_div=document.getElementById("add_images_div_"+nth_day);
	if(image_div.style.display == "block")
	{
		obj.src="/images/add_image.gif";
		image_div.innerHTML = "";
		image_div.style.display="none";
	}
	else
	{
		obj.src="/images/reduce_image.gif";
		image_div.innerHTML=document.getElementById("serach_image_hidden_div").innerHTML;
		var inputs = image_div.getElementsByTagName("input"); 
		var selects = image_div.getElementsByTagName("select"); 
		var destination = selects[0];
		var divs = image_div.getElementsByTagName("div"); 
		var div = divs[0];
		var keywords;
		var search_button;
		for(var i=0;i<inputs.length;i++)
		{
			if(inputs[i].name=="keywords")
			{
				keywords = inputs[i];
			}					
			if(inputs[i].type=="button")
			{
				search_button = inputs[i];
			}
		}
		var product = document.getElementById("product_id");
		search_button.onclick =  function(){
			var param = "type=search_images&keywords="+keywords.value+"&destination="+destination.value+"&product_id="+product.value+"&nth_day="+nth_day;
			var search_xml;
		    if(window.XMLHttpRequest) {
		        search_xml = new XMLHttpRequest();
		    } else {
		        search_xml = new ActiveXObject("MSXML2.XMLHTTP");
		    }
		    var url = '/cgi-bin/ajax.cgi?' + param;
		    search_xml.open("GET", url, true);
		    search_xml.onreadystatechange = function show_div()
		    {
		        if (search_xml.readyState == 4)
		        {
		            var rt_text=search_xml.responseText;
		            div.innerHTML = "";
		            div.innerHTML = rt_text;
		        }
		    };
		    search_xml.setRequestHeader("If-Modified-Since","0");
		    search_xml.send("");					
		};
		image_div.style.display="block";
	}
}
function removeThisNode(spanname,nth_day) {
	var position = spanname.lastIndexOf("_");
	var image_id = spanname.substring(position+1,spanname.length);
	var image_ids_obj = document.getElementById("image_ids_"+nth_day);
	var image_ids = image_ids_obj.value;
	image_ids=image_ids.replace(","+image_id+",",",");
	image_ids_obj.value=image_ids;
	var obj = document.getElementById(spanname);
	var objParent = obj.parentNode;	 	
	objParent.removeChild(obj);
	if(image_ids == ",")
	{
		var message = document.createElement("span");
		message.innerHTML="<img src='/images/logo/nophoto.gif' title='No image' width='70px' height='55px'/>";
		objParent.appendChild(message);
	}
}
function appendToImage(obj,spanname,nth_day) {
	var position = spanname.lastIndexOf("_");
	var image_id = spanname.substring(position+1,spanname.length);
	var image_ids_obj = document.getElementById("image_ids_"+nth_day);
	var image_ids = image_ids_obj.value;
	var exists = image_ids.indexOf(","+image_id+",");
	if(exists >= 0){
		alert("The image already exists!");
		obj.src='/images/already_add.gif';
		obj.onclick=function(){};
	    obj.onmouseover=function(){};
	    obj.onmouseout=function(){};
	    return;
	}
	var div = document.getElementById("image_show_div_"+nth_day);
	if(image_ids == ",")
	{
		var message = div.getElementsByTagName("span")[0];
		div.removeChild(message);
	}
	image_ids_obj.value = image_ids + image_id + ",";
	var objParent = obj.parentNode;	
	var simg = objParent.childNodes[0];
	var img = simg.cloneNode(false);
	img.onclick=function(){};
	var imageObj = document.createElement("span");
	imageObj.setAttribute('name', spanname);
	imageObj.setAttribute('id', spanname);
    imageObj.appendChild(img);
   	var delImag = document.createElement("img");
   	delImag.src="/images/ico_tr_del.gif";
   	delImag.className="delete_image";
	delImag.setAttribute('title', "Delete");
   	delImag.onmouseover= function(){this.src='/images/ico_tr_delover.gif';};
   	delImag.onmouseout= function(){this.src='/images/ico_tr_del.gif';};
    delImag.onclick= function(){removeThisNode(spanname,nth_day)};
    imageObj.appendChild(delImag);
    div.appendChild(imageObj);
    obj.src='/images/already_add.gif';
    obj.onclick=function(){};
    obj.onmouseover=function(){};
    obj.onmouseout=function(){};
}
function getPhotoDiv(obj)
{
	var parNode = obj.parentNode;
	var divNode = parNode.getElementsByTagName("div");
	return divNode[0];	
}
function appendToImageByImage(obj,spanname,nth_day)
{
	var parNode = obj.parentNode;
	var imgNode = parNode.getElementsByTagName("img");
	var add_button = imgNode[1];
	appendToImage(add_button,spanname,nth_day);
}

function getElementsByClassName(clsName,htmltag){ 
	var arr = new Array(); 
	var elems = document.getElementsByTagName(htmltag);
	for (var i = 0; i<elems.length; i++ )
	{
		var elem = elems[i];
		if (elem.className == clsName)
		{
			arr[arr.length] = elem;   
		}
	}
	return arr;
}
var CssClass = {};
CssClass.is = function(e, c){
		if(typeof e == "string") e = document.getElementById(e);
		var classes = e.className;
		if(!classes) return false;
		if(classes == c) return true;
    	return e.className.match(new RegExp('(\\s|^)'+c+'(\\s|$)'));		
};
CssClass.add = function(e, c){
	if(typeof e == "string") e = document.getElementById(e);
	if(CssClass.is(e, c)) return;
	if(e.className) c = " " + c;
	e.className += c;
};
CssClass.remove = function(e, c){
	if(typeof e == "string") e = document.getElementById(e);		
    if (CssClass.is(e,c)) {
		var reg = new RegExp('(\\s|^)'+c+'(\\s|$)');
        e.className=e.className.replace(reg,' ');
    }
};
CssClass.toggle = function(e,c) {
    if (CssClass.is(e,c)) {
        CssClass.remove(e,c);
    }
    else{
        addClass.add(e,c);
    }
};
CssClass.change = function(ele,oc,nc) {
    if (!CssClass.is(e,nc)) {
        if(CssClass.is(e,oc)){
        	CssClass.remove(e,oc);
        }
        CssClass.add(e,nc);
    }
};
function is_ie_six()
{
	var browser=navigator.appName
	var b_version=navigator.appVersion
	var version=b_version.split(";");
	var trim_Version=version[1].replace(/[ ]/g,"");
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0")
	{
		return true;
	}
	else
	{
		return false;
	}
}
//-->


