function paypaypal(fac)
{
	var data = post('carrito-informacion.php?if='+fac,'paypal=pagar');

	document.getElementById('html_paypal').innerHTML = data;
	document.getElementById('paypaypal').submit();
}

function confirmaBono()
{
	var texto = '';
	
	if(document.getElementById("confirmar_nombre").value == ""){
		texto+= 'Debe completar el Nombre obligatoriamente.\n';
	}
	
	if(document.getElementById("confirmar_nombre").value == ""){
		texto+= 'Debe completar la Fecha obligatoriamente.\n';
	}
	
	if(texto)
	{
		alert(texto);
	}
	else
	{
		document.getElementById('confirma_bono').submit();
	}
}

function cambioBonum()
{
	var texto = '';
	
	if(document.getElementById("identificador").value == ""){
		texto+= 'Debe completar el numero de bonum obligatoriamente.\n';
	}
	
	if(document.getElementById("email").value == ""){
		texto+= 'Debe completar el E-mail obligatoriamente.\n';
	}
	
	if(texto)
	{
		alert(texto);
	}
	else
	{
		document.getElementById('send_form').submit();
	}
}

function prodRel(id_productos,p)
{
	var data = post('ajax.php?p='+p,'id_productos='+id_productos+'&accion=prodRel');
    
	var explode = eval(data);
    
    
    document.getElementById('rel_prods').innerHTML = explode[0];
    document.getElementById('rel_pie').innerHTML   = explode[1];
    document.getElementById('rel_pages').innerHTML = explode[2];
}

function search_adv(host)
{
	var categorias = document.getElementById('iid_categorias').value;
	var zonas      = document.getElementById('iid_zonas').value;
	var precios    = document.getElementById('iid_precios').value;
	
	var url = '';
	if(categorias != '')
	{
		url = categorias+'/';
	}
	if(zonas != '')
	{
		url+= zonas+'/';
	}
	if(precios != '')
	{
		url+= precios+'/';
	}
	
	if(url != '')
	{
		var x = host+url.substr(0,((url.length)-1));
		document.location.href = x;
	}
}

function comprar()
{
	var texto = '';
	
	if(document.getElementById("email").value == ""){
		texto+= 'Debe completar el email obligatoriamente.\n';
	}
	else if(!isMail("email")){
		texto+= 'Debe ingresar una direccion de correo electronico valida.\n';
	}
	
	if(!document.getElementById('forma_pago_checkout'))
	{
		var metodo = document.getElementById('forma_pago');
		if(metodo.options[metodo.selectedIndex].value == 0){
			texto+= 'Debe seleccionar la forma de pago.\n';
		}
	}
	
	if(!document.getElementById('condiciones').checked){
		texto+= 'Debe aceptar nuestra Politica de Privacidad y Condiciones Generales.\n';
	}
	
	if(texto)
	{
		alert(texto);
	}
	else
	{
		document.getElementById('compra').value = 'ok';
		document.getElementById('carrito_main').submit();
	}
}

function showRefresh(id)
{
	document.getElementById('carrito_main').submit();
	return true;
	//document.getElementById('dd1').style.display = 'none';
	//document.getElementById('dd2').style.display = 'none';
	
	/*
	document.getElementById('dd3').style.display = 'none';

	if(document.getElementById('con_caja').checked)
	{
		document.getElementById('con_caja_form').style.display = 'block';
	}
	else
	{
		document.getElementById('con_caja_form').style.display = 'none';
	}
	
	var campo = document.getElementById('update_option_'+id);
	campo.innerHTML = '<a href="javascript:document.getElementById(\'carrito_main\').submit()" style="color:green">Actualizar</a>';
	*/
}

function conFactura()
{
	var campo = document.getElementById('factura');
	if(campo.options[campo.selectedIndex].value==0)
	{
		document.getElementById('factura_form').style.display = 'none';
	}
	else
	{
		document.getElementById('factura_form').style.display = 'block';
	}
}

