﻿

function capturesearch(id) {

    f = document.forms[0];
    langvalues = "";
    gendervalue = "";
    var searchstring = "";

    for (t = 0; t < f.elements.length; t++) {

        var elid = new String(f.elements[t].id);



        if (elid.indexOf("specialty") > 0) {

            var fe = document.getElementById(elid);

            //if (fe.options[fe.selectedIndex].value !== "Select") 
            //{
            //	usespec = 1;
            //specvalue = fe.options[fe.selectedIndex].value;
            searchstring = searchstring + elid + "~" + escape(fe.options[fe.selectedIndex].value) + "|";

            //}

        }

        if (elid.indexOf("city") > 0) {

            var fe = document.getElementById(elid);


            searchstring = searchstring + elid + "~" + fe.options[fe.selectedIndex].value + "|";



        }


        if (elid == "lname") {
            var fe = document.getElementById(elid);

            searchstring = searchstring + elid + "~" + fe.value + "|";


        }
        else if (elid == "practicename") {
            var fe = document.getElementById(elid);

            searchstring = searchstring + elid + "~" + fe.value + "|";


        }



        else {

        }






    } // for next?


    searchstring = searchstring.substring(0, searchstring.length - 1);


    window.location.href = "detail.aspx?recid=" + id + "&searchstring=" + searchstring


}


function dohover(recid, e) {

    q = "/ui/ajaxgetrow.aspx?recid=" + recid;

    var loader1 = new net.ContentLoader(q, sortoutpop, null, "GET", "");



    d = document.getElementById("popup");
    d.style.visibility = "visible";

    setLyr2("r" + recid, "popup");
    //d.style.left = (e.clientX + 100) + "px";
    //d.style.top = (e.clientY - 50) + "px" ;
    //alert(e.clientX);
   // setOpacity(50, "wholetable");

}



function handleOut() {
    d = document.getElementById("popup");
    d.style.visibility = "hidden";
    d.style.left = "-650px";
}


function sortoutpop() {

    alldata = new String(this.req.responseText);
    ardata = alldata.split("~");

    for (i = 0; i < ardata.length; i++) {
        if (ardata[i].indexOf("fullname=") > -1) {
            fullname = ardata[i].replace("fullname=", "");

        }

        if (ardata[i].indexOf("specialty=") > -1) {
            specialty = ardata[i].replace("specialty=", "");

        }
        if (ardata[i].indexOf("address1=") > -1) {
            address1 = ardata[i].replace("address1=", "");

        }
        if (ardata[i].indexOf("address2=") > -1) {
            address2 = ardata[i].replace("address2=", "");

        }
        if (ardata[i].indexOf("city=") > -1) {
            city = ardata[i].replace("city=", "");

        }
        if (ardata[i].indexOf("state=") > -1) {
            state = ardata[i].replace("state=", "");

        }
        if (ardata[i].indexOf("zip=") > -1) {
            zip = ardata[i].replace("zip=", "");

        }
        if (ardata[i].indexOf("phone=") > -1) {
            phone = ardata[i].replace("phone=", "");

        }
        if (ardata[i].indexOf("fax=") > -1) {
            fax = ardata[i].replace("fax=", "");

        }
        if (ardata[i].indexOf("email=") > -1) {
            email = ardata[i].replace("email=", "");

        }
        if (ardata[i].indexOf("website=") > -1) {
            website = ardata[i].replace("website=", "");

        }
        if (ardata[i].indexOf("image=") > -1) {
            image = ardata[i].replace("image=", "");

        }


    }

    strlocation = address1 + "<br>";
    if (address2 == "") {

    }
    else {
        strlocation = strlocation + address2 + "<br>";
    }
    strlocation = strlocation + city + ", " + state + " " + zip;

    scontactinfo = phone + " (office)<br>" + fax + " (fax)<br><a href='mailto: " + email + "' >" + email + "</a><br><a target=new href='" + website + "' >" + website + "</a>";


    document.getElementById("fullnamespec").innerHTML = fullname + "<br>" + specialty;
    document.getElementById("location").innerHTML = strlocation;
    document.getElementById("contactinfo").innerHTML = scontactinfo;
    if (image !== "") {
        document.getElementById("baseballphoto").style.display = "inline";
        document.getElementById("baseballphoto").src = image;
    }
    else {
        document.getElementById("baseballphoto").style.display = "None";
    }






}

function showsearch() {
    td = document.getElementById("searchpane");
    im = document.getElementById("ss1");
    im2 = document.getElementById("finddoctor");
    //btn_refine_search_closed.gif

    if (td.style.display == "none") {


        td.style.display = "block";
        im.src = "/images/images_people/btn_refine_search.gif";
        im2.src = "/images/images_people/btn_close.gif";

    }
    else {
        td.style.display = "none";
        im.src = "/images/images_people/btn_refine_search_closed.gif";
        im2.src = "/images/images_people/btn_open.gif";

    }

}


