var MapLoaded = false;
var Btype = 0;
var browserName=navigator.appName; 
if (browserName=="Netscape")
{ 
  Btype=0;
}
else 
{ 
 if (browserName=="Microsoft Internet Explorer")
 {
   Btype=1;
 }
 else
  {
     Btype=0;
   }
}



function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}



function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}


function xHeight(e,h)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(h)) {
    if (h<0) h = 0;
    else h=Math.round(h);
  }
  else h=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    h = xClientHeight();
  }
  else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(h>=0) {
      var pt=0,pb=0,bt=0,bb=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pt=gcs(e,'padding-top',1);
        if (pt !== null) {
          pb=gcs(e,'padding-bottom',1);
          bt=gcs(e,'border-top-width',1);
          bb=gcs(e,'border-bottom-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetHeight,e.style.height)){
          e.style.height=h+'px';
          pt=e.offsetHeight-h;
        }
      }
      h-=(pt+pb+bt+bb);
      if(isNaN(h)||h<0) return;
      else e.style.height=h+'px';
    }
    h=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(h>=0) e.style.pixelHeight=h;
    h=e.style.pixelHeight;
  }
  return h;
}


function xClientWidth()
{
  var w=0;
  if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }
  return w;
}



function xWidth(e,w)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
  }
  else w=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
  }
  else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
  }
  return w;
}


function xClientHeight()
{
  var h=0;
 if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

function xGetComputedStyle(oEle, sProp, bInt)
{
  var s, p = 'undefined';
  var dv = document.defaultView;
  if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(oEle,'');
    if (s) p = s.getPropertyValue(sProp);
  }
  else if(oEle.currentStyle) {
    // convert css property name to object property name for IE
    var a = sProp.split('-');
    sProp = a[0];
    for (var i=1; i<a.length; ++i) {
      c = a[i].charAt(0);
      sProp += a[i].replace(c, c.toUpperCase());
    }   
    p = oEle.currentStyle[sProp];
  }
  else return null;
  return bInt ? (parseInt(p) || 0) : p;
}



	function LoadMap(panelID,divID,MapURL)
	{

		detailRow = 'det' + panelID;
		imgID = 'img' + panelID;


		if(xGetElementById(detailRow).className == 'FrameHide')
		{
		xGetElementById(detailRow).className = 'FrameShow';
		xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelOpen.gif';
		xGetElementById(imgID).alt = 'Click here to close this Section';
		if(!MapLoaded) 	xGetElementById(divID).src = MapURL;
		MapLoaded = true;
		}
		else
		{
		xGetElementById(detailRow).className = 'FrameHide';
		xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelClosed.gif';
		xGetElementById(imgID).alt = 'Click here to view this Section';
		};
		return ;
	}


	function expandSection(sectionID)
	{

	if (sectionID=='')
	{
	//	alert('none');	
	}
	else
	{
		//document.filter.PanelSection.value = sectionID;
		
		if(xGetElementById('det' + sectionID).className == 'FrameHide')
		//if xGetElementById('det' + sectionID).style.display == ''
		//if xGetElementById('det' + sectionID).style.classname == 'FrameHide';
		
		{
		pnlExpand(sectionID);
	//	alert(sectionID);
	//	alert(xGetElementById(sectionID).value );
	
		if (xGetElementById(sectionID))
			{
			xGetElementById(sectionID).value = 'yes';
			if (sectionID == 'AdvSrch')
				{
				pnlCollapse('Main');
				pnlCollapse('Feature');
				xGetElementById('Main').value = 'no';
				xGetElementById('Feature').value = 'no';
				}
			}
		}
		else
		{
		pnlCollapse(sectionID);
		
		if (xGetElementById(sectionID))
		{
			xGetElementById(sectionID).value = 'no';
		}
		};
	}
	return ;
	}

	function ExpandTreeSection()
	{
		xGetElementById('detTree').className = 'FrameShow';
		xGetElementById('imgTree').src = 'Controls/Panels/Icons/SMSPanelOpen.gif';
		xGetElementById('imgTree').alt = 'Click to Collapse Panel';
		return;
	}

	function ToggleTreeSection()


	{
	if(xGetElementById('detTree').className == 'FrameHide')
	{

	xGetElementById('detTree').className = 'FrameShow';
	xGetElementById('imgTree').src = 'Controls/Panels/Icons/SMSPanelOpen.gif';
	xGetElementById('imgTree').alt = 'Click to Collapse Panel';
	}
	else
	{
	xGetElementById('detTree').className = 'FrameHide';
	xGetElementById('imgTree').src = 'Controls/Panels/Icons/SMSPanelClosed.gif';
	xGetElementById('imgTree').alt = 'Click to Expand Panel';
	};
	return ;
	}



	function pnlExpand(panelID)
	{
	var detailRow;
	var imgID;
	var parentStyle;

	detailRow = 'det' + panelID;
	imgID = 'img' + panelID;

	xGetElementById(detailRow).className = 'FrameShow';
	//xGetElementById(detailRow).style.display = '';
	xGetElementById(detailRow).style.display = '';
	xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelOpen.gif';
	xGetElementById(imgID).alt =  'Click here to close the ' + panelID + ' Section';
	if (xGetElementById(panelID))
	{
		xGetElementById(panelID).value = 'yes';
	}
	}


	function pnlCollapse(panelID)
	{
	var detailRow;
	var imgID;
	var parentStyle;

	detailRow = 'det' + panelID;
	imgID = 'img' + panelID;

	xGetElementById(detailRow).className = 'FrameHide';
	//xGetElementById(detailRow).style.display = 'none';
	xGetElementById(detailRow).style.display = 'none';
	xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelClosed.gif';
	xGetElementById(imgID).alt = 'Click here to view the ' + panelID + ' Section';
	if (xGetElementById(panelID))
	{
		xGetElementById(panelID).value = 'no';
	}
	}
	
	function doNothing()
	{
		return;
	}
	function showHidePanel(sectionID)
	
	{
		switch (xGetElementById(sectionID).value)
			{	
				case 'yes':
				{
				pnlExpand(sectionID);
				break;
				}
				case 'no':
				{
				pnlCollapse(sectionID);
				break;
				}
			}	
	}
	//function resizeBan(){
