﻿// JScript File
function LoadIndex(target)
{
	//alert(req.responseText);	
	window.location = "default.aspx";
}

function MainCallback(divid)
{
	
	document.getElementById(divid).innerHTML = req.responseText;
}

function MenuCallback(divid)
{
	document.getElementById('submenu').innerHTML =  req.responseText;
	AjaxRequest('menu=' + divid,'Ajax.aspx','','MainCallback','main');
}

function ParentCallback(divid)
{
	//alert(req.responseText); alert(divid);
//	if(divid == 'a_Img' || divid == 'b_Img')
//	{
//		parent.document.getElementById('imgForm0').src = '/etc/images/empty_pixle.gif';
//	}
//	else
//	{
//		parent.document.getElementById('imgForm1').src = '/etc/images/empty_pixle.gif';
//	}
//	parent.document.getElementById(divid).style.display = 'block';
	parent.document.getElementById(divid).innerHTML =  req.responseText;
}
function SubParentCallback(divid)
{
    parent.document.getElementById(divid).innerHTML =  req.responseText;
    
}
function MediaCallback(divid)
{
	//alert(req.responseText);	
	document.getElementById(divid).innerHTML = '<br><br><br>n/a';
}

function BoxSwitch(item, val1, val2)
{
	if(item.checked == true)
	{
		item.value = val1;
	}
	else
	{
		item.value = val2;
	}
}




//**************************************** POLL ****************************************
function Callback(divid)
{
	document.getElementById(divid).style.display = 'block';	
	document.getElementById(divid).innerHTML = req.responseText;
}

function Switch(item, val1, val2)
{
	if(item.checked == true)
	{
		item.value = val1;
	}
	else
	{
		item.value = val2;
	}
}

function ViewFlight(IdOrder)
{
    document.getElementById('ViewChiTietVe').innerHTML =  "<img src='images/ajax-loader.gif' align='absmiddle'>";
    AjaxRequest('id='+ IdOrder,'Flight-ViewDetail.aspx','&act=locktopic','MainCallback','ViewChiTietVe');
}

