//From "JavaScript Bible"
//Cookies
/*
//EXAMPLE:
var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now 
SetCookie ("ccpath", "http://www.hidaho.com/colorcenter/", expdate);
SetCookie ("ccname", "hIdaho Design ColorCenter", expdate);
SetCookie ("tempvar", "This is a temporary cookie.");
SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
SetCookie ("goner", "This cookie must die!");
document.write (document.cookie + "<br>");
DeleteCookie ("goner");
document.write (document.cookie + "<br>");
document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
document.write ("ccname = " + GetCookie("ccname") + "<br>");
document.write ("tempvar = " + GetCookie("tempvar") + "<br>");
*/
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//DHTML
function getObject(obj) {
	var theObj
	if (document.layers) {
		if (typeof obj == "string") {
			return document.layers[obj]
		} else {
			return obj
		}
	}
	else if (document.all) {
		if (typeof obj == "string") {
			return document.all(obj).style
		} else {
			return obj.style
		}
	}
	else if (document.getElementById) {
		if (typeof obj == "string") {
			return document.getElementById(obj).style
		} else {
			return obj.style
		}
	}
	return null
}

// position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	var theObj = getObject(obj)
	if (theObj.moveTo) {
		theObj.moveTo(x,y)
	} else if (typeof theObj.left != "undefined") {
		theObj.left = x
		theObj.top = y
	}
}

// move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj)
	if (theObj.moveBy) {
		theObj.moveBy(deltaX, deltaY)
	} else if (typeof theObj.left != "undefined") {
		theObj.left = parseInt(theObj.left) + deltaX
		theObj.top = parseInt(theObj.top) + deltaY
	}
}

// set the z-order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// set the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (theObj.bgColor) {
		theObj.bgColor = color
	} else if (typeof theObj.backgroundColor != "undefined") {
		theObj.backgroundColor = color
	}
}

// set the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj)
	//theObj.display = ""
	theObj.visibility = "visible"
}

// set the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj)
	//theObj.display = "none"
	theObj.visibility = "hidden"
}

// retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	return parseInt(theObj.left)
}

// retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	return parseInt(theObj.top)
}

function setImgDim(img,w,h,imgobj){
	var obj = imgobj? imgobj: document.getElementById(img);
	if(obj.width>w || obj.height>h){
		if(obj.width>=obj.height){
			obj.style.width=w;
			obj.style.height=parseInt((w*obj.height)/obj.width)
			/*
			obj.width=w;
			obj.height=parseInt((w*img.height)/img.width)
			*/
			}
		else{
			obj.style.height=h;
			obj.style.width=parseInt((h*obj.width)/obj.height)
			/*
			obj.height=h;
			obj.width=parseInt((h*img.width)/img.height)
			*/
			}
		}
	}


//TIONGLK, 25/07/2003 V1.0
//echo "return chkNumeric($objName,$p,$d,"true",'$allow','$j_err.$label','$j_xamt','$j_xrange','$j_xdec');";
function chkNumeric(objName,p,d,xZero,allow,j_err,j_xamt,j_xrange,j_xdec){
var checkOK = "0123456789" + allow; //comma + period + hyphen....
var allValid = true;
var allNum = "";
var chkVal = "";

//validate numeric
for (i=0; i<objName.value.length; i++){
	ch=objName.value.charAt(i);
	for(j=0; j<checkOK.length; j++) if(ch==checkOK.charAt(j)) break;
	if (j==checkOK.length){
		allValid = false; break;
		}
	if (ch != ",") allNum += ch;
	}

if (!allValid){	
	objName.select();
	alert(j_err + ' - ' + j_xamt)
	return false;
	}

//validate decimal
if (allNum.indexOf('.') != -1){
	chkVal= allNum.substring(allNum.indexOf('.')+1, allNum.length);
	if (chkVal.length > d || chkVal.length==0) {
		objName.select();
		alert(j_err + ' - ' + j_xdec)
		return false;
		}
	}
//validate precision
chkVal =  allNum.indexOf('.') != -1? allNum.substring(0,allNum.indexOf('.')): allNum;
if(chkVal.length > p || chkVal.length==0) {
	objName.select();
	alert(j_err + ' - ' + j_xrange)
	return false;
	}

if(xZero && parseFloat(allNum)==0){
	objName.select();
	alert(j_err + ' - ' + j_xrange)
	return false;
	}
}