// jslib.js
/*
Author/Autor: 
	Carlos Andres Caballero Pino, Panama   2004
Purpose/Proposito:
	Expose a common browser interface for object manipulation, as well as various
	utility functions. 

	Exponer una interface estandard para la manipulacion de objetos asi como otras
	funciones de utileria y efectos

BTW/A proposito:
	Dont expect too many comments
	No esperen muchos comentarios
*/

/*GLOBALS:    
	just state stuff ugly but functional...
	solo estados algo feo pero funcional...
*/
var _jslib_isIE=document.all?true:false;
var _jslib_isNS=document.layers?true:false;
var _jslib_isNS6=document.getElementById&&!document.all?true:false;
var _jsErrorMsg="";

//FX stuff
var __jsFadeRefresh=30;

//HTTP REQUEST STUFF
var __xmlRequest=null;
var __commands=new Array();
var __currentCommand=null;

//Dialog window stuff
var _dlgResult=null;		//dialog results
var _jsDlg=null;			//dialog window

//form validator, validadores de formas
var _jslibValidator=new Array();

function jsGetError(){
	return _jsErrorMsg;
}

function jsGetObject(name){
	if(_jslib_isIE){
		return document.all[name];
	}else if(_jslib_isNS){
		return eval("document.layers."+name)
	}else if (_jslib_isNS6){
		return document.getElementById(name);
	}
	return null;
}

function jsIsObject(obj){
	return typeof obj=='object' && !jsIsFunction(obj)
}
function jsIsArray(obj){
	return jsIsObject(obj) && obj.constructor==Array;
}
function jsIsFunction(obj){
	return typeof obj=='function'
}
function jsIsString(obj){
	return typeof obj=='string';
}

function jsAddEvent(obj,evname,func){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);	
	}
	if(jsIsObject(obj)){
		if(_jslib_isIE){
			obj.attachEvent("on" + evname, func);
		}else{
			obj.addEventListener(evname, func, true);
		}
	}
}

function jsGetParent(obj){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	if(jsIsObject(obj)){
		if(_jslib_isIE){
			return obj.parentElement;
		}else{
			return obj.parentNode;
		}
	}
}

function jsGetStyle(obj,style){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	var stl;
	if(jsIsObject(obj)){
		if((_jslib_isIE==true)||(_jslib_isNS6==true)){
			stl=eval("obj.style."+style);
		}else if(_jslib_isNS){
			stl=eval("obj."+style);
		}
		if(stl!=null){
			return stl;
		}
		_jsErrorMsg="Invalid Style";
		return null;
	}
	return null;
}

function jsGetStyles(obj,styles){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	if(jsIsObject(obj)){
		var res=new Array();
		for(var i=0;i<styles.length;i++){
			res[i]=jsGetStyle(obj,styles[i]);
		}		
		return res;
	}
	return null;
}

function jsSetStyle(obj,style,value){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}	
	if(jsIsObject(obj)){		
		if(jsGetStyle(obj,style)!=null){
			if((_jslib_isIE==true)||(_jslib_isNS6==true)){
				eval("obj.style."+style+"='"+value+"'");
			}else if(_jslib_isNS){
				eval("obj."+style+"='"+value+"'");
			}else{
				return false;
			}
			return true;
		}
		return false;
	}
	return false;
}

function jsSetStyles(obj,styles,values){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	if(jsIsObject(obj)){
		for(var i=0;i<styles.length,i<values.length;i++){
			jsSetStyle(obj,styles[i],values[i]);
		}
	}
}

function jsGetCoordinates(obj){
	var sx=0;
	var sy=0;
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	if(obj){
		sx=obj.offsetLeft?obj.offsetLeft:0;
		sy=obj.offsetTop?obj.offsetTop:0;		
		oparent=jsGetParent(obj);
		if(oparent){
			if(oparent.tagName!='BODY'){
				tmp=jsGetCoordinates(oparent);
				sx+=tmp[0];
				sy+=tmp[1];
			}
		}
	}
	
	return [sx,sy];
}


//JAVASCRIPT FORM VALIDATION

function jsRegisterFormValidator(name,function_name){
	_jslibValidator[name]=function_name;
}

