<!--

// intl cookie setting 

var expDays = 999;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length; 

//alert(unescape(document.cookie.substring(offset, endstr))); 

return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg){
			
			return getCookieVal (j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
 "; path=/" +
//((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function onLoadRedirect(){ 

    //alert("in onLoadRedirect"); 

	var favorite = GetCookie('rpage');

	url = 'default rpage'; 
	if (favorite != null) {
	    url = favorite; 
	    document.location = url;
	} 

//alert('You would have been taken to the ' + favorite + ' page (' + url + '), but this is just a demo!');
	
}

function selectRsiteSFpage(ids){ 
	
	val = ids.options[ids.selectedIndex].value; 
	
	if(val != ''){ 
		document.location = val; 
	}
	
}

function onLoadRedirect2(val){		
	if(val != ''){		
		SetCookie('rpage', val, exp); 
		document.location = val; 
	}
}

function selectRpage(ids){ 
	
	//alert(document.getElementById); 
	
	sf = document.getElementById(ids); 
	
	//alert(sf); 
	
	val = sf.options[sf.selectedIndex].value; 
	
	if(val != ''){
		
			SetCookie('rpage', val, exp); 
		
		document.location = val; 
	}
	
} 

// intl cookie setting end 

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];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
}

function escapeInput(qStr, qVar){
	if(qStr.split(qVar).length > 1){
		var qStrArr = qStr.split(qVar);
		if(qStr.split(qVar)[1].split('&').length > 1){
			qStr = qStrArr[0] + qVar + escape(qStrArr[1].split('&')[0]) + '&' + qStrArr[1].split('&')[1];
		} else {
			qStr = qStrArr[0] + qVar + escape(qStrArr[1].split('&')[0]);
		}
	}
	return qStr;
}

function switchLang(lang) {
	var cururl = unescape(document.location.toString());
	var newurl = "";
	var sind = cururl.indexOf("lang=");
	if (sind != -1) {
		var eind = cururl.indexOf("&", sind);
		if (eind != -1) {
			newurl = cururl.substring(0, sind) + "lang=" + lang + escape(cururl.substring(eind, cururl.length)); //20110316 KK|SPIYGAB added escape();
		} else {
			newurl = cururl.substring(0, sind) + "lang=" + lang;
		}
	} else {
		var qind = cururl.indexOf("?");
		if (qind != -1) {
			if (qind == cururl.length-1) {
				newurl = cururl + "lang=" + lang;
			} else {
				
				var cururls = cururl.split("?"); 
				var cururlPx = cururls[0]; 
				var cururlSx = cururls[1];
				//20110322 KK|SPIYGAB added escape() for textDest;
				newurl = cururlPx + "?lang=" + lang + "&" + cururls[1];
				newurl = escapeInput(newurl, 'txtDest=');
				newurl = escapeInput(newurl, 'txtAct=');
				newurl = escapeInput(newurl, 'txtHotel=');				
			}
		} else {
			newurl = cururl + "?lang=" + lang;
		}
	}
	if(newurl != '')
	{
		var tm = window.location.href.split("/");	
		var siteLang = tm[4];
		var url = tm[0] + "//" + tm[2] + "/chl/";

		if(siteLang.indexOf("INTL") != -1)
		{
			if(cururl.indexOf("selection") == -1)
			{
				url = url + lang + "/r/details/OTHERS?nav=top";
				SetCookie('rpage', url, exp); 
			}
		}
		else
		{
			if(siteLang.indexOf("_") != -1)
			{
				url = url + lang + "/r/homepage";
			}
			else
			{
				if(lang == 'en')
				{
					url = url + "r/homepage";
				}
				else
				{
					url = url + lang + "/r/homepage";
				}
			}
			SetCookie('rpage', url, exp); 
		}
	}
	document.location = newurl;
}


function getParameter(param) {
	var val = "";
	var qs = window.location.search;
	var start = qs.indexOf(param);
	
	if (start != -1) {
	start += param.length + 1;
	var end = qs.indexOf("&", start);
	if (end == -1) {
	end = qs.length
	}
	val = qs.substring(start,end);
	}
	return val;
}

function changeDepcity(code) {
  var destPath = "";
  var destVal = getParameter('depcity');
  if (destVal == '') {
  	var sp = getParamSp(location.href); 
  	destPath = location.href + sp + 'depcity=' + code;
  } else {
  	destPath = location.href.replace('depcity='+destVal, 'depcity='+code);
  }
  window.location.href = destPath;
}

function changeDest(code) {
  var destPath = "";
  var destVal = getParameter('dest');
  if (destVal == '') {
  	var sp = getParamSp(location.href); 
  	destPath = location.href + sp + 'dest=' + code;
  } else {
  	destPath = location.href.replace('dest='+destVal, 'dest='+code);
  }
  window.location.href = destPath;
}

function redirExtUrl(url) {
	var link = '/chl/views/redirect.jsp?refid=http://'+ escape(url);	
	eval ("window.open(link, 'Popup', 'width=800,height=600, toolbar =1, menubar=1, scrollbars=1, resizable=1, location=1, status=1');");
}

function redirExtUrlPopUp(url, x, y, winName) {
	var link = '/chl/views/redirect.jsp?refid=http://'+ escape(url);	
	if (x == null || y == null) {
		var newWin = window.open(link, '');
	} else {
		if (winName == null) {
			winName = 'Popup';
		}
		var k = window.open(link, winName, 'width='+x+',height='+y+',,resizable=1,scrollbars=1');
		k.focus();
	}	
}

function getParamSp(hrefStr){ 
	var sp = '&'; 
  	if(location.href.indexOf('?') == -1){ 
  		sp = '?'; 
  	} 
  	return sp; 
}
   
