function initialValues()
{
	var element = document.getElementById("state");
	element.value = "--- United States ---";
}

function VerifySex(radioElement)
{
	/*debugger;
	if (radioElement.value=="Men")	
	{ 
	  document.forms["form1"].Pattern.disabled = 'false';
	  document.forms["form1"].WomenPattern.disabled = 'true';
	}
	else 
	{
	  document.forms["form1"].WomenPattern.disabled = 'false';
	  document.forms["form1"].Pattern.disabled = 'true';
	}*/
}

function hiddenState(item)
{
    var element = document.getElementById('otherState');
    if (item.value == "--- Other ---")
    {
        element.style.display = "";
        element.value = "";
    }
    else
    {
        element.style.display = "none";
    }
}

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 == "--- United States ---" && theForm.country.value == "--- Select a Country ---") ||
	(theForm.state.value == "--- United States ---" && 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 == "--- Select a Country ---")
	{
		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 OnlyNumbers(e)
{	
	if (((document.all)?e.keyCode:e.which) < 48 ||((document.all)?e.keyCode:e.which) > 57)
	{
		if (e.keyCode)
		{
			e.keyCode = 0;
		}
		else
		{
			e.preventDefault();
			e.stopPropagation();
		}
	}
}