// this is for welcome page for custom dropdown

function changeimage() {

	var im = document.getElementById("selectact");
	var imSrc = im.src
	var imArr = imSrc.split("/")
	var imVal = imArr[imArr.length-1]

	if (imVal == "dropdown_select.gif") {
		im.src = "/images/" + "dropdown_select_hover.gif"
	} else {
		im.src = "/images/" + "dropdown_select.gif"
		
	}
	}
	
	function selectact() {
		//document.getElementById('n_d_back').style.display='block';
		if (document.getElementById("ssactnamelist").style.display == "block") {
			document.getElementById("ssactnamelist").style.display='none';
			//document.getElementById('n_d_back').style.display='none';
		} else {
			document.getElementById("ssactnamelist").style.display='block';
		}
	}


function selectItem(value, text) {
document.getElementById("ssactname").value = value;
document.getElementById("ssactnamelist").style.display='none';
document.getElementById("ssactnameselected").value = text;
}
// these are functions for classifed page //
		
		var _oN,_oNIS,_oInt; //Global objects: Div: container, Div: scroller; Object: Interval
		//var _nSW; //Total Scrollwidth - width of the content within the inner Div
		
		var container = new Array(4)
		var scroller = new Array(4)
		var intervals = new Array(4)
		var nstargs = new Array(4)
		
		
		var _nW; //Wisth of the div object
		var _nSTarg; // The position we want the scroller to be in before it repeats
		var _bS=false; //The master Scroll Boolean, this determines whether the scroller should scroll or not
		var _nS=50; //The speed at which the scroller scrolls (msecs)
		var intTopValue = 0;
		var _aS=9000;
		var intAdNum=0;
		var maxNum =3;
		var currentnum = 0;

		function stop_s(id) {
				clearInterval(intervals[id]); 
				intervals[id]=null;
			}
		function start_s(id) {
			intervals[id] = setInterval("s("+id+")",_nS);
		}
	
		function init_s(oN,oNIS, id) {
			try {
			container[id]=document.getElementById(oN);
			scroller[id]=document.getElementById(oNIS);
			_nSW=parseInt(container[id].scrollHeight);
			nstargs[id]=("-"+_nSW);
			_nW=parseInt(container[id].style.height);
			intervals[id] = setInterval("s("+id+")",_nS);
			} catch (e) { }
		}
		
		function s(id) {
			if(!_bS){

				if (parseInt(nstargs[id]) == 0) {
					try {
						nstargs[id] ="-"+parseInt(scroller_advertisingfront.scrollHeight);
					} catch(e) {
					}
				}
			
				if(parseInt(scroller[id].style.top)>parseInt(nstargs[id])){
					scroller[id].style.top=(parseInt(scroller[id].style.top)-1)+"px";
					} else {
						scroller[id].style.top=_nW+"px";
					}
			}
		}
		


var _newsS=80; 


/* NEWS ON FRONT PAGE */
function init_news(oN,oNIS) {
				_oN=document.getElementById(oN);
				_oNIS=document.getElementById(oNIS);
				_nSW=_oN.scrollHeight;
				_nSTarg="-"+_nSW;
				_nW=parseInt(_oN.style.height);
				_oInt = setInterval("s_news()",_newsS);	
			}
			
			
			function start_news() {
				_oInt = setInterval("s_news()",_newsS);
			}
			
				function stop_news(id) {
				clearInterval(_oInt); 
				_oInt=null;
			}
			
			function s_news() {
			
			if(!_bS){
			

			if (parseInt(_nSTarg) == 0) {
				try {
					_nSTarg ="-"+parseInt(news.scrollHeight);
					
					} catch(e) {
				}
			}
			
				
				if(parseInt(_oNIS.style.top)>parseInt(_nSTarg)){
				
					_oNIS.style.top=(parseInt(_oNIS.style.top)-1)+"px";

					} else {
						_oNIS.style.top=_nW+"px";
					}

			}
		}
		
		
		
		function rotateads(a) {
		
			_oInt = setInterval("ads("+a+")",_aS);
		
		}
		
		function ads(a) {
						
				
				imageId = 'ad1';
				image = document.getElementById(imageId);
				urllink = document.getElementById(imageId+'url');
				image.src=imgArray[intCurrImage];
				urllink.href=imgArray[intCurrImage+1];
				
				setOpacity(image, 0);
				image.style.visibility = 'visible';
				fadeIn(imageId,0);

					if (parseInt(intCurrImage+2) >= parseInt(imgArray.length)) {
						intCurrImage = 0;
					}		 else {
						intCurrImage = intCurrImage+2;
					}
		}
		
		

	
	
	function fadeIn(objId,opacity) {
	  if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
		  setOpacity(obj, opacity);
		  opacity += 10;
		  window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	  }
	}
		
		
		function setOpacity(obj, opacity) {
		  opacity = (opacity == 100)?99.999:opacity;
		  
		  // IE/Win
		  obj.style.filter = "alpha(opacity:"+opacity+")";
		  
		  // Safari<1.2, Konqueror
		  obj.style.KHTMLOpacity = opacity/100;
		  
		  // Older Mozilla and Firefox
		  obj.style.MozOpacity = opacity/100;
		  
		  // Safari 1.2, newer Firefox and Mozilla, CSS3
		  obj.style.opacity = opacity/100;
		}



