// JavaScript Document
var city_array="Beijing,Changsha,Chengde,Chengdu,Chongqing,Dali,Dalin,Datong,Dazu,Dengfeng,Deqin,Dunhuang,Guangzhou,Guilin,Guiyang,Gyangtse,Gyantse,Haikou,Hangzhou,Harbin,Hekuo,Henan,Hohhot,Hong Kong,Hotan,Huanglong,Jianshui,Jinan,Jindezhen,Jingdezhen,Jiuzhaigou,Kaifeng,Kaili,Kaili,Kashgar,Kunming,Lanzhou,Leshan,Lhasa,Lijiang,Longsheng,Luguhu,Luoyang,Macao,Maoxian,Minfeng,Mt. Huangshan,Mt.Emei,Mt.Everest,Mt.Huashan,Mt.Putuo,Mt.Wutaishan,Nam Co,Nanjing,Nanning,Naqu,Ningbo,Nyingchi,Others,Pingyao,Qingdao,Rongbuk Monastery,Rongjiang,Sanjiang,Sanya,Shanghai,Shangri-la,Shaoxing,Shenzhen,Shigatse,Suzhou,Taian,Taiyuan,The three Gorge Dam ,Tianjin,Tibet,Tiger Leaping Gorge,Tingri,Tongli,Turpan,Urumqi,Weifang,Wenzhou,Wolong,Wuhan,Wuxi,Wuzhen,Xiamen,Xian,Xining,Xishuangbanna,Yangshuo,Yangzhou,Yichang,Yuanyang,Zetang,Zhangjiajie,Zhaoxing,Zhengzhou,Zhongdian,Zhouzhuang,Zhuhai,Zigong";

var stepindex=1;

function GetTitle(str1){   
    var bound_arr=new Array("subject","StartCity","EndCity","DepartureDate","Duration","AdultNumbers","kidsnumber","HotelClass","MealPlan","OtherInformation","EmailAdress","FullName","OtherContactMethods","E-newsletter","liketoseeinChina","BudgetTotalperperson","currency","othercurrency","RoomType","TentativeItineary","triptype[]","TravelPlan");
var text_arr=new Array("Subject","Start City","End City","Preferred Departure Date","How long would you like to travel in China","Adult Numbers","Kids Numbers","Hotel Class","Meal Plan","Other information we should know","Your E-mail Address","How should we call you","Other Contact Methods","Sign up for our FREE E-newsletter","What would you like to see in China","Budget Per Person","Currency","Other Currency","Room Type","Your ideas of your trip","What type of experience do you want","What type of experience do you want","Your travel plan");
   
	var strTitle=str1;
	
	for(var i=0;i<bound_arr.length;i++){
	    if(bound_arr[i]==strTitle){
			strTitle=text_arr[i];	
			break;
		}
	}
	
	return strTitle;
}