function changeCurrency(code) {
  var currencyPath = "";
  var currencyVal = getParameter('currency');
  if (currencyVal == '') { 
  	var sp = getParamSp(location.href); 
  	currencyPath = location.href + sp + 'currency=' + code;
  } else {
  	currencyPath = location.href.replace('currency='+currencyVal, 'currency='+code);
  }
  window.location.href = currencyPath;
}

function popUpWin(url, x, y, winName) {
	if (x == null || y == null) {
		var newWin = window.open(url, '');
	} else {
		if (winName == null) {
			winName = 'Popup';
		}
		var k = window.open(url, winName, 'width='+x+',height='+y+',,resizable=1,scrollbars=1');
		k.focus();
	}	
}

function popUp(url) {
	eval ("window.open(url, 'Popup', 'width=650,height=600,,resizable=1,scrollbars=1');");
}

function fillvalue(from, to) {
	to.value = from.value;
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function getObj(name) {
	if (document.getElementById) {
		return document.getElementById(name);
	} else if (document.all) {
		return document.all[name];
	} else if (document.layers) {
		return document.layers[name];
	} else {
		return false;
	}
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    } else {
		return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.visibility = newVisibility;
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
} // changeObjectVisibility

function changeObjectColor(objectId, newColor) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.color = newColor;
		return true;
    } else {
		// we couldn't find the object, so we can't change its visibility
		return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		styleObject.left = newXCoordinate;
		styleObject.top = newYCoordinate;
		return true;
    } else {
		// we couldn't find the object, so we can't very well move it
		return false;
    }
} // moveObject

function convertUpper(formelement) {
  formelement.value = formelement.value.toUpperCase();	
} // convertUpper


// encode the string with utf-8 encoding
function utf8Encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}

// decode UTF-8 data
function utf8decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}

function getXYPosition(elementId) {
	var element = document.getElementById(elementId);
	var left = 0;
	var top = 0;

	if (element != null)
	{
	    try
	    {
	        while (element.offsetParent)
	        {
	            left += element.offsetLeft;
	            top += element.offsetTop;
	            element = element.offsetParent;
	        }
	    }
	    catch (e){		}
	return {x:left, y:top};
	}
}

function hideAllDivs(prefix, len) {
	for (var i=0 ; i<parseInt(len) ; i++) {
		if (document.getElementById(prefix + i) != null && document.getElementById(prefix + i).style.display != 'none') {
			document.getElementById(prefix + i).style.display='none';
		}
	}
}

function destinationPageRedirect(url, dest) {
	var encoded_dest = encodeURI(dest);
	location.href= url + "&txtDest=" + encoded_dest + "&offset=0";
}

function popularDest(lang, dest) {
	var encoded_dest = encodeURI(dest);
	var now = new Date();
	
	var s_Date = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7);
	var e_Date = new Date(now.getFullYear(), now.getMonth() + 3, now.getDate() + 7);
	
	var url = "/chl/r/pfinder/result";
	if (lang == "zh")  {
		url = "/chl/zh/r/pfinder/result";
	}
	
	var link = url + "?txtDest=" + encoded_dest + "&depds=" + s_Date.getDate() + "&depyms=" + s_Date.getFullYear() + s_Date.getMonth() + 
	"&depde=" + e_Date.getDate() + "&depyme=" + e_Date.getFullYear() + e_Date.getMonth() + "&offset=0";
		
	location.href = link;
}

function popularAct(lang, dest) {
	var encoded_dest = encodeURI(dest);
	var now = new Date();
	
	var s_Date = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 7);
	var e_Date = new Date(now.getFullYear(), now.getMonth() + 3, now.getDate() + 7);
	
	var url = "/chl/r/pfinder/result";
	if (lang == "zh")  {
		url = "/chl/zh/r/pfinder/result";
	}
	
	var link = url + "?txtAct=" + encoded_dest + "&depds=" + s_Date.getDate() + "&depyms=" + s_Date.getFullYear() + s_Date.getMonth() + 
	"&depde=" + e_Date.getDate() + "&depyme=" + e_Date.getFullYear() + e_Date.getMonth() + "&offset=0";
		
	location.href = link;
}
//CPPZUC ADD for PAX.0796 START
function popularDest2(lang, dest) {
	var encoded_dest = encodeURI(dest);
	
	var url = "/chl/r/pfinder2/result";
	if (lang == "zh")  {
		url = "/chl/zh/r/pfinder2/result";
	}
	
	var link = url + "?txtDest=" +  encoded_dest;
		
	location.href = link;
}

function popularAct2(lang, activity) {
	var encoded_activity = encodeURI(activity);
	
	var url = "/chl/r/pfinder2/result";
	if (lang == "zh")  {
		url = "/chl/zh/r/pfinder2/result";
	}
	
	var link = url + "?txtAct=" + encoded_activity ;
		
	location.href = link;
}
//CPPZUC ADD for PAX.0796 END

function gotoPackageDetailsPage(tourcode, lang) {
	if(lang == 'en') {
		location.href="/chl/r/pack/" + tourcode.toUpperCase();
	} else {
		location.href="/chl/" + lang + "/r/pack/" + tourcode.toUpperCase();
	}
}


/* temporary function for adding cookie for optional item email title */

function temp() {
	var cururl = unescape(document.location.toString());
	var url_strs = cururl.split("/");
	var j = url_strs[url_strs.length - 1];
	var filter = j.split("?");
	var tourcode = filter[0];
	if (tourcode.length  > 8 && tourcode.indexOf("index") == -1)  {
		SetCookie("CHL-TEMP-TOURCODE", tourcode);
	}
}


//-->