// this resizes teh content window
function getwidth(v) {
			  var myWidth = 0, myHeight = 0;
			  if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				myWidth = window.innerWidth;myHeight = window.innerHeight;
			  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;myHeight = document.documentElement.clientHeight;
			  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;myHeight = document.body.clientHeight;
			  }			  
				if (v==1) {
				  if (myWidth > 1148)  {
				  return myWidth-100;
				  } else if (myWidth > 942 && myWidth < 1200) {
				  return myWidth-210;		  
				  } else {
				  return myWidth-210;
				 }
			  } else {
				 return myHeight-155;
			  }
		}

// welcome page form check //	

	function checkform(objForm) {
	
	var bStat = true;	var bCase = true;
	
		var nameofact = document.getElementById("ssactname").value;
		var provision =  document.getElementById("ssprovision").value;
		var keywords =  document.getElementById("sskeyword").value;
		
		var casename =  document.getElementById("casename").value;
		var casekeyword =  document.getElementById("casekeyword").value;
		
		var casesmessage = document.getElementById("casesmessage")
		var statmessage = document.getElementById("statmessage")
	
		if (nameofact == "" && provision == "" && keywords  == "") bStat = false; 
		if (casename == "" && casekeyword  == "") bCase = false; 
		
		if (!bStat && !bCase) {
			alert("You can search either the statutes service or the cases. For statutes service enter an Act name with keywords \nwith an optional provision number. For cases search enter either a case name or keywords/phrase.");
		}
		
		if (bStat ) {
			if (nameofact !="" && provision =="" && keywords =="") return true; //name of act only
			if (nameofact !="" && provision =="" && keywords !="") return true; // name of act and keywords only
			
			if (nameofact !="" && provision != "" && keywords =="") return true; //name of act and provision only
			if (nameofact =="" && provision == "" && keywords !="") return true; //keyworsd only
			
			if (nameofact =="" && keywords =="" && provision != "") {
				alert("You can search with the following combinations:\n- Act Name\n- Act Name and Provision\n- Act name and Keywords\n- Keywords only");
				return false;
			}
	
			if (nameofact !="" && keywords !="" && provision != "") {
				alert("You can search with the following combinations:\n- Act Name\n- Act Name and Provision\n- Act name and Keywords\n- Keywords only");
				return false;
			}
		
			
			
		}
		
		if (bCase) {
			if (casename !="" && casekeyword !="") return true //{
			//	alert("Please enter either a case name or keywords");
			//	return false;
				//}
			if (casename =="" && casekeyword !="") return true;
			if (casename !="" && casekeyword =="") return true;
		
		
		}
		
		// get to here then return false
		return false;
		
	
	}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
  //return [ scrOfX, scrOfY ];
}


// CLW search
function checkChildren(status) {
			if (status) {
				document.getElementById("sentence").checked = true;
				document.getElementById("evidence").checked = true;
				document.getElementById("substantive").checked = true;
				document.getElementById("misc").checked = true;
			} else {
				document.getElementById("sentence").checked = false;
				document.getElementById("evidence").checked = false;
				document.getElementById("substantive").checked = false;
				document.getElementById("misc").checked = false;
			}	
		}
		
function checkAll() {
			document.getElementById("newcases").checked = true;
			document.getElementById("sentence").checked = true;
			document.getElementById("evidence").checked = true;
			document.getElementById("substantive").checked = true;
			document.getElementById("misc").checked = true;
			document.getElementById("newleg").checked = true;
			document.getElementById("mainmisc").checked = true;
			
		}
/// ----------------------

function showhide(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
		document.getElementById(id+"2").src = '/images/comment_right_corner_up.gif';
	} else {
		document.getElementById(id).style.display = 'none';
		document.getElementById(id+"2").src = '/images/comment_right_corner_down.gif';
	}
}

//STATUTES SECTION OF THE ADMIN

function showComments(divid) {
	var texttable = document.getElementById(divid+'_text');
	if (texttable.style.visibility == "visible") {
	texttable.style.visibility = "hidden";
	} else {
	texttable.style.visibility = "visible";
	}
}