function jsFFcheckEmpty(obj,hint){
	if(obj.value==''){
		if(obj.type!="hidden") obj.focus();
		return false;
	}
	return true;
}

function jsFFcheckMail(obj,hint){
	if(hint["required"] || obj.value!=""){		
		var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		var regex = new RegExp(emailReg);
		var res=regex.test(obj.value);
		if(!res){
			if(obj.type!="hidden") obj.focus();
			return false;
		}
	}
	return true;
}

function jsFFnumeric(obj,hint){
	if(hint["required"] && obj.value==""){
		if(obj.type!="hidden") obj.focus();
			return false;
	}
	if(obj.value!=""){
		if (isNaN(obj.value)){
			if(obj.type!="hidden") obj.focus();
			return false;
		}else{
			if(hint['min']){
				if(!isNaN(hint['min'])){
					hint['min']=parseFloat(hint['min']);
					num=parseFloat(obj.value);
					if(num<hint['min']){
						return false;
					}
				}
			}
			if(hint['max']){
				if(!isNaN(hint['max'])){
					hint['max']=parseFloat(hint['max']);
					num=parseFloat(obj.value);
					if(num>hint['max']){
						return false;
					}
				}
			}
		}
	}
	return true;
}

jsRegisterFormValidator("empty",jsFFcheckEmpty);
jsRegisterFormValidator("mail",jsFFcheckMail);
jsRegisterFormValidator("numeric",jsFFnumeric);

function jsValidateForm(form,beforeValidate,afterValidate,defaultMsg,notifier){	
	var id;
	var status=1;
	if(beforeValidate){
		if(!beforeValidate(form)){
			return false;
		}
	}
	form._jsnotifier=jsIsFunction(notifier)?notifier:function(elem,msg){alert(msg)};
	for(i=0;i<form.elements.length;i++){
		if(form.elements[i].type!="button" && form.elements[i].type!="submit"){
			elem=form.elements[i];
			validation='';	hint='';	
			validation=elem.getAttribute("validation");
			hint=elem.getAttribute("validationHint");
			if(hint){
				if(hint.indexOf('&')>=0){
					t_hint=hint.split('&');
					hint=new Array();
					for(j=0;j<t_hint.length;j++){
						tm=t_hint[j].split('=');
						if(tm.length==2){
							hint[tm[0]]=tm[1];
						}
					}
				}else{
					tm=hint.split('=');
					hint=new Array();
					if(tm.length==2){
						hint[tm[0]]=tm[1];
					}
				}
			}else{
				hint=new Array();
			}
			vmsg=elem.getAttribute("validationMsg");
			if(!vmsg){
				vmsg=defaultMsg?defaultMsg:'El campo "'+elem.name+' " es requerido';
			}else{
				vmsg=vmsg.replace(/{element}/,elem.name);
			}
			if(validation){
				if(_jslibValidator[validation]){
					if(!_jslibValidator[validation](elem,hint)){
						form._jsnotifier(elem.name,vmsg);						
						return false;							
					}
				}else{
					alert('Validator '+validation+' not found');
				}
			}
		}
	}
	if(afterValidate){
		if(!afterValidate(form)){
			return false;
		}
	}
	return true;
}
function jsSafeSubmit(obj,wtext){
	if(jsIsObject(obj)){
		obj.form.the_submit=obj;
		obj.disabled=true;
		obj.old_text=obj.value;
		obj.value=wtext?wtext:'Please  wait...';
		doit=true;
		if(obj.form.onsubmit){
			doit=obj.form.onsubmit()
		}
		if(doit){
			obj.form.submit();
		}
		obj.disabled=false;
		obj.value=obj.old_text;
	}
}

