﻿
var HttpRequest = false;

if (window.XMLHttpRequest) // Internet Explorer
{
    HttpRequest = new XMLHttpRequest();
}
else  // Other browsers  
{
    HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}


/// <summary>
///Lấy dữ liệu về thư mục bài viết từ server rồi đưa vào dropdown
/// </summary>
function getDiemDen(khoihanh)
{
    //resetDiemDen();
    
    if (!HttpRequest) return;
    if (khoihanh < 1) return;
    var loaitour;
    if($('rdnuocngoai').checked)
    {
        loaitour=1; //1 la nuoc ngoai
    }
    else if($('rdtrongnuoc').checked)
    {
        loaitour=2; //2 la trong nuoc
    }

    var url = "/AjaxServer.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");

           $('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;
               $('ddldiemden').options[i] = new Option(value, id);
           }
           
           $('ddldiemden').disabled = false;
           $('ddldiemden').focus();             
       }
   }   
   HttpRequest.send(null);
}

function getDateOut(tourid)
{
    //resetDiemDen();
    
    if (!HttpRequest) return;
    
    var url = "/getdayout.aspx?tourid=" + tourid;
    HttpRequest.open("GET",url);
    //alert(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("date");                      
           $('ctl00_ContentPlaceHolder1_cbngaydi').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;
               $('ctl00_ContentPlaceHolder1_cbngaydi').options[i] = new Option(value, id);
               
           }
           if(c.length==0)
                $('ctl00_ContentPlaceHolder1_cbngaydi').disabled = true;
           else
           {        
                $('ctl00_ContentPlaceHolder1_cbngaydi').disabled = false;
                $('ctl00_ContentPlaceHolder1_cbngaydi').focus();
           }
       }
   }
   
   HttpRequest.send(null);
}

function getDateIn(tourid)
{
    //resetDiemDen();
    
    if (!HttpRequest) return;
    
    var url = "/getdayin.aspx?tourid=" + tourid;
    HttpRequest.open("GET",url);
    //alert(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("date");                      
           $('ctl00_ContentPlaceHolder1_cbngaydi').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;
               $('ctl00_ContentPlaceHolder1_cbngaydi').options[i] = new Option(value, id);
               
           }
           if(c.length==0)
           {     $('ctl00_ContentPlaceHolder1_cbngaydi').disabled = true;   }
           else
           {                
                $('ctl00_ContentPlaceHolder1_cbngaydi').disabled = false;
                $('ctl00_ContentPlaceHolder1_cbngaydi').focus();
           }
       }
   }
   
   HttpRequest.send(null);
}

function dangky_nhantin(email)
{
    if (!HttpRequest) return;
    
    var url = "/nhantin.aspx?email=" + email;
    HttpRequest.open("GET",url);
    //alert(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("result");  
           var value  = c[0].firstChild.nodeValue;
           var id = c[0].attributes[0].value;
           if(value=="Thành công")
           {
                alert('Đăng ký nhận thông tin thành công');
           }
           else
           {
                alert('Đăng ký nhận thông tin không thành công');
           }
       }
   }
   
   HttpRequest.send(null);
}

function viewMark2(ikl)
{
    
    if (!HttpRequest) return;
    
    var url = "/xemdiem2.aspx?ikl=" + ikl;
    HttpRequest.open("GET",url);
    //alert(url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           //alert(url);
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("mark");
           var value  = c[0].firstChild.nodeValue;
           
           if(value!='NotExits')
           {
               var result = value.split(';');
               
               $('txtrhoten').value = result[0];
               $('txtrmaso').value = result[1];
               $('txtrdiem').value = result[2];
               $('dangnhap').style.display = 'none';
               $('diem').style.display = 'block';
           }
           else
           {
               alert('Thông tin khách hàng này không tồn tại. Vui lòng nhập thông tin khác.');               
           }
       }
   }
   
   HttpRequest.send(null);
}

function viewMark1(name,phone,cmnd)
{
    
    if (!HttpRequest) return;
    
    var url = "/xemdiem1.aspx?name=" + name + "&phone=" + phone + "&cmnd=" + cmnd;
    HttpRequest.open("GET",url);
    //alert(url);
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           //alert(url);
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("mark");
           var value  = c[0].firstChild.nodeValue;
           //alert(value);
           if(value!='NotExits')
           {
               var result = value.split(';');
               
               $('txtrhoten').value = result[0];
               $('txtrmaso').value = result[1];
               $('txtrdiem').value = result[2];
               $('dangnhap').style.display = 'none';
               $('diem').style.display = 'block';
           }
           else
           {
               alert('Thông tin khách hàng này không tồn tại. Vui lòng nhập thông tin khác.');               
           }
       }
   }
   
   HttpRequest.send(null);
}

