var navegador=navigator.appName;
var scrol_prin=0;
function ancho_pantalla(){
	if (navigator.appName.indexOf('Explorer') != -1)
		return document.body.parentNode.scrollWidth;
	else
		return window.innerWidth;
}
function alto_pantalla(){
	if (navigator.appName.indexOf('Explorer') != -1)
		return document.body.parentNode.scrollHeight;
	else
		return window.innerHeight;
}
var in_focus='';
	function _$(x){
		return document.getElementById(x);
	} 
	function tecla_pres(event){
		var theCode = (document.all) ? event.keyCode : event.which;
		return theCode;
	}
	function checha_l_fecha(fecha){
		var vf=fecha.value;
		if(vf.length>5 && vf.length!=10){
			alert('No ha completado la fecha, los campos de fecha deben tener el formato dd/mm/aaaa');
			fecha.focus();
		}
		return false;
	}
	function val_pas(event){
		if (tecla_pres(event))
			valida_login();
		else
			return false;
	}
	function calen(campo,fe,ev){
		var x=findPosX(campo,1);
		//var y=findPosY(campo);
		var y=posicion_mouse(ev);
		y=y.y;
		var divi=_$('calendario_div_'+fe);
		divi.style.top=y;
		divi.style.left=x;
		divi.style.display='block';
		xajax_calendario(campo.value,fe);
	}
	function dia(campo,fecha,s) {
		var campf=_$(campo);
		if(s=='1')
			campf.value=fecha;
		var divi=_$('calendario_div_'+campo);
		divi.style.display='none';
		campf.focus();
	}
	function redir(dir){
		location.href=dir;
	}
	function valida_login(){
		var vpass=_$('password').value;
		var vnick=_$('nick').value;
		if(vnick==''){
			alert('Por favor escriba un nick');
			return false;
		}
		if(vpass==''){
			alert('Por favor escriba la contrasena');
			return false;
		}
		xajax_val_login(vnick,vpass,navegador);
	}
	function oculta_div(div,o){
		var d=_$(div);
		if(o)
			d.style.display='none';
		else
			d.style.display='';
	}
	function capLock(e){
		kc=e.keyCode?e.keyCode:e.which;
		sk=e.shiftKey?e.shiftKey:((kc==16)?true:false);
		if(((kc>=65&&kc<=90)&&!sk)||((kc>=97&&kc<=122)&&sk))
			_$('div_caps').style.visibility = 'visible';
		else
			_$('div_caps').style.visibility = 'hidden';
	}
	function resize_div(div,aoa,dif){
		var div=_$(div);
		if(aoa=='alto'){
			if (navigator.appName.indexOf('Explorer') != -1)
				var addp=document.body.parentNode.scrollHeight-dif;
			else
				var addp=window.innerHeight-dif;
			div.style.height=addp;
		}
		if(aoa=='ancho'){
			if (navigator.appName.indexOf('Explorer') != -1)
				var addp=document.body.parentNode.scrollWidth-dif;
			else
				var addp=window.innerWidth-dif;
			div.style.width=addp;
		}
	}
	function resize_div2(div,w,h){
		//alert('resizeando');
		resize_div(div,'ancho',w);
		resize_div(div,'alto',h);
	}
	function roll(id1,id2){
		var img=_$(id1);
		img.style.display='none';
		var img2=_$(id2);
		img2.style.display='';
	}
    function crea_window(id_div,css){
		var plat=_$(id_div);
		//alert(css);
		if(css==undefined)
			css='windoww';
		if(plat==undefined){
			plat=document.createElement('div');
			plat.setAttribute('id',id_div);
			plat.setAttribute('class',css);plat.setAttribute('className',css);
			plat.style.zIndex='999';
			var pad=_$('div_master');
			pad.appendChild(plat);
			return true;
		}else{
			alertx('Ya tiene abierto este documento o ventana',2);
			return false;
		}
    }
	function close_window(id_div){
		if(_$(id_div)==undefined)
			return;
		var div=_$(id_div);
		var pdiv=div.parentNode;
		pdiv.removeChild(div);
	}
	function adjuntos(field,dir,fil,id,tam,maxtam,img,funex){
		xajax_render_ad(_$('iut_'+field+id).value,field,dir,fil,id,tam,maxtam,img,funex);
	}
	function posicion_mouse(e) {
		var posx = 0;
		var posy = 0;
		if(!e){ var e = window.event }
		posx = (e.pageX) ? e.pageX : window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = (e.pageY) ? e.pageY : window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;

		return {y: posy, x:posx}
	}
	function findPosX(obj,der){
		var obor=obj;
		var curleft = 0;
		if(obj.offsetParent)
			while(1){
				curleft += obj.offsetLeft;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if(obj.x)
			curleft += obj.x;
		if(der)
			return curleft+obor.offsetWidth;
		return curleft;
	  }
	function findPosY(obj){
		var curtop = 0;
		if(obj.offsetParent)
			while(1){
				curtop += obj.offsetTop;
				if(!obj.offsetParent)
					break;
				obj = obj.offsetParent;
			}
		else if(obj.y)
			curtop += obj.y;
		return curtop;
	 }
	 function table_search(d,ev,t){
		if(t!=undefined)
			_$(d).style.display='table';
		else
			_$(d).style.display='block';
		var pos=posicion_mouse(ev);
		x=pos.x;
		if (navigator.appName.indexOf('Explorer') != -1)
			var adp=document.body.parentNode.scrollWidth;
		else
			var adp=window.innerWidth;
		tam_div=_$(d).offsetWidth;
		x=x-(tam_div/2);
		if(x<0)
			x=0;
		if((x+tam_div)>adp)
			x=adp-tam_div;
		y=pos.y;
		_$(d).style.left=x;
		_$(d).style.top=y;
	 }
	function setOpacity(obj,value) {
		if(_$(obj)==undefined)
			return;
		testObj=_$(obj);
		testObj.style.opacity = value/10;
		testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
	}	 
	 function alertx(contenido,retardo,css){
		if(retardo==undefined)
			retardo=3000;
		else
			retardo*=1000;
		if(css==undefined)
			css='alertx';
		if(crea_window('div_alert',css)){
			_$('div_alert').innerHTML='<a onclick="close_window(\'div_alert\');"><img src="skin/'+skin+'/img/close.png" style="float:right;"><a><br/><div style="margin:15px;"><img src="skin/'+skin+'/img/alert.png"><br/>'+contenido+'</div>';
			window.setTimeout('close_window(\'div_alert\');',retardo+(retardo/30));
			for(x=0;x<10;x+=0.2)
				setTimeout("setOpacity('div_alert',"+x+");",retardo-(x*60));
		}else
			alert(cont);
	 }
	 function ventana_con(id,titulo,contenido,fun){
		if(fun!=undefined)
			xfun=fun;
		else
			xfun='';
		if(crea_window(id)){
			_$(id).innerHTML='<div class="barra_gad" id="arras_'+id+'"> '+titulo+'<a onclick="close_window(\''+id+'\');'+xfun+'"><img src="skin/'+skin+'/img/close.png" class="close_gad"></a> <a onclick="_$(\'wc_'+id+'\').style.display=\'block\';_$(\''+id+'\').style.top=0+\'px\';_$(\''+id+'\').style.left=0+\'px\';resize_div2(\'wc_'+id+'\',10,10);_$(\'res_'+id+'\').style.display=\'block\';_$(\'max_'+id+'\').style.display=\'none\';"><img src="skin/'+skin+'/img/maximize.png" class="close_gad" alt="Maximizar" title="Maximizar" id="max_'+id+'"></a> <a onclick="_$(\'wc_'+id+'\').style.width=\'800px\'; _$(\'wc_'+id+'\').style.height=\'600px\';oculta_div(\'wc_'+id+'\',0);_$(\'res_'+id+'\').style.display=\'none\';_$(\'max_'+id+'\').style.display=\'block\';_$(\'min_'+id+'\').style.display=\'block\';"><img src="skin/'+skin+'/img/restore.png" class="close_gad" style="display:none;"  alt="Restaurar" title="Restaurar" id="res_'+id+'"></a> <a onclick="_$(\'wc_'+id+'\').style.width=\'800px\';_$(\'wc_'+id+'\').style.height=\'0px\';_$(\'min_'+id+'\').style.display=\'none\';_$(\'res_'+id+'\').style.display=\'block\';"><img src="skin/'+skin+'/img/minimize.png" class="close_gad" alt="Minimizar" title="Minimizar" id="min_'+id+'"></a></div><div id="wc_'+id+'" class="window_con">'+contenido+'</div></div>';
			arrastrable.call(_$('arras_'+id),_$('arras_'+id).parentNode);
		}//else
			//alertx('Ocurrio un error al intentar abrir la ventana');
	 }
	 function alerty(id,contenido,retardo){
		if(crea_window(id,'alerty')){
			_$(id).innerHTML='<div class="barra_gad" id="arras_'+id+'"> <a onclick="close_window(\''+id+'\');"><img src="skin/'+skin+'/img/close.png" class="close_gad"></a></div><div style=\"margin:3px;\">'+contenido+'</div>';
			arrastrable.call(_$('arras_'+id),_$('arras_'+id).parentNode);
		}else
			alert(cont);
		if(retardo!=undefined){
			retardo*=1000;
			window.setTimeout('close_window(\'div_alert\');',retardo+(retardo/30));
			for(x=0;x<10;x+=0.2)
				setTimeout("setOpacity('div_alert',"+x+");",retardo-(x*60));
		}
	}
	/*function fisheye(e,t){
		if(t){
			e.style.width='32px';
			e.style.height='32px';
		}else{
			e.style.width='16px';
			e.style.height='16px';
		}
	}*/
	function envia_ticket(){
		if(_$('nombre').value==''){
			alertx('Por favor indique el nombre de quien envia el ticket');
			_$('nombre').focus();
			return false;
		}
		if(_$('asunto').value==''){
			alertx('Por favor indique el asunto de su ticket');
			_$('asunto').focus();
			return false;
		}
		if(_$('mensaje').value==''){
			alertx('Por favor indique el mensaje de su ticket');
			_$('mensaje').focus();
			return false;
		}
		xajax_universal('modulos/tickets/ajax.php','envia_ticket',xajax.getFormValues('new_ticket_def'),_$('tickets_depto').value);
	}
	/*ticket_js_sube_ar=function(h,i,fil,id){
		var nfil='archivos'+id;
		//alertx(nfil+' '+fil+' '+id);
		if(_$(nfil).value==""){
			_$(nfil).value=fil;
			_$('div_tick_fil'+id).innerHTML=fil;
		}else{
			_$(nfil).value=_$(nfil).value+'/'+fil;
			_$('div_tick_fil'+id).innerHTML=_$('div_tick_fil'+id).innerHTML+'<br/>'+fil;
		}
	}*/
	function respuesta_ticket(id,r,e,io){
		if(_$('mensaje'+id).value==''){
			alertx('Por favor indique el mensaje');
			_$('mensaje'+id).focus();
			return false;
		}
		xajax_universal('modulos/tickets/ajax.php','responder_ticket',xajax.getFormValues('new_ticket_def'+id),id,r,e,io);
	}
	function plug_conv_data(nom,asunto,mensaje){
		_$('nombre').value=nom;
		_$('asunto').value=asunto;
		_$('mensaje').value=mensaje;
		return true;
	}
