﻿// Search
//var _SearchType = "1";
var _SelSpecialtyID = "";
var _SelSubSpecialtyID = "";
var _SelAreaID = "";
var _TxtNameID = "";


function HomePageTopBoxSearch(_SearchType)
{
    var objType;
    var ddlSpeciality;
    var ddlSubSpeciality;
    var ddlArea;
    var textSearch;
    
    switch(_SearchType)
    {
        case "1": // doctors
            objType = "1"; // doctors
            break;
        case "2":
            objType = "2"; // institutes
            break;
        case "3": // dentists
            objType = "1"; // doctors
            break;
        case "4":
            objType = "4"; // alternative
            break;
    }
    
    var searchFilter = "";
    var expertSearchType = "";
    var area = "";

    var nameTxt = document.getElementById(_TxtNameID);
    var name = nameTxt.value;
    
    if ((name == "או חפש לפי שם") || (name == ""))
    {
        var specialtySel = document.getElementById(_SelSpecialtyID);
        var subSpecSel = "";
        if (_SelSubSpecialtyID != "")
        {
            subSpecSel = document.getElementById(_SelSubSpecialtyID);
        }
        var areaSel = document.getElementById(_SelAreaID);

        if (areaSel.value != "-1" && areaSel.value != "") 
        { 
            area = areaSel.value;
        }

        if (specialtySel.value != "-1" && specialtySel.value != "") 
        { 
            searchFilter += specialtySel.value; 
        }
        if (_SelSubSpecialtyID != "")
        {
            if (subSpecSel.value != "-1" && subSpecSel.value != "") 
            { 
               searchFilter += "%3b" + subSpecSel.value; 
            }
        }

		
        if (searchFilter == "" && (area=="")) {
            alert("אנא בחרו התמחות");
            return false;
        }
        //else
        //    return;

       if (_SelSubSpecialtyID != "" && subSpecSel.value != "-1" && subSpecSel.value != "") 
       { 
           expertSearchType = "3";
       }
       else if (specialtySel.value != "-1" && specialtySel.value != "") 
       { 
           expertSearchType = "2";
       }
    }
    else // search by name
    {
        searchFilter = name;
        expertSearchType = "1";
    }

    if (expertSearchType != "")
    {
        var page = "";
        switch(objType)
        {
            case "1": // doctors
                page = "/resultsexperts.aspx";
            case "4": // alternative
                page = "/resultsexperts.aspx";
                break;
            case "2": // institutes
                page = "/resultsinstitutes.aspx";
                break;
        }
        location.href = page + "?o=" + objType + "&a=" + area + "&t=" + expertSearchType + "&k=" + searchFilter;
    }
    
    return false;
}


function Home_ShowOptions (tmpSearchType, tmpSelSpecialtyID, tmpSelSubSpecialtyID, tmpSelAreaID, tmpTxtNameID)
{			
	_SearchType = tmpSearchType;
    _SelSpecialtyID = tmpSelSpecialtyID;
    _SelSubSpecialtyID = tmpSelSubSpecialtyID;
    _SelAreaID = tmpSelAreaID;
    _TxtNameID = tmpTxtNameID;
	
	/*
	for (i=1; i<=4 ; i++ )
	{
		document.getElementById ('searchBox_button_' + i).className = 'searchBox_button';
		document.getElementById ('search_options_' + i).style.display = 'none';
	}

	document.getElementById ('searchBox_button_' + tmpSearchType).className = 'searchBox_button searchBox_button_selected';
	document.getElementById ('search_options_' + tmpSearchType).style.display = '';
	*/
}

function Home_SetSpecialties()
{
    var specialtySel = document.getElementById(_SelSpecialtyID);
    specialtySel.length = _ArrSpecialty.length+1;
    specialtySel.options[0].text = "-- בחר התמחות --";
    specialtySel.options[0].value = "";
    for (var i = 0 ; i < _ArrSpecialty.length ; i++)
    {
        if (_ArrSpecialty[i] != "")
        {
            var specialtyValues = _ArrSpecialty[i].split("|");
            specialtySel.options[i+1].text = specialtyValues[0];
            specialtySel.options[i+1].value = specialtyValues[1];
        }
    }
    specialtySel.selectedIndex = 0;
}

function Home_GetSubSpecialties(tmpSelSpecialty, tmpSelSubSpecialty)
{
    _SelSpecialtyID = tmpSelSpecialty;
    _SelSubSpecialtyID = tmpSelSubSpecialty;

    var selectedSpecialty = document.getElementById(_SelSpecialtyID).value;
    if (selectedSpecialty != "")
    {
        // Get the sub-specialties
        CallService("SpecialtiesService.aspx", "parent=" + selectedSpecialty, "Home_SetSubSpecialities(xhr.responseText)");  
    }
    else
    {
        document.getElementById(_SelSubSpecialtyID).selectedIndex = 0;
    }
}
function Home_SetSubSpecialities(listSubSpecialities)
{
    var selSubSpecialty = document.getElementById(_SelSubSpecialtyID);
    var arrSubSpec = listSubSpecialities.split("~");
    selSubSpecialty.length = arrSubSpec.length+1;
    for (var i = 0 ; i < arrSubSpec.length ; i++)
    {
        if (arrSubSpec[i] != "")
        {
            var subSpecValues = arrSubSpec[i].split("|");
            selSubSpecialty.options[i+1].text = subSpecValues[0];
            selSubSpecialty.options[i+1].value = subSpecValues[1];
        }
    }
    selSubSpecialty.selectedIndex = 0;
}




function invokeDrugSearch(ddlDisease,ddlCompany,txtName){

    var searchString ="";
    var isFirstParameter = ""
    
    if($(ddlDisease).value>-1)
    {
        searchString += "dis=" + $(ddlDisease).value;
        isFirstParameter="&"
    }
        
    if($(ddlCompany).value>-1)
    {
        searchString += isFirstParameter + "comp=" + $(ddlCompany).value;
        isFirstParameter="&"
    }
        
    if($(txtName).value!="לפי שם")
        searchString += isFirstParameter + "drugname=" + escape($(txtName).value);
        
    if (searchString!="")
        location.href = "DrugsPage.aspx?" + searchString;
    else
        alert("יש לבחור קריטריונים לחיפוש");
    
}

function invokeDiseaseSearch(txtSearchCtl){
    var searchString ="";
    if ($(txtSearchCtl).value=="" || $(txtSearchCtl).value=="לפי שם")
        alert("יש לבחור קריטריונים לחיפוש");
    else
        location.href = '/DiseasesPage.aspx?s=' + escape($(txtSearchCtl).value);
}

function invokeExamSearch(ddlExamCtl, txtExamSearchCtl){
    
    if($((ddlExamCtl).value==-1) && ($(txtExamSearchCtl).value=="" || $(txtExamSearchCtl).value=="לפי שם"))
        alert("יש לבחור קריטריונים לחיפוש");
        
    if ($(txtExamSearchCtl).value!="" && $(txtExamSearchCtl).value!="לפי שם")
        location.href = '/ExaminationsPage.aspx?s=' + escape($(txtExamSearchCtl).value);
    else    
        location.href = '/ExaminationsByCatPage.aspx?caid=' +  $(ddlExamCtl).value;    
        
}

