/***********************************************************************************************************
    Purpose: Verify that stringObject is in valid email address format and generate an error if it is not.
***********************************************************************************************************/
function validateEmailAddress(stringObject) 
{
		var atSymbol="@";
		var dot=".";
		var locationOfAtSymbol=stringObject.indexOf(atSymbol);
		var stringLength=stringObject.length;
		var locationOfDot=stringObject.indexOf(dot);
    var nonExistent=-1;
    var beginningOfString=0;
    
    //@ symbol non-existent or at beginning or end of the string
    if (stringObject.indexOf(atSymbol)==nonExistent 
        || stringObject.indexOf(atSymbol)==beginningOfString 
        || stringObject.indexOf(atSymbol)==stringLength)
    {
       alert("Please enter a valid email address.");
       return false;
    }

    //dot non-existent or at beginning or end of the string
		if (stringObject.indexOf(dot)==nonExistent 
        || stringObject.indexOf(dot)==beginningOfString 
        || stringObject.indexOf(dot)==stringLength)
    {
		    alert("Please enter a valid email address.");
		    return false;
		}

    //multiple @ symbols
    if (stringObject.indexOf(atSymbol,(locationOfAtSymbol+1))!=nonExistent)
    {
        alert("Please enter a valid email address.");
        return false;
    }

    //dot appears directly on either side of the @ symbol
    if (stringObject.substring(locationOfAtSymbol-1,locationOfAtSymbol)==dot 
        || stringObject.substring(locationOfAtSymbol+1,locationOfAtSymbol+2)==dot)
    {
		    alert("Please enter a valid email address.");
		    return false;
    }

    //dot does not appear to the right of the @ symbol
    if (stringObject.indexOf(dot,(locationOfAtSymbol+2))==nonExistent)
    {
		    alert("Please enter a valid email address.");
		    return false;
		}
		
    //spaces in the address
		 if (stringObject.indexOf(" ")!=nonExistent)
     {
		    alert("Please enter a valid email address.");
		    return false;
		 }

 		 return true;
	}

/***********************************************************************************************************
    Purpose: Verify that the required fields for the ContactUs form are populated and valid
***********************************************************************************************************/
function validateContactUsForm(formObject)
{
    var userName=formObject.Name;
    var emailAddress=formObject.Email;
    var subjectText=formObject.Subject;
    var commentText=formObject.comments;
    
    if ((userName.value==null)||(userName.value==""))
    {
        alert("Please enter your name.");
        userName.focus();
        return false;
    }
    if ((emailAddress.value==null)||(emailAddress.value==""))
    {
        alert("Please enter your email address.");
        emailAddress.focus();
        return false;
    }
    if (validateEmailAddress(emailAddress.value)==false)
    {
        emailAddress.value="";
        emailAddress.focus();
        return false;
    }
    if ((subjectText.value==null)||(subjectText.value==""))
    {
        alert("Please enter a subject.");
        subjectText.focus();
        return false;
    }
    if ((commentText.value==null)||(commentText.value==""))
    {
        alert("Please enter a comment.");
        commentText.focus();
        return false;
    }
    return true;
}

/***********************************************************************************************************
    Purpose: Verify that the required fields for the IndividualHOQTemplateRequest form are populated and valid
***********************************************************************************************************/
function validateIndividualHOQTemplateRequestForm(formObject)
{
    var userName=formObject.Name;
    var emailAddress=formObject.Email;
    var acquaintedText=formObject.acquaintedWithQFDThrough;
    
    if ((userName.value==null)||(userName.value==""))
    {
        alert("Please enter your name.");
        userName.focus();
        return false;
    }
    if ((emailAddress.value==null)||(emailAddress.value==""))
    {
        alert("Please enter your email address.");
        emailAddress.focus();
        return false;
    }
    if (validateEmailAddress(emailAddress.value)==false)
    {
        emailAddress.value="";
        emailAddress.focus();
        return false;
    }
    if ((acquaintedText.value==null)||(acquaintedText.value==""))
    {
        alert("Please explain how you first became acquainted with \nQuality Function Deployment (QFD) and the House of Quality.");
        acquaintedText.focus();
        return false;
    }
    return true;
}

/***********************************************************************************************************
    Purpose: Verify that the required fields for the TemplateRequest form are populated and valid
***********************************************************************************************************/
function validateTemplateRequestForm(formObject)
{

    var userName=formObject.Name;
    var emailAddress=formObject.Email;
    var intendedUseForTemplates=formObject.intendedUse;

    if ((userName.value==null)||(userName.value==""))
    {
        alert("Please enter your name.");
        userName.focus();
        return false;
    }
    if ((emailAddress.value==null)||(emailAddress.value==""))
    {
        alert("Please enter your email address.");
        emailAddress.focus();
        return false;
    }
    if (validateEmailAddress(emailAddress.value)==false)
    {
        emailAddress.value="";
        emailAddress.focus();
        return false;
    }
    if (intendedUseForTemplates.selectedIndex==0)
    {
        alert("Please indicate your primary intended use for the templates.");
        intendedUseForTemplates.focus();
        return false;
    }
    return true;
}

/***********************************************************************************************************
    Purpose: Verify that the required fields for the TemplateRequestSubscription form are populated and valid
***********************************************************************************************************/
function validateTemplateRequestSubscriptionForm(formObject)
{

    var userName=document.getElementById("name");
    var emailAddress=document.getElementById("l225272-225272");
    var intendedUseForTemplates=document.getElementById("IntendedUse");

    if ((userName.value==null)||(userName.value==""))
    {
        alert("Please enter your name.");
        userName.focus();
        return false;
    }
    if ((emailAddress.value==null)||(emailAddress.value==""))
    {
        alert("Please enter your email address.");
        emailAddress.focus();
        return false;
    }
    if (validateEmailAddress(emailAddress.value)==false)
    {
        emailAddress.value="";
        emailAddress.focus();
        return false;
    }
    if (intendedUseForTemplates.selectedIndex==0)
    {
        alert("Please indicate your primary intended use for the templates.");
        intendedUseForTemplates.focus();
        return false;
    }
    return true;
}
