// JavaScript Document


window.onload = function() {
  setFooter();
}
window.onresize = function() {
  setFooter();
}

function openSTut(str) {
	window.open('common/stutPopup.asp?tutorial='+str,'_blank','width=800,height=570,top=0,left=0,scrollbars=no,location=no,toolbar=no,status=no,resizeable=no');
	}



// Check Contact feedback form
function checkContactForm() {
	//	Will be checked at end of function to determine whether form is sent
	var isValid = true;
	// get Form name
	var f = document.forms[0];
	// Create Error Msg Box
	var errors = "Please enter your information in the following required fields:               \n";

	if(f.firstname.value.length == 0)
	{
		errors += "\n\t *  A First Name is required.";
		isValid = false;	
	}
	if(f.surname.value.length == 0)
	{
		errors += "\n\t *  A Surname is required.";
		isValid = false;	
	}
	if(f.company.value.length == 0)
	{
		errors += "\n\t *  A Company Name is required.";
		isValid = false;	
	}	
	if(f.email.value.length == 0)
	{
		errors += "\n\t *  A Contact Email is required.";
		isValid = false;
	}
	 else
	{
		// Check for Properly Formatted Email Addresses
		if (!(isValidEmail(f.email.value))) {
			errors += "\n\t * A properly formatted Email address is required.";
			isValid = false;
		}
	}
	if(f.phone.value.length == 0)
	{
		errors += "\n\t *  A Contact Telephone Number is required.";
		isValid = false;	
	}
	if(f.findus.options[0].selected==true)
	{
		errors += "\n\t *  Please select where you found us.";
		isValid = false;	
	}
	
	if(!isValid)
	{
		alert(errors);
		return false;
	}
	else
		return true;
}












// Check Download form
function checkDownloadForm() {
	//	Will be checked at end of function to determine whether form is sent
	var isValid = true;
	// get Form name
	var f = document.forms[0];
	// Create Error Msg Box
	var errors = "Please enter your information in the following required fields:               \n";

		if(f.f_name.value.length == 0)
	{
		errors += "\n\t *  A First Name is required.";
		isValid = false;	
	}
		if(f.l_name.value.length == 0)
	{
		errors += "\n\t *  A Surname is required.";
		isValid = false;	
	}
	if(f.jobtitle.value.length == 0)
	{
		errors += "\n\t *  A Job Title is required.";
		isValid = false;	
	}
	if(f.email.value.length == 0)
	{
		errors += "\n\t *  A Contact Email is required.";
		isValid = false;	
	}
	if(f.company.value.length == 0)
	{
		errors += "\n\t *  A Company Name is required.";
		isValid = false;	
	}
	
	if(f.addr1.value.length == 0)
	{
		errors += "\n\t *  An Address is required.";
		isValid = false;	
	}
	if(f.postalcode.value.length == 0)
	{
		errors += "\n\t *  A Post Code is required.";
		isValid = false;	
	}
	
	
	if(f.country.options[0].selected==true)
	{
		errors += "\n\t *  Please select your company's Country of origin.";
		isValid = false;	
	}
	if(f.country.options[2].selected==true)
	{
		errors += "\n\t *  Please select your company's Country of origin.";
		isValid = false;	
	}
	
	
	
	if(f.email.value.length == 0)
	{
		errors += "\n\t *  A Contact Email is required.";
		isValid = false;
	}
	 else
	{
		// Check for Properly Formatted Email Addresses
		if (!(isValidEmail(f.email.value))) {
			errors += "\n\t * A properly formatted Email address is required.";
			isValid = false;
		}
	}
	if(f.phone.value.length == 0)
	{
		errors += "\n\t *  A Contact Telephone Number is required.";
		isValid = false;	
	}
	if(f.req.options[0].selected==true)
	{
		errors += "\n\t *  Please select what you plan on using VMPro2 for.";
		isValid = false;	
	}
	
	if(!isValid)
	{
		alert(errors);
		return false;
	}
	else
		return true;
}



// Check for valid Email Address
function isValidEmail(str) {
   return (str.indexOf(".") >= 1) && (str.indexOf("@") > 0);
}


// Check for matching Passwords
function checkPassword(str1, str2) {
	if (str1 == str2) {
		  return true;
		} else {
		  return false;
		}
}


// Set country menu to remove UK
function sortMenu() {
	var f = document.forms[0]
	var listLength = f.country.length;
	// loop through list to fin UK
	for (c = 200; c < (listLength-5); c++)
	{
		//remove UK option
		if (f.country.options[c].value == "United Kingdom")
		{
			f.country.options[c] = null;
		}
	}
}
















/*  footer  */
function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight= window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight= document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}


function setFooter() {
if (document.getElementById) {
var windowHeight=getWindowHeight();
if (windowHeight>0) {
  var contentHeight= document.getElementById('contentWrapper').offsetHeight;
  var footerElement= document.getElementById('footer');
  var footerHeight=footerElement.offsetHeight;
	if (windowHeight-(contentHeight+footerHeight)>=0) {
  	  footerElement.style.position='relative';
  	  footerElement.style.top=(windowHeight-
  	  (contentHeight+footerHeight))+'px';
	}
  	else {
	  footerElement.style.position='static';
 	}
  }
}
}
