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

function getElementSmall(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 OnSubmitSmall()
{
	var txtFullName = getElementSmall('txtFullName');
	var txtEmail = getElementSmall('txtEmail');
	var ddlConsultation = getElementSmall('ddlConsultation');
	var txtComments = getElementSmall('txtComments');
	var chkSingUp = getElementSmall('chkSingUp');
	var chkSingUpValue = "Yes";
	var contactDate = getElementSmall('contactDate');	
	var hdnContactFormID = getElementSmall('hdnContactFormID');
	var hdnContactFormType = getElementSmall('hdnContactFormType');

	if (ValidateDataSmall(txtFullName, txtEmail, ddlConsultation, txtComments, contactDate) == true)
	{
		if(!chkSingUp.checked)
			chkSingUpValue = "";
		
		window.location.href = "/savesmallcontact.aspx" + 
			"?txtFullName=" + txtFullName.value +
			"&txtEmail=" + txtEmail.value +
			"&ddlConsultation=" + ddlConsultation.value +
			"&txtComments=" + txtComments.value +
			"&chkSingUp=" + chkSingUpValue +
			"&hdnContactFormID=" + hdnContactFormID.value +
			"&hdnContactFormType=" + hdnContactFormType.value;
	}
}

function ValidateDataSmall(FullName, Email, Consultation, Comments, contactDate)
{
	_gaq.push(['_trackEvent', 'Webform', 'Start Submit', 'Small Contact']);	
	if (contactDate.value != "")
	{				
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Contact Date', 'Small Contact']);		
		return (false);
	}
	
	FullName.value = trim(FullName.value);
  	Email.value = trim(Email.value);
  	Comments.value = trim(Comments.value);
	
	if ((FullName.value == "") || (FullName.value == FullName.defaultValue))
	{
		alert('Please, enter your name.');
		FullName.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - FullName', 'Small Contact']);
		return false;
	}
	else
	{
		if(HasNumbers(FullName.value))
		{
			alert('Your name contains numbers, please remove them.');
			FullName.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - FullName', 'Small Contact']);
			return (false);
		}
	}
	
	if ((Email.value == "") || (Email.value == Email.defaultValue))
	{
		alert('Please, enter your email address.');
		Email.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Small Contact']);
		return false;
	}
	else
	{
		if(!ValidateEmail(Email.value))
		{
			alert("Please, check the emails address.");
			Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Small Contact']);
			return false;
		}
	}
		
	if (Consultation.value == "")
	{
		alert('Please, select your consultation.');
		Consultation.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Consultation', 'Small Contact']);
		return false;
	}
		
	if ((Comments.value == "") || (Comments.value == Comments.defaultValue))
	{
		alert('Please, enter your comments.');
		Comments.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Comments', 'Small Contact']);
		return false;
	}
	_gaq.push(['_trackEvent', 'Webform', 'Submit Ok', 'Small Contact']);
	return true;
}
