// ##########################################
// Common pages functions
// ##########################################



window.onerror= null;

isIE=		!!(window.attachEvent && !window.opera);
isOpera=	!!window.opera;
isWebKit=	navigator.userAgent.indexOf('AppleWebKit/') > -1;
isGecko=	navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1;

function ErrorHandler(msg, url, linenumber) {
  alert('Error message= '+msg+'\nURL= '+url+'\nLine Number= '+linenumber);
}


function confirmLink(theLink, theText) {
    is_confirmed = confirm(theText);
    if (is_confirmed) {
	  A= theLink.href.split('&#'); // save anchor link at end of url
	  if(A.length>1) theLink.href = A[0] + '&ProcConf=1&#' + A[1];
		else theLink.href += '&ProcConf=1';
    }
    return is_confirmed;
}

function confirmAndGoto(theText, address) {
    is_confirmed = confirm(theText);
    if (is_confirmed) {
	  A= address.split('&#'); // save anchor link at end of url
	  if(A.length>1) document.location.href= A[0] + '&ProcConf=1&#' + A[1];
		else document.location.href= address + '&ProcConf=1';
    }
}

function PromptSimpleValue(theLink, theText) {
	Txt= prompt(theText,"");
	if(Txt==null || Txt=="") return false;
	theLink.href += "&Prompted="+encodeURI(Txt);
	return true;
}

function LocaliseNumber(Num, ThSeparator) {
	Num= ""+Num; // conv to string
	Num.replace(/^\s+/, '');
	Num.replace(/\s+$/, '');
	for(x=9;x>0;x-=3)
	  if(Num.length>x) Num= Num.substring(0,Num.length-x)+ThSeparator+Num.substring(Num.length-x);
	return Num;
}

function jsSetLang(url, sel, isSEF){
  var w= url.length;
  var s= sel.options[sel.selectedIndex].value;
  if(s) url += (isSEF) ? '/' : 'lang=';
  if((!s)&&(!isSEF)&&(url.charAt(w-1)=='?')) url= url.substring(0,w-1);
  document.location.href= url + s;
}

function GoBack() {
  history.back();
  return false;
}

function PreviewInFrame(what) {
   window.open(what,"PreviewFrame","")
}

function FocusDivOnPos(DivId, Poz, Total, HtmlFocus) {
  var objDiv = document.getElementById(DivId);
  if (!objDiv) return;
  H1= objDiv.scrollHeight / Total;
  P= (Poz-2)*H1;
  if (P<0) P= 0;
  if (P>objDiv.scrollHeight) P= objDiv.scrollHeight;
  objDiv.scrollTop = P;
  if((!HtmlFocus)||(!Poz)) return;
  var Items= objDiv.getElementsByTagName("A");
  if((Poz>0)&&(Items[Poz-1])) Items[Poz-1].focus();
}

function swapNavigation(div) {  // for collapsing menu
  displayType = ( document.getElementById( div ).style.display == "none" ) ? "block" : "none";
  document.getElementById( div ).style.display = displayType;
  document.cookie = div + "=" + displayType;
}

function HtmlBlinker(Num) {
  if(HtmlBlinker_State==1) { newcolor= "#FF0000"; HtmlBlinker_State= 0; }
			else { newcolor= ""; HtmlBlinker_State= 1; }
  for(x=1;x<=Num;x++) {
    var obj = document.getElementById("HtmlBlinker"+x);
    if(obj) obj.style.color= newcolor;
  }
}

function PicPopup(url,w,h) {
  window.open(url,"flyout","resizable=no,scrollbars=no,margin=0,width="+w+",height="+h);
}

function ToggleDisplay(ObjId) {
  Obj= document.getElementById(ObjId);
  Obj.style.display= (Obj.style.display=="block") ? "none" : "block";
}

function ToggleDisplayByParam(ObjId, Param) {
  Obj= document.getElementById(ObjId);
  Obj.style.display= (Param) ? "block" : "none";
}

var TipTogglerState= 0;
function TipsToggleClick(TextShowTip,TextHideTip) {
  TipTogglerState++;
  if(TipTogglerState>1) TipTogglerState= 0;
  if(TipTogglerState) document.getElementById("aTipsToggler").innerHTML= TextHideTip;
    else document.getElementById("aTipsToggler").innerHTML= TextShowTip;
  document.getElementById("TipsTogglePanel").style.display= (TipTogglerState) ? "block" : "none";
}

