// Javascript functions required for prototypes, combined into this one file from three previously 2004-03-12 by Jon.


// do show/hide functionality
function swapSection(elem, elem2)
{
	if (elem.style.display == 'none'){
		elem.style.display ='' ;
		elem2.style.display = 'none';
	} else {
		elem.style.display = 'none';
		elem2.style.display ='' ;
	}
}

// Additional version of swapSection by 2003-10-08 to get the javascript drop downs working in Mozilla

function swapSectionW3C(elem, elem2)
{
	if (document.getElementById([elem]).style.display == 'none'){
		document.getElementById([elem]).style.display ='' ;
		document.getElementById([elem2]).style.display = 'none';
	} else {
		document.getElementById([elem]).style.display = 'none';
		document.getElementById([elem2]).style.display ='' ;
	}
}

function displayOnlyShow(elem, elem2)
{
	document.getElementById([elem]).style.display ='' ;
	document.getElementById([elem2]).style.display = 'none';
	
}


//---------------------------------------------------------------------------------------------


//R1 Segment Selector
function segSelector() 
{
    var x = document.form1.terms2.value;
    x += document.form1.operator.value + " " + document.form1.segment.value + "(" + document.form1.terms.value +") ";
    document.form1.terms2.value = x ;
    
}

//R2 Segment Selector
//segment selector widget
function addSegment(segDropdown, term, booloperator, textfield)
{
  var segContents = segDropdown[segDropdown.selectedIndex].value;
  var termContents = term.value;
  if (segContents != '' && termContents != '')
  {
	if (textfield.value.length < 1)
	{
	  var outString = booloperator[booloperator.selectedIndex].value;
	  if (booloperator[booloperator.selectedIndex].value != '')
	  {
	    outString += ' ';
	  }
	  outString += segContents + '(' + termContents + ')';	  
	}
	else
	{
	 var outString = ' ' + booloperator[booloperator.selectedIndex].value + ' ' + segContents + '(' + termContents + ')';
	}
	textfield.value += outString;
  }
}

//R3 Segment Selector
//segment selector widget
function addSegment2(segDropdown, term, booloperator, textfield)
{
  var segContents = segDropdown[segDropdown.selectedIndex].value;
  var termContents = term.value;
  if (booloperator[0].checked == true)
  {
  	var boolContents = "AND";
  }
  else if (booloperator[1].checked == true)
  {
    var boolContents = "OR";
  }
  
  if(segContents == '' && termContents == '')
  {
  	alert("Please select a document section and enter a search term.");
  }
  else if(segContents == '' && termContents != '')
  {
    	alert("Please select a document section.");
  }
  else if(segContents != '' && termContents == '')
  {
    	alert("Please enter terms to search within this document section.");
  }   
  else if (segContents != '' && termContents != '')
  {
	if (textfield.value.length < 1)
	{
	  var outString = segContents + '(' + termContents + ')';	  
	}
	else
	{
	 var outString = ' ' + boolContents + ' ' + segContents + '(' + termContents + ')';
	}
	textfield.value += outString;
	term.value='';
	segDropdown.selectedIndex=0;
	
  }
  
}

/* end of Jonr 2003-10-08 modification */
//-------------------------------------------------------------------------------------------------------------------------------

// copy of dynamicdrive's tooltip script as it seems to be included inline on some pages and nowhere at
// all in others

/*
Text Link/Image Map Tooltip Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, and 100's more DHTML scripts
Visit http://www.dynamicdrive.com
*/

if (!document.layers&&!document.all&&!document.getElementById)
event="test"
function showtip(current,e,text){

if (document.all||document.getElementById){
thetitle=text.split('<br>')
if (thetitle.length>1){
thetitles=''
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i]
current.title=thetitles
}
else
current.title=text
}

else if (document.layers){
document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
document.tooltip.document.close()
document.tooltip.left=e.pageX+5
document.tooltip.top=e.pageY+5
document.tooltip.visibility="show"
}
}
function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden"
}

