function sale(id){
$.get('trade/count.php?OUT='+id+'', function(data) {
  $('.result').html(data);
});
}

function ventana(Url,NombreVentana,width,height,extras) {
var largo = width;
var altura = height;
var adicionales= extras;
var top = (screen.height-altura)/2;
var izquierda = (screen.width-largo)/2; nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + ''); 
nuevaVentana.focus();
}

var tempo;
var opa = 0;
function ver() {
  opa+=1;
  if (opa==100) clearInterval(tempo);
  obj = document.getElementById('growlmsn');
  obj.style.display = 'block';
  if (document.all)
    obj.style.filter = 'alpha(opacity='+opa+')';
  else
    obj.style.MozOpacity = opa/50;
}


var opa2 = 100;

function ver2() {
  opa2-=5;
  if (opa2==0) clearInterval(tempo);
  obj2 = document.getElementById('growlmsn');
  if (document.all)
    obj2.style.filter = 'alpha(opacity='+opa2+')';
  else
    obj2.style.MozOpacity = opa2/50;
}

function quita2(){
	sesmsn = document.getElementById('growlmsn');
	sesmsn.style.display = 'none';
}
function quita() {
  opa-=1;
  obj2 = document.getElementById('growlmsn');
  if (opa==0) {clearInterval(tempo); obj2.style.display = 'none';}
  if (document.all)
    obj2.style.filter = 'alpha(opacity='+opa+')';
  else
    obj2.style.MozOpacity = opa/50;
}

setTimeout("tempo=setInterval('ver()',15)",4000)
//setTimeout("tempo=setInterval('ver2()',40)",24000)
setTimeout("tempo=setInterval('quita()',10)",20000)


function cerrarventana(){
	document.getElementById("wincont").style.visibility="hidden";
}
var fila = null;
function inpon(obj) {
  obj.className = 'cajaon';

}
function inquita(obj) {
  obj.className = 'caja';

}

function onbus(obj) {
  obj.className = 'qstyle';
  if (obj.value == 'Escribe el texto a buscar...'){
	  obj.value = '';
  }
}
function ofbus(obj) {
	if (obj.value.length > 1){
		obj.className = 'qstyle';
	}else if (obj.value.length < 1){
		obj.className = 'qstyleof';
  		obj.value = 'Escribe el texto a buscar...';
	}
}

function busclk(obj) {
  if (obj.value == 'Escribe el texto a buscar...'){
	  alert('ERROR: Debes escribir lo que deseas buscar.')
	  return false;
  }else if(obj.value.length < 4){
	  alert('ERROR: El texto a buscar es muy corto, mínimo 4 caracteres.')
	  return false;
  }
}

