function ValidateEmail(valor) 
{
    if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
	    return true;
    else
	    return false;
}  




function CustomValidateEmail(source, arguments)
{
    if(arguments)
    {
        var Email = getElementContact(source.controltovalidate);
        if (Email.value == "")
        {
	        source.errormessage = 'Please, enter your email.';
    	   
	        arguments.IsValid=false;
	        return;
        }
        else
        {
        if(!ValidateEmail(Email.value))
	        {
		        source.errormessage = "Please check your email.";
    		 
		        arguments.IsValid=false;
		        return;
	        }
        }
        arguments.IsValid=true;

    }    
}


function ValidateComments(source, arguments)
{

    var Comment = getElementContact(source.controltovalidate);
    if (Comment.value == "")
    {
	    source.errormessage = 'Please, enter your comments.';
	    //Comment.focus();
	    arguments.IsValid=false;
	    return;
    }		
    arguments.IsValid=true;
}




function getElementContact(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbContactLarge'); 
    for (var i=0; i<tbSmallContact.rows.length; i++)
    {
        for (var j=0; j<tbSmallContact.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbSmallContact.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbSmallContact.rows[i].cells[j].childNodes[k].id == name)
                {
                   object = tbSmallContact.rows[i].cells[j].childNodes[k];
                   return object;
                }
            }
        }
       
    }    
}


function IsNumber(incoming)
 {
	    var ValidChars = "0123456789";
	    var IsCorrect=true;
	    var Char;
        var IsValid=false;
   
	    for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	    { 
	        Char = incoming.charAt(cont); 
	        if (ValidChars.indexOf(Char) == -1) {
	            return false;
	             
	        }
	    }
	    return true;
 }
 
function LoadPhone(){

   
    if (Page_ClientValidate("LargeContact"))
    {
        var txtPhone=document.getElementById('txtPhone');     
        var txtPhone1=document.getElementById('txtPhone1'); 
        var txtPhone2=document.getElementById('txtPhone2'); 
        var txtPhone3=document.getElementById('txtPhone3'); 
        
        txtPhone.value="("+txtPhone1.value+") "+txtPhone2.value+"-"+txtPhone3.value;
        return true;
    }
    else return false;
   
    
   
}
function CustomHasNumbers(source, args) 
    {  
     	if (/[0-9]/.test(args.Value))
            args.IsValid = false;
        else
            args.IsValid = true;
    }
function CustomValidatePhone(source, arguments)
{
   
    var PhoneType = getElementContact('ddlPhoneType');
    var AreaCode = getElementContact('txtPhone1');
    var Prefix = getElementContact('txtPhone2');
    var Suffix = getElementContact('txtPhone3');
    var Phone = getElementContact('txtPhone');
    
    if(trim(AreaCode.value) != "" && trim(Prefix.value) != "" && trim(Suffix.value) != "" && PhoneType.value == "")
    {
        source.errormessage = 'Plese, select the phone type.';
        PhoneType.focus();
        arguments.IsValid=false;
        return;
    }
    
    if(trim(AreaCode.value) != "" && trim(Prefix.value) != "" && trim(Suffix.value) != "" && PhoneType.value != "")
    {
        Phone.value = '(' + AreaCode.value + ')-' + Prefix.value + '-' + Suffix.value;
    }
    
    if(trim(AreaCode.value) == "" || trim(Prefix.value) == "" || trim(Suffix.value) == "")
    {
        source.errormessage = 'Please, enter a valid Phone Number.';
        PhoneType.focus();
        arguments.IsValid=false;
        return;
    }
    
    arguments.IsValid=true;
}