function jsOnlyNumbers(obj,decimals,onlypositive){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	obj._decimals=decimals;
	obj._positive=onlypositive;
	obj.onkeydown=function(ev){

		failed=false;
		evt=document.all?event:ev;
		tg=document.all?evt.srcElement:evt.target;

		if ((evt.keyCode< 48 || evt.keyCode > 57) && (evt.keyCode< 96 || evt.keyCode > 105) && evt.keyCode !=8 
		  && evt.keyCode !=39 && evt.keyCode !=37 && evt.keyCode !=46 &&  evt.keyCode !=110 &&  evt.keyCode !=190
		  && evt.keyCode !=36 && evt.keyCode !=35 && evt.keyCode !=9 && evt.keyCode !=109) {
			failed=true;
		}else{			
			
			if(evt.keyCode==109 && tg._positive==true ){
				failed=true;
			}else{				
				if(evt.keyCode==109 && tg.value.indexOf('-')>=0){
					failed=true;
				}else{
					if(evt.keyCode==109 && tg.value.length>0){
						failed=true;
					}
				}
			}
			if(!failed){
				if(tg._decimals==0 && (evt.keyCode ==110 || evt.keyCode ==190) ){
					failed=true;
				}else{				
					if((evt.keyCode ==110 || evt.keyCode ==190) && tg.value.indexOf('.')>=0){
						failed=true;
					}else{
						if(evt.keyCode !=8 && evt.keyCode !=46 && evt.keyCode !=36 && evt.keyCode !=35
						   && evt.keyCode !=39 && evt.keyCode !=37){
							if(tg.value.indexOf('.')>=0){
								reg=new RegExp("[-]?[0-9][.][0-9]{"+tg._decimals+"}");
								failed=reg.test(tg.value);
							}
						}
					}
				}
			}
		}
		if(failed){
			if(document.all){
				event.returnValue=false;
			}else{
				evt.preventDefault( );
			}
		}
	}
} 

function jsLimitText(obj,limit,notify,notifytext){
	if(jsIsString(obj)){
		obj=jsGetObject(obj);
	}
	obj._limit=limit;
	obj._noti_text=notifytext?notifytext:"{current} of {limit}";
	
	if(notify){
		if(jsIsString(notify)){
			notify=jsGetObject(notify);
		}
		if(!jsIsObject(notify)){			
			notify=null;
		}
	}
	obj._notify=notify;
	
	obj.onkeydown=function(ev){
		evt=document.all?event:ev;
		tg=document.all?evt.srcElement:evt.target;
		if(tg.value.length>=tg._limit &&
		    evt.keyCode!=46 && evt.keyCode!=8 && 
			evt.keyCode!=33 && evt.keyCode!=34 && 
			evt.keyCode!=35 && evt.keyCode!=36 && 
			evt.keyCode!=38 && evt.keyCode!=37 && 
			evt.keyCode!=39 && evt.keyCode!=40
		   ){
			if(document.all){
				event.returnValue=false;
			}else{
				evt.preventDefault( );
			}
		}
		if(tg._notify){
			notifytext=tg._noti_text;
			notifytext=notifytext.replace(/{current}/,tg.value.length);
			notifytext=notifytext.replace(/{limit}/,tg._limit);
			tg._notify.innerHTML=notifytext;
		}
	}
}

