
var ChildWindow;
// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

window.onunload=CheckWindow;
function GetDate( ddlMonth , ddlDay , pathPrefix )   
{
	//debugger
	if (pathPrefix == null)
		pathPrefix = "";
		
	var currDay = document.getElementById(ddlDay).options[document.getElementById(ddlDay).selectedIndex].value;
	var currMonth = document.getElementById(ddlMonth).options[document.getElementById(ddlMonth).selectedIndex].value;
	
	//Tests IF SearchFlights_dpDeparting_ddlDay Element Exists in Page
	/*var DepartDdlDayID = document.getElementById("SearchFlights_dpDeparting_ddlDay");	
	if( typeof(DepartDdlDayID) != "undefined" && 
	   ( currDay == "-1" && currMonth == "-1" ) )
	{
	    currDay   = document.getElementById("SearchFlights_dpDeparting_ddlDay").options[document.getElementById("SearchFlights_dpDeparting_ddlDay").selectedIndex].value;
	    currMonth = document.getElementById("SearchFlights_dpDeparting_ddlMonth").options[document.getElementById("SearchFlights_dpDeparting_ddlMonth").selectedIndex].value;
	} */  
	var left = Math.min(xMousePos+50,xMousePosMax) + 'px';
	 
	var top = Math.min( yMousePos + 50,yMousePosMax) + 'px' ;
	
	//Just for check
	//left = window.event.x+document.body.scrollLeft + 50 ;
	//top = window.event.y+document.body.scrollTop + 50 ;
	//left += 'px';
	//top += 'px'; 
	
	var url = pathPrefix + 'CalenderModal.aspx?FormName=' + document.forms[0].name + '&DRPMonth=' + ddlMonth + '&DRPDay=' + ddlDay +'&DRPMonthVal=' + currMonth + '&DRPDayVal=' + currDay;
	//dialogLeft:"  + left + " ;dialogTop: " + top + ";
    var styleCmd = "dialogHeight: 200px; dialogWidth: 200px; center: yes; edge: raised; help: 0; resizable: 0; status: 0;scroll: 0;";
	//ChildWindow = window.showModalDialog(url, 
	//				this, styleCmd);
	if (document.layers) // Netscape
    {
		ChildWindow = window.open(url, "PopUpCalendar", "width=200,height=175,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no"); 
	}
	else if (document.all) 
	{
		ChildWindow = window.showModalDialog(url, this, styleCmd);
		//ChildWindow = window.open(url, "PopUpCalendar", "width=200,height=175,top=200,left=200,toolbars=no,scrollbars=yes,status=no,resizable=yes,location=yes");
	}
	else if (document.getElementById) // Netcsape 6
	{	
		ChildWindow = window.open(url, "PopUpCalendar", "width=200,height=165,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no"); 
	}
	
}

function CheckWindow()  
{ 
	if( ChildWindow + "" != "undefined")
		ChildWindow.close();
}
// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}


function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        
        //Use latter
        //xMousePos = window.event.x+document.body.scrollLeft;
        //yMousePos = window.event.y+document.body.scrollTop;
       // xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
       // yMousePosMax = document.body.clientHeight+document.body.scrollTop;
       //Use latter end
       
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

