var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
//document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0
var divctr = 0;
var tmpdiv='';
function showDest(){
	if(document.packageform.package_type[0].checked){
        	window.document.getElementById('dest_area').style.display='none';		
	}else{
		window.document.getElementById('dest_area').style.display='block';
	}
}

function showImage(divid,ino){
        for(i=1;i<ino;i++){
                window.document.getElementById('idiv'+i).style.display='none';
        }
        window.document.getElementById(divid).style.display='block';
}

function showAgeBlock(val,f){
  var f=document.forms[""+f];
  if(val<1){
        window.document.getElementById('cha1').style.display='none';
        window.document.getElementById('cha2').style.display='none';
        f.age1.value='';
        f.age2.value='';
  }
  if(val == 1){
        window.document.getElementById('cha1').style.display='block';
        window.document.getElementById('cha2').style.display='none';
        f.age2.value='';
  }
  if(val == 2){
        window.document.getElementById('cha1').style.display='block';
        window.document.getElementById('cha2').style.display='block';
  }
}

function send_more_detail(package_id,period,adt,package_type,p_category,citylist){
	window.location.href='/package_itinerary/detail.html?package_type='+package_type+'&p_category='+p_category+'&period='+period+'&ADT='+adt+'&package_id='+package_id+"&citylist="+citylist;
}

function ascii_value(c){
        var i;
        for(i = 0; i < 256; ++ i){
                var h = i.toString (16);
                if (h.length == 1)
                        h = "0" + h;
                h="%"+h;
                h=unescape (h);
                if(h==c)
                        break;
        }
        return i;
}

function CommaFormatted(amount){
        var delimiter = ","; // replace comma if desired
        var d = '';
        var i = amount;
        if(isNaN(i)) { return ''; }
        var minus = '';
        if(i < 0) { minus = '-'; }
        i = Math.abs(i);
        var n = new String(i);
        var a = [];
        while(n.length > 3){
                var nn = n.substr(n.length-3);
                a.unshift(nn);
                n = n.substr(0,n.length-3);
        }
        if(n.length > 0) { a.unshift(n); }
        n = a.join(delimiter);
        if(d.length < 1) { amount = n; }
        else { amount = n + '.' + d; }
        amount = minus + amount;
        return amount;
}

function getCategoryValue(radioObj, type, citytype, flg) {
        var radioLength = radioObj.length;
        var val;
	if(flg==1){
                val = document.packageform.p_category.value;
	}else{
        	for(var i = 0; i < radioLength; i++) {
                	if(radioObj[i].checked) {
				if(radioObj[i].value != 'other'){
                        		val = radioObj[i].value;
				}else{
					val = document.packageform.p_ocategory.value;
				}
                	}
        	}
	}
        getCity(val,citytype,type);
}

function toggle(divName){
        for(i=0; i<=5; i++){
                document.getElementById('tab'+i).style.display='none';
                document.getElementById(divName).style.display='';
        }
}

function change_img1(){
    document.getElementById("change_img").src="/images/YT/package_itinerary/change_imgs.jpg"
}

function change_img2(){
    document.getElementById("change_img").src="/images/YT/package_itinerary/change_imgs2.jpg"
}

function change_img3(){
    document.getElementById("change_img").src="/images/YT/package_itinerary/change_imgs3.jpg"
}

function change_img4(){
    document.getElementById("change_img").src="/images/YT/package_itinerary/change_imgs4.jpg"
}

function change_img5(){
    document.getElementById("change_img").src="/images/YT/package_itinerary/change_imgs5.jpg"
}

function closecalender(isdivt, fid){
	var caldiv = 'caldiv';
	var form = 'detail_form';
	if(isdivt==2){
	document.getElementById('calanderdivt').style.display='none';
	caldiv = 'caldivt'; 
	form='detail_form2';
	}else{
	document.getElementById('calanderdiv').style.display='none';
	}

	if(fid){
		var d = document.getElementById(caldiv);
  		var olddiv = document.getElementById(form);
  		d.removeChild(olddiv);
	}
}

function showcalender(){
        document.getElementById('calanderdiv').style.display='';
}

function sort_by_tpprice(a, b){
        var x = Math.round(a.mprr);
        var y = Math.round(b.mprr);
        return ((x <= y) ? -1 : ((x > y) ? 1 : 0));
}

function sort_by_rating(a, b){
        var x = Math.round(a.yrt);
        var y = Math.round(b.yrt);
        return ((x <= y) ? -1 : ((x > y) ? 1 : 0));
}

function sort_by_duration(a, b){
        var x = parseInt(a.dur);
        var y = parseInt(b.du);
        return ((x <= y) ? -1 : ((x > y) ? 1 : 0));
}