var pagenum = 0;
var sort = "";
var totalsearches = 0;
function runsearch(num) {

    pagenum = num;
    //setOpacity(1, "tableresults");

    f = document.forms[0];

    practicevalue = "";
    cityvalue = "";
    var lnamevalue = new String("");
    langvalues = "";
    gendervalue = "";
    specvalue = "";
    searchstring = "";
    var integrative = false;
    numd = 0;

    for (t = 0; t < f.elements.length; t++) {

        var elid = new String(f.elements[t].id);


/*
        if (document.getElementById("hbIntegrative").value == "true") {
            // clear it out for any subsequent search
            document.getElementById("hbIntegrative").value = "";
            integrative = true;
        }
        else 
        */
        {
            if (elid.indexOf("specialty") > 0) {

                var fe = document.getElementById(elid);

                //if (fe.options[fe.selectedIndex].value !== "Select") 
                //{
                //	usespec = 1;
                specvalue = fe.options[fe.selectedIndex].value;

                //}

            }
            if (elid.indexOf("city") > 0) {

                var fe = document.getElementById(elid);

                //if (fe.options[fe.selectedIndex].value !== "Select") 
                //{
                //	usespec = 1;
                cityvalue = fe.options[fe.selectedIndex].value;
                //	
                //}

            }

            if (elid == "lname") {
                var fe = document.getElementById(elid);

                lnamevalue = fe.value;

            }
            else if (elid == "practicename") {
                var fe = document.getElementById(elid);

                practicevalue = fe.value;

            }


            else {

            }
        }





    } // for next?



    if (lnamevalue !== "") {
        searchstring = searchstring + "[lastname] like '" + escape(lnamevalue.replace("'", "''")) + "**' and ";
        //lnamevalue = lnamevalue.substring(0,1).toUpperCase() + lnamevalue.substr(1);
       // alert(lnamevalue);
        //searchstring = searchstring + "[lastname] like '" + lnamevalue.replace("'", "''") + "**' and ";
    }
    if (practicevalue !== "") {
        //searchstring = searchstring + "[office locations] like '" + practicevalue + "**' and " ;
        searchstring = searchstring + "[officelocations] like '" + escape(practicevalue.replace("'", "''")) + "**' and ";
    }
    /**************************
    if (integrative == true) {
        searchstring = searchstring + "[IsIntegrativeMedicine] = 'True' and";
    } // integrative and specialties are mutually exclusive    
    else 
    ***************************/
    if (specvalue !== "Select") {
        //searchstring = searchstring + "[specialty] = '" + escape(specvalue) + "' and " ;

        searchstring = searchstring + "[specialty]  like '**" + escape(specvalue.replace("'", "''")) + "**' and ";
        //searchstring = searchstring + "[specialty]  = '" + escape(specvalue.replace("'", "''")) + "' and ";
       
    }
    if (cityvalue !== "Select") {
        //searchstring = searchstring + "[office locations] like '**|" + cityvalue + "**' and " ;
        searchstring = searchstring + "[alltowns] like '**" + cityvalue.replace("'", "''") + ",**' and "
    }
    

    // and
    searchstring = searchstring.substr(0, searchstring.length - 4);

    //stamfordhealthintegratedpractices
    totalsearches++;
    var ref = new String();
    ref = document.referrer;
    if (ref.indexOf("stamfordhealthintegratedpractices") > -1) {
        if (totalsearches <= 1) { // only the first search coming in should be ship?
            if (searchstring.length > 1) {
                searchstring = searchstring + " and [isSHIP] = 'True' ";
            }
            else {
                searchstring = searchstring + " [isSHIP] = 'True' ";
            }
        }
    } 
    else if (ref.match(/stamfordhospitalintegrative/i)) {
        if (totalsearches <= 1) { // only the first search coming in should be IM?
            if (searchstring.length > 1) {
                searchstring = searchstring + " and [IsIntegrativeMedicine] = 'True' ";
            }
            else {
                searchstring = searchstring + " [IsIntegrativeMedicine] = 'True' ";
            }
        }
    }

    //q = "/ui/ajaxgetrows.aspx?searchstring=" + searchstring + "&sort=" + sort;
    q = "/ui/ajaxgetrowsnew.aspx?searchstring=" + searchstring + "&sort=" + sort;
  

    var loader1 = new net.ContentLoader(q, searchaction, null, "GET", "");


} // end function


function searchaction() {


    var alldata = document.getElementById("alltext");
    var strdata = new String();
    strdata = this.req.responseText;
    if (strdata.length <= 100) {
        alldata.innerHTML = strdata + "<div style='padding: 30px 30px 30px 30px' >We're sorry, there were no results for your search</div>";
        var trecs = document.getElementById("trecs").innerHTML;
        document.getElementById("found").innerHTML = "0 of " + trecs + " doctors found";
        return;

    }
    else {
        alldata.innerHTML = strdata;
    }


    sortables_init();

    dopages(1);

}