function mapProducts(id)
{
    var data = post('ajax.php','id_mapas='+id+'&accion=mapProducts');
    
    document.getElementById('mapa').innerHTML = data;
}

function mailRecomandarAmigo()
{
	var texto = '';

	if(document.getElementById("mail").value == ""){
		texto+= 'Debe completar el campo "Mail de amigo/a" obligatoriamente.\n';
	}
	else if(!isMail("mail")){
		texto+= 'El "Mail de amigo/a ingresado es incorrecto.\n';
	}
	
	if(document.getElementById("nombre").value == ""){
		texto+= 'Debe completar el campo "Nombre" obligatoriamente.\n';
	}
	
	if(document.getElementById("tu_mail").value == ""){
		texto+= 'Debe completar el campo Mail obligatoriamente.\n';
	}
	else if(!isMail("tu_mail")){
		texto+= 'El Mail ingresado es incorrecto.\n';
	}

	if(texto){
		alert(texto);
	}
	else{
		document.getElementById('form_rec_amigo').submit();
	}
}

function changeTabFicha(show)
{
    for(var i=1; i<=3; i++)
    {
        document.getElementById('l'+i).className = '';
    }
    document.getElementById('l'+show).className = 'selected';
    
    if(show <= 2)
    {
        document.getElementById('capa2').style.display = 'none';
        document.getElementById('capa1').style.display = 'block';
        
        for(var i=1; i<=2; i++)
        {
            document.getElementById('t'+i).style.display = 'none';
        }
        document.getElementById('t'+show).style.display = 'block';
    }
    else
    {
        document.getElementById('capa1').style.display = 'none';
        document.getElementById('capa2').style.display = 'block';
    }
}

function post(url, vars){
	var xml = null;
	try {
		xml = new ActiveXObject('Microsoft.XMLHTTP');
	}catch(exception){
		xml = new XMLHttpRequest();
	}
	xml.open('POST',url,false);
	xml.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xml.send (vars);
	if(xml.status == 404) alert('Url no valida');
	return xml.responseText;
}

function popup(URL,w,h,vars) {
	
        var left = (screen.width - w) / 2;
        var top  = (screen.height - h) / 2
	
	window.open(URL,"","left="+left+",top=" + top + ",width="+w+",height="+h+",scrollbars=yes" + vars);
	
}

function jump(url,selected){
	location = url+selected.options[selected.selectedIndex].value;
}

function viewPic(img){    
   picfile = new Image();    picfile.src =(img);    fileCheck(img); }

function fileCheck(img){    
   if( (picfile.width!=0) && (picfile.height!=0) ){        makeWindow(img);    }else{
       funzione="fileCheck('"+img+"')";        intervallo=setTimeout(funzione,50);    }
}

function makeWindow(img){    
   ht = picfile.height;
    wd = picfile.width;

   var args= "height=" + ht + ",innerHeight=" + ht;
   args += ",width=" + wd + ",innerWidth=" + wd;
   if (window.screen){
       var avht = screen.availHeight;        var avwd = screen.availWidth;
       var xcen = (avwd - wd) / 2;        var ycen = (avht - ht) / 2;
       args += ",left=" + xcen + ",screenX=" + xcen;
       args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes";    
   }
   popwin=window.open("","_blank",args)
    popwin.document.open();
    popwin.document.write('<html><head><title>'+img+'</title></head><body bgcolor=white scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0><div style="position: absolute; top:0px;left:0px"><a href="javascript:window.close()"><img src="'+img+'" width="'+wd+'" height="'+ht+'" border="0"></a></div></body></html>')
    popwin.document.close()
}

function isMail(id)
{
    var s = document.getElementById(id);
    var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9]+[A-za-z]$/;
    if (s.length == 0 ) return true;
    
    if (filter.test(s.value)){
    	return true;
    }else{
    	return false;
    }
}