
var focus=false;
function CustomValidateConfEmail(source, arguments)
{
    if(arguments)
    {
        var ConfEmail = getElementContact(source.controltovalidate);
        if (ConfEmail.value == "")
	    {
		    source.errormessage = 'Please, confirm your Email.';
		    //ConfEmail.focus();
		    arguments.IsValid=false;
		    return;
	    }
		else
        {			
			if(!ValidateEmailCharacters(ConfEmail.value))
			{	
				source.errormessage = "Please, check the Email for confirmation.";    		 
		        arguments.IsValid=false;
		        return;
			}	
			
			if(!ValidateEmail(ConfEmail.value))
			{
				source.errormessage = "Please, check the Email for confirmation.";    		 
		        arguments.IsValid=false;
		        return;
			}
			
			if(!ValidateEmailDomain(ConfEmail.value))
			{
				source.errormessage = "Please, check the Email for confirmation.";    		 
		        arguments.IsValid=false;
		        return;
			}
			
			if(!ValidateConsonants(ConfEmail.value))
			{
				source.errormessage = "Please, check the Email for confirmation.";    		 
		        arguments.IsValid=false;
		        return;
			}
        
	    }
	    
	    var Email = getElementContact("txtEmail");
	    if(ConfEmail.value != Email.value)
	    {
		    source.errormessage = "The confirm email is not the same that the email.";
		    //ConfEmail.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.';
		    //Email.focus();
		    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 CustomValidateFirstName(source, arguments)
{
    var FirstName = getElementContact(source.controltovalidate);
    if (FirstName.value == "")
    {
	    source.errormessage = 'Please, enter your First Name.';
	    arguments.IsValid=false;
	    return;
    }
	else
	{
		if(!ValidateName(FirstName.value))
		{
			source.errormessage = 'Please, check your First Name.';
			arguments.IsValid=false;
			return;
		}
		
		if(!ValidateConsonants(FirstName.value))
		{
			source.errormessage = 'Please, check your First Name.';
			arguments.IsValid=false;
			return;
		}		
	}	
    arguments.IsValid=true;
}

function CustomValidateLastName(source, arguments)
{
    var LastName = getElementContact(source.controltovalidate);
    if (LastName.value == "")
    {
	    source.errormessage = 'Please, enter your Last Name.';
	    arguments.IsValid=false;
	    return;
    }
	else
	{
		if(!ValidateName(LastName.value))
		{
			source.errormessage = 'Please, check your Last Name.';
			arguments.IsValid=false;
			return;
		}
		
		if(!ValidateConsonants(LastName.value))
		{
			source.errormessage = 'Please, check your Last Name.';
			arguments.IsValid=false;
			return;
		}		
	}
	
	focus = false;
    arguments.IsValid=true;
}


function CustomValidateCity(source, arguments)
{
	var IsValid=false;
	incoming= document.getElementById(source.controltovalidate).value;
	if (incoming!="")
	{
		if (!ValidateName(incoming))
		{
			source.errormessage = 'Please, check your City.';
			arguments.IsValid= false;
            return;
		}
	}
	arguments.IsValid= true;
}

function CustomValidateAreaCode(source, arguments)
{
	var IsValid=false;
	incoming= document.getElementById(source.controltovalidate).value;
	if (incoming!="")
	{
		if (!ValidateAreaCode(incoming))
		{
			source.errormessage = 'Please, check your Zip Code.';
			arguments.IsValid= false;
            return;
		}
	}
	arguments.IsValid= true;
}

function CustomValidateState(source, arguments)
{
	var IsValid=false;
	incoming= document.getElementById(source.controltovalidate).value;
	if (incoming!="")
	{
		if (!ValidateName(incoming))
		{
			source.errormessage = 'Please, check your State/Province.';			
			arguments.IsValid= false;
            return;
		}
	}
	arguments.IsValid= true;
}


function ValidateEmail(valor) 
{
	valor = valor.toLowerCase();
	if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
		return true;
	else
		return false;
}


function CustomValidateComments(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('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 ValidateConsonants(valor) 
{
	   valor = valor.toLowerCase();
	if (/[bcdfghjklmnpqrstvwxyz]{7}/.test(valor))
		return false;
	else
		return true;
}

function ValidateEmailDomain(valor) 
{
	valor = valor.toLowerCase();
	if (/.ru$|.sk$|.ua$/i.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 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); 
}

