/**
 *  function for opening a new window
 *  
 *  @param url		filepath to new page, relative or absolute
 *  @param w			width of the new window
 *  @param h			height of the new window
 *  @param scroll	yes/no, if you want scrollbars on
 *  @param resize	yes/no, if you want window to be resizable
 */
function newWin(url,w,h,scroll,resize,newName) {
  if (scroll == 'no') {
    if (screen.availWidth < w) {
      scroll = "yes";
    } else {
      if (screen.availHeight < h) {
        scroll = "yes"
      } else {
        scroll = "no";
      }
    }
  }
  // turn on scrollers for caps popup if under 1024
  if (url.indexOf('caps')) {
    if (screen.availWidth <= 1024) {
      scroll = "yes";
    }
  }
  var x = (screen.availWidth - w)/2;
  var y = (screen.availHeight - h)/2;
  var params = "toolbar=no,location=no,scrollbars=" + scroll + ",directories=no,status=no,menubar=no,resizable=" + resize + ",copyhistory=no,left=" + x + ",screenX=" + x + ",top=" + y + ",screenY=" + y + ",width=" + w + ",innerWidth=" + w + ",height=" + h + ",innerHeight=" + h;
  window.open(url,newName,params);
}

/**
 * function for correct PNG transparencey in Win IE 5.5 or higher
 */
function correctPNG() {
    //alert ("correcting PNG");
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
	  	var imgName = img.src.toUpperCase()
	  	if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 	var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 	var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 	var imgStyle = "display:inline-block;" + img.style.cssText 
		 	if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 	if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 	if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 	var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 	+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     	+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 	+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 	img.outerHTML = strNewHTML
		 	i = i-1
		}
	}
}

/**
 * see if the browser is IE, if so call the correctPNG function
 */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
if (browser == "Internet Explorer")
{
	//alert ("calling the correctPNG function");
	window.attachEvent("onload", correctPNG);
}

/**
 * submit the form
 */
function submitForm() {
	// validate required fields
	if (!document.myForm.first.value || !document.myForm.last.value || !document.myForm.email.value || !document.myForm.state.value || !document.myForm.comments.value)  {
		alert ("please enter all required fields");
	} else {	
		if (isValidEmail(document.myForm.email.value)) {
			// submit form
			document.myForm.submit();
		} else {
			alert ("please enter a valid email address");	
		}	
	}
}

/**
 * clear the form
 */
function clearForm() {
	alert ("clear");
}

/** 
 * limit the input of textfields
 */
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

/**
 * hide div objects
 **/
function hidediv(divname) {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(divname).style.visibility = 'hidden'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.divname.visibility = 'hidden'; 
		} else { // IE 4 
			document.all.divname.style.visibility = 'hidden'; 
		} 
	} 
}

/**
 * show div objects
 **/
function showdiv(divname) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById(divname).style.visibility = 'visible'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.divname.visibility = 'visible'; 
		} else { // IE 4 
			document.all.divname.style.visibility = 'visible'; 
		} 
	} 
}
