// Celsius Global Client Scripting

//Default Button Functions
function enterPressed(btn){
	if (document.all){
		if (event.keyCode == 13) {
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		} 
	}
}

//NRL.COM functions
var handle;
function popupWindow(url,width,height,scrollbars) {
	if(arguments.length < 4) { scrollbars = 'no'; }
	if(handle != null && !handle.closed) {handle.close();}
	handle = window.open(url,'popup','toolbar=no,location=no,directories=no,status=no,scrollbars='+scrollbars+',resizable=yes,width='+width+',height='+height);
	handle.focus();
}
var menulock = new Array(0,0);
function menuOn(i) { if(!document.layers) { menulock[i] = 1; showMenu(i); } }
function menuOver(i) { menulock[i] = 1; }
function menuOff(i) { menulock[i] = 0; setTimeout("hideMenu("+i+")",100); }
function showMenu(i) {
	if (document.all) { document.all["nrlMenu"+i].style.visibility = 'visible'; }
	else if (document.getElementById) { document.getElementById("nrlMenu"+i).style.visibility = 'visible'; }
}
function hideMenu(i) {
	if(!menulock[i]) {
		if (document.all) { document.all["nrlMenu"+i].style.visibility = 'hidden'; } 
		else if (document.getElementById) { document.getElementById("nrlMenu"+i).style.visibility = 'hidden'; }
	}
}
function setMenus() {
	if (document.all) {
		if(document.body.clientWidth < 779) { document.all.nrlMenu0.style.left = '137px'; document.all.nrlMenu1.style.left = '137px'; }
		else { document.all.nrlMenu0.style.left = Math.ceil((document.body.clientWidth)/2)-253 + 'px'; document.all.nrlMenu1.style.left = Math.ceil((document.body.clientWidth)/2)-253 + 'px'; }
	} else if (document.getElementById) {
		if(window.innerWidth < 779) { document.getElementById("nrlMenu0").style.left = 137; document.getElementById("nrlMenu1").style.left = 137; }
		else { document.getElementById("nrlMenu0").style.left = window.innerWidth/2-260; document.getElementById("nrlMenu1").style.left = window.innerWidth/2-260; }
	}
}
function openStore() {window.open('http://svc001.bne009i.server-web.com/catalogue/nrl','store','menubar=yes,toolbar=yes,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=640,height=420');}

//Window functions
function CS_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function clickshow(num)
{
	for (i=1;i<3;i++)
	{
		menu=eval("document.all.block"+i+".style");	
		if (num==i)
		{
			if (menu.display=="block")
			{
				menu.display="none"; 
			}
		else {
			menu.display="block"; 
			}
		}
	}
}

// Image functions
function CS_swapImgRestore() {
  var i,x,a=document.CS_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function CS_preloadImages() {
  var d=document; if(d.images){ if(!d.CS_p) d.CS_p=new Array();
    var i,j=d.CS_p.length,a=CS_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.CS_p[j]=new Image; d.CS_p[j++].src=a[i];}}
}

function CS_findObj(n, d) {
  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=CS_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function CS_swapImage() {
  var i,j=0,x,a=CS_swapImage.arguments; document.CS_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=CS_findObj(a[i]))!=null){document.CS_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//SelectBox Functions
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
}

function moveOptionUp(obj){
	var selectedCount=0;
	for(i=0;i<obj.options.length;i++){
		if(obj.options[i].selected){
			selectedCount++;
		}
	}
	if(selectedCount!=1){
		return;
	}
	var i = obj.selectedIndex;
	if(i == 0){
		return;
	}
	swapOptions(obj,i,i-1);
	obj.options[i-1].selected = true;
}

function moveOptionDown(obj){
	var selectedCount=0;
	for(i=0;i<obj.options.length;i++){
		if(obj.options[i].selected){
			selectedCount++;
		}
	}
	if(selectedCount != 1){
		return;
	}
	var i = obj.selectedIndex;
	if(i ==(obj.options.length-1)){
		return;
	}
	swapOptions(obj,i,i+1);
	obj.options[i+1].selected = true;
}

function changeColour(listboxname, rowname) { 
	var listbox = document.getElementById(listboxname);
	var iSelectedIndex = listbox.selectedIndex;
	var iSelectedValue = listbox.options[iSelectedIndex].value;
	var sColour = '';
	if(iSelectedValue==0){ 
		sColour = '#ffffff'; 
	} else {
		if(iSelectedValue==1) {
			sColour = '#B8DFB7';
		} else { 
			sColour = '#FFE27E'; 
		}
	}
	var tablerow = document.getElementById(rowname);
	tablerow.style.background = sColour;
}
