var req;

var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function show(sw,obj) {
	// show/hide the divisions
	if (sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'visible';
	if (!sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'hidden';
	if (sw && ns4) document.layers[obj].visibility = 'visible';
	if (!sw && ns4) document.layers[obj].visibility = 'hidden';
}

function callPage(pageUrl, divElementId, loadinglMessage,errorMessage) {
     if (loadinglMessage.length>0) {
        document.getElementById(divElementId).innerHTML = loadinglMessage;
     }
     req=GetXmlHttpObject()
     if (req==null) {
        alert("Browser Does Not Support AJAX")
        return false
     }

     req.onreadystatechange = function() {responsefromServer(divElementId,errorMessage);};
     req.open("GET",pageUrl,true);
     req.send(null);
  }

function responsefromServer(divElementId,errorMessage) {
   var output = '';
   if(req.readyState == 4) {
      output=req.responseText;
      document.getElementById(divElementId).innerHTML = output;
   }
}
  
/* This Function is for Tab Panels */

function showMenu(menuname,theleft,thetop) {
	var oElement = document.all.maintbl;
	var mainLeft = oElement.offsetLeft;
	var mainTop = oElement.offsetTop;	
	menuLeft=parseFloat(mainLeft)+parseFloat(theleft)
	menuTop=parseFloat(mainTop)+parseFloat(thetop)
	document.getElementById(menuname).style.top=menuTop+"px";
	document.getElementById(menuname).style.left=menuLeft+"px";
	show(true,menuname)
}
function menuHideAll() {
	show(false,'hotmenu')
	show(false,'discmenu')
	show(false,'tipsmenu')

}
function activeTab(tab,mileID,maxtab) {   
    
    document.getElementById("actandnotes").innerHTML="<table border=1 width=600 height=250><tr><td width='50%' valign=top><span id=activity>&nbsp;</span></td><td width='50%' valign=top><span id=notes>&nbsp;</span></td></tr></table>"
    document.getElementById("docs").innerHTML=""
	var i=1;
	for (i=1;i<=maxtab;i++)
	{
		document.getElementById("tab"+i).className = "";
	}
    document.getElementById("tab"+tab).className = "active";
    callPage("submiletabs.aspx?mileid="+mileID,"subtabs","Loading","Error Loading Page")
}

function activeTab2(tab,submileID,leadID,mileID,maxtab) {  
    document.getElementById("notes").innerHTML="" 
	var i=1;
	for (i=1;i<=maxtab;i++)
	{
		document.getElementById("subtab"+i).className = "";
	}
    document.getElementById("subtab"+tab).className = "active";
    callPage("activitylist.aspx?submileId="+submileID+"&leadId="+leadID+"&mileid="+mileID,"activity","Loading")
}

function activeTab3(actID) { 
    callPage("actview.aspx?actID="+actID,"notes","")
}
function activeTab4(tab,submileID,leadID,mileID) { 
    callPage("activity.aspx?submileId="+submileID+"&leadId="+leadID+"&mileid="+mileID,"notes","Loading")
}
function activeTab5(tab,submileID,leadID,mileID,actID) { 
   callPage("activitylist.aspx?submileId="+submileID+"&leadId="+leadID+"&mileid="+mileID+"&actid="+actID+"&dowhat=changed","activity","Loading")
}
function activeTab6(tab,leadID,mileID,maxtab) {  
    document.getElementById("subtabs").innerHTML="<table align=center bgcolor='' width='100%' border=0 cellspacing=0 cellpadding=0><tr><td></td></tr></table>" 
    document.getElementById("actandnotes").innerHTML="" 
	var i=1;
	for (i=1;i<=maxtab;i++)
	{
		document.getElementById("tab"+i).className = "";
	}
    document.getElementById("tab"+tab).className = "active";     
    callPage("docs.aspx?leadid="+leadID+"&mileid="+mileID,"docs","Loading","Error Loading Page")
}
function showarea() {  
    document.getElementById("docs").style.visibility="hidden"    
}
function openedit() {
	var winX = (document.all)?window.screenLeft:window.screenX;
	var winY = (document.all)?window.screenTop:window.screenY;
	theX=parseFloat(winX)+parseFloat(100)
	theY=parseFloat(winY)+parseFloat(100)
	var W = "height=350,width=675,scrollbars=yes,left="+theX+",top="+theY	
	editwin4=open("blank.html","editwin4",W)
	return true
}

function GetXmlHttpObject() {
   var req=null;
   try  { // Firefox, Opera 8.0+, Safari
     req=new XMLHttpRequest();
   }
   catch (e) {  // Internet Explorer
      try {
        req=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (E) {
        req=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return req;
}
function showrules(actID) {
	document.getElementById("theactnotes").style.visibility="visible"
	callPage("viewNote.aspx?actID="+actID,"thenote","")
}
function hiderules() {
	document.getElementById("theactnotes").style.visibility="hidden"
}
function sanitizeHTML(s) {
    var d = document.createElement('div');
    d.appendChild(document.createTextNode(s));
    return d.innerHTML;
}

function displaySource()
{
    var h = sanitizeHTML(document.documentElement.outerHTML);
    document.getElementById('asText').innerText = h;
}