function IsAnySubChecked(FormName,ElementsName) {
  List= eval('document.'+FormName+'.'+ElementsName);
  checked= false;
  for(x=0; x<List.length; x++) if(List[x].checked) checked= true;
  return checked;
}

function miSCSS_OnLoad() {
   if (document.all&&document.getElementById) {
  	var ParentLIS= document.getElementById("miSCSS");
  	var LIS= ParentLIS.getElementsByTagName("li");
    for (i=0; i<LIS.length; i++) {
  	  var Obj= LIS[i];
	  Obj.onmouseover=function() { this.className+=" over"; }
	  Obj.onmouseout=function() { this.className=this.className.replace(" over", ""); }
   }}
}


function ColorizeAlignAndResizeTable(Tbl, Aligns, Sizes, HoverClass, NormClass, Color1, Color2) {
    Tab= document.getElementById(Tbl);
    if(!Tab) return;
    Trs= Tab.getElementsByTagName("tr");
    for (r=0; r<Trs.length; r++) {
  	  Tds= Trs[r].getElementsByTagName("td");
      for (d=0; d<Tds.length; d++) {
      	if(Sizes) Tds[d].width= Sizes[d];
		Tds[d].align= Aligns[d];
		Tds[d].className= NormClass;
		color= (r % 2 == 0) ? Color1 : Color2;
		Tds[d].style.backgroundColor= color;
    		Tds[d].onmouseover=function() {
			Tds= this.parentNode.getElementsByTagName("td");
			for(d=0; d<Tds.length; d++) Tds[d].className= HoverClass;
		}
		Tds[d].onmouseout=function() {
			Tds= this.parentNode.getElementsByTagName("td");
			for(d=0; d<Tds.length; d++) Tds[d].className= NormClass;
		}
      }
    }
}

function ColorizeAndAlignTable2(Tbl, Aligns, HoverClass, NormClass, Color1, Color2) {
	ColorizeAlignAndResizeTable(Tbl, Aligns, null, HoverClass, NormClass, Color1, Color2);
}
function ColorizeAndAlignTable(Tbl, Aligns, HoverClass) {
	ColorizeAlignAndResizeTable(Tbl, Aligns, null, HoverClass, "", "#eeeeee", "#f6f6f6");
}


function WbtCorrection() {
  if(obj= document.getElementById("WbtDiv")) {
	obj.style.position= "absolute";
	obj.style.left= "-18px";
  }
}


function getWindowSize() { // problem: includes vertical scroll in FF, use prototype.viewport...
	if(typeof(window.innerWidth)=='number') {
		return { width: window.innerWidth, height: window.innerHeight};
	} else if(document.documentElement && (document.documentElement.clientWidth ||document.documentElement.clientHeight) ) {
		return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight};
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		return { width: document.body.clientWidth, height: document.body.clientHeight};
	}
	return {width:0,height:0};
}



// #####################
// ##  Click counter  ##
// #####################

var ClickCounterPhpLink= '';
function ClickCounterInit(PhpLink) {
  ClickCounterPhpLink= PhpLink; // use real path
  var aTags= document.getElementsByTagName('a');
  for (i=0; i<aTags.length; i++) {
    var Obj= aTags[i];
    if(!Obj.name||!(Obj.name.substring(0,7)=='aBanner'||Obj.name.substring(0,8)=='aExtLink')) continue;
    if(document.addEventListener) Obj.addEventListener('click', ClickCounterEvent, false);
     else if(document.attachEvent) Obj.attachEvent('onclick', ClickCounterEvent);
      else Obj.onclick= ClickCounterEvent;
    // correction of left position for swf mask
    if(Obj.name.substring(0,7)=='aBanner'&&Obj.parentNode.tagName=='DIV'&&parseInt(Obj.parentNode.style.marginLeft)<0) {
      if(!document.all) {
 	    ppObj = Obj.parentNode.parentNode;
  	    W= (document.defaultView && document.defaultView.getComputedStyle)
  	     ? document.defaultView.getComputedStyle(ppObj,null).getPropertyValue("width")
   	     : ppObj.offsetWidth.toString();
   	    NewWidth= parseInt(W);
    	Obj.parentNode.style.marginLeft= 0-NewWidth+'px'; // div
    	Obj.firstChild.style.width= NewWidth+'px'; // spacer img
     }
     if(!document.all) Obj.parentNode.style.position= "relative";
    }
  }
}
function ClickCounterConnector(param) {
  var img= new Image();
  img.src= param;
}
function ClickCounterEvent(env) {
  var clicksrc= (document.all) ? window.event.srcElement : env.target;
  var tag= (clicksrc.tagName!="A") ? clicksrc.parentNode : clicksrc;
  if(tag&&tag.tagName!="A") tag= tag.parentNode; // in case of clicking on embed tag
  if(!tag||tag.tagName!="A") {alert('ClickCounterEvent: '+tag.tagName); return;}
  if(!tag.name) {alert('ClickCounterEvent: no tag.name'); return;}
  if(tag.name.substring(0,7)=='aBanner') param= 'b='+tag.name.substring(7, 99);
  if(tag.name.substring(0,8)=='aExtLink') param= 'e='+tag.name.substring(8, 99);
  setTimeout("ClickCounterConnector('"+ClickCounterPhpLink+"?"+param+"')", 10);
  return;
}




