function ValidateEmail(valor) 
{    
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,60}(\.[a-zA-Z]{2,4}){1,2}$/;  
    return emailPattern.test(valor); 
}

function ValidateConsonants(valor) 
{
	   valor = valor.toLowerCase();
	if (/[bcdfghjklmnpqrstvwxyz]{7}/.test(valor))
		return false;
	else
		return true;
}

function ValidateEmailCharacters(valor)
{
	valor = valor.toLowerCase();
	var ValidChars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";   
	var Char;
	var IsCorrect=true;
	
	for (cont = 0; cont < valor.length && IsCorrect == true; cont++) 
	{ 
		Char = valor.charAt(cont); 
		if (ValidChars.indexOf(Char) == -1) {
			return false;
		}
	}
	return true;
}

function ValidateEmailDomain(valor) 
{
	valor = valor.toLowerCase();
	if (/.ru$|.sk$|.ua$/i.test(valor))
		return false;	
	else
		return true;
} 



function ValidatePhone(source, arguments)
{
    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) {
             arguments.IsValid= false;
             return;
        }
    }
    arguments.IsValid= true;
}

function ValidateName(valor) 
	{
			valor = valor.toLowerCase();
		if (/^[a-z ]+$/i.test(valor))
			return true;
		else
			return false;
	}

function CustomValidateName(source, arguments)
{
    if(arguments)
    {
		var Name = document.getElementById(source.controltovalidate);
		if (Name.value == "")
		{
			source.errormessage = 'Please, enter your Name.';    	   
	        arguments.IsValid=false;
	        return;
		}
		else		
		{
			if (!ValidateName(Name.value))
			{
				source.errormessage = 'Please, check your Name.';    	   
				Name.focus();
				arguments.IsValid=false;
				return;
			}
			if(!ValidateConsonants(Name.value))
			{
				source.errormessage = 'Please, check your Name.';
				Name.focus();
				arguments.IsValid=false;				
				return;
			}
		}

		arguments.IsValid=true;
	}	
}



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(!ValidateEmailCharacters(Email.value))
			{
				source.errormessage = "Please check your Email.";
			 	arguments.IsValid=false;
				return;
			}	
			
			if(!ValidateEmail(Email.value))
			{
				source.errormessage = "Please check your Email.";
			 	arguments.IsValid=false;
				return;
			}
			
			if(!ValidateEmailDomain(Email.value))
			{
				source.errormessage = "Please check your Email.";
			 	arguments.IsValid=false;
				return;
			}
			
			if(!ValidateConsonants(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 ValidateFirstName(source, arguments)
{

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

function ValidateLastName(source, arguments)
{

    var LastName = getElementContact(source.controltovalidate);
    if (LastName.value == "")
    {
	    source.errormessage = 'Please, enter your last name.';
	    //LastName.focus();
	    arguments.IsValid=false;
	    return;
    }		
    arguments.IsValid=true;
}
*/
function getElementContact(name)
{
    var object = null;
    var tbLargeContact=document.getElementById('tbLarge'); 
    for (var i=0; i<tbLargeContact.rows.length; i++)
    {
        for (var j=0; j<tbLargeContact.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbLargeContact.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbLargeContact.rows[i].cells[j].childNodes[k].id == name)
                {
                   object = tbLargeContact.rows[i].cells[j].childNodes[k];
                   return object;
                }
            }
        }
       
    }    
}

