// init script for SSWSC site

function prologis_init()  {
	// called by body.onLoad of page - encapsulates multiple event calls
	startList();		// make css dropdowns IE functional
	simplePreload();	// preload any necessary images
}

function addEvent(obj, evType, fn){
	//function adds an event to an object
	//obj is pointer to the object being modified
	//evType should be an eventtype; for example:  click,change,mouseover (the "on" prefix is appended below)
	//fn is the function handler being assigned to the event; should be a "function object" - in other words the name of a function being assigned
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}

function dumpProps(obj, parent) {
	/*
	thanks to http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BF8004D72D6
	
	As you probably already know, JavaScript can be difficult to debug. One thing that has helped us out many times is this function to show all the properties of an object. This function recursively takes properties that are objects themselves and shows their properties. To see how it works, put a function call of "dumpProps(document)" in the "onclick" event of a button and you'll see everything about the document. That's what this button does:
	This function provides a couple of advantages for debugging. First, it allows you to verify what object you are working with during your script. It also allows you to verify the properties of that object (maybe you can't remember the property name or don't know how to spell it). It is also good if you are working with a heirarchy of properties. For example, if you think it might be document.body.referer for the property you want, but aren't sure, you can show all the document properties, recursively, to find out which one it is. (it's actually document.referer).
	This code uses confirm prompts so you don't have to go all the way through all the properties once you find the one you want. Clicking cancel will stop the processing. (Note that if you click cancel while the function has been recursing, it will stop that level of recursion and you can continue on or click cancel on the parent level).
	
	note:  above confirm prompt usage modified - instead save message to one long alert box; works in most cases but not for large objects
	*/
   var msg = '';
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
	  if (typeof obj[i] != "function" 
	  	&& typeof obj[i] != "object" 
		&& i != 'innerHTML'
		&& i != 'textContent')  {	  
	      if (parent) { msg = msg + parent + "." + i + " = " + obj[i] + "\n" ; } else { msg = msg + i + " = " + obj[i] + "\n" ; }
		}
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
	}
	alert(msg);
}

function popWindow(url, window_name, winheight, winwidth, winleft, wintop, resizeopt, scrollbaropt, toolbaropt, statusbaropt)  {
	// popup window function
	/* 
	defaults windows position  to left : 100; top : 100; width : 100; height : 100; resize = yes, scrollbar = yes, toolbar = yes, statusbar = yes
	if winleft/wintop/winwidth/winheight/resizeopt/scrollbaropt/toolbaropt/statusbaropt params _not_ passed
	*/
	if (winleft == '')  winleft = 100;
	if (wintop == '') wintop = 100;
	if (winwidth == '') winwidth = 100;
	if (winheight == '') winheight = 100;
	if (resizeopt == '') resizeopt = 'yes';
	if (scrollbaropt == '') scrollbaropt = 'yes';
	if (toolbaropt == '') toolbaropt = 'yes';
	if (statusbaropt == '') statusbaropt = 'yes';
	var newwindow=window.open(url,window_name,'height=' + winheight + ',width=' + winwidth + ',left=' + winleft + ',top=' + wintop + ',resizable=' + resizeopt + ',scrollbars=' + scrollbaropt + ',toolbar=' + toolbaropt + ',status=' + statusbaropt);
}

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

addEvent(window, 'load', function() {
    var input;
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; (input = inputs[i]); i++) {
		if (inputs[i].type == 'text')  {
			addEvent(input, 'focus', oninputfocus);
			addEvent(input, 'blur', oninputblur);
		}
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i = 0; (textarea = textareas[i]); i++) {
        addEvent(textarea, 'focus', oninputfocus);
        addEvent(textarea, 'blur', oninputblur);
    }
});

function getLabelForId(id) {
    var label, labels = document.getElementsByTagName('label');
    for (var i = 0; (label = labels[i]); i++) {
        if (label.htmlFor == id) {
            return label;
        }
    }
    return false;
}

function oninputfocus(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.style.borderColor='#a7b9e4';
}

function oninputblur(e) {
    /* Cookie-cutter code to find the source of the event */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return;
    }
    /* End cookie-cutter code */
    source.style.borderColor='#286a51';
}

addEvent(window, 'load', function() {
    var input;
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; (input = inputs[i]); i++) {
		if (inputs[i].type == 'text')  {
			addEvent(input, 'focus', oninputfocus);
			addEvent(input, 'blur', oninputblur);
		}
    }
    var textareas = document.getElementsByTagName('textarea');
    for (var i = 0; (textarea = textareas[i]); i++) {
        addEvent(textarea, 'focus', oninputfocus);
        addEvent(textarea, 'blur', oninputblur);
    }
});
