// JavaScript Document
var imagenes=null;
var automatico=true;
var ancho=null;
var alto=null;
var imghasta=0;
var imgdesde=0;
var imgmostrar=0;
var sig;
var ant;
var sigf=false;
var antf=false;
var tiempo=0;


var camposformulario=null;

/**************************************Galeria de Imagenes******************************/
function GaleriaImagenes()
{
	if(arguments.length>5)
	{
		tiempo=arguments[arguments.length-4];
		imghasta=arguments[arguments.length-3];
		imgmostrar=arguments[arguments.length-3];
		ancho=arguments[arguments.length-2];
		alto=arguments[arguments.length-1];
		
		imagenes=new Array(arguments.length-4);
	
		for(var i=0;i<imagenes.length;i++)
		{
			imagenes[i]=arguments[i];
		}
		verImagenes();
		
	}
	else
	{
		alert("Error En La Longitud de Parametros");
	}
}
function getDiv()
{
	var div=document.getElementById(arguments[0]);
	return div;
}


function existeDiv()
{	
	if(getDiv(arguments[0])==null)
	{
		alert("cree un Div <div id=''></div>");
		return false;
	}
	return true;
}

function verImagenes()
{
	var diseno="";
	if(existeDiv("galeria"))
	{
		diseno+="<div align='center'>";
		diseno+="<table border='0' style='top:250px;'>";
		diseno+="<tr>";	
		diseno+="<td>"; 
		diseno+="<div onclick='anterior();'><img src='lib/flechas/a.png' width='30 'height='30'/></div>";
		diseno+="</td>";
		for(var i=imgdesde;i<imghasta;i++)
		{
			if(imagenes[i]!=null)
			{
				diseno+="<td>";
				diseno+="<div onclick='cambioautomatico();' style='height:"+alto+"px;border: 5px solid #999999; -webkit-border-radius:15px;-moz-border-radius: 15px;'><img id='im"+i+"' src='"+imagenes[i]+"' width='"+ancho+"px' height='"+alto+"px'/></div>";
				diseno+="</td>";
			}
				
		} 
		diseno+="<td>"; 
		diseno+="<div onclick='siguiente();'><img src='lib/flechas/s.png' width='30 'height='30'/></div>";
		diseno+="</td>";  
		diseno+="</tr>";
		diseno+="</table></div>";
		getDiv("galeria").innerHTML=diseno;
		sig=setTimeout("siguiente()",tiempo);
	}	
}

function siguiente()
{
	if(automatico)
	{
		if(!sigf){
			
				if(imghasta<imagenes.length)
				{					
					moversiguiente();
				}
				else
				{sigf=true;antf=false;clearTimeout(sig);moveranterior();}
		}
	}
	else
	{
		if(imghasta<imagenes.length)
		{moversiguiente();clearTimeout(sig);clearTimeout(ant);}	
	}
}
function moversiguiente()
{
	imgdesde=imghasta;
	imghasta+=imgmostrar;
	verImagenes();	
}

function anterior()
{
	if(automatico)
	{
		if(!antf)
		{
			if(imgdesde>imagenes.length-imagenes.length)
			{
				moveranterior();
			}
			else
			{antf=true;sigf=false;clearTimeout(ant);moversiguiente();}
		
		}
	}
	else
	{
		if(imgdesde>imagenes.length-imagenes.length)
		{moveranterior();clearTimeout(ant);clearTimeout(sig);}
	}

}

function moveranterior()
{
	imghasta-=imgmostrar;
	imgdesde-=imgmostrar;			
	verImagenes();
	if(automatico)
	{ant=setTimeout("anterior()",tiempo);}
}


function cambioautomatico()
{
	automatico=!automatico;	
	if(!automatico)
	{
		clearTimeout(ant);
		clearTimeout(sig);	
	}
	else
	{
		if(!sigf)
		{
			sig=setTimeout("siguiente()",tiempo);
		}
		else
		{
			ant=setTimeout("anterior()",tiempo);
		}
	}
	
}

/************************************Validar Correo**************************************/
function validarcorreo()
{
  re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(arguments[0]))    {
        return false;
    }else{
        return true;
    }
}
/************************************Es Numero**************************************/
function esnumero()
{
	if(/^([0-9])*$/.test(arguments[0]))
		return true;
	
	return false;
}
/************************************formularios**************************************/
function formularios()
{
	var tipo=null;
	var c=0;
	
	if(document.forms.length!=0)
	{
		
		for(var i=0;i<document.forms.item(document.forms.length-1).elements.length;i++)
		{
			tipo=document.forms.item(document.forms.length-1).elements.item(i).type;
			if(tipo=="text")
			{c++;}
			
		}
		camposformulario=new Array(c);
		for(var i=0;i<camposformulario.length;i++)
		{
			camposformulario[i]=document.forms.item(document.forms.length-1).elements.item(i).value;
		}

	}
	return  camposformulario;
}
/************************************Ajax**************************************/
function ajax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function operacionajax()
{
	var rutas=arguments[0];
	var divs=arguments[1];
	var Object=ajax();
	Object.open("POST",rutas,true);
	Object.onreadystatechange=function() {
	 	if (Object.readyState==4) {		
			getDiv(divs).innerHTML=Object.responseText;		
		}
	}
		Object.send(null);	
}

/**********************************Div**************************************/
function div()
{
	this.id=arguments[0];
	this.estilo=arguments[1];
	this.evento=arguments[2];
}

function estilodiv()
{
	this.tipo=arguments[0];
	this.fondo_color=arguments[1];
	this.w=arguments[2];
	this.h=arguments[3];
	this.x=arguments[4];
	this.y=arguments[5];
	this.img=arguments[6];
	this.bw=arguments[7];
	this.bm=arguments[8];
	this.borde=arguments[9];
	this.tborde=arguments[10];
	this.cborde=arguments[11];
}

function eventodiv()
{
	this.cli=arguments[0];
	this.dbcli=arguments[1];
	this.tab=arguments[2];
	this.tpre=arguments[3];
	this.tarr=arguments[4];
	this.mab=arguments[5];
	this.mmov=arguments[6];
	this.msa=arguments[7];
	this.mover=arguments[8];
	this.movup=arguments[9];
}

function creardiv()
{
	var es=new estilodiv("absolute","red",50,50,200,200,"lib/flechas/s.png",10,10,5,"solid","green");
	var ev=new eventodiv("alert(\"holaa\")","","","","","","alert(\"efecto mouseover\")","","");
	var di=new div("uno",es,ev);

	var diseno= "<div id='"+di.id+"' style='position:"+di.estilo.tipo+";width:"+di.estilo.w+"px;height:"+di.estilo.h+"px;left:"+di.estilo.x+"px;top:"+di.estilo.y+"px;background-color:"+di.estilo.fondo_color+";background-image: url("+di.estilo.img+");-webkit-border-radius:"+di.estilo.bw+"px;-moz-border-radius:"+di.estilo.bw+"px;border:"+di.estilo.borde+"px  "+di.estilo.tborde+" "+di.estilo.cborde+";' onclick='"+di.evento.cli+"' ondblclick='"+di.evento.dbcli+"' onkeydown='"+di.evento.tab+"' onkeypress='"+di.evento.tpre+"' onkeyup='"+di.evento.tarr+"' onmousedown='"+di.evento.mab+"' onmousemove='"+di.evento.mmov+"' onmouseout='"+di.evento.msa+"' onmouseover='"+di.evento.mover+"' onmouseup='"+di.evento.movup+"'></div>";
	document.writeln(diseno);
	agregarcontenido(di.id);
	
}

function agregarcontenido()
{
	//alert(existeDiv());
}