function sendcontact(name,email,tour,content)
{
    if(!(name!=''&&email!=''&&tour!=''&&content!='')) return;    
    if (!HttpRequest) return;
    
    var url="/nxtour.aspx?name="+name+"&email="+email+"&tour="+tour+"&content="+content;
    HttpRequest.open("GET",url);    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("result");
           var value  = c[0].firstChild.nodeValue;
           
           if(value=='True')
           {               
               alert('Thông tin nhận xét của bạn đã được gửi thành công.');
               $('txthoten').value='';
               $('txtemail').value='';
               $('txtnoidung').value='';
               window.scroll(0,0);
           }
           else
           {
               alert('Thông tin nhận xét chưa được gửi.');               
           }
       }
   }
      
   HttpRequest.send(null);
}

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");                      
           $('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;
               $('ctl00_ContentPlaceHolder1_ddlvungmien').options[i] = new Option(value, id);
               
           }
           if(c.length==1)
           {
                $('ctl00_ContentPlaceHolder1_ddlvungmien').disabled = true;
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;
           }
           else
           {        
                $('ctl00_ContentPlaceHolder1_ddlvungmien').disabled = false;
                $('ctl00_ContentPlaceHolder1_ddlvungmien').focus();
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
                $('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");                      
           $('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;
               $('ctl00_ContentPlaceHolder1_ddlkhachsan').options[i] = new Option(value, id);
               
           }
           if(c.length==1)
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;
           else
           {        
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = false;
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').focus();
           }
       }
   }
   
   HttpRequest.send(null);
}

function gethotel1(cid)
{
    if (!HttpRequest) return;
    var url = "/gethotel1.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");                      
           $('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;
               
               $('ctl00_ContentPlaceHolder1_ddlkhachsan').options[i] = new Option(value, id);
               
           }
           if(c.length==1)
                {$('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = true;}
           else
           {
                $('ctl00_ContentPlaceHolder1_ddlvungmien').disabled = true;
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').disabled = false;
                $('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");
           $('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;
               $('ddltinhthanh').options[i] = new Option(value, id);
               
           }
           if(c.length==0)
                $('ddltinhthanh').disabled = true;
           else
           {        
                $('ddltinhthanh').disabled = false;
                $('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");                      
           $('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;
               $('ctl00_ContentPlaceHolder1_ddltinhthanh').options[i] = new Option(value, id);
               
           }
           if(c.length==0)
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = true;
           else
           {        
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').disabled = false;
                $('ctl00_ContentPlaceHolder1_ddltinhthanh').focus();
                $('ctl00_ContentPlaceHolder1_ddlkhachsan').options.length = 1;
           }
       }
   }
   
   HttpRequest.send(null);
}

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 getTour(type,pid,id)
{
    if (!HttpRequest) return;
    document.getElementById('tourcontainer').innerHTML='';
    var url = "/gettour.aspx?pid="+pid+"&type="+type;
    HttpRequest.open("GET",url);
    //get ten tour gan vao path
    document.getElementById('tourpath').innerHTML ='<a href="/'+(type==1?'du-lich-trong-nuoc/':'du-lich-nuoc-ngoai/')+'" class="catalog1">'+(type==1?'du lịch trong nước':'du lịch nước ngoài')+' >> </a><a href="'+ (type==1?'/tour-trong-nuoc/':'/tour-nuoc-ngoai/') + pid +'/'+RemoveUnicode((document.getElementById(id)?document.getElementById(id).innerHTML:''))+'.html" class="tourname">'+(document.getElementById(id)?document.getElementById(id).innerHTML:'')+'&nbsp;&nbsp;<span style="text-transfrom:lowercase; font-size: 10px; color:blue; font-weight: bold;">(Chi tiết)</span></a>'
    
    if(!(type!=''&&pid!='')) return;
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           var template='<div class="panel" id="panel_ItemStt"><div class="inside"><img src="/images_he/hotimg.gif" style="position: absolute; width: 32px; height: 24px; top: 5px; left:100px; z-index: 100; border: 0px;ItemHot" /><a href="/LinkType/ItemID/ItemNameFormat.html" title=""><img src="ItemImage" alt="ItemName" /></a><h2><a href="/LinkType/ItemID/ItemNameFormat.html" onmouseover="doTooltip(event,\'<strong>ItemName</strong><br><br />Số ngày đi: <strong>ItemSoNgayDi</strong><br />Khởi hành: <strong>ItemKhoiHanh</strong><br />Giá: <strong>ItemGia</strong>\')" onmouseout="hideTip()">ItemName1</a></h2></div></div>';
           var linktype='du-lich-trong-nuoc';
           linktype =(type==1?'du-lich-trong-nuoc':'du-lich-nuoc-ngoai');
           
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('#');
               
               var itemid= info[0];
               var name= info[1];
               var name1= info[2];
               var gia= info[3];
               var khoihanh= info[4];
               var songaydi= info[5];
               var hinh= info[6];
               var ngaytao= info[7];
               var hot= info[8];
               
               var tmp=template;
               tmp = tmp.replace(/LinkType/gi,linktype);
               tmp = tmp.replace(/ItemStt/gi,id);
               tmp = tmp.replace(/ItemID/gi,itemid);
               tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
               tmp = tmp.replace(/ItemName1/gi,name1);
               tmp = tmp.replace(/ItemName/gi,name);
               tmp = tmp.replace(/ItemImage/gi,hinh);
               tmp = tmp.replace(/ItemSoNgayDi/gi,songaydi);
               tmp = tmp.replace(/ItemKhoiHanh/gi,khoihanh);
               tmp = tmp.replace(/ItemGia/gi,gia);
               //tmp = tmp.replace(/ItemNgayTao/gi,ngaytao);
               if(hot=="False")
                    tmp = tmp.replace(/ItemHot/gi,'display:none');
               else
                    tmp = tmp.replace(/ItemHot/gi,'');
               document.getElementById('tourcontainer').innerHTML=document.getElementById('tourcontainer').innerHTML+tmp;
           }
           document.getElementById('tourcontainer').style.left='0px';
           curPanel =1;
       }
   }   
   HttpRequest.send(null);
}

