//--- SPOTTER general java functions used across pages.

//------- HIGHLIGHTING ROWS --------
	function mouse_over_element(obj, newclass) {
		if( !newclass) {
			newclass = 'rowon' ;
		}
		if(obj.className!='rowselected' ) 
			obj.className=newclass;		
	}
	function mouse_out_element(obj, newclass) {
		if( !newclass) {
			newclass = 'rowoff' ;
		}
		if(obj.className!='rowselected' ) 
			obj.className=newclass;		
	}
	function select_element(obj, rowid, newclass, selectedclass) {
		if( !newclass) {
			newclass = 'rowoff' ;
		}
		if( !selectedclass ) {
			selectedclass = 'rowselected';
		}
		if(document.getElementById(rowid).style.display!="none") {
			obj.className=selectedclass;		
		} else if(obj.className!=selectedclass ) {
			obj.className=selectedclass;		
		} else {
			obj.className=newclass;
		}
	}
//--- END HIGHLIGHTING ROWS --------
		
//--- SWAP IMAGE SOURCES FOR ROLL OVER EFFECT 
	function new_img_source( obj, new_src ) {
		obj.src = new_src ;		
	}

//------- COOKIE MANAGEMENT ------------
//--- function createCookie(name,value,days) {
//---	pass name, value and number days till
//---	expires. If days is 0 then cookie is removed
//---	when browser is closed and -1 will remove
//---	cookie immediately.
	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 returnCookie(name) {
//---	pass the cookie name and return its value, if
//---	cookie doesn't exist return null.
	function returnCookie(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;
	}
//--- function removeCookie(name) {
//---	pass name of cookie to remove. Calls
//---	createCookie function to remove the 
//--- 	cookie.
	function removeCookie(name) {
		createCookie(name,"",-1);
	}	
//------- END COOKIE MANAGEMENT ------------

//--------- FILTER SETTINGS ------------
//--- get_cookie() found in SwitchContent.js, setup 
//---	to work with URL strings.
	function onload_set_filter_display() {
		do_onload()
		if( get_cookie(window.location.pathname) == 'filter_display' ) {
			expandcontent('filter_img', 'sub_pref', 'pref') 
			select_element( 'pref', 'sub_pref' )		
		}		
	}
	
	function set_filter_display() {	
		if( get_cookie(window.location.pathname) == 'filter_display' ) {
			createCookie(window.location.pathname,"test", memoryduration)
		} else {			
			createCookie(window.location.pathname,"filter_display", memoryduration)		
		}
	}	
//--------- END FILTER SETTINGS ------------

//--------- WINDOW POPUP ---------------
//--- general popup function that centers window that is
//---	scrollable, resizable, and has status bar.
	function pop_up_win( url, win_name, w, h ) {
		var my_win;
		wX = screen.width; 
		hX = screen.height; 		
		hpos = ((wX - w)/2) ;
		vpos = ((hX - h)/2) ;
			
		my_win = window.open(url, win_name,'width='+w+',height='+h+',top=' + vpos + ',left=' + hpos + ',scrollbars=yes,resizable=yes,status=yes,menubar=no,directories=no,toolbar=no,location=no');
		my_win.focus();	
	}
//--- second popup function that centers window that is
//---	scrollable, resizable, displays status bar, and toolbar.
	function pop_up_win2( url, win_name, w, h ) {
		var my_win;
		wX = screen.width; 
		hX = screen.height; 		
		hpos = ((wX - w)/2) ;
		vpos = ((hX - h)/2) ;
			
		my_win = window.open(url, win_name,'width='+w+',height='+h+',top=' + vpos + ',left=' + hpos + ',scrollbars=yes,resizable=yes,status=yes,menubar=no,directories=no,toolbar=yes,location=no');
		my_win.focus();	
	}
//--- popup google map, pass city/state location that 
//---	centers window that is scrollable, resizable, 
//---	and displays status bar. 
	function popmapwin(city, state){
		var my_win;
		var url;
		
		url = 'http://maps.google.com/?hl="en&amp;q='+city+',+'+state ;
		my_win = window.open(url,'mapWin','width=850,height=500,scrollbars=yes,resizable=yes,status=yes,menubar=no,directories=no,toolbar=no,location=no');
		my_win.focus();
	}
//--------- END WINDOW POPUP ---------------	
	
//--------- PRINT SELECTED LOADS ---------------	
	//--- pass an array of selected ids
	function print_selected( ) {
		var objCheckBoxes, 
		    countCheckBoxes,
			selected_ids = '' ;
		
		if(!document.forms['request']) {			
			return;
		}
		
		objCheckBoxes = document.forms['request'].elements['selected_loads'];
		if(!objCheckBoxes) {
			return;
		}
		
		countCheckBoxes = objCheckBoxes.length;
		if( countCheckBoxes > 0 ) {
			for(var i = 0; i < countCheckBoxes; i++) {
				if( objCheckBoxes[i].checked == true ) {
					if( selected_ids.length == 0 ) {
						selected_ids = objCheckBoxes[i].value ;	
					} else {
						selected_ids += ', '+objCheckBoxes[i].value ;
					}
				}
			}
			if(selected_ids.length > 0 ) {
				pop_up_win2( 'print_loads.php?selected_ids='+selected_ids, 'print_page', '700', '500' );				
			} else {
				alert( 'Please check the loads you wish to print.' ) ;
			}			
		}		
	}	
//--------- PRINT SELECTED IDS ---------------	

//--------- PAGE LOADING ------------
	//--- add to page:
	//---	document.write('<div id="loading" align="ceneter"><br><br><h1>Loading page<br>please wait...</h1><img src="/images/running_dog.gif" alt="Loading"><br></div>');	
	//--- Call in body tag: onload="page_loading();"
	function page_loading(){	
		if (document.getElementById){
			document.getElementById('loading').style.visibility='hidden';
		} else if (document.layers){ //NS4
			document.loading.visibility = 'hidden';
		} else { //IE4
			document.all.loading.style.visibility = 'hidden';
		}		
	}		
//--------- END PAGE LOADING ------------

//--------- FADE EFFECT -----------
// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

/*window.onload = function () 
	{
	Fat.fade_all();
	}*/
//------------- END FADE EFFECT --------------