function cancelEvent(e) {
	if (!e) return false;
	if (navigator.appName=="Microsoft Internet Explorer") {
		e.returnValue = false;
		e.cancelBubble = true;
	} else {
		e.preventDefault();
		e.stopPropagation && e.stopPropagation();
	}
	return false;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}



function calcAbsolutePosition(Obj) {
    var valueT = 0, valueL = 0;
    do {
      valueT += Obj.offsetTop;
      valueL += Obj.offsetLeft;
      Obj = Obj.offsetParent;
      if (Obj) {
      	alert(Obj.tagName);
        if (Obj.tagName == 'BODY') break;
    	var p = Obj.style.position;
    	if (!p) {
      		var css = document.defaultView.getComputedStyle(Obj, null);
      		p = css ? css.position : null;
    	}
        if (p == 'relative' || p == 'absolute') break;
      }
    } while (Obj);
    return [valueL, valueT];
}

function getElementPosition(elm1, elm2) {
	var top = 0, left = 0;
	while (elm1 && elm1 != elm2) {
		left += elm1.offsetLeft;
		top += elm1.offsetTop;
		elm1 = elm1.offsetParent;
	}
	return [left, top];
}


function getDimensions(Obj) {
	// kalkulisane dimenzije
	if(document.defaultView && document.defaultView.getComputedStyle) { // FF
		var W = document.defaultView.getComputedStyle(Obj,null).getPropertyValue("width");
		var H = document.defaultView.getComputedStyle(Obj,null).getPropertyValue("height");
		return [parseInt(W)-2,parseInt(H)-2]; // ove korekcije još treba proveriti
	}
	var W = Obj.offsetWidth.toString();	//IE
	var H = Obj.offsetHeight.toString();
	return [parseInt(W)-1,parseInt(H)-1];
}


function SetElementHeightByRatio(ElementId, Ratio, Addition) {
	// f. za setovanje visine prema kalkulisanoj širini
	var E= document.getElementById(ElementId);
	var D= getDimensions(E);
	E.height= Math.round(D[0] * Ratio)+Addition;
}


function ExtImgResizer(element,wlimit,hlimit) {
	var w= element.offsetWidth;
	var h= element.offsetHeight;
	if((wlimit)&&(w>wlimit)) {		h= h * wlimit / w;		w= wlimit;	}
	if((hlimit)&&(h>hlimit)) {		w= w * hlimit / h;		h= hlimit;	}
	element.style.width= w+"px";
	element.style.height= h+"px";
 }


BusyDiv = {
	Show: function(elementId, aniPath, bgImg) {
		// make and show busy animantion over existing element
		if(typeof elementId == 'object') {
			var eDiv= elementId;
			elementId= elementId.Id;
		} else
			var eDiv= document.getElementById(elementId);
		var eDivDim= getDimensions(eDiv);
		var eDivPos= getElementPosition(eDiv);//calcAbsolutePosition//alert(eDivPos);
		var bDiv= document.createElement('div');
		bDiv.setAttribute('id', elementId+'_BusyDiv');
		document.body.appendChild(bDiv);
//alert(eDivDim[1]);
		var BG= (bgImg) ? "background-image:url("+bgImg+");" : "color:black;";
		bDiv.style.cssText= 'display:block;position:absolute;left:'+(eDivPos[0]-2)+'px;top:'+(eDivPos[1]-2)+'px;z-index:1001;';
		bDiv.innerHTML= '<table border="0" style="width:'+(eDivDim[0]+9)+'px;height:'+(eDivDim[1]+6)+'px"><tr><td align="center" valign="middle" style="height:100%;z-index:1001;'+BG+'"><img src="'+aniPath+'" alt="" style="z-index:1002;" /></td></tr></table>';
	},

	Hide: function(elementId) {
		if(typeof elementId == 'object') elementId= elementId.Id;
		var bDiv= document.getElementById(elementId+'_BusyDiv');
		if(!bDiv) return;
		bDiv.parentNode.removeChild(bDiv);
	}
}


