var cuan, pad, cuan1, cuan2, pag, rest, ide=0;
var activa, activa2;

function menu(id){
	cuan = 82;
	pad = 52;
	cuan1 = 0;
	cuan2 = 253;
	rest = 17;
	window.clearInterval(activa);
	window.clearInterval(activa2);
	for (i=1;i<5;i++){
		document.getElementById("sopc"+i).style.top="55px";	
		document.getElementById("opc"+i).style.height="84px";
		document.getElementById("opc"+i).style.top="253px";
	}
	
	if (id != ide){
		activa = window.setInterval("menu2("+id+")",1);	
	}else{
		ide=0;
	}
}

function menu2(id){
	cuan = cuan - 2;
	pad = pad - 2;
	if (pad > 0){
		document.getElementById("sopc"+id).style.top=""+pad+"px";		
	}
	if (cuan > 17){
		document.getElementById("opc"+id).style.height=""+cuan+"px";
	}else{
		window.clearInterval(activa);
		document.getElementById("opc"+id).style.paddingTop="0px";
		activa2 = window.setInterval("menu3("+id+")",20);
	}
}

function menu3(id){
	cuan2 = cuan2 - 2;
	if (cuan2 > 233){
		document.getElementById("opc"+id).style.top=""+cuan2+"px";
	}
	else{
		ide = id;
		window.clearInterval(activa2);
	}
}

function menue(num, id){
	cuan = 82;
	pad = 52;
	cuan1 = 0;
	cuan2 = 191;
	rest = 17;
	window.clearInterval(activa);
	window.clearInterval(activa2);
	for (i=1;i<5;i++){
		if (i != num){
			document.getElementById("sopc"+i).style.top="55px";	
			document.getElementById("iopc"+i).style.height="84px";
			document.getElementById("iopc"+i).style.top="191px";
		}
	}
	
	if (id != ide){
		activa = window.setInterval("mover("+id+")",1);	
	}else{
		ide=0;
	}
}

function mover(id){
	cuan = cuan - 2;
	pad = pad - 2;
	if (pad > 0){
		document.getElementById("sopc"+id).style.top=""+pad+"px";		
	}
	if (cuan > 16){
		document.getElementById("iopc"+id).style.height=""+cuan+"px";
	}else{
		window.clearInterval(activa);
		document.getElementById("iopc"+id).style.paddingTop="0px";
		activa2 = window.setInterval("subir("+id+")",20);
	}
}

function subir(id){
	cuan2 = cuan2 - 2;
	if (cuan2 > 174){
		document.getElementById("iopc"+id).style.top=""+cuan2+"px";
	}
	else{
		ide = id;
		document.getElementById("iopc"+id).style.top="174px";
		window.clearInterval(activa2);
	}
}

function ventana(dir, w, h){
	window.open(dir, "",",scrollbars=1,height="+h+",width="+w);	
}

function ventanav(dir, w, h){
	window.open(dir, "",",scrollbars=none,resizable=no,height="+h+",width="+w);	
}

function vaf(){
	obj = document.form;
	err = "";
	
	if (obj.numf.value == "") err = "Número: campo obligatorio";
	if (isNaN(parseFloat(obj.numf.value))) err = "Número: formato incorrecto";
	
	if (err != ""){
		alert(err);	
	}else{
		document.form.submit();	
	}
}

function vnum(f, b, num){
	obj = document.form;
	nv = 0;
	ni = 0;
	err = "";
	
	for (i=0;i<num;i++){
		if (eval("obj.numf"+i+".value") == "") nv = 1;
		if(isNaN(eval("obj.numf"+i+".value"))) ni = 1;
	}
	
	if (nv != 0) err = "Debe introducir número de copias para cada foto del pedido";
	if (ni != 0) err += "\nFormato incorrecto en alguno de los campos de número de copias";
	
	if (err != ""){
		alert(err);	
	}else{
		eval("obj."+b+".click();");	
	}
}

function delet(num, t, b){
	obj = document.form;
	eval("obj."+t+".value="+num+";");
	//obj.ndelet.value = num;
	eval("obj."+b+".click();");
}

function centrar(){
	var h=555;
	var mt=(parseInt(fsp.windowHeight())-h)/2;
	mt=(mt<0)?0:mt;
	document.getElementById("marco").style.marginTop=mt+"px";
}

var fsp={
	windowHeight:function(){
		if(window.innerHeight){
			return window.innerHeight;
    	}else if(document.body.parentElement.clientHeight){ 
			return document.body.parentElement.clientHeight;
		}else if(document.body && document.body.clientHeight){ 
			return document.body.clientHeight;
		}
		return 0;	
	},
	windowWidth:function(){
    	if (window.innerWidth) {
        	return window.innerWidth;
    	}else if (document.body.parentElement.clientWidth){
			return document.body.parentElement.clientWidth;
		}else if (document.body && document.body.clientWidth) {
        	return document.body.clientWidth;
		}
    	return 0;
	},
	addEvent:function(f,g,k){
		if(f.addEventListener){
			f.addEventListener(g,k,false);
		}else if(f.attachEvent){
			f.attachEvent("on"+g,k)
		}
	}
};

/*fsp.addEvent(window,"load",centrar);
fsp.addEvent(window,"resize",centrar);*/