function searchBySpecialty()
{
	$('HomeSearchByNameHeader').style.display = 'none';
	$('HomeSearchBySymptomHeader').style.display = 'none';
	$('HomeSearchBySmartHeader').style.display = 'none';
	$('HomeSearchBySpecialtyHeader').style.display = 'block';
	$('HomeSearchByNameForm').style.display = 'none';
	$('HomeSearchBySmartForm').style.display = 'none';
	$('HomeSearchBySpecialtyForm').style.display = 'block';
	$('HomeSearchBySymptom').style.display = 'none';
	$('HomeSearchForm').style.display = 'block';
	$('search_type').value = 'by_specialty';
}

function searchByName()
{
	$('HomeSearchBySpecialtyHeader').style.display = 'none';
	$('HomeSearchBySymptomHeader').style.display = 'none';
	$('HomeSearchBySmartHeader').style.display = 'none';
	$('HomeSearchByNameHeader').style.display = 'block';
	$('HomeSearchBySpecialtyForm').style.display = 'none';
	$('HomeSearchBySmartForm').style.display = 'none';
	$('HomeSearchByNameForm').style.display = 'block';
	$('HomeSearchBySymptom').style.display = 'none';
	$('HomeSearchForm').style.display = 'block';
	$('search_type').value = 'by_name';	
}

function searchBySymptom()
{
	$('HomeSearchBySpecialtyHeader').style.display = 'none';
	$('HomeSearchByNameHeader').style.display = 'none';
	$('HomeSearchBySmartHeader').style.display = 'none';
	$('HomeSearchBySymptomHeader').style.display = 'block';
	$('HomeSearchForm').style.display = 'none';
	$('HomeSearchBySymptom').style.display = 'block';
}

function searchBySmart()
{
	$('HomeSearchBySpecialtyHeader').style.display = 'none';
	$('HomeSearchByNameHeader').style.display = 'none';
	$('HomeSearchBySymptomHeader').style.display = 'none';
	$('HomeSearchBySmartHeader').style.display = 'block';
	$('HomeSearchBySpecialtyForm').style.display = 'none';
	$('HomeSearchByNameForm').style.display = 'none';
	$('HomeSearchBySmartForm').style.display = 'block';
	$('HomeSearchBySymptom').style.display = 'none';
	$('HomeSearchForm').style.display = 'block';
	$('search_type').value = 'by_smart';	
}

function changeCategory(select)
{
	var specialties = $('HomeSearchSpecialty');
	specialties.disabled = true;
	while (specialties.hasChildNodes())
		specialties.removeChild(specialties.lastChild);
	var option = $$('OPTION');
	option.appendChild($$text('Select a Specialty'));
	specialties.appendChild(option);
/*	option = $$('OPTION');
	option.appendChild($$text('-------------------------'));
	specialties.appendChild(option);*/
	if (select.selectedIndex == 0) {
		specialties.disabled = true;
	} else {
		var _specialties = _subcategories[select.selectedIndex - 1];
		for (var i = 0; i < _specialties.length; i++) {
			option = $$('OPTION');
			option.value = cleanTextLink(_specialties[i].name);
			option.appendChild($$text(_specialties[i].name));
			specialties.appendChild(option);
		}
		specialties.disabled = false;
	}
}


function buildLocationParam()
{
	var locationString = "";
	var _country_name = $('country_code');
	var _state_code = $('state_code');	
	var _city_name = $('city_name');	
	if(_country_name)
		locationString = _country_name.value;
	if(locationString != 'USA')
	{
		if(_city_name.value != "")
			locationString = locationString + ' | ' + _city_name.value;
		return locationString;
	}
	locationString = locationString + ' | ';
	if(_city_name.value != '')
	{
		locationString = locationString + _city_name.value;
		if(_state_code)
			locationString = locationString + ', ' + _state_code.value;
	}else
	{
		if(_state_code)
			locationString = locationString + _state_code.value;		
	}
	return locationString;
}