ComboDiv= {
	Make: function(CtrlName, Width, ListKeys, ListValues, CurrKey, CustomSelectEvent, KeyClasses) {
	    if (!KeyClasses) KeyClasses= false;
		if(typeof ListKeys.indexOf == "undefined") {
			var DefaultVal= -1;
			for(var i=0, im=ListKeys.length; i<im; i++) if(ListKeys[i]==CurrKey) DefaultVal= i;
		} else var DefaultVal= ListKeys.indexOf(CurrKey);

		DefaultVal= (DefaultVal>-1) ? ListValues[DefaultVal] : "";
		var Choose="", Class="", $Key= "";
		for(var x=0, xmax=ListKeys.length; x<xmax; x++) {
			Key= ListKeys[x];
			Class= (KeyClasses) ? Key : '';
			Class += (Key==CurrKey) ? ' ComboDivSelRow' : '';
			Class= (Class) ? ' class="'+Class+'"' : '';
			Choose += "\n			<div"+Class+" onmousedown=\"ComboDiv.OnSelect(this,'"+Key+"')\">"+ListValues[x]+"</div>";
		}
		var PH= document.getElementById(CtrlName+"_ComboDivPH");
		PH.innerHTML= '<div id="ComboDiv_'+CtrlName+'" class="ComboDiv" style="width:'+Width+'" onmousedown="ComboDiv.OnDropDown(this)">'+DefaultVal+'</div><div class="ComboDivDD" onmousedown="ComboDiv.OnDropDown(this.previousSibling)"></div><div style="clear:both"></div><div class="ComboDivOpts" style="width:'+Width+'">'+Choose+'</div><input type="hidden" name="'+CtrlName+'" value="'+CurrKey+'" />';
		if(CustomSelectEvent) setTimeout('document.getElementById("ComboDiv_'+CtrlName+'").CustomOnClick='+CustomSelectEvent, 300);
	},

	OnDropDown: function(ref) {
		var Input= ref;
		if(Input.tagName!='DIV') Input= Input.previousSibling;
		var Opts= ref.nextSibling;
		while((!Opts.className)||(Opts.className.substring(0,12)!='ComboDivOpts'))
			Opts= Opts.nextSibling;
		//var Pos= getElementPosition(Input);
		var Dim= getDimensions(Input);

		//Opts.style.marginleft= Pos[0]+'px';
		var AddOffset= (window.attachEvent) ? 1 : 5;
		//Opts.style.margintop= (Pos[1]+Dim[1]+AddOffset)+'px';
		Opts.style.display= (Opts.style.display=='block') ? 'none' : 'block';
		if(getDimensions(Opts)[1]>400) {
			Opts.style.height= '400px';
			Opts.style.overflowY= 'scroll';
		}
		var AddOffset= (window.attachEvent) ? -5 : 4;
		Opts.style.width= (Dim[0]+AddOffset)+'px';
		//OptList= Opts.getElementsByTagName('DIV');
		//for(var x=0, xmax=OptList.length; x<xmax; x++)
		//	OptList[x].style.width= (Dim[0]+AddOffset-4)+'px';
	},

	OnSelect: function(ref, key) {
		var Opts= ref.parentNode;
		var Input= Opts.previousSibling;
		while(!Input.id) Input= Input.previousSibling;
		Input.innerHTML= ref.innerHTML;
		var el= Opts.nextSibling;
		while(el.tagName!='INPUT') el=el.nextSibling;
		el.value= key;
		Opts.style.display= "none";
		if(Input.CustomOnClick) Input.CustomOnClick(key, Input.innerHTML);
	}
}


