	var initRegion   = ["","Select Region"];
	var initCity     = ["","Search all locations"];
	var initStreet   = ["","Search all locations"];

	function initiate(){
	
		if( document.getElementById('f_hi1') ) {
			Util.createDate("date2", "f_nen2", "f_tuki2", "f_hi2", null, 0);
    		Util.createDate("date1", "f_nen1", "f_tuki1", "f_hi1", Util.getInstance("date2"), 1);
		}
		if (document.getElementById("tiku_dai")){
    		Util.createOptionList("tiku_chu",initRegion);
    		Util.createOptionList("tiku_shou",initCity);
    		Util.createOptionList("tiku_sai",initStreet);
			onPageShow();
			setReverse();
		}else {
			if(document.search.f_dai.value != "japan"){
				document.search.f_s2.disabled =true;
				document.search.f_y1.disabled =true;
				document.search.f_y2.disabled =true;
				document.search.f_y3.disabled =true;
			}
		}	
 	}

	function onPageShow(){
    	document.getElementById("tiku_dai").disabled = false;
    	document.getElementById("tiku_chu").disabled  = true;
    	document.getElementById("tiku_shou").disabled = true;
    	document.getElementById("tiku_sai").disabled  = true;
    	document.getElementById("tiku_dai").value ="";
	}

	function setReverse(){
		if(document.search.f_dai.value == "japan"){
			document.search.f_tiku_dai.value =  "japan";
			
			var opList = RootTree.findChildAll("japan",1).getOptionalList();
			opList.reverse();
			opList.push(initRegion[1]); 
			opList.push(initRegion[0]);
			opList.reverse();
			if (opList.length < 3){
				document.getElementById("tiku_chu").disabled = true;
			}else{
	 			document.getElementById("tiku_chu").disabled = false;
	 		}	
			Util.createOptionList("tiku_chu",opList);
			
			if(document.search.f_chu.value!="") {
				opList = RootTree.findChildAll(document.search.f_chu.value,2).getOptionalList();
				opList.reverse();
				opList.push(initCity[1]); 
				opList.push(initCity[0]);
				opList.reverse();
				if (opList.length < 3){
					document.getElementById("tiku_shou").disabled = true;
				}else{
	 				document.getElementById("tiku_shou").disabled = false;
	 			}	
				Util.createOptionList("tiku_shou",opList);
				window.setTimeout("setValue();",10);
			}
			if(document.search.f_shou.value!="") {
				if(document.search.f_chu.value =="kyoto" && document.search.f_shou.value =="shi"){
					opList = RootTree.findChildAll("kyoto",3).getOptionalList();
				}else {
					opList = RootTree.findChildAll(document.search.f_shou.value,3).getOptionalList();
				}
				opList.reverse();
				opList.push(initStreet[1]); 
				opList.push(initStreet[0]);
				opList.reverse();
				if (opList.length < 3){
					document.getElementById("tiku_sai").disabled = true;
				}else{
	 				document.getElementById("tiku_sai").disabled = false;
	 			}	
				Util.createOptionList("tiku_sai",opList);
				if(document.search.f_chu.value =="kyoto" && document.search.f_shou.value =="shi"){
					document.search.f_tiku_shou.value =  "kyoto";
				} else {
					document.search.f_tiku_shou.value =  document.search.f_shou.value;
				}
			}
			if(document.search.f_sai.value!="") document.search.f_tiku_sai.value =  document.search.f_sai.value;
		}else {
			document.search.f_s2.disabled =true;
			document.search.f_y1.disabled =true;
			document.search.f_y2.disabled =true;
			document.search.f_y3.disabled =true;
			
			var opList = null ;
			if(document.search.f_chu.value != ""){
				opList = RootTree.findChildAll(document.search.f_chu.value,1).getOptionalList();
				opList.reverse();
				opList.push(initRegion[1]); 
				opList.push(initRegion[0]);
				opList.reverse();
				if (opList.length < 3){
					document.getElementById("tiku_chu").disabled = true;
				}else{
	 				document.getElementById("tiku_chu").disabled = false;
	 			}	
				Util.createOptionList("tiku_chu",opList);
			}

			if(document.search.f_chu.value!=""){
				document.search.f_tiku_dai.value =  document.search.f_chu.value;
				opList = RootTree.findChildAll(document.search.f_shou.value,2).getOptionalList();
				opList.reverse();
				opList.push(initCity[1]); 
				opList.push(initCity[0]);
				opList.reverse();
				if (opList.length < 3){
					document.getElementById("tiku_shou").disabled = true;
				}else{
	 				document.getElementById("tiku_shou").disabled = false;
	 			}	
				Util.createOptionList("tiku_shou",opList);
			}
			
			if(document.search.f_shou.value!=""){
				document.search.f_tiku_chu.value =  document.search.f_shou.value;
				//opList = RootTree.findChildAll(document.search.f_sai.value,3).getOptionalList();
				opList = new Array();
				opList.reverse();
				opList.push(initStreet[1]); 
				opList.push(initStreet[0]);
				opList.reverse();
				if (opList.length < 3){
					document.getElementById("tiku_sai").disabled = true;
				}else{
	 				document.getElementById("tiku_sai").disabled = false;
	 			}	
				Util.createOptionList("tiku_sai",opList);
			}
			if(document.search.f_sai.value!="")document.search.f_tiku_shou.value =  document.search.f_sai.value;
		}
	}

	function setValue(){
		document.getElementById("tiku_chu").value =  document.search.f_chu.value;
	}
	
   	function changePrefecture(index){
   		if(document.search.f_tiku_dai.value =="japan" ||document.search.f_tiku_dai.value =="" ){
   			document.search.f_s2.disabled =false;
			document.search.f_y1.disabled =false;
			document.search.f_y2.disabled =false;
			document.search.f_y3.disabled =false;
   		} else {
			document.search.f_s2.disabled =true;
			document.search.f_y1.disabled =true;
			document.search.f_y2.disabled =true;
			document.search.f_y3.disabled =true;
   		}
   	
		var tiku_dai = RootTree.findChildAll($("tiku_dai").options[index].value,1);
		if(tiku_dai){
			var opList = tiku_dai.getOptionalList();
			opList.reverse();
			opList.push(initRegion[1]); 
			opList.push(initRegion[0]);
			opList.reverse();
			if (opList.length < 3){
				document.getElementById("tiku_chu").disabled = true;
			}else{
	    		document.getElementById("tiku_chu").disabled = false;
	    	}
			Util.createOptionList("tiku_chu",opList);
		}else{
	    	Util.createOptionList("tiku_chu",initRegion);
	    	document.getElementById("tiku_chu").disabled = true;
		}
		Util.createOptionList("tiku_shou",initCity);
		Util.createOptionList("tiku_sai",initStreet);
   		document.getElementById("tiku_shou").disabled = true;
	    document.getElementById("tiku_sai").disabled = true;
   	} 

   	function changeCity(index){
		var tiku_chu = RootTree.findChildAll($("tiku_chu").options[index].value,2);
		if(tiku_chu){
			var opList = tiku_chu.getOptionalList();
			opList.reverse();
			opList.push(initCity[1]); 
			opList.push(initCity[0]);
			opList.reverse();
			if (opList.length < 3){
				document.getElementById("tiku_shou").disabled = true;
			}else{
				document.getElementById("tiku_shou").disabled = false;
			}
			Util.createOptionList("tiku_shou",opList);
		}else {
	    	Util.createOptionList("tiku_shou",initCity);
	    	document.getElementById("tiku_shou").disabled = true;
		}
		Util.createOptionList("tiku_sai",initStreet);
	    document.getElementById("tiku_sai").disabled = true;
   	}

   	function changeStreet(index){
		var tiku_shou = RootTree.findChildAll($("tiku_shou").options[index].value,3);
		if(tiku_shou){
			var opList = tiku_shou.getOptionalList();
			opList.reverse();
			opList.push(initStreet[1]); 
			opList.push(initStreet[0]);
			opList.reverse();
			if (opList.length < 3){
				document.getElementById("tiku_sai").disabled = true;
			}else{
	 			document.getElementById("tiku_sai").disabled = false;
	 		}	
			Util.createOptionList("tiku_sai",opList);
		}else {
	 		Util.createOptionList("tiku_sai",initStreet);
	 		document.getElementById("tiku_sai").disabled = true;
		}
   	} 

	function makeCalendar(dateObjName){
		var dateObj = Util.getInstance(dateObjName);
		var url = "";
	
		getStrYear  = dateObj.getYear();
		getStrMonth = dateObj.getMonth();
		url = ""
		// To be required to modifying below statement
		url += "http://travel.rakuten.co.jp/en/new_top/js/cal.html?year=" + getStrYear + "&mon=" + getStrMonth;
		url += "&oj1="+dateObjName;
		url += "&oj1name="+dateObjName;
		url += "&oj2="+dateObjName;
		url += "&oj2name="+dateObjName;
		url += "&oj3="+dateObjName;
		url += "&oj3name="+dateObjName;
		window.open(url,"cal","width=400,height=280,status=no");
	}

	function setCd(cd){
		document.search.f_cd.value = cd;
	}
	
	function setLocation(dai,chu,shou,sai){
		if(dai != null && dai !=""){
			document.search.f_dai.value  = dai;
			if(chu != null && chu !=""){
				document.search.f_chu.value  = chu;
				if(shou != null && shou !=""){
					document.search.f_shou.value = shou;
					if(sai != null && sai !=""){
						document.search.f_sai.value  = sai;
					} else {
						setCd("03");
					}
				} else {
					setCd("02");
				}
			} else {
				setCd("01");
			}
		} else {
			setCd("01");
		}
	}
	
	function en_search(){
		
		if(!document.getElementById("tiku_dai")){
			document.search.submit();
		} 	
	    var backupStateDai 	= document.getElementById("tiku_dai").disabled;
	    var backupStateChu  = document.getElementById("tiku_chu").disabled;
	    var backupStateShou = document.getElementById("tiku_shou").disabled;
	    var backupStateSai  = document.getElementById("tiku_sai").disabled;	
	
		document.getElementById("tiku_dai").disabled  = true;
		document.getElementById("tiku_chu").disabled  = true;
		document.getElementById("tiku_shou").disabled = true;
		document.getElementById("tiku_sai").disabled  = true;			
		if(document.search.f_tiku_dai.value =="japan"){
			if(document.search.f_tiku_chu.value =="Central Tokyo"){
				if(document.search.f_tiku_shou.value == ""){
					setCd("03");
					setLocation(document.search.f_tiku_dai.value,"tokyo","tokyo","");
				} else {
					setCd("04");
					setLocation(document.search.f_tiku_dai.value,"tokyo","tokyo",document.search.f_tiku_shou.value);
				}
			}
			else if(document.search.f_tiku_chu.value =="Tokyo Disney Resort,Maihama,Funabashi"){
					setCd("03");
					setLocation(document.search.f_tiku_dai.value,"tiba","keiyo","");
			}
			else if(document.search.f_tiku_chu.value =="Osaka city"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"osaka","shi","");
			}
			else if(document.search.f_tiku_chu.value =="Kyoto city"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"kyoto","shi","");
			}
			else if(document.search.f_tiku_chu.value =="Sapporo"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"hokkaido","sapporo","");
			}
			else if(document.search.f_tiku_chu.value =="Hakone"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"kanagawa","hakone","");
			}
			else if(document.search.f_tiku_chu.value =="Fuji"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"yamanasi","fujisan","");
			}
			else if(document.search.f_tiku_chu.value =="Hiroshima"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"hiroshima","hiroshima","");
			}
			else if(document.search.f_tiku_chu.value =="Fukuoka city"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"hukuoka","fukuoka","");
			}
			else if(document.search.f_tiku_chu.value =="Yokohama"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"kanagawa","yokohama","");
			}
			else if(document.search.f_tiku_chu.value =="Nagoya"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"aichi","nagoyashi","");
			}
			else if(document.search.f_tiku_chu.value =="Takayama/Hida"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"gihu","takayama","");
			}
			else if(document.search.f_tiku_chu.value =="Kobe"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"hyogo","kobe","");
			}
			else if(document.search.f_tiku_chu.value =="Nikko"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"tochigi","nikko","");
			}
			else if(document.search.f_tiku_chu.value =="Beppu"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"ooita","beppu","");
			}
			else if(document.search.f_tiku_chu.value =="Sendai"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"miyagi","sendai","");
			}
			else if(document.search.f_tiku_chu.value =="Niseko"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"hokkaido","niseko","");
			}
			else if(document.search.f_tiku_chu.value =="Hakuba"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"nagano","hakuba","");
			}
			else if(document.search.f_tiku_chu.value =="Kanazawa"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"ishikawa","kanazawa","");
			}
			else if(document.search.f_tiku_chu.value =="Nagasaki city"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"nagasaki","nagasaki","");
			}
			else if(document.search.f_tiku_chu.value =="Okinawa"){
				setCd("02");
				setLocation(document.search.f_tiku_dai.value,"okinawa","","");
			}
			else if(document.search.f_tiku_chu.value =="Narita Airport"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"tiba","narita","");
			}
			else if(document.search.f_tiku_chu.value =="Kansai Airport"){
				setCd("03");
				setLocation(document.search.f_tiku_dai.value,"osaka","nanbu","");
			}
			else {
				if(document.search.f_tiku_shou.value =="tokyo" ||
				   document.search.f_tiku_shou.value =="shi" ||
				   document.search.f_tiku_shou.value =="nagoyashi" ){
					setCd("04");
					setLocation(document.search.f_tiku_dai.value,
				            	document.search.f_tiku_chu.value,
				            	document.search.f_tiku_shou.value,
				            	document.search.f_tiku_sai.value);
				 }           
				 else if(document.search.f_tiku_shou.value =="kyoto"){
					setCd("04");
					setLocation(document.search.f_tiku_dai.value,
				            	document.search.f_tiku_chu.value,
				            	"shi",
				            	document.search.f_tiku_sai.value);
				 }
				 else {
					setCd("03");
					setLocation(document.search.f_tiku_dai.value,
				            	document.search.f_tiku_chu.value,
				            	document.search.f_tiku_shou.value,
				            	"");
				 }
			}
		}else{
			if(document.search.f_tiku_dai.value == ""){
				setCd("01");
				setLocation("","","","");
			}
			if(document.search.f_tiku_shou.value == ""){
				setCd("03");
				setLocation("kaigai",document.search.f_tiku_dai.value,document.search.f_tiku_chu.value,"");
			} else{
				setCd("04");
				setLocation("kaigai",document.search.f_tiku_dai.value,document.search.f_tiku_chu.value,document.search.f_tiku_shou.value);
			}
		}
	    if(checkData()){
	    	document.search.submit();
	    } else {
	    	document.getElementById("tiku_dai").disabled  = backupStateDai;
	   	 	document.getElementById("tiku_chu").disabled  = backupStateChu;
	    	document.getElementById("tiku_shou").disabled = backupStateShou;
	    	document.getElementById("tiku_sai").disabled  = backupStateSai;
	    }
	}
	
	function checkData() {
	    if(document.search.f_tiku_dai.value != ""){
	      if(document.search.f_tiku_chu.value != ""){
	      	if (document.search.f_tiku_chu.value == "Okinawa" ){
	      		return true;
	      	} else if ( document.search.f_cd.value == "03" || document.search.f_cd.value == "04") {
	      		return true;
			} else {
	        	if(document.search.f_tiku_shou.value == ""){
	        		alert("select Area");
	        	}
	      	}
	      } else {
	      	alert("select City/Region");
	      }	    	
	    } else {
	        alert("select country");
	    }   
		return false ;	
	}	
		