//
//			document.body.scroll = "no";
 //			DivDynamic.style.width= document.body.clientWidth - 218; //(DivFixed.style.width);
// 			DivDynamic.style.height= document.body.clientHeight - 35; //(DivMenu.style.height);
//
//			DivFixed.style.width = 200;
//			DivFixed.style.height = document.body.clientHeight - 35;
//		try{nstext.setActive();} //allows scrolling from keyboard as soon as page is loaded. Only works in IE 5.5 and above.
//		catch(e){}
//			document.body.scrollTop = 0;
//	return ;

//	}
	function resizeBan(){

			document.body.scroll = "no";
 			xGetElementById('DivDynamic').style.width= document.body.clientWidth - 5; //(DivFixed.style.width);
 			
 			xGetElementById('DivDynamic').style.height= document.body.clientHeight - 35; //(DivMenu.style.height);

		try{nstext.setActive();} //allows scrolling from keyboard as soon as page is loaded. Only works in IE 5.5 and above.
		catch(e){}
			document.body.scrollTop = 0;
	return ;

	}
	function GetCookie (name) 
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}


function SetCookie (name, value) 
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}


function DeleteCookie (name) 
{ 
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 
}

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}


function cookieForms() {  
	var mode = cookieForms.arguments[0];
	for(f=1; f<cookieForms.arguments.length; f++) {
		formName = cookieForms.arguments[f];
		if(mode == 'open') {	
			cookieValue = GetCookie('saved_'+formName);
			if(cookieValue != null) {
				var cookieArray = cookieValue.split('#cf#');
				if(cookieArray.length == document[formName].elements.length) {
					for(i=0; i<document[formName].elements.length; i++) {
						if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
						else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
						else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
						else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
					}
				}
			}
		}

		if(mode == 'save') {	
			cookieValue = '';
			for(i=0; i<document[formName].elements.length; i++) {
				fieldType = document[formName].elements[i].type;
				if(fieldType == 'password') { passValue = ''; }
				else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
				else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
				else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
				else { passValue = document[formName].elements[i].value; }
				cookieValue = cookieValue + passValue + '#cf#';
			}

			cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
			SetCookie('saved_'+formName, cookieValue, exp);		

		}	
	}
}



