/*	GLOBAL JAVASCRIPT FUNCTIONS */



/*	STATUS BAR INFO - Status bar message, for links. */
function info(msg){ window.status=msg?msg:''; return true }



function noRightClick(url){ document.onmousedown=function(e){ e=e?e.which:event.button; if(e==2||e==3){ if(url)window.open(url); return 0 }} }


// Bug fix for IE7 object patch, prevents "click to activate and use this control"
// error message in embedded flash and player objects.
// Objects must be created BY Javascript for this to work. Hard coded object tags are not be affected by it.
// It looks meaningless but it works.

function takeObjectOwnership(nm,o,i){
	if(nm) { o=document.getElementsByName(nm); if(o[0]) o[0].outerHTML=o[0].outerHTML; return false }
	else { o=document.getElementsByTagName('object'); i=o.length-1; if(i>-1) do o[i].outerHTML=o[i].outerHTML; while(i--); return false }
}



/*	POPUP WINDOWS
	Will load full screen if width and height are not defined.
	Will automatically center itself on the screen if x and y are not defined or less than 0.
	popUp() - All parameters are optional. Scrollbars default to auto, window is resizable.
	popUpParams() - scrollbars and resize can be defined with this one.
*/

function popUp(url,windowName,w,h,x,y){ return popUpAllParams(url,windowName,w,h,x,y,0,1,2) }
function popUpParams(url,nm,w,h,m,r,s,st){ return popUpAllParams(url,nm,w,h,-1,-1,m,r,s) } // (m)enubars, (r)esizable, (s)crollbars
function popUpMatching(url,nm){ // matches launching window's size and settings.
	eval((nm!='void'?nm+'=':'')+'window.open(\''+url+'\',\''+nm+'\')');
	return false;
}
function popUpAllParams(url,nm,w,h,x,y,m,r,s,st){
	nm=nm?nm:'popup'; url=url?url:this.location;
	with(window.screen){var W=availWidth-12;var H=availHeight-32}
	with(window){var X=document.all?screenLeft:screenX;var Y=document.all?screenTop:screenY}
	if(document.body)with(document.body){var cW=clientWidth;var cH=clientHeight}else{ var cW=0; var cH=0 }
	w=w?w:W; h=h?h:H; m=m==undefined?0:m; r=r==undefined?1:r; s=s==undefined?'auto':s; st=st==undefined?0:st;
	x=x==undefined||x==-1?w<W?parseInt((X+cW/2)-w/2):0:x; y=y==undefined||y==-1?h<H?parseInt((Y+cH/2)-h/2):0:y;
	eval((nm!='void'?nm+'=':'')+'window.open(\''+url+'\',\''+nm+'\',\'menubar='+m+',resizable='+r+',status='+st
	+',scrollbars='+s+',width='+w+',height='+h+',left='+x+',top='+y+'\')');
	return false;
}

// Sized for the Media Modeler Previews
function prevMediaModeler(lnk){ popUp(lnk,'previews',504,452); return false }

// Sized for the Flash Previews
function prevWin(lnk){ return popUpParams(lnk,'previews',700,450,0,1,0) }

// This one may not be is use anymore
function previewWin(lnk){ return popUpParams(lnk,'previews',550,400,0,1,0) }


/* SHOWDIV() - POPUPDIVOLD() - Simple CSS control for hiding and showing a div layer. */
function showDiv(divId, onState){
	with(document) var css=getElementById?getElementById(divId).style:all?all[divId].style:layers?layers[divId]:null;
	if(!css) return; // Bail out gracefully now if the style object does not exist.
	else css.visibility = onState?'visible':'hidden';
}


/*	POPUPDIV() - Advanced CSS control for hiding and showing a draggable div layer.

USAGE:
To make a non-draggable layer - the popUpChk image is optional:
dragDiv = new popUpDiv('cvvDiv', 'cvvHdr', 'cvvChk', 'cvvBody');
To make a draggable layer:
dragDiv = new popUpDiv('cvvDiv', 'cvvHdr', 'cvvChk', 'cvvBody', 1);


GLOBAL POPUP DIV CSS
.popDiv, .popUpHdr, .popUpBody, .popUpHdrBg { position:absolute; overflow:hidden }
.popUpBody, .popUpChk, .popUpHdrBg { background-color:#CCC }
.popUpHdr { color:#FFF; font-weight:bold; text-align:left; width:100%; padding:1 0 1 4; cursor:hand }
.popUpChk { position:relative; border:1px outset #999; left:2; float:right; z-index:1; margin:0 }
.popUpBody { color:#000; height:100%; width:100%; border:1px inset #CCC; top:15 }
.popDiv { border:2px outset #CCC }


TYPICAL POPUP DIV HTML - the id's here must match the object declaration.
<div class="popDiv" style="width:454; height:370; top:200; left:450; visibility:hidden" id="cvvDiv">
	<img src="images/popuphdr.gif" width="100%" height="15" border="0" class="popUpHdrBg">
	<div class="popUpHdr" id="cvvHdr">
		<img src="images/checkbox.gif" width="12" height="11" border="0" class="popUpChk" id="cvvChk">
		Credit Card Security Code
	</div>
	<div class="popupBody" id="cvvBody">
		<img src="images/bankcode1.gif" width="455" height="371" border="0">
	</div>
</div>

*/

