

curhover = 0;

function dohover(recid) {

curhover = recid;
q = "/ui/usercontrols/physicianfinder/ajaxgetrow.aspx?recid=" + recid ;

var loader1 = new net.ContentLoader(q, sortoutpop,null,"GET","");	



//d = document.getElementById("popup") ;
//d.style.visibility = "visible";




//setOpacity(25,"wholetable") ;

}



//function handleOut() {

//Spry.Effect.AppearFade('popup', {duration:1000,from:100,to:0});

//d = document.getElementById("popup") ;
//d.style.visibility = "hidden";
//d.style.left = "-650px";
//}


function sortoutpop() {

//Spry.Effect.AppearFade('popup', {duration:400,from:0,to:100});


alldata = new String(this.req.responseText) ;

ardata = alldata.split ("~") ;
image = "";
address1 = "";
address2 = "";
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("practicename=") > -1) {
		practicename = ardata[i].replace("practicename=","") ;
		
	}
	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("image=") > -1) {
		image = ardata[i].replace("image=","") ;
		
	}
		

}
var strlocation = "";

if (practicename == "")
{

}
else
{
    strlocation = practicename + "<br/>" ;
}

if (address1 == "")
{

}
else
{
strlocation = strlocation + address1 + "<br/>" ;
}
if (address2 == "")
{

}
else
{
strlocation = strlocation + address2 + "<br/>" ;

}

strlocation = strlocation + city + ", " + state + " " + zip ;

scontactinfo = phone + " (office)" ;

document.getElementById("drlink").innerHTML = "<img src='/ui/images/DrFinder/Df_arrow_pop.gif' alt='' width='15' height='14' border='0' style='padding-right:5px; vertical-align:middle;' />" + fullname  ;
document.getElementById ("drlink").href = "detail.aspx?recid=" + curhover ;
document.getElementById ("popspecialties").innerHTML = specialty ;
document.getElementById("locationinfo").innerHTML =  strlocation + "<br>" + scontactinfo ;
document.getElementById ("vcard").href = "/ui/usercontrols/physicianfinder/createVcard.aspx?recid=" + curhover ;



if (image !== "")
{

    document.getElementById ("drphoto").style.display  = "inline" ;
    document.getElementById ("drphoto").src = "http://sitemanager.acsysinteractive.com/webservices/genImage.aspx?h=135&w=102&fil=/" + image.substring(image.toLowerCase().indexOf("/vsitemanager"));

	//document.getElementById ("drphoto").src = image ;
}
else
{
	document.getElementById ("drphoto").style.display  = "None" ;
}



setLyr2(curhover, "popup") ;


}



var pagenum = 0;
var sort = "" ;
var friendlysort = "";
var sortorder = "desc";
var fresh = 1;