function addContent(statuteID,parentID,option) {

	switch (option) {
	case 1: 
		strUrl = "admin/popups/statutes_heading_edit.cfm";
		strMess = "You are about to add a child heading";
		alert(strMess);
	break;
	case 2:
		strUrl = "admin/popups/statutes_content_add.cfm";
		strMess = "You are about to add some content";
		alert(strMess);
	break;
	case 3:
		strUrl = "admin/popups/statutes_content_edit.cfm";
		strMess = "You are about to edit some existing content";
		alert(strMess);
	break;
	
	}


}

var eArray= new Array("d_commencement","d_amendment","d_transitional","d_definitions","d_miscellaneous","d_subordinate","d_auth","d_hansard","d_explanatory");


function toggle(id)
{
	closeRow(id);
	changeIcon(id);
	el = document.getElementById(id);
	var display = el.style.display ? '' : 'none';
	el.style.display = display;
}

function closeRow(id) {

	for (i=0; i< eArray.length; i++) {
	
		if (id != eArray[i]) {

			el = document.getElementById(eArray[i]);
			el.style.display = 'none';
			document.getElementById(eArray[i]).src="/images/arrow_up_blue.gif";
		}
			 
	}

}

function changeIcon(id) {

	var newid = "i" + Right(id,id.length-1)
	var src = document.getElementById(newid).src
	var ary = src.split("/")
	
	src = ary[ary.length-1]

	if (src=="arrow_up_blue.gif") {
			
			document.getElementById(newid).src="/images/arrow_down_blue.gif";
		} else {
			document.getElementById(newid).src="/images/arrow_up_blue.gif";
		}

}

//END OF STATUTES SECTION


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function rs(theform) {


theform.launch.value="search";
theform.submit();

}



function collapse(a) {
if (a == 1) {
parent.sec.cols="0,0,*"
}else {
parent.sec.cols="150,1,*"
}

}


//document.write(document.cookie);
// Browser detection variables
var IE = (document.all) ? 1 : 0;
var NN = (document.layers) ? 1 : 0;


function checkcpdform(a) {

	var ok = 1;
	
	if (a.name.value == "") { ok = 0; }
	if (a.firm.value == "") { ok = 0; }
	if (a.cpdref.value == "") { ok = 0; }
	
	if (ok == 1) {
	a.submit();
	
	} else {
	
	alert("Please fill in all the details");
	}

}



function stripSpaces(thestring){
  var mytext = new String("");
  mytext = thestring;
  while (mytext.charAt(0) == ' ') {
    mytext = mytext.substring(1,mytext.length);
  };
  while (mytext.charAt(mytext.length - 1) == ' ') {
    mytext = mytext.substring(0, (mytext.length - 1));
  };
  return mytext;
};

/// CLIPBAORD COOKIE

function readCookie() {

	var the_cookie = document.cookie;

	if  (the_cookie == "") {
		the_cookie = "CLIP=0"
		}

	var myRegExp = /; /gi;
	the_cookie = the_cookie.replace(myRegExp, ";");
	
	var broken_cookie = the_cookie.split(";");
	for (var i=0; i < broken_cookie.length; i++) {
		if (Left(broken_cookie[i], 4) == "CLIP") {
		var the_set = broken_cookie[i];
		var the_set = the_set.split("=");
		the_first = stripSpaces(the_set[0]);
		
			if (the_first == "CLIP") {
				var the_items = the_set[1];
				
				if (the_items) {
				the_set = the_items;
				} else {
				the_set = 0
				}
				
			} else {
			
				var the_set = 0;
				
			}
		
		i = broken_cookie.length;
		
		} else {
		
			var the_set = "not exists";
		}
	}

	return (the_set);

}

function imgclip(i) {

	var source = i.src;
	var filename = source.split("/")
	
	if (filename[filename.length-1] == "smalladdtoclip.gif") {
			i.src = "images/smalladdtoclip2.gif"
	}
	
	var agt = navigator.userAgent.toLowerCase();
	var agtVersion = parseInt(navigator.appVersion);
	
	// this is to fix a bug that doesnt show the above image change when on IE
	if (agt.indexOf("msie 6.0") != -1) {
		//agtName = "msie6"
		alert("Item added to clipboard");
		i.border = 1;
		
	}



}