function getTour1()
{
    if (!HttpRequest) return;
    document.getElementById('tourcontainer').innerHTML='';
    var url = "/gettour1.aspx";
    HttpRequest.open("GET",url);
    //get ten tour gan vao path
    document.getElementById('tourpath').innerHTML ='<a href="/du-lich-nuoc-ngoai/" class="catalog1">du lịch nước ngoài >> </a><a href="dm-tour-nuoc-ngoai/19/tour-hoi-cho.html" class="tourname">Tour hội chợ&nbsp;&nbsp;<span style="text-transfrom:lowercase; font-size: 10px; color:blue; font-weight: bold;">(Chi tiết)</span></a>'
    
    HttpRequest.onreadystatechange = function()
    {
        if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
        {
           var xml = HttpRequest.responseXML;
           var c = xml.getElementsByTagName("date");
           var template='<div class="panel" id="panel_ItemStt"><div class="inside"><img src="/images_he/hotimg.gif" style="position: absolute; width: 32px; height: 24px; top: 5px; left:100px; z-index: 100; border: 0px;ItemHot" /><a href="/LinkType/ItemID/ItemNameFormat.html" title=""><img src="ItemImage" alt="ItemName" /></a><h2><a href="/LinkType/ItemID/ItemNameFormat.html" onmouseover="doTooltip(event,\'<strong>ItemName</strong><br><br />Số ngày đi: <strong>ItemSoNgayDi</strong><br />Khởi hành: <strong>ItemKhoiHanh</strong><br />Giá: <strong>ItemGia</strong>\')" onmouseout="hideTip()">ItemName1</a></h2></div></div>';
           var linktype='du-lich-nuoc-ngoai';
           
           for (i = 0; i < c.length; i++)
           {
               var value  = c[i].firstChild.nodeValue;
               var id = c[i].attributes[0].value;
               var info=value.split('#');
               
               var itemid= info[0];
               var name= info[1];
               var name1= info[2];
               var gia= info[3];
               var khoihanh= info[4];
               var songaydi= info[5];
               var hinh= info[6];
               var ngaytao= info[7];
               var hot= info[8];
               
               var tmp=template;
               tmp = tmp.replace(/LinkType/gi,linktype);
               tmp = tmp.replace(/ItemStt/gi,id);
               tmp = tmp.replace(/ItemID/gi,itemid);
               tmp = tmp.replace(/ItemNameFormat/gi,RemoveUnicode(name));
               tmp = tmp.replace(/ItemName1/gi,name1);
               tmp = tmp.replace(/ItemName/gi,name);
               tmp = tmp.replace(/ItemImage/gi,hinh);
               tmp = tmp.replace(/ItemSoNgayDi/gi,songaydi);
               tmp = tmp.replace(/ItemKhoiHanh/gi,khoihanh);
               tmp = tmp.replace(/ItemGia/gi,gia);
               //tmp = tmp.replace(/ItemNgayTao/gi,ngaytao);
               if(hot=="False")
                    tmp = tmp.replace(/ItemHot/gi,'display:none');
               else
                    tmp = tmp.replace(/ItemHot/gi,'');
               document.getElementById('tourcontainer').innerHTML=document.getElementById('tourcontainer').innerHTML+tmp;
           }
           document.getElementById('tourcontainer').style.left='0px';
           curPanel =1;
       }
   }   
   HttpRequest.send(null);
}