function envono(){
re=/^(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
	
	if (document.contacto.nombre.value.length < 3){
		alert('Escribe tu nombre o nick');
	return false;
	
	}else if(document.contacto.asunto.value.length < 8){
		alert('Escribe tu asunto un poco más claro.');
		return false;
	
	}else if(!re.exec(document.contacto.email.value)){
		alert('El e-mail que has escrito no es válido.');
		return false;

	}else if(document.contacto.mensaje.value.length < 25){
		alert('El mensaje es demasiado corto, se más específico.');
		return false;

	}else if (confirm(document.contacto.nombre.value+', el mensaje que has escrito va dirigido para el administrador de la página.\n\n¿Deseas enviarlo ahora?')){
	tras = document.getElementById('espera');
    tras.style.display = 'block';
	return true;
		}else{
	return false;
	}
}

var ancho=235;
function cuentarc(cuenta){
lim = 250;
tras = document.getElementById('dirmail');

if (document.contacto.mensaje.value.length > lim){
	document.contacto.mensaje.value = document.contacto.mensaje.value.substring(0, lim);
}else{
	cact = document.contacto.mensaje.value.length;
	cuantos = lim-cact;
	if(cact < lim){
	document.contacto.cuenta.value = 'Caracteres restantes: '+cuantos;
	document.contacto.cuenta.style.backgroundColor = "#FFFFFF";
document.contacto.cuenta.style.backgroundImage = "url(imagenes/bglim.jpg)";
document.contacto.cuenta.style.color = "#034A7E";
var pos = ancho-parseInt((ancho*parseInt(document.contacto.mensaje.value.length))/250);
document.contacto.cuenta.style.backgroundPosition = "-"+pos+"px 0px";
tras.style.display = 'none';
	}else{
	document.contacto.cuenta.value = 'No puedes escribir mas caracteres';
	document.contacto.cuenta.style.backgroundColor = "#FF0000";
document.contacto.cuenta.style.backgroundImage = "url()";
document.contacto.cuenta.style.color = "#FFFFFF";

	
    tras.style.display = 'block';

	}
  }
}
num=1;
function crear(obj) {
num++;
limite = 10;
if(num > limite){
num = limite;
alert('Solo se permiten 10 destinatarios como máximo.');
}else{
  document.contacto.contador.value = num;
  
  f2 = document.getElementById('destinatarios'); // 1
  dcu = document.createElement('div'); // 2
  dcu.className = 'cun' // 3
  dcu.id = 'tdiv'+num; // 3
  dcu.innerHTML = num+'&raquo;';
  f2.appendChild(dcu); // 4
  
  fi = document.getElementById('destinatarios'); // 1
  crec = document.createElement('div'); // 2
  crec.id = 'div'+num; // 3
  fi.appendChild(crec); // 4
  
  
  
  ele = document.createElement('input'); // 5
  ele.type = 'text'; // 6
  ele.name = 'nombre'+num; // 6
  ele.id = 'nm'+num; // 6
  ele.className = 'cja1';
  crec.appendChild(ele); // 7
  
  
  ele = document.createElement('input'); // 5
  ele.type = 'text'; // 6
  ele.name = 'email'+num; // 6
  ele.id = 'em'+num; // 6
  ele.onkeydown = function () {revisaml(this.id)};
  ele.className = 'cja1';
  crec.appendChild(ele); // 7
  
  ele = document.createElement('img'); // 5
  ele.name = 'div'+num; // 8
  ele.id = 'CBC00'+num; // 8
  ele.src = 'imagenes/del.gif';
  ele.className = 'img1';
  ele.onclick = function () {borrar(this.name)} // 9
  crec.appendChild(ele); // 7
  
  vcont = document.getElementById('contadorid'); // 1
  vactual = vcont.value-1;
  idimg = 'CBC00'+vactual;
  document.getElementById(idimg).style.visibility='hidden';
  


 }
}

function borrar(obj) {
  fi = document.getElementById('destinatarios'); // 1 
  fi.removeChild(document.getElementById(obj)); // 10
  fi.removeChild(document.getElementById('t'+obj)); // 10
	num--;
	document.contacto.contador.value = num
	
	vcont = document.getElementById('contadorid'); // 1
  	vactual = 'CBC00'+vcont.value;
	document.getElementById(vactual).style.visibility='visible';
}


function valmail(num){

re=/^(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
var i;
if(document.getElementById('den').value.length <= 3){
	alert('Es necesario tu nombre o nick para que tu amigo sepa quien le recomienda la página.');
	return false;
 }
 if(!re.exec(document.getElementById('dem').value)){
  alert('ERROR: Tu email no es válido.');
  return false;
  }
  
for (i=1; i <= num; i++){
 if(!re.exec(document.getElementById('em'+i).value)){
  alert('ERROR:\n\nEl email "'+i+'" no es válido. Si no lo vas a utilizar, eliminalo :)');
  document.getElementById('em'+i).className = 'campoer';
  document.contacto.cadena.value = '';
  return false;
  }else{
  document.contacto.cadena.value += document.getElementById('em'+i).value+'###'+document.getElementById('nm'+i).value+'###';  
  }
  if(document.getElementById('nm'+i).value.length <= 3){
	alert('ERROR:\n\nEs necesario el nombre o nick que corresponde al email "'+i+'"');
	document.contacto.cadena.value = '';
	return false;
 }
 }
}

function revisaml(objetin){
re=/^(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
 if(!re.exec(document.getElementById(objetin).value)){
  document.getElementById(objetin).className = 'campoer';
  }else{
  document.getElementById(objetin).className = 'campook';
 }
}

function email(ojet){
re=/^(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
 if(!re.exec(document.getElementById(ojet).value)){
	 alert('El email es incorrecto.');
	 return false;
  }
}

function captcha(resultado){
var n1 = parseInt(document.getElementById('n1').value);
var n2 = parseInt(document.getElementById('n2').value);
var res = n1 + n2 - 2956;
 if(resultado != res){
	 alert('No sabes sumar, eh?...');
	 return false;
  }
}