function Popup(Pagename) {
  		var Popwidth = 634;
  		//var Popheight = screen.Height-55
		var Popheight = 800;
		window.open( ""+Pagename+"", "Sitemap", "scrollbars=yes,toolbar=no,menubar=no,status=no,resizable=yes,width="+Popwidth+",height="+Popheight+"screenX=1,screenY=1,top=1,left=1");
  	}

//-----------------------------------------------------------------------------------------------------------------------------------------
// script by JonR to grey-out court checkboxes in /webroot/global/R2/GLP_UK/LegalCaseSearch.asp based on jurisdiction checkbox selected
// bit tricky as the checkboxes are contained in iframes

function greyout_courts(elem, elem2){
	var f=parent.document.getElementById('LegalCourtsSearchSources').contentWindow.document.forms['courtform'];
	var j=document.forms['jurisdiction'];
	//grey-out all checkboxes first
	for (i = 0; i < f.elements.length; i++)
    	if (f.elements[i].type=="checkbox"){
      		if (elem2!='0'){
				f.elements[i].disabled = true ;
			}
			else{
				f.elements[i].disabled = false ;
			}				
   		}
	// then reinstate those we want to have active based on the Jurisdiction that was selected, making sure it has been checked rather than unchecked
	if (elem2=='0' && j.AllJurisdictions.checked==true){ //All
		// uncheck all other Jurisdiction boxes as per Chris's instructions.
		j.EnglandandWales.checked = false;
		j.Scotland.checked = false;
		j.NorthernIreland.checked = false;
		j.European.checked = false;		
		
		// if there are any checked boxes, retain them them, otherwise check the "all" box.
		for (i = 0; i < f.elements.length; i++)
    	if (f.elements[i].type=="checkbox"){
      		if (f.elements[i].checked == true){
				//alert("checked boxes") ;
				return;
			}
		}
		//alert("no checked boxes");
		f.AllCourts.checked = true;
		return;				
	}
	if (elem2=='1' && j.EnglandandWales.checked==true){ // England & Wales
		
		var Namearray= new Array("AllCourts","PC","HL","CA","CACivD","CACrimD","FamD","QBD","AdminCt","ADMLTYCT","COMMLCT","TCC","ChD","PatCt","CompCt","EAT","LT","VATTrib");
		 for (var jurisdiction_names=0; jurisdiction_names<Namearray.length; jurisdiction_names++){
    		f.elements[Namearray[jurisdiction_names]].disabled = false;
 		 }
		// uncheck all other Jurisdiction boxes as per Chris's instructions.
		j.AllJurisdictions.checked = false;
		j.Scotland.checked = false;
		j.NorthernIreland.checked = false;
		j.European.checked = false;
		f.AllCourts.checked=false;
		
		// uncheck all court options as per instructions
		for (i = 0; i < f.elements.length; i++)
    	if(f.elements[i].type=="checkbox"){
      		f.elements[i].checked = false ;
		}
	}
	if (elem2=='2' && j.Scotland.checked==true){ //Scotland
		
		var Namearray= new Array("HCJust","CtSess");
		 for (var jurisdiction_names=0; jurisdiction_names<Namearray.length; jurisdiction_names++){
    		f.elements[Namearray[jurisdiction_names]].disabled = false;
 		 }
		 // recheck cleared boxes if england and wales checked
		 if (j.EnglandandWales.checked==true){
		 	var Namearray= new Array("AllCourts","PC","HL","CA","CACivD","CACrimD","FamD","QBD","AdminCt","ADMLTYCT","COMMLCT","TCC","ChD","PatCt","CompCt","EAT","LT","VATTrib");
		 	for (var jurisdiction_names=0; jurisdiction_names<Namearray.length; jurisdiction_names++){
    			f.elements[Namearray[jurisdiction_names]].disabled = false;
 		 	}		 
		}	
	}
	if (elem2=='3' && j.NorthernIreland.checked==true){ //Northern Ireland
		
		var Namearray= new Array("NICA","NICrCt","NIChD","NIQBD","NIFamD");
		 for (var jurisdiction_names=0; jurisdiction_names<Namearray.length; jurisdiction_names++){
    		f.elements[Namearray[jurisdiction_names]].disabled = false;
 		 }
	}
	if (elem2=='4' && j.European.checked==true){ //European
		
		// uncheck all other Jurisdiction boxes as per Chris's instructions.
		j.AllJurisdictions.checked = false;
		j.EnglandandWales.checked = false;
		j.Scotland.checked = false;
		j.NorthernIreland.checked = false;
		f.AllCourts.checked=false;
			
		var Namearray= new Array("ECJ","EctHR","CFI");
		 for (var jurisdiction_names=0; jurisdiction_names<Namearray.length; jurisdiction_names++){
    		f.elements[Namearray[jurisdiction_names]].disabled = false;
 		 }
		 
		// uncheck all court options as per instructions
		for (i = 0; i < f.elements.length; i++)
    	if(f.elements[i].type=="checkbox"){
      		f.elements[i].checked = false ;
		}
	}
}

