// JavaScript Document
/*
Event.observe(window, 'load', function() {
	$('listado_productos').style.display='none';
});
*/
function PopUp (pagina) {
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, width=600, height=200,  resizable=no, top=85, left=140";
	window.open(pagina,"",opciones);
}

// hacer tablas a rayitas
function zebra (table) {
	var current = "linea1";
	var trs = table.getElementsByTagName("tr");
	for (var i = 0; i < trs.length; i++) {
	  trs[i].className += " " + current;
	  current = current == "linea2" ? "linea1" : "linea2";
	}
}

function cpValid(cp) {
	var n = Number(cp.value);
	if(isNaN(n) || cp.value.length!=5) {
		//alert("Por favor, introduzca un codigo postal valido.");
		return false;
	}
	else return true;
}

function emailValid(el) { 
	 em=/[\w-\.]+@[\w-\.]+[a-z]+/i; 
	  if (!em.test(el.value)) { 
		  //alert('Por favor, introduzca un email valido.'); 
		  el.select(); 
		  return false;
	  } 
	  else return true;
} 

function Input_Filled(nombre, element) {
	if((element.value=='')||(element.value=='nada')) {
		//alert("Por favor, rellene el campo "+nombre+".");
		return false;
	}
	else return true;
}

function tlfValid(tlf){
	var n = Number(tlf.value);
	if(isNaN(n) || tlf.value.length==0){
		alert("Por favor, introduzca un nmero de telfono vlido.");
		return false;
	}
	else return true;
}

// Funcin que comprueba la entrada de datos
function CompruebaDatos(elCIF) 
{
  var resul = false;
  var temp = elCIF.value.toUpperCase(); // pasar a maysculas

  if (!/^[A-Za-z0-9]{9}$/.test(temp))  // Son 9 dgitos? 

    	alert("Longitud incorrecta, un CIF consta de 9 dgitos");

  else if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) // Es una letra de las admitidas ?

     alert("El primer dgito es incorrecto, debe ser una letra de las siguientes: A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S ");

  else 

     resul = true;

  return resul;
}


function espere() {
	Control.Modal.load(); 
	Control.Modal.open("", {containerClassName: 'espere', overlayClassName: 'espere'});
}


// Funcin de validacin del CIF, indica el dgito de control.
// La funcin recibe el CIF completo: A58818501
function ValidaCIF(elCIF) 
{

  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;

  
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(elCIF.value.substr(i-1,1)) ];
      temp = temp + parseInt(elCIF.value.substr(i,1));
    };

  temp = temp + v1[ parseInt(elCIF.value.substr(7,1)) ];

  temp = (10 - ( temp % 10));

  if( temp == 10 )
    alert( "El dgito de control es: J  0" );
  else
    alert( "El dgito de control es: "+temp ); 

  return true;
}