//JAVASCRIPT GRID
function jsGrid(name,width,height){
	this.name=name;
	this.width=width;
	this.height=height;
	this.labelStyle='defGridHeader';
	this.gridStyle='defGridStyle';
	this.itemStyle='defDataClass';
	this.selectedStyle='defDataSelected';
	this.selected=null;
	this.onClick='jsGridSelectRow';
	this.headerEvents=new Array();
	this.cellEvents=new Array();
	this.rowEvents=new Array();
	this.selectedColor='#EDF5CD';
	this.headerEvents['click']=function(id){ this.gridDriver.sortColumn(this); };
	this.headerEvents['over']=function(id){ 
		this.oldcolors= jsGetStyles(this,['borderBottomColor','backgroundColor']) ;
		jsSetStyles(this,['borderBottomColor','backgroundColor'],['#FFBB00','#FFFFFF']); 
	};
	this.headerEvents['out']=function(id){ 
		jsSetStyles(this,['borderBottomColor','backgroundColor'],this.oldcolors); 
	};

	this.cellEvents['over']=function(id){
		tg=jsGetParent(this)
		tg.oldcolors= jsGetStyles(tg,['backgroundColor','color']) ;
		jsSetStyles(tg,['backgroundColor','color'],['#DDF5FF','#000000']); 
	};
	this.cellEvents['out']=function(id){
		tg=jsGetParent(this)
		jsSetStyles(tg,['backgroundColor','color'],tg.oldcolors); 
	};

	this.Create=function(labels){		
		cssFound=false;
		if(document.styleSheets.length>0){
			rules=document.all?document.styleSheets[0].rules:document.styleSheets[0].cssRules;
			for(i=0;i<rules.length;i++){
				if(rules[i].selectorText=='defGridStyle'){
					cssFound=true;
					break;
				}						 
			}
		}
		
		if(!cssFound){
			document.write('<style>.defGridStyle{border:1px solid #B9DEFF;scrollbar-base-color:#EEEEEE;scrollbar-highlight-color:#EEEEEE;scrollbar-shadow-color:#EEEEEE;scrollbar-3dlight-color:#AAAAAA;scrollbar-darkshadow-color:#AAAAAA;scrollbar-track-color:#DDDDDD;background:#FFFFFF;}					.defGridHeader{border-left:1px solid #FFFFFF;border-top:3px solid #EEEEEE;border-right:1px solid #AAAAAA;border-bottom:2px solid #AAAAAA;background-color:#F8F8EF;font-family:Arial, Helvetica, sans-serif;font-size:11px;font-weight:bold;padding-left:5px;padding-right:5px;height:20px;text-align:center;} .defDataClass{font-size:10px;border-bottom:1px solid #000000;border-right:1px solid #000000;font-family:Arial, Helvetica, sans-serif;padding:3px;}	.defDataSelected{background-color:#000000;font-size:11px;color:#FFFFFF;border-bottom:1px solid #FFFFFF;border-right:1px solid #FFFFFF;font:Arial, Helvetica, sans-serif;padding:3px;}</style>');
		}
		
		eval("this.cellEvents['click']=function(id){ "+this.onClick+"(this); }");
		document.writeln('<div id="jsgrid_'+this.name+'" style="width:'+this.width+';height:'+this.height+';overflow:auto;" class="'+this.gridStyle+'" >');
		document.writeln('<table width="100%" id='+this.name+' cellpading="0" cellspacing="0" border="0">');
		document.writeln('</table>');
		document.writeln('</div>');
		
		if(labels.length){	
			var tbl=jsGetObject(this.name);
			var row,cell;
			row=tbl.insertRow(-1);
			row.gridDriver=this;
			
			for(i=0;i<labels.length;i++){
				cell=row.insertCell(-1);				
				cell.id=this.name+'_label'+i;
				cell.className=this.labelStyle;
				lbl_text=labels[i];
				lbl_text=lbl_text.replace(/ /g,'&nbsp;')
				
				cell.innerHTML=lbl_text;
				cell.parentGrid=this;

				cell.onclick=this.headerEvents['click'];
				cell.onmouseover=this.headerEvents['over'];
				cell.onmouseout=this.headerEvents['out'];
				cell.gridDriver=this;
				
			}
		}		
		var tbl=jsGetObject(this.name)
		tbl.setAttribute('selectedItem',null);
	}
	this.insertRow=function(data){
		var tbl=jsGetObject(this.name);
		var row,cell;
		row=tbl.insertRow(-1);
		row.gridDriver=this;
		for(i=0;i<tbl.rows[0].cells.length,i<data.length;i++){			
			cell=row.insertCell(-1);
			cell.id=this.name+'_item_'+tbl.rows.length+'_'+row.cells.length;
			cell.className=this.itemStyle;
			cell.selectedStyle=this.selectedStyle;
			cell.normalStyle=this.itemStyle;
			if(data[i].pop){
				cell.innerHTML=i<data.length?data[i][0]:'&nbsp;';
				cell.cell_value=i<data.length?data[i][1]:'';
			}else{
				cell.innerHTML=i<data.length?data[i]:'&nbsp;';
				cell.cell_value=i<data.length?data[i]:'';
			}
			cell.parentGrid=this;
			cell.onclick=this.cellEvents['click'];
			cell.onmouseover=this.cellEvents['over'];
			cell.onmouseout=this.cellEvents['out'];
			cell.gridDriver=this;
		}
	}
	this.setRowData=function(row_id,data){
		var tbl=jsGetObject(this.name);
		var row,cell;
		if(row_id>=1 && row_id<tbl.rows.length){
			row=tbl.rows[row_id];
			for(i=0;i<row.cells.length, i<data.length ;i++){			
				if(data[i].pop){
					row.cells[i].innerHTML=i<data.length?data[i][0]:'&nbsp;';
					row.cells[i].cell_value=i<data.length?data[i][1]:'';
				}else{
					row.cells[i].innerHTML=i<data.length?data[i]:'&nbsp;';
					row.cells[i].cell_value=i<data.length?data[i]:'';
				}
			}
		}
	}
	this.setColumnWidth=function(data){
		var tbl=jsGetObject(this.name);
		var row,cell;
		row=tbl.rows[0];
		for(i=0;i<row.cells.length,i<data.length;i++){			
			jsSetStyle(row.cells[i],'width',data[i]);
		}
	}	
	this.moveUp=function (){
		tobj=jsGetObject(this.name);
		if(this.selected!=null){
			if(this.selected.rowIndex>1){
				rd=tobj.rows[this.selected.rowIndex-1];
				ro=this.selected;
				for(i=0;i<rd.cells.length;i++){
					tmp=rd.cells[i].innerHTML;
					rd.cells[i].innerHTML=ro.cells[i].innerHTML;
					ro.cells[i].innerHTML=tmp;
				}
				jsGridSelectRow(rd.cells[0]);
			}
		}
	}
	this.moveDown=function (){
		tobj=jsGetObject(this.name);
		if(this.selected!=null){
			if(this.selected.rowIndex<(tobj.rows.length-1))	{
				rd=tobj.rows[this.selected.rowIndex+1];
				ro=this.selected;
				for(i=0;i<rd.cells.length;i++){
					tmp=rd.cells[i].innerHTML;
					rd.cells[i].innerHTML=ro.cells[i].innerHTML;
					ro.cells[i].innerHTML=tmp;
				}
				jsGridSelectRow(rd.cells[0]);
			}
		}
	}
	this.removeSelected=function(){
		tobj=jsGetObject(this.name);
		if(this.selected!=null){
			tobj.deleteRow(this.selected.rowIndex);
			this.selected=null;
		}
	}
	this.Clear=function(){
		tobj=jsGetObject(this.name);
		while(tobj.rows.length>1){
			tobj.deleteRow(1);
		}
		this.selected=null;
	}
	this.getRowData=function(){		
		if(this.selected!=null){
			var res=new Array();
			for(i=0;i<this.selected.cells.length;i++){
				res[i]=this.selected.cells[i].cell_value;				
			}
			return res;
		}
		return null;
	}
	
	this.getRowDataIdx=function(row_id){		
		var tbl=jsGetObject(this.name);
		var row,cell;
		var res=new Array();
		if(row_id>=1 && row_id<tbl.rows.length){
			row=tbl.rows[row_id];
			for(i=0;i<row.cells.length;i++){
				res[i]=row.cells[i].cell_value;				
			}
		}
		return res;
	}	
	this.getCell=function(col,row){
		var tbl=jsGetObject(this.name);
		if(tbl){
			if(tbl.rows[row]){
				if(tbl.rows[row].cells[col]){
					return tbl.rows[row].cells[col];
				}
			}
		}
		return null;
	}
	this.sortColumn=function(col){
		return null;
	}
}

