
function openBrowser(theURL, winName, width, height) { 
  var features, top, left;
  top = (screen.availHeight - height) / 3;
  left = (screen.availWidth - width) / 2;
  if ((navigator.appName.indexOf('Netscape') != -1) && (navigator.appVersion.substr(0, 3) < '5.0')) {
    height = parseInt(height) + 15;
  }
  features = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',screenY=' + top + ',screenX=' + left + ',location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
  var newWindow = window.open(theURL, winName, features);
  newWindow.focus();
}

function openBrowserCloseSelf(theURL, winName, width, height) { 
  var features, top, left;
  top = (screen.availHeight - height) / 3;
  left = (screen.availWidth - width) / 2;
  if ((navigator.appName.indexOf('Netscape') != -1) && (navigator.appVersion.substr(0, 3) < '5.0')) {
    height = parseInt(height) + 15;
  }
  features = 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',screenY=' + top + ',screenX=' + left + ',location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
  var newWindow = window.open(theURL, winName, features);
  window.top.close();
  newWindow.focus();
}

function statusbarDisplay(str) {
  window.status = str;
  return true;
}

function statusbar(str) {
  window.status = str;
  return true;
}

function validateEmailForm(){
 if(!valid_email(document.teetime.email.value)){
	window.alert("The e-mail you entered seems to be invalid.\nPlease correct the e-mail address field and resubmit the form.");
    return false;
 }
  if (document.teetime.name.value == ""){
	window.alert("You have left the name field blank!\nPlease enter a name and resubmit the form.");
    return false;
  }else if(document.teetime.phone.value == ""){
	window.alert("You have left the phone number field blank!\nPlease enter a phone number and resubmit the form.");
    return false;
  }else{
    return true;
  }

}

function validatePackagerForm(){
 if(!valid_email(document.packager.email.value)){
	window.alert("The e-mail you entered seems to be invalid.\nPlease correct the e-mail address field and resubmit the form.");
    return false;
 }
  if (document.packager.name.value == ""){
	window.alert("You have left the name field blank!\nPlease enter a name and resubmit the form.");
    return false;
  }else if(document.packager.message.value == ""){
	window.alert("You have left the message field blank!\nPlease enter a message and resubmit the form.");
    return false;
  }else{
    return true;
  }

}

function validateContactForm(){
  if(!valid_email(document.mail.email.value)){
	window.alert("The e-mail you entered seems to be invalid.\nPlease correct the e-mail address field and resubmit the form.");
    return false;
  }

 if (document.mail.phone.value == ""){
	window.alert("You have left the phone number field blank!\nPlease enter a phone number and resubmit the form.");
    return false;
 }
  if (document.mail.message.value == ""){
	window.alert("You have left the message field blank!\nPlease enter a message and resubmit the form.");
    return false;
  }else{
    return true;
  }
}

function validatePromoForm(){
  if(!valid_email(document.mail.email.value)){
	window.alert("The e-mail you entered seems to be invalid.\nPlease correct the e-mail address field and resubmit the form.");
    return false;
  }

 if (document.mail.phone.value == ""){
	window.alert("You have left the phone number field blank!\nPlease enter a phone number and resubmit the form.");
    return false;
 }
  if (document.mail.name.value == ""){
	window.alert("You have left the name field blank!\nPlease enter your name and resubmit the form.");
    return false;
  }else{
    return true;
  }
}

function valid_email(strTest) {
  var mask = new RegExp("^[^\*|,\\\":<>\\[\\]{}`';()&%@ ]+@[^\*|,\\\":<>\\[\\]{}`';()&%@ ]+[^\*|,.\\\":<>\\[\\]{}`';()&%@ ]+$", "g");
  strTest = Trim(strTest);
  return mask.test(strTest);
}

function LTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
      j++;
    }
    s = s.substring(j, i);
  }
  return s;
}

function RTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1; 
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
      i--;
    }
    s = s.substring(0, i+1);
  }
  return s;
}

function Trim(str) {
  return RTrim(LTrim(str));
}

function closePane(){
  window.top.close();
}

function updateCartPrice(fPrice){
  if(isNaN(fPrice)){
     document.teetime.numcarts.value = "N/A";
  }else{
	 var numberOf = parseFloat(document.teetime.carts.value);
	 var price    = parseFloat(fPrice);
	 var returnPrice  = parseFloat(numberOf * price);
	 if(returnPrice=="N/A"){
	   document.teetime.numcarts.value = returnPrice;
	 }else{
       document.teetime.numcarts.value = "$" + returnPrice + ".00";
	 }
  }
}
function updatePlayerPrice(fPrice){
  if(isNaN(fPrice)){
     document.teetime.numplayers.value = "N/A";
  }else{
	 var numberOf = parseFloat(document.teetime.players.value);
	 var price    = parseFloat(fPrice);
	 var returnPrice  = parseFloat(numberOf * price);
	 if(returnPrice=="N/A"){
	   document.teetime.numplayers.value = returnPrice;
	 }else{
       document.teetime.numplayers.value = "$" + returnPrice + ".00";
	 }
  } 
}