function DeletePanelCookie() {
	var formid = DeletePanelCookie.arguments[0];
	SetCookie('filterpanels_' + formid,'');
}


function CookiePanelForms() {  

	var mode = CookiePanelForms.arguments[0];
	var	formName = CookiePanelForms.arguments[1];
	var	formid = CookiePanelForms.arguments[2];
	if(mode == 'open') {	
		cookieValue = GetCookie('filterpanels_' + formid);
		if(cookieValue != null) {
			var cookieArray = cookieValue.split('|P|');
			for(i=0; i<cookieArray.length; i++) {
				var panelparams = cookieArray[i].split('|D|');
				var parentRow;
				var detailRow;
				var imgID;
				var panelid;
				panelid = panelparams[0].substring(3);
				if(panelid != 'Filter') {
					parentRow = 'pnl' + panelid;
					detailRow = 'det' + panelid;
					imgID = 'img' + panelid;
					if(xGetElementById(parentRow) != null) {
						if(panelparams[1] == 'FrameHide')
						{
							xGetElementById(detailRow).className = 'FrameHide';
							xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelOpen.gif';
							xGetElementById(imgID).alt = 'Click to Collapse Panel';
						}
						else
						{
							xGetElementById(detailRow).className = 'FrameShow';
							xGetElementById(imgID).src = 'Controls/Panels/Icons/SMSPanelClosed.gif';
							xGetElementById(imgID).alt = 'Click to Expand Panel';
						}
					}
				}
			}
		}

	}
	if(mode == 'save') 
	{	
		cookieValue = '';
		for(i=0; i<document[formName].all.length; i++) {
			fieldType = document[formName].all[i].id;
			if(fieldType.substring(0, 3) == 'det') 
			{ 
				cookieValue = cookieValue + fieldType + '|D|' + document[formName].all[i].className + '|P|' ;
			}
		}
		SetCookie('filterpanels_' + formid, cookieValue, exp);
	}
}

	function showHistory()
	{
	if (xGetElementById('ddlPub'))
	{
		//xGetElementById('ddlPub').style.display = 'none';
		xGetElementById('ddlPub').style.visibility = 'hidden';
		//xGetElementById('ddlNonPub').style.display = 'none';
	}
	xGetElementById('history').className = 'HistoryTable';
	xGetElementById('history').style.left =  document.body.clientWidth - xGetElementById('history').offsetWidth;
	
	}
	function hideHistory()
	{
	if (xGetElementById('ddlPub'))
	{
		//xGetElementById('ddlPub').style.display = '';
		xGetElementById('ddlPub').style.visibility = 'visible';
		//xGetElementById('ddlNonPub').style.display = '';
	}
	xGetElementById('history').className = 'DefaultHidden';
	
	}
	function startDrag()
	{
	xGetElementById('drag').value = 'yes';
	}
	function stopDrag()
	{
	xGetElementById('drag').value = 'no';	
	}
	function moveDiv(name)
	{
	if (xGetElementById('drag').value == 'yes')
		{
		xGetElementById(name).className = 'HistoryTable2';
		}
	else
		{
		xGetElementById(name).className = 'HistoryTable';
		}
	}

	function show(sName)
	{
		xGetElementById(sName).style.display = '';
	}
	function hide(sName)
	{
		xGetElementById(sName).style.display = 'none';
	}
	
	
	
	