function addtoclip(a) {


if (isNaN(a)) {

	var myRegExp = /,/gi;
	a = a.replace(myRegExp, "^");
	
	}
	
	var theclip = readCookie();

	if (theclip == "not exists") {
	
	window.status = "cookie does not exist";
		
	} else {
	
		// if no items in cookie
		if (theclip == 0) {
		
			window.status="Nothing returned from cookie";
		
			var the_cookie = "CLIP=" + a;
			document.cookie = the_cookie + "; path=/;"
			
			window.status="Cookie updated";
		
		} else {
		
			//alert("Something returned from cookie:" + theclip);
		
			var the_cookie = document.cookie;
			var myRegExp = /; /gi;
			the_cookie = the_cookie.replace(myRegExp, ";");
			var broken_cookie = the_cookie.split(";");
			for (var i=0; i < broken_cookie.length; i++) {
	

				if (Left(broken_cookie[i], 4) == "CLIP") {
				
					var thevalues = broken_cookie[i].split("=");
					
					newlist = thevalues[1] + "^" + a;
				
					var the_cookie = "CLIP=" + newlist;
					
					document.cookie = the_cookie + "; path=/;"
	
				}
				
			}
		
		}
	
	}

}


function Left(STRING,CHARACTER_COUNT){
return STRING.substring(0,CHARACTER_COUNT);
}
function Right(STRING,CHARACTER_COUNT){
return STRING.substring((STRING.length - CHARACTER_COUNT),STRING.length);
}
function Replace(STRING,REPLACE_THIS,REPLACE_WITH){
while(STRING.indexOf(REPLACE_THIS) > -1){
STRING = STRING.replace(REPLACE_THIS,REPLACE_WITH);
}
return STRING;
}


function updateclip(a) {

found = false;

if (isNaN(a)) {

	var myRegExp = /,/gi;
	a = a.replace(myRegExp, "^");
	
	}
	
	var theclip = readCookie();

	if (theclip == "not exists") {
	
	window.status = "cookie does not exist";
		
	} else {
	
		// if no items in cookie
		if (theclip == 0) {
		
			//alert("Nothing returned from cookie");
		
			var the_cookie = "CLIP=" + a;
			document.cookie = the_cookie + "; path=/;"
		
		} else {
		
					
			var the_cookie = document.cookie;
			var myRegExp = /; /gi;
			the_cookie = the_cookie.replace(myRegExp, ";");
			var broken_cookie = the_cookie.split(";");
			var newlist = ""
		
			var items = new String(a);
		
			// IF COMMA EXISTS THEN THERE ARE MORE THAN 1
			if (items.indexOf("^") == 0) { morethanone = false} else {morethanone = true }
			

//CHECK EXISTS
	for (var i=0; i < broken_cookie.length; i++) {
		if (Left(broken_cookie[i], 4) == "CLIP") {
			
			var thevalues = broken_cookie[i].split("=");
				currentitems = thevalues[1];
				theitems = currentitems.split("^");
			
					if (!morethanone) {
				
						// ONLY ONE ITEM EXISTS
						for (var j=0; j < theitems.length; j++) {
						
							if (theitems[j] != a) {
								newlist = newlist + "^" + theitems[j] ;
							} else {
								found = true
							} 
					
						}
						
						currentitems = newlist
					
					
					} else {
						
					
						
						// MORE THAN ONE ITEM
						found = true
						itemstocheck = items.split("^")
						itemstokeep = "";
						currentitems = "^"+currentitems+"^"
						for (var k=0; k < itemstocheck.length; k++) {
							bOK = true;
							for (var j=0; j < theitems.length; j++) { // CHECK COOKIE AGAINST NEW ITEMS
		
								if (theitems[j] == itemstocheck[k]) {
									bOK = false;
									
									currentitems = Replace(currentitems,"^"+theitems[j]+"^","^")
								} 
					
							} // END LOOP FOR CHECK COOKIE AGAINST NEW ITEMS
							
							if (bOK) {
								
								itemstokeep = itemstokeep + "^" + itemstocheck[k]
							}
							
						}
					
				}
	
				
						// clean up lists
		if (Left(currentitems, 1) == "^") {
				currentitems = Right(currentitems, currentitems.length-1) 
		}

	if (Left(itemstokeep, 1) == "^") {
				itemstokeep = Right(itemstokeep, itemstokeep.length-1) 
		}
				
			var the_cookie = "CLIP=" + currentitems + itemstokeep;
		
			document.cookie = the_cookie + "; path=/;"
		}
	}
// END CHECK EXISTS
		
		

	if (!found) {
		// ADD ITEM TO COOKIE
		var newlist = ""
		for (var i=0; i < broken_cookie.length; i++) {
			if (Left(broken_cookie[i], 4) == "CLIP") {
				var thevalues = broken_cookie[i].split("=");
				newlist = thevalues[1] + "^" + a;
				var the_cookie = "CLIP=" + newlist;
				document.cookie = the_cookie + "; path=/;"
			}
		}
		/// END ADD TO COOKIE
	}
		
		}
	
	}
}