//-----------------------------------------------------------------------------

function PopupWinLookup(page){
		window.open(page,"IndexLookup","width=400,height=450,scrollbars=1,resizable=1,menubar=0,top="+eval(document.body.clientHeight / 2-200)+",left="+eval(document.body.clientWidth / 2-300));
	}


function PopupWinDel(page){
		window.open(page,"PopupWinDel","width=625,height=460,scrollbars=1,resizable=0,menubar=0,top="+eval(document.body.clientHeight / 2-200)+",left="+eval(document.body.clientWidth / 2-300));
	}


// RH -------------------------------------------------------------------------
function openWindow(page, w, h)
{
  var popupWin = window.open(page, "popup", "width=" + w + ",height=" + h);
}

//------

function goPage(page)
{
  var i = page.menu.selectedIndex;
  if (i == 0)
{
 parent.location.href = "NewsResultsList.asp";
}
  if (i == 1)
{
  parent.location.href = "NewsResultsListExpanded.asp";
}	
  if (i == 2)
  {
    parent.location.href = "NewsResultsDoc2.asp";
  }
if (i == 3)
{
    parent.location.href = "NewsResultsDoc.asp";
}
}

//-----
  
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();

function UpdateSegmentsWidget(sQueryStringStatus, selOperator)
{
  if (sQueryStringStatus == 'open')
  {
    selOperator.selectedIndex = 1;
  }
}

//--------------------------------------------------------------------------------------
// create the list of sources required to do the dropdown 
function BuildSourceArray()
{
  var aSources = new Array();

}

function UpdateRightBox(iIndex, selRightBox)
{
  // clear all current entries
  //
  RemoveAll(selRightBox);
  
}

function RemoveAll(selBox)
{
  for (var x = selBox.length; i >= 0; i--)
  {
    selBox.remove(x);
  }
}



function build_search_form_summary(the_obj,array_match) {

  //declare vars
  var x = eval('document.all.'+the_obj.id)
  var the_summary=""
  var the_alt=""
  var summary_div = eval('parent.document.all.'+the_obj.id+'_div')
  var combinable = 0

   
  Sources_array[array_match][2]=the_obj.checked
 
  //Disable or Enable other options when source that cannot be combined is clicked
  if(Sources_array[array_match][1]=="false") { 
		for(i=0; i<=x.length-1; i++) {
             if(i!=array_match) { 
			          if(the_obj.checked) {  x.item(i).parentElement.parentElement.style.color='#999999'; x.item(i).disabled=true;  } else { x.item(i).parentElement.parentElement.style.color='#333333'; x.item(i).disabled=false; }
			 } 	 
        }

  }



for(i=0; i<=Sources_array.length-1; i++) {
	if(x.item(i).checked==true && Sources_array[i][1]!="false") { combinable++ }
}

if(combinable!=0) {
	for(i=0; i<=Sources_array.length-1; i++) {
	    if(Sources_array[i][1]=="false") { x.item(i).parentElement.parentElement.style.color='#999999'; x.item(i).disabled=true; }
	}
} else {
	for(i=0; i<=Sources_array.length-1; i++) {
	    if(Sources_array[i][1]=="false") { x.item(i).parentElement.parentElement.style.color='#333333'; x.item(i).disabled=false;  }
	}
}

   
	for(i=0; i<=Sources_array.length-1; i++) {
		if(Sources_array[i][2]==true && x.item(i).disabled==false) { 
			the_summary += ", " + Sources_array[i][0] 
			the_alt += ", " + Sources_array[i][0]
		}
	}
        
		
		 the_summary=the_summary.substr(2,the_summary.length); 
		 the_alt=the_alt.substr(2,the_alt.length);
  	     if(the_summary=="") { the_summary="None Selected" }
		 if(the_summary.length<150) { 
  			  summary_div.innerHTML="<font title='"+the_alt+"'>"+the_summary+"</font>"
  		 } else {
    		  summary_div.innerHTML="<font title='"+the_alt+"'>"+the_summary.substr(0,150)+"...</font>"
  	     }
}

