﻿var _order="1";
var _pagecount=0;
var _currentpage=0;
var _type=1;
var _curtab='tongquan';

function booktour(ncc)
{
    if(ncc=='FIDITOUR')
        return true;
    else
    {
        alert('Bạn vui lòng đặt tour tại website của nhà cung cấp.');
        return false;
    }
}

function setCheckoutdate()
{
    var checkin=TLib.getObj('txt_nhanphong').value;
    TLib.getObj('txt_traphong').value=TLib.addDate(1,checkin,'EU');;
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function createCookie(name,value,days){if (days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires="";document.cookie=name+"="+value+expires+"; path=/";}
function readCookie(name) {var nameEQ=name + "=";var ca=document.cookie.split(';');for(var i=0;i < ca.length;i++){var c=ca[i];while (c.charAt(0)==' ') {c=c.substring(1,c.length);}if (c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}}return null;}
function eraseCookie(name){createCookie(name,"",-1);}

function showcontent(id)
{
    if(_curtab!='') { document.getElementById(_curtab).style.display='none';}
    _curtab=id;
    document.getElementById(id).style.display='block';
}

function RemoveUnicode(str) {
   str= str.toLowerCase();
   str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
   str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
   str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
   str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
   str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
   str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
   str= str.replace(/đ/g,"d");
   str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-"); 
 /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */ 
   str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1- 
   str= str.replace(/^\-+|\-+$/g,"");  
 //cắt bỏ ký tự - ở đầu và cuối chuỗi  
   return str;
   }

function ShowData(url)
{
    document.getElementById('kslist').style.display='block';
    if(document.getElementById('khuyenmai'))
    { document.getElementById('khuyenmai').style.display='none'; }
    if(url=="") return;
    if (!HttpRequest) return;
    
    HttpRequest.open("GET",url);
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           document.getElementById('kslist').innerHTML='';
           var xml = HttpRequest.responseXML;
           if(xml==null){ _pagecount=0;_currentpage=0;document.getElementById('showpager').innerHTML=''; return;}
           var c = xml.getElementsByTagName("date");
           var template='<div class="ksitem1"><a href="/khachsan1/chitietks.aspx?id=ItemID" class="kstitle">ItemName<br><img src="/images/saoItemStart.jpg" style="width: 50px; height: 10px;" /><br><span class="gia1">Giá tốt nhất</span></a><a href="/khachsan1/chitietks.aspx?id=ItemID"><img src="ItemImage" class="demo" /></a><div class="ksdesc">ItemDesc</div><a href="/khachsan1/datphongkhachsan.aspx?id=ItemID" class="chitiet"><img src="/images92010/bt_datphong.jpg"></a></div>';
                      
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('~');
               if(i==0)
               { _pagecount=value;}
               else
               {
                   var itemid= info[0];
                   var name= info[1];
                   var image= info[2];
                   var desc= info[3];
                   var start= info[4];
                   var price= info[5];
                   var ngoaite= info[6];
                   
                   price = TLib.addCommas(price);
                   
                   var tmp=template;
                   tmp = tmp.replace(/ItemID/gi,itemid);
                   tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
                   tmp = tmp.replace(/ItemName/gi,name);
                   tmp = tmp.replace(/ItemImage/gi,'http://www.fiditour.com'+image);
                   tmp = tmp.replace(/ItemDesc/gi,desc);
                   tmp = tmp.replace(/ItemStart/gi,start);
                   tmp = tmp.replace(/ItemPrice/gi,price);
                   tmp = tmp.replace(/ItemDVT/gi,ngoaite);
                   document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+tmp;
                   if(i%3==0) {document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+'<div class="seperator"></div>';}
               }
           }
           CreatePager(_pagecount,_currentpage);
       }
   }   
   HttpRequest.send(null);
}