function runsearch(num,sortstring) {

pagenum = num ;
friendlysort = sortstring ;

f = document.forms[0];


lnamevalue = "";
locvalue = "";
gendervalue = "";
specvalue = "" ;
searchstring = "";
cancvalue = "";
neurovalue = "";
heartvalue = "";
orthovalue = "";

numd = 0;
var cookiestring = "";



 if (sortorder == "desc")
    {
        if (pagenum > 1)
        {
        
        }
        else
        {
        if (fresh == 1)
        {
        sortorder = "asc";
        }
        }
        
    }
    else
    {
        if (pagenum > 1)
        {
        
        }
        else
        {
        if (fresh == 1)
        {
        sortorder = "desc";
        }
        }
    }


if (sortstring == "Doctor Name")
{
   
    sort = "lastname " + sortorder ;
    
}
else if (sortstring == "Location")
{
    sort = "(select top 1 city from Halifax_list_locations where recordid = (select top 1 relatedid from trelateditems where recordid = Halifax_list_doctors.recordid and masterlistid = 37 and relatedtablename = 'Halifax_list_locations' and relatedgroup = 'Halifax_list_locations'  order by primaryorder )) " + sortorder ;
}
else if (sortstring == "Specialties")
{
    sort = "(select top 1 longname from toptions where optionid = (select top 1 relatedid from trelateditems where recordid = halifax_list_doctors.recordid and masterlistid = 37 and relatedtablename = 'toptions' and relatedgroup = 'Specialty'  order by primaryorder )) " + sortorder ;
}
else if (sortstring == "Gender")
{
    sort = "gender " + sortorder ;
}

else
{

}
fresh = 0;

for (t=0;t < f.elements.length;t++) {
	
	var elid = new String(f.elements[t].id) ;
	 
	if (elid.indexOf ("specialties") > 0) {
	
		var fe = document.getElementById (elid) ;
		
		specvalue = fe.options[fe.selectedIndex].value;	
		cookiestring = cookiestring + elid + "~" + specvalue + ";" ;
		
	}
	
	
	if (elid == "lname") {
		var fe = document.getElementById (elid) ;
		
		lnamevalue = fe.value ;
		cookiestring = cookiestring + elid + "~" +lnamevalue + ";" ;
	
	}
	
	if (elid.indexOf("location") >= 0) {
		var fe = document.getElementById (elid) ;
		
		locvalue = fe.options[fe.selectedIndex].value ;
		cookiestring = cookiestring + elid + "~" +locvalue + ";" ;
	
	}
	
	if (elid.indexOf ("gender") >= 0) {
	    var fe = document.getElementById (elid) ;
		
		gendervalue = fe.options[fe.selectedIndex].value ;
		cookiestring = cookiestring + elid + "~" + gendervalue + ";" ;
			
	}
	
	if (elid.indexOf ("chkcancer") >= 0) {
	    var fe = document.getElementById (elid) ;
		if (fe.checked )
		{
		cancvalue = fe.value ;
		cookiestring = cookiestring + elid + "~" + cancvalue + ";" ;
		}	
	}
	
	if (elid.indexOf ("chkneuro") >= 0) {
	    var fe = document.getElementById (elid) ;
		if (fe.checked )
		{
		neurovalue = fe.value ;
		cookiestring = cookiestring + elid + "~" + neurovalue + ";" ;
		}	
	}
	
	if (elid.indexOf ("chkheart") >= 0 ) {
	    var fe = document.getElementById (elid) ;
		if (fe.checked )
		{
		heartvalue = fe.value ;
		cookiestring = cookiestring + elid + "~" + heartvalue + ";" ;
		}
	}
	
	if (elid.indexOf ("chkortho") >= 0 ) {
	    var fe = document.getElementById (elid) ;
		if (fe.checked )
		{
		orthovalue = fe.value ;
		cookiestring = cookiestring + elid + "~" + orthovalue + ";" ;
		}
	}
	
	
	
	
			
} // for next?



if (lnamevalue !== "") {
   
    
	searchstring = searchstring + " ( [lastname] like '" + lnamevalue.replace("'","''") + "%' ) and " ;
}

if (locvalue !== "") {
	
	 searchstring = searchstring + " ( recordid in (select recordid from trelateditems where relatedtablename = 'halifax_list_locations' and relatedgroup = 'halifax_list_locations' and masterlistid = 37 and relatedid in (select recordid from halifax_list_locations where city = '" + escape(locvalue) + "'))) and " ;

}



if (gendervalue !== "")
{
    searchstring = searchstring + "( [gender] = '" + gendervalue + "' ) and " ;
}

if (specvalue !== "") {
	// + "[specialties] like '**" + escape(specvalue) + "**' and " ;
	searchstring = searchstring + " ( recordid in (select recordid from trelateditems where relatedtablename = 'toptions' and relatedgroup = 'Specialty' and masterlistid = 37 and relatedid in (select optionid from toptions where longname like '" + escape("%" + specvalue + "%") + "'))) and " ;
}

searchstring = searchstring.substr(0,searchstring.length - 4) ;

var servicestring = "";

if (cancvalue !== "")
{
     
     servicestring = servicestring + " or ( recordid in (select recordid from trelateditems where relatedtablename = 'toptions' and relatedgroup = 'Specialty' and masterlistid = 37 and relatedid in (select optionid from toptions where longname like '" + escape("%" + cancvalue + "%") + "')) )" ;  
    
}
if (orthovalue !== "")
{
    
     servicestring = servicestring + " or ( recordid in (select recordid from trelateditems where relatedtablename = 'toptions' and relatedgroup = 'Specialty' and masterlistid = 37 and relatedid in (select optionid from toptions where longname = '" + escape(orthovalue) + "')) )" ;   
    
}
if (heartvalue !== "")
{
    
     servicestring = servicestring + " or ( recordid in (select recordid from trelateditems where relatedtablename = 'toptions' and relatedgroup = 'Specialty' and masterlistid = 37 and relatedid in (select optionid from toptions where longname like '" + escape("%" + heartvalue + "%") + "')) )" ;   
    
}
if (neurovalue !== "")
{
   //Neurological Rehabilitation
     servicestring = servicestring + " or ( recordid in (select recordid from trelateditems where relatedtablename = 'toptions' and relatedgroup = 'Specialty' and masterlistid = 37 and relatedid in (select optionid from toptions where longname = '" + escape(neurovalue) + "' or longname = 'Neurological Rehabilitation' or longname = 'Neuroradiology'   )) ) ";
    
}


// and


SetCookie ("s",cookiestring) ;
if (servicestring !== "")
{
    servicestring = servicestring.substring(3,servicestring.length);
}

if (searchstring !== "")
{
    if (servicestring !== "")
    {
    servicestring = " and ( " + servicestring + " )";
    }
}

q = "/ui/usercontrols/physicianfinder/ajaxgetrows.aspx?searchstring=" + searchstring + servicestring + "&page=" + num + "&sort=" + sort;

//alert(q);

var loader1 = new net.ContentLoader(q, searchaction,null,"GET","");	




} // end function


