/////////////////agragar trim
	
	String.prototype.trim=function()
	{	
			return this.replace(/^s+|s+$/g,'');
	}
	
/////////////////////////////////

function teclas(e)
{
	var tecla;	
	if(document.all)
	{
		tecla=e.keyCode;
	}
	else
	{
		tecla=e.which;
	}	
	 return tecla;
}

function ajaxConsultaDivGet(direccion,div)
{
	var xml=zXmlHttp.createRequest();
	xml.open("get",direccion,true);
	xml.onreadystatechange=function()
	{
		if(xml.readyState==4)
		{
			if(xml.status==200)
			{								
				insertarDiv(div,xml.responseText);
			}			
		}
	}
	xml.send(null);
}

function ajaxConsultaGet(direccion)
{
	var xml=zXmlHttp.createRequest();
	var texto;
	xml.open("get",direccion,true);
	xml.onreadystatechange=function()
	{
		if(xml.readyState==4)
		{
			if(xml.status==200)
			{	
				texto=xml.responseText;
				return texto;
			}
		}
	}
	xml.send(null);
	return texto;
}


function insertarDiv(div,texto)
{
	var temp=document.getElementById(div);
	temp.innerHTML=texto;
}

function ocultarDiv(div,valor)
{
	div=document.getElementById(div);
	if(valor)
	{
		div.style.display="none";
	}
	else
	{
		div.style.display="inline";
	}
}

function trimForm(formu)
{
	for(var i=0;i<formu.length;i++)
	{
		formu.elements[i].value=trim(formu.elements[i].value);
	}
	return true;
}

function trim(cadena)
{
	var inicio=0,fin=cadena,fin=cadena.length;
	for(i=0;i<i<cadena.length;i++)
	{
		if(cadena.charAt(i)==' ' || cadena.charAt(i)=="\n")
		{
			inicio++;
		}
		else
		{
			break;
		}
	}
	for(i=cadena.length-1;i>=0;i--)
	{	
		if(cadena.charAt(i)==' '  || cadena.charAt(i)=="\n")
     		{
			fin--;
		}
		else
		{
			break;
		}
	}
	if(inicio==cadena.length)
	{
		return "";
	}
	return cadena.substring(inicio,fin);
}

function loading()
{
	var div=document.getElementById("loading");
	var string='<div style="border:1px  double black;background-color:#D1D1D1;text-align:center;width:400px;height:200px;vertical-align:middle;";><p><br>Cargando....<br>Por favor espere.<br><img src="../images/loading.gif"></div>';
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="loading";
		b.appendChild(temp);		
		loading();
		return;
	}
	x=document.documentElement.clientWidth;
	y=document.documentElement.clientHeight
	div.style.position="absolute";
	div.style["vertical-align"]="middle";
	div.style.top=Math.ceil((y/2)-150)+"px";
	div.style.left=Math.ceil((x/2)-150)+"px";	
	div.innerHTML=string;	
	div.style.visibility="visible";
}

function verAyuda(e,tipo)
{	
	var div=document.getElementById("toolTipAyuda");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="toolTipAyuda";
		temp.onmouseover=seguirAyuda;
		temp.onmouseout=noVerAyuda;
		temp.onclick=noVerAyuda;
		b.appendChild(temp);		
		verAyuda(e,tipo);
		return;
	}
	div.innerHTML="";
	ajaxConsultaDivGet("php/codes/ayudas.php?num="+tipo,"toolTipAyuda");
	var x=e.clientX;
	var y=e.clientY;
	x+=document.body.scrollLeft+ document.documentElement.scrollLeft;
	y+=document.body.scrollTop+ document.documentElement.scrollTop;	
	div.style.top=y+"px";
	div.style.left=x+"px";	
	div.style.visibility="visible";
	setTimeout("noVerAyuda()",8000);
}

function seguirAyuda()
{
	var div=document.getElementById("toolTipAyuda");
	div.style.visibility="visible";
}


function noVerAyuda()
{
	var div=document.getElementById("toolTipAyuda");
	div.style.visibility="hidden";
}

