var peticion_activa=0;
function consulta_ajax(id,url){	
	var objajax=new Ajax.Updater(id, url, {asynchronous:true, evalScripts: true,
			onCreate: function(){
				mostrar_mensaje("Informacion","Cargando...","info");
			},
			onComplete:function(){
				ocultar_mensaje();
			}
	});
}
function GetValueSelect(id){
	return $(id).options[$(id).selectedIndex].value;
}
function exeAjax(url,mgs){
	if(peticion_activa==0){		
		var objajax=new Ajax.Request(url, {asynchronous:true, evalScripts: true,
				onCreate: function(){
					peticion_activa=1;
					mostrar_mensaje("Informacion",mgs,"info");
				},
				onComplete:function(request){
					peticion_activa=0;
					eval(request.responseText);					
					objeto_tiempo = setInterval(ocultar_mensaje, 1800);
				}
		});
	}else{
		alert("Por favor espere hay una peticion en Proceso");
	}
}
function getCaptcha(id,path){
	$(id).src="GetCaptcha/"+Math.round(Math.random() * 1000)+"/"+path;
}
function addfilacarritoquick(contenido){		
	tab = $('productoscarritoquick');
	fila = tab.insertRow(tab.rows.length);
	celda=fila.insertCell(fila.cells.length);
	celda.innerHTML=contenido;
}
var theTop = 200;
var old = theTop;
function mostrar_mensaje(titulo,mensaje,tipo){	
	$("mensajes").style.display='block';
	$("mensajes").innerHTML="<div class='ventanamensaje'>\n<div class='titulo'>\n<span>"+titulo+"</span>\n</div>\n<div class='contenido1'>\n<table class='mensaje'>\n<tr>\n<td>\n<img src='images/mensajes/"+tipo+"'.png>\n</td>\n<td>"+mensaje+"</td>\n</tr>\n</table>\n</div>\n</div>";
	centrar_div("mensajes");			
}
function centrar_div(id){	
	if (window.innerHeight)
	{
        var yScrollPos = window.pageYOffset;
        var screenWidth = window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		var yScrollPos = document.documentElement.scrollTop;
        var screenWidth = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
        var yScrollPos = document.body.scrollTop;
        var screenWidth = document.body.clientWidth;
	}
	if (yScrollPos < theTop)
        yScrollPos = theTop;
	else
        yScrollPos += 200;
        
	if (yScrollPos == old)
	{
		$(id).style.top = yScrollPos;
	}
	$(id).style.top = yScrollPos+'px';
	old = yScrollPos;
    var objWidth = /*getElementWidth(elementID);*/200;
    var objHeight = /*getElementHeight(elementID);*/100;
    $(id).style.left =((screenWidth-objWidth) / 2)+'px';
}
function ocultar_mensaje(){
	$("mensajes").innerHTML="";
	$("mensajes").style.display='none';
	clearInterval(objeto_tiempo);
}
function registrar(form,respuesta,url){
	//alert(form);
	var params='';
	if(peticion_activa==0){
		peticion_activa=1;
		if($(form))
    	 params= Form.serialize($(form));
    	new Ajax.Updater(respuesta, url, {asynchronous:true, parameters:params, evalScripts: true, onComplete:function(){peticion_activa=0;}});
	}
    else{
		alert("Por favor espere hay una peticion pendiente...");
	}	
	return false;
}
var ventana_activa=null;
function open_window(url,ancho,alto){
	if(ventana_activa==null|| ventana_activa.closed){
		ventana_activa=window.open(url,"ventana",'height='+alto+', width='+ancho+',toolbar=no,directories=no,status=no,menubar=no,resizable=no,modal=yes,scrollbars=yes,left='+((screen.width/2)-(ancho/2))+',top='+((screen.height/2)-(alto/2)));
		//ventana_activa.moveTo((screen.width/2)-(ancho/2),(screen.height/2)-(alto/2));	
	}
	else{
		alert('Ya existe una ventana abierta debe cerrarla primero');
		ventana_activa.focus();
	}
}