function jsDatePicker(szField, szDate, szAction)
{  
  var objform = document.forms[0];  
  var objfield = objform.elements[szField];  
  if(szAction == '1')	//set
  {  
     objfield.value=szDate;  
  }  
  return objfield.value;  
} 

function postIt() { 
	var form = document.inputform; 
	form.submit(); 
}


function confirmdelete()
{
	var form = document.inputform;
	if (window.confirm("Are you sure you want to delete this record?"))
	{
		form.cmd.value='delete';
		form.submit();
	}
}

function confirmDelete() {
    return confirm("Are you sure you want to delete this record?");
}
function getMonthArr() {

	months = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,";
	return months.split(",");
}

function CheckDate(objDate, mandatory, description)
{
	if (!objDate)
		return true;
	var sdate = objDate.value;
	var adate;
	var msg = sdate + ' is not a valid ' + description;
	var time = null;
	
	if (!mandatory && (sdate == '' || sdate == ' '))
		return true;
	
	if (sdate == '' || sdate == ' ')
	{
		alert("Please enter a " + description);
		return false;
	}	
	if (sdate.indexOf("/") != -1)
	{
		adate = sdate.split("/");
	}
	else if (sdate.indexOf("-") != -1)
	{
		adate = sdate.split("-");
	}
	else if (sdate.indexOf(" ") != -1)
	{
		adate = sdate.split(" ");
	}
	else
	{
		alert(msg);
		return false;
	}
	if (adate.length < 3)
	{
		alert(msg);
		return false;
	}
	if (adate.length > 3)
		time = adate[3];
	else if (adate[2].split(" ").length > 1)
		time = adate[2].split(" ")[1];

	if (time != null)
	{
		atime = time.split(":");
		if (atime.length < 2 || atime.length > 3)
		{
			alert(time + " is not a valid time");
			return false;
		}
		var h = parseInt(atime[0]);
		var m = parseInt(atime[1]);
		var s = 0;
		if (atime.length == 3)
			s = parseInt(atime[2]);
		if (h < 0 || h > 23 || m < 0 || m > 59 || s < 0 || s > 59)
		{
			alert(time + " is not a valid time");
			return false;
		}
		time = h + ":" + ((m < 10) ? ("0" + m) : m);
		if (atime.length == 3)
			time += ":" + ((s < 10) ? ("0" + s) : s);
		
	}
	var monthArr = getMonthArr();
	
	if (adate[1] >= 0 && adate[1] <= 12)
		month = adate[1];
	else
	{
		months = months.toLowerCase();
		month = months.indexOf(adate[1].toLowerCase())
		if (month == -1)
		{
		  alert(msg);
			return false;
		}
		month = month / 4 + 1;
	}
	var year = parseInt(adate[2]);
	if (year < 100)
		year += 2000;

	var testDate = new Date(year, month - 1, adate[0]);
//	alert("testDate = " + testDate + ", testDateStr = " + testDateStr)
	if (testDate.getDate() != adate[0] || testDate.getMonth() != month - 1 || (testDate.getYear() != year && testDate.getFullYear() != year))
	{
		alert(msg);
		return false;
	}
	// Format the source object's date correctly so that Access doesn't screw it up if the user put in a 
	// date with an ambiguous date/month
	var newDateStr = testDate.getDate() + " " + monthArr[testDate.getMonth()] + ", " + testDate.getFullYear();
	if (time != null)
		 newDateStr += " " + time;
	objDate.Value = newDateStr;
	return true;
}
/*
function CheckDate(objDate, mandatory, description)
{
	var sdate = objDate.value;
	var adate;
	var msg = sdate + ' is not a valid ' + description;
	
	if (!mandatory && (sdate == '' || sdate == ' '))
		return true;
	
	if (sdate == '' || sdate == ' ')
	{
		alert("Please enter a " + description);
		return false;
	}	
	if (sdate.indexOf("/") != -1)
	{
		adate = sdate.split("/");
	}
	else if (sdate.indexOf("-") != -1)
	{
		adate = sdate.split("-");
	}
	else if (sdate.indexOf(" ") != -1)
	{
		adate = sdate.split(" ");
	}
	else
	{
	  alert(msg);
		return false;
	}
	if (adate.length != 3)
	{
	  alert(msg);
		return false;
	}

	months = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,";
	var monthArr = months.split(",");
	
	if (adate[1] >= 0 && adate[1] <= 12)
		month = adate[1];
	else
	{
		months = months.toLowerCase();
		month = months.indexOf(adate[1].toLowerCase())
		if (month == -1)
		{
		  alert(msg);
			return false;
		}
		month = month / 4 + 1;
	}
	var testDateStr = month + "-" + adate[0] + "-" + adate[2];
	var testDate = new Date(testDateStr);
//	alert("testDate = " + testDate + ", testDateStr = " + testDateStr)
	if (testDate.getDate() != adate[0] || testDate.getMonth() != month - 1 || (testDate.getYear() != adate[2] && testDate.getFullYear() != adate[2]))
	{
	  alert(msg);
		return false;
	}
	// Format the source object's date correctly so that Access doesn't screw it up if the user put in a 
	// date with an ambiguous date/month
	objDate.value = testDate.getDate() + " " + monthArr[testDate.getMonth()] + ", " + testDate.getFullYear();
	return true;
}

function ParseDate(sdate)
{
	var adate;
	var msg = sdate + ' is not a valid date';
	
	if (sdate == '' || sdate == ' ')
	{
		alert("Please enter a valid date");
		return NULL;
	}	
	if (sdate.indexOf("/") != -1)
	{
		adate = sdate.split("/");
	}
	else if (sdate.indexOf("-") != -1)
	{
		adate = sdate.split("-");
	}
	else if (sdate.indexOf(" ") != -1)
	{
		adate = sdate.split(" ");
	}
	else
	{
	  alert(msg);
		return NULL;
	}
	if (adate.length != 3)
	{
	  alert(msg);
		return NULL;
	}

	months = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,";
	var monthArr = months.split(",");
	
	if (adate[1] >= 0 && adate[1] <= 12)
		month = adate[1];
	else
	{
		months = months.toLowerCase();
		month = months.indexOf(adate[1].toLowerCase())
		if (month == -1)
		{
		  alert(msg);
			return NULL;
		}
		month = month / 4 + 1;
	}
	var testDateStr = month + "-" + adate[0] + "-" + adate[2];
	var testDate = new Date(testDateStr);
//	alert("testDate = " + testDate + ", testDateStr = " + testDateStr)
	if (testDate.getDate() != adate[0] || testDate.getMonth() != month - 1 || (testDate.getYear() != adate[2] && testDate.getFullYear() != adate[2]))
	{
	  alert(msg);
		return NULL;
	}
	// Format the source object's date correctly so that Access doesn't screw it up if the user put in a 
	// date with an ambiguous date/month
	return testDate;
}
*/
/*
// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked)
	  cal.callCloseHandler(); // Comment this out to force a double click to close the calendar
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  calendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (calendar != null) {
    // we already have some calendar created
    calendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(true, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    calendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  calendar.setDateFormat(format);    // set the specified date format
  calendar.parseDate(el.value);      // try to parse the text in field
  calendar.sel = el;                 // inform it what input field we use
  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
//  calendar.showAtElement(el.nextSibling, "Br");        // show the calendar
  calendar.showAtElement(el, "Bl");        // show the calendar

  return false;
}
*/
function CheckNumber(objStr, mandatory)
{
	var num = new Number(objStr.value);

	if (isNaN(num))
		return false;

	if (mandatory && (objStr.value = '' || num.value == 0))
		return false;

	objStr.value = num;

	return true;
}

