function turnMouseOff(ImageName) {
	//  closePopup();
	//  if (document.images != null) {
	//    document[ImageName].src = eval(ImageName + "Off.src");
	//  }
}

// var oPopup = window.createPopup();
function turnMouseOver(ImageName) {
	// The popup object exposes the document object and its properties.
	//   var oPopBody = oPopup.document.body;
	//	var desc;
	//	switch(ImageName){
	//	case 'login':  desc = jlogindesc;  break;
	//	case 'search': desc = jsearchdesc; break;
	//	case 'advsch': desc = jadvschdesc; break;
	//	case 'brief':  desc = jbriefdesc;  break;
	//	case 'full':   desc = jfulldesc;   break;
	//	case 'prev':   desc = jprevdesc;   break;
	//	case 'next':   desc = jnextdesc;   break;
	//	case 'rdrs':   desc = jrdrsdesc;   break;
	//	case 'help':   desc = jhelpdesc;   break;
	//	case 'logout': desc = jlogoutdesc;
	//	}
	
	// Setup colours
	//	oPopBody.style.backgroundColor = "#666699";
	//	oPopBody.style.border = "#666699 1px";
	// The following HTML that populates the popup object with a string.
	//	oPopBody.innerHTML ='<font size=3 color="white" face="Arial"><b>'+desc+'</b></font>';
	// Parameters of the show method are in the following order: x-coordinate,
	// y-coordinate, width, height, and the element to which the x,y
	// coordinates are relative. Note that this popup object is displayed
	// relative to the body of the document.
	//	oPopup.show(175, 39, 150, 25, document.body);
	
	//	if (document.images != null) {
	//	document[ImageName].src = eval(ImageName + "Over.src");
	//	}
}

function turnMouseDown(ImageName) {
	//  if (document.images != null) {
	//    document[ImageName].src = eval(ImageName + "Down.src");
	//  }
}

function closePopup()
{
	oPopup.hide();
}

function MarkRow(RowNum, Action, multi, allrows, cookies) {
	var ThisRow = document.getElementById("Selectable"+RowNum);
	var curclass = ThisRow.className;
	var begcurclass = curclass.substr(0,7);
	if (Action == 'down') {
		if (multi != true) {
			ClearAllRows();
		}
		if (allrows) {
			ThisRow.className = "rdtdatasel";
			} else {
			if (begcurclass == 'rdhirow') {
				if (curclass == 'rdhirowsel') {
					ThisRow.className = "rdhirowover";
					} else {
					ThisRow.className = "rdhirowsel";
				}
			}
			if (begcurclass == 'rdtdata') {
				if (curclass == 'rdtdatasel') {
					ThisRow.className = "rdtdataover";
					} else {
					ThisRow.className = "rdtdatasel";
				}
			}
		}
		//		if (cookies) {
		//			SetCookies(multi);
		//		}
		} else if (Action == 'over') {
		if ((curclass != 'rdhirowsel') && (curclass != 'rdtdatasel')){
			ThisRow.className = curclass+"over";
		}
		
		} else if (Action == 'out') {
		//		if ((curclass != 'rdhirowsel') && (curclass != 'rdtdatasel')){
		if ((curclass == 'rdtdatasel') || (curclass == 'rdhirowsel')) {
			if (begcurclass == 'rdhirow') {
				ThisRow.className = "rdhirow";
				} else {
				ThisRow.className = "rdtdata";
			}
		}
	}
	if (cookies) {
		SetCookies(multi);
	}

}

function ClearAllRows()
{
	cRowArray=document.getElementsByTagName('tr');
	var rowCellsCnt  = cRowArray.length;
	for (c = 1; c < rowCellsCnt; c++) {
		ccurname = cRowArray[c].getAttribute('Id');
		if (ccurname == null) continue;
		ccurname = ccurname.substr(0,10);
		ccurclass = cRowArray[c].className;
		cbegcurclass = ccurclass.substr(0,7);
		if (ccurname == "Selectable") {
			if (cbegcurclass == "rdtdata") {
				cRowArray[c].className = "rdtdata";
				} else	{
				cRowArray[c].className = "rdhirow";
			}
		}
	}
}


