function ValidateCapcha()
{
    var txt = document.getElementById("txtCaptcha");
    if(txt != null)
    {
        if(trim(txt.value) == "")
        {
           alert("Please, fill the captcha");
           txt.value = "";
           txt.focus(); 
           return false;
        }
    }
    return true;
}

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 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 getElementUpcomingEvents(name)
{
	var object = null;
	var tbFormUpcomingEvents=document.getElementById('tbFormUpcomingEvents'); 
	for (var i=0; i<tbFormUpcomingEvents.rows.length; i++)
    {
        for (var j=0; j<tbFormUpcomingEvents.rows[i].cells.length; j++)
        {
            for (var k=0; k<tbFormUpcomingEvents.rows[i].cells[j].childNodes.length; k++)
            {                
                if(tbFormUpcomingEvents.rows[i].cells[j].childNodes[k].id == name)
                {
                    object = tbFormUpcomingEvents.rows[i].cells[j].childNodes[k];
                    return object;
                }
            }
        }
        
    }    
}

function VerifyCheckBox(checkBoxElement)
{
	if (checkBoxElement.checked)	checkBoxElement.value = 'true';
	else checkBoxElement.value = 'false';
}

function EvaluateFriendName(checkBoxElement)
{
	var chkBringingFriend = document.getElementById('chkBringingFriend');
	var txtFriendsName = document.getElementById('txtFriendsName');
	if (chkBringingFriend.checked)
		txtFriendsName.disabled=false;			
	else {
		txtFriendsName.disabled=true;
		txtFriendsName.value='';
	}
}
		
function ValidateUpcomingEvents()
{
	var element = document.getElementById('contactDate');
	if (element.value != "")
	{
		return false;
	}
	
  element = getElementUpcomingEvents('txtFirstName');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    element.focus();
    return false;
  }
  
  element = getElementUpcomingEvents('txtLastName');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    element.focus();
    return false;
  }
     
 
  var element = getElementUpcomingEvents('txtPhone');
  element.value=trim(element.value);
  if(element.value != "" && !ValidatePhone(element.value))
	{
		alert("Please check the \"Daytime Phone\" field.");
		element.focus();
		return false;
	}
	
   
  
    
  
  var element = getElementUpcomingEvents('txtEmail');
  element.value=trim(element.value);
  if (element.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    element.focus();
    return false;
  }
  else
	{
		if(!ValidateEmail(element.value))
		{
			alert("Please check the \"Email\" field.");
			element.focus();
			return false;
		}
	}    
  return true;
}


function ValidateFirstName(source, arguments)
{

    var FirstName = getElementUpcomingEvents(source.controltovalidate);
    if (FirstName.value == "")
    {
	    source.errormessage = 'Please, enter your First Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateLastName(source, arguments)
{
    var LastName = getElementUpcomingEvents(source.controltovalidate);    
    if (LastName.value == "")
    {
	    source.errormessage = 'Please, enter your Last Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function CustomValidateEmail(source, arguments)
{
    if(arguments)
    {
        var Email = getElementUpcomingEvents(source.controltovalidate);
        if (Email.value == "")
        {
	        source.errormessage = 'Please, enter your Email.';
    	   
	        arguments.IsValid=false;			
	        return;
        }
        else
        {
        if(!ValidateEmail(Email.value))
	        {
		        source.errormessage = "Please check the emails address.";
    		 
		        arguments.IsValid=false;				
		        return;
	        }
        }
        arguments.IsValid=true;
    }    
}

function ValidatePhone(source, arguments)
{
    var Phone = getElementUpcomingEvents(source.controltovalidate);
    if (!Phone.value == "")
    {    
	    var ValidChars = "0123456789.()- ";
	    var IsCorrect=true;
	    var Char;
        var IsValid=false;
        incoming= document.getElementById(source.controltovalidate).value;
	    for (cont = 0; cont < incoming.length && IsCorrect == true; cont++) 
	    { 
	        Char = incoming.charAt(cont); 
	        if (ValidChars.indexOf(Char) == -1) {
				 source.errormessage = 'Please, check the Phone.';
	             arguments.IsValid= false;
	             return;
	        }
	    }
	 }
	 arguments.IsValid= true;
}