

//------------------- for clearing and replacing text in form input fields and textareas -------------------//
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

function ValidateDataSmall(FullName, Email, contactDate)
{
	if (contactDate.value != "")
	{
		return false;
	}
	
	if ((FullName.value == "") || (FullName.value == '* Name'))
	{
		alert('Please, enter your Name.');
		FullName.focus();
		return false;
	}
	else
	{
		if(HasNumbers(FullName.value))
		{
			alert('Name contains numbers, please remove them.');
			FullName.focus();
			return (false);
		}
	}
	
	if ((Email.value == "") || (Email.value == '* Email'))
	{
		alert('Please, enter your email.');
		Email.focus();
		return false;
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please check the emails address");
			Email.focus();
			return false;
		}
	}
		
	if  ( 
			hasSpamStrings(FullName) 			
		)
	{
		return false;
	}
	
	return true;
}

function hasSpamStrings(textField)
{

	var fieldValue = textField.value;
	
	if (	
			fieldValue.indexOf('@')			!=	-1 	|| 
			fieldValue.indexOf('http://')	!=	-1
		)
	{
			alert('Please, enter a valid value.');
			textField.focus();
			return true;
	}	
	else
	{
			return false;
	}
}
	
function OnSubmit(){

	var FullName=getElement('txtFullName');	
	var Email=getElement('txtEmail');	
	var contactDate=getElement('contactDate');			
	
	if (ValidateDataSmall(FullName, Email, contactDate)==true)		
		window.location.href="/SaveSmall.aspx?txtFullName="+FullName.value+"&txtEmail="+Email.value;
}

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

	
function HasNumbers(valor) 
{
    if (/[0-9]/.test(valor))
            return true;
    else
            return false;
}
    
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;
                }
            }
        }
        
    }    
}
