var bgActiveColor="#FFFDD7";
var bgNormalColor="#FFFFFF";
var objActive;
var BURL = window.location.href;
function Zaehlen () {
	// 1 sec = 1000
	//window.open(BURL,"_self");
	window.location.reload ();
	aktiv = window.setTimeout("Zaehlen()", 300000);
}
function ClearTime () {
	window.clearTimeout(aktiv);
	aktiv = window.setTimeout("Zaehlen()", 300000);
}
aktiv = window.setTimeout("Zaehlen()", 300000);
window.ClearTime();
function setSelectSearch(obj) { if (obj.type!="select-one") { obj.select(); } obj.style.background=bgActiveColor;}
function setBgNormal(obj) { obj.style.background=bgNormalColor; }
function SetFocus(){   document.form1.txtqDocID.focus();  }
function LoadObj(str){return(document.getElementById(str));}
function showSearch(){
	imS = LoadObj('imgSearch');
	if(imS.src.indexOf('ico_search_act')!=-1){
		imS.src="images/ico_search.gif";
		LoadObj('TbSearch').style.display="none";
	}else{
		imS.src="images/ico_search_act.gif";
		LoadObj('TbSearch').style.display="";
	}
}
function setCboCompareDate() {
        var objCompare = document.form1.cboqDatecd;
        //disable text ###############################
        document.getElementById("lyDateSearch1").style.display="none";
        document.getElementById("lyDateSearch2").style.display="none";
        switch (objCompare.value) {
        //user only value1 ###################################
        case "ATDATE" :
        case "LESS" :
        case "LESSEQUAL" :
        case "MORE" :
        case "MOREEQUAL" :
                document.getElementById("lyDateSearch1").style.display="";
        break;
        //user both value1 and value2 ########################
        case "BETWEEN" :
                document.getElementById("lyDateSearch1").style.display="";
                document.getElementById("lyDateSearch2").style.display="";
        break;
        }
}
function setCboCompareNumber() {
	var objCompare = document.form1.cboqNumcd;
	//disable text ###############################
	document.getElementById("lyNumberSearch1").style.display="none";
	document.getElementById("lyNumberSearch2").style.display="none";

	switch (objCompare.value) {
		//user only value1 ###################################
		case "EQUAL" :
		case "LESS" :
		case "LESSEQUAL" :
		case "MORE" :
		case "MOREEQUAL" :
			document.getElementById("lyNumberSearch1").style.display="";
			break;
		case "BETWEEN" :
			document.getElementById("lyNumberSearch1").style.display="";
			document.getElementById("lyNumberSearch2").style.display="";
			break;
	}
}
function ChangeStatus(DocID, fixStatus){
	var Status = $('ly'+DocID).getAttribute('propStatus');
	var ConfirmNo = $('ly'+DocID).getAttribute('propConfirmNo');
	var SP2 = $('ly'+DocID).getAttribute('propSP2');
	var spCXL = $('ly'+DocID).getAttribute('propspCXL');
	var Mode = 1;
	var Search = 0;

	if(Status=="RSVN"){ Status="RESERVED";}

	if (spCXL == '1')
	{
		window.open("UpdateStatusHC.php?status="+Status+"&mode="+Mode+"&DocID="+DocID+"&file="+ConfirmNo+"&fStatus="+fixStatus+"&s="+Search+"&SP2="+SP2+"&"+(+new Date()),"wStatus");
	} else {
		switch(fixStatus){
			case"CONF":
			case"AMENDCONF":
				window.open("UpdateStatusHB.php?status="+Status+"&mode="+Mode+"&DocID="+DocID+"&file="+ConfirmNo+"&fStatus="+fixStatus+"&s="+Search+"&SP2="+SP2+"&"+(+new Date()),"wStatus");
				break;
			default:
				window.open("UpdateStatusHB.php?status="+Status+"&mode="+Mode+"&DocID="+DocID+"&file="+ConfirmNo+"&fStatus="+fixStatus+"&s="+Search+"&SP2="+SP2+"&"+(+new Date()),"wStatus");
				break;
		}
	}
}
function waiting(DocID,status){
	window.open("waiting.php?DateTime=" + (+new Date())+"&docid="+DocID+"&status="+status,"wWaiting");
}
function JumpToVoucher(DocID){
	window.open("rptVoucher.php?DocID="+DocID+"&"+ (+new Date()), "_blank", "left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800);
}
function JumpToDetail(DocID,Status,doctype){
    if(doctype=="HB"){
        window.open("rptHBooking.php?DocID="+DocID+"&Status="+Status,"_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800); }
    else if(doctype=="AHB"){
        window.open("rptAHBooking.php?DocID="+DocID+"&Status="+Status,"_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800);   }
    else {
        window.open("rptCHBooking.php?DocID="+DocID+"&Status="+Status,"_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800);  }
    }
function Msg(DocID){
    window.open("MsgMercury.php?DocID="+DocID,"_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800);
    window.location.reload();}
function Allotment(ServiceNo,Status){
    window.WAllotment.open("AcceptAllotment.php?ServiceNo="+ServiceNo+"&s="+Status,"_self"); }
function LoadCbo(obj){
	DocType=document.form1.cboqDocType.value;
	window.open("LoadcboStatus.php?DocType="+DocType,"LoadStatus");
}
function OpendReport(){   window.open("rptHBsmy.php","_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800); }
function OpendReport1(){   window.open("rptArrivaldate.php","_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800); }
function OpendReport2(){   window.open("rMakeToDay.php","_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800); }
function SendEmailConfirm(Status,DocID,ConfirmNo,Mode,fixStatus){
    objDate = new Date();
    if(Status=="CONF")
	{
		window.open("HBookingSendmail.php?Status="+Status+"&DocID="+DocID+"&"+ (+new Date()),"wSpecial");
	}
    else if(Status=="AMENDCONF")
	{
		window.open("AHBookingSendmail.php?Status="+Status+"&DocID="+DocID+"&"+ (+new Date()),"wSpecial");
	} else {
		window.open("CHBookingSendmail.php?Status="+Status+"&DocID="+DocID+"&"+ (+new Date()),"wSpecial");
	}
}//SendEmailConfirm


function getXMLHTTPRequest() {
	try {req = new XMLHttpRequest();}
		catch(err1) {  try {req = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (err2) { try {req = new ActiveXObject("Microsoft.XMLHTTP");}
		catch (err3) {req = false;}
	  }
	}
	return req;
}

function $ (str){return document.getElementById(str);}
function Neptune () {
	this.LoadListStatus = function (){
		/*
		var myurl = "Func/LoadListStatus.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			//$("lyListStatus").innerHTML = mytext;
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send("Code="+this.Code+"&"+(+new Date()));
		*/
	};

	this.LoadStatus = function (StatusValue, Mode){
		$('lyLoadStatus').innerHTML = '<img src="../b2b/images/sLoad.gif">';
		var myurl = "Func/LoadStatus.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			$("lyLoadStatus").innerHTML = mytext;
			if (JB.SPrice)
			{
				var elm = $("lyLoadStatus").getElementsByTagName("span");
				for (var i=0; i<elm.length; i++)
				{
					if (elm[i].getAttribute("SPrice")=="1")
					{
						setTimeout("JB.getCostByServiceNo('"+elm[i].getAttribute("ServiceNo")+"');", 50);
					}
				}
			}
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send("Code="+this.Code+"&Mode="+Mode+"&StatusValue="+StatusValue+"&"+(+new Date()));
	};

	this.Search = function (){
		param = "pSupplierCode="+this.Code;
		param += "&Mode=Search";
		param += "&pFileNo=" + $("txtqFileNo").value;
		param += "&pDocID=" + $("txtqDocID").value;
		param += "&pVoucherNo=" + $("txtqVoucherNo").value;
		param += "&pDocType=" + $("cboqDocType").value;
		param += "&pStatus=" + $("cboqStatus").value;
		param += "&pCode=" + $("cboqCode").value;
		param += "&pGuestName=" + $("txtqGuestName").value;
		param += "&pSearchDate=" + $("cboqSearchDate").value;
		param += "&pFromDate=" + $("txtqsfromdate").value;
		param += "&pDatecd=" + $("cboqDatecd").value;
		param += "&pToDate=" + $("txtqstodate").value;
		param += "&pSearchNum=" + $("cboqSearchnum").value;
		param += "&pFromPrice=" + $("txtqfromprice").value;
		param += "&pNumcd=" + $("cboqNumcd").value;
		param += "&pToPrice=" + $("txtqtoprice").value;

		var myurl = "Func/LoadSearch.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			$("lyLoadStatus").innerHTML = mytext;
			if($("lyLoadStatus").innerHTML){
				var elm = $("lyLoadStatus").getElementsByTagName("span");
				for (var i=0; i<elm.length; i++)
				{
					if (elm[i].getAttribute("SPrice")=="1")
					{
						setTimeout("JB.getCostByServiceNo('"+elm[i].getAttribute("ServiceNo")+"');", 50);
					}
				}
			}
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+(+new Date()));
	};

	this.getDocumentDetail = function (myurl, DocID, Status){
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			$("lyDetail").innerHTML = mytext;
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send("DocID="+DocID+"&Status="+Status+"&"+(+new Date()));
	};

	this.Login = function (){
		if (!this.LoginMode)this.LoginMode = 1;

		var param = "Mode="+this.LoginMode;
		param += "&SupplierID="+$("txtSupplierID").value;
		param += "&UserName="+$("txtUserName").value;
		param += "&Password="+$("txtPassword").value;
		var myurl = "Func/Login/Login.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			$("result-login").innerHTML = mytext;
			if ($("txt-result-login") && $("txt-result-login").value!="") {
				if($("txt-result-login").value=="Y"){
					window.open("../newNeptune/Master.php", "_self");
				}
				else if($("txt-result-login-group") && ($("txt-result-login-group").value=="SUPPLIER" || $("txt-result-login-group").value=="ACCOM")){
					window.open("../Neptune/Neptune.php", "_self");
				}
				else {
					window.open("../newNeptune/Neptune.php", "_self");
				}
			}else{ alert("username or password invalid");}
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+(+new Date()));
	};

	this.MasterLoadList = function (){
		var param = "Mode=MasterLoadList";
		var myurl = "Func/Master/Master.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			$("lyMaster").innerHTML = mytext;
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+(+new Date()));
	};

	this.MastergetProfile = function (Code){
		var param = "Mode=MastergetProfile";
		param += "&Code="+Code;
		var myurl = "Func/Master/Master.php";
		var http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseText;
			window.open ("Neptune.php?"+(+new Date()), "wDetail");
		};
		http.open("POST", myurl, true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(param+"&"+(+new Date()));
	};

}
var JB = new Neptune () ;
JB.getCostByServiceNo = function (ServiceNo){
	var param = "ServiceNo="+ServiceNo;
	var myurl = "Func/LoadCostByServiceNo.php";
	var http = new getXMLHTTPRequest();
	http.onreadystatechange = function() {if (http.readyState != 4) { return; }
		var myprice = eval("("+http.responseText+")");

		n=myprice.length;
		i=0;
		while(i<n){
			i++;
			//$("s-"+ServiceNo+"-"+i).innerHTML = jNumberFormat(myprice[i-1][0]+myprice[i-1][1]+myprice[i-1][2], 2) + " " + myprice[i-1][3];
			$("s-"+ServiceNo+"-"+i).innerHTML = (myprice[i-1][0]+myprice[i-1][1]+myprice[i-1][2]) + " " + myprice[i-1][3];
			if(i>1){
				$("s-"+ServiceNo+"-"+i).innerHTML="<br>"+$("s-"+ServiceNo+"-"+i).innerHTML;
			}
			$("s-"+ServiceNo+"-"+i).setAttribute("xroom", myprice[i-1][0]);
			$("s-"+ServiceNo+"-"+i).setAttribute("xcompulsory", myprice[i-1][1]);
			$("s-"+ServiceNo+"-"+i).setAttribute("xsupplement", myprice[i-1][2]);
			$("s-"+ServiceNo+"-"+i).setAttribute("xcurrency", myprice[i-1][3]);
		}
	};
	http.open("POST", myurl, true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http.send(param+"&"+(+new Date()));
}

JB.popcostshow = function(obj){
	var room = parseFloat(obj.getAttribute("xroom"));
	var compulsory = parseFloat(obj.getAttribute("xcompulsory"));
	var supplement = parseFloat(obj.getAttribute("xsupplement"));
	var headname = "";
	switch (obj.getAttribute("xroomtype"))
	{
		case "SGL":headname = "Single ";break;
		case "TW":headname = "Twin ";break;
		case "DBL":headname = "Double ";break;
		case "TPL":headname = "Triple ";break;
		case "TPL":headname = "Triple ";break;
		case "TPLC":headname = "Triple Child ";break;
		case "QUAD":headname = "Quad ";break;
	}
	headname += obj.getAttribute("xnight") + " Nights";
	$("lypopcost-head").innerHTML = headname;
	$("lypopcost-room").innerHTML = jNumberFormat(room, 2) + " " + obj.getAttribute("xcurrency");
	$("lypopcost-compulsory").innerHTML = jNumberFormat(compulsory, 2) + " " + obj.getAttribute("xcurrency");
	$("lypopcost-supplement").innerHTML = jNumberFormat(supplement, 2) + " " + obj.getAttribute("xcurrency");
	$("lypopcost-total").innerHTML = jNumberFormat(room+compulsory+supplement, 2) + " " + obj.getAttribute("xcurrency");
	$("lypopcost").style.top = Calendar.getAbsolutePos (obj).y - 115+"px";
	$("lypopcost").style.left = Calendar.getAbsolutePos (obj).x + 5+"px";
	$("lypopcost").style.visibility = "";
}

JB.popcosthide = function(){
	$("lypopcost").style.visibility = "hidden";
}

JB.onloadpage = function(){
	JB.LoadListStatus ();
	JB.LoadStatus (sStatus, "1");
}

function OpendDetail (DocID, Status){
	var strFileName = "Func/ChangeRate/index.php?DocID="+DocID+"&Status="+Status+"&"+(+new Date());
	window.open(strFileName, "_blank", "left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + 900 + ",height=" + 800);
}

function OpenReport(){
	imS = LoadObj("imgReport");
	if(imS.src.indexOf('ico_search_act')!=-1){
		imS.src="images/ico_search.gif";
		LoadObj('lyReport').style.display="none";
	}else{
		imS.src="images/ico_search_act.gif";
		LoadObj('lyReport').style.display="";
	}
}

function GotoReport(strType){
	var strFileName;
	switch(strType){
		case "ArrivalbyDate":
			strFileName="../Report/RSVN/ArrivalbyDateReportSearch.php";
		break;
		case "ArrivalbyHotel":
			strFileName="../Report/RSVN/ArrivalByHotelReportSearch.php";
		break;
		case "DeparturebyDate":
			strFileName="../Report/RSVN/DepartureByDateReportSearch.php";
		break;
		case "DeparturebyHotel":
			strFileName="../Report/RSVN/DepartureByHotelReportSearch.php";
		break;
		case "Cancellation":
			strFileName="../Report/RSVN/CancellationReportSearch.php";
		break;
		case "HotelBookingSummary":
			strFileName="../Report/RSVN/HBookingSmySearch.php";
		break;
		case "VoucherAccomSummary":
			strFileName="../Report/RSVN/VoucherAccomSmySearch.php";
		break;
		case "CreditorInvoiceCosting":
			strFileName="../Report/Account/CreditorInvoiceCostingSearch.php";
		break;
	}
	strFileName += "?Code="+JB.Code+"&GroupCode="+JB.GroupCode+"&"+(+new Date());
	window.open(strFileName,"_blank","left=0,top=0,status=no,scrollbars=yes,resizable=yes,width=" + (screen.width-10) + ",height=" + (screen.height-50));
}
function refreshNeptune(){
	window.open("Neptune.php?"+(+new Date()),"_self");
}
