var ventanas = new Array();
nVentanas = 0;

document.onmousemove = window.onmousemove = function() {
    for (i = 0; i < nVentanas; i++) {
        if (ventanas[i] != null && !ventanas[i].closed) { ventanas[i].focus(); }
    };
}

function windowOpen(Enlace, nombreVentana, Width, Height, resizable, scrollbars, menubar, toolbar, directories, location, status, statusbar){
var wf = '';
	wf= wf + 'left=' + (screen.width-Width)/2 + 'px';
	wf= wf + ',top=' + (screen.height-Height)/2 + 'px';
	wf= wf + 'screenX=' + (screen.width-Width)/2 + 'px';
	wf= wf + ',screenY=' + (screen.height-Height)/2 + 'px';
	wf = wf + ',width='+Width+'px';
	wf = wf + ',height='+Height+'px';
	wf = wf + ',resizable='+resizable;
	wf = wf + ',scrollbars='+scrollbars;
	wf = wf + ',menubar='+menubar;
	wf = wf + ',toolbar='+toolbar;
	wf = wf + ',directories='+directories;
	wf = wf + ',location='+location;
	wf = wf + ',status='+status;
	wf = wf + ',statusbar='+statusbar;
	return window.open(Enlace,nombreVentana,wf);
}
function windowMaximize(){
	if (window.top!=window) window.top.location.href=window.location.href;
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth, screen.availHeight);
}
function windowFocus(vent){
    try {
        if (vent != null && !vent.closed) { vent.focus(); }
	}catch(E){}
}
function windowClose(vent) {
    try{
	    if (vent!=null && !vent.closed) vent.close();
    } catch (E) { }
}
function windowRecargarPadre(){
    if (window.opener!=null && !window.opener.closed) window.opener.location.href=window.opener.location.href;
}
function windowCenter(vent){
	try{
	    var x = parseInt((parseInt(screen.width)-parseInt(document.body.offsetWidth))/2);
	    var y = parseInt((parseInt(screen.height)-parseInt(document.body.offsetHeight))/2);
	    if (vent!=null && !vent.closed) vent.moveTo(x,y);
	}catch(ex){}
}
function windowCentrar(){

}
function panelCentrar(campo,ancho,alto){
	var item= document.getElementById(campo);
	if (item==null) return;
	var x,y;
	if (self.innerHeight){ 
	    x = parseInt(self.innerWidth);
	    y = parseInt(self.innerHeight);
	}else if (document.documentElement && document.documentElement.clientHeight){
	    x = parseInt(document.documentElement.clientWidth);
	    y = parseInt(document.documentElement.clientHeight);
	}else if (document.body){ 
	    x = parseInt(document.body.clientWidth);
	    y = parseInt(document.body.clientHeight);
	}
	item.style.position='absolute';
	item.style.width=ancho+'px';
	item.style.height=alto+'px';
	item.style.left=(x-ancho)/2;
	item.style.top=(y-alto)/2;
}
function enfocaControl(id){
	document.getElementById(id).focus();
}
function enfocaTextBox(id, cssEnfocado) {
    try {
        document.getElementById(id).className = cssEnfocado;
        document.getElementById(id).focus();
        document.getElementById(id).select();
    } catch (e) {
    }
}
function desEnfocaTextBox(id, cssNormal){
    try{
        document.getElementById(id).className = cssNormal;
	} catch (e) {
    }
}
function windowSinPadre(){
	if (window.top!=window) window.top.location.href=window.location.href;
}
function getForm(){
    return document.forms[0];
}
function csmsPostBack(eventTarget,eventArgument) {
	var theform= getForm();
	theform.__EVENTTARGET.value = eventTarget.split('$').join(':');
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}

function stopEvent(e) {
    if (!e) e = window.event;
    if (e.stopPropagation) e.stopPropagation();
    else e.cancelBubble = true;
}
function cancelEvent(e) {
    if (!e) e = window.event;
    if (e.preventDefault) e.preventDefault();
    else e.returnValue = false;
}
function disableFormAndControls(){
var frm = getForm();
    frm.disabled=true;
	for (i=0;i<frm.elements.length;i++) frm.elements[i].disabled=true;
}

//Inicio Revista xarxa
function desactivaControles(dom) {
	if (dom.nodeName=='INPUT' || dom.nodeName=='A') dom.disabled=true;
    if (dom.nodeName!='#text') dom.onmouseover= dom.onclick= dom.onmouseout= null;
	for (var i = 0; i < dom.childNodes.length; i++) desactivaControles(dom.childNodes.item(i));
}
   
function desactivaEventos(control){
    var item= document.getElementById(control);
	if (item==null) return;
    desactivaControles(item);
}
//Fin Revista xarxa