function jsGridSelectRow(obj){
	var tobj=jsGetParent(obj)
	tobj=jsGetParent(tobj);
	if(tobj.rows.length>1){
		selectedItem=obj.parentGrid.selected;
		if(selectedItem==null){			
			row=jsGetParent(obj);
			obj.parentGrid.selected=row;
			for(i=0;i<row.cells.length;i++){	
				row.cells[i].className=row.cells[i].selectedStyle;
			}
		}else{
			if(selectedItem.rowIndex==jsGetParent(obj).rowIndex){
				obj.parentGrid.selected=null;
				row=jsGetParent(obj);
				for(i=0;i<row.cells.length;i++){				
					row.cells[i].className=row.cells[i].normalStyle;
				}
			}else{
				row=selectedItem;
				for(i=0;i<row.cells.length;i++){				
					row.cells[i].className=row.cells[i].normalStyle;
				}				
				row=jsGetParent(obj);
				obj.parentGrid.selected=row;
				for(i=0;i<row.cells.length;i++){				
					row.cells[i].className=row.cells[i].selectedStyle;
				}
			}
		}
	}
}

function jsToolTipOver(ev){	
	var target=document.all?ev.srcElement:ev.currentTarget;
	target.visibleTip=target.visibleTip?false:true;	
	jsShowTip(target.id,ev.clientX+5,ev.clientY-(105),20.00,target.fadeSpeed,true);
}

