
function initialValues()
{
	var element = document.getElementById("ddlState");
	element.value = "";
}

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

function VerifySex(radioElement)
{	
	if (radioElement.value=="Men")	
	{ 
	  getElementContact("rblMenHairLossPatterns").disabled = 'false';
	  getElementContact("rblWomenHairLossPatterns").disabled = 'true';	  
	}
	else 
	{
	  getElementContact("rblMenHairLossPatterns").disabled = 'true';
	  getElementContact("rblWomenHairLossPatterns").disabled = 'false';
	}
}

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

function displayReferredDetails(ddlreferred)
{
    try
    {
 	var element = document.getElementById("tblReferredDetails");
    if (!(ddlreferred.value == "Word of Mouth" || ddlreferred.value == "Magazine" || ddlreferred.value == "Friend" || ddlreferred.value == "Salon" || ddlreferred.value == "Other"))
    {
        element.style.display = "none";
    }
    else
        element.style.display = "block";
    }
    catch(e)
    {}
}

function ValidateData(theFormName)
{
   
    var theForm=document.getElementById(theFormName);
	if (theForm.requiredddlSetupConsultation.value == "-- Select --" || theForm.requiredddlSetupConsultation.value == "" )
	{
		alert('Please, select how you would like to setup a consultation?');
		theForm.requiredddlSetupConsultation.focus();
		return false;
	}

	if (theForm.requiredfirstName.value == "")
	{
		alert('Please, enter your first name.');
		theForm.requiredfirstName.focus();
		return (false);
	}

	if (theForm.requiredlastName.value == "")
	{
		alert('Please, enter your last name.');
		theForm.requiredlastName.focus();
		return (false);
	}

	/*if (theForm.Phone.value == "")
	{
		alert('Please, enter your phone.');
		theForm.Phone.focus();
		return (false);
	}
	
	if (theForm.ZipCode.value == "")
	{
		alert("Please enter a value for the Zip Code field.");
		theForm.ZipCode.focus();
		return (false);
	}
	if (theForm.ZipCode.value.length != 5)
	{
		alert("Please enter 5 characters in the Zip Code field.");
		theForm.ZipCode.focus();
		return (false);
	}
	else 
	{
		if (theForm.ZipCode.value.length == 5)
		{
			if (isNaN(theForm.ZipCode.value)) 
			{
				alert("Please enter only numerical digits in the Zip Code field.");
				theForm.ZipCode.focus();
				return false;	
			}					    
		}
	}*/
	
	if (theForm.city.value == "")
	{
		alert('Please, enter your city.');
		theForm.city.focus();
		return (false);
	}
	
	if ((theForm.state.value == "" && theForm.country.value == "") ||
	(theForm.state.value == "" && theForm.country.value == "United States") ||
	(theForm.state.value == "--- Other ---" && theForm.country.value == "United States"))
	{
		alert('Please, enter your state.');
		theForm.state.focus();
		return (false);
	}
	else if (theForm.state.value == "--- Other ---" && theForm.country.value != "United States" && theForm.otherState.value == "")
	{
		alert('Please, enter your state.');
		theForm.otherState.focus();
		return (false);
	}
	
	if (theForm.country.value == "")
	{
		alert('Please, enter your country.');
		theForm.country.focus();
		return (false);
	}
	
	if (theForm.state.value != "--- Other ---" && theForm.country.value != "United States")
	{
		alert('Please, enter your state.');
		theForm.state.focus();
		return (false);
	}
	
	if ((theForm.requiredemail.value == "") || (theForm.requiredemail.value == 'Email'))
	{
		alert('Please, enter your email.');
		theForm.requiredemail.focus();
		return (false);
	}
	else
	{
		if(!ValidateEmailHistory(theForm.requiredemail.value))
		{
			alert("Please check the emails address");
			theForm.requiredemail.focus();
			return false;
		}
	}
	
	if (theForm.age.value.length > 3)
	{
		alert("Please enter maximum 3 characters in the Age Code field.");
		theForm.age.focus();
		return (false);
	}
	else 
	{
		if (isNaN(theForm.age.value)) 
		{
			alert("Please enter only numerical digits in the Age Code field.");
			theForm.age.focus();
			return false;	
		}
		else	
		{
			if (theForm.ageHairloss.value.length > 3)
			{
				alert("Please enter maximum 3 characters in the Age Code field.");
				theForm.ageHairloss.focus();
				return (false);
			}
				else 
			{
				if (isNaN(theForm.ageHairloss.value)) 
				{
				alert("Please enter only numerical digits in the Age Code field.");
				theForm.ageHairloss.focus();
				return false;	
				}	
				else
				{
					if(theForm.ageHairloss.value > theForm.age.value)
					{
					alert("Please enter correct Age to onsent.");
					theForm.ageHairloss.focus();
					return false;						
					}
				}
			}

		}
	}

	if (theForm.Frontal.value != "")
	{
		if (!filterFileType('Frontal')) 
		{
		theForm.Frontal.focus(); 
		return false;
		}
	}
	
	if (theForm.Top.value != "")
	{
		if (!filterFileType('Top')) 
		{
		theForm.Top.focus(); 
		return false;
		}
	}
	
	if (theForm.Side.value != "")
	{
		if (!filterFileType('Side')) 
		{
		theForm.Side.focus(); 
		return false;
		}
	}
	
	if (theForm.Back.value != "")
	{
		if (!filterFileType('Back')) 
		{
		theForm.Back.focus(); 
		return false;
		}
	}
	
	CheckValues(theForm);	
}

