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 CustomValidateGender(source, arguments)
{

    var male =getElementContact('rbtnMale');	
	var female =getElementContact('rbtnFemale');
	
    if (!male.checked && !female.checked)
	{
	    source.errormessage =  "Please, select a gender.";
	    arguments.IsValid=false;
	    return (false);
	}
	
	var gender = getElementContact('txtGender');
	gender.value = male.checked?male.value:female.value;
    arguments.IsValid=true;
}
function CustomValidateDate(source, arguments)
{
    var month =getElementContact('txtDatemm');
	var day =getElementContact('txtDatedd');
	var year =getElementContact('txtDateyy');
	
	if (month.value == "" || day.value == "" || year.value == "")
	{
		source.errormessage = "Please, enter your date birth.";
		/*if (month.value == "")
		    month.focus();
		
		else if (day.value == "")
		    day.focus();
		
		else if (year.value == "")
		    year.focus();*/
		arguments.IsValid=false;
		return;
	}
	
    var dateF = new Date(year.value,month.value - 1 ,day.value) 
	if(isNaN(dateF) || !ValidateDate(month.value + "/" + day.value +"/" + year.value))
	{
	    source.errormessage = "Please, enter a valid date birth.";
	    arguments.IsValid=false;
	}
	var date = getElementContact('txtDate');
	date.value = month.value +"/" + day.value + "/" + year.value 
    arguments.IsValid=true;
}
function ValidateEmail(valor) 
{
    if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
	    return true;
    else
	    return false;
}


function ValidateDate(valor)
{
    if (/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/.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;
                }
            }
        }
    }    
}