
/*****************************************************************************************************************
	This javacript file is mainly used by the forms which are public (contactus, free trial..)
    Srinivas Komma
    Added new function "ValidateAndSubmitEmailToFriend" For Email to fiend page - 2/12/2008 : Srinivas Komma
******************************************************************************************************************
*/

//--- variables -----
var i

//--------------------
function ValidateAndSubmitInnerLoop ()
{		
	var fm = document.FormEmail
	
	if (IsRadioSelected(fm.SummerParty) || IsRadioSelected(fm.HolidayParty))
		{
		alert("Please choose both summer and holiday party option")
	}
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}
}


//********************************************************************************************************************************
function ValidateAndSubmitWWForm()
{		
	var fm = document.WedWeekly_Form
	
	if ((fm.TxtFullName.value == '') || (fm.TxtCompany.value=='') || (fm.TxtPhone.value == '') || (fm.TxtEmail.value=='') || IsRadioSelected(fm.ContactMe))
	{
		alert("Enter fields marked *");
		return false;
	}
	else if (ValidateEmail(fm.TxtEmail.value))
	{
		alert('Invalid Email Address');
		return false;
	}
	else if (ValidatePhone(fm.TxtPhone.value))
	{	
		alert('Invalid Phone Number')
		return false;
	}
	else
	{
		fm.vmode.value="send"
		return true;
	}
}

//********************************************************************************************************************************
function ValidateAndSubmitContactUsForm ()
{		
	var fm = document.ContactUs2_Form

	if ((fm.TxtFullName.value == '') || (fm.TxtCompany.value=='') || (fm.TxtPhone.value == '') || (fm.TxtEmail.value=='') || (fm.ListHearAbtUs.value == '')|| (fm.chkContactME.checked==false && fm.ChkPress.checked==false && fm.ChkWW.checked==false))
	{
		alert("Enter fields marked *");
		if ((fm.TxtFullName.value == '') && (fm.TxtCompany.value=='') && (fm.TxtPhone.value == '') && (fm.TxtEmail.value==''))
		{
			fm.TxtFullName.style.background='#C6EDFF';
			fm.TxtCompany.style.background='#C6EDFF';
			fm.TxtPhone.style.background='#C6EDFF';
			fm.TxtEmail.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtFullName.style.background='';
			fm.TxtCompany.style.background='';
			fm.TxtPhone.style.background='';
			fm.TxtEmail.style.background='';
		}
		if (fm.TxtFullName.value == '')
		{
			fm.TxtFullName.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtFullName.style.background='';
		}

		if (fm.TxtCompany.value == '')
		{
			fm.TxtCompany.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtCompany.style.background='';
		}

		if (fm.TxtPhone.value == '')
		{
			fm.TxtPhone.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtPhone.style.background='';
		}

		if (ValidateEmail(fm.TxtEmail.value) == '')
		{
			fm.TxtEmail.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtEmail.style.background='';
		}
	
		return false;
	}
	else if (ValidateEmail(fm.TxtEmail.value))
	{
		alert('Invalid Email Address');
		return false;
	}
	else if (ValidatePhone(fm.TxtPhone.value))
	{	
		alert('Invalid Phone Number')
		return false;
	}
	else
	{
		fm.vmode.value="send"
		//fm.submita.class="btn_submit_disable"
		//fm.btn_submit.disabled=true
		return true;
	}
}
//********************************************************************************************************************************







//********************************************************************************************************************************
function ValidateAndSubmitGSAWhitepaperBisnow ()
{		
	var fm = document.GSAWhitePaperBisNow

	if ((fm.TxtFullName.value == '') || (fm.TxtCompany.value=='')  ||  (fm.TxtPhone.value=='') ||  (fm.TxtEmail.value==''))
	{
		alert("Enter fields marked *");
		if ((fm.TxtFullName.value == '') && (fm.TxtCompany.value=='') && (fm.TxtPhone.value=='') && (fm.TxtEmail.value==''))
		{
			fm.TxtFullName.style.background='#C6EDFF';
			fm.TxtCompany.style.background='#C6EDFF';
			fm.TxtPhone.style.background='#C6EDFF';
			fm.TxtEmail.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtFullName.style.background='';
			fm.TxtCompany.style.background='';
			fm.TxtPhone.style.background='';
			fm.TxtEmail.style.background='';
		}
		if (fm.TxtFullName.value == '')
		{
			fm.TxtFullName.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtFullName.style.background='';
		}

		if (fm.TxtCompany.value == '')
		{
			fm.TxtCompany.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtCompany.style.background='';
		}
		if (fm.TxtPhone.value == '')
		{
			fm.TxtPhone.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtPhone.style.background='';
		}
		
		if (ValidateEmail(fm.TxtEmail.value) == '')
		{
			fm.TxtEmail.style.background='#C6EDFF';
		}
		else
		{
			fm.TxtEmail.style.background='';
		}
	
		return false;
	}
	else if (ValidateEmail(fm.TxtEmail.value))
	{
		alert('Invalid Email Address');
		return false;
	}
	else if (ValidatePhone(fm.TxtPhone.value))
	{
		alert('Invalid Phone Number');
		return false;
	}
	else
	{
		fm.vmode.value="send"
		//fm.submita.class="btn_submit_disable"
		//fm.btn_submit.disabled=true
		return true;
	}
}
//********************************************************************************************************************************













