// JavaScript Document
var xmlHttp;
function createXmlHttpRequest()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
        if(xmlHttp.overrideMimeType)
        {
            xmlHttp.overrideMimeType("text/xml");
        }
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    
    if(!xmlHttp)
    {
        window.alert("你的浏览器不支持创建XMLHttpRequest对象！");
    }
    
    return xmlHttp;
}


//显示线路处理
function GetTourList(sValue,sTValue,inpE,action,taValue)
{
	 //alert(taValue);
    var geturl="Attractions="+sValue+"&Action="+action;
	
	if(typeof sTValue == "string")
	{ 
	  if(sTValue.length > 0)
	  {
		geturl+="&tours="+sTValue;
	  }
	}
	   //alert("showtourlist.asp?"+geturl);
	  //document.write("showtourlist.asp?"+geturl);
	 //return; 
	
    $.ajax({
        type: "get",
        dataType: "text",
        processData: false,
        url: "showtourlist.asp",
        data: geturl,
		success: function(msg){
		   // alert(msg);
			if(typeof msg =="string")
			{
				if(msg.length  > 1 )
				{
					 
					   for(ai = 0 ; ai< taValue.length ; ai++)
					  {
						  regstr = eval("/"+taValue[ai]+"/g");
						  msg = msg.replace(regstr,"<b style='color:#FFCC00'>"+taValue[ai]+"</b>");
					  } 
				     document.getElementById(inpE).innerHTML=msg;
				 
				}
				else
				{
					document.getElementById(inpE).innerHTML="";
					 
				} 
		   }
            
        }//,
        //error: function(Request){
            //alert("Can,t get tour!");
        //}
    });
	 
}
//处理数据
function HResultData(rValue,sAValue)
{
	var l =rValue.split("|_") ,ml,outHtml="";
	
	for( li = 0 ;li< l.length;li++)// 
	{  
		if(typeof l[li] =="string")
		{  
			if(l[li].length > 1) 
			{
			   ml=l[li].split("#_");  
			   if( ml.length <  10  )ml.length = 10;
				 
				for(ai = 0 ; ai< sAValue.length ; ai++)
				 {
					 ml[5] = ml[5].replace(sAValue[ai],"<b style='color:#FFCC00'>"+sAValue[ai]+"</b>");
				 }
				 outHtml+=formateOutHtml(ml[0],ml[1],ml[2],ml[3],ml[4],ml[5],ml[6],ml[7],ml[8],ml[9]);
			}
		 
		}
	}
	return outHtml; 
	
	
}
//删除选择线路
function RemoveSelectTour(e)
{
	$("#"+e).hide().empty();
}

//删除景点
function RemoveSelectAttractions(e)
{
 
	var cknum = $("input[name='checkAtS']").length;
	 
	if(cknum < 2) 
	{ 
	 alert("You should select a attraction at least!So, you can't remove the last one any more!");
	 $("#btn"+$("input[name='checkAtS']").val()).hide();
	  return; 
	}
	 
	$("#"+e).hide().empty();
	
	if(cknum < 3) 
	{
		 $("#btn"+$("input[name='checkAtS']").val()).hide();
	} 
	
}

//
//显示线路处理
//function GetTourList(checkboxname,action)
//{
//	var chkarr=document.forms["form1"][checkboxname]; 
//	var chktrr=document.forms["form1"]["checkTours"];
//	var Attractions="",tours="";
//  	
//	if(chkarr)   
//	{   
//		var kmax=chkarr.length;   
//		for(var k=0;k<kmax;k++)
//		{   
//			if(chkarr[k].checked)
//			{
//				if(Attractions!="")   
//					Attractions=Attractions+","+chkarr[k].value;
//				else
//					Attractions=chkarr[k].value;
//			}
//		}
//	}   
//	if(chktrr)   
//	{   
//		var tmax=chktrr.length;   
//		for(var n=0;n<tmax;n++)
//		{   
//			if(chktrr[n].checked)
//			{
//				if(tours!="")   
//					tours=tours+","+chktrr[n].value;
//				else
//					tours=chktrr[n].value;
//			}
//		}
//	}   
//	alert(tours);
//    createXmlHttpRequest();
//    var url="showtourlist.asp?Attractions="+Attractions+"&Action="+action;
//	if(trim(tours)!="")
//	{
//		url="showtourlist.asp?Attractions="+Attractions+"&Action="+action+"&tours="+tours;
//	}
//    xmlHttp.open("post",url,true);
//	alert(url);
//    xmlHttp.onreadystatechange=GetTourListResult;
//	xmlHttp.setRequestHeader("Connection", "close");
//	
//	if(xmlHttp.RequestMethod.toLowerCase() == "post") 
//	{ 
//		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
//	} 
//	
//	xmlHttp.setRequestHeader("Content-Type","text/xml");
//	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
//    xmlHttp.send("");
//}
//显示线路处理回调函数
function GetTourListResult()
{
	if(xmlHttp.readyState==4)//服务器响应状态
    {
		//alert(xmlHttp.readyState+" "+xmlHttp.status+"  "+xmlHttp.responseText);
        if(xmlHttp.status==200)//代码执行状态
        {
			document.getElementById("divtourlist").innerHTML = xmlHttp.responseText;
			document.getElementById("divtourlist").style.display = "block";
			
			try
			{
				if(LeaveCheckedCount("checkTourslist")==0)
				{
					document.getElementById("divtourseltitle").style.display = "none";
				}
			}
			catch(e){}
        }
        
    }
}

