﻿// JScript File
// Summary description for AskUs.js
// FileName                 : AskUs.js
// Descriptio               : Validating User Information To be Sent for Sending Mail 
// Developer                : Aruna 
// Created Date             : 15-Oct-2007 

function Validation()
{
    var IsValid=0;
    var Msg = "Required Information Is Missing \n\n";
    
    if(document.getElementById("ctl00_cphUser_txtName").value == "")
    {
        Msg = Msg + "Name\n";
        IsValid = 1;
    }
    else
    {
        var sizechar=document.getElementById("ctl00_cphUser_txtName").value;
        var testName =/^([a-z]|[A-Z]| )*$/;
        if(!testName.test(sizechar))
        {
			Msg=Msg + "Name doesn't contain Digits \n";
			IsValid=1;
		}
    }
        
    if(document.getElementById("ctl00_cphUser_txtEmailId").value == "")
    {
        Msg = Msg + "Email Id \n";
        IsValid = 1;
    }
    else
     {
        var email = document.getElementById("ctl00_cphUser_txtEmailId");
        if(echeck(email.value) == false)
        {
            email.focus();
            Msg = Msg + "Invalid Email Id \n";
            IsValid = 1;
        }
     }
     
     if(document.getElementById("ctl00_cphUser_txtPhoneNum").value != "")
     {
        var Contact = document.getElementById("ctl00_cphUser_txtPhoneNum").value;
        var stripped = Contact.replace(/[\(\)\.\-\ ]/g,'');
        if(isNaN(stripped))
        {
            Msg = Msg + "Telephone Contains Characters \n";
            IsValid = 1;
        }
     }
     
     if(document.getElementById("ctl00_cphUser_txaInfo").value == "")
     {
        Msg = Msg + "Information \n";
        IsValid = 1;
     }
     
     if(IsValid == 1)
     {
        alert(Msg);
        document.getElementById("ctl00_cphUser_txtName").focus();
        return false;
     }
}


    function echeck(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;		
    }