function ShowData111(url)
{//dung cho querybuilder2
    document.getElementById('kslist').style.display='block';
    if(document.getElementById('khuyenmai'))
    { document.getElementById('khuyenmai').style.display='none'; }
    if(url=="") return;
    if (!HttpRequest) return;
    
    HttpRequest.open("GET",url);
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           document.getElementById('kslist').innerHTML='';
           var xml = HttpRequest.responseXML;
           if(xml==null){ _pagecount=0;_currentpage=0;document.getElementById('showpager').innerHTML=''; return;}
           var c = xml.getElementsByTagName("date");
           var template='<div class="ksitem1"><a href="/khachsan1/chitietks.aspx?id=ItemID" class="kstitle">ItemName<br><img src="/images/saoItemStart.jpg" style="width: 50px; height: 10px;" /><br><span class="gia1">Giá tốt nhất</span></a><a href="/khachsan1/chitietks.aspx?id=ItemID"><img src="ItemImage" class="demo" /></a><div class="ksdesc">ItemDesc</div><a href="/khachsan1/datphongkhachsan.aspx?id=ItemID" class="chitiet"><img src="/images92010/bt_datphong.jpg"></a></div>';
           //var template='<div class="ksitem1"><a href="/khachsan1/chitietks.aspx?id=ItemID" class="kstitle">ItemName<br><img src="/images/saoItemStart.jpg" style="width: 50px; height: 10px;" /><br>Giá: <span class="gia1">ItemPrice ItemDVT</span></a><a href="/khachsan1/chitietks.aspx?id=ItemID"><img src="ItemImage" class="demo" /></a><div class="ksdesc">ItemDesc</div><a href="/khachsan1/datphongkhachsan.aspx?id=ItemID" class="chitiet"><img src="/images92010/bt_datphong.jpg"></a></div>';
           
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('~');
               if(i==0)
               { _pagecount=value;}
               else
               {
                   var itemid= info[0];
                   var name= info[1];
                   var image= info[2];
                   var desc= info[3];
                   var start= info[4];
                   var price= info[5];
                   var ngoaite= info[6];
                   
                   price = TLib.addCommas(price);
                   
                   var tmp=template;
                   tmp = tmp.replace(/ItemID/gi,itemid);
                   tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
                   tmp = tmp.replace(/ItemName/gi,name);
                   tmp = tmp.replace(/ItemImage/gi,'http://www.fiditour.com'+image);
                   tmp = tmp.replace(/ItemDesc/gi,desc);
                   tmp = tmp.replace(/ItemStart/gi,start);
                   tmp = tmp.replace(/ItemPrice/gi,price);
                   tmp = tmp.replace(/ItemDVT/gi,ngoaite);
                   document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+tmp;
                   if(i%3==0) {document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+'<div class="seperator"></div>';}
               }
           }
           CreatePager111(_pagecount,_currentpage);
       }
   }   
   HttpRequest.send(null);
}

function Promotion(url)
{
    document.getElementById('kslist').style.display='none';
    document.getElementById('khuyenmai').style.display='block';
    if(url=="") return;
    if (!HttpRequest) return;
    
    HttpRequest.open("GET",url);
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           document.getElementById('khuyenmai').innerHTML='';
           var xml = HttpRequest.responseXML;
           if(xml==null){ _pagecount=0;_currentpage=0;document.getElementById('showpager').innerHTML=''; return;}
           var c = xml.getElementsByTagName("date");
           var template='<div class="ksitem1"><a href="/khach-san1/ItemID/ItemNameFormat.html" class="kstitle">ItemName<br><img src="/images/saoItemStart.jpg" style="width: 50px; height: 10px;" /></a><a href="/khach-san1/ItemID/ItemNameFormat.html"><img src="ItemImage" class="demo" /></a><div class="ksdesc">ItemDesc</div><a href="" class="chitiet">Chi tiết</a></div>';
           
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('~');
               if(i==0)
               { _pagecount=value;}
               else
               {
                   var itemid= info[0];
                   var name= info[1];
                   var image= info[2];
                   var desc= info[3];
                   var start= info[4];
                   
                   var tmp=template;
                   tmp = tmp.replace(/ItemID/gi,itemid);
                   tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
                   tmp = tmp.replace(/ItemName/gi,name);
                   tmp = tmp.replace(/ItemImage/gi,'http://www.fiditour.com'+image);
                   tmp = tmp.replace(/ItemDesc/gi,desc);
                   tmp = tmp.replace(/ItemStart/gi,start);
                   document.getElementById('khuyenmai').innerHTML=document.getElementById('khuyenmai').innerHTML+tmp;
                   if(i%3==0) {document.getElementById('khuyenmai').innerHTML=document.getElementById('khuyenmai').innerHTML+'<div class="seperator"></div>';}
               }
           }
           CreatePager(_pagecount,_currentpage);
       }
   }   
   HttpRequest.send(null);
}

function Promotion1(id)
{
    //var url='/khachsan1/km.aspx?pid='+id+'&s=&l=&v=&t=&n=&p=&o=';
    var url='/khachsan1/km1.aspx?id='+id;
    document.getElementById('kslist').style.display = 'block';
    //đổi màu tabcontrol
    var Arr= new Array(5,72,6,8,24,7,95,14,13,10,9,4,3,2);
    for ( j=0;j< Arr.length;j++)
    {
        if (id == Arr[j])
        document.getElementById(Arr[j]).className="selected";
        else
            document.getElementById(Arr[j]).className = "";
    }
    //end
    if(url=="") return;
    if (!HttpRequest) return;

    HttpRequest.open("GET", url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           document.getElementById('kslist').innerHTML='';
           var xml = HttpRequest.responseXML;
           if(xml==null){ _pagecount=0;_currentpage=0;document.getElementById('showpager').innerHTML=''; return;}
           var c = xml.getElementsByTagName("date");
           var template='<div class="ksitem1"><a href="ItemLinktarget" class="kstitle">ItemName<br><img src="/images/saoItemStart.jpg" style="width: 50px; height: 10px;" /></a><a href="ItemLinktarget"><img src="ItemImage" class="demo" /></a><div class="ksdesc">ItemDesc<span style="color: red;"><strong>Giá khuyến mãi:</strong>:<span style="color: black; font-weight: bold;">PromoPrice</span></div><a href="ItemLinktarget" class="chitiet">Chi tiết</a></div>';
                      
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('~');
               if(i==0)
               { _pagecount=value;}
               else
               {   var linktarget='';
                   var itemid= info[0];
                   var name= info[1];
                   var image= info[2];
                   var desc= info[3];
                   var start= info[4];
                   var promoprice= info[5];
                   var itemlink= info[6];
                   var promo= info[7];
                   
                   //linktarget
                   if(promo=='False')
                   {
                    //khach san
                    linktarget='/khachsan1/chitietks.aspx?id='+itemid+'&k=1';
                   }
                   else
                   {
                    //tin khuyen mai
                    linktarget='/khuyen-mai-khach-san/'+RemoveUnicode(name)+'-i'+itemid+'.html';
                   }
                   
                   var tmp=template;
                   tmp = tmp.replace(/ItemID/gi,itemid);
                   tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
                   tmp = tmp.replace(/ItemName/gi,name);
                   tmp = tmp.replace(/ItemImage/gi,'http://www.fiditour.com'+image);
                   tmp = tmp.replace(/ItemDesc/gi,desc);
                   tmp = tmp.replace(/ItemStart/gi,start);
                   tmp = tmp.replace(/PromoPrice/gi,promoprice);
                   tmp = tmp.replace(/ItemLinktarget/gi,linktarget);
                   document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+tmp;
                   if(i%3==0) {document.getElementById('kslist').innerHTML=document.getElementById('kslist').innerHTML+'<div class="seperator"></div>';}
               }
           }
           //CreatePager1(_pagecount,_currentpage);
       }
   }   
   HttpRequest.send(null);
}