function CollectRows(returnfield)
{
	var valuefield = "";
	var newret = "";
	var curname;
	var curid;
	var curclass;
	RowArray=document.getElementsByTagName('tr');
	var rowCellsCnt  = RowArray.length;
	for (c = 1; c < rowCellsCnt; c++) {
		curname = RowArray[c].getAttribute('Id');
		if (curname == null) continue;
		curid = curname.substr(10);
		curname = curname.substr(0,10);
		curclass = RowArray[c].className;
		if (curname == "Selectable") {
			if ((curclass == "rdtdatasel") || (curclass == "rdhirowsel")){
				if (valuefield == "") {
					valuefield = curid;
					} else {
					valuefield = valuefield + "%FD" + curid;
				}
			}
		}
	}
	if (valuefield == "") {
		alert("No rows have been selected");
		} else {
		newret=returnfield.replace(/RowID/,valuefield);
		location = newret;
	}
}

function setfocus() {
	if (document.forms[0]!=null) {
		if (document.forms[0].length != null) {
			for (var i = 0; i < document.forms[0].length; i++) {
				if (document.forms[0].elements[i].type == "text") {
					// Set first text field to have focus
					document.forms[0].elements[i].focus();
					break;
				}
			}
		}
	}
}

function ShowRows()
{
	var valuefield = "";
	var newret = "";
	var curname;
	var curid;
	var curclass;
	RowArray=document.getElementsByTagName('tr');
	var rowCellsCnt  = RowArray.length;
	for (c = 1; c < rowCellsCnt; c++) {
		curname = RowArray[c].getAttribute('name');
		curid = RowArray[c].getAttribute('Id');
		curclass = RowArray[c].className;
		if (curname == "Selectable") {
			if ((curclass == "rdtdatasel") || (curclass == "rdhirowsel")){
				if (valuefield == "") {
					valuefield = curid;
					} else {
					valuefield = valuefield + "," + curid;
				}
			}
		}
	}
	if (valuefield == "") {
		alert("No rows have been selected");
		} else {
		alert(valuefield);
	}
}

function SetCookies(multi)
{
	var teststr = "";
	var newret = "";
	var curname;
	var curid;
	var curclass;
	var hrows = new Array();
	var i = 0;
	var j = 0;
	var RowValue = 0;
	RowArray=document.getElementsByTagName('tr');
	var rowCellsCnt  = RowArray.length;
	// Find cookies on this page and delete them!
	var cookievalues = document.cookie.split(";");
	if (cookievalues.length != 0) {
		for (i=0; i<cookievalues.length; i++){
			teststr = cookievalues[i];
			if (teststr.search(/SelResults/) != -1) {
				break;
			}
		}
		if (multi==true) {
			// Check that there is a SelResults cookie in the list
			if (teststr.search(/SelResults/) != -1) {
				var selrows = teststr.split('=');
				if (selrows.length > 1) { // Make sure there are some highlighted rows
					hrows = selrows[1].split(",");
					// numerically sort the array into numerical order
					hrows.sort(function(a,b) {return a-b;});
					// Now find begining and end rows in page
					var rowtop = 0;
					var rowbottom = 0;
					// We have to go around the houses because Internet Explorer is crap and doesn't support GetElementsByName except for <A> and <Form> elements
					for (j=0; j < rowCellsCnt; j++) {
						curname = RowArray[j].getAttribute('id');
						if (curname == null) continue;
						curid = curname.substr(10);
						curname = curname.substr(0,10);
						if (curname == "Selectable") {
							if (rowtop == 0) {
								rowtop = (+curid);
								} else {
								rowbottom = (+curid);
							}
						}
					}
					// Deal with single row tables (e.g. a full display)
					if (rowbottom == 0) {
					   rowbottom = rowtop;
						}
					i = 0;
					do {
						RowValue = (+hrows[i]);
						if ((RowValue >= rowtop) && (RowValue <= rowbottom)) {
							hrows.splice(i,1); // remove element i
							} else {
							i++;
						}
					} while (i < hrows.length);
				}
			}
		}
		// Now add array elements for rows that are highlighted
		for (c = 0; c < rowCellsCnt; c++) {
				curid = RowArray[c].getAttribute('id');
				if (curid == null) continue;
				curname = curid.substr(0,10);
				curid = curid.substr(10);
				if (curname == "Selectable") {
				curclass = RowArray[c].className;
				if ((curclass == "rdhirowsel") || (curclass == "rdtdatasel")){
					hrows.push(curid);   // add this item to array
					}
				}
			}
		document.cookie = "SelResults="+hrows.join();
	}
}


