﻿// JScript File
    function AlphabetsOnly()
    {
        var is_char;
        is_char = event.keyCode;
        if((is_char>=65 && is_char<=90) ||(is_char>=97 && is_char<=122)||is_char==32)
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }
    
    function AlphaNumeric()
    {
        var is_char;
        is_char = event.keyCode;
        if((is_char>=65 && is_char<=90) ||(is_char>=97 && is_char<=122)||(is_char>=48 && is_char<=57)||is_char==32)
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }
    
    function AllowAddress()
    {
   
        var is_char;
        is_char = event.keyCode;
        if(is_char!=124 && is_char!=60 && is_char!=62)
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }
    
    function AllowPhoneNumber()
    {
        var is_char;
        is_char = event.keyCode;
        if((is_char>=48 && is_char<=57)|| is_char==40 || is_char==41 || is_char==43 || is_char==45 )
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }
    
     function AllowEmail()
    {
        var is_char;
        is_char = event.keyCode;
        if((is_char>=65 && is_char<=90) ||(is_char>=97 && is_char<=122)||(is_char>=48 && is_char<=57)||is_char==95||is_char==46||is_char==64||is_char==45)
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }
    
    function ValidateOnRegSubmit()
    {
    if(TrimAll(document.getElementById("tbFirstName").value,' ')=="")
        {
            alert("Please enter First Name.");
		    document.getElementById("tbFirstName").focus();
		    return false;
		}
	  if(TrimAll(document.getElementById("tbLastName").value,' ')=="")
        {
            alert("Please enter Last Name.");
		    document.getElementById("tbLastName").focus();
		    return false;
		}
		  if(TrimAll(document.getElementById("tbLocation").value,' ')=="")
        {
            alert("Please enter your Location.");
		    document.getElementById("tbLocation").focus();
		    return false;
		}	
	    if(TrimAll(document.getElementById("tbCompanyName").value,' ')=="")
        {
            alert("Please enter your Company Name.");
		    document.getElementById("tbCompanyName").focus();
		    return false;
		}
		   if(TrimAll(document.getElementById("tbDesignation").value,' ')=="")
        {
            alert("Please enter your Designation.");
		    document.getElementById("tbDesignation").focus();
		    return false;
		}
		
		if(TrimAll(document.getElementById("tbEmailWork").value,' ')=="" && TrimAll(document.getElementById("tbEmailPersonal").value,' ')=="")
        {
            alert("Please enter atleast one Email Address.");
		    document.getElementById("tbEmailWork").focus();
		    return false;
		}
		else
		{
		var tbWork=document.getElementById("tbEmailWork");
		var tbPers=document.getElementById("tbEmailPersonal");
		if(document.getElementById("tbEmailWork").value!="")
		{
		    if(!isValidEmail(document.getElementById("tbEmailWork")))
			    {
			    document.getElementById("tbEmailWork").focus();
			    return false;
			    }
		}
			
		if(TrimAll(document.getElementById("tbEmailPersonal").value,' ')!="")
		{
		    if(!isValidEmail(document.getElementById("tbEmailPersonal")))
			    {
			    document.getElementById("tbEmailPersonal").focus();
			    return false;
			    }
		}
		}
		
function isValidEmail(oEMailField) {// function for check mail validation
try{
	if(oEMailField.value == "")	
	{
		return true;
	}

	var good_chars_arr	= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	var MailArray		= oEMailField.value.split(",");
	var iMailIndex		= 0;
	var retval			= true;
	
	for (iMailIndex = 0; iMailIndex < MailArray.length; iMailIndex++) {

		if ((MailArray[iMailIndex]).length == 0) {//if (trim(MailArray[iMailIndex]).length == 0) {
			alert("Each of the string literals separated by commas should be valid e-mail ids.");
			oEMailField.focus();
			return false;
		} else if (MailArray[iMailIndex].substring(MailArray[iMailIndex].length - 1, MailArray[iMailIndex].length) == "@") {
			alert("The Email address should not end with '@'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(0, 1) == "@") {
			alert("The Email address should not begin with '@'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(0, 1) == ".") {
			alert("The Email address should not begin with '.'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(MailArray[iMailIndex].length - 1, MailArray[iMailIndex].length) == ".") {
			alert("The Email address should not end with '.'");
			oEMailField.focus();		
			//retval = false;
			return false;
		} else {
			var flag1 = 1;
			if (MailArray[iMailIndex] != "") {
				var flag = 0;
				for (var i = 0; i < MailArray[iMailIndex].length; i++) {
					if (MailArray[iMailIndex].substring(i, i + 1) == "@") {
						flag = 1;
					}
				}
				if (flag == 0) {
					flag1 = 0;
					alert("The Email Address field does not contain an @.");
					oEMailField.focus();
				} else {
					flag = 0;
					for (var i = 0; i < MailArray[iMailIndex].length; i++) {
						if (MailArray[iMailIndex].substring(i, i + 1) == ".") {
							flag = 1;
						}
					}
					if (flag == 0) {
						flag1 = 0;
						alert("The Email Address field does not contain a dot.");
						oEMailField.focus();
					}
				}
				if (flag != 0) {
					if (MailArray[iMailIndex].indexOf('@') !=  MailArray[iMailIndex].lastIndexOf('@')) {
						flag1 = 0;
						alert("The Email address contains more than one @ characters");
						oEMailField.focus();
					} else if ((MailArray[iMailIndex].charAt(MailArray[iMailIndex].indexOf('@') + 1) ==  '.') || 
							   (MailArray[iMailIndex].charAt(MailArray[iMailIndex].indexOf('@') - 1) ==  '.')) {
						flag1 = 0;
						alert("The Email address cannot contain '@' and '.' in sequence");
						oEMailField.focus();
					} else if (MailArray[iMailIndex].indexOf('@') > MailArray[iMailIndex].lastIndexOf('.')) {
						flag1 = 0;
						alert("The Email address should not contain a '@' after the last '.'");
						oEMailField.focus();
					} else if (MailArray[iMailIndex].indexOf('..') > 0) {
						flag1 = 0;
						alert("The Email address should not contain consecutive '.'s.");
						oEMailField.focus();
					}
				}
			}

			if (flag1 == 0) {
				//retval = retval && false;
				return false;
			} else {
				retval = retval && true;
				//return true;
			}

		}
	}
	//alert('retval from email check=' + retval);
	return retval;
	}catch(e){return false;}
}	
		
		
    }
    
   function NumbersOnly()
    {
        var is_char;
        is_char = event.keyCode;
        if(is_char>=48 && is_char<=57)
        {
        return true;
        }
        else
        {
        event.keyCode=0;
        return false;
        }
    }    
//**************************************************************SUBSCRIPTION******************************************
    function ValidateOnSubscrptSubmit()
    {
   
        if( TrimAll(document.getElementById("tbFirstName").value,' ')=="")
        {
            alert("Please enter First Name.");
		    document.getElementById("tbFirstName").focus();
		    return false;
		}
		 
		 if(TrimAll(document.getElementById("tbLastName").value,' ')=="")
        {
            alert("Please enter Last Name.");
		    document.getElementById("tbLastName").focus();
		    return false;
		}
    
    	 if(TrimAll(document.getElementById("tbCompanyName").value,' ')=="")
        {
            alert("Please enter Company Name.");
		    document.getElementById("tbCompanyName").focus();
		    return false;
		}
		 if(TrimAll(document.getElementById("tbEmail").value,' ')=="")
        {
            alert("Please enter Email Address.");
		    document.getElementById("tbEmail").focus();
		    return false;
		}
		else
		{
		
		if(!isValidEmail(document.getElementById("tbEmail")))
			    {
			    document.getElementById("tbEmail").focus();
			    return false;
			    }
		}
		
		 if(TrimAll(document.getElementById("tbEmailRetype").value,' ')=="")
        {
            alert("Please Re-Enter Email Address.");
		    document.getElementById("tbEmailRetype").focus();
		    return false;
		}
		else
		{
		
		if(!isValidEmail(document.getElementById("tbEmailRetype")))
			    {
			    document.getElementById("tbEmailRetype").focus();
			    return false;
			    }
		}
		
		
		  if(TrimAll(document.getElementById("tbEmailRetype").value,' ') != TrimAll(document.getElementById("tbEmail").value,' '))
        {
            alert("Email addresses doesn't match.");
            document.getElementById("tbEmailRetype").focus();
            document.getElementById("tbEmailRetype").value = "";
            document.getElementById("tbEmail").focus();
            document.getElementById("tbEmail").value = "";
            return false;
        }
        
         if(TrimAll(document.getElementById("tbBillingAdd1").value,' ')=="")
        {
            alert("Please enter Billing Address.");
		    document.getElementById("tbBillingAdd1").focus();
		    return false;
		}
        
           if(TrimAll(document.getElementById("tbCityTown").value,' ')=="")
        {
            alert("Please enter City/Town");
		    document.getElementById("tbCityTown").focus();
		    return false;
		}
		
		 if(TrimAll(document.getElementById("tbState").value,' ')=="")
        {
            alert("Please enter your State.");
		    document.getElementById("tbState").focus();
		    return false;
		}
        
        
         if(TrimAll(document.getElementById("tbPostalCode").value,' ')=="")
        {
            alert("Please enter your Postal Code/Zip.");
		    document.getElementById("tbPostalCode").focus();
		    return false;
		}
		
		if(TrimAll(document.getElementById("tbPhoneResidence").value,' ')=="" && TrimAll(document.getElementById("tbPhoneOffice").value,' ')=="" && TrimAll(document.getElementById("tbMobileNumber").value,' ')=="")
        {
            alert("Please enter atleast one phone number.");
		    document.getElementById("tbPhoneResidence").focus();
		    return false;
		}
		else
		{
		    if(TrimAll(document.getElementById("tbPhoneResidence").value,' ')!="")
		    {
		        if(TrimAll(document.getElementById("tbPhoneResidence").value,' ').length<10)
		            {
		            alert("Atleast 10 digits are required for Contact number.");
		            document.getElementById("tbPhoneResidence").focus();
		            return false;
		            }
		    }
		    
		     if(TrimAll(document.getElementById("tbPhoneOffice").value,' ')!="")
		    {
		        if(TrimAll(document.getElementById("tbPhoneOffice").value,' ').length<10)
		            {
		            alert("Atleast 10 digits are required for Contact number.");
		            document.getElementById("tbPhoneOffice").focus();
		            return false;
		            }
		    }
		    
		         if(TrimAll(document.getElementById("tbMobileNumber").value,' ')!="")
		    {
		        if(TrimAll(document.getElementById("tbMobileNumber").value,' ').length<10)
		            {
		            alert("Atleast 10 digits are required for Contact number.");
		            document.getElementById("tbMobileNumber").focus();
		            return false;
		            }
		    }
		}
		
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
function isValidEmail(oEMailField) {// function for check mail validation
try{
	if(oEMailField.value == "")	
	{
		return true;
	}

	var good_chars_arr	= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	var MailArray		= oEMailField.value.split(",");
	var iMailIndex		= 0;
	var retval			= true;
	
	for (iMailIndex = 0; iMailIndex < MailArray.length; iMailIndex++) {

		if ((MailArray[iMailIndex]).length == 0) {//if (trim(MailArray[iMailIndex]).length == 0) {
			alert("Each of the string literals separated by commas should be valid e-mail ids.");
			oEMailField.focus();
			return false;
		} else if (MailArray[iMailIndex].substring(MailArray[iMailIndex].length - 1, MailArray[iMailIndex].length) == "@") {
			alert("The Email address should not end with '@'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(0, 1) == "@") {
			alert("The Email address should not begin with '@'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(0, 1) == ".") {
			alert("The Email address should not begin with '.'");
			oEMailField.focus();
			//retval = false;
			return false;
		} else if (MailArray[iMailIndex].substring(MailArray[iMailIndex].length - 1, MailArray[iMailIndex].length) == ".") {
			alert("The Email address should not end with '.'");
			oEMailField.focus();		
			//retval = false;
			return false;
		} else {
			var flag1 = 1;
			if (MailArray[iMailIndex] != "") {
				var flag = 0;
				for (var i = 0; i < MailArray[iMailIndex].length; i++) {
					if (MailArray[iMailIndex].substring(i, i + 1) == "@") {
						flag = 1;
					}
				}
				if (flag == 0) {
					flag1 = 0;
					alert("The Email Address field does not contain an @.");
					oEMailField.focus();
				} else {
					flag = 0;
					for (var i = 0; i < MailArray[iMailIndex].length; i++) {
						if (MailArray[iMailIndex].substring(i, i + 1) == ".") {
							flag = 1;
						}
					}
					if (flag == 0) {
						flag1 = 0;
						alert("The Email Address field does not contain a dot.");
						oEMailField.focus();
					}
				}
				if (flag != 0) {
					if (MailArray[iMailIndex].indexOf('@') !=  MailArray[iMailIndex].lastIndexOf('@')) {
						flag1 = 0;
						alert("The Email address contains more than one @ characters");
						oEMailField.focus();
					} else if ((MailArray[iMailIndex].charAt(MailArray[iMailIndex].indexOf('@') + 1) ==  '.') || 
							   (MailArray[iMailIndex].charAt(MailArray[iMailIndex].indexOf('@') - 1) ==  '.')) {
						flag1 = 0;
						alert("The Email address cannot contain '@' and '.' in sequence");
						oEMailField.focus();
					} else if (MailArray[iMailIndex].indexOf('@') > MailArray[iMailIndex].lastIndexOf('.')) {
						flag1 = 0;
						alert("The Email address should not contain a '@' after the last '.'");
						oEMailField.focus();
					} else if (MailArray[iMailIndex].indexOf('..') > 0) {
						flag1 = 0;
						alert("The Email address should not contain consecutive '.'s.");
						oEMailField.focus();
					}
				}
			}

			if (flag1 == 0) {
				//retval = retval && false;
				return false;
			} else {
				retval = retval && true;
				//return true;
			}

		}
	}
	//alert('retval from email check=' + retval);
	return retval;
	}catch(e){return false;}
}


function TrimAll(sString,trimBy)
{
    while(sString.substring(0,1)==trimBy)
    {
    sString=sString.substring(1,sString.length);
    }

    while(sString.substring(sString.length-1,sString.length)==trimBy)
    {
    sString=sString.substring(0,sString.length-1);
    }

    return sString;
}