function ValidatePhone(source, arguments)
{
var Phone = getElementContact(source.controltovalidate);
    if (Phone.value != "")
    {
	    var ValidChars = "0123456789.()- ";
	    var IsCorrect=true;
	    var Char;
        var IsValid=false;
        incoming= document.getElementById(source.controltovalidate).value;
	    for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	    { 
	        Char = incoming.charAt(cont); 
	        if (ValidChars.indexOf(Char) == -1) {
				 source.errormessage = 'Please, check the Phone.';
	             arguments.IsValid= false;
	             return;
	        }
	    }
	 }
	 arguments.IsValid= true;
}

function ValidateFullName(source, arguments)
{

    var FullName = getElementContact(source.controltovalidate);
    if (FullName.value == "")
    {
	    source.errormessage = 'Please, enter your Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateWebsite(source, arguments)
{
    var Website = getElementContact(source.controltovalidate);
    if (Website.value == "")
    {
	    source.errormessage = 'Please, enter your Website Address.';
	   
	    arguments.IsValid=false;		
	    return;
    }
    else
    {
        var tomatch = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
        var othermatch = /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/    
    
        var theurl=Website.value;     

         if (!(tomatch.test(theurl) || othermatch.test(theurl)))
         {                       
             source.errormessage = 'URL invalid. Try again.';
             arguments.IsValid=false;		
             return;
         }	    
    }	
    arguments.IsValid=true;
}

function ValidateCity(source, arguments)
{
    var City = getElementContact(source.controltovalidate);
    if (City.value == "")
    {
	    source.errormessage = 'Please, enter your City.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateState(source, arguments)
{    
    var State = getElementContact(source.controltovalidate);
        
	if (State.value == "")
	{
		source.errormessage = "Please, enter your State.";
		arguments.IsValid=false;		
	    return;
	}    
    arguments.IsValid=true;
}

function ValidateComments(source, arguments)
{

    var Comments = getElementContact(source.controltovalidate);
    if (Comments.value == "")
    {
	    source.errormessage = 'Please, enter your Comments.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function getElementContact(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbServices'); 
    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 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 the emails address.";
    		 
		        arguments.IsValid=false;				
		        return;
	        }
        }
        arguments.IsValid=true;
    }    
}

function ValidateInterest(source, arguments)
{
    var cblInterest = document.getElementById(source.controltovalidate);
    var length = 2;
    for (i = 0; i <length; i ++)
    {
        if (document.getElementById("cblInterest_" + i ).checked)
        {
            arguments.IsValid=true;
            return;
        }
    }
    
    source.errormessage = 'Please, select any Services Interest.';   
    arguments.IsValid=false;		
    return;
}
