/*-------------------------------------------------------
top.js
depends on prototype.js(http://prototype.conio.net/)
@version  V1.0
@author   youngjin.shin (2008/01/17)
Copyright (c) 2008 Rakuten Travel, Inc. All Rights Reserved.
--------------------------------------------------------*/
function openWin(f)
{
 adWindow=window.open(f,'help','width=450,height=450,scrollbars,resizable');
}

	function initiate(){
    	Util.createSuggest("sg1", "f_query", "", "suggest1", "mask1", suggestList);
    	Util.createDate("date2", "f_nen2", "f_tuki2", "f_hi2", null, 0);
    	Util.createDate("date1", "f_nen1", "f_tuki1", "f_hi1", Util.getInstance("date2"), 1);
    	Util.getInstance("date1").addDay(1);
    	Util.createOptionList("tiku_chu",initRegion);
    	Util.createOptionList("tiku_shou",initCity);
    	Util.createOptionList("tiku_sai",initStreet);
		onPageShow();
 	}

	function onPageShow(){
        if(document.getElementById("tId").value){
        	changeTab(document.getElementById("tId").value);
        } else {
        	changeTab(tabList[0]);
        }
    	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 ="";
    	document.getElementById("tiku_chu").value ="";
    	document.getElementById("tiku_shou").value ="";
    	document.getElementById("tiku_sai").value ="";
    	document.search.f_dai.value="";
    	document.search.f_chu.value="";
    	document.search.f_shou.value="";
    	document.search.f_sai.value="";	
    }
    

 	var tabList 	 = ["tab_japan","tab_china","tab_korea","tab_asia"]; 
 	var tabImgOList	 = ["img/top/Tab1_o.gif","img/top/Tab2_o.gif","img/top/Tab3_o.gif","img/top/Tab4_o.gif"]; 
 	var tabImgList	 = ["img/top/Tab1.gif","img/top/Tab2.gif","img/top/Tab3.gif","img/top/Tab4.gif"]; 
	var initRegion   = ["","Select a City"];
	var initCity     = ["","All locations"];
	var initStreet   = ["","All locations"];
	var prefList	 = ["yamanasi",	"aomori",	"akita",	"osaka",	"wakayama",	"tokushima",
						"kagawa",	"kouchi",	"saga",		"iwate",	"tokyo",	"aichi",
						"ooita",	"miyagi",	"tochigi",	"shizuoka",	"tottori",	"toyama",
						"miyazaki",	"ibaragi",	"gunma",	"okinawa",	"kagoshima","niigata",
						"nagasaki",	"hukuoka",	"nara",		"simane",	"hiroshima","yamaguchi",
						"ehime",	"mie",		"tiba",		"kanagawa",	"hukui",	"nagano",
						"hokkaido",	"yamagata",	"kyoto",	"hyogo",	"shiga",	"saitama",
						"ishikawa",	"hukushima","kumamoto", "okayama",	"gihu"];
	function isPrefecture(tiku){
		if(tiku){
			for(i=0;i<prefList.length;i++){
				if(tiku == prefList[i]){
				   return true;
				}
			}
		}
		return false;
	}
						
 	function changeTab(tabid){
 		document.getElementById("tId").value = Util.escapeHTML(tabid);
 		for (i=0;i<tabList.length;i++){
 			if(tabList[i] == tabid){
				$("img"+tabList[i]).src    = tabImgOList[i];			
    			$(tabList[i]).style.display="";
    			$("img"+tabList[i]).style.cursor="default";
 			} else {
				$("img"+tabList[i]).src    = tabImgList[i];			
  				$(tabList[i]).style.display="none";
    			$("img"+tabList[i]).style.cursor="pointer";
  			}
 		}
 		return false;
 	}
 	
   	function changePrefecture(index){
		var tiku_dai = RootTree.findChild($("tiku_dai").options[index].value);
		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();
			if(isPrefecture(tiku_chu.getCode())){
				opList.push("Select locations");
			} else {
				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 += "/share/ext/js/en/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 getAction(){
		return "http://web.travel.rakuten.co.jp/portal/my/en_kensaku2.k1";
	}
	
	function en_search(act){
	    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(act!= null && act == "addChildren"){
			document.searchChild.f_cd.value = document.search.f_cd.value;
			document.searchChild.f_dai.value = document.search.f_dai.value;
			document.searchChild.f_chu.value = document.search.f_chu.value;
			document.searchChild.f_shou.value = document.search.f_shou.value;
			document.searchChild.f_sai.value = document.search.f_sai.value;
			document.searchChild.f_adult_su.value = document.search.f_adult_su.value;
			document.searchChild.f_heya_su.value = document.search.f_heya_su.value;
			document.searchChild.f_nen1.value = document.search.f_nen1.value;
			document.searchChild.f_tuki1.value = document.search.f_tuki1.value;
			document.searchChild.f_hi1.value = document.search.f_hi1.value;
			document.searchChild.f_nen2.value = document.search.f_nen2.value;
			document.searchChild.f_tuki2.value = document.search.f_tuki2.value;
			document.searchChild.f_hi2.value = document.search.f_hi2.value;
	    	document.searchChild.submit();
	    } else {
	    	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 == ""){
	        alert("select country");
	    } else {
	      if(document.search.f_tiku_chu.value == ""){
	      	alert("select City/Region");
	      } else {
	      	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");
	        		}
	        	}
	      	}
	      }     	
	    }   
		return false ;	
	}
