﻿// JScript 文件
function isIE(){ //ie? 
    if (window.navigator.userAgent.indexOf("MSIE")>=1) 
        return true; 
    else 
        return false; 
}

function $(id) {
 if (document.getElementById != null) {
 return document.getElementById(id);
 }
 else if (document.all != null) {
 return document.all[id];
 }
 else {
 return null;
 }
}

function create_xmlhttp() {
var req=null;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
}else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}   

return req;
} 

function ajax_post(url,data){

var xmlhttp = create_xmlhttp();
xmlhttp.open("POST", url, false);
xmlhttp.setrequestheader("cache-control","no-cache"); 
xmlhttp.setrequestheader("content-length",data.length); 
xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); 
xmlhttp.send(data);
    if(xmlhttp.readyState == 4) {
        if(xmlhttp.status == 200){      
            if(xmlhttp.responseText == "True") {
             return true;
            } 
            else 
            {
              return false;
            } 
        } 
    }  
}

var GetNodeValue = function(obj)
{
var str = "";
if(window.ActiveXObject)    //IE
{
str = obj.text;
}
else //Mozilla
{
try
{
   str = obj.childNodes[0].nodeValue;
}
catch(ex)
{
   str = "";
}
}
return str;
}

if(document.implementation && document.implementation.createDocument)
{
XMLDocument.prototype.loadXML = function(xmlString)
{
var childNodes = this.childNodes;
for (var i = childNodes.length - 1; i >= 0; i--)
   this.removeChild(childNodes[i]);

var dp = new DOMParser();
var newDOM = dp.parseFromString(xmlString, "text/xml");
var newElt = this.importNode(newDOM.documentElement, true);
this.appendChild(newElt);
};

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
    // prototying the XMLDocument
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
    {
    if( !xNode ) { xNode = this; }
    var oNSResolver = this.createNSResolver(this.documentElement);
    var aItems = this.evaluate(cXPathString, xNode, oNSResolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    var aResult = [];
    for( var i = 0; i < aItems.snapshotLength; i++)
    {
    aResult[i] = aItems.snapshotItem(i);
    }
    return aResult;
    }

    // prototying the Element
    Element.prototype.selectNodes = function(cXPathString)
    {
    if(this.ownerDocument.selectNodes)
    {
    return this.ownerDocument.selectNodes(cXPathString, this);
    }
    else{throw "For XML Elements Only";}
    }
}

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
    // prototying the XMLDocument
    XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
    {
    if( !xNode ) { xNode = this; }
    var xItems = this.selectNodes(cXPathString, xNode);
    if( xItems.length > 0 )
    {
    return xItems[0];
    }
    else
    {
    return null;
    }
    }  
    // prototying the Element
    Element.prototype.selectSingleNode = function(cXPathString)
    {  
    if(this.ownerDocument.selectSingleNode)
    {
    return this.ownerDocument.selectSingleNode(cXPathString, this);
    }
    else{throw "For XML Elements Only";}
    }
}
}



function hideElementAll(){
	HideElement("SELECT");		
	HideElement("OBJECT");	
}

function showElementAll(){
	ShowElement("SELECT");
	ShowElement("OBJECT");
}

function CreateDialog(content,subject,msgw,msgh)
{
var sWidth,sHeight;
sWidth  = document.body.scrollWidth;
//sHeight = document.body.scrollHeight;
var ch = document.body.clientHeight, sh = document.body.scrollHeight;
sHeight = (sh > ch ? sh : ch);
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.left="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);";
bgObj.style.opacity="0.3";
bgObj.style.width= sWidth + "px";
bgObj.style.height= sHeight + "px"; 
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);

var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.style.position = "absolute";
//msgObj.className = "lightbox";
msgObj.className = "helpbox";
msgObj.style.left = "50%";
msgObj.style.top = "45%";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75 + document.documentElement.scrollTop +"px";
msgObj.style.width = msgw + "px";
msgObj.style.height = msgh + "px";
msgObj.style.zIndex = "10001";

var title=document.createElement("div");
title.setAttribute("id","msgTitle");
title.className = "title";
title.innerHTML='<img src="/images/ico_close_3.gif" alt="Close this Dialog" onclick="RemoveDialog()"  style="cursor:pointer;" id="close" > ' + subject;
if(isIE()) hideElementAll();
document.body.appendChild(msgObj);
$("msgDiv").appendChild(title);
var txt = document.createElement("div");
txt.setAttribute("id","msgTxt");
txt.className ="content";
txt.style.height = msgh  - 65;
txt.innerHTML = content;
$("msgDiv").appendChild(txt);

}

function RemoveDialog()
{
if($("bgDiv")){
document.body.removeChild($("bgDiv"));
$("msgDiv").removeChild($("msgTitle"));
document.body.removeChild($("msgDiv"));
if(isIE()) showElementAll();
}
}