function readStatCookie() {

	var the_cookie = document.cookie;
	var myRegExp = /; /gi;
	the_cookie = the_cookie.replace(myRegExp, ";");
	var broken_cookie = the_cookie.split(";");
	for (var i=0; i < broken_cookie.length; i++) {
		if (Left(broken_cookie[i], 5) == "STAT=") {
		var the_set = broken_cookie[i];
		var the_set = the_set.split("=");
		the_first = stripSpaces(the_set[0]);

			if (the_first == "STAT") {
				var the_items = the_set[1];
				if (the_items) {
					the_set = the_items;
				} else {
					the_set = 0
				}
				
			} else {
			
				var the_set = 0;
				
			}
		
		i = broken_cookie.length;
		
		} else {
		
			var the_set = "not exists";
		}
	}

	return (the_set);

}

function addtoStatclip(a) {


if (isNaN(a)) {

	var myRegExp = /,/gi;
	a = a.replace(myRegExp, "^");
	
	}

	var theclip = readStatCookie();


	if (theclip == "not exists") {
	
	window.status = "cookie does not exist";
		
	} else {
	
		// if no items in cookie
		if (theclip == 0) {
		
			//alert("Nothing returned from cookie");
		
			var the_cookie = "STAT=" + a;
			document.cookie = the_cookie + "; path=/;"
		
		} else {
		
			//alert("Something returned from cookie:" + theclip);
		
			var the_cookie = document.cookie;
			var myRegExp = /; /gi;
			the_cookie = the_cookie.replace(myRegExp, ";");
			
			var broken_cookie = the_cookie.split(";");
			for (var i=0; i < broken_cookie.length; i++) {

				if (Left(broken_cookie[i], 5) == "STAT=") {
				
					var thevalues = broken_cookie[i].split("=");
					
					newlist = thevalues[1] + "^" + a;
				
					var the_cookie = "STAT=" + newlist;
					
					document.cookie = the_cookie + "; path=/;"
	
				}
				
			}
		
		}
	
	}
}

function resizeHandle(){
  history.go(0);
}

browserName = navigator.appName;
browserVendor = browserName.substring(0,9);
browserVer = parseInt(navigator.appVersion);

if (browserVer=="4" && browserVendor=="Netscape")
{window.onresize=resizeHandle;}


function checksearch(a) {
	var keywords=a.keywords.value,judgedate=a.JudgementDateSelect.value,judgedatetext=a.JudgementDateText.value,judgename=a.JudgeNameSelect.value,judgenametext=a.JudgeNameText.value,clwissues=a.CLWIssuesSelect.value,clwissuestext=a.CLWIssuesText.value;
	(keywords!="")?bKeywordsFull=true:bKeywordsFull=false;
	(judgedate!="all"&&judgedatetext!="")?bJudgeDateFull=true:bJudgeDateFull=false;
	(judgename!="all"&&judgenametext!="")?bJudgeNameFull=true:bJudgeNameFull=false;
	(clwissues!="all"&&clwissuestext!="")?bCLWIssueFull=true:bCLWIssueFull=false;
		
		if (!bKeywordsFull && !bJudgeDateFull && !bJudgeNameFull && !bCLWIssueFull) {
			alert("Please make sure you enter either, keywords/ phrases in the search boxes\n or select a date of judgment, judge name or selected issues");
			return false;
		} else{
				
				keywords = escape(keywords)

			a.action = a.action+"?launch=searchresults&q="+keywords
			a.submit();
		}
}



function addnewcase(number) {

amount = document.searchform.seq.length;
startfrom = number -1;
d = document.searchform;
/*
for (var j=startfrom;j< amount; j++) {

	if (d.seq[j].value != "" || d.seq[j].value !=0) {
	
			var thecurrent = d.seq[j].value * 1;

			d.seq[j].value = thecurrent + 1;

	}
}
*/

var newurl = "admin/popups/cases_add.cfm?number=" + number + "&count=" + amount;
openWin(newurl, 'cases', 'addcases', 460, 340, CENTER);
}




function addseq(d) {
//alert("Please be patient as this may take some time");

if (d == 'searchform') {
d = document.searchform;
}

seqlength = d.seq.length;
if (seqlength) {
a=0;

/// get the count
for (var j=0;j< seqlength; j++) {

	if (d.seq[j].value != "" || d.seq[j].value !=0) {
		if (d.seq[j].value > a) {
			a=d.seq[j].value;
		}
	}
}

a = a * 1;

if (a==0) {

	a = 1;

}

for (var i=0; i < seqlength; i++) {

	if (d.seq[i].value == "") {
	d.seq[i].value=a;
	a=a+1;
	}
}
} else {

if (d.seq.value == "") {
	d.seq.value=1;
	}
}


}


