function SetValueCheckBox(checkbox)
{ 
    checkbox.value="No";
    if (checkbox.checked)
        checkbox.value="Yes";
}

function ValidateData()
{
	
	var contactDate = document.getElementById('contactDate');
	var FullName = getElementLarge('txtFullName');
	var Address = getElementLarge('txtAddress');
	var City = getElementLarge('txtCity');
	var State = document.getElementById('ddlState');
	var ZipCode = getElementLarge('txtZipCode');
	var Phone = getElementLarge('txtPhone');
	var Email = getElementLarge('txtEmail');
	var HearAboutUs = document.getElementById('ddlHearAboutUs');
	var Country = document.getElementById('ddlCountry');
	var Comments = getElementLarge('txtComments');
	var chkSingUp = getElementLarge('chkSingUp');

	
	FullName.value=trim(FullName.value);
	Address.value=trim(Address.value);
	City.value=trim(City.value);
	ZipCode.value=trim(ZipCode.value);
	Phone.value=trim(Phone.value);
	Email.value=trim(Email.value);
	Comments.value=trim(Comments.value);
	
	
	
	if (contactDate.value != "")
	{
		return false;
	}

    _gaq.push(['_trackEvent', 'Webform', 'Start Submit', 'Large Contact']);
	//First Name
	if (FullName.value == "")
	{
		alert('Please, enter your full name.');
		FullName.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Full Name', 'Large Contact']);
		return false;
	}
	else
	{
        if(!ValidateName(FullName.value))
		{
			alert("Please check your full name.");
			FullName.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Full Name', 'Large Contact']);
			return false;
		}

		if(!ValidateConsonants(FullName.value))
		{
			alert("Please check your full name.");
			FullName.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Full Name', 'Large Contact']);
			return false;
		}
	}
	
	
	//Address
	if (Address.value == "")
	{
		alert('Please, enter your address.');
		Address.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Address', 'Large Contact']);
		return false;
	}
	
	//City
	if (City.value == '')
	{
		alert("Please enter your city.");
		City.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - City', 'Large Contact']);
		return false;
	}
	else
	{
		if (!ValidateCityState(City.value))
		{
			alert("Please check your city.");
			City.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - City', 'Large Contact']);
			return false;
		}
		if(!ValidateConsonants(City.value))
		{
			alert("Please check your city.");
			City.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - City', 'Large Contact']);
			return false;
		}
	}
	
	
	//State
	if (State.value == "") {
	  alert("Please, enter your state.");
      State.focus();
	  _gaq.push(['_trackEvent', 'Webform', 'Validation Error - State', 'Large Contact']);
	  return false;
    }

	
	//ZipCode
	if (ZipCode.value == "")
	{
		alert('Please, enter your zip.');
		ZipCode.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - ZipCode', 'Large Contact']);
		return false;
	}
	
	
	//Phone
	if (Phone.value == "")
	{
		alert('Please, enter your phone.');
		Phone.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Phone', 'Large Contact']);
		return false;
	}
	else
	{
		if(!ValidatePhone(Phone.value))
		{
			alert("Please, enter a valid phone number.");
			Phone.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Phone', 'Large Contact']);
			return false;
		}
	}
	
	
    //Email
	if (Email.value == "")
	{
		alert('Please, enter your email.');
		Email.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
		return false;
	}
	else
	{

		if(!ValidateEmail(Email.value))
		{
		   	alert("Please check your email.");
		  	Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
		   	return false;
		}
		if(!ValidateEmailCharacters(Email.value))
		{
		   	alert("Please check your email.");
		  	Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
		   	return false;
		}
		if(!ValidateEmailLarge(Email.value))
		{
			alert("Please check your email.");
			Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
			return false;
		}
		if(!ValidateEmailDomain(Email.value))
		{
			alert("Please check your email, domain (.ru, .sk, .ua) isn't valid.");
			Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
			return false;
		}

		if(!ValidateConsonants(Email.value))
		{
			alert("Please check your email.");
			Email.focus();
			_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Email', 'Large Contact']);
			return false;
		}
	}

	//HearAboutUs
	if (HearAboutUs.selectedIndex < 0)
	{
		alert("Please select 'How did you hear about us?' option.");
		HearAboutUs.focus();
		return false;
	}
	if (HearAboutUs.selectedIndex == 0)
	{
		alert("The first 'How did you hear about us?' option is not a valid selection. Please choose one of the other options.");
		HearAboutUs.focus();
		return false;
	}
	
	
	
	if (Comments.value == "")
	{
		alert('Please, enter your comments.');
		Comments.focus();
		_gaq.push(['_trackEvent', 'Webform', 'Validation Error - Comment', 'Large Contact']);
		return false;
	}

	SetValueCheckBox(chkSingUp);
	
	_gaq.push(['_trackEvent', 'Webform', 'Submit Ok', 'Large Contact']);
	return true;
}