function findPosX(obj){
	var curleft = 0;
    	if(obj.offsetParent)
        	while(1){
          		curleft += obj.offsetLeft;
          		if(!obj.offsetParent)
            			break;
          		obj = obj.offsetParent;
        	}
    	else if(obj.x)
        	curleft += obj.x;
 return curleft;
}

function findPosY(obj){
	var curtop = 0;
    	if(obj.offsetParent)
        	while(1){
          		curtop += obj.offsetTop;
          		if(!obj.offsetParent)
            			break;
          		obj = obj.offsetParent;
        	}
    	else if(obj.y)
        	curtop += obj.y;
 return curtop;
}

function set_date(cidate,isshow,flg,codate){
 if(isshow){
	alert('Please change the date, the days following it are not available.');
 }else{
	if(flg==2){
	window.document.detail_form2.cidate.value=cidate;
	window.document.detail_form2.codate.value=codate;
	}else{
	window.document.detail_form.cidate.value=cidate;
	window.document.detail_form.codate.value=codate;
	}
 }
}

function showResult(){
 var min;
 var max;
 var ctr=0;
 var doint=''; 
 fname='sortform';
 chk = 'pscope';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
 	if(document.forms[""+fname][chk][i].checked){
        	doint += document.forms[""+fname][chk][i].value;
       	}
 }
 chk = 'budget';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
 	if(document.forms[""+fname][chk][i].checked){
        	val = document.forms[""+fname][chk][i].value.split('|');
                if(ctr == 0){   min=val[0];     max=val[1];     }
                ctr++;
                if(min>val[0]){ min = val[0];   }
                if(max<val[1]){ max = val[1];   }
       	}
 }
 fname='leftfilter';
 chk='rating';
 var rating='';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        if(document.forms[""+fname][chk][i].checked){
                rating = rating+''+document.forms[""+fname][chk][i].value;
        }
 }
 if(!document.forms[""+fname][chk].length){	
	if(document.leftfilter.rating.checked && document.leftfilter.rating.value){
		rating=document.leftfilter.rating.value;
	}else if(!document.leftfilter.rating.checked && document.leftfilter.rating.value){
		rating='';
	}else{
	rating='NA1234567'; 
	}
 }
 fname='leftfilter';
 chk='duration';
 var duration='';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        if(document.forms[""+fname][chk][i].checked){
                duration += document.forms[""+fname][chk][i].value;
        }
 }
 if(!document.forms[""+fname][chk].length){     
	if(document.leftfilter.duration.checked && document.leftfilter.duration.value){
		duration=document.leftfilter.duration.value;
	}else if(!document.leftfilter.duration.checked && document.leftfilter.duration.value){
		duration='';
	}else{
	duration='abcdefghij'; 
	}
 }
 //Start City Filter
 chk='scity_id';
 citylist='';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        if(document.forms[""+fname][chk][i].checked){
                citylist = citylist+'|'+document.forms[""+fname][chk][i].value+'|';
        }
 }
 if(!document.forms[""+fname][chk].length){
        if(document.leftfilter.scity_id.checked && document.leftfilter.scity_id.value){
                citylist='|'+document.leftfilter.scity_id.value+'|';
        }else if(!document.leftfilter.scity_id.checked && document.leftfilter.scity_id.value){
                citylist='';
        }
 }
 //End City Filter
 room_code='allroom';
 var sortType = 'Price';
 setResults(sortType,min,max,doint,rating,duration,room_code,citylist);
}

function resetResults(sortOrder,min,max){
 fname='sortform';
 chk = 'pscope'; 
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
 	document.forms[""+fname][chk][i].checked=true;
 }
 chk = 'budget';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        document.forms[""+fname][chk][i].checked=true;
 }
 fname='leftfilter'
 chk='rating';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        document.forms[""+fname][chk][i].checked=true;
 }
 if(!document.leftfilter.rating.checked && document.leftfilter.rating.value){
                document.leftfilter.rating.checked=true;
 }
 chk='duration';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        document.forms[""+fname][chk][i].checked=true;
 }
 if(!document.leftfilter.duration.checked && document.leftfilter.duration.value){
                document.leftfilter.duration.checked=true;
 }
 chk='scity_id';
 citylist='';
 for(var i=0; i < document.forms[""+fname][chk].length; i++){
        document.forms[""+fname][chk][i].checked=true;
	citylist = citylist+'|'+document.forms[""+fname][chk][i].value+'|';
 }
 if(!document.leftfilter.scity_id.checked && document.leftfilter.scity_id.value){
                document.leftfilter.scity_id.checked=true;
		citylist = citylist+'|'+document.leftfilter.scity_id.value+'|';
 }
 setResults(sortOrder,'0','999999','DI','NA1234567','abcdefghij','allroom',citylist);
}

