function oddjob()
{
	this.debugon=false;
	this.debugWindowDiv = false;
	this.debugWindowName='debugw';
	
	this.followMouseOn = false;
	this.mousex = false;
	this.mousey = false;


	this.shout=function(blah)
	{ alert(blah);};
	
	this.setInnerHTML=function(elm,str) 
	{ 
		if(this.getObject(elm)) 
		{  this.getObject(elm).innerHTML=str;  }; 
	};
	
	this.appendInnerHTML=function(elm,str) 
	{ 
		if(this.getObject(elm)) 
		{  this.getObject(elm).innerHTML=this.getObject(elm).innerHTML+str;  }; 
	};
	
	this.appendInnerHTMLFront=function(elm,str) 
	{ 
		if(this.getObject(elm)) 
		{  this.getObject(elm).innerHTML= str + this.getObject(elm).innerHTML;  }; 
	};
	
	
	
this.addLoadEvent = function(func) 
{
	 var oldonload = window.onload;
	 if (typeof window.onload != 'function') 
	 {
	 	window.onload = func;
	}
	else
	{
		window.onload = function() 
		{
			 oldonload();
			 func();
		 }
	 }
}
	
	

	
//string fun
this.trim = function(str) 
{
	return (this.isString(str)? str.replace(/^\s+|\s+$/g,"") : str );
}

this.ltrim = function(str) 
{
	return (this.isString(str)? str.replace(/^\s+/,"") : str );
}

this.rtrim = function(str) 
{
	return (this.isString(str)? str.replace(/\s+$/,"") : str );
}


this.randomString = function() 
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

this.randomNumber = function()
{
	return this.rand(1,65536*2*2*2);
}

this.rand = function(a,b)
{
	var lo,hi,ret;
	if(a>b)
	{
		lo=b; hi=a;
	}
	else if(a<b)
	{
		lo=a; hi=b;
	}
	else {return a;};
	
	ret = hi-lo;
	ret = Math.floor(Math.random()*ret);
	ret += lo;
	
	if(ret <= hi && ret >= lo)
	{	return ret;	}
	else { alert('rand() function looks to be broken'); }
};

// OBJECT

	
	
	this.getObject=function(elmID) 
	{
	
	    if(!this.isString(elmID)) {return elmID;}
	
	    if(document.getElementById) {elmID = document.getElementById(elmID);}
	    else if(document.all) {elmID = document.all[elmID];}
	    else if(document.forms) 
	    {
		if(document.forms[elmID]) {elmID = document.forms[elmID];}
		else 
		{
		    for(var i=0; i<document.forms.length; i++) 
		    {
			if(document.forms[i][elmID]) 
			{
			    elmID = document.forms[i][elmID];
			    break;
			}
		    }
		}
	    }
	    else {elmID = null;}
	
	    return elmID;
	};
	
	
	this.getElementsByClass = function(searchClass,node,tag) 
	{
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
		for (i = 0, j = 0; i < elsLen; i++) 
		{
			if ( pattern.test(els[i].className) ) 
			{
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}
	
	//VALIDATING
	this.isDefined=function(x)
	{
		return typeof(x)!="undefined";
	};
	
	this.isUndefined=function(x)
	{
		return !this.isDefined(x);
	};
	
	this.isNull=function(x)
	{
		return typeof(x)=="object"&&!x;
	};
	
	this.isUndefOrNull=function (x) 
	{ 
		return this.isUndefined() || this.isNull();
	};
	
	this.isFunction=function(x)
	{
		return typeof(x)=="function";
	};
	
	this.isObject=function(x)
	{
		return (x&&typeof(x)=="object")||this.isFunction(x);
	};
	
	this.isEmpty=function(x)
	{
		return (!this.isDefined(x)||this.isNumeric(x))?false:(x==="");
	};
	
	this.isEmail=function(x)
	{
		return this.isDefined(x)?
			(/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i).test(x):
			false;
	};
	
	this.isArray=function(x)
	{ 
		return this.isObject(x)&&x.constructor==Array;
	};
	
	
	this.isInteger=function(x)
	{
		if(!this.isDefined(x))
		{
			return false;
		}
	
		x=(""+x).replace(/\.0*$/g,"");
	
		var intNumber=parseInt(x,10);
	
		if(!isNaN(intNumber)&&(x=x.remove(/^0*/))==="")
		{
			x=0;
		}
	
		intNumber=parseInt(x,10);
	
		if((!isNaN(intNumber))&&((""+intNumber)==x))
		{
			return true;
		}
	
		return false;
	};
	
	this.isFloat=function(x)
	{
		if(!this.isDefined(x))
		{
			return false;
		}
	
		x=(""+x).replace(/,/g,".");
	
		return x!==""&&!isNaN(x);
	};
	
	this.isNumeric=function(x)
	{
		return this.isFloat(x);
	};
	
	this.isNumber=function(x)
	{
		return this.isFloat(x);
	};
	
	this.isString=function(x)
	{
		if(!this.isDefined(x))
		{
			return false;
		}
	
		return typeof(x)=="string";
	};

	//test function	
	this.whatType = function(obj)
	{
		var a = this.getObject(obj);
		if(this.isString(obj)){this.shout('isString');};
		if(this.isNumeric(obj)){this.shout('isNumeric');};
		if(this.isFloat(obj)){this.shout('isFloat');};
		if(this.isInteger(obj)){this.shout('isInteger');};
		if(this.isArray(obj)){this.shout('isArray');};
		if(this.isEmail(obj)){this.shout('isEmail');};
		if(this.isEmpty(obj)){this.shout('isEmpty');};
		if(this.isObject(obj)){this.shout('isObject');};
		if(this.isFunction(obj)){this.shout('isFunction');};
		if(this.isUndefOrNull(obj)){this.shout('isUndefOrNull   TRUSTWORTHY?');};  // bad fxn
		if(this.isNull(obj)){this.shout('isNull');};
		if(this.isUndefined(obj)){this.shout('isUndefined');};
		if(this.isDefined(obj)){this.shout('isDefined');};
	};
	
	this.in_array =function (val,array)
	{
		for(var i in array){ if(array[i]==val) return true;}
		return false;
	};
	
	
	this.base2base = function(n, b1, b2)
	{	return parseInt(String(n), b1).toString(b2); }
	
	this.bin2oct = function(n) 
	{ return this.base2base(n,  2,  8); }
	
	this.bin2dec = function(n) 
	{ return this.base2base(n,  2, 10); }
	
	this.bin2hex = function(n)
	{ return this.base2base(n,  2, 16); }
	
	this.oct2bin = function(n)
	{ return this.base2base(n,  8,  2); }
	
	this.oct2dec = function(n)
	{ return this.base2base(n,  8, 10); }
	
	this.oct2hex = function(n)
	{ return this.base2base(n,  8, 16); }
	
	this.dec2bin = function(n)
	{ return this.base2base(n, 10,  2); }
	
	this.dec2oct = function(n)
	{ return this.base2base(n, 10,  8); }
	
	this.dec2hex = function(n)
	{ return this.base2base(n, 10, 16); }
	
	this.hex2bin = function(n)
	
	{ return this.base2base(n, 16,  2); }
	this.hex2oct = function(n)
	
	{ return this.base2base(n, 16,  8); }
	
	this.hex2dec = function(n) 
	{ return this.base2base(n, 16, 10); }
	
	
	this.colorhex2rgb = function(hex) 
	{
		var i = hex.length / 3;
		var r = hex.substr(0*i,i);
		var g = hex.substr(1*i,i);
		var b = hex.substr(2*i,i);
		
		if (r.length == 1) r = r + r;
		if (g.length == 1) g = g + g;
		if (b.length == 1) b = b + b;
		
		return 'rgb(' + [hex2dec(r),hex2dec(g),hex2dec(b)].join(',') + ')';
	}
	
	this.rgb2hex = 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;
	}
	
	//POSITIONING
	this.getPosition=function(obj)
	{
		var o = this.getObject(obj);
		var left = 0;
		var top = 0;
		var ret = new Object;
	
		while (o.offsetParent)
		{
			left += o.offsetLeft;
			top += o.offsetTop;
			o = o.offsetParent;
		}

		left += o.offsetLeft;
		top += o.offsetTop;
		
		ret.left=left;
		ret.top=top;
		var sr=(this.isDefined(o.style.width) ? o.style.width : o.width);
		var sb=(this.isDefined(o.style.height) ? o.style.height : o.height);
		ret.right = left + sr;
		ret.bottom = top + sb;
	
		return ret;
	};
	
	
	this.makePosition = function(x,y)
	{
		//creates an object that get|setPosition likes
		obj = new Object;
		obj.left=x;
		obj.top=y;
		return obj;
	}
	
	this.setPosition = function(elm,posobj)
	{
		var e = this.getObject(elm);
		if(this.isDefined(e.style))
		{
			e.style.position='absolute';
			e.style.top =posobj.top;
			e.style.left=posobj.left;
		}
		
		else
		{
			return false;
			//this.debugWindow();
			//this.setDebugMsg('you are trying to set something setPosition cant find_ '+elm);
		}
		
	}
	
	
	
	this.splitQueryString = function()
	{
		var strURL = document.location.search;
		var strQuery=strURL.match(/^\??(.*)$/)[1],
			tokens=strQuery.split("&"),
			len=tokens.length,
			i=0,
			parts=null,
			result=[];
	
		for(i=0;i<len;i++)
		{
			parts=tokens[i].split("=");
			result[parts[0]]=parts[1];
		}
	
		return result;
	};
	
		
	
	//collection of random tag attribute names, in case one forgets
	//dont call this, should exist as oddjob.common
	this.getcommon=function()
	{
		var a;
		var c=new Object();
		var tagAttribs=new Object();
		var formAttribs = new Array();
		
		//tag attributes
		a = new Object();
		a.type="text/javascript";
		a.language="javascript";
		tagAttribs.script=a;
		
		a = new Object();
		a.type="text/css";
		a.rel="stylesheet";
		tagAttribs.stylesheet=a;

		a = new Object();
		a.href="#";
		a.target="_self";
		tagAttribs.a=a;		
		c.tagAttribs=tagAttribs;
		
		c.path = new Object();
		c.path.selfurl=document.location;
		c.path.testurl='http://127.0.0.1/common/js/test.js';
		
		//form attribs
		a = ['name' , 'id', 'type', 'value','defaultValue' ,'cols','rows','qid','qfmt','checked','disabled','selected','ojid','background','className','link','rel','language','href','target','form'];
		c.formAttribs=a;	
		
		
		return c;
	};
	
	
	this.common=this.getcommon();
	
	
	this.selectedValue=function(obj)
	{
		var a = this.getObject(obj);
		return a.options[a.selectedIndex].value;
	}
	

	this.debugWindow=function()
	{
		if(this.debugon==false)
		{
			var elm = document.createElement('div'); //element type
			elm.setAttribute('id',this.debugWindowName);
			elm.style.padding="2px";
			elm.style.textAlign="left";
			elm.style.border="1px solid #000";
			elm.style.backgroundColor="#ABCDEF";

//			var elm2 = document.createElement('div'); //element type
//			elm2.setAttribute('id',this.debugWindowName);
//			elm.innerHTML='<a href="javascript:oddjob.debugWindowClose();">x</a> close<br />'+elm2;

			this.firstTag('div').appendChild(elm);
			this.setPosition(this.debugWindowName,this.makePosition(500,30));

			this.setInnerHTML(this.debugWindowName,'.');
			
			this.debugWindowDiv=this.getObject(this.debugWindowName);
			this.debugon=true;
			
		}
	}
	
	this.setDebugMsg = function(msg)
	{
		if(this.debugon==true)
		{
			this.appendInnerHTML(this.debugWindowName,msg+"<br />\n");
		}
	}


	this.debugWindowClose=function()
	{	
		this.debugon=false;
		if(this.isDefined(this.debugWindowDiv))
		{
			var o = this.debugWindowDiv.parentNode;
			o.removeChild(this.debugWindowDiv);
		}
	}


	
	
	this.firstTag=function(type)
	{
		var a = document.getElementsByTagName(type);
		return a[0];
	}
	
	
	this.dump = function(arr,level) 
	{
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "&mdash;&mdash;&mdash;";
		
		if(typeof(arr) == 'object') 
		{ //Array/Hashes/Objects 
			for(var item in arr) 
			{
				var value = arr[item];
				
				if(typeof(value) == 'object') 
				{ //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...<br />\n";
					dumped_text += this.dump(value,level+1);
				}
				else 
				{
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"<br />\n";
				}
			}
		} 
		else 
		{
			//Stings/Chars/Numbers etc.
			dumped_text = "=>"+escape(arr)+" ("+typeof(arr)+")";
		}
		eval ('var var_name = \''+arr+'\';');
		
		
			return var_name+" "+typeof(arr)+"\n"+dumped_text;
	}



	this.changeImgSize = function(objectId,newWidth,newHeight) 
	{
		theImg = this.getObject(objectId);
		oldWidth = theImg.width;
		oldHeight = theImg.height;
		if(newWidth>0)
		{
			theImg.width = newWidth;
		} 
		if(newHeight>0)
		{
			theImg.height = newHeight;
		} 
	}






// SCREEN STUFF

	this.dumpScreenRes = function()
	{
		this.debugWindow();
		this.setDebugMsg(this.dump(screen));
	}

	this.getPageScroll = function()
	{
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body ;
		
		var pos = new Object;
		pos.top = document.all? iebody.scrollLeft : pageXOffset;
		pos.left = document.all? iebody.scrollTop : pageYOffset;

		return pos;
	}

	

	this.followMouseStop = function()
	{
		this.followMouseOn=false;
		document.onmousemove=false;
		document.onclick=false;
		this.setDebugMsg(' follow stopped');
	}


	// needs to borrow your instance of oddjob , 'this' doesnt work 
	this.followMouse = function(odd)
	{
		var oddobject = this.getObject(odd);
		oddobject.followMouseOn=true;

		//oddobject.debugWindow();

		document.onmousemove = function(e) // don't know how, but e is the event
		{
			var pos = oddobject.getMousePosition(e); 
			oddobject.mousex=pos.left; 
			oddobject.mousey=pos.top;
	
			//oddobject.setdebugMsg(oddobject.mousex+', '+oddobject.mousey + ' ' + oddobject.randomString());	
		
		}
	}



	this.getMousePosition = function(e) 
	{
		//quirksmode way of positioning an event
			if (!e) var e = window.event; 
			var posx = 0;
			var posy = 0;


			if (e.pageX || e.pageY) 	
			{
				posx = e.pageX;
				posy = e.pageY;
			}
			
			else if (e.clientX || e.clientY) 	
			{
				posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
			}

			return { "left":posx , "top":posy};


	}



	this.formElements = new Object();
	
	this.inspectForm = function(form)
	{
		var f = this.getObject(this.getObject(eval('document.'+form)));
		var e,t;
		
		for(i=0;i<f.elements.length;i++)
		{
			if(this.isDefined(f.elements[i].type))
			{
				e = f.elements[i];	
				this.setDebugMsg(e.type +'&mdash;'+ e.name + '&mdash;'+e.value);
			}
		}
	}

	this.loadScript = function(url)
	{
	   var e = document.createElement("script");
	   e.src = url;
	   e.type="text/javascript";
	   document.getElementsByTagName("head")[0].appendChild(e);
	}

/** // doesn't really work
	this.loadStyle = function(url)
	{
		var e = document.createElement("link");
		e.href = url;
		e.rel = "stylesheet";
		e.type="text/css";
		e.media ="screen";
		document.getElementsByTagName("head")[0].appendChild(e);
	}
//*/


	this.toggleDisplay = function(obj) 
	{
		var el = this.getObject(obj);
		if ( el.style.display != 'none' ) 
		{
			el.style.display = 'none';
		}
		else 
		{
			el.style.display = '';
		}
	}
	
	this.toggleCheck = function(obj) 
	{
		this.getObject(obj).checked=!this.getObject(obj).checked;
	}
	
	this.getRadioValueByName = function(formName,radioName)
	 {
		var val = false;
		for( var i = 0; i < document.formName.radioName.length; i++ ) 
		{ 
			if( document.formName.radioName[i].checked == true ) 
			val = document.formName.radioName[i].value; 
		} 
		return val;
	}
		
	
	this.getCookie = function( name ) 
	{
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
		{
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ';', len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}
	
	this.setCookie = function( name, value, expires, path, domain, secure ) 
	{
		var today = new Date();
		today.setTime( today.getTime() );
		if ( expires ) 
		{
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name+'='+escape( value ) +
			( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
			( ( path ) ? ';path=' + path : '' ) +
			( ( domain ) ? ';domain=' + domain : '' ) +
			( ( secure ) ? ';secure' : '' );
	}
	
	this.deleteCookie = function( name, path, domain ) 
	{
		if ( getCookie( name ) ) document.cookie = name + '=' +
				( ( path ) ? ';path=' + path : '') +
				( ( domain ) ? ';domain=' + domain : '' ) +
				';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}
	
	
	
	this.isGreater = function(apple,orange)
	{
		if(apple > orange)
			{return true;}
		else {return false;}
	}
	
	this.isLesser = function(apple,orange)
	{
		if(apple < orange)
			{return true;}
		else {return false;}
	}
	
	
	this.resizeTextArea = function(txtar,cols,rows)
	{
		
		var nc,nr,txt,again;
		var go = false;
		var timeinc=10;
		txt=this.getObject(txtar);
		
			
		if ( 	this.isNumber(cols)  && this.isNumber(txt.cols)  && cols!=txt.cols  )
		{
			if(this.isGreater(txt.cols,cols))
			{
				for(i=1;i<=(txt.cols-cols);i++)
				{
					setTimeout('document.getElementById("'+txtar+'").cols='+(txt.cols-i)+';',(timeinc*i));
				}
				
			}
			else
			{
				for(i=1;i<=(cols-txt.cols);i++)
				{
					setTimeout('document.getElementById("'+txtar+'").cols='+(txt.cols+i)+';',(timeinc*i));
				}
			}
		}
			
		if ( 	this.isNumber(rows)  && this.isNumber(txt.rows)  && rows!=txt.rows ) 
		{
			if(this.isGreater(txt.rows,rows))
			{
				for(i=1;i<(txt.rows-rows);i++)
				{
					setTimeout('document.getElementById("'+txtar+'").rows='+(txt.rows-i)+';',(timeinc*i));
				}
				
			}
			else
			{
				for(i=1;i<(rows-txt.rows);i++)
				{
					setTimeout('document.getElementById("'+txtar+'").rows='+(txt.rows+i)+';',(timeinc*i));
				}
			}
		}
	}
	
}


function yo(){alert('oddjob: yo');};

