// JavaScript Document

function getRouteDir(opt,obj,sId){
	var id=obj.options[obj.selectedIndex].value;
	if(id!=-1||id!=0){
		var url="Ajax/Ajax_TourRouteDirSelect.asp?cid="+id+"&n="+Math.random();
		var xmlhttp=createxmlhttp(); 
		if(xmlhttp){
			xmlhttp.open("GET",url,true);
			xmlhttp.onreadystatechange=function(){f_getRouteDir(opt,xmlhttp,sId);}
			xmlhttp.send();
		}
	}
}
function f_getRouteDir(obj,xmlhttp,sId){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var opts=xmlhttp.responseText;
			var Options=opts.split("#");
			var OptionAtt;
			obj.innerHTML="";
			for(var i=0; i<Options.length-1; i++){
				OptionAtt=Options[i].split(",");
				AppendOpts(obj,OptionAtt[0],OptionAtt[1],sId);
			}
		}else{alert(xmlhttp.status);}
	}
}
function AppendOpts(obj,id,name,sId){
	var op=document.createElement("option");
	op.innerHTML=name;
	op.value=id;
	if(op.value==sId){
		op.selected="selected";
	}
	obj.appendChild(op);
}

//**************************************************Ajax二级联动，由大洲选择国家/地区
function LoadProvince(obj,sId){
	var Id=obj.options[obj.selectedIndex].value;
	if(Id!=0){
	var xmlhttp=createxmlhttp();
	var url="Ajax/Ajax_Country.asp?Id="+Id+"&n="+Math.random();
	if(xmlhttp){
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function(){f_GetProvince(xmlhttp,sId);}
		xmlhttp.send(null);
		}
	}else{
		var op=document.createElement("option");
		op.innerHTML='--请先选择大洲--';
		op.value=0;
		document.getElementById("Province").innerHTML="";
		document.getElementById("Province").appendChild(op);
	}
}
function f_GetProvince(xmlhttp,sId){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var txt=xmlhttp.responseText;
			var ArrOpt=txt.split("#");
			var OptionAtt;
			var obj=document.getElementById("Province");
			obj.innerHTML="";
			for(var i=0; i<ArrOpt.length-1; i++){
				OptionAtt=ArrOpt[i].split(",");
				AppendOpts(obj,OptionAtt[0],OptionAtt[1],sId);
			}
		}else{alert(xmlhttp.status);}
	}
}

//**************************************************Ajax二级联动，由国家/地区选择城市
function LoadCity(obj,sId){
	var Id=obj.options[obj.selectedIndex].value;
	if(Id!=0){
	var xmlhttp=createxmlhttp();
	var url="Ajax/Ajax_Country.asp?Id="+Id+"&n="+Math.random();
	if(xmlhttp){
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function(){f_GetCountry(xmlhttp,sId);}
		xmlhttp.send(null);
		}
	}else{
		var op=document.createElement("option");
		op.innerHTML='--请先选择省份--';
		op.value=0;
		document.getElementById("City").innerHTML="";
		document.getElementById("City").appendChild(op);
	}
}
function f_GetCountry(xmlhttp,sId){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var txt=xmlhttp.responseText;
			var ArrOpt=txt.split("#");
			var OptionAtt;
			var obj=document.getElementById("City");
			obj.innerHTML="";
			for(var i=0; i<ArrOpt.length-1; i++){
				OptionAtt=ArrOpt[i].split(",");
				AppendOpts(obj,OptionAtt[0],OptionAtt[1],sId);
			}
		}else{alert(xmlhttp.status);}
	}
}
//****************************************************二级联动：由城市找景区
function LoadSpot(obj,sId){
	var Id=obj.options[obj.selectedIndex].value;
	if(Id!=0){
	var xmlhttp=createxmlhttp();
	var url="Ajax/Ajax_Spot.asp?Id="+Id+"&n="+Math.random();
	if(xmlhttp){
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function(){f_GetSpot(xmlhttp,sId);}
		xmlhttp.send(null);
		}
	}else{
		var op=document.createElement("option");
		op.innerHTML='--请先选择目的地--';
		op.value=0;
		document.getElementById("AllSpots").innerHTML="";
		document.getElementById("AllSpots").appendChild(op);
	}
}
function f_GetSpot(xmlhttp,sId){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var txt=xmlhttp.responseText;
			var ArrOpt=txt.split("#");
			var OptionAtt;
			var obj=document.getElementById("AllSpots");
			obj.innerHTML="";
			for(var i=0; i<ArrOpt.length-1; i++){
				OptionAtt=ArrOpt[i].split(",");
				AppendOpts(obj,OptionAtt[0],OptionAtt[1],sId);
			}
		}else{alert(xmlhttp.status);}
	}
}
//*******************************************************填充到select
function AppendOpts(obj,id,name,sId){
	var op=document.createElement("option");
	op.innerHTML=name;
	op.value=id;
	if(op.value==sId){
		op.selected="selected";
	}
	obj.appendChild(op);
	if(obj.disabled==true){
		obj.disabled=false;
	}
}

function CheckForm(){
	if(document.getElementById("msgVname").value==""){
		alert('称呼不能为空');
		return false;
	}
	if(document.getElementById("msgContent").value==""){
		alert('留言内容不能为空');
		return false;
	}
	if(document.getElementById("CheckCodeStatus").value=="0"){
		alert("验证码错误！");
		RefreshImage('imgCaptcha');
		return false;
	}
	return true;
}

function CheckCodes(){
	var code=document.getElementById("msgCheckCode").value;
	var now=new Date();
	var url="Ajax/Ajax_CheckCode.asp?Str="+code+"&n="+Math.random();
	var xmlhttp=createxmlhttp();
	if(xmlhttp){
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function(){f_getCheckCodes(xmlhttp);}
		xmlhttp.send();
	}
}
function f_getCheckCodes(xmlhttp){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var resStr=xmlhttp.responseText;
			if(resStr==1){
				document.getElementById("CheckCodeStatus").value="1";
			}else if(resStr==0){
				document.getElementById("CheckCodeStatus").value="0";
			}
			if(CheckForm()){
				document.getElementById("orderform").submit();	
			}
		}else{alert('错误代码：'+xmlhttp.status);}
	}
}