function addOption(srcSelect, targSelect)
{
	var srcOpt = srcSelect.item(srcSelect.selectedIndex)
	// check for potential duplicates
	for(var i = 0; i < targSelect.length; i++)
		if (targSelect.item(i).value == srcOpt.value)
			return;
	var newOpt = new Option(srcOpt.text, srcOpt.value);
	newOpt.value = srcOpt.value;	// Copy the ID
	targSelect.options[targSelect.options.length] = newOpt;
}

function removeOption(targSelect)
{
	if (targSelect.selectedIndex != -1)
		targSelect.options[targSelect.selectedIndex] = null;	
}

function SelectAll(targSelect)
{
	for(var i = 0; i < targSelect.length; i++)
		targSelect.item(i).selected = true;
}

function findLivePageHeight(){
  var ih; // Set inner height
		
  if (window.innerWidth == null)
    ih=document.body.clientHeight; 
  else 
    ih = window.innerHeight;
		
  return ih;
}
 
function findLivePageWidth() {
  if (window.innerWidth != null) return window.innerWidth;
	
  if (document.body.clientWidth != null) return document.body.clientWidth;
  
	return (null);
}

function gettbl(){
		scrollid='ScrollTable';
		
		e = gE(scrollid);
		
		if(e) {
			if(l)
				e.pageYOffset = selDivPX - 34;
			else
				e.scrollTop = selDivPX - 34;
		}
}

