//**************************************************
var xmlHttp_Nav
var xmlHttp_ST
var xmlHttp_ED
//
function AjCalReset(LangID) {//Reset Cal of ST, obj=ST/ED, LangID=language
	DtIntiST = document.getElementById("DtIntiST").value
	DtIntiED = document.getElementById("DtIntiED").value
	DtThisTP = document.getElementById("DtThisTP").value
	DtST = AjCal_GetDate('ST')
	DtED = AjCal_GetDate('ED')
    //*** ST Start **********************
    if ( DtThisTP=='ST' ) { 
	    //---1a. For droplist use only
		xmlHttp_ST =GetXmlHttpObject()
		if (xmlHttp_ST==null){
			alert ("Browser does not support HTTP Request")
			return
		}
		var url ="/_includes/CalendarAj/CalendarPopup.asp"
		url =url+"?Date="+DtST
		url =url+"&LangID="+LangID
		url =url+"&sid="+Math.random()
		xmlHttp_ST.onreadystatechange = stateChangedDateStart_ST
		xmlHttp_ST.open("GET",url,true)
		xmlHttp_ST.send(null)
		
	    //---1b. For droplist and nav use
		xmlHttp_ED =GetXmlHttpObject()
		if (xmlHttp_ED==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url ="/_includes/CalendarAj/CalendarPopup.asp"
		url =url+"?Date="+DtED
		url =url+"&LangID="+LangID
		url =url+"&sid="+Math.random()
		xmlHttp_ED.onreadystatechange = stateChangedDateStart_ED
		xmlHttp_ED.open("GET",url,true)
		xmlHttp_ED.send(null)
	}	
    //*** ST End **************************
	
    //*** ED Start *************************
    if ( DtThisTP=='ED' ) {
	    //---2a. For droplist use only
		xmlHttp_ST =GetXmlHttpObject()
		if (xmlHttp_ST==null){
			alert ("Browser does not support HTTP Request")
			return
		}
		var url ="/_includes/CalendarAj/CalendarPopup.asp"
		url =url+"?Date="+DtST
		url =url+"&LangID="+LangID
		url =url+"&sid="+Math.random()
		xmlHttp_ST.onreadystatechange = stateChangedDateStart_ST
		xmlHttp_ST.open("GET",url,true)
		xmlHttp_ST.send(null)	
		
	    //--2b. For droplist and nav use
		xmlHttp_ED =GetXmlHttpObject()
		if (xmlHttp_ED==null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		var url ="/_includes/CalendarAj/CalendarPopup.asp"
		url =url+"?Date="+DtED
		url =url+"&LangID="+LangID
		url =url+"&sid="+Math.random()
		xmlHttp_ED.onreadystatechange = stateChangedDateStart_ED
		xmlHttp_ED.open("GET",url,true)
		xmlHttp_ED.send(null)		
	}
    //*** ED Start ************************
}
function stateChangedDateStart_ST() {
	DtIntiST = document.getElementById("DtIntiST").value
    if (xmlHttp_ST.readyState==4 || xmlHttp_ST.readyState=="complete") { 
        document.getElementById(DtIntiST+'_CalCell').innerHTML = xmlHttp_ST.responseText 
    } 
}
function stateChangedDateStart_ED() {
	DtIntiED = document.getElementById("DtIntiED").value
    if (xmlHttp_ED.readyState==4 || xmlHttp_ED.readyState=="complete") { 
        document.getElementById(DtIntiED+'_CalCell').innerHTML = xmlHttp_ED.responseText 
    } 
}
//*************************************************************
function AjCalNav(obj,obj2) {
    xmlHttp_Nav =GetXmlHttpObject()
    if (xmlHttp_Nav==null) {
        alert ("Browser does not support HTTP Request")
        return
    } 
    var url ="/_includes/CalendarAj/CalendarPopup.asp"
    url =url+"?Date="+obj
    url =url+"&sid="+Math.random()
	url =url+"&LangID="+obj2
    xmlHttp_Nav.onreadystatechange = stateChangedDateStart
    xmlHttp_Nav.open("GET",url,true)
    xmlHttp_Nav.send(null)
} 
function stateChangedDateStart() {
	DtIntiST = document.getElementById("DtIntiST").value
	DtIntiED = document.getElementById("DtIntiED").value
	DtThisTP = document.getElementById("DtThisTP").value
    if (DtThisTP=='ST') { STED = document.getElementById("DtIntiST").value }
    if (DtThisTP=='ED') { STED = document.getElementById("DtIntiED").value }
	
    if (xmlHttp_Nav.readyState==4 || xmlHttp_Nav.readyState=="complete") { 
        document.getElementById(STED+'_CalCell').innerHTML = xmlHttp_Nav.responseText 
    } 
}//

function GetXmlHttpObject()
{ 
    var objXMLHttp =null
    if (window.XMLHttpRequest){
        objXMLHttp =new XMLHttpRequest()
    }
    else if (window.ActiveXObject){
        objXMLHttp =new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}
function DaysDiff(Dt1, Dt2) { //Dt1/Dt2 = '1/1/2007'
    var mmm = 1000*60 *60*24
	Dt1 = new Date(Dt1)
	Dt2 = new Date(Dt2)	
    m1 = parseInt(Dt1.getMonth())
	d1 = Dt1.getDate()
	y1 = Dt1.getFullYear()
    m2 = parseInt(Dt2.getMonth())
	d2 = Dt2.getDate()
	y2 = Dt2.getFullYear()
	t1 = Date.UTC(y1, m1, d1)
	t2 = Date.UTC(y2, m2, d2)
	Diff = Math.round((t2-t1)/mmm)
    return(Diff)
}


function AjAddDays(d) { //Shift Checkout date 2 days forward when elected, only for Start date
	DtIntiST = document.getElementById("DtIntiST").value
	DtIntiED = document.getElementById("DtIntiED").value
	DtThisTP = document.getElementById("DtThisTP").value
	DtST = AjCal_GetDate('ST')
	DtED = AjCal_GetDate('ED')
	//alert (langType)
	RealAdded = d
	Diff = DaysDiff(DtST, DtED)
	if ( DtThisTP=='ST' || ( DtThisTP=='ED' && Diff<=0 ) ) { //Triger only when ST or ED/earlier
		if ( DtThisTP=='ED' && Diff<=0 ) { 
			alert("Sorry, the check out date should be later than check in date.")
			RealAdded = 1
        }
		
		DtST = new Date(DtST)
		m1 = DtST.getMonth()
		d1 = DtST.getDate()
		y1 = DtST.getFullYear()
		Dt2 = new Date(y1, m1, parseInt(d1)+parseInt(RealAdded) )
		m2 = Dt2.getMonth()+1
		d2 = Dt2.getDate()
		y2 = Dt2.getFullYear()
		document.getElementById(STED+'Date').value = m2 +'/'+ d2 +'/'+ y2 
	}
}
//****************************************************************
