/*
globals.js

*/
var css_browser_selector = function() {
		 var 
		 		 ua=navigator.userAgent.toLowerCase(),
		 		 is=function(t){ return ua.indexOf(t) != -1; },
		 		 h=document.getElementsByTagName('html')[0],
		 		 b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		 		 os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
		 var c=b+os+' js';
		 h.className += h.className?' '+c:c;
}();

// Helper functions
function openDBRelativeURL( url, target ) {

  //Check we have a target window;
  target = (target == null ) ? window : target;

  //Work out the path of the database;
  var p = location.pathname;
  path = p.slice( 1, p.toLowerCase().lastIndexOf('.nsf')+4) + '/';
  target.location.href = "/" + path + url;
}
function getDBRelativeURL(url) {
  //Work out the path of the database;
  var p = location.pathname;
  path = p.slice( 1, p.toLowerCase().lastIndexOf('.nsf')+4) + '/';
  return "/" + path + url;  
}

function createDoc(url) {
  openDBRelativeURL(url);
}

// Categorisation
function addToList() {
  var boxes = document.forms[0].Tags;
  var theOptions = new Array ("Select...");

  for (var i=0; i<boxes.length; i++) { 
    var box = boxes[i];
    if (box.checked) {
      theOptions.push(box.value);
    } 
  }
  var master = document.getElementById("MainTag");
  if(master.type!='hidden') {
    j = master.options.length;
    if (j >0) {
      master.options.length -= j;
      master.options[j] = null;
    }
    count = 0;
    for (e=0; e<theOptions.length; e++) {
      master.options[count] = new Option();
      master.options[count].text = theOptions[e];
      master.options[count].value = theOptions[e];
      count=count+1;
    }
  }

}

// JS version of @replacesubstring
function replacesubstring(sourceList,fromList,toList) { 
	for (var i=0; i<sourceList.length; i++) { 
		if (sourceList.substring(i,i+fromList.length) == fromList) { 
			sourceList = sourceList.substring(0,i)+toList+sourceList.substring(i+fromList.length,sourceList.length) 
		} 
	} 
	return sourceList 
} 
	 

// Extra Milonic code
function mm_changeItemProperty(menuName, itemName, codeRef, newValue, updateDisplay)
{
  menuName = menuName.toLowerCase();
  for (i=0; i<_mi.length; i++)
    if (_mi[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
  if (i == _mi.length) return;
  _mi[i][codeRef] = newValue;
  if (updateDisplay) BDMenu(_mi[i][0]);
}
function mm_GetItemProperty(menuName, itemName, codeRef) {
	try {
		menuName = menuName.toLowerCase();
		for (i=0; i<_mi.length; i++)
			if (_mi[i][1].replace(/\ \;/ig,' ') == itemName && _m[_mi[i][0]][1] == menuName) break;
	 		return _mi[i][codeRef];
	} catch(err) {}
}
// Search functions
var strSearchStartingText="";

function clearSearch(){
	if(document.getElementById('BDOsearchInput').value==strSearchStartingText){
		document.getElementById('BDOsearchInput').value='';
	}
}
function populatePreSearch(){
	if(document.getElementById('BDOsearchInput').value==''){
		document.getElementById('BDOsearchInput').value=strSearchStartingText;
	}
}

function doSearch(obj,event) {
	if(enterKeyDo(obj,event)==true) {
		if(document.getElementById('BDOsearchInput').value!=""){
			qs(document.getElementById('BDOsearchInput').value);
		}
	}
}
function clickSearchButton(){
		if(document.getElementById('BDOsearchInput').value!="" & document.getElementById('BDOsearchInput').value!=strSearchStartingText){
			qs(document.getElementById('BDOsearchInput').value);
		}
}

function enterKeyDo(myfield,e){
	var keyPressed;

	if(window.event){ //IE
		keyPressed = e.keyCode;
	}else if(e.which){ // Netscape/Firefox/Opera
		keyPressed = e.which;
	}

	if (keyPressed == 13){
		return true;
	}else{
		return false;
	}
} 
function qs(v) {
	//var v = document.getElementById("SearchString").value;
	var s = globalDb + "DominoSearchInt?searchview&query=("+v+")&searchorder=4&searchmax=1000";
	location.href = s;
}
function filterByName() {
	var v = document.getElementById("filter").value;
	location.href = location.pathname + "?openview&showdocs=" + v + "&start=1&count=20";
}
function doSubmit(f) {
	f.submit();
}
function doPrint() {
	newwin = window.open(location.pathname+"?opendocument&style=print_style_template");
	newwin.print();	
}



