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 ValidatePhone(valor)
{
    var ValidChars = "0123456789.()- ";
    var IsCorrect=true;
    var Char;
    var IsValid=false;
    
    for (cont = 0; cont < valor.length && IsCorrect == true; cont++) 
    { 
        Char = valor.charAt(cont); 
        if (ValidChars.indexOf(Char) == -1) {
             return false;
        }
    }
    
    return true;
}

function trim(myString)
{
    return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function ValidateDataSmall(FName,Email,Comment,contactDate)
{
    FName.value=trim(FName.value);
    Email.value=trim(Email.value);
    Comment.value=trim(Comment.value);
    
	if (contactDate.value != "")
	{						
		return (false);
	}
	
	if (FName.value == "")
	{
		alert('Please, enter your full name.');
		FName.focus();
		return (false);
	}
	else
	{
		if(HasNumbers(FName.value))
		{
			alert('Your full name contains numbers, please remove them.');
			FName.focus();
			return (false);
		}
	}
	
	if (Email.value == "")
	{
		alert('Please, enter your email.');
		Email.focus();
		return (false);
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please, check your email.");
			Email.focus();
			return false;
		}
	}
		
	if (Comment.value == "")
	{
		alert('Please, enter your comments.');
		Comment.focus();
		return (false);
	}
	
	return true;
}

function OnSubmit()
{
    var FName=getElement('txtFullName');
	var Email=getElement('txtEmail');
	var Comment=getElement('txtComments');
	var SingUp=getElement('chkSingUp');
	var contactDate=getElement('contactDate');
	var hdnContactFormID=getElement('hdnContactFormID');
	var hdnContactFormType=getElement('hdnContactFormType');
	
	if (ValidateDataSmall(FName,Email,Comment,contactDate)==true)
	{
	    if(SingUp.checked)
	        SingUp.value = "Yes";
	    else
	        SingUp.value = "No"
	    var url = "/savesmallform.aspx?txtFullName="+FName.value+"&txtEmail="+Email.value+"&txtComments="+Comment.value+"&chkSingUp="+SingUp.value+"&hdnContactFormID="+hdnContactFormID.value+"&hdnContactFormType="+hdnContactFormType.value;
		window.location.href=url;
	}
}

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;
}