function doSearch()
{
	var div = $('HomeAdvancedSearchForm');
	var isAdvanced = false;
	var queryString = '';
	var form = $('HomeSearchForm');
	var path = 'care-providers-directory/';

	if (form.search_type.value != "by_specialty") {
		//parametros para categories.php
		if(!validateSearch(form,form.search_type.value))
			return false;	
		setDefaultLocation(form.defaultlocation);
		queryString = 'keyword=';
		switch(form.search_type.value)
		{
			case "by_name":
				queryString = queryString + cleanTextLink(form.name_search.value);
				break;
			case "by_smart":
				queryString = queryString + cleanTextLink(form.symptom_dicease_search.value);
				break;
		}
		/*if(form.country_code)
			queryString = queryString + '&country_code=' + form.country_code.value;
		if(form.state_code)
			queryString = queryString + '&state_code=' + form.state_code.value;
		queryString = queryString + '&city_name=' + form.city_name.value;*/	
		queryString = queryString + '&location=' + form.city_name.value;	
		queryString = queryString + '&locationUser=' + form.city_name.value;		
		queryString = queryString + '&search_type=' + form.search_type.value;	
		if(form.insurance_code.value == "")
			queryString = queryString + '&advanced_search=';
		else
		{
			queryString = queryString + '&advanced_search=1';
			queryString = queryString + '&insurance_code=' + form.insurance_code.value;
		}
		if(form.sort_by_code)
			queryString = queryString + '&sort_by_code=' + form.sort_by_code.value;		
		if(form.defaultlocation.checked == true)
			queryString = queryString + '&defaultlocation=on';
		//queryString = path + 'categories.php?' + queryString;
		queryString = path + 'verifyLocation.php?' + queryString;	
		window.location = queryString;		
	} else {
		//parametros para results.php
		if(!validateSearch(form,form.search_type.value))
			return false;			
		setDefaultLocation(form.defaultlocation);
		queryString = 'location=' + form.city_name.value; //+ buildLocationParam();
		queryString += '&locationUser=' + form.city_name.value; 
		queryString = queryString + '&category=' + form.category.value + ',' + form.subcategory.value;		
		if(form.insurance_code.value != "")
		{
			queryString = queryString + '&insurance_code=' + form.insurance_code.value;
		}
		if(form.sort_by_code)
		{
			if(form.sort_by_code.value != "")
				queryString = queryString + '&sort_by_code=' + form.sort_by_code.value;
		}		
		if(form.defaultlocation.checked == true)
			queryString = queryString + '&defaultlocation=on';			
		queryString = queryString + '&search_type=' + form.search_type.value;			
//		queryString = path + 'results.php?' + queryString;
		queryString = path + 'verifyLocation.php?' + queryString;
		window.location = queryString;
	}	
	return false;
}


function validateSearch(form, type_search)
{
	if (form.city_name.value == '') {
		alert('Please type a City or Zipcode');
		form.city_name.focus();
		return false;	
	}
	if(form.country_code)
	{
		if (form.country_code.value == 'USA') {
			if(form.state_code.value == "--") {
				alert('Please select your State');
				return false;				
			}
		}
	}
	if(type_search != 'by_specialty') {
		switch(type_search)
		{
			case "by_name":
				if (form.name_search.value == '') {
					alert('Please type Health Professional or Facility Name, Specialty, Symptom');
					form.name_search.focus();
					return false;
				}			
				break;
			case "by_smart":
				if (form.symptom_dicease_search.value == '') {
					alert('Please type Specialty, Symptom or Dicease');
					form.symptom_dicease_search.focus();
					return false;
				}			
				break;
		}
	} else {
		if (form.subcategory.selectedIndex < 1) {
			alert('Please select a specialty');
			return false;
		}
	}
	return true;
}

function validateLogin(form)
{
	if (form.loginName.value == '') {
		alert('Please type your email account');
		form.loginName.focus();
		return false;
	}
	if(form.user_pwd.value == '') {
		alert('Please type your email account password');
		form.user_pwd.focus();
		return false;
	}
	if (form.rememberme) 
		if(form.rememberme.checked) {
			var value = form.loginName.value + ',' + form.user_pwd.value;
			setCookie('hcSignUp', value, 365);
		} else {
			deleteCookie('hcSignUp');
		}
	form.login.value = 'Login';
	return true;
}

function loadHome()
{
	var data = getCookie('hcSignUp');
	var form = $('HomeLoginForm');

	if (data) {
		data = data.split(',');
		form.loginName.value = data[0];
		form.user_pwd.value = data[1];
		form.rememberme.checked = true;
	} else {
		form.loginName.value = '';
		form.user_pwd.value = '';
	}
}

function showSearch()
{
	var parameters = getParameters();
	for (var i = 0; i < parameters.length; i++)
		if (parameters[i].name = 'search') {
			switch (parameters[i].value) {
				case 'specialty':
					searchBySpecialty()
					break;
				case 'name':
					searchByName()
					break;
				case 'symptom':
					searchBySymptom()
					break;
				case 'smart':
					searchBySmart()
					break;
			}
			break;
		}
}