function jsToolTipOut(ev){	
	var target=document.all?ev.srcElement:ev.currentTarget;
	if(jsGetStyle('js_current_tool_tip','display')!='none'){
		jsShowTip(target.id,ev.clientX+5,ev.clientY-(105),100.00,target.fadeSpeed,false);	
	}
}

function jsShowTip(obj,x,y,alpha,step,show){
	var target=jsGetObject(obj);
	var tip=jsGetObject('js_current_tool_tip');
	if(jsGetStyle(tip,'display')!='') jsSetStyle(tip,'display','');

	if(show){
		if(!tip.toolSet){
			tip.innerHTML='<b>'+target.toolTipTitle+'</b><hr size="1" color="#FFCC00">'+target.toolTip;
			tip.className=target.tipClass;
			jsSetStyles(tip,['left','top'],[x,y]);
			tip.toolSet=true;
		}		
	}
	
	if(document.all){
		jsSetStyle(tip,'filter','alpha(opacity='+alpha+')');		
	}else{
		jsSetStyle(tip,'MozOpacity',alpha/100.00);
	}
	if(show==true){	
		if(alpha<100){
			alpha+=step;
			setTimeout('jsShowTip("'+obj+'",'+x+','+y+','+alpha+','+step+',true)',__jsFadeRefresh);
		}
	}else{
		if(alpha>0){
			alpha-=step;
			setTimeout('jsShowTip("'+obj+'",'+x+','+y+','+alpha+','+step+',false)',__jsFadeRefresh);
		}else{
			tip.toolSet=false;	
			jsSetStyle(tip,'display','none');
		}
	}	
}

function jsAddToolTip(id_obj,title,txt,cls,speed){
		var obj=jsGetObject(id_obj);
		obj.fadeSpeed=speed;
		obj.toolTip=txt;
		obj.tipClass=cls;
		obj.toolTipTitle=title;
		jsAddEvent(obj,'click',jsToolTipOver);
		jsAddEvent(obj,'mouseout',jsToolTipOut);
		var tip=jsGetObject('js_current_tool_tip');
		if(!tip){
			document.write('<div id="js_current_tool_tip" style="position:absolute;top:0px;left:0px; display:none; width:220px; height:100px;"></div>')
		}
}

function jsImageSlider(name,target,imTime){
	this.target=jsIsString(name)?jsGetObject(target):target;
	this.name=name;
	this.images=new Array();
	this.imageTime=imTime;
	this.current=0;
	this.paused=false;
	this.addImage=function(url){
		this.images.push(url);	
	}
	this.Pause=function(){
		this.paused=!this.paused;
	}
	this.Next=function(){
		if(this.images.length>0){
			this.paused=true;	
			this.target.src=this.images[this.current];
			
			this.current++;
			if(this.current>(this.images.length-1)){
				this.current=0;
			}
		}
	}
	this.Prev=function(){
		if(this.images.length>0){
			this.paused=true;
			this.target.src=this.images[this.current];
			
			this.current--;
			if(this.current<0){
				this.current=this.images.length-1;
			}
		}
	}
	this.Execute=function(){
		if(this.target){
			if(!this.paused && this.images.length>0){
				this.target.src=this.images[this.current];
				this.current++;
				if(this.current>(this.images.length-1)){
					this.current=0;
				}
			}
			setTimeout(this.name+".Execute()",this.imageTime);
		}
	}
}

