// JavaScript Document for pNav childNav Menu
<!--

var subNavActive = false;

function subNav(){
	subNavActive = true;	
}

function navchildNav_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 navchildNav_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function navchildNav_show(childNav, parentId, posX, posY, pnavID, theItem)
{
    navCHildNav_hideAll("subnav");
	it = document.getElementById("subnav");
	subObj = document.getElementById(childNav);
    navParent_active(theItem);
	
    if ((it.style.top == '' || it.style.top == 0) 
        && (it.style.left == '' || it.style.left == 0))
    {
        // need to fixate default size (MSIE problem)
        it.style.width = it.offsetWidth + 'px';
        it.style.height = it.offsetHeight + 'px';
        
        obj = document.getElementById(parentId); 
    
        // if tooltip is too wide, shift left to be within parent 
        if (posX + it.offsetWidth > obj.offsetWidth) posX = obj.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = navchildNav_findPosX(obj) + posX;
        y = navchildNav_findPosY(obj) + posY;
        
        it.style.top = y + 'px';
        it.style.left = x + 'px';
    }
    
    it.style.visibility = 'visible'; 
	subObj.className = '';

	subNavActive = true;
}

it = this.document.getElementById("subnav");
if(it) {
	if ((it.style.top == '' || it.style.top == 0) 
		&& (it.style.left == '' || it.style.left == 0))
	{
			
			it.style.width = it.offsetWidth + 'px';
			it.style.height = it.offsetHeight + 'px';
			if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
			if (posX < 0 ) posX = 0; 
			x = navchildNav_findPosX(img) + posX;
			y = navchildNav_findPosY(img) + posY;
			
			it.style.top = y + 'px';
			it.style.left = x + 'px';
			it.style.visibility = 'visible'; 
	}
}


function navchildNav_hide(id, pnavID)
{
    /*
	it = document.getElementById(id); 
    it.style.visibility = 'hidden'; 
	*/
	InitializeTimer(1);
	subNavActive = false;
}

function navParent_active(theItem){
	navParent = document.getElementById("parent");
	//alert(navParent.childNodes.length + '  ' + theItem);
	for(x=0; x < navParent.childNodes.length; x++){
		if(navParent.childNodes[x].hasChildNodes()){
			if(navParent.childNodes[x].firstChild.name == theItem && navParent.childNodes[x].firstChild.className != 'active'){
				navParent.childNodes[x].firstChild.className = 'over';
				//alert(navParent.childNodes[x].firstChild.className);
			} else {
				if(navParent.childNodes[x].firstChild.className != 'active'){
					navParent.childNodes[x].firstChild.className = '';
				}
			}
		}
		
	}
}

function _remNavII(){
    it = this.document.getElementById('leftCol');
    if(it.childNodes[0].childNodes[0].nodeName == "UL" && !it.childNodes[0].childNodes[0].hasChildNodes())
         it.childNodes[0].childNodes[0].removeNode(false); //it.childNodes[0].childNodes[0].style.display="none";
    else
        alert(it.childNodes[0].childNodes[0].nodeName);

        
}

function navCHildNav_hideAll(id)
{
	//Lets make sure to hide all sub nav items before we display
	it = this.document.getElementById(id);
	for(x=0; x < it.childNodes.length; x++){
		if(it.childNodes[x].nodeName == "DIV"){
			it.childNodes[x].className = 'subNavObj';
		}
	}
}

var secs
var timerID = null
var timerRunning = false
var delay = 1500

function InitializeTimer(time)
{
    // Set the length of the timer, in seconds
    secs = time
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0 & !subNavActive)
    {
        StopTheClock()
        // What to do when time is reached function call or direct response 
		// We are hidding the subnav layer and removing the parent menu className
        it = document.getElementById("subnav"); 
	    it.style.visibility = 'hidden'; 
		navParent_active('none');
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}




/* ############################################################# */
/* 						Attorney Stats 							 */
/* ############################################################# */
var statsVis = false;

function stats_show(parentId)
{
	if(!statsVis){
		//node = 3 + nodeOffset;
		
		if(IEn){
			obj = document.getElementById(parentId);
			it = obj.lastChild;
			obj1 = obj.firstChild;
			if(obj1.hasChildNodes()){
				obj2 = obj1.firstChild;
				//alert("has child nodes" + obj2.nodeName);	
			}
		} else {
			obj = document.getElementById(parentId);
			it = obj.childNodes[3];
			obj1 = obj.childNodes[1];
			if(obj1.hasChildNodes()){
				obj2 = obj1.childNodes[0];
			}
			//alert(obj.childNodes[1].nodeName + " \n" + obj.childNodes[3].nodeName);
		}

	old = document.getElementById('activeAtt');
	if(old) {
		old.id = '';
	}

    
    paObj = "pa"+parentId;
    paSet = document.getElementById(paObj);


	newValue = it.innerHTML;

	obj2.id = 'activeAtt';
	vs = document.getElementById("attorneyPreview"); 
	
		x = navchildNav_findPosX(obj1);
       	y = navchildNav_findPosY(obj1);	
		py = navchildNav_findPosY(vs);
		newYpadding = (y - py - obj.offsetHeight) + 32 ;
		if(newYpadding < 0){
			newYpadding = 0;	
		}
	    
	    vs.innerHTML = "<div style='margin-top:"+newYpadding+"px !important;'>" + newValue + "</div>";
	    
    //vs.innerHTML = newValue;    //copy to VS area
    
    statsVis = true;

    // LOAD PRACTICE AREA TO SEARCH MOUSEOVER RESULT
    //getMyPA("ajax/attorney_practice_areas.aspx?id="+parentId,paObj,parentId);
    if(!paSet){
        getMyPA("ajax/attorney_practice_areas.aspx?id="+parentId,parentId,paObj);
        statsVis = false;
    }
    //newValue += "<div id='myPA'>test</div>"




	
	}
}

