var noErrors=true;
var errorMessage="";
var focusOnError=false;

var ie = "Microsoft Internet Explorer";
var nn = "Netscape";
var browser = navigator.appName;
var version = navigator.appVersion;
var mac = "MacPPC";
var os = navigator.platform;

function launchBrowser(url, name, width, height) {
        var x = 0;
        var y = 0;
        if(navigator.appVersion.length > 0 && navigator.appVersion.charAt(0) > '3' && navigator.appVersion.charAt(0) <= '9') {
                if(width > screen.availWidth - 12) {
                        width = screen.availWidth - 12;
                }
                if(height > screen.availHeight - 48) {
                        height = screen.availHeight - 48;
                }
                x = (screen.availWidth - 12 - width) / 2;
                y = (screen.availHeight - 48 - height) / 2;
        }
        var params =  "resizable=yes,scrollbars=yes,location=yes,status=yes,toolbar=yes,menubar=yes,directories=yes,screenX=" + x + ",screenY=" + y + ",width=" + width + ",height=" + height + ")";
        var windowvar = window.open(url, name, params);
        windowvar.focus();
}

function checkInput(control,error) {
	if (control.value.length<1) {
		setFocusOnError(control);
		addError(error);
	}
}

function checkInputValue(control,value,error) {
	if (control.value==value) {
		setFocusOnError(control);
		addError(error);
	}
}

function addError(error) {
	errorMessage += error + "\n";
	noErrors=false;
}

function initErrors () {
	noErrors=true;
	errorMessage="";
	focusOnError=false;
}

function showErrors() {
	if (noErrors) {
		return true;
	} else {
		alert("The following errors were found:\n\n" + errorMessage);
		if (focusOnError) {
			//focusOnError.focus();
		}
		return false;
	}
}

function setFocusOnError(ctrl) {
	if (focusOnError==false) {
		focusOnError=ctrl;
	}
}

function isValidDate (myDate) {
// checks if date passed is in valid mm/dd/yyyy format

  if (myDate.length==0) {return true;}

  if (myDate.length == 10) {
      if (myDate.substring(2,3) == "/" && myDate.substring(5,6) == "/") {
          var month  = myDate.substring(0,2);
          var date = myDate.substring(3,5);
          var year  = myDate.substring(6,10);

          var test = new Date(year,month-1,date);

          year = y2k(test.getYear());
          if (year>=1900 && (month-1 == test.getMonth()) && (date == test.getDate())) {
              return true;
          }
      }
  }
  return false;
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isValidZip(zip,mode) {
  if (zip.length<1) return true;
  switch (mode) {
    default:
      re = /^\d{5}$/
      if(zip.search(re)==-1) {
        return false;
      } else {
        return true;
      }
  }
}

function isValidCCNum(s) {
  if (s.length<1) return true;
  re = /^\d{10,20}$/
  if (s.search(re)==-1) {
    return false;
  } else {
    return true;
  }
}

function isValidCCExpDate(ExpMonth,ExpYear) {
  if (ExpMonth.length<1 || ExpYear.length<1) return true;
  re = /^\d+$/
  if (ExpMonth.search(re)==-1 || ExpYear.search(re)==-1) {
    return false;
  } else {
    if (ExpMonth.substring(0,1)=='0') {
      m = parseInt(ExpMonth.substring(1));
    } else {
      m = parseInt(ExpMonth);
    }
    if (ExpYear.substring(0,1)=='0') {
      y = parseInt(ExpYear.substring(1));
    } else {
      y = parseInt(ExpYear);
    }

    if (m<1 || m>12 || y<3) {
      return false;
    } else {
      return true;
    }
  }
}

function isValidCCSecCode(s) {
  if (s.length<1) return true;
  re = /^\d{2,6}$/
  if (s.search(re)==-1) {
    return false;
  } else {
    return true;
  }
}

function RegExpTest(TestString,re) {
  if (TestString.length<1) return true;
  if (TestString.search(re)==-1) {
    return false;
  } else {
    return true;
  }
}


function formatCurrency(myNum){
	var prefix="";
	var wd;

	wd="w";
	var tempnum=myNum.toString();
	for (i=0;i<tempnum.length;i++){
		if (tempnum.charAt(i)=="."){
			wd="d"
			break
		}
	}
	if (wd=="w") {
		return prefix+tempnum+".00";
	} else {
		if (tempnum.charAt(tempnum.length-2)=="."){
			return prefix+tempnum+"0";
		} else {
			tempnum=Math.round(tempnum*100)/100;
                        if (tempnum == Math.round(tempnum)) {tempnum=formatCurrency(tempnum);}
                        if (tempnum.toString().charAt(tempnum.length-2)==".") {
  			  return prefix+tempnum+"0";
                        } else {
			  return prefix+tempnum;
                        }
		}
	}
}

function helpWindow(URL) {
//  features = "height=,width=,status=yes,toolbar=no,menubar=yes,location=yes, left=240, top=30";
  window.open(URL,"","");
}

function getFilename(pathname) {
  for (i=pathname.length; i>=1; i--){
    if (pathname.charAt(i)=="/"){
      output = pathname.substr(i+1);
      break;
    }
  }
  return output;
}

btnPre = "/images/btn/btn";

function loadBtnImg (src) {
	img = new Image();
	img.src = src;
}

function btnImg(name) {
  img = btnPre + name + ".gif";
  img_down = btnPre + name + "_down.gif";
  document.write("<input id=btn" + name + " type=image src=" + img + " onmouseup=\"this.src='" + img + "'\" onmouseout=\"this.src='" + img + "'\" onmousedown=\"this.src='" + img_down + "'\" alt=" + name + " style=\"cursor:default\">");

	//load the mouse-down image
	loadBtnImg(img_down);
}

function btnImgCustom(name,onclickAction) {
  img = btnPre + name + ".gif";
  img_down = btnPre + name + "_down.gif";
  document.write("<img id=btn" + name + " onclick=\"" + onclickAction + "\" src=" + img + " onmouseup=\"this.src='" + img + "'\" onmouseout=\"this.src='" + img + "'\" onmousedown=\"this.src='" + img_down + "'\" alt=" + name + ">");

	//load the mouse-down image
	loadBtnImg(img_down);
}

function btnImgBack(name) {
  img = btnPre + name + ".gif";
  img_down = btnPre + name + "_down.gif";
  document.write("<img id=btn" + name + " src=" + img + " onclick=\"history.back();\" onmouseup=\"this.src='" + img + "'\" onmouseout=\"this.src='" + img + "'\" onmousedown=\"this.src='" + img_down + "'\" alt=" + name + ">");

	//load the mouse-down image
	loadBtnImg(img_down);
}

function calImg(objName,dateFormat) {
  src = "/images/btn/btnCal.gif";
  src_down = "/images/btn/btnCal_down.gif";
  document.write("<img alt=\"Select Date\" align=top src=" + src + " onClick='popUpCalendar(this, " + objName + ", \"" + dateFormat + "\")' border=0 onmouseup=\"this.src='" + src + "'\" onmouseout=\"this.src='" + src + "'\" onmousedown=\"this.src='" + src_down + "'\">");

	//load the mouse-down image
	loadBtnImg(src_down);
}



