
var imgs = new Array('');

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function preloadImgs(){
  for(var i=0;i<imgs.length;i++){
    MM_preloadImages(imgs[i]);
  }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function NonStandards()
{
  var ver = getInternetExplorerVersion();
  
  if ( ver == -1 || ver >= 8.0)
  {
    return false;
  }
  else
  {
    return true;
  }
}

function getClientCodes()
{

	var url="InlineJustis.aspx?a=GetGroups"
	http2=getHttpObject();
		
	http2.onreadystatechange = ReadyStateClientCodes
	http2.open("GET", url , true) 
	http2.send(null)

}

function clearClientCodes()
{

	var url="InlineJustis.aspx?a=ClearCode"
	http2=getHttpObject();
		
	http2.onreadystatechange = ReadyStateUpdateCode
	http2.open("GET", url , true) 
	http2.send(null)

}

function ReadyStateClientCodes()
{
	if ( http2.readyState == 4 )
	{
		//alert(http2.responseText);
	
		var groups = eval("( [" + http2.responseText + " ])") ;
		
		var divGroups = document.getElementById('ccddMenu');
				
		var htmlGroups = "<ul>"
				
		for (i = 0; i<groups.length;i++)
		{			
			htmlGroups += "<li><a href=\"javascript:;\" onclick=\"updateClientCode('" + groups[i].GroupName + "')\">" + groups[i].GroupName + "</a></li>"
		}
			
		htmlGroups += "</ul><div class=\"clear\"><a href=\"javascript:;\" onclick=\"clearClientCodes()\">Clear Client Code</a></div>"
		
		divGroups.innerHTML = htmlGroups;
		
	}
}

function updateClientCode(group)
{

	var url="InlineJustis.aspx?a=ChangeCode&group=" + group
	http2=getHttpObject();
		
	http2.onreadystatechange = ReadyStateUpdateCode
	http2.open("GET", url , true) 
	http2.send(null)

}

function ReadyStateUpdateCode()
{
	if ( http2 && http2.readyState == 4 )
	{
		//alert(http2.responseText);
	
		var groups = eval( http2.responseText ) ;
				
	}
}

function ni()
{
	alert('Not Implemented');
}

function clearDefaults()
	{
		var form = document.forms[0];
		/*
		var breaksessionstate = false;
		for(var i = 0; i < form.elements.length; i++)
			if (form.elements[i].value == "break")
				breaksessionstate = true;
		*/
		for(var i = 0; i < form.elements.length; i++)
		{
		/*
			if (breaksessionstate && form.elements[i].name == '__VIEWSTATE') 
			{
				alert('clearing: ' + form.elements[i].value);
				form.elements[i].value +='=';
			}
		*/
			
			if (form.elements[i].name != null && aryTextDefaults[form.elements[i].name] == form.elements[i].value)
			{
				form.elements[i].value = '';
			}
			//if (form.elements[i].value == '(optional)')
				//form.elements[i].value = ''

		}
	}

function showFields()
{
	if(arguments.length <= 1)
		return;
		
	if (arguments[0] == '1')
		var status = 'visible'
	else
		var status = 'hidden'
		
		
	for (var i=1; i <= arguments.length -1; i++)
	{
		current = arguments[i]
		document.getElementById(current).style.visibility = status;
	}
}

function minmax(clicked)
{
	document.getElementById('static').style.overflow='hidden';  
	
	if (clicked.innerHTML == 'Minimize') 
	{ 
		if (isie)
			document.getElementById('static').style.height='25px'; 	
		else
			document.getElementById('static').style.height='10px'; 
		
		clicked.innerHTML='Maximize'; 
	} 
	else 
	{ 
		document.getElementById('static').style.height=''; 
		clicked.innerHTML='Minimize'; 
	}
	
	document.getElementById('static').style.sIndex = "1";
	
	clicked.style.zIndex = "1";
	
	resizer();
}


function getChildren(item)
{
	var children = null;
	for (var x=0; x<item.childNodes.length; x++)
	{
		if (item.childNodes[x].nodeName == 'UL')
		{
			children = item.childNodes[x];
			break;
		}
	}
	return children;

}


function onClickHandler(evt)
{
	var item = evt ? evt.target : event.srcElement;
	
	if (item.className == "parent")
	{
		if (item.expanded)
		{
			item.style.listStyleImage = 'url(http://justdev/justcite/justis_images/right.gif)';
			getChildren(item).style.display = "none";
			item.expanded = false;
		}
		else
		{
	
			getChildren(item).style.display = "block";
			item.style.listStyleImage = 'url(http://justdev/justcite/justis_images/downarrow.gif)';
			item.expanded = true;
		}
	}
	
	return true;
}

document.onclick = onClickHandler;


window.onload =	function () 
{
	var mySlider1 = new slider(document.getElementById("extra"),document.getElementById("showExtra"));
	
	var sug =document.getElementById('allowSuggest')
	
	if(sug && sug.checked == true) 
	{
		var objTextbox = new Suggest(document.getElementById("fldFullText"), new Suggestions(), document.getElementById("sResults"));        								
	}
								
	self.name='Justis_Browser';
	//window.focus();
}

var currentTip = 0;

function showTip()
{
	var arrTips = new Array(
			"Use the 'Filter Results' box to show results profiles containing only the text you specify.",
			"You can customise many aspects of Justis in the 'My Justis' tab.",
			"You can change your default search screen in the 'My Justis' tab.",
			"Justis can make suggestions for your search as you type it in. Click the 'Let Justis suggest searches as I type' box  to turn on this feature.",
			"Try using operators such as AND, OR, NOT to narrow or widen your search criteria. <a href=\"javascript: ShowHelp(\'help/operators.html\');\">View the Help</a>",
			"Use the 'Search In' forms to easily specify criteria for related data sources, e.g. Legislation.",
			"You can sort the results of your search by clicking the column headers.",
			"Try using the ?, * and - wild cards when spelling and/or accents are uncertain. <a href=\"javascript: ShowHelp(\'help/wild-cards.html\');\">View the Help</a>"
			)
	
	document.getElementById("tip").innerHTML = arrTips[currentTip]
	currentTip++;
	
	if (currentTip == arrTips.length)
		currentTip = 0;
			
}


function LaunchPopup(strURL, strWinName, nWidth, nHeight) {
	var winLeft = (screen.width - nWidth) / 2;
	var winTop = (screen.height - nHeight) / 2;
	
	window.open(strURL, strWinName, 'toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,width=' + nWidth + ',height=' + nHeight + ',left=' + winLeft + ',top=' + winTop);
}

function ShowHelp(helpFile){
	LaunchPopup(helpFile, 'HelpWindow', 600, 470);
}
function jLinkInit()
{
	
	var jlink = document.getElementById('jlinkpanelcontent');
	var jlinkjustispanel = document.getElementById('jlinkjustis');
	var jlinkjustcitepanel = document.getElementById('jlinkjustcite');
	
	var txt = '';
	
	if (window.getSelection)
		txt = window.getSelection();
	else if (document.getSelection)
		txt = document.getSelection();
	else if (document.selection)
		txt = document.selection.createRange().text;
		
	if (txt != '' && jlinkjustispanel)
	{
		txt = txt.toString().substring(0, Math.min(txt.toString().length, 512))
		jlinkjustispanel.innerHTML = '<div style="background: url(justis_images/busy.gif) no-repeat left center;padding-left: 18px;margin-top: 5px;"  >Attempting JLink...</div>' + txt;
		Syntalex(txt, jlinkResult);
	}
		
	
	
	
	//jlink.innerHTML = '<div style="background: url(justis_images/busy.gif) no-repeat left center;padding-left: 18px;margin-top: 5px;"  >Attempting JLink...</div>' + txt;
		
}

function getJLink()
{
		var jlink = document.getElementById('jlinkpanelcontent');
		
	var jlinkjustispanel = document.getElementById('jlinkjustis');
	var jlinkjustcitepanel = document.getElementById('jlinkjustcite');
	
		var panel = document.getElementById('jlinkpanel');
		if (panel && panel.style.height == '0px')
			return;
			
		var txt = '';
				
		if (window.getSelection)
		{
			txt = window.getSelection();
		}
		else if (document.getSelection)
		{
			txt = document.getSelection();
		}
		else if (document.selection)
		{
			txt = document.selection.createRange().text;
		}
		else return;
			
		txt = txt.toString().substring(0, Math.min(txt.toString().length, 512))
		
		if (txt != '' && jlinkjustispanel)
		{
			jlinkjustispanel.innerHTML = '<div style="background: url(justis_images/busy.gif) no-repeat left center;padding-left: 18px;margin-top: 5px;">Attempting JLink...</div>' + txt;
			
			Syntalex(txt, jlinkResult);
		}
		else
		{
			jlinkjustispanel.innerHTML = '<p>No reference selected.</p>';
			jlinkjustcitepanel.innerHTML = '<p>No reference selected.</p>';
		}
		
}

function jlinkResult(txt)
{
	var jlink = document.getElementById('jlinkpanelcontent');
	var jlinkjustispanel = document.getElementById('jlinkjustis');
	var jlinkjustcitepanel = document.getElementById('jlinkjustcite');
	if (jlink)
	{	
		
		var SynResultsCount = 0;
		var SynResults = null;
		try { eval (txt); }
		catch (ex) {  jlinkjustispanel.innerHTML = '<p>Unfortunately, the linking engine is temporarily unavailable...</p>'; }
		
		//alert(SynResultsCount);
		if (SynResultsCount == 0)
		{
			jlinkjustispanel.innerHTML = '<p>No links found.</p>';
			jlinkjustcitepanel.innerHTML = '<p>No links found.</p>';
		}
		else
		{
			var justisHtml = '';
			var justciteHtml = '';
			var justisCount = 0;
			
			for (x = 0; x < SynResults.length; x++)
			{
				if (SynResults[x].JUSTIS==1)
				{
					justisCount++;
					justisHtml += '<a href="javascript:;" onclick="doLink(\'' + SynResults[x].REF + '\');">' + SynResults[x].REF + '</a>'
					if (SynResults[x].SOURCE != '')
						justisHtml += ' : ' + SynResults[x].SOURCE;
					justisHtml += '<br />';
				}
			}
		
			for (x = 0; x < SynResults.length; x++)
			{
				justciteHtml += '<a href="javascript:;" onclick="doJustCiteLink(\'' + SynResults[x].REF + '\');">' + SynResults[x].REF + '</a><br />';
			}

			if (justisCount == 0)
			{
					jlinkjustispanel.innerHTML = '<p>No links found.</p>';
					jlinkjustcitepanel.innerHTML = justciteHtml;
			}
			else
			{
				jlinkjustispanel.innerHTML  = justisHtml;
				jlinkjustcitepanel.innerHTML = justciteHtml
			}

		}
	}
	
}

	function showHand()
	{
		var agt=navigator.userAgent.toLowerCase();
	
		if (agt.indexOf("msie 5.0") !=-1 || agt.indexOf("msie 5.5") !=-1)
			return 'hand';
		else
			return 'pointer';
	}

	function centerDiv(div)
	{
		var win = getWindow();
		
		div.style.top = win.Scrolled + (win.Height/3) - (div.offsetHeight/2) + 'px'
		
		div.style.left = (win.Width/2) - (div.offsetWidth/2) + 'px'
		
		//div.style.left = (win.Width - div.offsetWidth) /2 + 'px';
		//div.style.top = (win.Height - div.offsetHeight) / 2 + 'px';
	}