function HighlightRows() {
	var cookievalues = document.cookie.split(";");
	if (cookievalues.length != 0) {
		var l = 0;
		for (l=0; l<cookievalues.length; l++){
			teststr = cookievalues[l];
			if (teststr.search(/SelResults/) != -1) {
				break;
			}
		}
		// Check that there is a SelResults cookie in the list
		if (teststr.search(/SelResults/) != -1) {
			var selrows = teststr.split('=');
			if (selrows.length > 1) { // Make sure there are some highlighted rows
				var rowlist = selrows[1].split(',');
				if (rowlist.length > 0) {
					for (m=0; m < rowlist.length; m++) {
						var rowelement = document.getElementById("Selectable"+rowlist[m]);
						if (rowelement == null) continue;
						rowelement.className = 'rdtdatasel';
						var selbox = document.getElementById('I'+rowlist[m]);
						selbox.checked = true;
					}
				}
			}
		}
	}
}


function checkdownload(frm) {
	if (frm.target.options == null) {
		return true;
	}
	var NewTarget = frm.target.options[frm.target.selectedIndex].value;
	var BtnName = frm.elements['continue'].value;
	if (BtnName == 'Cancel') {
	   document.history.go(-2);
		return false;
		} else {
		if (NewTarget == "download") {
			var session = frm.SessionID.value;
			var dataset = frm.DataSetName.value;
			var downloadfile = frm.downloadName.value;
			var oldaction = frm.action;
			frm.action = oldaction + "/" + downloadfile + "?target=download&DataSetName=" + dataset + "&SessionID=" + session;
		}
		return true;
	}
}

function select_change() {
	var btntxt = '';
	var sel_element = document.forms[0].elements[0];
	var selection = sel_element.options[sel_element.selectedIndex].value;
	switch(selection) {
		case 'print': btntxt = previewbtntxt;
		break;
		case 'download': btntxt = Downbtntxt;
		break;
		case 'email': btntxt = emailbtntxt;
		break;
		case 'basket': btntxt = addbasbtntxt;
		break;
	}
	document.forms[0].elements['continue'].value = btntxt;
}

function circhandler(parameters) {
	var pageinputs = document.getElementsByTagName('input');
	var circinputs = "";
	for (var i=0; i< pageinputs.length; i++) {
	    if (pageinputs[i].name == "SessionID") {
	      continue;
	    }
	    if (pageinputs[i].value.indexOf("#") != -1) {
	      continue;
	    }
	    circinputs = circinputs+"&"+pageinputs[i].name+"="+pageinputs[i].value;
	    var testinput = pageinputs[i].name.substr(0,6);
	    if ((testinput == "Inputs") && (pageinputs[i].value == "")) {
		alert(circinputerror);
		return;
	    }
	}
	var finalstr = parameters + circinputs;
	location = finalstr;
	exit();
}

function checkfield() {
	var pageinputs = document.getElementsByTagName('input');
	var circinputs = "";
	for (var i=0; i< pageinputs.length; i++) {
	    var testinput = pageinputs[i].name.substr(0,6);
	    if ((testinput == "Inputs") && (pageinputs[i].value == "")) {
		alert(circinputerror);
		return false;
	    }
	}
}

function checkfieldID(fieldID,fieldIDMessage) {
	var checkfield2 = document.getElementById(fieldID);
	if (checkfield2.value=="") {
		alert(fieldIDMessage);
		return false;
	} else {
		return true;
	}
}

function CookieSelectRow(imgrow) {
	if (document.images) {
		var StrRowNum = imgrow.substr(1);
		var CurSelImg = document.getElementById(imgrow);
		var giflength = CurSelImg.src.length;
		var gifname = CurSelImg.src.substr(giflength-10,6);
		if (gifname == 'select') {
			CurSelImg.src = selectimg.src;
			MarkRow(StrRowNum, 'down', true, false, true);
			} else {
			CurSelImg.src = selectedimg.src;
			MarkRow(StrRowNum, 'down', true, false, true);
		}
	}
}


