	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(Name,Email,ReferralSource,ReferredDetails,Consultation,ContactReason,Comment,contactDate)
	{
        Name.value=trim(Name.value);        
        Email.value=trim(Email.value);   
        
        ReferredDetails.value=trim(ReferredDetails.value);  
        Comment.value=trim(Comment.value); 
		if (contactDate.value != "")
		{						
			return (false);
		}
		
		if ((Name.value == "") || (Name.value == Name.defaultValue))
		{
			alert('Please, enter your name.');
			Name.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 your email.");
				Email.focus();
				return false;
			}
		}
			
			
		if ((ReferralSource.value == "") || (ReferralSource.value == ReferralSource.defaultValue))
		{
			alert('Please, enter your Referred By.');
			ReferralSource.focus();
			return (false);
		}
		
		if (ReferralSource.value == "Word of Mouth" || ReferralSource.value == "Magazine" || ReferralSource.value == "Friend" || ReferralSource.value == "Salon" || ReferralSource.value == "Other" || ReferralSource.value == "Doctor" )
        {
             if ((ReferredDetails.value == "") || (ReferredDetails.value == ReferredDetails.defaultValue))
		    {
			    alert('Please, enter your Referred Details.');
			    ReferredDetails.focus();
			    return (false);
		    }
        }
        
		
	    if ((Consultation.value == "") || (Consultation.value == Consultation.defaultValue))
		{
			alert('Please, enter your Consultation.');
			Consultation.focus();
			return (false);
		}
		
		if ((ContactReason.value == "") || (ContactReason.value == ContactReason.defaultValue))
		{
			alert('Please, enter your Type Consultation.');
			ContactReason.focus();
			return (false);
		}
		
		if ((Comment.value == "") || (Comment.value ==Comment.defaultValue ))
		{
			alert('Please, enter your comments.');
			Comment.focus();
			return (false);
		}
		
		return true;
	}

	

    function getElement(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 OnSubmit(){
		   
		var txtFullName=document.getElementById('txtFullName');		
		var txtEmail=document.getElementById('txtEmail');
		var ddlReferralSource=document.getElementById('ddlReferralSource');	
		var txtReferredDetails=document.getElementById('txtReferredDetails');	
		var ddlConsultation=document.getElementById('ddlConsultation');	
		var ddlContactReason=document.getElementById('ddlContactReason');	
		var txtComments=document.getElementById('txtComments');	
		var chkSingUp=document.getElementById('chkSingUp');			
		var hdnContactFormID=document.getElementById('hdnContactFormID');
		var hdnContactFormType=document.getElementById('hdnContactFormType');
		var contactDate=document.getElementById('contactDate');
				
		if (ValidateDataSmall(txtFullName,txtEmail,ddlReferralSource,txtReferredDetails,ddlConsultation,ddlContactReason,txtComments,contactDate)==true)		
		    ValidateMollom(txtFullName.value + " " + txtEmail.value + " " + txtComments.value);	   
	}
	
	function OnAfterSubmit(){
		   
		var txtFullName=document.getElementById('txtFullName');		
		var txtEmail=document.getElementById('txtEmail');
		var ddlReferralSource=document.getElementById('ddlReferralSource');	
		var txtReferredDetails=document.getElementById('txtReferredDetails');	
		var ddlConsultation=document.getElementById('ddlConsultation');	
		var ddlContactReason=document.getElementById('ddlContactReason');	
		var txtComments=document.getElementById('txtComments');	
		var chkSingUp=document.getElementById('chkSingUp');	

		
		var hdnContactFormID=document.getElementById('hdnContactFormID');
		var hdnContactFormType=document.getElementById('hdnContactFormType');
		var contactDate=document.getElementById('contactDate');

		if (ValidateDataSmall(txtFullName,txtEmail,ddlReferralSource,txtReferredDetails,ddlConsultation,ddlContactReason,txtComments,contactDate)==true)		
		    window.location.href= "/savesmallform.aspx?txtFullName="+txtFullName.value+
			"&txtEmail="+txtEmail.value+
			"&ddlReferralSource="+ddlReferralSource.value+
			"&txtReferredDetails="+txtReferredDetails.value+
			"&ddlConsultation="+ddlConsultation.value+
			"&ddlContactReason="+ddlContactReason.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: 280px; 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;
    }
	
	function displayReferredDetailsSmall(ddlreferred)
    {
        try
        {
 	    var element = document.getElementById("tblReferredDetailsSmall");
        if (!(ddlreferred.value == "Word of Mouth" || ddlreferred.value == "Magazine" || ddlreferred.value == "Friend" || ddlreferred.value == "Salon" || ddlreferred.value == "Other" || ddlreferred.value == "Doctor" ))
        {
            element.style.display = "none";
        }
        else
        {
    	
            element.style.display = "table-row";
    	

        }
        }
        catch(e)
        {
		    element.style.display = "block";
	    }
    }
	