function cambiarColorFila(fila,color)
{	
	fila.style.backgroundColor=color;	
}

function inArray(valor,mat)
{
	if(valor==null || mat==null)
	{
		return false;
	}
	for(var i=0;i<mat.length;i++)
	{
		if(valor.toLowerCase()==mat[i].toLowerCase())
		{
			return true;
		}
	}
	return false;
}


function selText(inicio,fin,campo)
{ 
	input=campo;
	if(typeof document.selection != 'undefined' && document.selection)
	{ 
		tex=input.value; 
		input.value=''; 
		input.focus(); 
		var str = document.selection.createRange(); 
		input.value=tex; 
		str.move('character', inicio); 
		str.moveEnd("character", fin-inicio); 
		str.select(); 
	} 
	else if(typeof input.selectionStart != 'undefined')
	{ 
		input.setSelectionRange(inicio,fin); 
		input.focus(); 
	} 
} 

function crearLink()
{
	var cad="a";
	for(var i=0;i<5;i++)
	{
		var randomnumber=Math.floor(Math.random()*11);
		cad+=randomnumber;
	}
	return cad;
}

function validarPassword(p1,p2)
{
	if(p1!=p2)
	{
		return false;
	}
	return true;
}

function validarCorreo(correo)
{
	var regex=/^[a-zA-z\d]+([\.]?[\w])*@[a-zA-Z\d]+([\w]|-)*(\.[a-zA-Z]+)+$/
	return regex.test(correo);
}

function validarEntero(num)
{
	if(trim(""+num).length==0)
	{
		return false;
	}
	var regex=/^[\d]+$/
	return regex.test(""+num);
}

function validarReal(num)
{	
	if(trim(""+num).length==0)
	{
		return false;
	}
	regex=/^[\d]*([\.][\d])?[\d]*$/
	return regex.test(""+num)
}

function crearVariablesFormulario(formu,escap)
{	
	var mat=new Array(formu.length);
	for(var i=0;i<formu.length;i++)
	{		
		if(formu.elements[i].type=="checkbox")
		{
			if(!formu.elements[i].checked)
			{				
				continue;
			}			
		}		
		if(escap!=null)
		{
			mat[i]=formu.elements[i].name+"="+escape(((formu.elements[i].value)));
		}
		else
		{
			mat[i]=formu.elements[i].name+"="+((formu.elements[i].value));
		}
	}
	return mat.join('&');
}

function validaciones(texto,validacion)
{
	var div=document.getElementById("msgError");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("input");
		temp.id="msgError";
		temp.type="hidden";
		b.appendChild(temp);				
		return validaciones(texto,validacion);
	}
	var	matValidacion=validacion.split('-');
	if(matValidacion.length==0)	
	{
		return true;
	}
	for(var i=0;i<matValidacion.length;i++)
	{
		if(matValidacion[i].toLowerCase()=="v")
		{
			if(trim(texto).length==0)
			{
				document.getElementById("msgError").value="El campo no puede estar vacio";
				return false;
			}
		}
		if(matValidacion[i].toLowerCase()=="c")
		{
			if(!validarCorreo(texto))
			{
				document.getElementById("msgError").value="El formato del correo es incorrecto";
				return false;
			}
		}
		if(matValidacion[i].toLowerCase()=="r")
		{
			if(!validarReal(texto))
			{
				document.getElementById("msgError").value="No es un nmero";
				return false;
			}
		}
	}
	return true;
}

function isAnioBisiesto(iAnio)
{
	if(iAnio %4==0)
	{
		if(iAnio%100==0 )
		{
			if(iAnio%400==0)
			{
				return true;
			}
			return false;
		}
		return true;
	}
	return false;
}
///////////////////////////////////////////////////
////1 Tipo de Error; 2:Normal
function cambiarFondo(campo,tipo,color)
{
	if(tipo==1)
	{
		campo.style["backgroundColor"]=color;	
		campo.style["backgroundImage"]="url(../images/warning.gif)";
		campo.style["backgroundRepeat"]="no-repeat";
		campo.style["backgroundPosition"]="right";
	}
	else
	{
		color=color==null?"white":color;
		campo.style["backgroundColor"]=color;	
		campo.style["backgroundImage"]="none";
	}
}