function popUpDiv(divId, divHdrId, divChkBoxId, divBodyId, draggable, scrollable){
	with(this){
		this.obj = function(id){ with(document)return getElementById?getElementById(id):all?all[id]:null }
		this.moveWhat = obj(divId);
		if(!moveWhat) return;
		var scroll=!scrollable?'':'; overflow:scroll';
		this.chkBgOn='#AAA';
		this.div = null;
		ddEnabled = false;
		this.offset = [];
		this.hide = null;
		this.chk = obj(divChkBoxId);
		this.divHdrId = divHdrId;
		this.handle = obj(divHdrId);
		this.bdy = obj(divBodyId);
		bdy.style.height=parseInt(moveWhat.style.height)-(scrollable==2?19:2);
		this.sty = function(o){ return o.style?o.style:o }
		this.evt = function(e){ e=e?e:event; return [e.clientX,e.clientY] }
		this.canc = function(){ document.onmousemove=null }
		this.hide = function(){ with(this) sty(moveWhat).visibility='hidden' }
		this.show = function(){ with(this) sty(moveWhat).visibility='visible' }
		this.write = function(h){ with(this) bdy.innerHTML=h }
		this.moveTo = function(e){
			with(this){ with(moveWhat.style){ left=offset[2]+evt(e)[0]-offset[0]; top=offset[3]+evt(e)[1]-offset[1] } return false }
		}
		this.move = function(e){
			div = e?e.target:event.srcElement;
			if(div.id==divHdrId){
    			with(moveWhat.style) offset = [evt(e)[0], evt(e)[1], parseInt(left), parseInt(top)];
			    document.onmousemove=moveTo;
			}
		}

		// initialize the objects and functions here
		if(chk){
			this.chkOn = function(){ with(this) with(sty(chk)) { borderStyle='inset'; backgroundColor=chkBgOn } }
			this.chkOff = function(){ with(this)with(sty(chk)) { borderStyle='outset'; backgroundColor=chkBgOff } }
			this.chkBgOff=sty(chk).backgroundColor;
			chk.onmousedown = this.hide;
			chk.onmouseover = this.chkOn;
			chk.onmouseout = this.chkOff;
		}
		if(draggable){
			document.onmousedown = this.move;
			document.onmouseup = this.canc;
		}
	}
}




/*	COOKIEOBJ()
	Sets and retrieves cookies for either simple single value cookies or key/value cookies.
	USAGE: var myCookie = new cookieObj('uservisits', 1, 'www.mydomain.com', '/ThisDirOnly');
	PARAMETERS: name is required, set hours to 0 for session cookies, domain is optional, path is optional
	METHODS: cookieObj.set(value,key), cookieObj.get(key), cookieObj.del()

	var myCookie = new cookieObj('uservisits', 1, 'mydomain.com'); 1 = expires in 1 hour, 0 = session cookie only
	myCookie.set('some value') 				sets a simple string value
	myCookie.get()					returns a simple string value
	myCookie.del()					deletes the cookie

	Or, if a named key is passed:
	myCookie.set(1,'visitCt')		sets a named key
	myCookie.get('visitCt')			returns a single named key value

*/

function cookieObj(name, hoursToExpire, domain, path){
	this.nm=name; this.hrs=hoursToExpire; this.dom=domain; this.path=path?path:'/'; this.u=unescape;
	this.set=function(v,k,s){with(this){s=v;if(k){h=hsh(val());h[k]=escape(v);s=str(h)};sav(s);return v}}
	this.get=function(k,s){with(this){s=val();h=hsh(s);return k?h[k]?unescape(h[k]):'':s}}
	this.del=function(){this.sav('',-1)}
	this.val=function(i,s){with(this){s=document.cookie.split(nm+'=');s=(s[1]?s[1]:'').split(';');return s[1]?s[0]:s}}
	this.str=function(h,s){s='';for(var i in h)if(i)s+=(s?'&':'')+i+'='+unescape(h[i]);return s}
	this.hsh=function(s,h){h=[];with(this)if(s){a=unescape(s).split('&');for(i=0;i< a.length;i++){s=a[i].split('=');if(s)h[s[0]]=unescape(s[1])}}return(h)}
	this.dat=function(hrs,x){x=new Date();x.setTime(x.getTime()+(isNaN(hrs)?0:hrs)*3600*1000);return x.toGMTString()}
	this.sav=function(v,h){with(this)document.cookie=nm+'='+v+(!hrs&&!h?'':'; expires='+dat(h?h:hrs))+(path?'; path='+path:'')+(dom?'; domain='+dom:'')}
}


function fixFeb(o){
	var m,d,y,s,e;
	with(o.form){
		m =  parseInt(bMo.options[bMo.selectedIndex].value);
		d =  parseInt(bDy.options[bDy.selectedIndex].value);
		y =  parseInt(bYr.options[bYr.selectedIndex].value);
		s = bMo[0].value==''?1:0;
		switch(m){
			case 2: {e=(y%4==0||isNaN(y)?29:28)+s; if(bDy.selectedIndex>e-1)bDy.options[e-1].selected=true; break }
			case 4,6,10,11: { e=30+s; break }
			default: e=31+s;
		}
		bDy.length=e;
		for(var x=s;x<e;x++) bDy.options[x].value = bDy.options[x].text = x;
	}
}

// Rollovers
function preLoad(a){a=arguments;if(document.images){var i=a.length-1;do{var x=new Image();x.src=a[i]}while(i--)}}
function imgSwap(i,s,tmp){i=i.name?i.name:i; with(document)if(images){tmp=s?images[i].src:s;images[i].src=s?s:imgSwapTmp;imgSwapTmp=tmp}}
imgSwapTmp=null;

function getRef(id){ with(document)return document.getElementById?getElementById(id):all?all[id]:null }
function getCss(lyr){ return lyr.style?lyr.style:lyr }
function setBg(id,clr,o){ o=getRef(id); if(o)getCss(o).backgroundColor=clr }
function divWrite(id,html,o){ o=getRef(id); if(o.innerHTML!='undefined')o.innerHTML=html }
function sortList(lst){ return lst.replace(/, /g, ',').split(',').sort().join(', ') }