isEmail = function(val)
{
    if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(val)) { return true; }
    else { return false; }
}

function dangky()
{
    var email=document.getElementById('txtemaildangky').value;
    if(email!='')
    {
        if(isEmail(email))
        {Ajax.Get('/khachsan1/nhantin.aspx?email='+email,'Chúc mừng bạn đã đăng ký thành công.','Đăng ký không thành công. Vui lòng thử lại sau.');}
        else{ alert('Thông tin địa chỉ email bạn nhập không hợp lệ.');}
    }
    else
    {
        alert('Vui lòng nhập thông tin địa chỉ email của bạn');
    }
    return false;
}

function TimKiemVMB()
{
    var type=1;
    if(document.getElementById('rdomotchieu').checked==true){type=2;}
    if(document.getElementById('ddl_kh_vmb').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin điểm khởi hành"); return false;
    }
    if(document.getElementById('ddl_den_vmb').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin điểm đến"); return false;
    }
        //type la tim kiem khu hoi hay mot chieu
    if(type==1) //khu hoi
    {
        var ngaykh=document.getElementById('ngay_kh').value;
        var thangkh=document.getElementById('thang_kh').value;
        var ngayve=document.getElementById('ngay_ve').value;
        var thangve=document.getElementById('thang_ve').value;
        
        var reg=new RegExp('/','g');
        window.location = "/"+document.getElementById('ddl_kh_vmb').value+"/"+document.getElementById('ddl_den_vmb').value+"/"+"tim-kiem-ve-may-bay-tu-"+formattext('ddl_kh_vmb')+"-den-"+formattext('ddl_den_vmb')+"-di-ngay-"+(ngaykh+'-'+thangkh)+"-ve-ngay-"+(ngayve+'-'+thangve)+".html";
        //alert('khu hoi');
    }
    else //mot chieu
    {
        var ngaykh=document.getElementById('ngay_kh').value;
        var thangkh=document.getElementById('thang_kh').value;
        var reg=new RegExp('/','g');
        window.location = "/"+document.getElementById('ddl_kh_vmb').value+"/"+document.getElementById('ddl_den_vmb').value+"/"+"tim-kiem-ve-may-bay-tu-"+formattext('ddl_kh_vmb')+"-den-"+formattext('ddl_den_vmb')+"-di-ngay-"+(ngaykh+'-'+thangkh)+".html";
        //alert('mot chieu');
    }
}

function binddate()
{
    var now = new Date();
    var ngay,thang,nam,id;
    ngay = now.getDate();
    nam = now.getFullYear();
    thang = now.getMonth();
    thang++;
    //alert(thang+1);
    for(var i=0;i<=12;i++)
    {
        id=i+1;
        if(thang>12) {thang=1; nam++;}
        document.getElementById('thang_kh').options[i] = new Option('Tháng '+(thang)+' '+ nam, thang+'-'+nam);
        document.getElementById('thang_ve').options[i] = new Option('Tháng '+(thang)+' '+ nam, thang+'-'+nam);
        thang++;
    }
    var thang1=document.getElementById('thang_kh').value;
    var thang2=document.getElementById('thang_ve').value;
    var t,n;
    t=thang1.split('-')[0];
    n=thang1.split('-')[1];
    var DOM=31;
    switch(t)
	{	case 2:
			DOM = ((((n % 4) == 0) && ((n % 100) != 0)) || ((n % 400) == 0)) ? 29 : 28;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			DOM = 30; break;
		default:
			DOM = 31;
	}
	document.getElementById('ngay_kh').options.length=0;
	document.getElementById('ngay_ve').options.length=0;
	
	var stt=0;
    for(var j=ngay;j<DOM;j++)
    {
        document.getElementById('ngay_kh').options[stt] = new Option(j+1, j+1);
        document.getElementById('ngay_ve').options[stt] = new Option(j+1, j+1);
        stt++;
    }
}

