//////////////////////////////////////////////////////////////////
// 		Libreria comun de rutinas
//////////////////////////////////////////////////////////////////


	// Abrir ventana
	function win(theURL,winName,ancho,alto,barras) {
		var winl = (screen.width - ancho) / 2;
		var wint = (screen.height - alto) / 2;
		var paramet='top='+wint+',left='+winl+',width='+ancho+',height='+alto+',scrollbars='+barras+'';
		var splashWin=window.open(theURL,winName,paramet);
		splashWin.focus();
	}

	// Abrir ventana eficiente
	function popc(a){
		var enlace = a.getAttribute("href");
		var nombre = a.getAttribute("nombre");
		var ancho = a.getAttribute("ancho");
		var alto = a.getAttribute("alto");
		var barras = a.getAttribute("barras");
		if(isNaN(ancho)) ancho = 300;
		if(isNaN(alto)) alto = 250;
		if(isNaN(barras)) barras = 0;
		win(enlace,nombre,ancho,alto,barras);
	}

	// Validar email
	function validarEmail(valor) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)) {
			return (true);
		} else {
			return (false);
		}
	};

	// Contar
	function contar(ayo,mes,dia,hora,minuto,segundo,id) {
	
	  var dif = 'Dia ' + dia + ' del ' + mes + ' de ' + ayo + ', a las ' + hora + ':';
	  if (minuto < 10) { dif+='0'; }
	  dif+=minuto + '<br>';
	  //document.getElementById('evento' + id).innerHTML=dif
	  var a = new Date();
	  //hora, minuto,segundo, mes,dia a?o.
	  var dif= mktime(hora,minuto,segundo,mes - 1,dia,ayo) - mktime(a.getHours(),a.getMinutes(),a.getSeconds(),a.getMonth(),a.getDate(), a.getFullYear());
	  if (dif < 0) { document.getElementById('contar' + id).innerHTML="<font color='#FF0000'>Termin&oacute; la oferta!!</font>"; }
	  else {
		dia= Math.floor(dif/60/60/24);  
		hora= Math.floor((dif - dia*60*60*24)/60/60);
		minuto= Math.floor((dif - dia*60*60*24 - hora*60*60)/60);
		segundo= Math.floor(dif - dia*60*60*24 - hora*60*60 - minuto*60);
		var txt = '';
		if (dia > 0) {
			txt=dia+' d&iacute;a';
			if (dia != 1) { txt+='s'; }
			txt+=' - '; 
		}
		if (hora > 0 || dia > 0) {
			txt+=hora+'h ';
			//if (hora != 1) { txt+='s '; }
		}
		if (minuto > 0 || hora > 0 || dia > 0) {
			txt+=minuto+'m ';
			//if (minuto != 1) { txt+='s '; }
		}
		txt+=segundo+'s';
		//if (segundo != 1) { txt+='s'; }
		document.getElementById('contar' + id).innerHTML=txt;
		}
	
		function mktime() {
		
			var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
			d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
		 
			var dateManip = {
				0: function(tt){ return d.setHours(tt); },
				1: function(tt){ return d.setMinutes(tt); },
				2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
				3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
				4: function(tt){ return d.setDate(tt+mb); },
				5: function(tt){ return d.setYear(tt+ma); }
			};
			
			for( i = 0; i < argc; i++ ){
				no = parseInt(argv[i]*1);
				if(no && isNaN(no)){
					return false;
				} else if(no){
					// arg is number, let's manipulate date object
					if(!dateManip[i](no)){
						// failed
						return false;
					}
				}
			}
		 
			return Math.floor(d.getTime()/1000);
		} // en mktime

	} // end contar
	