function cambiarClase(e,cl)
{
	for(var q=0;q<e.attributes.length;q++)
	{
		if(e.attributes.item(q).nodeName=="class")
	  	{
			e.attributes.item(q).nodeValue=cl;			
		}
	}
}

function makeDate(dias,meses,anios,campoModificar)
{			
	var dia=dias.value;
	var mes=meses.value;
	var anio=anios.value;
	switch(parseInt(mes))
	{		
		case 2:
		{
			if(parseInt(dia)>=29)
			{				
				var iDia=parseInt(dia);				
				var iAnio=parseInt(anio);
				if(isAnioBisiesto(iAnio))
				{
					dias.options[28].selected=true;
					break;
				}				
				dias.options[27].selected=true;
			}
			break;
		}		
		case 4:
		case 6:
		case 9:
		case 11:
		{			
			if(parseInt(dia)>30)
			{
				dias.options[29].selected=true;
			}
			break;
		}		
	}
	dia=dias.value;
	var fecha=anio+"-"+mes+"-"+dia;	
	campoModificar.value=fecha;			
	return true;
}

function cambiarFondoFila(fila,color)
{
		fila.style["backgroundColor"]=color;
}

function cambiarFecha(fecha)//cambia la fecha de dd-mm-aa A aa-mm-dd
{
	var matFecha=fecha.split('-');
	var matResultado=new Array(matFecha[2],matFecha[1],matFecha[0]);
	return(matResultado.join('-'));
}

function innerPopUp(valor,texto,root)
{
	var div=document.getElementById("innerPopUp");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="innerPopUp";
		temp.style["visibility"]="hidden";
		temp.style["position"]="absolute";
		temp.style["width"]="100%";
		temp.style["height"]=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight+"px":document.body.clientHeight+"px";	
		temp.style["top"]="0";
		temp.style["left"]="0";		
		temp.style["backgroundColor"]="#000000";
		temp.style["opacity"]=".65";
		temp.style["filter"]="alpha(opacity=65)";
		temp.style["padding"]="0";
		temp.style["margin"]="0";		
		temp.style["zIndex"]=980;
		b.appendChild(temp);				
		inertarInnerPopUp(texto,root);
		innerPopUp(valor);
		return;
	}
	var div2=document.getElementById("campoTexto");
	if(valor)
	{
//		verTrancision("inputBox",0,65);
		div.style["height"]=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight+"px":document.body.clientHeight+"px";	
		div.style["visibility"]="visible";
		div2.style["visibility"]="visible";
		return;
	}
	div.style["visibility"]="hidden";
	div2.style["visibility"]="hidden";
}

function inertarInnerPopUp(texto,root)
{
	var div=document.getElementById("campoTexto");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="campoTexto";
		temp.style["visibility"]="hidden";
		temp.style["position"]="absolute";
		temp.style["width"]="500px";
		temp.style["height"]="300px";			
		temp.style["top"]=(Math.floor(document.documentElement.clientHeight/2)-150)+"px";
		temp.style["left"]=(Math.floor(document.documentElement.clientWidth/2)-250)+"px";
		temp.style["opacity"]="1";
		temp.style["filter"]="alpha(opacity=100)";
		temp.style["zIndex"]=990;
		temp.style["backgroundColor"]="#ffffff";	
		temp.style["padding"]="0";
		temp.style["margin"]="0";
		temp.style["overflow"]="hidden";
//		temp.style["overflow"]="hidden";		
		var html="<table width=\"100%\" height=\"100%\" style=\"padding:0;margin:0;border-spacing:0;border-collapse:collapse\">";
				html+="<tr>";
					html+="<td style=\"padding:0;margin:0;\">";
						if(root==null)
							html+="<img src=\"../images/header_comentarios.jpg\">";
						else
							html+="<img src=\"images/header_comentarios.jpg\">";
					html+="<td>";
				html+="</tr>";
				html+="<tr>";
					html+="	<td valign=\"middle\"><center>";
						html+="<table>";
							html+="<tr>";
								html+="<td>";
									html+="<div id=\"textoInterno\">";
										html+=texto;
									html+="</div><p>";								
								html+="</td>";
							html+="</tr>";
						html+="<table>";
					html+="</td>";					
				html+="</tr>";				
			html+="</table>";
		temp.innerHTML=html;
		div=temp;
		b.appendChild(temp);						
	}
	return div;
}