function selectmonth(id)
{
    var now = new Date();
    var nam = now.getFullYear();
    if(id==0)
    {
        var ngay=document.getElementById('ngay_kh').value;
        var thang1=document.getElementById('thang_kh').value;
        var t,n;
        var dom1=31;
        t= parseInt(thang1.split('-')[0]);
        n= parseInt(thang1.split('-')[1]);
        switch(t)
	    {	case 2:
			    dom1 = ((((n % 4) == 0) && ((n % 100) != 0)) || ((n % 400) == 0)) ? 29 : 28;
			    break;
		    case 4:
		    case 6:
		    case 9:
		    case 11:
			    dom1 = 30; break;
		    default:
			    dom1 = 31; break;
	    }
	    document.getElementById('ngay_kh').options.length=0;
        for(var j=0;j<dom1;j++)
        {
            document.getElementById('ngay_kh').options[j] = new Option(j+1, j+1);
        }
	    if(ngay>dom1)
	    {
            document.getElementById('ngay_kh').selectedIndex=dom1-1;
        }
        else
        {
            document.getElementById('ngay_kh').selectedIndex=ngay-1;
        }
    }
    else
    {
        var ngay=document.getElementById('ngay_ve').value;
        var thang2=document.getElementById('thang_ve').value;
        var t,n;
        var dom1=31;
        t= parseInt(thang2.split('-')[0]);
        n= parseInt(thang2.split('-')[1]);
        switch(t)
	    {	case 2:
			    dom1 = ((((n % 4) == 0) && ((n % 100) != 0)) || ((n % 400) == 0)) ? 29 : 28;
			    break;
		    case 4:
		    case 6:
		    case 9:
		    case 11:
			    dom1 = 30; break;
		    default:
			    dom1 = 31;
	    }
	    document.getElementById('ngay_ve').options.length=0;
        for(var j=0;j<dom1;j++)
        {
            document.getElementById('ngay_ve').options[j] = new Option(j+1, j+1);
        }
        if(ngay>dom1)
	    {
            document.getElementById('ngay_ve').selectedIndex=dom1-1;
        }
        else
        {
            document.getElementById('ngay_ve').selectedIndex=ngay-1;
        }
    }
}

function CreatePager(pageCount, currentPage)
{
    document.getElementById('showpager').innerHTML='';
    var pages = new Array();
    var startPage = 0;
    var endPage = 0;
    
    if(eval(pageCount) == 1)
    {
    	document.getElementById("showpager").display = "none";
    	return;
    }
    startPage = currentPage - 2;
    if(startPage < 0) startPage = 0;
    if(startPage + 4 < pageCount)
    {
        endPage = startPage + 4;
    }
    else
    {
        endPage = pageCount - 1;
    }
    if(endPage - 4 < 0)
    {
        startPage = 0;
    }
    else
    {
        startPage = endPage - 4;
    }
    
    //pages[pages.length] = "<a class='Page' " + (pageCount > 0 ? "href='" + url.replace("{page}", 0) + "'" : "") + ">|&lt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='_currentpage=0;QueryBuilder("+_type+");return false;'"+">|&lt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='if(_currentpage>0){_currentpage--;QueryBuilder("+_type+");}return false;'>&lt;</a>";
    for(var i = startPage; i <= endPage; i++)
    {
        pages[pages.length] = "<a class='" + (i == currentPage?"Current":"Page") + "' href='' onclick='_currentpage="+i+";QueryBuilder("+_type+");return false;'>" + (i + 1) + "</a>";
    }    
    pages[pages.length] = "<a class='Page' href='' onclick='if(_currentpage<(_pagecount-1)){_currentpage++;QueryBuilder("+_type+");}return false;' >&gt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='_currentpage="+(pageCount-1)+";QueryBuilder("+_type+");return false;'>&gt;|</a>";
    //document.write(pages.join("&nbsp;&nbsp;"));
    //alert(pages.join("&nbsp;&nbsp;"));
    document.getElementById('showpager').innerHTML = pages.join("&nbsp;&nbsp;");
}