function gE(e,f)
{
	if(document.getElementById)
	{
		return document.getElementById(e);                        //if supported                        
	}
	
	if(l)
	{
		f=(f)?f:self;
		V=f.document.layers;
		
		if(V[e]) return V[e];
		
		for(W=0;W<V.length;)
			return(gE(e,V[W++]));
	}
	
	if(document.all)
		return document.all[e];
}

function isunique(list, value)
{
	var a = list.split('|');
	var i;
	for(i = 0; i < a.length; i++)
	{
		if (a[i].toUpperCase() == value.toUpperCase())
			return false;
	}
	return true;
}
/*
function fnTrapKD(btn, event)
{
 if (document.all){
  if (event.keyCode == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
}
 else if (document.getElementById){
  if (event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
 else if(document.layers){
  if(event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
}
*/
function onEnter(btn)
{
	if (document.all)
	{     document.onkeydown = function ()
		{     var key_enter= 13; // 13 = Enter
			if (key_enter==event.keyCode)
			{
			event.keyCode=0;
			document.getElementById(btn).click()
			return false;
			}
		}
	}
}	


function formatNumber2(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function SetSelectValue(sel, value)
{
	for(var i = 0; i < sel.options.length; i++)
		if (sel.options[i].text == value || sel.options[i].value == value)
			sel.selectedIndex = i;
}

function SetNodeValue(node, nodeName, nodeValue)
{
	if (node.id == nodeName)
	{
		if (node.nodeName == "INPUT" || node.nodeName == "TEXTAREA")
			node.value = nodeValue;
		else if (node.nodeName == "SELECT")
			SetSelectValue(node, nodeValue);
		else if (node.tagName == "TD")
			node.innerText = nodeValue;
		return true;
	}
	if (node.childNodes)
	{
		var i;
		for(i = 0; i < node.childNodes.length; i++)
			if (SetNodeValue(node.childNodes[i], nodeName, nodeValue))
				return true;
	}
	return false;
}

function GetNodeValue(node, nodeName)
{
	if (node.id  == nodeName)
		if (node.nodeName == "INPUT" || node.nodeName == "SELECT" || node.nodeName == "TEXTAREA")
			return node.value;
		else if (node.tagName == "TD")
			return node.innerText;

	if (node.childNodes)
	{
		var i;
		for(i = 0; i < node.childNodes.length; i++)
		{
			val = GetNodeValue(node.childNodes[i], nodeName);
			if (val)
				return val;
		}
	}
	return null;
}

function GetControlText(node)
{
	if (node.nodeName == "INPUT" || node.nodeName == "TEXTAREA")
		return node.value;
	else if (node.nodeName == "SELECT")
		return node.options[node.selectedIndex].text;
	else if (node.tagName == "TD")
		return node.innerText;
	else
		return null;
}

function FindNode(node, nodeName)
{
	if (node == null)
	    return null;
	else if (node.id == nodeName)
		return node;

	if (node.childNodes)
	{
		var i;
		for(i = 0; i < node.childNodes.length; i++)
		{
			var foundNode = FindNode(node.childNodes[i], nodeName);
			if (foundNode)
				return foundNode;
		}
	}
	return null;
}

var debugWin = null;

function onDebugClose()
{
	alert("closing"); 
	debugWin = null; 
}

function getDebugDoc()
{
	if (debugWin)
	{
		try
		{
			var testDoc = debugWin.document;
		}
		catch(e)
		{
			alert(e);
			debugWin = null;
		}
	}
	if (!debugWin)
	{
		attr = 'left=0,top=0,height=' + 600 + ',width=' + 600 + ',menubar=no,scrollbars=yes,status=yes,toolbar=no,location=no,resizeable=yes';
		debugWin = window.open("#",'popup', attr);
		debugWin.onunload = onDebugClose;
		debugWin.document.writeln("<html><body style='font-family:verdana; font-size:8pt;'>");

	}
	var doc = debugWin.document;
	return doc;
}

function writeDebugString(str)
{
	var doc = getDebugDoc();
	doc.writeln(str);
}

function writeDebugObject(obj)
{
	var doc = getDebugDoc();
	
	doc.writeln("<table style='font-family:verdana; font-size:8pt;'>");
	for(var i in obj)
	{
		doc.writeln("<tr><td>" + i + "</td><td>=</td><td>" + obj[i] + "</td></tr>");
	}
	doc.writeln("</table>");
	doc.writeln("<hr>");
}
