
/*
	This javacript file is mainly used by the forms which are public (contactus, free trial..)
    Srinivas
*/


//--- variables -----
var i

function ValidateNominationForm()
{
	var fm = document.FormEmail
	
	if ((fm.UserName.value == '') || (fm.UserTel.value == '') || (fm.UserEmail.value == ''))
	{
		alert('Enter fields marked *')
	}
	else if (ValidateEmail(fm.UserEmail.value))
	{
		alert('Invalid Email Address')
	}
	else if (ValidatePhone(fm.UserTel.value))
	{	
		alert('Invalid Phone Number')
	}
	
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}	
}

//************************************************************************************




function ValidateNomination()
{
	var fm = document.FormEmail
	
	if ((fm.UserName.value == '') || (fm.UserTel.value == '') || (fm.Category.value == '') || (fm.Award.value == '') || (fm.UserEmail.value == ''))
	{
		alert('Enter fields marked *')
	}
	else if (ValidateEmail(fm.UserEmail.value))
	{
		alert('Invalid Email Address')
	}
	else if (ValidatePhone(fm.UserTel.value))
	{	
		alert('Invalid Phone Number')
	}
	else if (ValidateZipCode(fm.UserZip.value))
	{
		alert('Invalid Zip Code')	
	}
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}	
}

//************************************************************************************

// Email Validation 

function ValidateEmail(email){
	var emailID=email
	
	if ((emailID==null)||(emailID=="")){
		return false
	}
	if (CheckEmail(emailID)==false){
		return true
	}
	return false
 }

function CheckEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

//*********************************************************************

//Phone Validation (Criteria is to check whether they are 10 digits or not: as per requirement by MI team)

function ValidatePhone(phonenumber)
{
	var NumCount = 0
	for(i=0;i< phonenumber.length; i++)
	{
		if (((phonenumber.charAt(i) >= "0") && (phonenumber.charAt(i) <= "9")))
		{
			NumCount = NumCount + 1
		}
	}
	
	if (NumCount == 10)
	{
		return false
	}
	else
	{
		return true
	}	
}

//************************************************************************

//Zip Code Validation (Criteria was to check whether it had 5 digits or not : as per requirement by MI)

function ValidateZipCode(zipcode)
{
	var NumCount = 0
	if (zipcode.length == 5)
	{
		for(i=0;i< zipcode.length; i++)
		{
			if (((zipcode.charAt(i) >= "0") && (zipcode.charAt(i) <= "9")))
			{
				NumCount = NumCount + 1
			}
		}
		if (NumCount == 5)
		{
			return false
		}
		else
		{
			return true
		}		
	}
	else
	{
		return true
	}
}

//*****************************************************************************
// This function returns true if nothing is selected in radio list sent as parameter

function IsRadioSelected(control)
{
	var sel = true
	if (control)
	{
		for(i=0;i < control.length; i++)
		{
			if (control[i].checked == true)
			{
				sel = false
				break
			}
			
		}	
	}
	return sel
}
//************************************************************************************

function ValidateEventOrder()
{
	var fm = document.FormEmail
	
	if ((fm.LastName.value == '') || (fm.FirstName.value=='') || (fm.UserCompany.value == '') || (fm.UserAddress.value=='') || (fm.UserCity.value=='') || (fm.UserState.value == '') || (fm.UserZip.value == '') || (fm.UserTel.value == '') || (fm.UserEmail.value == '') )
	{
		alert('Enter fields marked *')
	}
	else if (ValidateEmail(fm.UserEmail.value))
	{
		alert('Invalid Email Address')
	}
	else if (ValidatePhone(fm.UserTel.value))
	{	
		alert('Invalid Phone Number')
	}
	else if (ValidateZipCode(fm.UserZip.value))
	{
		alert('Invalid Zip Code')	
	}
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}	
}

//****************************************************************************************
