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 trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}
	
function ValidateDataSmall(FName,LName,Email,Comment,contactDate)
{

	FName.value=trim(FName.value);
	LName.value=trim(LName.value);
	Email.value=trim(Email.value);         
	Comment.value=trim(Comment.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('Your 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('Your Last Name contains numbers, please remove them.');
			LName.focus();
			return (false);
		}
	}
	
	if (Email.value == "")
	{
		alert('Please, enter your Email.');
		Email.focus();
		return (false);
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please check the your Email.");
			Email.focus();
			return false;
		}
	}
		
	if (Comment.value == "")
	{
		alert('Please, enter your Comment.');
		Comment.focus();
		return (false);
	}
	
	return true;
}

function OnSubmit()
{
    var FName=getElement('txtFirstName');
	var LName=getElement('txtLastName');
	var Email=getElement('txtEmail');
	var Comment=getElement('txtComments');
	var SingUp=document.getElementById('chkSingUp');
	var contactDate=getElement('contactDate');
	var hdnContactFormID=getElement('hdnContactFormID');
	var hdnContactFormType=getElement('hdnContactFormType');
	
	if (ValidateDataSmall(FName,LName,Email,Comment,contactDate)==true)
	{
	    var url = "/savesmallform.aspx?txtFirstName="+FName.value+"&txtLastName="+LName.value+"&txtEmail="+Email.value+"&txtComments="+Comment.value+"&chkSingUp="+SingUp.value+"&hdnContactFormID="+hdnContactFormID.value+"&hdnContactFormType="+hdnContactFormType.value;
		window.location.href="/savesmallform.aspx?txtFirstName="+FName.value+"&txtLastName="+LName.value+"&txtEmail="+Email.value+"&txtComments="+Comment.value+"&chkSingUp="+SingUp.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;
}