function clearseq(d) {

if (d == 'searchform') {

d = document.searchform;
}

seqlength = d.seq.length;


for (var i=0; i < seqlength; i++) {

	d.seq[i].value="";

}


}



function checkfreetrial(d) {

var checkit = "ok";

if (d.Password.value == "") {checkit = "password";}
if (d.Username.value == "") {checkit = "username";}
if (d.Tel.value == "") {checkit = "telephone";}
if (d.Firm.value == "") {checkit = "organisation";}
if (d.Lastname.value == "") {checkit = "last name";}
if (d.Firstname.value == "") {checkit = "first name";}

			// if all is ok to here now submit it
			if (checkit == "ok") {
				if (confirm("By registering for Criminal Law Week Online you agree to the terms and conditions\nas found under the information menu")) {
				d.submit();
				}
			} else {
				alert("Please make sure that you have\nfilled out the " + checkit + " field");
			}
}

function checkregister(d) {

var checkit = "ok";

if (d.Tel.value == "") {checkit = "telephone";}
if (d.Town.value == "") {checkit = "town";}
if (d.Address1.value == "") {checkit = "address";}
if (d.Lastname.value == "") {checkit = "last name";}
if (d.Firstname.value == "") {checkit = "first name";}

			// if all is ok to here now submit it
			if (checkit == "ok") {
				//if (confirm("By registering for Criminal Law Week Online you agree to the terms and conditions\nas found under the information menu")) {
				d.submit();
				//}
			} else {
				alert("Please make sure that you have\nfilled out the " + checkit + " field");
			}

}


function checkimage(a) {
if (a) {
if (a == "criminal") {
self.document.images["fullscreen"].src = "images/minimise.gif";

self.parent.main.location.href = parent.opener.parent.main.location.href;

}
}
}


function gobig(a) {
	
	if (parent.name != "criminal") {
	
	thewin = window.open('index.cfm','criminal','fullscreen=yes,scrollbars=yes');
	
	//
	} else {
	

	parent.opener.parent.main.location.href=a;
	parent.close();
	}
	
}

function donothing(d) {
	window.status = d;
}

function MM_checkPlugin(plgIn) { //from dreamweaver then edited
  var ok=false;
  with (navigator) if (appName.indexOf('Microsoft')==-1)  ok=(plugins && plugins[plgIn]);
  else if (appName.indexOf('Netscape')==-1) ok=(plugins && plugins[plgIn]);
   { 
    if (plgIn.indexOf("Flash")!=-1 &&MM_flash!=null) ok=MM_flash;
    } 
}

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function tmt_findObj(n){
	var x,t; if((n.indexOf("?"))>0&&parent.frames.length){t=n.split("?");
	x=eval("window.parent.frames['"+t[1]+"'].document.getElementById('"+t[0]+"')");
	
	}else{x=document.getElementById(n)}return x;
}

function moveLayerToPosition(thelayer) {
thelayer = thelayer.split("?");
thelayername = thelayer[0];

try {
    if (IE) {
			thelayername = parent.frames['main'].document.getElementById(thelayername).style;
			position = parent.frames['main'].document.body.scrollTop;
            thelayername.pixelTop = position;
    }		
	} catch (exception)  {
			//alert(exception);
	}
}

function MM_showHideLayers() { 
//v3.0A Modified by Al Sparber and Massimo Foti for NN6 Compatibility
if (MM_showHideLayers.arguments[2] =='show') {
 moveLayerToPosition(MM_showHideLayers.arguments[0])
 }
  var i,p,v,obj,args=MM_showHideLayers.arguments;if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){ obj=tmt_findObj(args[i]);v=args[i+2];
   v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;}} else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }}
}

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_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 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];}
}


var currentlayers = new Array(2);


currentlayers[0] = "information";
currentlayers[1] = "cpd";
currentlayers[2] = "reg";
currentlayers[3] = "links";
//nvis = "invis";


function hidealllayers() {
//alert("at least the function is being called!!");
MM_showHideLayers('invis?1', '', 'hide');
MM_showHideLayers('subscribers?1', '', 'hide');
MM_showHideLayers('information?3', '', 'hide');
MM_showHideLayers('cpd?3', '', 'hide');
MM_showHideLayers('reg?3', '', 'hide');
MM_showHideLayers('invis2?3', '', 'hide');
MM_showHideLayers('links?3', '', 'hide');

}


function dolayers(a) {
MM_showHideLayers(a + "?3", '', 'show');
MM_showHideLayers("subscribers?1", '', 'hide');


	for (var i = 0; i < 2; i++) 
	{
		if (currentlayers[i] != a) {
		
		MM_showHideLayers(currentlayers[i] + "?3", '', 'hide');
		}
	}
}