function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || " ";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || " ";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ValidatePasswordServices()
{
	var fm = document.FormEmail
	
	if ((fm.LastName.value == '') || (fm.FirstName.value=='') || (fm.UserCompany.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 ValidateFreeTrial()
{
	var fm = document.FormEmail
	
	if ((fm.LastName.value == '') || (fm.FirstName.value=='') || (fm.UserCompany.value == '') || (fm.UserAddress.value=='') || (fm.UserCity.value=='') || (fm.UserState.value == '') || (fm.hear.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)
	}	
}

//****************************************************************************************

function ValidateFsiIntel()
{
	var fm = document.FormEmail
	
	if (fm.UserEmail.value == '')
	{
		alert('Please enter a valid Email Address')
	}
	else if (ValidateEmail(fm.UserEmail.value))
	{
		alert('Invalid Email Address')
		fm.UserEmail.focus()
	}
	else
	{
		if (fm.Enable.checked)
		{
			fm.send.value = 'true'
			fm.action = 'fsintel.asp'
			fm.submit(this.form)
		}
		else
		{			
			fm.action = 'fsintelform.asp'
			fm.submit(this.form)
		}
	}
}
//****************************************************************************************

function ValidateFsiIntelForm()
{
	var fm = document.FormEmail
	
	if ((fm.FirstName.value == '') || (fm.LastName.value == '') || (fm.Company.value == '') || (fm.Address.value=='') || (fm.City.value=='') || (fm.ZipCode.value == '') || (fm.Phone.value == '') || (fm.Email.value == '') )
	{
		alert('Enter fields marked *')
	}
	else if (ValidateEmail(fm.Email.value))
	{
		alert('Invalid Email Address')
	}
	else if (fm.Country.value == 'US')
	{
		if (fm.State.value == 'XX')
		{
			alert('Select State')	
		}
		else if (ValidatePhone(fm.Phone.value))
		{	
			alert('Invalid Phone Number')
		}
		else if (ValidateZipCode(fm.ZipCode.value))
		{
			alert('Invalid Zip Code')	
		}
		else if ( fm.CurrentEmail.value != fm.Email.value )
		{
			if (confirm("You are about to change your email address"))
			{
				fm.vmode.value="send"
				fm.submit(this.form)
			}
		}
		else
		{
			fm.vmode.value="send"
			fm.submit(this.form)
		}
	}
	else if ( fm.CurrentEmail.value != fm.Email.value )
	{
		if (confirm("You are about to change your email address"))
		{
			fm.vmode.value="send"
			fm.submit(this.form)
		}
	}
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}	
}
//************************************************************************************

function ValidateEventsAlert()
{
	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)
	}
}
//************************************************************************************

function ValidateContactUpdate()
{
	var fm = document.FormEmail
	
	if ((fm.LastName.value == '') || (fm.FirstName.value=='') || (fm.UserCompany.value == '') || (fm.UserEmail.value == '') || (fm.LastName2.value == '') || (fm.FirstName2.value=='') || (fm.UserCompany2.value == '') || (fm.UserEmail2.value == ''))
	{
		alert("Enter fields marked *")		
	}
	else if (ValidateEmail(fm.UserEmail.value))
	{
		alert ('Invalid Email Address')
		fm.UserEmail.focus()
	}
	else if (ValidateEmail(fm.UserEmail2.value))
	{
		alert ('Invalid Email Address')
		fm.UserEmail2.focus()
	}
	else if ((fm.LastName.value.toUpperCase() == fm.LastName2.value.toUpperCase() ) && (fm.FirstName.value.toUpperCase() == fm.FirstName2.value.toUpperCase()) && (fm.UserCompany.value.toUpperCase() == fm.UserCompany2.value.toUpperCase()) && (fm.UserEmail.value.toUpperCase() == fm.UserEmail2.value.toUpperCase()) )
	{
		alert ('New and Old Information are identical')
	}
	else
	{
		fm.vmode.value="send"
		fm.submit(this.form)
	}
}
//************************************************************************************

function ValidateAndSubmitEmailToFriend()
{
    var fm = document.MainForm
    
    if (IsEmptyTextField(fm.ToEmail.value) || IsEmptyTextField(fm.FromEmail.value))
        {
            alert('Please enter fields marked *');
        }
    else
        {
           if (ValidateEmail(fm.ToEmail.value) || ValidateEmail(fm.FromEmail.value) || ( !(IsEmptyTextField(fm.ToEmail1.value)) && (ValidateEmail(fm.ToEmail1.value))) || ( !(IsEmptyTextField(fm.ToEmail2.value)) && (ValidateEmail(fm.ToEmail2.value))) || ( !(IsEmptyTextField(fm.ToEmail3.value)) && (ValidateEmail(fm.ToEmail3.value))))
           {
                alert("Enter valid Email address");
           }
           else
           {
                fm.IsPostBack.value = "true"
	            fm.submit(this.form);
           }
        }   
}
//************************************************************************************

//************************************************************************************

function ValidateAndSubmitOutlookRegister08()
{
    var fm = document.RegisterEvent
    
    if (IsEmptyTextField(fm.UserName.value) || IsEmptyTextField(fm.Email.value))
        {
            alert('Please enter fields marked *');
        }
    else
        {
           if (ValidateEmail(fm.Email.value))
           {
                alert("Enter valid Email address");
           }
           else
           {
                fm.IsPostBack.value = "true"
	            fm.submit(this.form);
           }
        }   
}
//************************************************************************************


//******** To find whether a string is empty******************************************
function IsEmptyTextField (s)
      {
           var i;
           var whitespace = " \t\n\r";
           if ((s == null) || (s.length == 0)) 
           {
                return true;
           }
           for (i = 0; i < s.length; i++)
           {
                var c = s.charAt(i);
                if (whitespace.indexOf(c) == -1) return false;
           }
           return true;
      }
//************************************************************************************

// 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)
	}	
}

//****************************************************************************************



























