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 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 VerifyCheckBox(checkBoxElement)
{
	if (checkBoxElement.checked)	checkBoxElement.value = 'true';
	else checkBoxElement.value = 'false';
}
		
function ValidateData()
{
  var element = document.getElementById('contactDate');
  if (element.value != "")
  {
    return false;
  }
	
  var element = getElementLarge('txtFirstName');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    element.focus();
    return false;
  }
  if (element.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"First Name\" field.");
    element.focus();
    return false;
  }
  
  var element = getElementLarge('txtLastName');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    element.focus();
    return false;
  }
  if (element.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Last Name\" field.");
    element.focus();
    return false;
  }
  
  var element = getElementLarge('txtZipCode');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"ZipCode\" field.");
    element.focus();
    return false;
  }
  if (element.value.length > 12)
  {
    alert("Please enter at most 12 characters in the \"ZipCode\" field.");
    element.focus();
    return false;
  }
  
  var element = getElementLarge('txtPhone');
  element.value=trim(element.value);
  if (element.value != "")
  {
	if(!ValidatePhone(element.value))
	{
	 alert("Please check the Phone field");
	 element.focus();
	 return false;
	}
  }
  
  var element = getElementLarge('txtCellPhone');
  element.value=trim(element.value);
  if (element.value != "")
  {    
	if(!ValidatePhone(element.value))
	{
	 alert("Please check the Cell Phone field");
	 element.focus();
	 return false;
	}
  }

  var element = getElementLarge('txtEmail');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    element.focus();
    return false;
  }
  if(!ValidateEmail(element.value))  
  {
	alert("Please check the E-mail field");
	element.focus();
	return false;
  }
  if (element.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Email\" field.");
    element.focus();
    return false;
  }
  
  element = document.getElementById('ddlProcedureInterest');
	if (element.value == "")
	{
		alert("Please select one of the \"Procedure\" options.");
		element.focus();
		return false;
	}	
    
  return true;
}