//---------------------------------------------------------------------------------- 
// Replace Unwanted Characters 
//---------------------------------------------------------------------------------- 
function ReplaceChr(sData) { 
	var myString = new String(sData) 
	rExp = /'/gi; 
	var newString = new String ("") 
	myString = myString.replace(rExp, newString) 
	rExp = /"/gi;
	return(myString.replace(rExp, newString)); 
}
//---------------------------------------------------------------------------------- 
// Format Amount Fields 
//---------------------------------------------------------------------------------- 
function PvtFormatAmount(CAmount) { 
	var CString 
	if (CAmount == 0) { 
		CString = "0.00"; 
		return(CString); 
	} else { 
		var CString = String(Math.round(CAmount * 100) / 100); 
		var pos = CString.indexOf("."); 
		switch(pos) { 
			case -1: 
				CString = CString + ".00"; 
				return(CString); 
				break; 
			case CString.length - 2: 
				CString = CString + "0"; 
				return(CString); 
				break; 
			default: 
				return(CString); 
		} 
	} 
}
//---------------------------------------------------------------------------------- 
// Edit Double Fields 
//---------------------------------------------------------------------------------- 
function Amountonchange() {
	var el = event.srcElement; 
	if (isNaN(el.value)) {
		el.value = "0.00";
		} else {
		var CAmount = parseFloat(el.value);
		if (isNaN(CAmount)) CAmount = 0;
		var CString = String(Math.round(CAmount * 100) / 100);
		var pos = CString.indexOf(".");
			switch(pos)
			{
			case -1: 
				el.value = CString + ".00";
				break; 
			case CString.length - 2:
				el.value = CString + "0";
				break; 
			default:
				el.value = CString;
			}
		}
	}
//---------------------------------------------------------------------------------- 
// Edit Integer Fields
//---------------------------------------------------------------------------------- 
function Amountonchange1() {
	var el = event.srcElement; 
	if (isNaN(el.value)) {
		el.value = "0";
		} else {
		var CAmount = parseInt(el.value);
		if (isNaN(CAmount)) CAmount = 0;
				el.value = CAmount;
		}
	}
//---------------------------------------------------------------------------------- 
// Edit Phone Fields 
//---------------------------------------------------------------------------------- 
function PhoneCheck() {
	var el = event.srcElement; 
	if (el.value != "") {
		if (el.value.length == 10) {
			el.value = "(" + el.value.substr(0,3) + ")" + el.value.substr(3,3) + "-" + el.value.substr(6,4);
			}
			if (el.value.indexOf('(', 0) != 0 || el.value.indexOf(')', 0) != 4 || el.value.indexOf('-', 0) != 8) {
				alert("Invalid Phone Number. Format(999)999-9999");
				el.focus();
			}
		}
	}
//---------------------------------------------------------------------------------- 
// Edit Zip Code Fields 
//---------------------------------------------------------------------------------- 
function ZipCheck() {
	var el = event.srcElement; 
	if (el.value != "") {	
			if (el.value.indexOf('-', 0) != 5 && el.value.length > 5 || el.value.length < 5 || el.value.length > 5 && el.value.length < 10 || el.value.indexOf('-', 0) != -1 && el.value.length <= 5) {
				alert("Invalid Zip Code. Format 99999-9999");
				el.focus();
			}
		}
	}
//---------------------------------------------------------------------------------- 
// Check Email Addresses
//---------------------------------------------------------------------------------- 
function EmailCheck() {
	var el = event.srcElement; 
	if (el.value != "") {
	
			if (el.value.indexOf('@', 0) == -1 || el.value.indexOf('.', 0) == -1 || el.value.length < 7) {
				alert("Invalid Email Address, make corrections.");
				el.focus();
			}
		} 
	}
//---------------------------------------------------------------------------------- 
// Edit Date Fields 
//---------------------------------------------------------------------------------- 
function Dateonchange() {
	var el = event.srcElement; 
	if (el.value != "") {
		var dSep1 = el.value.indexOf('/', 0);
		var	dSep2 = el.value.indexOf('/', dSep1 + 1);
			if (!isDate(el.value.substr(dSep1+1,dSep2-dSep1-1), el.value.substr(0,dSep1), el.value.substr(dSep2+1))) {
				alert("Invalid Date");
				el.focus();
			}
		}
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
	
function isDate (day,month,year) {
	// checks if date passed is valid
	// will accept dates in following format:
	// isDate(dd,mm,ccyy), or
	// isDate(dd,mm) - which defaults to the current year, or
	// isDate(dd) - which defaults to the current month and year.
	// Note, if passed the month must be between 1 and 12, and the
	// year in ccyy format.

    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false;
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false;
	}	
//---------------------------------------------------------------------------------- 
// AddDomElement 
//---------------------------------------------------------------------------------- 
function AddDomElement(objDom, strName, strValue) { 
	var objNode //Add new node 
	objNode = objDom.createElement(strName); 
	objNode.text = strValue 
	objDom.documentElement.appendChild(objNode); 
} 
//---------------------------------------------------------------------------------- 
// Table Mouse Over Event 
//---------------------------------------------------------------------------------- 
function doMouseOver() {
	var el = event.srcElement;
	el = el.parentElement;
	el.style.background = "lightsteelblue";
}
//---------------------------------------------------------------------------------- 
// Table Mouse Out Event  
//---------------------------------------------------------------------------------- 
function doMouseOut() {
	var el = event.srcElement;
	el = el.parentElement;
	el.style.background = "whitesmoke";
}
//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}
//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}