function CookieSelClrRows() {
	RowArray = document.getElementById('selclr');
	giflength = RowArray.src.length;
	gifname = RowArray.src.substr(giflength-10,6);
	if (gifname == 'selted') {
		RowArray.src = clearimg.src;
		CookieSelectAllRows();
		} else {
		RowArray.src = selectimg.src;
		ClearAllRows();
		ClearAllTics();
		SetCookies(false);
	}
}

function SelClrRows() {
	RowArray=document.getElementsByName('selclr');
	var rowCellsCnt = RowArray.length;
	for (c = 0; c < rowCellsCnt; c++) {
		curid = RowArray[c].getAttribute('Id');
		// See if the row ID is in the array
		if (curid == 'selclr') {
			RowNum = c+1;
			var StrRowNum = RowNum+'';
			giflength = RowArray[c].src.length;
			gifname = RowArray[c].src.substr(giflength-10,6);
			if (gifname == 'selted') {
				RowArray[c].src = clearimg.src;
				SelectAllRows();
				} else {
				RowArray[c].src = selectimg.src;
				ClearAllRows();
				ClearAllTics();
			}
		}
	}
}

function SelectAllRows() {
	bRowArray=document.getElementsByName('selection');
	var browCellsCnt = bRowArray.length;
	for (d = 0; d < browCellsCnt; d++) {
		StrRowNum = bRowArray[d].getAttribute('Id');
		StrRowNum = StrRowNum.substr(1);
		bRowArray[d].src = selectimg.src;
		MarkRow(StrRowNum, 'down', true, true, false);
	}
}

function CookieSelectAllRows() {
	var bRowArray = document.getElementsByTagName('input');
	var browCellsCnt = bRowArray.length;
	for (d = 0; d < browCellsCnt; d++) {
		var StrRowNum = bRowArray[d].getAttribute('id');
		if (StrRowNum != null) {
			if (StrRowNum.substr(0,1) == "I") {
				StrRowNum = StrRowNum.substr(1);
				bRowArray[d].checked = true;
				MarkRow(StrRowNum, 'down', true, true, true);
			}
		}
	}
}

//function CookieSelectAllRows() {
//	var bRowArray = document.getElementsByTagName('img');
//	var browCellsCnt = bRowArray.length;
//	for (d = 0; d < browCellsCnt; d++) {
//		var StrRowNum = bRowArray[d].getAttribute('id');
//		if (StrRowNum != null) {
//			if (StrRowNum.substr(0,1) == "I") {
//				StrRowNum = StrRowNum.substr(1);
//				bRowArray[d].src = selectimg.src;
//				MarkRow(StrRowNum, 'down', true, true, true);
//			}
//		}
//	}
//}

function ClearAllTics() {
   aRowArray=document.getElementsByTagName('input');
	var arowCellsCnt = aRowArray.length;
	for (d = 0; d < arowCellsCnt; d++) {
		acurname = aRowArray[d].getAttribute('id');
		if (acurname == null) continue;
		acurname = acurname.substr(0,1);
		if (acurname == "I") {
			aRowArray[d].checked = false;
		}
	}
}

//function ClearAllTics() {
//  aRowArray=document.getElementsByTagName('img');
//	var arowCellsCnt = aRowArray.length;
//	for (d = 0; d < arowCellsCnt; d++) {
//		acurname = aRowArray[d].getAttribute('id');
//		if (acurname == null) continue;
//		acurname = acurname.substr(0,1);
//		if (acurname == "I") {
//			aRowArray[d].src = selectedimg.src;
//		}
//	}
//}


function SingleSelectRow(imgrow) {
	if (document.images) {
		RowElement2=document.getElementById(imgrow);
		var StrRowNum = imgrow.substr(1);
//		giflength = RowElement2.src.length;
//		gifname = RowElement2.src.substr(giflength-10,6);
		if (RowElement2.checked == true) {
			// Clear all rows before selecting the right one.
			imgarray = document.getElementsByTagName('input');
			imgCellsCnt = imgarray.length;
			for (g=0; g<imgCellsCnt; g++) {
				var imgid = imgarray[g].getAttribute('id');
				if (imgid == null) continue;
				if (imgid.substr(0,1)=="I") {
				imgarray[g].checked = false;
				}
			}
			RowElement2.checked = true;
			MarkRow(StrRowNum, 'down', false, false, true);
			} else {
			imgarray = document.getElementsByTagName('input');
			imgCellsCnt = imgarray.length;
			for (g=0; g<imgCellsCnt; g++) {
				var imgid = imgarray[g].getAttribute('id');
				if (imgid == null) continue;
				if (imgid.substr(0,1)=="I") {
				imgarray[g].checked = false;
				}
			}
			RowElement2.checked = false;
			MarkRow(StrRowNum, 'out', false, false, true);
		}
	}
}