function test(){
var reg=/^[0-9]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}  

function test2(){
var reg=/^[0-9.]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}

function test3(){
var reg=/^[0-9-]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}

//可折叠式滑动显示
var colContentHeight=0;
function displayIt(contentID,maxHeight){
	var h = $(contentID).offsetHeight;
	var max_h = maxHeight;
	var anim = function(){
		h += 15;
		if(h >= max_h){
			$(contentID).style.height = maxHeight + "px";
			if(tt){
				window.clearInterval(tt);
			}
		}else{
			$(contentID).style.display="block";
			$(contentID).style.overflow = "hidden";
			$(contentID).style.height = h + "px";
			
		}
	}
	var tt = window.setInterval(anim,2);
}

function hiddenIt(contentID,maxHeight){
	var h = $(contentID).offsetHeight;
	var anim = function(){
		h -= 15;
		if(h <= 5){
			$(contentID).style.display="none";		
			if(tt){
				window.clearInterval(tt);
			}
		}else{
			$(contentID).style.height = h + "px";
			$(contentID).style.overflow = "hidden";
		}
	}
	var tt = window.setInterval(anim,2);
}

function collapseIt(contentID,colContentHeight){
	 //if(colContentHeight==0) colContentHeight = $(contentID).offsetHeight;
	 //alert($(contentID).offsetHeight);
	if($(contentID).style.display == "block"){
		hiddenIt(contentID,colContentHeight);
	}else{
		displayIt(contentID,colContentHeight);
	}
}

//不间断横向向左滚动
function initSlide(wrapper,content1,content2){
var slideSpeed=30;
var sct=$(wrapper);
var sct1=$(content1);
var sct2=$(content2);
if(sct1.offsetWidth > sct.offsetWidth ) {
sct2.innerHTML=sct1.innerHTML;
function Marquee(){
if(sct2.offsetWidth - sct.scrollLeft <= 0){
sct.scrollLeft -= sct1.offsetWidth;
}else{
sct.scrollLeft++;
}
}
var MyMar=setInterval(Marquee,slideSpeed);
sct.onmouseover=function() {clearInterval(MyMar);};
sct.onmouseout=function() {MyMar=setInterval(Marquee,slideSpeed);};
}
}

function DisplayAndHiddenObj(arg,titleobj,bodyobj){
    if(arg == true){
      titleobj.style.display="none";
      bodyobj.style.display="block";
    }  
    else{
      titleobj.style.display="block";
      bodyobj.style.display="none";
    }
        return false;
}

function HideElement(strElementTagName){

	try{

		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){

			var objTemp = window.document.all.tags(strElementTagName)[i];

			objTemp.style.visibility = "hidden";

		}

	}catch(e){

		//alert(e.message);
	}

}


function ShowElement(strElementTagName){

	try{

		for(i=0;i<document.getElementsByTagName(strElementTagName).length; i++){

			var objTemp = document.getElementsByTagName(strElementTagName)[i];

			objTemp.style.visibility = "visible";

		}

	}catch(e){
		//alert(e.message);
	}
}

function getCookie(objName){
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
   var aCrumb = aCookie[i].split("=");
   if (objName == aCrumb[0])
   {
    if (aCrumb.length > 1 )
     return unescape(aCrumb[1]);
    else
     return "";
   }
}
return "";
}


///////////////////////////////
function CleanText(obj)
{
if(obj.value == 'keyword'){
 obj.value = '';
 }
}       
function Search()
{
var url = 'search.aspx?Keywords=';
if($('sKeywords').value != 'keyword' && $('sKeywords').value !='')  url += encodeURI($('sKeywords').value);
 if($('sDestination').selectedIndex > 0 ) url +="&Destination="+encodeURI($('sDestination').value);
 if($('sDays').selectedIndex > 0 ) url +="&Days="+$('sDays').value;
 if($('Tdeparture').selectedIndex > 0) url +="&Departure="+ $('Tdeparture').value;
 location.href=url;
}

function SearchHotel()
{
  var url = "hotel.aspx?";
  if($('Tclass1').selectedIndex > 0) url +="country="+ $("Tclass1").value + "&";
  if($('Tclass2').selectedIndex > 0) url +="city="+ $("Tclass2").value + "&";
  if($('starlevel').selectedIndex > 0) url +="star="+ $("starlevel").value ;
   location.href=url;
}

function SetSelect(IsDeparture)
{
  if(IsDeparture)
  {
    $('sClass').options[0].selected = true;
     $('sDestination').options[0].selected = true;
  }
  else
  {
      $('Tdeparture').options[0].selected = true;
  }
}

 