function dopages(pagenum) {

    var nrecpages = document.getElementById("numperpage");
    nperpage = nrecpages.options[nrecpages.selectedIndex].value;

    var newheight = 0;

    beginslice = (pagenum * nperpage) - nperpage + 1;
    endslice = (pagenum * nperpage);


    var tab = document.getElementById("tableresults"); //the all table
    var tbod = tab.getElementsByTagName("tbody");

    var trs = tbod[0].getElementsByTagName("tr");

    var totalrecords = trs.length;
    r = 0;




    for (i = 0; i < trs.length; i++) {

        trs[i].style.backgroundColor = "#f4f7fc";
        r++;

        if ((r <= endslice) && (r >= beginslice)) {
            trs[i].style.display = "";
        }
        else {
            trs[i].style.display = "none";
        }


    } // for


    var trecs = document.getElementById("trecs").innerHTML;

    document.getElementById("found").innerHTML = r + " of " + trecs + " doctors found";
    // assume on first page

    if (nperpage == "All") {
        nperpage = 5000;
    }

    var alldata = document.getElementById("alltext");
    alldata.style.height = "95%";

    totalpages = Math.floor(r / nperpage) + 1;
    if (totalpages > 1) {
        if ((pagenum - 1) == 0) {
            strpages = "<a id='previous' href=# onclick='return false;' >&laquo; </a>"
        }
        else {
            strpages = "<a id='previous' href=# onclick='dopages(" + (pagenum - 1) + ");return false;' >&laquo; </a>"
        }
    }
    else {
        strpages = "";
    }

    strpages = strpages + "&nbsp;pg&nbsp;" + pagenum + "&nbsp;of&nbsp;" + totalpages + "&nbsp;";


    if (totalpages > 1) {
        if ((pagenum + 1) > totalpages) {
            strpages = strpages + "<a id='next' href='#' onclick = 'return false;' >&raquo;</a>";
        }
        else {
            strpages = strpages + "<a id='next' href='#' onclick = 'dopages(" + (pagenum + 1) + "); return false;' >&raquo;</a>";
        }
    }

    document.getElementById("pager").innerHTML = strpages;




}
function doqs() {
    var sl = new String(window.location.search)
    if (sl.length > 3) {

        scrit = getQueryVariable("searchstring");
        arcrit = scrit.split("|");

        for (u = 0; u < arcrit.length; u++) {

            parts = arcrit[u].split("~");
            fe = document.getElementById(parts[0]);
/*
            if (parts[0].match(/specialty/i) && parts[1] != null && parts[1].match(/Integrative( |%20|\+)Medicine/i)) {
                document.getElementById("hbIntegrative").value = "true";               
            }
            else 
*/            
            if (fe.type == "text") {
                fe.value = unescape(parts[1]);
            }
            else if (fe.type == "select-one") {

                for (t = 0; t < fe.options.length; t++) {
                    //.replace('%20',' ')

                    if (fe.options[t].value == unescape(parts[1])) {
                        fe.options[t].selected = true;
                    }
                }
            }
        }

        runsearch(1);



    } //is search string
    else {
        runsearch(1);
    }


}


function closepopup() {

    document.getElementById("popup").style.top = "-650px";
    //setOpacity(100, "wholetable");
}


function setLyr(obj1, lyr) {
    obj = document.getElementById(obj1);
    var newX = findPosX(obj);
    var newY = findPosY(obj);

    var x = document.getElementById(lyr);
    x.style.top = (newY + 13) + 'px';
    x.style.left = newX + 'px';
    //x.style.backgroundColor = "whitesmoke";
    //window.setTimeout ("closerv();",8000);

}
function setLyr2(obj1, lyr) {
    obj = document.getElementById(obj1);
    var newX = findPosX(obj);
    var newY = findPosY(obj);

    var x = document.getElementById(lyr);
    x.style.top = (newY - 50) + 'px';
    x.style.left = (newX + 170) + 'px';
    //x.style.backgroundColor = "whitesmoke";
    //window.setTimeout ("closerv();",8000);

}

function findPosX(obj) {
    var curleft = 0;

    if (obj.offsetParent) {
        while (obj.offsetParent) {

            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    var printstring = '';
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;

    return curtop;
}



function closerv() {
    var r = document.getElementById("rv");
    r.style.left = "200px";
    r.style.top = "-500px";
}



function doaddcompare(id) {
    var sfullname = "";
    tr = document.getElementById("r" + id);
    tds = tr.getElementsByTagName("td");
    if (browser.IsIE) {
        sfullname = tds[1].innerText;
    }
    else {
        sfullname = tds[1].textContent;
    }


    var strParams = "recid=" + id + "&sfullname=" + sfullname;

    var loader2 = new net.ContentLoader("/UI/ajaxaddcompare.aspx?" + strParams, updatedisplay, null, "GET", "");


}
function doaddcompare2(id, sfullname) {

    var strParams = "recid=" + id + "&sfullname=" + sfullname;
    var loader1 = new net.ContentLoader("/UI/ajaxaddcompare.aspx?" + strParams, updatedisplay, null, "POST", "");

}

function updatedisplay() {
    // change controls on other pages //ABOVE TO
    var d = document.getElementById("ctl00_cphMainContent_FindDoctors1_compareto");

    d.innerHTML = this.req.responseText;
}