function searchaction ()
{


	var alldata = document.getElementById ("alltext") ;
	  // document.getElementById ("alltext").innerHTML = this.req.readyState ;
	  

	alldata.innerHTML = this.req.responseText ;	
	
	//sortables_init();	
	//alert(alldata.innerHTML);
    

	dopages(pagenum) ;
}	

function dopages(pnum)
{

	//var nrecpages = document.getElementById ("numperpage") ;
	nperpage = 20 ;
    var newheight = 0 ;


	beginslice = (pnum * nperpage) - nperpage + 1;
	endslice = (pnum * nperpage) ;
	var filteredtotal = 0;

    if (document.getElementById ("tableresults"))
	{
	        var tab = document.getElementById ("tableresults") ; //the all table
	        var tbod = tab.getElementsByTagName("tbody");

	        var trs = tbod[0].getElementsByTagName("tr") ;
	        //var trs = tab.getElementsByTagName("tr") ;
        	
	        
	        if (document.getElementById("filteredrecs"))
	        {	
	         filteredtotal = document.getElementById("filteredrecs").innerHTML ;
	         }
        	
	        r=0;
	
	
	
	
	            for (i=0;i < trs.length; i++) {
            	
		            // alternate rows here		
		            if (i % 2 == 0)
		            {
		            trs[i].className = ""; //style.backgroundColor = "#edefe4";		
		            }
		            else
		            {
		            trs[i].className = "TblHdrTwo" ;//style.backgroundColor = "#dcdec9";
		            }
            			
		            r++;		
	            } // for

		} // if there is a result set
		var trecs = document.getElementById ("trecs").innerHTML ;

		document.getElementById ("found").innerHTML =  filteredtotal  ;
		if (filteredtotal == 0)
		{
		    document.getElementById ("alltext").innerHTML += "<div style='padding-left: 20px;' ><br><br><br>We're sorry no doctors match your criteria, please revise your search and try again.</div>";
		}	
	    
		
// assume on first page
       
      //  newheight = nperpage * 39 ;
	//	if (nperpage == 5000) {
			
	//		newheight = 0;
	//		newheight = r * 41 ;
	//	}
        
        
		totalpages = Math.ceil (filteredtotal / nperpage)  ;
		
		// size adjust
		//var alldata = document.getElementById ("alltext") ;
		//alldata.style.height = newheight + "px" ;
		
		if (totalpages > 1) {
			if ((pagenum - 1) == 0) 
			{
				strpages = "<a id='previous' href=# onclick='return false;' >&laquo; </a>";
			}
			else
			{
				strpages = "<a id='previous' href=# onclick=\"runsearch(" + (pagenum - 1) + ",'" + friendlysort + "');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 = \"runsearch(" + (pagenum + 1) + ",'" + friendlysort + "'); return false;\" >&raquo;</a>";
			}
		}
       
		document.getElementById("pager").innerHTML = strpages;
        //document.getElementById("pager2").innerHTML = strpages;
		

}




function setOpacity(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")";
}

function getOpacity(id) {
	var object = document.getElementById(id).style; 
	if (object.opacity) return (object.opacity*100);
	return (100);
}


function closepopup() {

	document.getElementById ("popup").style.top = "-1000px";
	//document.getElementById("numperpage").style.visibility = 'visible';
	
	
	//Spry.Effect.AppearFade('popup', {duration:400,from:100,to:0});
	
	//setOpacity(100,"wholetable") ;
}


function setLyr10(obj1,lyr)
{

	obj = document.getElementById (obj1) ;
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	
	var x = document.getElementById(lyr);
	
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.version == "3")
	{
	    x.style.top = (newY + 195) + 'px';
	
		x.style.left = (newX - 15) + 'px';
	}
	else
	{
	
	    x.style.top = (newY + 15) + 'px';
	    x.style.left = (newX - 30) + 'px';
	}
	
	
	
	
}
function setLyr2(obj1,lyr)
{
	obj = document.getElementById ("r" + obj1) ;
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	
	var x = document.getElementById(lyr);
	
	if(BrowserDetect.browser == "Firefox" && BrowserDetect.version == "3")
	{
		x.style.top = (newY + 200) + 'px';
		x.style.left = (newX + 100) + 'px';	
	}
	else
	{
		x.style.top = (newY + 22) + 'px';
		x.style.left = (newX + 100) + 'px';	
	}
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }



