function validateContact(){	
	var emailV = 1;
	if(document.contact.name.value=="" || document.contact.email.value=="" || document.contact.message.value==""){
		alert("Please fill in the required fields");
		return false;
	}
	
	email = document.contact.email.value;
	if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        emailV = 0;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        emailV = 0;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        emailV = 0;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		emailV = 0;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
		emailV = 0;
    }
    
    if(emailV == 0){
		alert("Please enter a valid email address");
		return false;
	}
}

function validateNewsletter(){
	var emailV = 1;
	if(document.newsletter_form.name.value=="" || document.newsletter_form.email.value=="" ){
		alert("Please fill in the required fields");
		return false;
	}
	
	email = document.newsletter_form.email.value;
	 if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        emailV = 0;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        emailV = 0;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        emailV = 0;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		emailV = 0;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
		emailV = 0;
    }
    
    if(emailV == 0){
		alert("Please enter a valid email address");
		return false;
	}
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function openimage(image, w, h){

	window.open(image, "newWind", "menubar=0,status=0,resizable=1, width="+w+", height="+h);
}

function validateLogin(){
	if(document.login.username.value=="" || document.login.pass.value=="" ){
		alert("Please fill in the required fields");
		return false;
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      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
         }
      }
   }    
}

