
var stepindex=1;

function GetTitle(str1){   

 var bound_arr=new Array('subject','Todest[]','OtherDest','Groupsize','WhenToTravel','HotelClass','OtherInformation','EmailAdress','FullName');
 var text_arr=new Array('Subject','Short tour started from Shanghai to','Other Destination Name','How large is your group','When do you want to travel China','Hotel Class','Enter your Question','Your E-mail Address','Your Full Name');

	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 validate_email(field,alerttxt)
	{
	with (field)
	{
	apos=value.indexOf("@")
	dotpos=value.lastIndexOf(".")
	if (apos<1||dotpos-apos<2) 
	  {alert(alerttxt);return false}
	else {return true}
	}
	}

	
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;
			}else if(validate_email(formobj["EmailAdress"],"The e-mail you typed is not valid. Please try again.")==false){
			formobj["EmailAdress"].focus();return ;
			}
			
			
		    }
		catch(err)
		{ 
		    alert("Please Enter you Email Address.");
		    return;
		}		
		

		formobj.method="post";
 formobj.action="../forms/sendmail/cotmailer.php";

		formobj.submit();	
}

function water_in(fieldid,class_name){
	var obj=document.getElementById(fieldid);
     obj.className=class_name;

}
function water_out(fieldid,class_name,class_clear){
	var obj=document.getElementById(fieldid);
	if(obj.value=="") {
		obj.className=class_name;
	}else{
		obj.className=class_clear;
	}
}

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="";
       }
}