function jsFadeSetRefresh(r){
	__jsFadeRefresh=r;
}
function jsFade(obj,alpha,step,show,onFinish){
	target=jsGetObject(obj);
	if(onFinish){
		target.onFadeFinish=onFinish;
	}
	if(document.all){
		jsSetStyle(target,'filter','alpha(opacity='+alpha+')');
	}else{
		jsSetStyle(target,'MozOpacity',alpha/100.00);
	}
	target.current_alpha=alpha;
	if(show==true){	
		if(alpha<100){
			alpha+=step;
			setTimeout('jsFade("'+obj+'",'+alpha+','+step+',true)',__jsFadeRefresh);
		}else{
			if(jsIsFunction(target.onFadeFinish)){
				target.onFadeFinish();
				target.onFadeFinish=null;
			}
		}
	}else{
		if(alpha>0){
			alpha-=step;
			setTimeout('jsFade("'+obj+'",'+alpha+','+step+',false)',__jsFadeRefresh);
		}else{
			if(jsIsFunction(target.onFadeFinish)){
				target.onFadeFinish();
				target.onFadeFinish=null;
			}
		}
	}	
}
//HTTP REQUEST STUFF
function jsRequestHandle(){
	if (__xmlRequest.readyState==4 || __xmlRequest.readyState=="complete"){
		if(__currentCommand){
			if(__xmlRequest.status==200){
				__currentCommand.onEnd(__currentCommand.handle=='xml'?__xmlRequest.responseXML:__xmlRequest.responseText);
			}else{
				__currentCommand.onFailed(__xmlRequest.statusText);
			}
			if(__currentCommand) window.clearTimeout(__currentCommand.idTime);
			__currentCommand=null;
		}
	}
}
function jsRequestInit(){
	if (window.XMLHttpRequest){
		__xmlRequest=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		__xmlRequest=new ActiveXObject("Microsoft.XMLHTTP")
	}
}
function jsRequestAddHandler(ev,command){
	if(jsIsObject(command) && command.onBegin!=null){
		__commands[ev]=command;
	}else{
		alert('invalid handler for "'+ev+'" event');	
	}
}
function jsRequestAbort(){
	if((__xmlRequest.readyState == 1)||(__xmlRequest.readyState == 2)||(__xmlRequest.readyState == 3)){			
		__xmlRequest.abort();
		if(__currentCommand)	__currentCommand.onFailed('timeout reached');
	}
	if(__currentCommand) window.clearTimeout(__currentCommand.idTime);
	__currentCommand=null;
}
function jsRequestExecute(ev){
	if(!__xmlRequest) jsRequestInit();
	if(__commands[ev]){
		__commands[ev].onBegin();
		__commands[ev].pushState();				
		if (__xmlRequest.readyState==4 || __xmlRequest.readyState==0){
			__currentCommand=__commands[ev];
			__currentCommand.idTime=window.setTimeout('jsRequestAbort()',__currentCommand.timeout);		
			__xmlRequest.open("GET",__currentCommand.popState(),true);
			__xmlRequest.onreadystatechange=jsRequestHandle;
			__xmlRequest.send(null);
		}else{
			__commands[ev].onFailed('bussy');
		}
	}else{
		alert('Command '+ev+' not found');
	}
}
function jsRequestCommand(handles){
	this.handle=handles;
	this.url='';
	this.idTime=0;
	this.timeout=5000;
	this.state_stack=new Array()
	this.onCall=function(){	}
	this.onEnd=function(data){}
	this.onFailed=function(msg){	alert('Error:'+msg);	}
	this.pushState=function(){	this.state_stack.push(this.url);	}
	this.popState=function(){
		if(this.state_stack.length>0){			return this.state_stack.pop();		}		return this.url;
	}
}

