function replace(texto,s1,s2)
{
    return texto.split(s1).join(s2);
}

function clearText(thefield)
{
    if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 

function replaceText(thefield)
{
    if (thefield.value=="") { thefield.value = thefield.defaultValue }
}	

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 trim(myString)
{
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function ValidateDataSmall(FName,LName,Email,Comment,contactDate,month,day,year,male,female)
{
    
    FName.value=trim(FName.value);
    LName.value=trim(LName.value);
    Email.value=trim(Email.value);
    Comment.value=trim(Comment.value);
 
    month.value=trim(month.value);
    day.value=trim(day.value);
    year.value=trim(year.value);
    
	if (contactDate.value != "")
	{						
		return (false);
	}
	
	if (FName.value == "")
	{
		alert('Please, enter your first name.');
		FName.focus();
		return (false);
	}
	else
	{
		if(HasNumbers(FName.value))
		{
			alert('First name contains numbers, please remove them.');
			FName.focus();
			return (false);
		}
	}
	
	if (LName.value == "")
	{
		alert('Please, enter your last name.');
		LName.focus();
		return (false);
	}
	else
	{
		if(HasNumbers(LName.value))
		{
			alert('Last name contains numbers, please remove them.');
			LName.focus();
			return (false);
		}
	}
	
	if (month.value == "" || day.value == "" || year.value == "")
	{
		alert('Please, enter your date birth.');
		if (month.value == "")
		    month.focus();
		
		else if (day.value == "")
		    day.focus();
		
		else if (year.value == "")
		    year.focus();
		    
		return (false);
	}
	
	
	var dateF = new Date(year.value,month.value - 1 ,day.value) 
	
	if(isNaN(dateF) || !ValidateDate(month.value + "/" + day.value +"/" + year.value))
	{
	    alert('Please, enter a valid date birth.');
	    month.focus();
	    return (false);
	}
	
	
	if (!male.checked && !female.checked)
	{
	    alert('Please, select a gender.');
	    male.focus();
	    return (false);
	}
	
	if (Email.value == "")
	{
		alert('Please, enter your email.');
		Email.focus();
		return (false);
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please check the email address.");
			Email.focus();
			return false;
		}
	}
		
	if (Comment.value == "")
	{
		alert('Please, enter your comments.');
		Comment.focus();
		return (false);
	}
	
	return true;
}

function OnSubmit()
{
    var FName=getElement('txtFirstName');
	var LName=getElement('txtLastName');
	var Email=getElement('txtEmail');
	
	var month =getElement('txtDateMM');
	var day =getElement('txtDateDD');
	var year =getElement('txtDateYY');
	
	var male =getElement('rbtnMale');
	
	var female =getElement('rbtnFemale');
	
	var Comment=getElement('txtComments');	
	var contactDate=getElement('contactDate');
	var chkSingUp=document.getElementById('chkSingUp');
	var hdnContactFormID=getElement('hdnContactFormID');
	var hdnContactFormType=getElement('hdnContactFormType');
	
	if (ValidateDataSmall(FName,LName,Email,Comment,contactDate, month, day, year, male, female)==true)
	{
	    var gender = male.checked?male.value:female.value;
	    
		window.location.href="/savesmallform.aspx?txtFirstName="+FName.value+
		"&txtLastName="+LName.value+
		"&txtDate="+ month.value +"/" + day.value + "/" + year.value +
		"&txtDateMM="+ month.value +
		"&txtDateDD="+ day.value +
		"&txtDateYY="+ year.value +
		"&txtGender="+ gender +
		"&txtEmail="+Email.value+
		"&txtComments="+Comment.value+
		"&chkSingUp="+chkSingUp.checked+
		"&hdnContactFormID="+hdnContactFormID.value+
		"&hdnContactFormType="+hdnContactFormType.value;
    }
}

function getElement(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbSmallContact'); 
    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 HasNumbers(valor) 
{
	if (/[0-9]/.test(valor))
			return true;
	else
			return false;
}