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

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

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

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

function ValidateEmailDomain(valor) 
{
	valor = valor.toLowerCase();
	if (/.ru$|.sk$|.ua$/i.test(valor))
		return false;	
	else
		return true;
} 

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 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 ValidateName(valor) 
{
		valor = valor.toLowerCase();
	if (/^[a-z ]+$/i.test(valor))
		return true;
	else
		return false;
}



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

function ValidateDataSmall(FullName, Email, Phone, contactDate)
{
    FullName.value = trim(FullName.value);
    Email.value = trim(Email.value);
    Phone.value=trim(Phone.value);
    
	if (contactDate.value != "")
	{						
		return (false);
	}
	
	if ((FullName.value == "") || (FullName.value == "Full Name *"))
	{
		alert('Please, enter your full name.');
		FullName.focus();
		return false;
	}
	else		
	{
		if (!ValidateName(FullName.value))
		{
			alert('Please, check your full name.');
			FullName.focus();
			return false;
		}
		if(!ValidateConsonants(FullName.value))
		{
			alert('Please, check your full name.');
			FullName.focus();
			return false;
		}
	}

	if ((Email.value == "") || (Email.value == "Email *"))
	{
		alert('Please, enter your email.');
		Email.focus();
		return false;
	}
	else
	{			
		if(!ValidateEmailCharacters(Email.value))
		{
			alert('Please, check your email.');
			Email.focus();
			return false;
		}	
		
		if(!ValidateEmail(Email.value))
		{
			alert('Please, check your email.');
			Email.focus();
			return false;
		}
		
		if(!ValidateEmailDomain(Email.value))
		{
			alert('Please, check your email.');
			Email.focus();
			return false;
		}
		
		if(!ValidateConsonants(Email.value))
		{
			alert('Please, check your email.');
			Email.focus();
			return false;
		}
	}
		
	if ((Phone.value == "") || (Phone.value == "Phone Number *"))
	{
		alert('Please, enter your phone number.');
		Phone.focus();
		return (false);
	}
	else
	{
		if(!ValidatePhone(Phone.value))
		{
			alert("Please, check your phone number.");
			Phone.focus();
			return false;
		}
	}
	
	return true;
}



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 FullName = getElementSmall('txtFullName');
	var Email = getElementSmall('txtEmail');
	var Phone = getElementSmall('txtPhone');
	var chkSendMeInformation=getElementSmall('chkSendMeInformation');	
	var contactDate = getElementSmall('contactDate');
			
	if (ValidateDataSmall(FullName, Email, Phone, contactDate) == true)
	{
		{		
		 window.location.href = "/SaveSmall.aspx" +
	        "?txtFullName=" + FullName.value +
	        "&txtEmail=" + Email.value + 
	        "&txtPhone=" + Phone.value +
		    "&chkSendMeInformation=" + chkSendMeInformation.checked;
		PopupCenter('http://www.denovaresearch.com/includes/inc-thankYou.shtml', 'window', 628,160);
		}
	}
}

function PopupCenter(pageURL, title,w,h) 
{
 var left = (screen.width/2)-(w/2);
 var top = (screen.height/2)-(h/2);
 window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