function StaticImageOnLoad(I,w,h) {
	// patch za IE i Operu koji ne kontaju stil max-width
	// pozvati sa: <img src=".." style="max-width:54px;max-height:46px" onload="StaticImageOnLoad(this,54,46)" />, dakle bez width i height atributa
    if(!(window.attachEvent)) return; // zaustavi FF, propusti IE i Opera
  	I.style.visibility= "hidden";
	I.removeAttribute("width");
	I.removeAttribute("height");
  	//alert("Orig size: "+I.width+"x"+I.height);
  	var s= [I.width, I.height];
    var ratio=  s[0]/s[1];
    if(s[0]>w) s= [w, w/ratio];
    if(s[1]>h) s= [h*ratio, h];
    I.width=s[0];	I.height=s[1];
    I.style.visibility= "visible";
}


function MakeVideoPlayer(PlayerId, Link, PlayerSrc, AP) {
  	 var Opts= { src:PlayerSrc };
  	 if((window.attachEvent)||(window.opera)) {
	 	var D= getDimensions(document.getElementById(PlayerId));
	 	Opts.height= D[0]*0.8; // patch for IE & Opera
  	 }
	 flashembed(PlayerId, Opts,
		{config: {	autoPlay:AP,			controlBarBackgroundColor:"0x535353",
					initialScale: "fit",	showFullScreenButton: false,
					showMenu: false,		videoFile: Link
		}}	);
  }

function MakeAudioPlayer(PlayerId, Link, PlayerSrc, AP) {
  	 var E= document.getElementById(PlayerId);
  	 var Dim= getDimensions(E.parentNode);
  	 var W= parseInt(Dim[0]*0.98);
  	 if((window.attachEvent)||(window.opera)) W -= 6; // Stupid IE and Opera
  	 AP= (AP) ? '&amp;autoplay=1' : '&amp;autoload=1'; // nemože zajedno i AP i AL
  	 E.innerHTML= '<object type="application/x-shockwave-flash" width="'+W+'" height="20" data="'+PlayerSrc+'"><param name="wmode" value="transparent" /><param name="movie" value="'+PlayerSrc+'" /><param name="FlashVars" value="mp3='+Link+'&amp;width='+W+AP+'&amp;showvolume=1&amp;loop=1" /><\/object>';
  }

function MakeMP3Album(PlayerId, Link, PlayerSrc, ObjHeight) {
  	 var E= document.getElementById(PlayerId);
  	 var Dim= getDimensions(E.parentNode);
  	 var W= parseInt(Dim[0]*0.98);
  	 if((window.attachEvent)||(window.opera)) W -= 6; // Stupid IE and Opera
  	 E.innerHTML= '<object type="application/x-shockwave-flash" width="'+W+'" height="'+ObjHeight+'" data="'+PlayerSrc+'"><param name="wmode" value="transparent" /><param name="movie" value="'+PlayerSrc+'" /><param name="FlashVars" value="mp3='+Link+'&amp;width='+W+'&amp;height='+ObjHeight+'&amp;showvolume=1" /><\/object>';
  }





/* FastInit
* http://tetlaw.id.au/view/javascript/fastinit
* Andrew Tetlaw
* Version 1.4.1 (2007-03-15)
* Based on:
* http://dean.edwards.name/weblog/2006/03/faster
* http://dean.edwards.name/weblog/2006/06/again/
* Help from: http://www.cherny.com/webdev/26/domloaded-object-literal-updated
*/
var FastInit = {
	onload : function() {
		if (FastInit.done) { return; }
		FastInit.done = true;
		for(var x = 0, al = FastInit.f.length; x < al; x++)
			FastInit.f[x]();
	},
	addOnLoad : function() {
		var a = arguments;
		for(var x = 0, al = a.length; x < al; x++) {
			if(typeof a[x] === 'function') {
				if (FastInit.done ) a[x]();
				 else FastInit.f.push(a[x]);
			}
		}
	},
	listen : function() {
		if (/WebKit|khtml/i.test(navigator.userAgent)) {
			FastInit.timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					clearInterval(FastInit.timer);
					delete FastInit.timer;
					FastInit.onload();
				}}, 10);
		} else if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', FastInit.onload, false);
		} else if(!FastInit.iew32) {
			if(window.addEventListener) window.addEventListener('load', FastInit.onload, false);
			 else if (window.attachEvent) return window.attachEvent('onload', FastInit.onload);
		}
	},
	f:[],done:false,timer:null,iew32:false
};
/*@cc_on @*/
/*@if (@_win32)
FastInit.iew32 = true;
document.write('<script id="__ie_onload" defer src="' + ((location.protocol == 'https:') ? '//0' : 'javascript:void(0)') + '"><\/script>');
document.getElementById('__ie_onload').onreadystatechange = function(){if (this.readyState == 'complete') { FastInit.onload(); }};
/*@end @*/
FastInit.listen();
/* end of FastInit */