function domouseover(d, thelink) {

var thelink;

d.style.background="#ffff99";
window.status = thelink;

}

function domouseout(d, thelink) {

var thelink;

d.style.background="#cccccc";
window.status = thelink;
//d.cells[0].innerHTML="<a href='' class='dropdown'>" + thelink + "</a>";

}


function openpopup(url, issueyear, issuenumber) {

var newurl = url + "?issuenumber=" + issuenumber + "&issueyear=" + issueyear;
openWin(newurl, 'issuewin', '', 300, 220, CENTER);

}

function editsection(url, sectionid) {

var newurl = url + "?sectionid=" + sectionid ;
openWin(newurl, 'issuewin', '', 300, 170, CENTER);

}

function editindex(url, sectionid) {

var newurl = url + "?indexheadid=" + sectionid ;
openWin(newurl, 'issuewin', '', 300, 170, CENTER);

}

function editparentindex(url, sectionid) {

var newurl = url + "?indexheadid=" + sectionid ;
openWin(newurl, 'issuewin', '', 400, 220, CENTER);

}

function editsubindex(url, parent, head, id) {

var newurl = url + "?parent=" + parent + "&head=" + head + "&indexdetailid=" + id;
openWin(newurl, 'issuewin', '', 380, 140, CENTER);

}

function editindexheadlinks(itemid,a) {

var newurl = "admin/popups/indexlinksframe.cfm?itemid=" + itemid + "&page=" + a ;
openWin(newurl, 'issuewin', '', 500, 400, CENTER);

}

function editcases(url,  id) {
	
	if (url.indexOf("?") > 0) {
		connector = "&"
	} else {
		connector = "?"
	}

var newurl = url + connector+"casesformatid=" + id;
openWin(newurl, 'issuewin', '', 450, 340, CENTER);

}

function editstatinst(url,  id) {

var newurl = url + "?statid=" + id;
openWin(newurl, 'issuewin', '', 450, 200, CENTER);

}

function editstatsub(url, statid, statsubid) {

var newurl = url + "?statid=" + statid + "&statsubid=" + statsubid;
openWin(newurl, 'issuewin', '', 300, 170, CENTER);

}

function edituser(url,  id) {

var newurl = url + "?userid=" + id;
openWin(newurl, 'issuewin', '', 700, 470, CENTER,RESIZABLE,SCROLLBARS);

}

function editjudgenames(itemid,a) {

var newurl = "admin/popups/judgeframe.cfm?itemid=" + itemid + "&page=" + a ;
openWin(newurl, 'issuewin', '', 550, 400, CENTER);

}

function showhelp(url) {
//alert(url);
var lengthofwin = 330;
var widthofwin = 230;
var newurl = "help/" + url + ".cfm";

if (url == "judgments") {
var lengthofwin = 390;
var widthofwin = 300;
}

if (url == "judges") {
var lengthofwin = 290;
var widthofwin = 300;
}

if (url == "CLWsections") {
var lengthofwin = 290;
}

if (url == "searchlen") {
var lengthofwin = 185;
}

if (url == "maxresults") {
var lengthofwin = 225;
}

if (url == "CLWadvanced1") {
var lengthofwin = 400;
var widthofwin = 350;
}

if (url == "CLWadvanced2") {
var lengthofwin = 400;

}

openWin(newurl, 'issuewin', '', widthofwin, lengthofwin, CENTER, SCROLLBARS);

}


function areyousure(d) {
	
	if (confirm("Are you sure you\nwant to delete this?")) {
	d.submit();
	} else {
	return false;
	}
}

function genissues(page, year, issue) {

var newurl = "admin/popups/issues.cfm?year=" + year; 
	if (issue > 0) {
	newurl = newurl + "&issuenum=" + issue;
	}
openWin(newurl, 'issuewin', '', 320, 200, CENTER);

}

function genissuesoff(page, year, issue) {

var newurl = "admin/popups/offline_issues.cfm?year=" + year; 
	if (issue > 0) {
	newurl = newurl + "&issuenum=" + issue;
	}
openWin(newurl, 'issuewin', '', 320, 200, CENTER,STATUS,TOOLBAR);

}

////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


function generateSS(strURL) {
var newurl = "/admin/popups/generateofflineframeSS.cfm?pagename=" + strURL;
openWin(newurl, 'ss', 'ss', 320, 140, UPPERRIGHT,RESIZABLE);
}


function generateweekly() {
var newurl = "admin/popups/generateweekly.cfm";
openWin(newurl, 'issuewin', '', 320, 200, UPPERRIGHT,STATUS,TOOLBAR,RESIZABLE);
}

