// JavaScript Document
function ClassGeneral()
{
	this.navign = new ClassNavigator();
	this.boxTemp = null;
	this.layerTrans = null;
	this.pageAction = null;
	this.scrollPage = function()
	{
		/* pagina sin XHTML*/
		//document.body.clientHeight
		
		/* pagina en XHTML*/
		if (this.navign._NAV==3)
				return document.body.scrollTop;
		else
				return window.document.documentElement.scrollTop;
	}
	
	this.windowWidth = function()
	{
		/* pagina sin XHTML*/
		//return parseInt(document.body.clientWidth);
		
		/* pagina en XHTML*/
		//window.innerWidth; -->por si hubiera problemas cn explorer
		if (this.navign._NAV==3)
				return parseInt(document.body.clientWidth);
		else
				return parseInt(document.documentElement.clientWidth);			
	}
	
	this.windowHeight = function()
	{
		/* pagina sin XHTML*/
		//return parseInt(document.body.clientHeight);
		
		/* pagina en XHTML*/
		//window.innerHeight; -->por si hubiera problemas cn explorer
		if (this.navign._NAV==3)
				return parseInt(document.body.clientHeight);
		else
				return parseInt(document.documentElement.clientHeight);				
	}

	this.staticOpacity = function(id)
	{
		var temp_EFECT = null;
		var _STATIC= new Array();
		_STATIC[0]=new Array();
		_STATIC[0]['layer']=document.getElementById(id).style;
		_STATIC[0]['opacity']=60;		
		temp_EFECT= new ClassOpacity(_STATIC,null,null,null);
	}
	
	this.createOpacity = function()
	{
		var temLay = document.createElement('div');
		temLay.id='capTrans';
		document.body.appendChild(temLay);
		this.changeClass('capTrans','layerTrans');
		this.staticOpacity('capTrans');
		this.resizeLayer('capTrans','contenido');		
	}
	
	this.layerLoading = function()
	{
		this.createOpacity();
		temLay = document.createElement('div');
		temLay.id='boxTemp';
		temLay.innerHTML = '<center><img src="/img/loading1.gif"></center>';
		document.body.appendChild(temLay);
		this.changeClass(temLay.id,'layerTrans');
		this.scrollTopLeft('boxTemp');		
	}
	
	this.createBox = function(value)
	{		
		this.createOpacity();
		temLay = document.createElement('div');
		temLay.id='boxTemp';
		temLay.innerHTML = value+'<center><button class="btn1" onClick="ObjGen.deleteBox();" style="width:100px" type="button">Cerrar</button></center>';
		document.body.appendChild(temLay);
		this.changeClass(temLay.id,'errorBox');
		this.scrollTopLeft('boxTemp');
	}
	
	this.deleteBox = function()
	{
		document.body.removeChild(document.getElementById('capTrans'));
		document.body.removeChild(document.getElementById('boxTemp'));
	}
	
	this.scrollLayer = function (id)
	{
		document.getElementById(id).style.top = parseInt((this.windowHeight()/2)+this.scrollPage())+'px';
	}

	
	this.scrollTopLeft = function (id)
	{
		try{
		document.getElementById(id).style.top = (parseInt((this.windowHeight()/2)+this.scrollPage())-(parseInt(document.getElementById(id).clientHeight)/2))+'px';		
		document.getElementById(id).style.left = (parseInt((this.windowWidth()/2) - (parseInt(document.getElementById(id).clientWidth)/2)))+'px';
		}
		catch (err){}

	}

	this.scrollLayer2 = function (id)
	{
		document.getElementById(id).style.top = parseInt(this.scrollPage())+'px';
	}
	
	this.layerVisibility = function(layer,property)
	{
		document.getElementById(layer).style.visibility=property;
	}

	this.layerDisplay = function(layer,property)
	{
		document.getElementById(layer).style.display=property;
	}

	this.changeClass = function(id,clase)
	{
		document.getElementById(id).setAttribute('class',clase); 
		document.getElementById(id).setAttribute('className',clase); 
		/*if (this.navign._NAV==1)
			document.getElementById(id).setAttribute('className',clase); 
		else
			document.getElementById(id).setAttribute('class',clase); */
	}
	
	this.resizeLayer = function(layer,ancla)
	{
		
		if (ancla!=null)
		{
			document.getElementById(layer).style.height = (parseInt(document.getElementById(ancla).clientHeight))+'px';
		}
		else
		document.getElementById(layer).style.height = this.windowHeight()+'px';
		document.getElementById(layer).style.width = this.windowWidth()+'px';
	}
	

	this.checkRow = function(id)
	{
		if (document.getElementById(id).checked==true)
				document.getElementById(id).checked=false;
		else
				document.getElementById(id).checked=true;
	}

	this.checkRow2 = function(id,value)
	{
		document.getElementById(id).checked=value;
	}


	this.selectRow = function(id)
	{
		if (this.navign._NAV==1)
			_value = document.getElementById(id).getAttribute('className'); 
		else
			_value = document.getElementById(id).getAttribute('class'); 
		
		if (_value=='selOff')
				this.changeClass(id,'selOn');
		else
				this.changeClass(id,'selOff');
	}
	
	this.checkAll = function(pre,elements,type)
	{
		for (i=0;i<elements;i++)
		{
			this.checkRow2(pre+i,type);
		}		
	}
	
	this.selectAll = function (pre,elements,type)
	{
		if (type==true)
				{
					for (i=0;i<elements;i++)
					{
						this.changeClass(pre+i,'selOn');
					}
				}
		else
				{
					for (i=0;i<elements;i++)
					{
						this.changeClass(pre+i,'selOff');
					}
				}		
		
	}
	
	this.selectExe = function (id,elements)
	{
		this.selectExe(null,elements,document.getElementBiId(id).checked);
	}
	
	this.buildValues = function (formu)
	{
		var cadValues='';
		for (i=0;i<formu.elements.length;i++) 
     { 	
		 	 if (formu.elements[i].type == "checkbox") 
			 		if (formu.elements[i].checked==true)
							cadValues=cadValues+'&'+formu.elements[i].name+'='+formu.elements[i].value;
		 }
		 return cadValues;
	}
	
	this.setStyleMouse = function(id,background,color)
	{
		if (id != sele)
		{
		document.getElementById(id).style.background=background;
		document.getElementById(id).style.color=color;
		}
	}

	this.setStyleMouse2 = function(id,background,color)
	{
		document.getElementById(id).style.background=background;
		document.getElementById(id).style.color=color;
	}

	this.layerVisible2 = function (id)
	{
		document.getElementById('T'+sele).style.display='none';
		document.getElementById(id).style.display='block';
	}

	this.layerVisible2 = function (id)
	{
		if('T'+sele!=id)
			document.getElementById('T'+sele).style.display='none';
		if (document.getElementById(id).style.display=='block')
				document.getElementById(id).style.display='none';
		else
				document.getElementById(id).style.display='block';
	}
	
	this.ajaxForm = function (formu,type,layer,layer_lo)
	{
		
		var values='';
		if (formu!=null)
				values = this.buildValues(formu);
		values = type+values;
		if (this.pageAction!=null)
				var ajax = new libreriaAJAX(values,this.pageAction);
		else
				var ajax = new libreriaAJAX(values,'../../includes/php/action_article.php');
			ajax.setaction_(function (texto)
			{
				var trozos=new Array();
				trozos=texto.split("~");	
				if (trozos[0]=='1')
						{
							document.getElementById(layer).innerHTML = trozos[1];
							setTimeout("ObjGen.layerVisibility('"+layer_lo+"','hidden')",1500);		
						}
				else
				if (trozos[0]=='2')
						{														
							setTimeout("ObjGen.deleteBox();eval('"+trozos[1]+"');",1500);		
						}
				else
				if (trozos.length>1)
						{
							if (layer!=null)
								document.getElementById(layer).innerHTML = trozos[1];
							eval(trozos[0]);
						}
				else
				if (layer!=null)
						{
							document.getElementById(layer).innerHTML = texto;
						}
				else
				if (layer_lo!=null)
						setTimeout("ObjGen.layerVisibility('"+layer_lo+"','hidden')",1500);	
				
			}
			);
		if (layer_lo!=null)
			{
				this.layerVisibility(layer_lo,'visible');
			}
		ajax.ejecution();
	}
	
}