function stats_hide(obj){
	//node = 1 + nodeOffset;
/*	
	it = document.getElementById(obj);
	if(IEn){
		it.firstChild.className = '';
		it.lastChild.className = 'vitalStats';
	} else {
		it.childNodes[1].className = '';
		it.childNodes[3].className = 'vitalStats';
	}
*/
	InitializeTimerAtt(0);
	statsVis = false;

}

var IEn = document.all?true:false
if (IEn) { // grab the x-y pos.s if browser is IE
	nodeOffset = -1;
} else {  // grab the x-y pos.s if browser is NS
	nodeOffset = 0;
}  

var secsAtt
var timerIDatt = null
var timerRunningAtt = false
var delayAtt = 250

function InitializeTimerAtt(time)
{
    // Set the length of the timer, in seconds
    secsAtt = time
    StopTheClockAtt()
    StartTheTimerAtt()
}

function StopTheClockAtt()
{
    if(timerRunningAtt)
        clearTimeout(timerIDatt)
    timerRunningAtt = false
}

function StartTheTimerAtt()
{
    if (secsAtt==0 & !statsVis)
    {
        StopTheClockAtt()
        // What to do when time is reached function call or direct response 
		// We are hidding the subnav layer and removing the parent menu className
        it = document.getElementById("attorneyPreview"); 
	    //it.style.visibility = 'hidden'; 
		//navParent_active('none');
		it.innerHTML = '';
    }
    else
    {
        self.status = secsAtt
        secsAtt = secsAtt - 1
        timerRunningAtt = true
        timerIDatt = self.setTimeout("StartTheTimerAtt()", delayAtt)
    }
}

/*******************************************************************/
var xmlhttpPA=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttpPA = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttpPA = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttpPA = false;
  }
 }
@end @*/
if (!xmlhttpPA && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttpPA = new XMLHttpRequest();
	} catch (e) {
		xmlhttpPA=false;
	}
}
if (!xmlhttpPA && window.ActiveXObject) {
	try {
		//xmlhttpPA = window.createRequest();
		xmlhttpPA = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//xmlhttpPA=false;
		
		try {
			xmlhttpPA = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttpPA = false;
		}
		
	}
}

function getMyPA(serverPage,objID,newID) {
if(xmlhttpPA) {
	
	var subObj = "sub"+objID;
	var obj = document.getElementById(subObj);
	
	try {
		xmlhttpPA.open("GET", serverPage);
	} catch (e) {
		alert("Error: " + serverPage);	
	}
	
	
	xmlhttpPA.setRequestHeader("Content-Type","text/xml;charset=UTF-8")
	xmlhttpPA.onreadystatechange = function() {
		/*if( xmlhttpPA.status == 0 )
		{
			document.getElementById('loadStatus').innerHTML="Aborted...";	
		}
		else */
		try {
		    if (xmlhttpPA.readyState == 4) {
    			
		   	    if (xmlhttpPA.status==200) {
				    //alert("URL Exists!")  
				    var xmlResponse = xmlhttpPA.responseText;
    	
				    obj.innerHTML = obj.innerHTML +"<div class='paStatStyles' id='"+newID+"'>"+xmlResponse+"</div>";
				    stats_show(objID);
    				
				    if(document.location.hash){
					    var rm = document.location.hash;
					    removeElem(rm.replace(/#/,""));
				    }
		   	    }
			    else if (xmlhttpPA.status==404)  {
				    alert("URL doesn't exist!");
				    //document.write("<h2>Nothing</h2>");
			    }
			    else {
				    //alert("Status is "+xmlhttpPA.status);
				    
			    }
		      } else {
        		    //obj.innerHTML="<img src='images/loading.gif' style='margin:0 auto;' />";
        		    //obj.innerHTML = obj.innerHTML +"<img src='images/loading.gif' style='margin:0 auto;' />";
		      }
		  } catch(e) {
		    //failure to read the status
		  }
		
	}
	xmlhttpPA.send(null);
	
    //s_pageName=tab;
   //s_gs(s_account);
} //Close if statement for xmlhttpPA validation
}

//-->