function ValidatePhone(incoming)
{
	var ValidChars = "0123456789.()- ";
	var IsCorrect=true;
	var Char;

	for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	{ 
		Char = incoming.charAt(cont); 
		if (ValidChars.indexOf(Char) == -1) 
			return false;
	}
	return true;
}

function clearText(thefield)
{
	if (thefield.defaultValue == thefield.value) 
		thefield.value = "";
} 

function replaceText(thefield)
{
	if (thefield.value == "") 
		thefield.value = thefield.defaultValue;
}

function trim(myString)
{
 return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function getElementLarge(name)
{
	var object = null;
	var tbLargeContact=document.getElementById('tbLargeContact'); 
	for (var i=0; i<tbLargeContact.rows.length; i++)
    {
        for (var j=0; j<tbLargeContact.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbLargeContact.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbLargeContact.rows[i].cells[j].childNodes[k].id == name)
                {
                    object = tbLargeContact.rows[i].cells[j].childNodes[k];
                    return object;
                }
            }
        }
        
    }    
}

function hiddenState(item)
{
    var element = document.getElementById('txtOtherState');
    if (item.value == "Out of USA")
    {
        element.style.display = "";
        element.value = "";
    }
    else
    {
        element.style.display = "none";
    }
    
    var ddlCountry = document.getElementById('ddlCountry');
    if (item.value == "")
        ddlCountry.value="";
    
    else{
        if (item.value != "Out of USA")
            ddlCountry.value="United States";
        else 
            ddlCountry.value="";
    }
}

function hiddenCountry(item)
{     
    var ddlState = document.getElementById('ddlState');
    var element = document.getElementById('txtOtherState');
    if (item.value != "United States" && item.value != "")
    {
        ddlState.value="Out of USA";
        element.style.display = "";
        element.value = "";
    }
    else
    {
        if (item.value == "United States" || item.value == "")
        ddlState.value="";
        element.style.display = "none";
    } 
}

function changeState(item)
{
    
    var ddlState = document.getElementById('ddlState');
    if (item.value != "" && item.value !='United States')
    {   
        ddlState.value="Out of USA";
        var element = document.getElementById('txtOtherState');
        element.style.display = "";
        element.value = "";
    }
    
    else{
        if (item.value =='United States')
            ddlState.value="";
    }
    
}

function ValidateConsonants(valor) 
{
       valor = valor.toLowerCase();
	if (/[bcdfghjklmnpqrstvwxyz]{7}/.test(valor))
		return false;
	else
		return true;
}  


function ValidateName(valor) 
{
      	valor = valor.toLowerCase();
	if (/^[a-z ]+$/i.test(valor))
		return true;
	else
		return false;
} 

function ValidateEmailCharacters(valor)
{
	valor = valor.toLowerCase();
 	var ValidChars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";   
 	var Char;
 	var IsCorrect=true;
	
	for (cont = 0; cont < valor.length && IsCorrect == true; cont++) 
 	{ 
	  	Char = valor.charAt(cont); 
  		if (ValidChars.indexOf(Char) == -1) {
			return false;
		}
	}
	return true;
}


function ValidateEmailLarge(valor) 
{
	valor = valor.toLowerCase();
	if (valor.charAt(valor.length-1)=='.') return false;
	
	if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(valor))
		return true;
	else
		return false;
}


function ValidateEmailDomain(valor) 
{
	valor = valor.toLowerCase();
	if (/.ru$|.sk$|.ua$/i.test(valor))
		return false;	
	else
		return true;
}  
	
function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

function findElement(container, name)
{

    for (var i=0; i<container.childNodes.length; i++)
    {
        child = container.childNodes[i];
        if(child.id == name)     
           return child;
       
        object=findElement(child, name);
        if (object!=null)
            return object;      
    }  
    return null;  
}

function ValidateCityState(valor) 
{
	valor = valor.toLowerCase();
	if (/^[a-z ]+$/i.test(valor))
		return true;
	else
		return false;
} 

function ValidateAreaCode(incoming)
{
	var ValidChars = "0123456789";
	var IsCorrect=true;
	var Char;

	for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	{ 
		Char = incoming.charAt(cont); 
		if (ValidChars.indexOf(Char) == -1) 
			return false;
	}
	return true;
}

function ValidateEmail(valor) 
{    
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,60}(\.[a-zA-Z]{2,4}){1,2}$/;  
    return emailPattern.test(valor); 
}

