// JavaScript Document

///Left trim the string
function LTrim(str)
	{
	 if (str==null){return null;}
	      for(var i=0;str.charAt(i)==" ";i++);
	          return str.substring(i,str.length);
	}
	
///Right trim the string
function RTrim(str)
    {
      if 
      (str==null){return null;}
         for(var i=str.length-1;str.charAt(i)==" ";i--);
             return str.substring(0,i+1);
    }
    
 ///Trim the string
 function Trim(str)
     { 
      return LTrim(RTrim(str));
     }
	 
function IsValEmail(strControlName, strFieldName)
	{   var stremail;
		stremail=document.getElementById(strControlName).value;
		if ( stremail.length > 0)
		{
		var rgeExp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/ ;
		return IsValidData(strControlName, strFieldName, rgeExp, 'Invalid E-mail Id', false) ;
	    }
	}
	
// Function to validate a control for valid value.
	// If boolMatch is true then match the expression, else don't match the expression.
	function IsValidData(strControlName, strFieldName, rgeExp, strErrorMsg, boolMatch)
	{
		if (boolMatch)
		{
			if (document.getElementById(strControlName).value.search(rgeExp) >= 0)
			{
				//SetError(strFieldName, strErrorMsg) ;
				return false ;
			}
		}
		else
		{
			if (document.getElementById(strControlName).value.search(rgeExp) < 0)
			{
				//SetError(strFieldName, strErrorMsg) ;
				return false ;
			}
		}
		return true ;
	}
	
	function CheckSubscriptionEmail()

			{
				
				 if (Trim(document.getElementById('subbox').value) == '' || document.getElementById('subbox').value=='Enter your email address...')

					{

						//alert('Email can not be blank!');

						document.getElementById('lblError').innerHTML='Email address can not be blank!';

						document.getElementById('subbox').focus();

						//return false;

					}

				else if (IsValEmail('subbox','') == false)

							{

								//alert('Email is not valid!');

								document.getElementById('lblError').innerHTML='Email address is not valid!';

								document.getElementById('subbox').focus();

								//return false;

							}

				else

					{

						//return true;

						document.subscribeemail.submit();

					}

			}
			
function CheckSubscriptionEmailPopup()

			{
				
				 if (Trim(document.getElementById('subboxpopup').value) == '' || document.getElementById('subboxpopup').value=='Enter your email address...')

					{

						//alert('Email can not be blank!');

						document.getElementById('lblErrorpopup').innerHTML='Email address can not be blank!';

						document.getElementById('subboxpopup').focus();

						//return false;

					}

				else if (IsValEmail('subboxpopup','') == false)

							{

								//alert('Email is not valid!');

								document.getElementById('lblErrorpopup').innerHTML='Email address is not valid!';

								document.getElementById('subboxpopup').focus();

								//return false;

							}

				else

					{

						//return true;

						document.subscribeemailpopup.submit();

					}

			}
			
function CheckRequiredFields()

			{
				
				if (document.getElementById('txtEmail') != null && Trim(document.getElementById('txtEmail').value) == '')

					{

						//alert('Email can not be blank!');

						document.getElementById('spanError').innerHTML='Email address can not be blank!';

						document.getElementById('txtEmail').focus();

						//return false;

					}

				else if (document.getElementById('txtEmail') != null && IsValEmail('txtEmail','') == false)

					{

						//alert('Email is not valid!');

						document.getElementById('spanError').innerHTML='Email address is not valid!';

						document.getElementById('txtEmail').focus();

						//return false;

					}
				 
				 else if (document.getElementById('ddlState') != null && Trim(document.getElementById('ddlState').value) == '')

					{

						//alert('Email can not be blank!');

						document.getElementById('spanError').innerHTML='Please select a state';

						document.getElementById('ddlState').focus();

						//return false;

					}
					
				else if (document.getElementById('txtState') != null && Trim(document.getElementById('txtState').value) == '')

					{

						//alert('Email can not be blank!');

						document.getElementById('spanError').innerHTML='Please select a state';

						document.getElementById('txtState').focus();

						//return false;

					}

				else

					{

						//return true;

						document.subscriptionform.submit();

					}

			}