function genissuesoff2(page, year, id) {
var newurl = "offline_issues.cfm?week=1&year=" + year + "&id="+id;
openWin(newurl, 'issuewin', '', 320, 200, CENTER,STATUS,TOOLBAR,RESIZABLE);
}

function generateoff2(page, letter) {
var newurl = "generate_offline_" + page + ".cfm?a=a"
//var newurl = "generateofflineframe.cfm?week=1&pagename=" + page;
if (letter != 0) {
newurl = newurl + "&letter=" + letter;
}
openWin(newurl, 'issuewin', '', 320, 200, CENTER,STATUS,TOOLBAR,RESIZABLE);
}

function generateCaseSections(sectionid) {
var newurl = "generate_offline_cases.cfm?sectionid="+sectionid
//var newurl = "generateofflineframe.cfm?week=1&pagename=" + page;

openWin(newurl, 'issuewin', '', 320, 200, CENTER,STATUS,TOOLBAR,RESIZABLE);
}


////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function generateoff(page, letter) {

var newurl = "admin/popups/generateofflineframe.cfm?pagename=" + page;
if (letter != 0) {
newurl = newurl + "&letter=" + letter;
pagetext = page + " [" + letter + "]";
} else {
pagetext = page;
}
openWin(newurl, 'issuewin', '', 320, 200, CENTER,STATUS,TOOLBAR);
}

function generate(page, letter) {

var newurl = "admin/popups/generateframe.cfm?pagename=" + page;
if (letter != 0) {
newurl = newurl + "&letter=" + letter;
pagetext = page + " [" + letter + "]";
} else {
pagetext = page;
}
openWin(newurl, 'issuewin', '', 320, 200, CENTER);
}

function updatefirst(d) {
	
	if (confirm("Update the form first?,\nor continue despite losing any changes")) {
	d.submit();
	} else {
	return true;
	}
}

function getcasesinfo(caseid) {

var newurl = "main/showcases.cfm?ref=" + caseid ;
openWin(newurl, 'issuewin', '', 400, 300, SCROLLBARS, CENTER);

}

function sources() {

var newurl = "main/sources.cfm";
openWin(newurl, 'sources', '', 570, 410, CENTER);

}

function reviews(d) {
if (d ==1){
var newurl = "main/reviews.cfm";
} 

if (d ==2) {
var newurl = "main/cpd_reviews.cfm";

}
openWin(newurl, 'reviews', '', 600, 450, CENTER);

}

function backissues() {

var newurl = "main/backissues.cfm";
openWin(newurl, 'backissues', 'backissues', 220, 340, CENTER);

}

function openkeywords() {

var newurl = "search/searchframe.cfm";
openWin(newurl, 'issuewin', '',600, 400, CENTER);

}

function editcpdsheet(sectionid) {

if (sectionid==0)
{var newurl = "admin/popups/cpdsheet_add.cfm";}
else
{var newurl = "admin/popups/cpdsheet_edit.cfm?sectionid=" + sectionid;}
openWin(newurl, 'editcpdsheet', '',300, 190, CENTER);

}

function editcpdsheetbarr(sectionid) {

if (sectionid==0)
{var newurl = "admin/popups/cpdsheet_add_barr.cfm";}
else
{var newurl = "admin/popups/cpdsheet_edit_barr.cfm?sectionid=" + sectionid;}
openWin(newurl, 'editcpdsheet', '',300, 190, CENTER);

}

function selectitems() {

var newurl = "admin/popups/selectitems.cfm";
openWin(newurl, 'issuewin', '',600, 400, CENTER);

}

function selectallitems(d) {

for (var i = 0; i < d.length; i++)
{	d.options[i].selected = true; }

}

function doneselectitems(d) {

var thelist = "";
for (var i = 1; i < d.items.length; i++) {
	if (d.items.options[i].selected) 
	{	thelist = thelist  + d.items.options[i].value + ","; }
}

opener.keywordform.itemlist.value = thelist;
self.close();
}

var running = false
var endTime = null
var timerID = null

function startTimer(a) {
	running = true
	now = new Date()
	now = now.getTime()
	
	// change last multiple for the number of minutes
	if (a == "close") {
	endTime = now
	} else {
	endTime = now + (40 * 60 * 1)
	}
	showCountDown(a)
}

function showCountDown(a) {
	var now = new Date()
	now = now.getTime()
	
	if (endTime - now <= 0) {
		stopTimer()
		if (a == "close") {
		window.close()
		} else {
		location.href=a
		}
	} else {
		if (running) {
			timerID = setTimeout("showCountDown('" + a + "')",1000)
		}
	}
}

function stopTimer() {
	clearTimeout(timerID)
	running = false
}


function isNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function doprint() {

	window.focus();
	window.print();

}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