function CheckValues(theForm)
{
	if (theForm.sendBrochure.checked)
	{
		theForm.sendBrochure.value = 'true';
	}
	else
	{
		theForm.sendBrochure.value = 'false';
	}	
	
	
	if (theForm.webCamConsultation.checked)
	{		
		theForm.webCamConsultation.value = 'true';
	}
	else
	{
		theForm.webCamConsultation.value = 'false';
	}
	
	if (theForm.father.checked)
	{
		theForm.father.value = 'true';
	}
	else
	{
		theForm.father.value = 'false';
	}
	
	if (theForm.mother.checked)
	{
		theForm.mother.value = 'true';
	}
	else
	{
		theForm.mother.value = 'false';
	}	
	
	if (theForm.brothers.checked)
	{
		theForm.brothers.value = 'true';
	}
	else
	{
		theForm.brothers.value = 'false';
	}	
	
	if (theForm.paternalUncle.checked)
	{
		theForm.paternalUncle.value = 'true';
	}
	else
	{
		theForm.paternalUncle.value = 'false';
	}
	
	if (theForm.maternalUncle.checked)
	{
		theForm.maternalUncle.value = 'true';
	}
	else
	{
		theForm.maternalUncle.value = 'false';
	}
	
	if (theForm.paternalGrandfather.checked)
	{
		theForm.paternalGrandfather.value = 'true';
	}
	else
	{
		theForm.paternalGrandfather.value = 'false';
	}
	
	if (theForm.maternalGrandfather.checked)
	{		
		theForm.maternalGrandfather.value = 'true';
	}
	else
	{
		theForm.maternalGrandfather.value = 'false';
	}
	
	if (theForm.indepthConsult.checked)
	{
		theForm.indepthConsult.value = 'true';
	}
	else
	{
		theForm.indepthConsult.value = 'true';
	}
	
	if (theForm.talkToPatients.checked)
	{
		theForm.talkToPatients.value = 'true';
	}
	else
	{
		theForm.talkToPatients.value = 'false';
	}
	
	if (theForm.meetPatients.checked)
	{
		theForm.meetPatients.value = 'true';
	}
	else
	{
		theForm.meetPatients.value = 'false';
	}
	
	if (theForm.viewProcedure.checked)
	{
		theForm.viewProcedure.value = 'true';
	}	
	else
	{
		theForm.viewProcedure.value = 'false';
	}		
}

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

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

