	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 ValidateDataSmall(FirstName,LastName,Phone,Email,Comment,contactDate)
	{
        FirstName.value=trim(FirstName.value);
        LastName.value=trim(LastName.value);
		Phone.value=trim(Phone.value);
        Email.value=trim(Email.value);   
        Comment.value=trim(Comment.value);   
		if (contactDate.value != "")
		{						
			return (false);
		}
		
		if ((FirstName.value == "") || (FirstName.value == FirstName.defaultValue))
		{
			alert('Please, enter your first name.');
			FirstName.focus();
			return (false);
		}	

		
		if ((LastName.value == "") || (LastName.value == LastName.defaultValue))
		{
			alert('Please, enter your last name.');
			LastName.focus();
			return (false);
		}
		
		if (Phone.value == "")
		{
			alert('Please, enter your phone.');
			Phone.focus();
			return false;
		}
		else
		{
			if(!ValidatePhone(Phone.value))
			{
				alert("Please, enter a valid phone number.");
				Phone.focus();
				return false;
			}
		}		
		
		if ((Email.value == "") || (Email.value == Email.defaultValue))
		{
			alert('Please, enter your email.');
			Email.focus();
			return (false);
		}
		else
		{
			if(!ValidateEmail(Email.value))
			{
				alert("Please check the emails address.");
				Email.focus();
				return false;
			}
		}
			
		if ((Comment.value == "") || (Comment.value ==Comment.defaultValue ))
		{
			alert('Please, enter your comments.');
			Comment.focus();
			return (false);
		}
		
		return true;
	}

	function getSmallContactElement(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 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 OnSubmit(){	
	    
		var txtFirstName=getSmallContactElement('txtFirstName');	
		var txtLastName=getSmallContactElement('txtLastName');		
		var txtPhone=getSmallContactElement('txtPhone');
		var txtEmail=getSmallContactElement('txtEmail');
		var txtComments=getSmallContactElement('txtComments');	
		var contactDate=getSmallContactElement('contactDate');
		var hdnContactFormID=getSmallContactElement('hdnContactFormID');
		var hdnContactFormType=getSmallContactElement('hdnContactFormType');
		var chkSingUp=getSmallContactElement('chkSingUp');
		
		if (ValidateDataSmall(txtFirstName,txtLastName,txtPhone,txtEmail,txtComments,contactDate)==true)
		{
		    ValidateMollom(txtComments.value);
		}
	}
	
	function OnAfterSubmit(){		  		  
		var txtFirstName=getSmallContactElement('txtFirstName');	
		var txtLastName=getSmallContactElement('txtLastName');		
		var txtPhone=getSmallContactElement('txtPhone');
		var txtEmail=getSmallContactElement('txtEmail');
		var txtComments=getSmallContactElement('txtComments');	
		var contactDate=getSmallContactElement('contactDate');
		var hdnContactFormID=getSmallContactElement('hdnContactFormID');
		var hdnContactFormType=getSmallContactElement('hdnContactFormType');
		var chkSingUp=getSmallContactElement('chkSingUp');
		
		if (ValidateDataSmall(txtFirstName,txtLastName,txtPhone,txtEmail,txtComments,contactDate)==true)
			window.location.href="/savesmallform.aspx?"+
			                "txtFirstName="+txtFirstName.value+
			                "&txtLastName="+txtLastName.value+
							"&txtPhone="+txtPhone.value+
			                "&txtEmail="+txtEmail.value+
			                "&txtComments="+txtComments.value+
			                "&chkSingUp="+chkSingUp.checked+
			                "&hdnContactFormID="+hdnContactFormID.value+
			                "&hdnContactFormType="+hdnContactFormType.value;		
	}
	
	function ValidateMollom(value_Comment)
    {
        if(value_Comment != "")
        {
            var strURL = "/Mollom.aspx?comment=" + value_Comment;
            var req = getXMLHTTP();

            if (req)
            {

                req.onreadystatechange = function()
                {
                    if (req.readyState == 4)
                    {
                        // only if "OK"
                        if (req.status == 200)
                        {
                            var resulMollom = req.responseText;                            
						    if(resulMollom == 'No')
						    {
							    var valor=fnOpenPopUp();
							    try{
		                            if(valor[0]=='Y')
		                            {
		                                OnAfterSubmit();
		                            }
		                        }
		                        catch (e)
				                {					
					                return;
	                            }
						    }
						    else
						    {
							    OnAfterSubmit();
						    }
                        }
                        else
                            alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }                
                }
                req.open("GET", strURL, true);
                req.send(null);
            }
        }
    }
    
    function fnOpenPopUp(){       
       var url= "/Frame.aspx";
       var valor=window.showModalDialog(url, "MOLLOM", "dialogHeight: 260px; dialogWidth: 300px; center: Yes; resizable: No; Scroll:no")
       return valor;
    }
    
    function SendResp() 
    {
    var arrValues = new Array();
		arrValues.push('Y'); 
		parent.window.returnValue = arrValues;
		parent.window.close();
	}
    
    function getXMLHTTP() 
    {
        //fuction to return the xml http object
     var xmlhttp=false;
     try
        {
      xmlhttp=new XMLHttpRequest();
     }
     catch(e)
        {
            try
            {
        xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e1)
            {
       try
                {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       }
       catch(e2)
                {
         xmlhttp=false;
       }
      }
     }

     return xmlhttp;
    }
	
	function ValidateCapcha()
    {
        var txt = document.getElementById("txtCaptcha");
        if(trim(txt.value) == "")
        {
           alert("Please, fill the captcha");
           txt.value = "";
           txt.focus(); 
           return false;
        }
        return true;
    }