//place functions here that need to be fired on a page load
function bccInit() {
	//set page font-size if it's been set
	if (readCookie('textsizestyle')) {
		fsize(readCookie('textsizestyle'),'%','main');
	}
}
// POP UP script for transaction windows ONLY (use script below for others)
// Opens a window and loads the supplied URL into this new window.
var pop;
function transOpenWindow(url) {
  if (pop == null || pop.closed) {
    var winWidth = null; 
    var winHeight = null; 
    var windowURL = url;
    var windowName = 'popWindow';
    var windowfeatures = 'width='+winWidth+',height='+winHeight+',top=0,left=0,screenX=0,screenY=0,directories=0,location=0,scrollbars=1,menubar=0,status=1,toolbar=0,resizable=1';
    pop = window.open(windowURL, windowName, windowfeatures);
    pop.focus();
  } else {
    pop.focus();
  }  
}

//Script for the kerbsite collection dropdown box.
function showddListItemValue(){
	document.getElementById("ddListItemValue").innerHTML = document.getElementById("ddListItem").value; 
}

// POP UP script for ALL OTHERS (this is the default script to use)
// Opens a window and loads the supplied URL into this new window.
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Scripts to check that something has been entered in the search field
// Purpose: Validation for Search field
function validateSearch() {
	// this is for the search input box on the search page
	if (document.getElementById("searchFor").value == "") {
		alert("Please enter a search term.");
		document.getElementById("searchFor").focus();
		return false;
	} else {
		return true;
	}
}
function validateTopSearch() {
	// this is for the search input box on every page
	if (document.getElementById("topSearchFor").value == "") {
		alert("Please enter a search term.");
		document.getElementById("topSearchFor").focus();
		return false;
	} else {
		return true;
	}
}

// add a function to fire on the body onload event
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//text resizing function
function fsize(size,unit,id){
	var vfontsize = document.getElementById(id);
	if(vfontsize){
		vfontsize.style.fontSize = size + unit;
		createCookie("textsizestyle", size, 365);
	}
}

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;
}