function LoadExternalJS(files) {
	//alert("Launch LoadExternalJS: "+files)
	if(typeof files == "string")
		files= new Array(files);
	headObj= document.getElementsByTagName("head")[0];
	if(typeof LoadExternalJS_Log == "undefined") {
		LoadExternalJS_Log= [];
		var nl= document.getElementsByTagName('script'); // enumerate scripts from doc
		for (i=0; i<nl.length; i++) if(nl[i].src) LoadExternalJS_Log.push(nl[i].src);
		nl = headObj.getElementsByTagName('script');	// enumerate scripts from head
		for (i=0; i<nl.length; i++) if(nl[i].src) LoadExternalJS_Log.push(nl[i].src);
		//alert("Prepoznao: "+LoadExternalJS_Log);
	}
	for(var x=0, xmax=files.length; x<xmax; x++) {
		var stripped= files[x], used= false;
		while(stripped.substring(0,3)=='../') stripped= stripped.substring(3);
		for(var y=0, ymax=LoadExternalJS_Log.length; y<ymax; y++)
			if(LoadExternalJS_Log[y].indexOf(stripped)>0) {
				//alert("Skipping: "+files[x]);
				used= true;
			}
		if(used) continue;
		//alert("Loading: "+files[x]);
		var e = document.createElement("script");	// inserting via DOM fails in Safari 2.0
   		e.setAttribute("type","text/javascript");
    	e.setAttribute("src",files[x]);
   		headObj.appendChild(e);
		//LoadExternalJS_Log.push([files[x],e]);
		LoadExternalJS_Log.push(files[x]);
	}
}

function LoadExternalCSS(files) {
	if(typeof files=="string")
		files= new Array(files);
	for(var x=0, xmax=files.length; x<xmax; x++) {
		var e=document.createElement("link");
		e.setAttribute("rel", "stylesheet");
		e.setAttribute("type", "text/css");
		e.setAttribute("href", files[x]);
		document.getElementsByTagName("head")[0].appendChild(e);
	}
}


function LoadDatePickerControl(Months, Days, Params) {
	LoadExternalJS(jsRootDir+"inc/datepickercontrol/datepickercontrol.js");
	LoadDatePickerControlData= [Months, Days, Params];
	LoadDatePickerControlInt= setInterval("LoadDatePickerControl2()", 100);
}
function LoadDatePickerControl2() {
	if(typeof DatePickerControl == 'undefined' || !DatePickerControl) return;
	if(!DatePickerControl.LOADED) return;
	clearInterval(LoadDatePickerControlInt);
	DatePickerControl.Months= LoadDatePickerControlData[0];
	DatePickerControl.Days= LoadDatePickerControlData[1];
    for (var property in LoadDatePickerControlData[2]) {
    	DatePickerControl[property]= LoadDatePickerControlData[2][property];
    }
	DatePickerControl.init();
}


function mFormImgLoadDefRemove(ref,ConfirmText) {
	var refH= ref.nextSibling;
	var aClass= " mFormImgLoaderRemove";
	var aCL= aClass.length;
	if(refH.value=="D") {
		refH.value="";
		if(ref.className.substr(-aCL)==aClass)
			ref.className= ref.className.substring(0, (ref.className.length)-aCL);
	} else if(confirm(ConfirmText)) {
		refH.value="D";
		ref.className+=aClass;
	}
	return false;
}


function SimpleAjax(ref, url) {
	var ajaxOpts= {
		method: "POST",
		asynchronous: true,
		onComplete: function(response) {
    		BusyDiv.Hide(ref);
			ref.innerHTML= response.responseText;
		}
	}
	new Ajax.Request(url, ajaxOpts);
	BusyDiv.Show(ref, jsRootDir+"img/interface/BusyBig.gif", jsRootDir+"img/interface/shade/80a.png");
}