//景点显示处理
function GetAttractionList(checkboxname,action)
{
	var xform=document.forms["form1"];   
  	var chkarr=xform[checkboxname]; 
	var Attractions="";
  
  	if(chkarr&&chkarr.length>0)   
	{   
		var kmax=chkarr.length;   
      	for(var k=0;k<kmax;k++)
		{   
          	if(chkarr[k].checked)
		  	{
		  		if(Attractions!="")   
              		Attractions=Attractions+","+chkarr[k].value;
				else
					Attractions=chkarr[k].value;
			}
		}
  	}   

    createXmlHttpRequest();
    var url="showAttractionlist.asp?Attractions="+Attractions+"&Action="+action;
	//alert(url);
    xmlHttp.open("post",url,true);
	//alert(url);
    xmlHttp.onreadystatechange=GetAttractionListResult;
    xmlHttp.send(null);
}
//回调函数
function GetAttractionListResult()
{
	if(xmlHttp.readyState==4)//服务器响应状态
    {
        if(xmlHttp.status==200)//代码执行状态
        {
			document.getElementById("divattractionlist").innerHTML=xmlHttp.responseText;
			document.getElementById("divattractionlist").style.display="block";
        }
        
    }
}
function SetACheckBox(checkboxname,itemno,action)
{
	var xform=document.forms["form1"];   
  	var chkarr=xform[checkboxname]; 
	var Attractions="";
  
  	document.getElementById("checkbox"+trim(itemno)).checked=false;
	//alert(document.getElementById("checkbox"+trim(itemno)).checked);
	GetTourList(checkboxname,action);
}

//计算某组checkbox或radio控件已经选择的数量
function LeaveCheckedCount(checkboxname)
{
	var xform=document.forms["form1"]; 
		
  	var chkarr=xform[checkboxname]; 
	var leavecnt=0;
  
  	if(chkarr&&chkarr.length>0)   
	{   
		var kmax=chkarr.length;   
      	for(var k=0;k<kmax;k++)
		{   
          	if(chkarr[k].checked)
		  	{
		  		leavecnt=leavecnt+1;
			}
		}
  	}
	
	if(chkarr.length==undefined)
	{
		if(chkarr.checked)
			return 1;
		else
			return 0;
	}
	
	return leavecnt;
}
//移出景点
function RemoveAttraction(idtag)   
{   
	//if(LeaveCheckedCount("checkAttractions")==1)
//	{
//		alert("You should select a attraction at least!So, you can't remove the last one any more!");
//		return;
//	}
	var cknum = $("input[name='checkAttractions']:checked").length;
	if(cknum < 2 ) 
	{
		alert("Please select a attraction at least!");
     	return false;	
	}
	//var rastr="";
	//rastr=document.getElementById("removeattractions").value;
	//if(rastr=="")
	//{
	//	rastr=idtag;
	//}
	//else
	//{
	//	rastr=rastr+","+idtag;
	//}
	//document.getElementById("removeattractions").value=rastr;
	document.getElementById("acheckbox"+trim(idtag)).checked=false;
	document.getElementById("adiv"+trim(idtag)).style.display="none";
	//alert("acheckbox"+trim(idtag)+" "+document.getElementById("acheckbox"+trim(idtag)).checked);
} 

