// JavaScript Document



//Jquery y Javascript
var $jq=jQuery.noConflict();


$jq(document).ready(function(){
	
	
	
function estadisticas()
{
	
$jq.post("GA/gapi_mtp.php",function(datos)
 {
	 
$paginas=datos.paginas;
$visitas=datos.visitas;
$tiempo=datos.tiempodevisita;
 
$jq(".estadisticas").html($paginas);	

}, "json");	
}



$jq(window).load(function() {estadisticas();});


jQuery.fn.reset = function () {
  $(this).each (function() { this.reset(); });
}


function comprueba_form () {
	
if ($jq("input#nombre").val() != "" )
	{$jq("label#nombre").html("<span id='email' class='texto tamano14 verde'>Nombre</span>"); }
else {$jq("label#nombre").html("<span id='email' class='texto tamano14 rojo'>Nombre</span>"); }	

if ($jq("input#apellidos").val() != "" )
	{$jq("label#apellidos").html("<span id='email' class='texto tamano14 verde'>Apellidos</span>"); }
else {$jq("label#apellidos").html("<span id='email' class='texto tamano14 rojo'>Apellidos</span>"); }	

if ($jq("input#domicilio").val() != "" )
	{$jq("label#domicilio").html("<span id='email' class='texto tamano14 verde'>Domicilio/Población</span>"); }
else {$jq("label#domicilio").html("<span id='email' class='texto tamano14 rojo'>Domicilio/Población</span>"); }	

if (($jq("input#email").val().indexOf("@") != -1) && ($jq("input#email").val().indexOf(".") != -1) && ($jq("input#email").val() != "" ))
	{$jq("label#email").html("<span id='email' class='texto tamano14 verde'>e-mail</span>"); }
else {$jq("label#email").html("<span id='email' class='texto tamano14 rojo'>e-mail</span>"); }	


if ($jq("input#url").val() != "http://" )
	{$jq("label#url").html("<span id='email' class='texto tamano14 verde'>Web a anunciar</span>"); }
else {$jq("label#url").html("<span id='email' class='texto tamano14 rojo'>Web a anunciar</span>"); }	

if ($jq("input#tooltip").val() != "" )
	{$jq("label#tooltip").html("<span id='email' class='texto tamano14 verde'>Breve descripción</span>"); }
else {$jq("label#tooltip").html("<span id='email' class='texto tamano14 rojo'>Breve descripción</span>"); }	
}

$jq("input").keyup(comprueba_form);

});
//para el formulario de publicidad***************


 function multPrice(num) {
      var str = document.getElementById('tipo').value;
      document.getElementById('duracion').disabled=false;      
      if (str == 'sponsors125_1') { document.getElementById('precio').value = 25 * num; }
	  if (str == 'sponsors125_2') { document.getElementById('precio').value = 15 * num; }
      if (str == 'sponsors200') { document.getElementById('precio').value = 50 * num; }
      if (str == 'iconads') { document.getElementById('precio').value = 5 * num; }
     
	  if (str == 'reportaje') {
		 if ((document.getElementById('duracion').value<24) && (document.getElementById('duracion').value>21)){ num=document.getElementById('duracion').value=24;}
if ((document.getElementById('duracion').value<21) && (document.getElementById('duracion').value>18)){ num=document.getElementById('duracion').value=21;}
if ((document.getElementById('duracion').value<18) && (document.getElementById('duracion').value>15)){ num=document.getElementById('duracion').value=18;}
if ((document.getElementById('duracion').value<15) && (document.getElementById('duracion').value>12)){ num=document.getElementById('duracion').value=15;}
if ((document.getElementById('duracion').value<12) && (document.getElementById('duracion').value>9)){ num=document.getElementById('duracion').value=12;}
if ((document.getElementById('duracion').value<9) && (document.getElementById('duracion').value>6)){ num=document.getElementById('duracion').value=9;}
if ((document.getElementById('duracion').value<6) && (document.getElementById('duracion').value>3)){ num=document.getElementById('duracion').value=6;}
if ((document.getElementById('duracion').value<3) && (document.getElementById('duracion').value>0)){ num=document.getElementById('duracion').value=3;}
		  document.getElementById('precio').value = 70 * num; }
	        
			if (str == 'tienda') {
if ((document.getElementById('duracion').value<24) && (document.getElementById('duracion').value>18)){ num=document.getElementById('duracion').value=24;}
if ((document.getElementById('duracion').value<18) && (document.getElementById('duracion').value>12)){ num=document.getElementById('duracion').value=18;}
if ((document.getElementById('duracion').value<12) && (document.getElementById('duracion').value>6)){ num=document.getElementById('duracion').value=12;}	
if ((document.getElementById('duracion').value<6) && (document.getElementById('duracion').value>0)){ num=document.getElementById('duracion').value=6;}	
				 document.getElementById('precio').value = 110 * num; }
     
    }
//******validar email



 
 
function  enviar_form(thisform)
{

  $jq("span.enviado").html("...enviando....");
	
	
var nombre2=thisform.nombre.value;	
var apellidos2=thisform.apellidos.value;	
var domicilio2=thisform.domicilio.value;	
var telefono2=thisform.telefono.value;	
var email2=thisform.email.value;	

var titular2=thisform.titular.value;	
var nif2=thisform.nif.value;	

var tipo2=thisform.tipo.value;	
var url2=thisform.url.value;	
var tooltip2=thisform.tooltip.value;	
var duracion2=thisform.duracion.value;	

var precio2=thisform.precio.value;
var pago2=thisform.pago.value;	

var obs2=thisform.obs.value;		
	
with (thisform)
  {
	$jq("span.enviado").html("..2.....");  
  var dataString = 'nombre='+ nombre2 + '&apellidos=' + apellidos2 + '&domicilio=' + domicilio2 + '&telefono=' + telefono2 + '&email=' + email2 + '&titular=' + titular2 + '&nif=' + nif2 + '&tipo=' + tipo2 + '&url=' + url2 + '&tooltip=' + tooltip2 + '&duracion=' + duracion2 + '&precio=' + precio2 + '&pago=' + pago2 + '&obs=' + obs2;
// alert (dataString);return false;


  $jq.ajax({
    type: "POST",
    url: "enviomail.php",
    data: dataString,
    success: function() {
	
      $jq('span.enviado').html("Enviado");
	  //$jq("#formu").reset();
	  $jq('#formu').each (function(){
  this.reset();
});
	 $jq( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
     return false;
	  
    } 
	
	
  });
	$jq("span.enviado").html("..3....."); 	return false;	   
	  
	  
	  
  //return true;
  
  	  
	  
  }
  
  return false;	
  
  
  
}