/*Desactiva todos los clicks si se llama: disableClick(document.getElementsByTagName("body")[0]); */
function disableClick(el) {
	try{
		el.onclick=function(){ return false; }; 
		if (el && el.childNodes){
		    for (var x = 0; x < el.childNodes.length; x++) {
			    disableClick(el.childNodes[x]);
		    }
		}
	}catch(E){}
}
function desactivarForm(){
	disableClick(document.getElementById("form1"));
	if (mensajeProcesando!='' || imagenProcesando!=''){ 
		var it= document.createElement('div');
		it.id='dcMissatgeProces';
		document.getElementsByTagName('body')[0].insertBefore(it,document.getElementsByTagName('body')[0].firstChild);
		var cad="<table width='100%' height='100%' class='processant'><tr><td valign=middle align=center>";
		if (mensajeProcesando!='') cad +=mensajeProcesando;
		if (imagenProcesando!=''){
			if (mensajeProcesando!='') cad +="<br /><br />";
			cad +="<img src='"+imagenProcesando+"'/>";
		}
		cad +="</td></tr></table>"
		document.getElementsByTagName('body')[0].firstChild.innerHTML=cad;
		panelCentrar('dcMissatgeProces',400,100);
	}
	setTimeout('disableFormAndControls();',0);
}
function procesando(){
    var frm = getForm();
    frm.onsubmit=desactivarForm;
    if (window.__doPostBack!='undefined'){
       var oldPostBack=window.__doPostBack;
       window.__doPostBack=function(arg1,arg2){
            desactivarForm();
            oldPostBack(arg1,arg2);
       }
    }
}

function disableKeyENTER(){
  var codigo, targ;
  if (!e) var e = window.event;
  if (e.keyCode) codigo = e.keyCode;
  else if (e.which) codigo = e.which;
  else return;
  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;
  else return;
  if (targ.nodeType == 3) targ = targ.parentNode; 
  if (codigo == 13 && targ.nodeName=='INPUT'){
      if (e.keyCode)  e.keyCode=0;
      else if (e.which)  e.which=0;
  }
}

//var ctrlConEnterActivo = null;
//function EnterToClick() {
//    $("input").keypress(function(e) {
//        if (e.which == 13) document.getElementById(ctrlConEnterActivo).click();
//    });
//}

/*Pendiente de revisar*/
function setOpacity(element, opacity){
		element.style.filter = "alpha(opacity:" + opacity + ")"; 
		element.style.KHTMLOpacity = opacity / 100;
		element.style.MozOpacity = opacity / 100; 
		element.style.opacity = opacity / 100;
};

function  hint(status,txt,css){
      var id= "csmsVentanaAyuda";
      var MouseX = (window.Event) ? e.pageX : (event.clientX + document.body.scrollLeft - document.body.clientLeft);
      var MouseY = (window.Event) ? e.pageY : (event.clientY + document.body.scrollTop - document.body.clientTop); 
      var htmObj = document.getElementById(id); 
	  if(!htmObj){
				  htmObj=document.createElement("div");
				  htmObj.setAttribute("id", id);
				  htmObj.className=css;
				  document.body.appendChild(htmObj);
	  }
	  htmObj.style.top = (MouseY+20) + 'px';
	  htmObj.style.left = (MouseX+20) + 'px';
	  htmObj.style.visibility = (status) ? 'visible' : 'hidden';
	  if (htmObj.style.visibility =='visible') htmObj.innerHTML=txt;
	  else htmObj.innerHTML='';
 }

 /*Ratón*/
    /*Posición exacta de un objeto*/
    function getTagPixels(StartTag, Direction) {
        var PixelAmt = (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
          while ((StartTag.tagName != 'BODY') && (StartTag.tagName != 'HTML')) {
               StartTag = StartTag.offsetParent;
               PixelAmt += (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
          }
          return PixelAmt;
    }
    
    function objVisual(idItem){
        this.id=idItem;
        this.X=0;
        this.Y=0;
        this.XX=0;
        this.YY=0;
        this.item= document.getElementById(idItem);
        this.valido=function(){
            return (this.item);
        }
        this.getCoordenadas=function(){
            if (!this.valido()) return;
            this.X = getTagPixels(this.item, 'LEFT');
            this.XX = this.X + this.item.offsetWidth;
            this.Y = getTagPixels(this.item, 'TOP');
            this.YY = this.Y  + this.item.offsetHeight;
        }
    }
    
    var dcMouse={   x:0,
                    y:0,
                    dentroRectangulo: function(X,Y,XX,YY){
                        return (this.x>=X && this.x<=XX && this.y>=Y && this.y<=YY);
                    },
                    dentroObjeto: function(obj){
                        this.dentroRectangulo(obj.X,obj.Y,obj.XX,obj.YY);
                    },
                    dentroItem: function(idItem){
                         var objItem= document.getElementById(idItem);
                         if (!objItem) return false;
                         var X = getTagPixels(objItem, 'LEFT');
                         var XX = X + objItem.offsetWidth;
                         var Y = getTagPixels(objItem, 'TOP');
                         var YY = Y  + objItem.offsetHeight;
                         return this.dentroZona(X,Y,XX,YY);
                    }
                 };
    function mouseMove(ev){
        ev = ev || window.event;
        if (ev.pageX || ev.pageY){
            dcMouse.x= ev.pageX;
            dcMouse.y= ev.pageY;
        }else{
            dcMouse.x= ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            dcMouse.y= ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    }
    String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, '') }
    /*
   function IsDigit(){
            var NUMEROS="0123456789";
            key = charFromCharCode(event.keyCode);
            return NUMEROS.indexOf(key)>=0;
        }

        function charFromCharCode(charCode) {
            return unescape('%' + charCode.toString(16));
       } 
   
       function changeCSS(theClass,element,value) {
             var cssRules;
	         if (document.all) cssRules = 'rules';
	         else if (document.getElementById) cssRules = 'cssRules';
	         for (var S = 0; S < document.styleSheets.length; S++)
	              for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
	                if (document.styleSheets[S][cssRules][R].selectorText == theClass)
	                    if (document.styleSheets[S][cssRules][R].style[element]) document.styleSheets[S][cssRules][R].style[element] = value;        
        }*/

    