function CreatePager111(pageCount, currentPage)
{
//dung cho querybuilder2
    document.getElementById('showpager').innerHTML='';
    var pages = new Array();
    var startPage = 0;
    var endPage = 0;
    
    if(eval(pageCount) == 1)
    {
    	document.getElementById("showpager").display = "none";
    	return;
    }
    startPage = currentPage - 2;
    if(startPage < 0) startPage = 0;
    if(startPage + 4 < pageCount)
    {
        endPage = startPage + 4;
    }
    else
    {
        endPage = pageCount - 1;
    }
    if(endPage - 4 < 0)
    {
        startPage = 0;
    }
    else
    {
        startPage = endPage - 4;
    }
    
    //pages[pages.length] = "<a class='Page' " + (pageCount > 0 ? "href='" + url.replace("{page}", 0) + "'" : "") + ">|&lt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='_currentpage=0;QueryBuilder2("+_type+");return false;'"+">|&lt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='if(_currentpage>0){_currentpage--;QueryBuilder2("+_type+");}return false;'>&lt;</a>";
    for(var i = startPage; i <= endPage; i++)
    {
        pages[pages.length] = "<a class='" + (i == currentPage?"Current":"Page") + "' href='' onclick='_currentpage="+i+";QueryBuilder2("+_type+");return false;'>" + (i + 1) + "</a>";
    }    
    pages[pages.length] = "<a class='Page' href='' onclick='if(_currentpage<(_pagecount-1)){_currentpage++;QueryBuilder2("+_type+");}return false;' >&gt;</a>";
    pages[pages.length] = "<a class='Page' href='' onclick='_currentpage="+(pageCount-1)+";QueryBuilder2("+_type+");return false;'>&gt;|</a>";
    //document.write(pages.join("&nbsp;&nbsp;"));
    //alert(pages.join("&nbsp;&nbsp;"));
    document.getElementById('showpager').innerHTML = pages.join("&nbsp;&nbsp;");
}
function ShowLargeImage(url)
{
    //alert(url);
    document.getElementById('largeimage').src="http://www.fiditour.com/upload/HinhKhachSan"+url;
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function Trim( value ) {
	
	return LTrim(RTrim(value));
	
}


function trim1(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function ShowHotelImage()
{
    var list=document.getElementById('hotelimage').innerHTML;
    var stritem=list.split(';');
    for(var i=0; i<stritem.length; i++)
    {
        if(i==0) { document.getElementById('largeimage').src='http://www.fiditour.com/upload/HinhKhachSan'+stritem[0];}
        //document.getElementById('imglist').innerHTML=document.getElementById('imglist').innerHTML+"<img class='item' onclick='ShowLargeImage(\"http://www.fiditour.com/upload/HinhKhachSan"+stritem[i]+"\");' src='http://www.fiditour.com/upload/HinhKhachSan"+stritem[i]+"' alt='' />";
        document.getElementById('imglist').innerHTML=document.getElementById('imglist').innerHTML+'<img class="item" onclick="ShowLargeImage(\''+trim1(stritem[i])+'\');" src="http://www.fiditour.com/upload/HinhKhachSan'+trim1(stritem[i])+'" alt="" />';
        //alert("ShowLargeImage(\""+stritem[i]+"\")");
    }
    //alert(document.getElementById('imglist').innerHTML);
}

function khuyenmai1()
{
    document.getElementById('showpager').innerHTML='';
    document.getElementById('kslist').style.display='none';
    document.getElementById('khuyenmai').style.display='block';
    return false;
}

function uncheckall()
{
    for(var j=1;j<=3;j++)
    {
        document.getElementById('loai'+j).checked==false;
    }
    for(var k=0;k<_vitri;k++)
    {
        document.getElementById('vitri'+k).checked==false;
    }
    for(var l=0;l<_nhucau;l++)
    {
        document.getElementById('nhucau'+l).checked==false;
    }
    for(var m=0;m<_tiennghi;m++)
    {
        document.getElementById('tiennghi'+m).checked==false;
    }
}

function QueryBuilder()
{
    var pid='';
    if(document.getElementById('ctl00_ContentPlaceHolder1_ddlthanhpho'))
    {
        if(document.getElementById('ctl00_ContentPlaceHolder1_ddlthanhpho').selectedIndex!=0)
            pid=document.getElementById('ctl00_ContentPlaceHolder1_ddlthanhpho').value;
    }
    //sao dang chon
    var sao=0;
    for(var i=1;i<=5;i++)
    {
        if(document.getElementById(i+'sao').checked==true){sao=i;}
    }
    //loai khach san
    var loai='';
    for(var j=1;j<=3;j++)
    {
        if(document.getElementById('loai'+j).checked==true){loai=j;}
    }
    //vi tri
    var vitri='';
    for(var k=0;k<_vitri;k++)
    {
        if(document.getElementById('vitri'+k).checked==true) {vitri=vitri+document.getElementById('vitri'+k).value+',';}
    }
    //nhu cau
    var nhucau='';
    for(var l=0;l<_nhucau;l++)
    {
        if(document.getElementById('nhucau'+l).checked==true) {nhucau=nhucau+document.getElementById('nhucau'+l).value+',';}
    }
    //tien nghi
    var tiennghi='';
    for(var m=0;m<_tiennghi;m++)
    {
        if(document.getElementById('tiennghi'+m).checked==true) {tiennghi=tiennghi+document.getElementById('tiennghi'+m).value+',';}
    }
    var url='';
    if(_type==1||_type==3) {url='/khachsan1/getdata.aspx';}
    else {url='/khachsan1/km.aspx';}
    url+='?pid='+pid+'&s='+sao+'&l='+loai+'&v='+vitri.substring(0,vitri.length-1)+'&t='+tiennghi.substring(0,tiennghi.length-1)+'&n='+nhucau.substring(0,nhucau.length-1)+'&p='+_currentpage+'&o='+_order;
    //alert(url);
    if(_type==1)
    { ShowData(url);}
    else if(_type==2)
    { Promotion(url);}
    else
    {
        createCookie('dlmscookie',url,100);
        createCookie('action','1',100);
        //alert('tao côkie');
        window.location="/khach-san1.html";
    }
}

function getstart(sao)
{
    var url = '/khachsan1/getdata.aspx';
    url+='?pid=&s='+sao+'&l=&v=&t=&n=&p=&o=';
    ShowData(url);
}


function setDefault()
{
    //alert(readCookie('dlmscookie'));
    if(readCookie('dlmscookie')!=null)
    {
        var url1=readCookie('dlmscookie');
        var tmp=url1.split('&');
        var id=tmp[0].substring(tmp[0].length-1,tmp[0].length);
        if(id!='=')
        {}
        var s=tmp[1].substring(tmp[1].length-1,tmp[1].length);
        if(s!='=')
        {
            document.getElementById(s+'sao').checked=true;
        }
        ShowData(url1);
    }
    else
    {
        var url2='/khachsan1/getdata.aspx?pid=&s=5&l=&v=&t=&n=&p=0&o=1';
        document.getElementById('5sao').checked=true;
        ShowData(url2);
    }
}

function search(pid,start)
{
    var url2='/khachsan1/getdata.aspx?pid='+pid+'&s='+start+'&l=&v=&t=&n=&p=0&o=1';
    document.getElementById(start+'sao').checked=true;
    ShowData(url2);
}

function QueryBuilder1(order)
{
    var url='/khachsan1/getdata1.aspx';
    url+='?p='+_currentpage+'&o='+order;
    //alert(url);
    if(_type==1)
    { ShowData(url);}
    else if(_type==2)
    { Promotion(url);}
    else 
    {
        createCookie('dlmscookie',url,100);
        createCookie('action','1',100);
        //alert('tao côkie');
        window.location="/khach-san1.html";
    }
}

function SelectCity()
{
    var val=document.getElementById('ctl00_ContentPlaceHolder1_ddlthanhpho').value;
    var name=document.getElementById("ctl00_ContentPlaceHolder1_ddlthanhpho").options[document.getElementById("ctl00_ContentPlaceHolder1_ddlthanhpho").selectedIndex].text;
    document.getElementById('tieude').innerHTML='Tìm kiếm nâng cao tại '+name;
    document.getElementById('cityname').innerHTML='Khách sạn tại '+name;
    document.getElementById('1sao').checked=true;
    document.getElementById('loai1').checked=true;
    _pagecount=0;_currentpage=0;
    QueryBuilder();
}

function SelectCity1()
{
    var val=document.getElementById('ctl00_ContentPlaceHolder1_ddlthanhpho').value;
    document.getElementById('1sao').checked=true;
    _pagecount=0;_currentpage=0;
    _type=3;
    QueryBuilder();
}

function hiliteRow(row, mouseOver)
{
    if(row.checked) return;
    if(mouseOver)
        row.style.backgroundColor = "#ffffe6";
    else
        row.style.backgroundColor = "";
}

var HttpRequest = false;

if (window.XMLHttpRequest) // Internet Explorer
{
    HttpRequest = new XMLHttpRequest();
}
else  // Other browsers  
{
    HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}

function getcountry(cid)
{
    if (!HttpRequest) return;
    
    var url = "/getcountry.aspx?tourid=" + cid;
    HttpRequest.open("GET",url);
    var nuocngoai=false;
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           document.getElementById('ctl00_ContentPlaceHolder1_ddlvungmien').options.length = 0; //Xóa dữ liệu cũ
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               document.getElementById('ctl00_ContentPlaceHolder1_ddlvungmien').options[i] = new Option(value, id);
               
           }
           if(c.length==1)
           {
                document.getElementById('ctl00_ContentPlaceHolder1_ddlvungmien').disabled = true;
                document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;
           }
           else
           {        
                document.getElementById('ctl00_ContentPlaceHolder1_ddlvungmien').disabled = false;
                document.getElementById('ctl00_ContentPlaceHolder1_ddlvungmien').focus();
                document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;
           }
       }
   }
   HttpRequest.send(null);
}

