function getElementContact(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbContact'); 
    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 ValidateFirstName(source, arguments)
{

    var FirstName = getElementContact(source.controltovalidate);
    if ((FirstName.value == "") || (FirstName.value == FirstName.defaultValue))
    {
	    source.errormessage = 'Please, enter your First Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateLastName(source, arguments)
{
    var LastName = getElementContact(source.controltovalidate);    
    if ((LastName.value == "") || (LastName.value == LastName.defaultValue))
    {
	    source.errormessage = 'Please, enter your Last Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateAddress(source, arguments)
{    
    var Address = getElementContact(source.controltovalidate);    
    if ((Address.value == "") || (Address.value == Address.defaultValue))
    {
	    source.errormessage = 'Please, enter your Address.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateCity(source, arguments)
{
    var City = getElementContact(source.controltovalidate);    
    if ((City.value == "") || (City.value == City.defaultValue))
    {
	    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 == "") || (State.value == State.defaultValue))
    {
	    source.errormessage = 'Please, enter your State.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateZipCode(source, arguments)
{    
    var ZipCode = getElementContact(source.controltovalidate);
    if ((ZipCode.value == "") || (ZipCode.value == ZipCode.defaultValue))
    {
	    source.errormessage = 'Please, enter your ZipCode.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateCountry(source, arguments)
{    
    var Country = getElementContact(source.controltovalidate);
    if ((Country.value == "") || (Country.value == Country.defaultValue))
    {
	    source.errormessage = 'Please, enter your Country.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidatePhone(source, arguments)
{
    var Phone = getElementContact(source.controltovalidate);
    if ((Phone.value == "") || (Phone.value == Phone.defaultValue))
    {
	    source.errormessage = 'Please, enter your Phone.';
	   
	    arguments.IsValid=false;		
	    return;
    }
    else
    {
	    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 ValidatePhone2(source, arguments)
{
    var Phone = getElementContact(source.controltovalidate);
    if ((Phone.value != "") && (Phone.value != Phone.defaultValue))
    {	    
	    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 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 ValidateContactMe(source, arguments)
{
    var cblContactMe = document.getElementById(source.controltovalidate);
    var length = 4;
    for (i = 0; i <length; i ++)
    {
        if (document.getElementById("cblHowContactYou_" + i ).checked)
        {
            arguments.IsValid=true;
            return;
        }
    }
    
    source.errormessage = 'Please, select any Contact Me.';   
    arguments.IsValid=false;		
    return;
}

function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 

function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

function trim(myString)
{
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}