
function opwin(url,h,w)
{
XPos = screen.availWidth/2 - w/2; 
YPos = (screen.availHeight/2 - h/2) - 85; 
var opwin = window.open(url, "newwindow", "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,location=top,status=no,width="+w+",height="+h+",ScreenX=0,ScreenY=0,Top="+YPos+",Left="+XPos); 
opwin.focus();
}

function ow(url,lk)
{
h = 480; 
w = 650;
XPos = screen.availWidth/2 - w/2; 
YPos = (screen.availHeight/2 - h/2) - 85; 
var ow = window.open(url, "newwindow", "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,location=top,status=no,width="+w+",height="+h+",ScreenX=0,ScreenY=0,Top="+YPos+",Left="+XPos); 
if (!(navigator.appName.indexOf("Netscape")!= -1 && parseInt(navigator.appVersion) == 4)) {lk.style.color = '#800080';}
ow.focus();
}

function opwin1(url,h,w)
{
theHeight = h; 
XPosition = screen.availWidth/2 - w/2; 
YPosition = screen.availHeight/2 - theHeight/2; 
	window.open(url, "newwindow", "toolbar=no,menubar=no,scrollbars=no,resizable=no,location=top,status=no,width="+w+",height="+theHeight+",ScreenX=0,ScreenY=0,Top="+YPosition+",Left="+XPosition);
}

function opwin2(url,h,w)
{
theHeight = h; 
XPosition = screen.availWidth/2 - w/2; 
YPosition = screen.availHeight/2 - theHeight/2; 
window.open(url, "newwindow", "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,location=top,status=no,width="+w+",height="+theHeight+",ScreenX=0,ScreenY=0,Top="+YPosition+",Left="+XPosition); 
}

function popup(c,url,e) {
	var r = null;
	if(getCookie(c) == null) {
		setCookie(c, "true", e);
		r = window.open('', 'special','width=320,height=320,resizable=0');
		if (r != null) {
			if (r.opener == null) {
				r.opener = self;
			}
			r.location.href = url;
		}
	}
}

function popup2(c,url,e,wn,h,w) {
	var r = null;
	if(getCookie(c) == null) {
		setCookie(c, "true", e);
		r = window.open('', wn,'width='+w+',height='+h+',resizable=0');
		if (r != null) {
			if (r.opener == null) {
				r.opener = self;
			}
			r.location.href = url;
		}
	}
}

function popup3(url,h,w)
{
	var x= screen.availWidth/2 - w/2; 
	var y= screen.availHeight/2 - h/2; 
	window.open(url, "newwindow", "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=top,status=no,width="+w+",height="+h+",ScreenX=0,ScreenY=0,Top="+y+",Left="+x); 
}

function getCookie(name) { 
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}

function setCookie(name, value, e) { 
	// e = in minutes
	var today = new Date();
	var expiry = new Date(today.getTime() + e * 60 * 1000); // plus 1 hour
	document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
}


function IsEmpty(szFieldName)
{
      var i;
      var ch;

 	  if (parseInt(szFieldName.value.length) == 0)
         return true;

      for (i=0; i<parseInt(szFieldName.value.length); i++) {
            ch = szFieldName.value.charAt(i);
            if (ch != ' ' && ch != '\t')
                  return false;
      }
      return true;
}

function IsDouble(szFieldName)
{
      //This function checks the input for 0 - 9 digits, period (.) and comma (,)
      var i;
      var IsDouble;
      var ch;

      IsDouble = true;
      TrimField(szFieldName);
      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if (((ch >= "0") && (ch <= "9")) || (ch == ".") || (ch == ","))
               IsDouble = true;
            else
                  return false;
      }
      return IsDouble;
}

function IsValidDate(dateStr) {
	// Checks for the following valid date formats:
	// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
	// Also separates date into month, day, and year variables
	
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
	}
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn't have 31 days!")
		alert("Please enter a valid date.");
		return false
	}
	if (month == 2) { // check for february 29th
		var g = parseInt(year / 4);
		if (day > 29 || (day == 29 && (year / 4) != g)) {
			//alert("February in "+year+" doesn't have "+day+" days!")
			alert("Please enter a valid date.");
			return false;
   		}
	}
	return true;  // date is valid
}

function SetFocusSelect(szFieldName)
{
      szFieldName.focus();
      szFieldName.select();
      return true;
}

function TrimField(szFieldName)
{
  var szNewStr="";
  if (szFieldName.value == "")
  	return;
  if (szFieldName.value.length > 0) {
	szNewStr = TrimString(szFieldName.value);
	szFieldName.value = szNewStr;
	}
}

function TrimString(szString)
{
      var i = 0;
      var j = 0;

      for (i=0; i<parseInt(szString.length); i++) {
            if(szString.charAt(i) != " ") {
                  for (j=parseInt(szString.length) - 1; j > i; j--) {
                        if (szString.charAt(j) != " ") {
                              break;
                        }
                  }
                  break;
            }
      }

      if (i > j)
            i = j;

      if (szString.length > 0 && szString.charAt(j) != " ")
            j++;

      return szString.substring(i, j);
}

function Round(num,decPlace)
{
	decPlace = (!decPlace ? 2 : decPlace);
	return Math.round(num * Math.pow(10,decPlace)) / Math.pow(10,decPlace);
}

function FormatNumber(num)
{
	var rawNumStr = Round(num) + '';
	rawNumStr = (rawNumStr.charAt(0) == '.' ? '0' + rawNumStr : rawNumStr);
	if (rawNumStr.charAt(rawNumStr.length-3) == '.') {
		rawNumStr = rawNumStr;
		}
	else if (rawNumStr.charAt(rawNumStr.length-2) == '.'){
		rawNumStr = rawNumStr + '0';
		}
	else {
		rawNumStr = rawNumStr + '.00';
		}
		
	return AddComma(rawNumStr);
}

/* -- not working in Netscape
function FilterNum(num) 
{
	// removes "$" and ","

	re = /^\$|,/g;
	var temp = num.replace(re, ""); 	
	return temp;
}
*/

function FilterNum(num) 
{
	// removes ","

	var i;
    var ch;
    var newstr;

	newstr = "";
    for(i=0; i<parseInt(num.length); i++) 
    {
    	ch=num.charAt(i);
        if (ch != ","){
        	newstr = newstr + ch;}
    }
    return newstr;
}

function AddComma(num) 
{
	num = '' + num;
	if (num.length > 3) 
	{
		var mod = num.length % 3;
		var output = (mod > 0 ? (num.substring(0,mod)) : '');
		
		for (i=0 ; i < Math.floor(num.length / 3); i++) 
		{
			if ((mod == 0) && (i == 0))
			{
				output += num.substring(mod+ 3 * i, mod + 3 * i + 3);
			}
			else
			{
				if (num.charAt(mod + 3 * i)==".")
					output += num.substring(mod+ 3 * i, mod + 3 * i + 3);
				else 
					output+= ',' + num.substring(mod + 3 * i, mod + 3 * i + 3);
			}
		}
		return (output);
	}
	else return num;
}

function IsNumeric(szFieldName)
{
      var i;
      var IsNum;
      var ch;

      IsNum=true;
      TrimField(szFieldName);
      for(i=0; i<parseInt(szFieldName.value.length); i++) {
            ch=szFieldName.value.charAt(i);
            if ((ch >= "0") && (ch <= "9"))
               IsNum= true;
            else
                  return false;
      }
      return IsNum;
}

//
function changeOpenerURL(whichURL)
{
	var objwindow = window.opener;
	objwindow.location.href = whichURL;	
}