function subscribeformSubmit()
{
	var result = false;
	document.getElementById('validationmessage').innerHTML = '';

	//If the whole form has not been made visible, show it, otherwise validate and submit the form
	if (document.getElementById('subscribeform').style.display =='none')
	{
		document.getElementById('subscribeform').style.display = 'block';
	}
	else
	{
		if (!(isValidEmail(document.getElementById('EMAIL').value)) )
		{
			document.getElementById('validationmessage').innerHTML = 'Email is not valid<br>';
		}
		else if (document.getElementById('EMAIL').value != document.getElementById('confirmemail').value)
		{
			document.getElementById('validationmessage').innerHTML = document.getElementById('validationmessage').innerHTML + 'Email is not entered or does not match confirmation email<br>';
		}
		else if (document.getElementById('FIRSTNAME').value == '')
		{
			document.getElementById('validationmessage').innerHTML = document.getElementById('validationmessage').innerHTML + 'First Name is empty or not valid';
		}
		else if (document.getElementById('LASTNAME').value == '')
		{
			document.getElementById('validationmessage').innerHTML = document.getElementById('validationmessage').innerHTML + 'Last Name is empty or not valid';
		}
		else
		{
			//everything is valid, submit the form
			//document.getElementById('subscribeform').submit();
			result = true;
		}
	}

	return result;
}

/* validate email address*/
function isValidEmail(strValue)
{
  //1.must have 5 chars
  var blnLength = false;
  if (strValue.length >= 5){
	blnLength = true;
  }
  var strVLength = strValue.length;

  //2.must have '@' sign in str
  var blnAt = false;
  for (var x = 0; x < strVLength; x++)
  {
    if (strValue.charAt(x) == "@"){
	blnAt = true;
    }
  }

  //3. must have a period after the at but not first and last character
  var isAt = strValue.indexOf("@");
  var afterAt = strValue.substr(isAt + 1);
  var blnPeriod = false;
			    
  // make sure string exists
  if (afterAt.length > 0){
	if ((afterAt.charAt(0) == ".")||		
	    (afterAt.charAt(afterAt.length-1) == ".")){
	    	blnPeriod = false;
	    }
		//if string is greater than 2 
		//(else previous if statement would have assigned a value to blnPeriod)
						
		if (afterAt.length > 2){
			for (var x = 1; x < afterAt.length-1; x++){
				if (afterAt.charAt(x) == "."){
					blnPeriod = true;
				}
			}
		}				
	}
			 
			
	if ( (blnAt) && (blnPeriod) && (blnLength) ){
		return true;
	}
	else{
		return false;
	}
			 
}