function gethotel(cid)
{
    if (!HttpRequest) return;
    
    var url = "/gethotel.aspx?tourid=" + cid;
    HttpRequest.open("GET",url);
    //alert(url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').options.length = 0; //Xóa dữ liệu cũ
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').options[i] = new Option(value, id);
               
           }
           if(c.length==1)
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;
           else
           {        
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = false;
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').focus();
           }
       }
   }
   
   HttpRequest.send(null);
}

function getProvince(cid)
{
    if (!HttpRequest) return;
    
    var url = "/getProvince.aspx?tourid=" + cid;
    HttpRequest.open("GET",url);
    //alert(url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           document.getElementById('ddltinhthanh').options.length = 0; //Xóa dữ liệu cũ
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               document.getElementById('ddltinhthanh').options[i] = new Option(value, id);
               
           }
           if(c.length==0)
           {
                document.getElementById('ddltinhthanh').disabled = true;
           }
           else
           {        
                document.getElementById('ddltinhthanh').disabled = false;
                document.getElementById('ddltinhthanh').focus();
           }
       }
   }
   
   HttpRequest.send(null);
}

function getProvince1(cid)
{
    if (!HttpRequest) return;
    
    var url = "/getProvince.aspx?tourid=" + cid;
    HttpRequest.open("GET",url);
    //alert(url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').options.length = 0; //Xóa dữ liệu cũ
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').options[i] = new Option(value, id);
           }
           if(c.length==0)
                document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
           else
           {        
                document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = false;
                document.getElementById('ctl00_ContentPlaceHolder1_ddltinhthanh').focus();
                document.getElementById('ctl00_ContentPlaceHolder1_ddlkhachsan').options.length = 1;
           }
       }
   }
   
   HttpRequest.send(null);
}