function closerv() {
	var r = document.getElementById ("rv");
	r.style.left = "-600px";
	r.style.top = "-200px";
}
function closerv1() {
	var r = document.getElementById ("rv1");
	r.style.left = "-600px";
	r.style.top = "-200px";
}

function getCompare()
{
 var loader3 = new net.ContentLoader("/UI/UserControls/PhysicianFinder/ajaxgetcompare.aspx", updatecompare,null,"GET","");	
    
}
function updatecompare()
{
    if (this.req.responseText !== "")
    {
        document.getElementById ("comparerows").innerHTML = this.req.responseText ;
        setLyr10('rcv1','rv1');
    }
}


function doaddcompare(id) {
	var sfullname = "";
	
	el = document.getElementById ("ck" + id);
	
	
	if (el.checked )
	{
	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/UserControls/PhysicianFinder/ajaxaddcompare.aspx?" + strParams, updatedisplay,null,"GET","");	
    }
    else
    {
        // remove
         var loader2 = new net.ContentLoader("/UI/UserControls/PhysicianFinder/ajaxremovecompare.aspx?recid=" + id, updatedisplay ,null,"GET","");	
    }
    

}


function updatedisplay() {
	// change controls on other pages //ABOVE TO
	
	
	var d = document.getElementById ("rcv1") ;
	if (this.req.responseText == "0")
	{
	    d.href = "#";
	}
	else
	{
	    d.href = "compare.aspx";
	}
	d.innerHTML = "Compare: " + this.req.responseText;
}

function SetCookie(sName, sValue)
{
  date = new Date()  ;
  var m = date.getMinutes ();
  m += 1;
  date.setMinutes (m);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function setSearchValues ()
{


        
		var wholevalue = new String() ;
		wholevalue = GetCookie("s");
		
		
	    if (window.location.search == "")
		{ // look for cookie and saved value
		
		if (wholevalue !== null)
		{
			wholevalue = wholevalue.substring (0, wholevalue.length - 1) ; // last semi
			arwhole = wholevalue.split (";");
			
			for (i=0;i<arwhole.length;i++)
			{
				arval = arwhole[i].split("~") ;
				
				
				if (arval.length == 2)
				{
					field = arval[0] ;
					val = arval[1] ;
					
					el = document.getElementById(field) ;
					
					if (el.type == "select-one")
					{
							for (t=0;t<el.options.length;t++) 
							{
								
								if (el.options[t].value == val )
								{
									el.options[t].selected = true;
								}
								
							}
					}
					else if (el.type == "text")
					{
						el.value = val ;
					}
					else if (el.type == "checkbox")
					{
					    
						if (val !=="")
						{
							el.checked = true;
						}
						else
						{
							el.checked = false;
						}
						
						
					}
					else if (el.type == "radio")
					{
						if (val=="Male")
						{
							el.checked = true;
						}
						else if (val == "Female")
						{
						    el.checked = true ;
						}
						else
						{
							el.checked = true;
						}
					}
					else { 
					
				    }		
			
			    }
		
		    }
		
		}
		

		} // end look for queries
		else
		{
		
		    lname = getQueryVariable("lname");
    		

		    if(lname !== "")
		    {
		        el = document.getElementById("lname");	    
		        el.value = unescape(lname);			
    		    
		    }
    		
		    gender = getQueryVariable("gender");
    		
		    if (gender !== "")
		    {
    		
		        el = document.getElementById ("gender"); 
		        if (gender.toLowerCase() == "male")
		        {
		            el.selectedIndex = 1;
		        }
		        else if (gender.toLowerCase() == "female")
		        {
		            el.selectedIndex = 2;
		        }
		        else
		        {
		            el.selectedIndex = 0;
		        }
    		    
		    }
    		
    		
    		
		     val = getQueryVariable("specialty");
    		
		    if(val !== "")
		    {
    		   
		        el = document.getElementById(findControl("specialties"));
    		    		 
		        if (val == "None")
		        {
		            val = "";
		        }
		   	    for (t=0;t<el.options.length;t++) 
			    {
				    if (el.options[t].value == unescape(val) )
				    {
			    	    el.options[t].selected = true;
				    }				
			    }	    
		    }
    		
    		
		     val = getQueryVariable("town");
    		
		    if(val !== "")
		    {
    		   
		        el = document.getElementById(findControl("locations"));
    		   		 
		        if (val == "None")
		        {
		            val = "";
		        }
		   	    for (t=0;t<el.options.length;t++) 
			    {
				    if (el.options[t].value == unescape(val) )
				    {
			    	    el.options[t].selected = true;
				    }				
			    }	    
		    }
		
		
        }		
		
		
		
}