function jsInitDrag(){
	if(!document._js_drag_mevents){
		document._js_drag_mevents=new Array();
		document._js_drag_mevents['move']=document.onmousemove;
		document._js_drag_mevents['up']=document.onmouseup;
		document._js_drag_mevents['down']=document.onmousedown;
		document.onmousedown=jsDragStart;		
	}
}
function jsDragStart(ev){
	r_event=document.all?window.event:ev;
	tg=document.all?window.event.srcElement:ev.target;
	candrag=tg.getAttribute('drag');
	if(candrag=='true' || candrag=='yes' || candrag=='1'){		
		dragtarget=jsGetObject(tg.getAttribute('dragtarget'));
		
		if(dragtarget){		tg=dragtarget;		}
		
		pos=jsGetStyle(tg,'position');
		
		dummy=tg.getAttribute('dummyDrag');
		
		if(pos!='absolute' && !dummy){			
			coords=jsGetCoordinates(tg);
			jsSetStyles(tg,['position','left','top'],['absolute',coords[0],coords[1]]);
		}
		
		limits=tg.getAttribute('draglimits');
				
		tg._jsIsDummy=dummy;
				
		if(limits){
			limits=limits.split(',');
			if(limits[4]=='area'){
				limits[2]=parseInt(limits[2]);
				limits[2]-=tg.offsetWidth;
				limits[3]=parseInt(limits[3]);
				limits[3]-=tg.offsetHeight;
			}
		}else{
			limits=[null,null,null,null,null];
		}
		
		dragstart=tg.getAttribute('jsOnDragStart');
		if(dragstart){
			if(!tg._jsOnDragStart){				
				eval('tg._jsOnDragStart='+dragstart);
								
			}
		}
		if(!jsIsFunction(tg._jsOnDragStart)){
			tg._jsOnDragStart=function(){}
		}
		dragevent=tg.getAttribute('jsOnDrag');
		if(dragevent){
			if(!tg._jsOnDrag){				
				eval('tg._jsOnDrag='+dragevent);
			}
		}
		if(!jsIsFunction(tg._jsOnDrag)){
			tg._jsOnDrag=function(){}
		}
		
		dragend=tg.getAttribute('jsOnDragEnd');
		if(dragend){
			if(!tg._jsOnDragEnd){				
				eval('tg._jsOnDragEnd='+dragend);
			}
		}
		if(!jsIsFunction(tg._jsOnDragEnd)){
			tg._jsOnDragEnd=function(){}
		}
		
		document._jsDragLimits=limits;
		document._jsdragTarget=tg;
		document.onmousemove=jsDrag;
		document.onmouseup=jsDragEnd;
		
		document._jsDragStartPos=jsGetStyles(tg,['left','top']);
		invalidx=true;
		invalidy=true;

		if(document._jsDragStartPos[0]){
			document._jsDragStartPos[0]=document._jsDragStartPos[0].replace('px','');
			document._jsDragStartPos[0]=parseInt(document._jsDragStartPos[0]);
			invaludx=false;
		}
		if(document._jsDragStartPos[1]){
			document._jsDragStartPos[1]=document._jsDragStartPos[1].replace('px','');		
			document._jsDragStartPos[1]=parseInt(document._jsDragStartPos[1]);
			invalidy=false;
		}
		if(invalidx || invalidy){
			coords=jsGetCoordinates(tg);
			dx=invalidx?coords[0]:document._jsDragStartPos[0];
			dy=invalidy?coords[1]:document._jsDragStartPos[1];
			document._jsDragStartPos=[dx,dy];
		}	
	
		document._jsDragStartMPos=[r_event.clientX,r_event.clientY];
		
		tg._jsOnDragStart(tg,document._jsDragStartPos[0],document._jsDragStartPos[1])		
				
		return false;
	}else{
		if(jsIsFunction(document._js_drag_mevents['down'])){
			document._js_drag_mevents['down'](ev);
		}
	}
}
function jsDragEnd(ev){
	if(document._jsdragTarget){
		document._jsdragTarget._jsOnDragEnd(document._jsdragTarget)
	}
	document._jsdragTarget=null;
	document._jsDragStartPos=null;
	document.onmousemove=document._js_drag_mevents['move'];
	document.onmouseup=document._js_drag_mevents['up'];
	return false;
	
}
function jsDrag(ev){
	var mv=document.all?window.event:ev;
	px=document._jsDragStartPos[0]+(mv.clientX-document._jsDragStartMPos[0]);
	py=document._jsDragStartPos[1]+(mv.clientY-document._jsDragStartMPos[1]);

	if(document._jsDragLimits[0])	px=Math.max(document._jsDragLimits[0],px);
	if(document._jsDragLimits[1])	py=Math.max(document._jsDragLimits[1],py);	
	if(document._jsDragLimits[2])	px=Math.min(document._jsDragLimits[2],px);
	if(document._jsDragLimits[3])	py=Math.min(document._jsDragLimits[3],py);	

	if(!document._jsdragTarget._jsIsDummy){
		jsSetStyles(document._jsdragTarget,['left','top'],[px,py]);
	}
	
	document._jsdragTarget._jsOnDrag(document._jsdragTarget,px,py,document._jsDragStartPos[0],document._jsDragStartPos[1])
	return false;
}