function DropDownAjaxContent(ref, url, buildFunc) {
	var T= ref.nextSibling.nextSibling.nextSibling;
	if(T.style.display=="block") {
		T.style.display= "none";
		return;
	}
	T.style.display= "block";
	T.style.visibility= "visible";
	var ajaxOpts= {
		method: "POST",
		asynchronous: true,
		onComplete: function(response) {
    		BusyDiv.Hide(T);
			ref.DDACSuccess= 1;
			if(buildFunc) buildFunc(ref, response)
			  else T.innerHTML= response.responseText;
		}
	}
	if(!ref.DDACSuccess) {
		new Ajax.Request(url, ajaxOpts);
		BusyDiv.Show(T, jsRootDir+"img/interface/BusyBig.gif", jsRootDir+"img/interface/shade/80a.png");
	}
}



// opacity and its subroutines
function opacity(id, opacStart, opacEnd, millisec, timeoffset) {
	var speed= Math.round(millisec / 100);
	var timer=0, opac=opacStart, step=(opacStart>opacEnd)?-1:1;
	if(!timeoffset) timeoffset= 0;
	do{
		opac += step;
		setTimeout("changeOpac("+opac+",'"+id+"')", timer*speed + timeoffset);
		timer++;
	}while( (step==-1) ? (opac>=opacEnd) : (opac<=opacEnd) );
}
function changeOpac(opacity, id, prop, newvalue) { //change the opacity for different browsers
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if(prop) object[prop]= newvalue;
}
function blendimage(divid, imageid, imagefile, millisec) {
	var timer = 0;
	var speed = Math.round(millisec / 100);
	document.getElementById(divid).style.backgroundImage = //set the current image as background
		"url(" + document.getElementById(imageid).src + ")";
	changeOpac(0, imageid); //make image transparent
	document.getElementById(imageid).src = imagefile; //make new image
	for(i = 0; i <= 100; i++) { //fade in image
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}


function StaffBtnClick(cid,sid) {
	var d0= document.getElementById("Staff"+cid+"c0");
	if(!d0.StaffFormLocation) d0.StaffFormLocation= 0;
	var source= document.getElementById("Staff"+cid+"c"+ d0.StaffFormLocation);
	var dest= document.getElementById("Staff"+cid+"c"+sid);
	if(source==dest) {ToggleDisplay("Staff"+cid+"c"+sid);return;}
	dest.innerHTML= source.innerHTML;
	source.innerHTML= "";
	d0.StaffFormLocation= sid;
	source.style.display= "none";
	dest.style.display= "block";
	document["form"+cid].StaffID.value= sid;
}

function jsProtText(sid,text) {
	var obj= document.getElementById("jsProtText"+sid);	if(!obj) return;
	var T= text.split(",");
	var out= '';
	for(var t in T) out += "&#"+(T[t]^11)+";";
	obj.innerHTML= out;
}


function mSlowScroll(ElementId, Height, Delay) {
	this.ElementId= ElementId;
	var E= document.getElementById(ElementId);
	if(!E) return;
	this.E= E;
	E.style.position= "relative";
	E.style.overflow= "hidden";
	this.Height= parseInt(Height);
	E.style.height= this.Height+"px";
	var C= E.innerHTML;
	E.innerHTML= "<div>"+C+"</div>";
	var scrollerinstance= this;
	setInterval(function(){scrollerinstance.Run()}, Delay);
	this.E2= this.E.firstChild;
	this.E2.style.cssText= "position:absolute;left:0;top:"+this.Height+"px";
	var D= getDimensions(this.E2);
	this.E.ContHeight= D[1];
}
mSlowScroll.prototype.Run= function() {
 	var Y= parseInt(this.E2.style.top);
	if(-Y>=this.E.ContHeight) Y= this.Height;
	this.E2.style.top= (Y-1)+"px";
}


function GetScreenResolution() {
	var V= mGetCookie("VisitTracker").split("|");
	if(!V[1]) mSetCookie("VisitTracker", V[0]+"|"+screen.width+"|"+screen.height);
}


// cookie funcs
function mSetCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
function mGetCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName == -1) return '';
	var posValue = posName + (escape(cookieName) + '=').length;
	var endPos = document.cookie.indexOf(';', posValue);
	return (endPos!=-1)
		? unescape(document.cookie.substring(posValue,endPos))
		: unescape(document.cookie.substring(posValue));
}



// -------------------------------
//         jquery funcs
// -------------------------------