function Search_Flight()
{
    document.getElementById('View_Search_Flight').innerHTML =  "<img src='../../images/ajax-loader.gif' align='absmiddle'>";
    var postdata;
    var show= document.getElementById("ShowLast").value;
    var a_search= document.getElementById("a_search").value;
    var b_search= document.getElementById("b_search").value;
    var cat_filter= document.getElementById("cat_filter").value;
    var tinhtrang= document.getElementById("tinhtrang").value;
    postdata="show="+ show +"&HK="+ a_search + "&TV="+ b_search +"&Hang="+ cat_filter +"&TinhTrang="+ tinhtrang;
    
    AjaxRequest(postdata,'Flight-ViewDetail.aspx','&act=locktopic','MainCallback','View_Search_Flight');
}
function ViewFlightAdmin(IdOrder,divid)
{
    document.getElementById(divid).innerHTML =  "<img src='../../images/ajax-loader.gif' align='absmiddle'>";
    AjaxRequest('id='+ IdOrder,'Flight-ViewInfo.aspx','&act=locktopic','MainCallback',divid);

}
function UpdateStatus_Flight(IdOrder,idselect)
{
   var postdata;
   postdata="IDOrder="+ IdOrder +"&Chon="+ idselect;
   AjaxRequest(postdata,'Flight-Update.aspx','&act=UpdateStatus','CallBack_Flight','aaa');
}
function ChuyenKhoan_Flight(IdOrder)
{
    var postdata;
    var sok= document.getElementById("SoK").value;
    var rdgd =document.getElementById("Radio1");
    var value;
    if(rdgd.checked)
    {
    value=1;
    }
    else
    {
    value=0;
    }
    
    if(sok=="0" || sok=="")
    {
        alert("Nhập số K cần chuyển");
        return;
    }
    var ND= document.getElementById("txtnoidung").value;
     postdata="IDOrder="+ IdOrder +"&SoK="+ sok +"&ND="+ ND +"&value="+ value;
    AjaxRequest(postdata,'Flight-Update.aspx','&act=ChuyenKhoan','CallBack_Flight','aaa');
}
function AddNew_HangMayBay()
{
    var postdata;
    var txttenhang= document.getElementById("txttenhang").value;
    if (txttenhang=="")
    {
         alert("Nhập tên hãng máy bay");
        return;
    }
    postdata="tenhang="+ txttenhang ;
    AjaxRequest(postdata,'Flight-Update.aspx','&act=AddNewHang','View_HangMayBay','View_HangMayBay');
}
function DelHangMayBay(id)
{
    var answer = confirm ("Bạn có chắc chắn xóa hãng máy bay này không? (id=" + id + ')')
	if (answer)
    {
        var postdata = 'id=' + id ;
        AjaxRequest(postdata,'Flight-Update.aspx','&act=DeleteHang','View_HangMayBay','View_HangMayBay');
    }
}
function View_HangMayBay(divid)
{
     document.getElementById(divid).innerHTML =  "<img src='../../images/ajax-loader.gif' align='absmiddle'>";
   
      AjaxRequest('','Flights-Hang.aspx','&act=locktopic','MainCallback',divid);

}
function CallBack_Flight(divid)
{
    var text = req.responseText;
    alert(text);
}
function ViewChuyenBay()
{
     var postdata;
    var cboHang= document.getElementById("ctl00$ContentPlaceHolder1$DropDownList3").value;
    var cboTinhDen= document.getElementById("ctl00$ContentPlaceHolder1$DropDownList2").value;
    var cboTinhTu= document.getElementById("ctl00$ContentPlaceHolder1$DropDownList1").value;
   
    if (cboHang=="" || cboTinhDen=="" || cboTinhTu=="")
    {
        alert("Xin vui long chon chuyen bay");
        return;
    }
    postdata="Hang="+ cboHang +"&TinhTu="+cboTinhTu+"&TinhDen="+ cboTinhDen;
    document.getElementById("ViewChuyenBay").innerHTML =  "<img src='../../images/ajax-loader.gif' align='absmiddle'>";
   AjaxRequest(postdata,'Flights-ViewChuyenBay.aspx','&act=locktopic','MainCallback',"ViewChuyenBay");

    
  
}
function AddNewFlight()
{
    
    showPopWin('Flights-AddNew.aspx', 450, 450, '');
}
function EditChuyenBay(id)
{
    var link="Flights-Edit.aspx?id="+ id;   
    
    showPopWin(link, 450, 450, '');
}

function validate(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry!  Only numbers are accepted!");
//field.focus();
field.select();
   }
}
function CheckEmail(field) {
var ok = "yes";
if (field.value=="")
{
    alert("Please enter your Email");
    var ok = "no";
}
if (field.value!="")
{
    txt= field.value
    if (txt.indexOf("@")<3)
	{
		alert("I'm sorry. This email address seems wrong")
		 var ok = "no"
	}
    
}
if (ok == "no") {
//field.focus();
field.select();
   }
   
}
function LockTopic(id)
{
    AjaxRequest('id='+ id,'../Ajax/XulyCapnhat.aspx','&act=locktopic','ActionCallBack','1');
}
function DelMess(id,userid)
{
    
    AjaxRequest('id='+ id +'&userid='+ userid,'../Ajax/XulyCapnhat.aspx','&act=DelMess','ActionCallBack','2');
}
function EditMess(mess,topic,forum)
{
    var link="EditMessage.aspx?mess="+ mess +"&forum="+ forum +"&topic="+ topic;
    window.location = link;
}
function ActionCallBack(divid)
{
    var OK=req.responseText;
    if (OK=="OK") 
    {
         switch (divid)
      {
        case "1": { alert("Chu de nay da duoc khoa"); break }
        
        case "2": {alert("Bai viet nay da duoc xoa"); break}
        default: {break }
      }
      
    }
    else
    {
        alert(OK);
    }
    
}

//**************************************** mr.hai: 0907 868 893 ****************************************

//divid - index view
// Protype - idloai sp
// page - begin page
// noofpages - Sum sp view

function ViewProducts_Home(divid,ProType,page,noOfPages)   
{
    var postdata;
   postdata="ProType="+ ProType + "&p="+ page +"&div="+ divid +"&noOfPages="+ noOfPages;
   document.getElementById(divid).innerHTML =  "<img src='images/ajax-loader.gif' align='absmiddle'>";
   AjaxRequest(postdata,'data.aspx','&act=locktopic','MainCallback',divid);

}