function innerPopUp2(valor,texto,root)
{
	var div=document.getElementById("innerPopUp");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="innerPopUp";
		temp.style["visibility"]="hidden";
		temp.style["position"]="absolute";
		temp.style["width"]="100%";
		temp.style["height"]=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight+"px":document.body.clientHeight+"px";	
		temp.style["top"]="0";
		temp.style["left"]="0";		
		temp.style["backgroundColor"]="#000000";
		temp.style["opacity"]=".65";
		temp.style["filter"]="alpha(opacity=65)";
		temp.style["padding"]="0";
		temp.style["margin"]="0";	
		temp.style["zIndex"]=980;
		//temp.style["zIndex"]=980;
		b.appendChild(temp);				
		inertarInnerPopUp2(texto,root);
		innerPopUp2(valor);
		return;
	}
	var div2=document.getElementById("campoTexto");
	if(valor)
	{
//		verTrancision("inputBox",0,65);
		div.style["height"]=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight+"px":document.body.clientHeight+"px";	
		div.style["visibility"]="visible";
		div2.style["visibility"]="visible";
		return;
	}
	div.style["visibility"]="hidden";
	div2.style["visibility"]="hidden";
}

function inertarInnerPopUp2(texto,root)
{
	var div=document.getElementById("campoTexto");
	if(div==null)
	{		
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		var b=document.getElementsByTagName("body").item(0);		
		var temp=document.createElement("div");
		temp.id="campoTexto";
		temp.style["visibility"]="hidden";
		temp.style["position"]="absolute";
		temp.style["width"]="500px";
		temp.style["height"]="300px";			
		temp.style["top"]=(Math.floor(document.documentElement.clientHeight/2)-150)+"px";
		temp.style["left"]=(Math.floor(document.documentElement.clientWidth/2)-250)+"px";
		temp.style["opacity"]="1";
		temp.style["filter"]="alpha(opacity=100)";
		temp.style["zIndex"]=990;
		temp.style["backgroundColor"]="#ffffff";	
		temp.style["padding"]="0";
		temp.style["margin"]="0";
		temp.style["overflow"]="hidden";
		var html="<table width=\"100%\" height=\"100%\" style=\"padding:0;margin:0;border-spacing:0;border-collapse:collapse\">";
				html+="<tr>";
					html+="<td style=\"padding:0;margin:0;\">";						
					html+="<td>";
				html+="</tr>";
				html+="<tr>";
					html+="	<td valign=\"middle\"><center>";
						html+="<table>";
							html+="<tr>";
								html+="<td>";
									html+="<div id=\"textoInterno\" style=\"z-index:1\">";
										html+=""+texto+"";
									html+="</div><p>";								
								html+="</td>";
							html+="</tr>";
						html+="<table>";
					html+="</td>";					
				html+="</tr>";				
			html+="</table>";
		temp.innerHTML=html;
		div=temp;
		b.appendChild(temp);						
	}
	return div;
}

function ventana(direccion,nombre)
{
	var parametros="width=910,height=580,directories=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=yes";
	window.open(direccion,nombre,parametros);
}

function ventana2(direccion,nombre)
{
	var parametros="width=400,height=200,directories=no,location=no,status=no,toolbar=no,resizable=yes,scrollbars=yes";
	window.open(direccion,nombre,parametros);
}