// Preload the spacer.
var spcr = new Image();
spcr.src = "img/_.gif";


// Pop up window. Parameters: URL, left, top, width, height.
var popUpWin = 0;
function pop(URL, l, t, w, h) {
   if (l == null) l = 50;
   if (t == null) t = 50;
   if (w == null) w = 520;
   if (h == null) h = 420;
   if ((popUpWin) && (!popUpWin.closed)) popUpWin.close();
   popUpWin = open(URL, 'popUpWin', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, copyhistory=0, width=' + w + ', height=' + h + ', left=' + l + ', top=' + t + ', screenX=' + l + ', screenY=' + t + '');
}


// Adds the page to Favorites.
function addBookmark() {
   if (window.external) {
      window.external.AddFavorite(location.href, document.title);
   }
   else {
      alert("Your browser doesn't support this feature. The bookmark is NOT added.\nTIP: As an alternative, try pressing <CTRL+D>.");
   }
}


// Checks for a valid email address.
function checkEmail(val) {   
   var mailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (mailFilter.test(val)) {
      return true;
   }
	else {
	   return false;
	}
}


// Opens help for a help ID.
function help(HID) {
   pop("http://www.cwtihq.net/Help.asp?src=" + HID);
}


// Form validation - checks required fields.
// Parameters: form, requred fields[], field description[].
function formCheck(formObj, reqField, fieldDesc) {
   var blank=" ";
   var alertMsg = "Please complete the following fields:\n";
   var lenMsg = alertMsg.length;
   for (var i = 0; i < reqField.length; i++) {
      var obj = formObj.elements[reqField[i]];
      if (obj) {
         switch(obj.type) {
            case "select-one":
               if ((obj.selectedIndex == -1) || (obj.options[obj.selectedIndex].text == "") || (obj.value == "")) {
                  alertMsg += "  - " + fieldDesc[i] + "\n";
               }
               break;
            case "select-multiple":
               if (obj.selectedIndex == -1) {
                  alertMsg += "  - " + fieldDesc[i] + "\n";
               }
               break;
            case "text":
            case "textarea":
               if ((obj.value == "") || (obj.value == null) || (obj.value == blank)) {
                  alertMsg += "  - " + fieldDesc[i] + "\n";
               }
               break;
            default:
               if ((obj.value == "") || (obj.value == null) || (obj.value == blank)) {
                  alertMsg += "  - " + fieldDesc[i] + "\n";
               }
         }
      }
   }
   if (alertMsg.length == lenMsg) {
      return true;
   }
   else {
      alert(alertMsg);
      return false;
   }
}