function setimage(index){
    document.getElementById("topimg_step").src="../image/custom_step"+index+".gif";	
}
function setlogoimage(index){
    document.getElementById("logoimg").src="../image/custom_logo"+index+".gif";		
}
function changestep(index){
	if(index==1){
	   var tp=document.getElementsByName("TravelPlan");
	   
	   if(tp[0].checked)
	   {		   
		   StepVisable(4);
	   }
	   else
	   {		   
		   StepVisable(2);
	   }
	   
	}	
	else if(index==2){
	   var fp=document.getElementsByName("FixedBudget");
	   
	   if(fp[0].checked)
	   {		  
		   StepVisable(3);
	   }
	   else
	   {
		   
		   StepVisable(5);	  
		   
	   }	   
	}
	else
	{
		StepVisable(1);		
	}
}
function StepVisable(index)
{
	var obj=null,objhead=null;
	obj=document.getElementById("zhengshu");
	objhead=document.getElementById("zhengshuhead");
	
	stepindex=index-2;	
	if(index>2){
		obj.style.display="";	
		objhead.style.display="";	
	}
	else{
		obj.style.display="none";
		objhead.style.display="none";	
	}	
	for(i=1;i<=5;i++){
	   	obj=document.getElementById("step"+i);
		obj.style.display="none";
		if(i==index) obj.style.display="";		
	}
	obj=document.getElementById("previewbt")
	if(index==1)
	{
		setimage(1);
		setlogoimage(1);
		obj.style.display="none";		
		document.getElementById("step1").style.height=getPageHeight()+"px";
	}
	else if(index==2)
	{
		setimage(3);
		setlogoimage(1);
		obj.style.display="";
		obj.href="javascript:StepVisable(1)";
		document.getElementById("step2").style.height=getPageHeight()+"px";	
	}
	else if(index==3)
	{
		obj.style.display="";
		obj.href="javascript:StepVisable(2)";
		setimage(4);
		setlogoimage(2);
	}
	else if(index==4)
	{
		//plan
		obj.style.display="";
		obj.href="javascript:StepVisable(1)";
		setimage(2);
		setlogoimage(3);
	}
	else if(index==5)
	{		
		obj.style.display="";
		obj.href="javascript:StepVisable(2)";
		setimage(4);
		setlogoimage(5);
	}
	
	if (document.documentElement && document.documentElement.scrollTop)
    {
        document.documentElement.scrollTop=0;
    }
	else
	{
		document.body.scrollTop=0;
		
	}	
}
function SubmitCustomform(formname){	
    	
		var formobj=document.getElementById(formname);
		try{
			if(formobj["EmailAdress"]!=null && formobj["EmailAdress"].value==""){
				alert("Please Enter you Email Address.");
				formobj["EmailAdress"].focus();
				return;
			}
			
		}
		catch(err)
		{ 
		    alert("Please Enter you Email Address.");
		    return;
		}		
		

		formobj.method="post";

		formobj.action="sendmail/cotmailer_custom.php";

		formobj.submit();	
}
function init(){
	
	StepVisable(1);	
	var obj=null;
	//뿪
	obj=document.getElementById("customform1").DepartureDate;
	if(obj.value=="") obj.className="watered_departdate";
	
	obj=document.customform2.DepartureDate;
	if(obj.value=="") obj.className="watered_departdate";
	
	obj=document.customform4.DepartureDate;
	if(obj.value=="") obj.className="watered_departdate";
	
	//travel days
	obj=document.customform1.Duration;
	if(obj.value=="") obj.className="watered_duration";
	
	obj=document.customform2.Duration;
	if(obj.value=="") obj.className="watered_duration";
	
	
	obj=document.customform4.Duration;
	if(obj.value=="") obj.className="watered_duration";
	
	//other information
	obj=document.customform1.OtherInformation;
	if(obj.value=="") obj.className="watered_otherinfo1";
	
	obj=document.customform2.OtherInformation;
	if(obj.value=="") obj.className="watered_otherinfo";
	

	obj=document.customform4.OtherInformation;
	if(obj.value=="") obj.className="watered_otherinfo";
	
	//see in china 
	obj=document.customform1.liketoseeinChina;
	if(obj.value=="") obj.className="watered_seeinchina";
	
	obj=document.customform2.TravelPlan;
	if(obj.value=="") obj.className="watered_seeinchina";
	
	obj=document.customform4.liketoseeinChina;
	if(obj.value=="") obj.className="watered_seeinchina";
	
	
	
}
function changetextbox(formid,szObj,stylename){
	var formobj=document.getElementById("customform"+formid);
	var ctlobj=formobj[szObj];
	if(stylename!="water"){
	   if(ctlobj.value=="") ctlobj.className=stylename;	
	   else ctlobj.className="water";
	}
	else
	{
		ctlobj.className=stylename;	
	}
		
	
    
}
function preview(formid){

   var formobj=document.getElementById("customform"+formid);
   var szStr="<h4 class='h4' style='font-size:17px'>Preview Your Inquiry:</h4><table width='95%' border='0' cellpadding='0' cellspacing='0' style='margin:10px' >";   var objname="",strtemp="";
   var nRowCount=0;
   for(i=0;i<formobj.length;i++){ 
       
		if(formobj[i].type=="checkbox" || formobj[i].type=="radio"){		    
			if(formobj[i].checked){				
			   if(objname==formobj[i].name){				  
				   strtemp+=formobj[i].value+",";   
			   }	
			   else
			   {
				   strtemp=formobj[i].value+",";
			   }
			}
		}	
		else
		{
			if(strtemp!=""){
				      szStr+="<tr><td class='tda1"+(nRowCount==0?" tda1a":"")+"'>&nbsp;"+GetTitle(objname) +":</td><td class='tda2"+(nRowCount==0?" tda1a":"")+"'>&nbsp;"+ strtemp.substr(0,strtemp.length-1)+"</td></tr>";
					  nRowCount++;
					  strtemp="";
			}
				   
			//else 
	        if(formobj[i].value!=""){
				szStr+="<tr><td class='tda1"+(nRowCount==0?" tda1a":"")+"'>&nbsp;"+GetTitle(formobj[i].name) +":</td><td class='tda2"+(nRowCount==0?" tda1a":"")+"'>&nbsp;"+formobj[i].value+"</td></tr>";
				nRowCount++;
			}
			
		}	
		if(formobj[i].type=="select-one") formobj[i].style.display="none";
		
		objname=formobj[i].name;
   }
   szStr+="</table>";
   szStr+="<p align=center><a href=\"javascript:SubmitCustomform('customform"+formid+"')\"><img src=\"../image/custom_submit.gif\" border=\"0\" /></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:hideScreen("+formid+")\"><img src=\"../image/custom_close.gif\" border=\"0\" /></a></p>";
   document.getElementById("preview").style.width="600px";
   document.getElementById("preview").innerHTML=szStr;
   
   showScreen();

}
function getWidth()
{
    var strWidth,clientWidth,bodyWidth;
    clientWidth = document.documentElement.clientWidth;
    bodyWidth = document.body.clientWidth;
    if(bodyWidth > clientWidth){
        strWidth = bodyWidth + 20;
    } else {
        strWidth = clientWidth;
    }
    return strWidth;
}
//ȡ߶
function getHeight()
{
    var strHeight,clientHeight,bodyHeight;
    clientHeight = document.documentElement.clientHeight;
    bodyHeight = document.body.clientHeight;
    if(bodyHeight > clientHeight){
        strHeight = bodyHeight + 30;
    } else {
        strHeight = clientHeight;
    }
    return strHeight+1000;
}
// 
function showScreen()
{	
    var Msg = document.getElementById('preview');
    var Bg = document.getElementById('Screen');

    Bg.style.width = getWidth()+'px';
    Bg.style.height = getHeight()+'px';	
	
    Msg.style.left=((getLeft()-600)/2)+"px";//((document.body.clientWidth-Msg.style.width)/2)+"px";	
    Msg.style.top=(getPageScrollTop()+20)+"px";
	//Msg.style.top=document.documentElement.scrollTop;//((screen.height-Msg.style.height)/2)+"px";
    Msg.style.display = 'block';
    Bg.style.display = 'block';
}
//
function hideScreen(formid)
{
	var formobj=document.getElementById("customform"+formid);
   
   for(i=0;i<formobj.length;i++){  
		if(formobj[i].type=="select-one") formobj[i].style.display="";
   }
   
    var Msg = document.getElementById('preview');
    var Bg = document.getElementById('Screen');
    Msg.style.display = 'none';
    Bg.style.display = 'none';
}
function getPageScrollTop(){
 var yScroll;
 if (self.pageYOffset) {
  yScroll = self.pageYOffset;
 } else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
  yScroll = document.documentElement.scrollTop;
 } else if (document.body) {// all other Explorers
  yScroll = document.body.scrollTop;
 } 
 return yScroll;
}
function getPageHeight(){
	var ClientHeight=0;
	try{
	if(window.screenTop){
		ClientHeight=window.screen.availHeight-window.screenTop-40;
	}
	else
	{
		ClientHeight=window.innerHeight;
	}
	}
	catch(err)
	{
		ClientHeight=688;
	}
	return ClientHeight-200;	
}
function getLeft(){
   var xpos=0;
   if (document.documentElement && document.documentElement.clientWidth){  // Explorer 6 Strict
  xpos = document.documentElement.clientWidth;
 } else if (document.body) {// all other Explorers
  xpos = document.body.clientWidth;
 } 
 return xpos;
}
function EnlargePic(str){
   var obj=document.getElementById("preview");
   obj.style.width="750px";
   showScreen();
   if(str!=""){
	   obj.innerHTML="<div style='padding:2px;margin:0;text-align:right'><a href='javascript:HidePic()' style='text-decoration:underline'>Close picture</a></div><img src='../image/"+str+"'/>";	 
	   
	   var formobj=document.getElementById("customform"+stepindex);
   
       for(i=0;i<formobj.length;i++){ 		
		 if(formobj[i].type=="select-one") formobj[i].style.display="none";
       }

   }
}
function HidePic(){
	document.getElementById("preview").style.display="none";
	document.getElementById('Screen').style.display="none";
   
  var formobj=document.getElementById("customform"+stepindex);
   
       for(i=0;i<formobj.length;i++){ 
		 if(formobj[i].type=="select-one") formobj[i].style.display="";
       }
}


//fix Southest Asia form for coustm_asia.htm
function SubmitAsiaform(formname){	
    	
		var formobj=document.getElementById(formname);
		try{
			if(formobj["EmailAdress"]!=null && formobj["EmailAdress"].value==""){
				alert("Please Enter you Email Address.");
				formobj["EmailAdress"].focus();
				return;
			}
			
		}
		catch(err)
		{ 
		    alert("Please Enter you Email Address.");
		    return;
		}		
		

		formobj.method="post";

		formobj.action="sendmail/cotmailer_asia.php";

		formobj.submit();	
}
