/*
	'***************************************************************************
	' Program Name : calendar.js
	' Description  : Javascript code used for invoking the pdi calendar. After
	'				 the user selects a date, the function setDate() is called
	'				 back to set the source controls date.
	'
	'***************************************************************************	
*/

/* rootURL for pdi */
var pdi_rootURL=location.href
var i=pdi_rootURL.indexOf("/pdi/",0)
pdi_rootURL=pdi_rootURL.substr(0,i+4); 

//These globals must be present
var gDate = "";
var gSource = "";
																		/*Cross Browser Compatability Issue*/
if(!window.event && window.captureEvents)
{
  // set up event capturing for mouse events (add or subtract as desired)
  window.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP|Event.ALERT);

  // set window event handlers (add or subtract as desired)
  window.onmousedown = WM_getCursorHandler;
  window.onmousemove = WM_getCursorHandler;
  window.onmouseup = WM_getCursorHandler;
  //window.alert = WM_getCursorHandler;

  // create an object to store the event properties
  window.event = new Object;
}
function WM_getCursorHandler(e)
{
  // set event properties to global vars (add or subtract as desired)
  window.event.clientX = e.pageX;
  window.event.clientY = e.pageY;
  window.event.x = e.layerX;
  window.event.y = e.layerY;
  window.event.screenX = e.screenX;
  window.event.screenY = e.screenY;

  // route the event back to the intended function
  if ( routeEvent(e) == false )
  {
    return false;
  }
  else
  {
    return true;
  }
}
var x,y,nx,ny;

function Click()
{
        x = window.event.x;
        y = window.event.y;
}

/*function Move()
{
        window.status = "X:" + window.event.x + " Y:" + window.event.y;
}*/

function Calc()
{
        nx = (window.event.x - x) / 14;
        ny = (window.event.y - y) / 14;

        nx = nx.toFixed(2);
        ny = ny.toFixed(2);
        ny = (ny - (ny * 2));

        window.alert("Result:\n\nChange in X: " + nx + " s\nChange in Y: " + ny + " mV");
}
																		/*Cross Browser Compatability Issue*/

//Pass the input control to which the date should be applied.
function show_calendar(sSource)
{

	gDate = sSource.value;
	gSource = sSource;
	//showModelessDialog(pdi_rootURL + "/Library/Pickers/calendar/calendar.htm",window,"scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px");
	//showModelessDialog("../../Library/Pickers/calendar/calendar.htm",window,"scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px");
	openCalendar(sSource);
	openCalendar1(sSource, dSource)
}
		
//callback from pop-up calendar
function SetDate(sDate, sSource)
{
	sSource.value = sDate
}

function openCalendar1(sSource, dSource)
{
	var pWidth = 180;
	var pHeight = 165;
	var lastMouseX = event.screenX;
	var lastMouseY = event.screenY;
				 
	//alert('2')
	if (lastMouseX - pWidth < 0) {
		lastMouseX = pWidth;
	}
	if (lastMouseY + pHeight > screen.height) {
		lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
	}
	lastMouseX -= pWidth;
	lastMouseY += 10;
	//sFeatures = "scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px;"
	//sFeatures += "dialogLeft=" + lastMouseX + ";dialogTop=" + lastMouseY;
	//alert('3')
		 
	//gDate = getItemData(sSource)
	gDate = dSource.value;
	gSource = sSource;
	//alert(pdi_rootURL + "/Library/Pickers/calendar/calendar.htm");
	//showModelessDialog(pdi_rootURL + "/Library/Pickers/calendar/calendar.htm",window,sFeatures);
	//showModelessDialog("../../calendars/calendar.htm",window,sFeatures);
	//alert('3')
	sSource.readonly = false;
	//showModalDialog("Library/calendar/calendar.htm",window,sFeatures);
																		/*Cross Browser Compatability Issue*/	
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		sFeatures = "scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px;"
		sFeatures += "dialogLeft=" + lastMouseX + ";dialogTop=" + lastMouseY;
		showModalDialog("library/CALENDAR/calendar.htm",window,sFeatures);
	}
	else
	{
		sFeatures = "scrollbars=no,status=false,left="+lastMouseX+",top="+lastMouseY+",width="+pWidth+",height="+pHeight;
		open('library/CALENDAR/calendar.htm','window', sFeatures);
	}
																		/*Cross Browser Compatability Issue*/
}
function openCalendar(sSource)
{
	var pWidth = 180;
	var pHeight = 165;
	var lastMouseX = event.screenX;
	var lastMouseY = event.screenY;
				 
	//alert('2')
	if (lastMouseX - pWidth < 0) {
		lastMouseX = pWidth;
	}
	if (lastMouseY + pHeight > screen.height) {
		lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
	}
	lastMouseX -= pWidth;
	lastMouseY += 10;
//	sFeatures = "scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px;"
//	sFeatures += "dialogLeft=" + lastMouseX + ";dialogTop=" + lastMouseY;
	//alert('3')
		 
	//gDate = getItemData(sSource)
	gDate = sSource.value;
	gSource = sSource;
	//alert(pdi_rootURL + "/Library/Pickers/calendar/calendar.htm");
	//showModelessDialog(pdi_rootURL + "/Library/Pickers/calendar/calendar.htm",window,sFeatures);
	//showModelessDialog("../../calendars/calendar.htm",window,sFeatures);
	//alert('3')
	//showModalDialog("Library/calendar/calendar.htm",window,sFeatures);
																		/*Cross Browser Compatability Issue*/
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		sFeatures = "scroll:no;help:no;status:no;dialogWidth:165px;dialogHeight:180px;"
		sFeatures += "dialogLeft=" + lastMouseX + ";dialogTop=" + lastMouseY;
		showModalDialog("library/CALENDAR/calendar.htm",window,sFeatures);
	}
	else
	{
		sFeatures = "scrollbars=no,status=false,left="+lastMouseX+",top="+lastMouseY+",width="+pWidth+",height="+pHeight;
		open('library/CALENDAR/calendar.htm','window', sFeatures);
	}
																		/*Cross Browser Compatability Issue*/
}
