//para insertar flash
function pongoflash(pelicula,ancho,alto){
		document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+ancho+"' height='"+alto+"'>");
		document.write("<param name='movie' value='"+pelicula+"' />");
		document.write("<param name='quality' value='high' />");
		document.write("<embed src='"+pelicula+"' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+ancho+"' height='"+alto+"'></embed>");
		document.write("</object>");
}

//para insertar flash transparente
function flash(pelicula,ancho,alto){
		document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+ancho+"' height='"+alto+"'>");
		document.write("<param name='movie' value='"+pelicula+"' />");
		document.write("<param name='quality' value='high' />");
		document.write("<param name='wmode' value='transparent' />");
		document.write("<embed src='"+pelicula+"' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' wmode='transparent' width='"+ancho+"' height='"+alto+"'></embed>");
		document.write("</object>");
}

function pongoflashmenu(pelicula,ancho,alto){
		var URL = document.location.pathname;
		URL = URL.substring(1,URL.length);
		document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+ancho+"' height='"+alto+"'>");
		document.write("<param name='movie' value='"+pelicula+"?activo="+URL+"' />");
		document.write("<param name='quality' value='high' />");
		document.write("<param name='wmode' value='transparent' />");
		document.write("<embed src='"+pelicula+"?activo="+URL+"' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' wmode='transparent' width='"+ancho+"' height='"+alto+"'></embed>");
		document.write("</object>");
}

//para insertar pop-up centrados
function popup(pag,alto,ancho){

resx = screen.width;
resy = screen.height;
posx = (resx-ancho)/2
posy = (resy-alto)/2



propiedades="width="+ancho+", height="+alto+",top="+posy+",left="+posx+",scrollbars=yes, toolbar=no";
window.open(pag,"x",propiedades)

}

function botogaleria(idseccion){
 var seccion;
 
 seccion = document.getElementById(idseccion);
 seccion.innerHTML = "<span class='menuseleccionado'>"+idseccion+"</span>"  
}

function setH() {

	if(!document.getElementById('lateral-izquierdo')){
		var maxH = Math.max(document.getElementById('lateral-derecho').offsetHeight,document.getElementById('centro').offsetHeight);	
		document.getElementById('lateral-derecho').style.height=maxH+'px';
		document.getElementById('centro').style.height=maxH+'px';
	}
	
	if(!document.getElementById('lateral-derecho')){
		var maxH = Math.max(document.getElementById('lateral-izquierdo').offsetHeight,document.getElementById('centro').offsetHeight);	
		document.getElementById('lateral-izquierdo').style.height=maxH+'px';
		document.getElementById('centro').style.height=maxH+'px';
	}

	if(!document.getElementById('centro')){
		var maxH = Math.max(document.getElementById('lateral-izquierdo').offsetHeight,document.getElementById('lateral-derecho').offsetHeight);	
		document.getElementById('lateral-izquierdo').style.height=maxH+'px';
		document.getElementById('lateral-derecho').style.height=maxH+'px';
	}
	
	//altura top
	topH = document.getElementById("header").offsetHeight;
	topH = 0;
	
	if(document.getElementById('lateral-izquierdo') && document.getElementById('centro') && document.getElementById('lateral-derecho')){
		var maxH = Math.max(document.getElementById('lateral-izquierdo').offsetHeight, document.getElementById('lateral-derecho').offsetHeight, document.getElementById('centro').offsetHeight);	
		maxH+=topH;
		document.getElementById('lateral-izquierdo').style.height=maxH+'px';
		document.getElementById('lateral-derecho').style.height=maxH+'px';
		document.getElementById('centro').style.height=maxH+'px';
		
		document.getElementById('centro').style.height=maxH+'px';
	}
}
window.onload=setH;

function validaAddCarrito(id_prod, cantprod) {
	if(id_prod > 0) {
		if(isNaN(cantprod)){
			alert("Debe ingresar un valor numérico en la cantidad a pedir.");
			return 1;
		} else {
			if(cantprod == 0) {
				alert("La cantidad a pedir no puede ser CERO.");
				return 1;
			} else {
				if(cantprod.length == 0) {
					alert("No ha completado la cantidad a pedir.");
					return 1;
				}else {
					return 0;
				}
			}
		}
	} 
	return 0;
}


function recalcular(){
	//theform = document.formCarrito;
	theform=document.getElementById("formCarrito");
	tamano = theform.elements.length;
	//alert(tamano);
	pass = true;
	intP = 0;

	for (i=0;i<tamano;i++){
		if(theform.elements[i].name=="txtcantidad"){
			intP = parseInt(theform.elements[i].value);
			if (isNaN(intP)){
				pass = false;
				break;
			}else{
				theform.elements[i].value = Math.abs(intP);
			}

		} 
	}
	
	var Acantarray = "";
	var Aprecioarray = "";
	var Aidarray = "";
	
	for(i=0; i<tamano;i++){
		if(theform.elements[i].name == "txtcantidad"){
			Acantarray+=theform.elements[i].value + ",";
		}
		if(theform.elements[i].name == "txtprecio"){
			Aprecioarray+=theform.elements[i].value + ",";
		}
		if(theform.elements[i].name == "id"){
			Aidarray+=theform.elements[i].value + ",";
		}
	}
	Acantarray = Acantarray.substring(0,Acantarray.length-1);
	Aprecioarray = Aprecioarray.substring(0,Aprecioarray.length-1);
	Aidarray = Aidarray.substring(0,Aidarray.length-1);
	//alert(Acantarray)
	if (!pass) {
		alert("Las cantidades deben ser valores numéricos")	
	}else{
		document.getElementById("cantarray").value = Acantarray;
		document.getElementById("precioarray").value = Aprecioarray;
		document.getElementById("idarray").value = Aidarray;
		document.formCarrito.submit();
	}


}

function confirmaPedido() {
	document.formCarrito.action  =  "finalizarPedido.php"
	document.formCarrito.submit();
}

function validoClave(){
	pwd = document.getElementById("clave");
	pwd1 = document.getElementById("clave1");
	pwd2 = document.getElementById("clave2");
	error = "";
	pass=true;
	if(pwd.value == "" || pwd1.value == "" || pwd2.value == "") {
		error+="Debe completar todos los datos para realizar\nel cambio de clave.";
		pass=false;
	} else {
		if(pwd1.value != pwd2.value){
			error+="Las contraseñas ingresadas no son iguales.\nPor favor corríjalas y vuelva a intentar.";
			pass=false;
		}
	}
	
	if(!pass){
		alert(error);
		return false;
	}
	return true;
}
function cambioClave(){
	usuario = document.getElementById("usuario");
	email = document.getElementById("email");
	error = "";
	pass=true;
	if(usuario.value == "" || email.value == "") {
		error+="Debe completar todos los datos para recuperar la clave.";
		pass=false;
	} 
	if(!pass){
		alert(error);
		return false;
	}
	return true;
}

function mainmenu(){
	$(" #nav2 ul ").css({display: "none"}); // Opera Fix
	$(" #nav2 li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(100);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});

	$(" #nav ul ").css({display: "none"}); // Opera Fix
	$(" #nav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(100);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});
}
$(document).ready(function(){					
	mainmenu();
});



function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
