var numero=0;
var tiempo=0;
var nnumero=0;
var unumero=0;

function iniciar(){
	numero=0;
	tiempo=0;
}

function rota(){
	nnumero=0;
}

function rota2(){
	unumero=0;
}

function cambio_menu(num,tot){
	clearTimeout(tiempo);
	$('footer').show();
	for (var i=1;i<=tot;i++){
		document.getElementById("dmenu"+i).className = "normal";
	}
	if(num!=0){
		document.getElementById("dmenu"+num).className = "selected";
	}
}

function cambio_noticia(num,tot){
	clearTimeout(tiempo);
	for (var i=1;i<=tot;i++){
		document.getElementById("td"+i).className = "normal";
	}
	if(num!=0){
		document.getElementById("td"+num).className = "selected";
	}
}

function cambio_modelo(num,tot){
	for (var i=1;i<=tot;i++){
		document.getElementById("dmodelos"+i).className = "normal";
	}
	if(num!=0){
		document.getElementById("dmodelos"+num).className = "selected";
	}
}

function open_vista(url,contenedor,base){	
	if(url==''){
		document.getElementById(contenedor).innerHTML="";
	}
	else{
		new Ajax.Updater({success: contenedor,failure: "error"}, url,
					{
						evalScripts:true,
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><br/><br/><br/><br/><br/><div style="height:300px;"><img src="http://ecuawagen.misiva.com.ec/imagenes/iconos/cargando.gif"/></div></center>';
						}
					});
	}
}

function open_vista2(url,contenedor){	
	if(url==''){
		document.getElementById(contenedor).innerHTML="";
	}
	else{
		new Ajax.Updater(contenedor, url,
					{
						evalScripts:true,
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><br/><br/><br/><br/><br/><div style="height:200px;"><img src="http://ecuawagen.misiva.com.ec/imagenes/iconos/cargando.gif"/></div></center>';
						}
					});
	}
}

function open_vista3(url2,contenedor2,url,contenedor,fondo){	
	if(url==''){
		document.getElementById(contenedor).innerHTML="";
	}
	else{
		if(fondo!='')
			document.body.style.backgroundImage='url('+fondo+')';
		new Ajax.Updater({success: contenedor,failure: "error"}, url,
					{
						evalScripts:true,
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><br/><br/><br/><br/><br/><div style="height:200px;"><img src="http://ecuawagen.misiva.com.ec/imagenes/iconos/cargando.gif"/></div></center>';
						},
						onSuccess: function(response){
							open_vista(url2,contenedor2);
						}
					});
	}
}

function cambio_modelos(total){
	for (var j=1;j<=total;j++){
		document.getElementById("imodelos"+j).className = "normal";
		document.getElementById("inombres"+j).className = "normal2";
	}
	document.getElementById("imodelos"+numero).className = "selected";
	document.getElementById("inombres"+numero).className = "selected2";
	numero++;
	if(numero>total)
		numero=1;
	tiempo=setTimeout("cambio_modelos("+total+")", 5000);
}

function rotar(numero,movimiento,total,f1,f2,ver,dnombre){
	$(f1).show();
	$(f2).show();
	ver--;
	if(numero+movimiento<=0){
		$(f1).hide();
	}
	if(numero+ver+movimiento>=total-1){
		$(f2).hide();
	}
	for(k=0;k<total;k++){
		if(k<numero+movimiento || k>numero+ver+movimiento){
			$(dnombre+k).hide();
		}
		else{
			$(dnombre+k).show();
		}	
	}
}

function enviar_forma(forma,accion,contenedor){
	new Ajax.Updater(contenedor, accion,
					{
						evalScripts:true,
						method: 'post',
						parameters: $(forma).serialize(), 
						onLoading: function(request){ 
							document.getElementById(contenedor).innerHTML='<center><br/><br/><br/><br/><br/><br/><div style="height:300px;"><img src="http://ecuawagen.misiva.com.ec/imagenes/iconos/cargando.gif"/></div></center>';
						}
					});
}

function cargar_combo(contenedor,url,id){
	var valor=document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	
	if(valor!=''){
		new Ajax.Updater(contenedor, url+valor,
				{
					onLoading: function(request){ 
						document.getElementById(contenedor).innerHTML='<center>Cargando...</center>';
					},
				});
	}
}

function show_roll(contenedor,imagen){
	$(contenedor + "_image").innerHTML="<img src="+imagen+" />";
	Effect.SlideDown(contenedor,{ duration: 1.5 });
}

function hide_roll(contenedor){
	$(contenedor + "_image").innerHTML="";
	$(contenedor).hide();
}