function TimKSTrongNuoc()
{
    if(document.getElementById('ctl00_ddlvungmien').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin vùng miền cần tìm"); return false;
    }
    if(document.getElementById('ddltinhthanh').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin tỉnh thành cần tìm"); return false;
    }
    else
    {
        //alert('nuoc ngoai');
        window.location="/tim-khach-san-trong-nuoc/"+document.getElementById('ddltinhthanh').value+"/"+document.getElementById('ddlloaiks').value+"/";
        return false;
    }
}

function TimKSTrongNuoc1()
{
    if(document.getElementById('ddlvungmien').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin vùng miền cần tìm"); return false;
    }
    if(document.getElementById('ddltinhthanh').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin tỉnh thành cần tìm"); return false;
    }
    else
    {
        //alert('nuoc ngoai');
        window.location="/tim-khach-san-trong-nuoc/"+document.getElementById('ddltinhthanh').value+"/"+document.getElementById('ddlcapdo').value+"-sao/";
        return false;
    }
}

function TimKS()
{
    //ctl00_ContentPlaceHolder1_ddlkhoihanh
    if(TLib.getObj('ctl00_ContentPlaceHolder1_ddlkhoihanh')!=null)
    {
        if(TLib.getObj('ctl00_ContentPlaceHolder1_ddlkhoihanh').selectedIndex==0)
        {
            alert("Vui lòng chọn thông tin địa điểm cần tìm"); return false;
        }
    }
    else
    {
        if(TLib.getObj('ctl00_ddlkhoihanh').selectedIndex==0)
        {
            alert("Vui lòng chọn thông tin địa điểm cần tìm"); return false;
        }
    }
    if(TLib.getObj('txt_nhanphong').value==''||TLib.getObj('txt_traphong').value=='')
    {
        alert('Bạn vui lòng chọn thông tin ngày nhận phòng và ngày trả phòng');return false;
    }
    else
    {
        if(TLib.getObj('ctl00_ContentPlaceHolder1_ddlkhoihanh'))
        {
            var id=TLib.getSelectValue('ctl00_ContentPlaceHolder1_ddlkhoihanh');
        }else
        {
            var id=TLib.getSelectValue('ctl00_ddlkhoihanh');
        }
        window.location = "/khach-san/tim-kiem-khach-san-i"+id+".html";
        
    }
    return false;
}

function TimKS1()
{
    //ctl00_ContentPlaceHolder1_ddlkhoihanh
    if(TLib.getObj('ddlkhoihanh')!=null)
    {
        if(TLib.getObj('ddlkhoihanh').selectedIndex==0)
        {
            alert("Vui lòng chọn thông tin địa điểm cần tìm"); return false;
        }
    }
    else
    {
        if(TLib.getObj('ddlkhoihanh').selectedIndex==0)
        {
            alert("Vui lòng chọn thông tin địa điểm cần tìm"); return false;
        }
    }
    if(TLib.getObj('txt_nhanphong').value==''||TLib.getObj('txt_traphong').value=='')
    {
        alert('Bạn vui lòng chọn thông tin ngày nhận phòng và ngày trả phòng');return false;
    }
    else
    {
        if(TLib.getObj('ddlkhoihanh'))
        {
            var id=TLib.getSelectValue('ddlkhoihanh');
        }else
        {
            var id=TLib.getSelectValue('ddlkhoihanh');
        }
        window.location = "/khach-san/tim-kiem-khach-san-i"+id+".html";
        
    }
    return false;
}

function getDiemDen(khoihanh)
{
    //resetDiemDen();
    
    if (!HttpRequest) return;
    if (khoihanh < 1) return;
    var loaitour;
    if(document.getElementById('rdnuocngoai').checked)
    {
        loaitour=1; //1 la nuoc ngoai
    }
    else if(document.getElementById('rdtrongnuoc').checked)
    {
        loaitour=2; //2 la trong nuoc
    }

    var url = "/getdiemden.aspx?khoihanh=" + khoihanh+"&loai="+loaitour;
    HttpRequest.open("GET",url);
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           //alert(url);
           
           var xml = HttpRequest.responseXML;
           //kiem tra ben trang AjaxServer.aspx
           var c = xml.getElementsByTagName("category");

           document.getElementById('ddldiemden').options.length = 0; //Xóa dữ liệu cũ
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               document.getElementById('ddldiemden').options[i] = new Option(value, id);
           }
           
           document.getElementById('ddldiemden').disabled = false;
           document.getElementById('ddldiemden').focus();
       }
   }   
   HttpRequest.send(null);
}

