﻿var appUrl = "";
var myExploricaUrl = "";

function isValidTc(code) {
	var re = /^[a-zA-Z]([\w'.]{1,}-){1,}[0-9]+[\s]*$/;
	return re.test(code); 	
}

function viewPrintableItinerary()
{
    var url = "PrintableItinerary";
    var newWin = window.open(url, "PrintItin", "toolbar=yes,scrollbars=yes,menubar=yes,width=668,height=500");
    if(newWin != null && newWin.focus) newWin.focus();
}

function viewMap() {
    var newWin = window.open("Map", "_blank", "toolbar=no,location=no,scrollbars=auto,width=500,height=520");
}

function viewPopDoc(topic) {    
  var features = "dependent=yes,width=500,height=510,scrollbars=yes,resizable=yes";
  var newWin = window.open( appUrl + "PopupDocument.aspx?topic=" + topic, "popup", features );
}

function openWin( URL, width, height, scrollbars, windowname) {
	var newWin = window.open(URL,windowname,"toolbar=no,location=no,scrollbars=" + scrollbars + ",width=" + width + ",height=" + height);
}

function viewTourDiary(code) {
    var features = "dependent=yes,width=600,height=410";
    var url = "http://diary.explorica.com/TourDiary.aspx?tourCenterCode=" + code;    
    
    if ( 3 == arguments.length )
        url += "&diaryDate=" + arguments[1] + "&imageNum=" + arguments[2];
        
    location.href = url;
}

function changeCountry(list) {
    var value = list.value;
	var url = null;
	
	if(value != null && value != "")
	{
		if(value == "1")
		{
			url = appUrl.substr(0, appUrl.lastIndexOf(".")) + ".com";
		}
		else if(value == "2")
		{
			url = appUrl.substr(0, appUrl.lastIndexOf(".")) + ".ca";
		}
		
		if(url != null)
			window.location.href = url;
	}
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


var activeTT = null;


function showTTRating(sender)
{
   var divRating = $ge("divRating");
   var tt = $ge("ttTable");
   if(tt)
   {
        toggleVisible("ttTable",false);
   }
   var left = 0, top = 0;
   divRating.style.display = "block";  
   for(var parent = sender; parent != null; parent = parent.offsetParent) {
        left += parent.offsetLeft;
        top += parent.offsetTop;
    }    
   activeTT = divRating;  
   divRating.style.top = (top+15) + "px";
   divRating.style.left = (-110 + left) + "px";
}

function hideTTRating()
{
    var divRating = $ge("divRating");
    if(divRating) { divRating.style.display = "none";  }
    if(activeTT !=null ) { hideTT(); }
}

function showTT(a, topOffset, leftOffset, parentControlName) {
    if(activeTT != null) {
        if(a == activeTT) {
            toggleVisible("ttTable", false);
            activeTT = null;
            return false;
        }         
    }
    var tt = $ge("ttTable");
    var divRating = $ge("divRating");
    if(divRating)
    {
        if(activeTT == $ge("divRating"))
        {
            divRating.style.display = "none"; 
        }
    }
    var left = 0, top = 0;
    var text = a.getAttribute("Description");
    var matches = text.match(/\{\d+\}/);        
    if(matches != null && matches.length > 0) {
        var more = a.getAttribute("MoreInfoText").split("#@#");
        var hrefs = a.getAttribute("MoreInfoHref").split("#@#");
        var target = (a.getAttribute("NoTarget") == null) ? "" : a.getAttribute("NoTarget");        
        do {
            var num = new Number(matches[0].substr(1,1)); 
            text = text.replace(matches[0], "<a href='" + hrefs[num] + "' target='" + target + "'>" + more[num] + "</a>");            
        }while((matches = text.match(/\{\d+\}/)) != null && matches.length > 0);
    }    
    $ge("ttTableText").innerHTML = text;
    activeTT = a;
    var parentControl = $ge(parentControlName);
    if(!parentControl)
    {
        parentControl = a;
    }
    for(var parent = parentControl; parent != null; parent = parent.offsetParent) {
        left += parent.offsetLeft;
        top += parent.offsetTop;
    }
    tt.style.display = "block";        
    tt.style.top = (top-tt.offsetHeight+topOffset) + "px";
    tt.style.left = (left + leftOffset) + "px";                    
}

function hideTT() {
	var x = $ge("ttTable");
    if(x) x.style.display = "none";
    activeTT = null;
    hideTTRating();
}
		
		
function openDestination( destination, width, height, windowname, tab ) {
			  var URL = appUrl + "DestinationsViewer.aspx?&destinations=" + destination + "&tab=" + tab;
			  var newWin = window.open(URL,windowname,"toolbar=no,location=no,scrollbars=yes,width=" + width + ",height=" + height);
}

var nh_st_timer;
var nh_st_pauselength = 750;

function nh_label_on(){

		imageName="nh_st_label";	
		document[imageName].src = "images/nh_st_on.gif";
		nh_open_sub();
}

function nh_label_off(){
				
		imageName="nh_st_label";	
		document[imageName].src = "images/nh_st_off.gif";
		nh_close_sub();
}

function nh_open_st(){

	window.clearTimeout(nh_st_timer);
	nh_label_on();
	
}

function nh_close_st(){

	nh_st_timer = setTimeout( "nh_label_off()", nh_st_pauselength );

}

function nh_open_sub(){

	str="nh_sub";
	thediv = document.getElementById(str);
	thediv.style.display = "block";
}

function nh_close_sub(){
	str="nh_sub";
	thediv = document.getElementById(str);
	thediv.style.display = "none";
}

function nh_sub_over( obj ){
	window.clearTimeout(nh_st_timer);
	obj.style.backgroundColor="#a0a0a0";
	obj.style.color="#ffffff";
}

function nh_sub_out( obj ){
	nh_st_timer = setTimeout( "nh_label_off()", nh_st_pauselength );
	obj.style.backgroundColor="";
	obj.style.color="#ee9132";
}

function nh_sub_href( url ){

    if( url.indexOf("Browse") > -1 ){
        document.location = url;
    }else{	
	    window.open( url );
	}
}

function draw_flag_icons(){
	
	dl = document.location.toString().toLowerCase();

	cn_na_url="http://usacanada.explorica.cn";
	us_na_url="http://usacanada.explorica.com";
	ca_na_url="http://usacanada.explorica.ca";
	cn_int_url="http://www.explorica.cn";
	us_int_url="http://www.explorica.com";
	ca_int_url="http://www.explorica.ca";
	

	if( dl.indexOf( "usacanada.explorica.com" ) >= 0 ){
				   
		us_icon = "<a href=\"" +  us_na_url + "\"><img src=\"../../../images/nh_icon_us.gif\" alt=\"转到美国英语\" width=\"16\" height=\"11\" border=\"0\" /></a>";
		ca_icon = "<a href=\"" + ca_na_url + "\"><img src=\"../../../images/nh_icon_ca.gif\" alt=\"转到加拿大英语\" width=\"16\" height=\"11\" hspace=\"5\" border=\"0\" /></a>";
		cn_icon = "<a href=\"" + ca_na_url + "\"><img src=\"../../../images/nh_icon_cn.gif\" alt=\"转到中文\" width=\"16\" height=\"11\" hspace=\"5\" border=\"0\" /></a>";
		
		drawstring = us_icon + " " + ca_icon + " " + cn_icon;
				   
	}else{
		us_icon = "<a href=\"" +  us_int_url + "\"><img src=\"../../../images/nh_icon_us.gif\" alt=\"转到美国英语\" width=\"16\" height=\"11\" border=\"0\" /></a>";
		ca_icon = "<a href=\"" +  ca_int_url + "\"><img src=\"../../../images/nh_icon_ca.gif\" alt=\"转到加拿大英语\" width=\"16\" height=\"11\" hspace=\"5\" border=\"0\" /></a>";
		cn_icon = "<a href=\"" +  cn_int_url + "\"><img src=\"../../../images/nh_icon_cn.gif\" alt=\"转到中文\" width=\"16\" height=\"11\" hspace=\"5\" border=\"0\" /></a>";
		
		if( dl.indexOf("explorica.com" ) >= 0 ){
			
				drawstring = us_icon + " " + ca_icon + " " + cn_icon;
		}else{
			
				drawstring = ca_icon + " " + us_icon + " " + cn_icon;
		}
		
	}
	
	document.write( "<div style=\"\">" + drawstring + "</div>");
}

function initializePRM() {
	var prm = Sys.WebForms.PageRequestManager.getInstance();
	var form = prm._form;
	form._initialAction = form.action = window.location.href;
}