function ValidateDataSeminar(theForm)
{
	if (theForm.FirstName.value == "")
	{
		alert('Please, enter your first name.');
		theForm.FirstName.focus();
		return (false);
	}

	if (theForm.Telephone.value == "")
	{
		alert('Please, enter your Telephone.');
		theForm.Telephone.focus();
		return (false);
	}
	
	if (theForm.Zip.value == "")
	{
		alert("Please enter a value for the Zip Code field.");
		theForm.Zip.focus();
		return (false);
	}
	if (theForm.Zip.value.length != 5)
	{
		alert("Please enter 5 characters in the Zip Code field.");
		theForm.Zip.focus();
		return (false);
	}
	else 
	{
		if (theForm.Zip.value.length == 5)
		{
			if (isNaN(theForm.Zip.value)) 
			{
				alert("Please enter only numerical digits in the Zip Code field.");
				theForm.Zip.focus();
				return false;	
			}					    
		}
	}

	if ((theForm.EmailAddress.value == "") || (theForm.EmailAddress.value == 'Email'))
	{
		alert('Please, enter your email.');
		theForm.EmailAddress.focus();
		return (false);
	}
	else
	{
		if(!ValidateEmail(theForm.EmailAddress.value))
		{
			alert("Please check the emails address");
			theForm.EmailAddress.focus();
			return false;
		}
	}	
}

function filterFileType(field) { 
	
    var fd = document.getElementById(field);
	
    var ext = document.getElementById('hddimageExtension').value;
    var arrext = ext.split(",");
    var part_num=0;
    var val=0;
    while (part_num < arrext.length)
        {
            if (fd.value.toLowerCase().indexOf(arrext[part_num]) == -1) 
            { 
	            val +=1;
            } 
        part_num+=1;
        }
	
    if (val == part_num)
    {
    alert('Your uploaded file must be a Image "' + ext + '" type file.\nPlease select again.'); 
    return false; 
    }
    else
    {			
    return true; 
    }
}

function getElementContact(name)
{
    var object = null;
    var tbSmallContact=document.getElementById('tbContact'); 
    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 ValidateFirstName(source, arguments)
{

    var FirstName = getElementContact(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 = getElementContact(source.controltovalidate);    
    if (LastName.value == "")
    {
	    source.errormessage = 'Please, enter your Last Name.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidateCity(source, arguments)
{
    var City = getElementContact(source.controltovalidate);    
    if (City.value == "")
    {
	    source.errormessage = 'Please, enter your City.';
	   
	    arguments.IsValid=false;		
	    return;
    }		
    arguments.IsValid=true;
}

function ValidatePhone(source, arguments)
{
    var Phone = getElementContact(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;
}

function CustomValidateEmail(source, arguments)
{
    if(arguments)
    {
        var Email = getElementContact(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 CustomValidateState(source, arguments)
{
    if(arguments)
    {
        var State = getElementContact("ddlState");
        if (trim(State.value) == "")
	    {
		    source.errormessage = 'Please, enter your State.';
		    State.focus();
		    State.value = "";
		    arguments.IsValid=false;
		    return;
	    }
	    
        arguments.IsValid=true;
    
    }    
}

function CustomValidateReasonConsultation(source, arguments)
{
    if(arguments)
    {
        var Consultation = getElementContact("ddlContactReason");
        if (trim(Consultation.value) == "")
	    {
		    source.errormessage = 'Please, enter your Consultation.';
		    Consultation.focus();
		    Consultation.value = "";
		    arguments.IsValid=false;
		    return;
	    }
	    
        arguments.IsValid=true;    
    }    
}

function CustomValidateCountry(source, arguments)
{
    if(arguments)
    {
        var Country = getElementContact("ddlCountry");
        if (trim(Country.value) == "")
	    {
		    source.errormessage = 'Please, enter your Country.';
		    Country.focus();
		    Country.value = "";
		    arguments.IsValid=false;
		    return;
	    }
	    
        arguments.IsValid=true;
    
    }    
}

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 hiddenState(item)
{
    var element = document.getElementById('txtOtherState');
    if (item.value == "--- Other ---")
    {
        element.style.display = "";
        element.value = "";
    }
    else
    {
        element.style.display = "none";
    }
    
    var ddlCountry = document.getElementById('ddlCountry');
    if (item.value == "")
        ddlCountry.value="";
    
    else{
        if (item.value != "--- Other ---")
            ddlCountry.value="United States";
        else 
            ddlCountry.value="";
    }
}

function hiddenCountry(item)
{
    
    var ddlState = document.getElementById('ddlState');
    var element = document.getElementById('txtOtherState');
    if (item.value != "United States" && item.value != "")
    {
        ddlState.value="--- Other ---";
        element.style.display = "";
        element.value = "";
    }
    else
    {
        if (item.value == "United States" || item.value == "")
        ddlState.value="";
        element.style.display = "none";
    } 
}