//线路日期选择
function tourDateSelectChange(rowid)
{       
     var textobj= document.getElementById(rowid);
	 if(rowid=="fixed"){
	 	 textobj.style.display="";
		 textobj= document.getElementById("flexible");
		 textobj.style.display="none";
	 }
	 else if (rowid=="flexible"){
	     textobj.style.display="";
		 textobj= document.getElementById("fixed");
		 textobj.style.display="none";
	 }	   
}
//去左空格; 
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
} 
//去左右空格; 
function trim(s){ 
return rtrim(ltrim(s)); 
} 
function SetCheckBox(checkboxname,itemno,action)
{
	var xform=document.forms["form1"];   
  	var chkarr=xform[checkboxname]; 
	var Attractions="";
  
  	document.getElementById("checkbox"+trim(itemno)).checked=false;
	//alert(document.getElementById("checkbox"+trim(itemno)).checked);
	GetTourList(checkboxname,action);
}
//显示或隐藏div
function Showorhide(object,xvhao)   
{   
	if(object.checked==true)
	{
		document.getElementById("div"+xvhao).style.display="block";
		document.getElementById("div"+xvhao).style.height="auto";
		document.getElementById("div"+xvhao).innerHTML=document.getElementById("hidden"+xvhao).value;
	}
	else
	{
		document.getElementById("div"+xvhao).style.display="none";
		document.getElementById("div"+xvhao).style.height="0px";
		document.getElementById("div"+xvhao).innerHTML="";
	}
} 


var formateOutHtml = (function(){ 
    var buffAr = [
             "<div class='newtourlistzt2'><h6><a href='",
			 '',//&file_url& 1
			 "' target='_blank' >",
			 '',//&rs("CLI2_Name")&3
			 "</a>(",
			'', //&rs("CLI_NO")& 5
			 ")</h6><div class='newtourPhoto'><a href='",
			 '',//&file_url& 7
			 "'><img src='",
			 '',//&pic_url& 9
			 "' alt='",
			 '',//&rs("CLI2_Name")& 11
			 "' width='100' height='75'/></a></div><div class='newtourInfo'><ul><li><strong>Destination</strong>: ",
			 '',//&PassCity& 13
			 "</li><li><strong>Attraction</strong>:",
			 '',//&PassAttraction& 15
			 "&nbsp;&nbsp;&#187<a href='",
			 '',//&file_url& 17
			 "'  target='_blank'><strong>Itinerary &amp;  Price Details</strong></a></li></ul></div> <div class='newtourPrice'><div class='newtourFrom'><strong>from: </strong><span class='redRate'>$ ",            '',//&rs("CLP_TwoToFiveAdultPrice")& 19
			 "</span></div><div class='newtourRate'><p><strong>",
			'',//&tclass& 21
			 "</strong><br />2-5 persons</p>",
			 '',//this  23
		 "</div></div> <div class='clear'></div></div>"]; 
	
    return(function(fileUrl, tName, cNO, pUrl,pCity ,PAttraction,ttPrice,tcalss,booltour,action){ 
      
           buffAr[1] = fileUrl;
		   buffAr[3] = tName;
		   buffAr[5] = cNO;
		   buffAr[7] = fileUrl;
		   buffAr[9] = pUrl;
		   buffAr[11] = tName; 
		   buffAr[13] = pCity;
		   buffAr[15] = PAttraction;
		   buffAr[17] = fileUrl;
		   buffAr[19] = ttPrice;
		   buffAr[21] = tcalss;
	 
		var str = "";
		if (action=1) 
		{
			str+= "<p>Select it: <span class='newtourFrom redRate'>";
			 
			if (booltour=="True" || booltour=="true")
			{ 
				str+=  "<input type='checkbox' name='checkTours' checked='checked' onclick=\"SetTourCheckBox('"+cNO+"',this.checked)\"  />";
			}
			else
			{
				str+=  "<input type='checkbox' name='checkTours'   onclick=\"SetTourCheckBox('"+cNO+"',this.checked)\"  />";
			}
			 
			str+= "</span><br />";
			str+=  "</p>";
		}
		else
		{
			if (action=2)
			{
				str+= "<p><input type='checkbox' name='checkTourslist' id='checkbox"+cNO+"' value='"+cNO+"' style='display:none' checked='checked' />";
				str+="<input class='formBtn' type='button' name='button3' id='checkbox"+cNO+"' value='Remove'  onclick=\"SetTourCheckBox('"+cNO+"',2)\" /><br /></p>";
			}
			else
			{
				 str+= "<p>Select it: <span class='newtourFrom redRate'><input name='radioTours' type='radio' value='"+cNO+"' /></span><br /></p>";
			}
			 
		}
        buffAr[23] = str;
        return buffAr.join('');
        
    });
})();
 	 