// Form validation and general functions

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function toggleDisplay(currMenu) {
	if (document.getElementById) {
		thisMenu = document.getElementById(currMenu).style
		if (thisMenu.display == "block") {
			thisMenu.display = "none"
			}
		else {
			thisMenu.display = "block"
			}
		return true
		}
	else {
		return true
		}
}

function redirect(URLStr) { location = URLStr; }

function isNotEmpty(String) {
   // Return false if "string" is empty or all blank
  if (String.length == 0) {return (false);}
  for (var i=0; i < String.length; i++) {
    if (String.substring(i) != " ") {return (true);}
  }
  return (false);
}

function validateHomeForm(contactform) {
	var strFullName=contactform.FullName.value,
	 	strCompany=contactform.Company.value,
		strPhone=contactform.Phone.value,
	 	strEmail=contactform.Email.value,
		strNumEmployees=contactform.Employees.value,	
		errors='';
		
	var normalizedPhone = stripCharsInBag(strPhone, phoneNumberDelimiters);
		
	if (!isNotEmpty(strFullName)) { 
		errors+='Name is required\n';
		}
	if (!isNotEmpty(strCompany)) { 
		errors+='Company is required\n';
		}
	if (!isNotEmpty(strNumEmployees)) { 
		errors+='# of employees is required\n';
		}
	if (!isUSPhoneNumber(normalizedPhone)) { 
		errors+='A valid 10 digit Phone Number is required, e.g. 999-999-9999\n';
		}		
	if (!isEmail(strEmail, false))  {
		errors+='The Email Address entered is invalid\n';
		}

	if (isNotEmpty(errors)) {
		alert('The following error(s) occurred:\n'+errors);
		return (false);
		}
	return (true); 
}

function validateForm(contactform) {
	var strFullName=contactform.FullName.value,
	 	strCompany=contactform.Company.value,
		strAddress=contactform.Address.value,
		strCity=contactform.City.value,
		strZip=contactform.Zip.value,
		strPhone=contactform.Phone.value,
	 	strEmail=contactform.Email.value,	
		errors='';
		
	var normalizedPhone = stripCharsInBag(strPhone, phoneNumberDelimiters);
		
	if (!isNotEmpty(strFullName)) { 
		errors+='Full Name is required\n';
		}
	if (!isNotEmpty(strCompany)) { 
		errors+='Company is required\n';
		}
	if (!isNotEmpty(strAddress)) { 
		errors+='Address is required\n';
	}
	if (!isNotEmpty(strCity)) { 
		errors+='City is required\n';
	}
	if (!isNotEmpty(strZip)) { 
		errors+='Zipcode is required\n';
	}
	if (!isUSPhoneNumber(normalizedPhone)) { 
		errors+='A valid 10 digit Phone Number is required, e.g. 999-999-9999\n';
		}		
	if (!isEmail(strEmail, false))  {
		errors+='The Email Address entered is invalid\n';
		}

	if (isNotEmpty(errors)) {
		alert('The following error(s) occurred:\n'+errors);
		return (false);
		}
	return (true); 
}