//function SingleSelectRow(imgrow) {
//	if (document.images) {
//		RowElement2=document.getElementById(imgrow);
//		var StrRowNum = imgrow.substr(1);
//		giflength = RowElement2.src.length;
//		gifname = RowElement2.src.substr(giflength-10,6);
//		if (gifname == 'select') {
//			// Clear all rows before selecting the right one.
//			imgarray = document.getElementsByTagName('img');
//			imgCellsCnt = imgarray.length;
//			for (g=0; g<imgCellsCnt; g++) {
//				var imgid = imgarray[g].getAttribute('id');
//				if (imgid == null) continue;
//				if (imgid.substr(0,1)=="I") {
//				imgarray[g].src = selectedimg.src;
//				}
//			}
//			RowElement2.src = selectimg.src;
//			MarkRow(StrRowNum, 'down', false, false, false);
//			} else {
//			imgarray = document.getElementsByTagName('img');
//			imgCellsCnt = imgarray.length;
//			for (g=0; g<imgCellsCnt; g++) {
//				var imgid = imgarray[g].getAttribute('id');
//				if (imgid == null) continue;
//				if (imgid.substr(0,1)=="I") {
//				imgarray[g].src = selectedimg.src;
//				}
//			}
//			RowElement2.src = selectedimg.src;
//			MarkRow(StrRowNum, 'down', false, false, false);
//		}
//	}
//}

function MultiSelectRow(imgrow) {
	if (document.images) {
		RowElement2=document.getElementById(imgrow);
		var StrRowNum = imgrow.substr(1);
		var giflength = RowElement2.src.length;
		var gifname = RowElement2.src.substr(giflength-10,6);
		if (gifname == 'select') {
			RowElement2.src = selectimg.src;
			MarkRow(StrRowNum, 'down', true, false, false);
			} else {
			RowElement2.src = selectedimg.src;
			MarkRow(StrRowNum, 'down', true, false, false);
		}
	}
}

//function MultiSelectRow(imgrow) {
//	if (document.images) {
//		RowArray=document.getElementsByName('selection');
//		var rowCellsCnt = RowArray.length;
//		for (c = 0; c < rowCellsCnt; c++) {
//			curid = RowArray[c].getAttribute('Id');
			// See if the row ID is in the array
//			if (curid == imgrow) {
//				var StrRowNum = imgrow.substr(1);
//				giflength = RowArray[c].src.length;
//				gifname = RowArray[c].src.substr(giflength-10,6);
//				if (gifname == 'select') {
//					RowArray[c].src = selectimg.src;
//					MarkRow(StrRowNum, 'down', true, false, false);
//					} else {
//					RowArray[c].src = selectedimg.src;
//					MarkRow(StrRowNum, 'down', true, false, false);
//				}
//				break;
//			}
//		}
//	}
//}

function ClearAllOtherRows(imgrow) {
	if (document.images) {
		RowArray=document.getElementsByName('selection');
		var rowCellsCnt = RowArray.length;
		for (e = 0; e < rowCellsCnt; e++) {
			curid = RowArray[e].getAttribute('Id');
			// See if the row ID is in the array
			if (curid == imgrow) {
				var StrRowNum = imgrow.substr(1);
				giflength = RowArray[e].src.length;
				gifname = RowArray[e].src.substr(giflength-10,6);
				if (gifname == 'select') {
					for (d = 0; d < rowCellsCnt; d++) {
						if (d != e) {
							RowArray[d].src = selectedimg.src;
							ClearAllRows();
						}
						break;
					}
				}
			}
		}
	}
}


function BuildPage(details) {
  details.replace(/\&/,"&amp;");
  location = details;
}