//-------------------------------------------------------------------------------

//R2 Results List Checkbox
//RP3 -- topCheckbox updated RRW 15 March 2004 for correct functionality & to work in non-IE browsers
function toggleAllCheckboxes(bChecked){
	var cc=document.form1.chkEnable;
	if (bChecked){
		for(x=0;x<cc.length;x++)  cc[x].checked=true;
	}else{
		for(x=0;x<cc.length;x++)  cc[x].checked=false;
	}
}

function topCheckbox(){
	var cc=document.form1.chkEnable;
	var i = 0;
		for( x=0;x<cc.length;x++ ) { 
			if ( cc[x].checked==true ) { 
				i++
			}
		}
			
		if (i == cc.length){
			document.form1.chkAll.checked=true;
		} else {
			document.form1.chkAll.checked=false;
		}
}
//END R2 Results List Checkbox

//added 2004Apr26 by RRW
//creates tables with alternating-coloured rows	
  //stripe(id) is adapated from the script at http://www.alistapart.com/articles/zebratables/		
  // this function is need to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

// id is the table's id; cellstyle is the default style for the table cells; lineeven is the style for the divider lines on even rows and lineodd is the style for the divider lines on the odd rows
 function stripe(id,cellstyle,lineeven,lineodd) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[4] ? arguments[4] : "#fff";
    var oddColor = arguments[5] ? arguments[5] : "#ebebd8";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor && mytd.id != "line") {
      
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
            }
     		if (mytd.id = "line") {
				     mytd.getAttributeNode("class").value = even ? lineeven : lineodd;
				 } else {
				     mytd.getAttributeNode("class").value = cellstyle
				 }			
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
  
//  -------------------------------------------------------------------

// allow adaptations to seamlessly link to the Core pages, issuing an advisory message en-route. 
// The message is to inform the user that links within the new page will only link to other Core pages.
// example link is javascript:LinkToCorePages('(K1-0)Preferences-GeneralSettings.asp');

function LinkToCorePages(destination){
	alert("You are now accessing a Core page.  Please be aware that links from this page will link to other Core Pages, and you will need to hit the back button to return to the adaptation.");
	top.location="../Core/"+destination;
}

function openCorePageWindow(page, w, h){
  	var popupWin = window.open("../Core/"+page, "popup", "width=" + w + ",height=" + h);
	alert("You are now accessing a Core page.  Please be aware that links from this page will link to other Core Pages.");
}



//\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\//
// broaden document.domain to avoid javascript security errors. 
try {
	// document.domain = "lexisnexis.com"
}
catch (e) 
{
	// Avoid issues with domain on csdev. Do nothing. 
}


function getWhichServer()
{
	var hostPort    = (window.location.port != "") ? ":" + window.location.port : "";
	return window.location.protocol + "//" + window.location.hostname + hostPort;
}

//\\//\\////\\//\\////\\//\\////\\//\\////\\//\\////\\//\\//
// Cookie Functions

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
	

	
	
	
	
	









