function $(v) {return document.getElementById(v)}
function $t(x,v){return x.getElementsByTagName(v)}
function $a(x,v){return x.getAttribute(v)}

function checkForm()
{
	if(document.f1.nombre.value=='' || document.f1.apellidos.value=='' ||   document.f1.direccion.value=='' || document.f1.cp.value=='' || document.f1.localidad.value=='' || document.f1.provincia.value=='' || document.f1.telefono.value=='' || document.f1.email.value=='')
	{
		alert('Por favor, rellene todos los campos del formulario de datos de envío');
		return;
	}
	if(document.f1.factura.checked)
	{
		if(document.f1.e_nombre.value=='' || document.f1.e_cif.value=='' ||   document.f1.e_direccion.value=='' || document.f1.e_cp.value=='' || document.f1.e_localidad.value=='' || document.f1.e_provincia.value=='' || document.f1.e_telefono.value=='' || document.f1.e_email.value=='')
		{
			alert('Por favor, rellene todos los campos del formulario de datos de facturación');
			return;
		}	
	}
	document.f1.submit();
}

function ponResumen()
{
	$('ifr').src='resumen.php?rand='+Math.random();
}

function aniadeProd(id,cant)
{
	$('carrito1').innerHTML="<br/><br/><br/><br/>Actualizando carrito...";
	$('ifr').src='aniadeProd.php?id='+id+'&cantidad='+cant+'&rand='+Math.random();
}

function infoProd(id)
{
	$('info').innerHTML="Cargando producto...";
	$('info').style.display='block';
	$('lista').style.display='none';
	$('ifr').src='datosProd.php?id='+id+'&rand='+Math.random();
}

function volver()
{
	$('info').style.display='none';
	$('lista').style.display='block';
}

function ponYoutube(codigo)
{
	$('tablaFlash').style.display='block';
	$('contFlash').innerHTML="<object width='425' height='355'><param name='movie' value='http://www.youtube.com/v/"+codigo+"&autoplay=1'></param><param name='wmode' value='transparent'></param><embed src='http://www.youtube.com/v/"+codigo+"&autoplay=1' type='application/x-shockwave-flash' wmode='transparent' width='425' height='355'></embed></object>";
}
function ponFlash(fichero,ancho,alto)
{
	$('tablaFlash').style.display='block';
	$('contFlash').innerHTML="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+ancho+"' height='"+alto+"' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='./_img_admin/"+fichero+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='./_img_admin/"+fichero+"' quality='high' bgcolor='#ffffff' width='"+ancho+"' height='"+alto+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />	</object>";
}
function cierraFlash()
{
	$('contFlash').innerHTML="";
	$('tablaFlash').style.display='none';
}

var nImgIntro=0;

function cargaImgIntro()
{
	if(++nImgIntro==16)
		intro();
}

function intro()
{
	fadeOut('cargando',10,'intro2()');
}

function intro2()
{
	fadeIn('fondo',10,'intro3()');
}

function intro3()
{
	fadeIn('lat',10,'intro4()');
}

function intro4()
{
	fadeIn('tit',10,'intro5()');
}

function intro5()
{
	var t=$('main');
	t.style.cursor='pointer';
	t.onclick=function(){window.location.href='main.php'};
	setTimeout("window.location.href='main.php'",10000);
}


var nImg=14;
var imgAct=new Array();
var destino=0;
var nueva=0;
function cambiaImg()
{
	destino=Math.floor(Math.random()*4);
	nueva=Math.floor(Math.random()*nImg);
	while (imgAct[0]==nueva || imgAct[1]==nueva || imgAct[2]==nueva || imgAct[3]==nueva)
	{
		nueva=Math.floor(Math.random()*nImg);
	}
	fadeOut('img'+destino,10,'cambiaImg2()');
}

function cambiaImg2()
{

	$('img'+destino).src='img/top/'+nueva+'.jpg';
	imgAct[destino]=nueva;
	fadeIn('img'+destino,10,'cambiaImg3()');
}

function cambiaImg3()
{
	setTimeout('cambiaImg()',5000);
}



var ob=null;
var op=100;
var callback='';
var step=0;
var maxOp=100;

function fadeOut(id,val,call)
{
	op=maxOp;
	ob=$(id);
	step=val;
	callback=call;
	setTimeout("hazFadeOut()",25);
}

function hazFadeOut()
{
	op-=step;
	if(op<=0)
	{
		K_trans(ob,0);
		ob.style.display='none';
		if(callback)
			eval(callback);
	}
	else
	{
		K_trans(ob,op);
		setTimeout("hazFadeOut()",25);
	}
}

function fadeIn(id,val,call)
{
	op=0;
	ob=$(id);
	ob.style.display='block';
	step=val;
	callback=call;
	setTimeout("hazFadeIn()",25);
}

function hazFadeIn()
{
	op+=step;
	if(op>=maxOp)
	{
		K_trans(ob,maxOp);
		if(callback)
			eval(callback);
	}
	else
	{
		K_trans(ob,op);
		setTimeout("hazFadeIn()",25);
	}
}

function K_trans(obj,opacity)
//By Richard Rutter
{
 	opacity = (opacity == 100)?99.999:opacity;
  	obj.style.KhtmlOpacity = opacity/100;
  	obj.style.filter = "alpha(opacity:"+opacity+")";
  	obj.style.MozOpacity = opacity/100;
  	obj.style.opacity = opacity/100;
}