function holidaytab(divName){
 for(i=0; i<=4; i++){
	document.getElementById('holidaytabshowhide'+i).style.display='none';
        document.getElementById(divName).style.display='';
 }
}

function go_detail(searchid,pid,rc,mi,vers){
	if(!vers){	vers = 'YT';	}
	window.document.location.href='/package_itinerary/more_detail.html?search_id='+searchid+"&package_id="+pid+"&room_code="+rc+"&moreinfo="+mi+"&VERSION="+vers;
}

function gostep4(vars,promotionCodeName){
    if(vars =='YT' || vars =='FM'){
 	var promCodd = document.promCode.elements[""+promotionCodeName].value;
 	document.package_detail.promotion_code.value = promCodd;
}
	document.package_detail.submit();
}

function getMouseXY(e) {
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  return true
}

function generateDiv(divid){
 if(divctr>1){
        var str = "<div id='calloader' style='position:absolute; z-index:1000; top:"+(tempY-700)+"px; left:100px; display:none;'><img src='/images/YT/package_itinerary/calloader.gif' /><br/>Loading...</div><div style='position:absolute; z-index:1000; display:none; width:288px; top:"+(tempY-700)+"px; left:100px;' id='calanderdiv'><div id='calendermain' style='float:left;'><div id='caldiv'></div></div></div>";
        document.getElementById(divid).innerHTML=str;
        removeElement(divid);
 }else{
        var str = "<div id='calloader' style='position:absolute; z-index:1000; top:"+(tempY-700)+"px; left:100px;'><img src='/images/YT/package_itinerary/calloader.gif' /><br/>Loading...</div><div style='position:absolute; z-index:1000; display:none; width:288px; top:"+(tempY-700)+"px; left:100px;' id='calanderdiv'><div id='calendermain' style='float:left;'><div id='caldiv'></div></div></div>";
        document.getElementById(divid).innerHTML=str;
 }
}

function generateDivtForDetail(divid){
        var str = "<div id='calloader' style='position:absolute; z-index:1000; width:288px; top:325px; left:325px;'><img src='/images/YT/package_itinerary/calloader.gif' /><br/>Loading...</div><div style='position:absolute; z-index:1000; display:none; width:288px; top:325px; left:325px;' id='calanderdivt'><div id='calendermain' style='float:left;'><div id='caldivt'></div></div></div>";
        //document.getElementById(divid).innerHTML=str;
		document.getElementById("calendar").style.display = '';
		document.getElementById("calendar").innerHTML=str;
}

function generateDivForDetail(divid){
	var str = "<div id='calloader' style='position:absolute; z-index:1000; width:288px; top:325px; left:325px;'><img src='/images/YT/package_itinerary/calloader.gif' /><br/>Loading...</div><div style='position:absolute; z-index:1000; display:none; width:288px; top:325px; left:325px;' id='calanderdiv'><div id='calendermain' style='float:left;'><div id='caldiv'></div></div></div>";
        //document.getElementById(divid).innerHTML=str;
		document.getElementById("calendar").style.display = '';

		document.getElementById("calendar").innerHTML=str;

}

function removeElement(divid) {
	document.getElementById('calloader').style.top = (tempY-700);
	document.getElementById('calloader').style.display='block'; 
        document.getElementById('calanderdiv').style.top = (tempY-700);
	/*for(i=0;i<document.forms.length;i++){
                if(document.forms[i].name.indexOf('detail_form')!=-1){
		}
        }*/
}

var count=0;
function checklength(val){
  var selectedvar="";
  var selObj = document.packageform.origin;
  var slno=0;
  var selectedcode = '';
  var count=0;
  for (var i=0; i<selObj.options.length; i++) {
  	if (selObj.options[i].selected) {
		if(count<6){
			if(selectedcode.length>0){	
                	selectedcode = selectedcode + "|" + selObj.options[i].value;
			}else{
			selectedcode= selObj.options[i].value;
			}
			count++;
		}
		slno = i;
    	}
  }
  if(count>5){
	alert('Maximum 5 cities allowed.');
	selObj.options[slno].selected=false;
  }else{
  	document.packageform.citylist.value=selectedcode;
  }
}

function selallcat(){
 var selObj = document.packageform.p_ocategory;
 selObj.options[0].selected=true;
}

function checkcity(cityidstr){
alert(cityidstr);
}
