
function FormatDateUS(datestr) {
	var ArrDate = datestr.split("/")
	var d = ArrDate[0];
	var m = ArrDate[1];
	var y = String(ArrDate[2]);
	if (y.length == 2) y = parseInt(y) + 2000;
	return new Date(y, m, d);
}

function CheckNumeric(txtbox) {

	var numval = txtbox.value;

	if (numval == "") {
		txtbox.value = "0";
		return true;
	}

	if (isNaN(numval)) {
		alert("This field requires a numeric value.");
		txtbox.select();
		txtbox.focus();
		return false;
	}
	else
		return true;
}

function CheckCurrency(txtbox) {

	var curval = String(txtbox.value);

	if (curval == "") {
		txtbox.value = "0.00";
		return true;
	}
	
	curval = curval.replace(",", "");

	if (isNaN(curval)) {
		alert("This field requires a numeric value.");
		txtbox.select();
		txtbox.focus();
		return false;
	}
	else {
		FormatCurrency(txtbox);
		return true;	
	}
}

function FormatCurrency(txtbox) {

	var curval = String(txtbox.value);
	curval = curval.replace(",", "");

	var curval_int = parseInt(curval);
	var curval_float = parseFloat(curval) - curval_int;
	curval_float = Math.round(curval_float * 100);
	if(curval_float == 0) curval_float = "00";
	txtbox.value = String(curval_int) + "." + String(curval_float);
	return true;
}

//Appends a new option to a list box
function AddOption(ListBox, OptionValue, OptionText, OptionIsSelected) {
	ListBox.options[ListBox.options.length] = new Option(OptionText, OptionValue);
	if(OptionIsSelected) {
		ListBox.options[ListBox.options.length-1].selected = true;
		ListBox.options[ListBox.options.length-1].defaultSelected = true;
	}
}

function GetListBoxValue(ListBox) {
	return ListBox[ListBox.selectedIndex].value;
}

function SetListBoxValue(ListBox, ListBoxValue) {
	for (var i=0; i<ListBox.length; i++) {
		if (ListBox[i].value == ListBoxValue) {
			ListBox[i].selected = true;
			return;
		}
	}
}

function getCookie(NameOfCookie){
    if (document.cookie.length > 0) {              
    begin = document.cookie.indexOf(NameOfCookie+"=");       
    if (begin != -1) {           
      begin += NameOfCookie.length+1;       
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(NameOfCookie, value, expiredays) {
/*
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

  document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
*/
}

function delCookie(NameOfCookie) {
	document.cookie = NameOfCookie + "=";
}

function delAllCookie() {
	var strCookie = document.cookie;
	var arrCookie = strCookie.split(";");
	for (var i = 0; i < arrCookie.length - 1; i++) {
		
		
	}
}

function GenFlashTag(FlashImageSrc, StillImageSrc, ImgHeight, ImgWidth) {
	if (useFlash && isMinIE4)
		document.write('<embed type="application/x-shockwave-flash" width="' + ImgWidth + '" height="' + ImgHeight + '" src="' + FlashImageSrc + '" border="0">')
	else
		document.write('<img width="' + ImgWidth + '" height="' + ImgHeight + '" src="' + StillImageSrc + '" border="0">')
}

//Example: appendFuncToEvent("window.onload", "InitPage()")
function appendFuncToEvent(eventName, funcName) {
	
	eval("var eventRef = " + eventName);
	
	if (eventRef == null) {
		var BracketPos = funcName.indexOf("(");
		if(BracketPos != -1) funcName = funcName.substring(0, BracketPos);
		eval(eventName + "=" + funcName);
	}
	else {
		var eventCode = String(eventRef);
		var eventFuncName = eventCode.substring(eventCode.indexOf("function ") + 9, eventCode.indexOf("("));
		eventCode = eventCode.substring(0, eventCode.lastIndexOf("}"));
		eventCode = eventCode + " \n " + funcName + ";" + "\n }";
		eval(eventCode);
		eval(eventName + "=" + eventFuncName + ";");
	}
}

//Example: insertFuncToEvent("window.onload", "InitPage()")
function insertFuncToEvent(eventName, funcName) {
	
	eval("var eventRef = " + eventName);
	
	if (eventRef == null) {
		var BracketPos = funcName.indexOf("(");
		if(BracketPos != -1) funcName = funcName.substring(0, BracketPos);
		eval(eventName + "=" + funcName);
	}
	else {
		var eventCode = String(eventRef);
		var eventFuncName = eventCode.substring(eventCode.indexOf("function ") + 9, eventCode.indexOf("("));
		eventCode = eventCode.substring(0, eventCode.lastIndexOf("{") + 1) + " \n " + funcName + ";" + "\n " + eventCode.substring(eventCode.indexOf("{") + 1);
		eval(eventCode);
		eval(eventName + "=" + eventFuncName + ";");
	}
}

function DateBefore(datebefore, dateafter) {
	if ((parseInt(FormatDateUNIX(datebefore)) < parseInt(FormatDateUNIX(dateafter))))
		return true;
	else
		return false;
}

function DateBeforeOrEqual(datebefore, dateafter) {
	if ((parseInt(FormatDateUNIX(datebefore)) <= parseInt(FormatDateUNIX(dateafter))))
		return true;
	else
		return false;
}

function FormatDateUNIX(datestr) {
	var ArrDate = datestr.split("/");
	var d = String(ArrDate[0]);
	var m = String(ArrDate[1]);  //months start at 0 for Jan etc... (!)
	var y = String(ArrDate[2]);
	
	if (d.length < 2) d = "0" + d;
	if (m.length < 2) m = "0" + m;
	if (y.length == 2) y = String(parseInt(y) + 2000);
	
	//alert(d + "/" + m + "/" + y);
	return y + m + d;
}