function resetkh()
{ 
    document.getElementById('ddlkhoihanh').selectedIndex=0;
    document.getElementById('ddldiemden').selectedIndex=0;
}

function TraCuuTour()
{
    if(document.getElementById('ddlkhoihanh').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin điểm khởi hành"); return false;
    }
    if(document.getElementById('ddldiemden').selectedIndex==0)
    {
        alert("Vui lòng chọn thông tin điểm đến"); return false;
    }
    else
    {
        if(document.getElementById('rdnuocngoai').checked==true)
        {
            window.location="/du-lich-trong-nuoc/tim-kiem-tour-trong-nuoc-"+document.getElementById('ddlkhoihanh').value+"-"+document.getElementById('ddldiemden').value+".html";
        }
        else
        {
            window.location="/du-lich-nuoc-ngoai/tim-kiem-tour-nuoc-ngoai-"+document.getElementById('ddlkhoihanh').value+"-"+document.getElementById('ddldiemden').value+".html";
        }
    }
}


function getdiemdenvmb(kh)
{
    u_SendReq('/diemdenvmb.aspx?kh='+kh,2,'','','ddl_den_vmb');
}

function getDiemDenVMB(khoihanh)
{
    if (!HttpRequest) return;

    var url = "/diemdenvmb1.aspx?kh=" + khoihanh;
    HttpRequest.open("GET",url);
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("result");

           var selectMenu = document.getElementById("ddl_den_vmb");
           selectMenu.options[0] = new Option("Chọn điểm đến", 0);
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var opt_group = document.createElement("optgroup");
               opt_group.label = value;
               opt_group.className='sub1';
               AddChildItem(opt_group,id,khoihanh);
           }
           document.getElementById('ddl_den_vmb').focus();
       }
   }   
   HttpRequest.send(null);
}

function removeall(id)
{
    var sel=document.getElementById(id);
    while (sel.firstChild) {
        sel.removeChild(sel.firstChild);
    }
}


function AddChildItem(optgroup,id,khoihanh)
{
    var HttpRequest1 = false;

    if (window.XMLHttpRequest) // Internet Explorer
    {
        HttpRequest1 = new XMLHttpRequest();
    }
    else  // Other browsers  
    {
        HttpRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (!HttpRequest1) return;
    var url = "/diemdenvmb2.aspx?kv=" + id + "&kh="+khoihanh;
    HttpRequest1.open("GET",url);
    HttpRequest1.onreadystatechange = function()
    {
        if (HttpRequest1.readyState == 4 && HttpRequest1.status == 200)
        {
           var xml = HttpRequest1.responseXML;
           var c = xml.getElementsByTagName("result");

           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var cereal = document.createElement("option");
               cereal.value = id;
               cereal.appendChild(document.createTextNode(value));
               cereal.className='sub';
               optgroup.appendChild(cereal);
           }
           //alert('13123');
           var selectMenu = document.getElementById("ddl_den_vmb");
           selectMenu.appendChild(optgroup);
        }
    }
    HttpRequest1.send(null);
}

function formattext(id)
{
    if(document.getElementById(id))
    {
        var s=document.getElementById(id).options[document.getElementById(id).selectedIndex].text;
        
        return locdau(s);
    }
}
function locdau(str) {  
  str= str.toLowerCase();  
  str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");  
  str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");  
  str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");  
  str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");  
  str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");  
  str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");  
  str= str.replace(/đ/g,"d");  
  str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-"); 
/* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */ 
  str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1- 
  str= str.replace(/^\-+|\-+$/g,"");  
//cắt bỏ ký tự - ở đầu và cuối chuỗi  
  return str;
}


var _first=true;
function showposition(obj)
{
    if(obj!=null)
    {
        var divobj=document.getElementById('timnangcao');
        if(divobj && _first)
        {
            divobj.style.left=(obj.offsetLeft-250)+'px';
            divobj.style.top=(obj.offsetTop + 30)+'px';
            $('#timnangcao').fadeIn("slow");
            _first=false;
        }
        else
        {
            $('#timnangcao').fadeOut("slow"); _first=true;
        }
    }
    return false;
}

function dong()
{
    $('#timnangcao').fadeOut("slow"); _first=true;
    return false;
}

var _first1=true;
function showposition1(obj)
{
    if(obj!=null)
    {
        var divobj=document.getElementById('timtheosao');
        if(divobj && _first1)
        {
            divobj.style.left=obj.offsetLeft+'px';
            divobj.style.top=(obj.offsetTop + 30)+'px';
            $('#timtheosao').fadeIn("slow");
            _first1=false;
        }
        else
        {
            $('#timtheosao').fadeOut("slow"); _first1=true;
        }
    }
    return false;
}
function dong1()
{
    $('#timtheosao').fadeOut("slow"); _first1=true;
    return false;
}



