$(function() {
	$("a[href='#noLink']").each(function()
	{ 
		$(this).removeAttr('target');
        $(this).removeAttr('href');
		
		if($(this).parent().hasClass('titulo'))
			$(this).css('color','#1D4A73');

		if($(this).parent().hasClass('texto'))
			$(this).css('color','#393939');
			
        $(this).hover(function() {
            $(this).css('cursor','default');
        }, function() {
            $(this).css('cursor','auto');
        });        
        
		$(this).click(function() {
			return false;
		});		
	});
});

function checkFormGeneral(){
	var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+[A-za-z]$/;
	var filter2=/^[A-Za-z][A-Za-z0-9_.]*$/;
	var sinError=true;

	$('.required').each(function(){
		if($.trim($(this).val()) == ''  && sinError==true){
			alert('Debe completar el dato '+$(this).attr("alt")+' que es obligatorio.')
			$(this).focus();
			sinError=false;
		}
	});
		
	$('.numerico').each(function(){
		if ($(this).val() != "" && isNaN($(this).val()) && sinError==true) { 
			$(this).focus();
			alert('El dato '+$(this).attr("alt")+' debe ser numerico.')
			sinError=false;
		}
		
	});
	
	$('.emailValido').each(function(){
		if (!filter.test($(this).val()) && sinError==true) {
			$(this).focus();
			alert('Debe seleccionar un email valido')
			sinError=false;
		}
		
	});
		
	$('.usuarioValido').each(function(){
		if (!filter2.test($(this).val())  && sinError==true) {
			$(this).focus();
			alert('Debe seleccionar un usuario valido')
			sinError=false;
		}
		
	});
	
	$('.seleccione').each(function(){
		if ($(this).val() == -1  && sinError==true) { 
			$(this).focus();
			alert('Debe seleccionar una opcion en '+$(this).attr("alt"))
			sinError=false;
		}
		
	});
	
	if (sinError == false) {
		$('#btnSubmit').show();
	}
		
	return sinError;
}

function writeDate(divId) {
  var now = new Date();
  var today = now.getDate();
  var days = now.getDay();
  var minutes = now.getMinutes() + ''; /* las comillas son para que los minutos sean leidos como string y no como numero, para asi analizar el length y rellenarlo con ceros */
  if(minutes.length < 2) {minutes = '0' + minutes;}
  var hour = now.getHours()+":"+minutes;
	var dayName = new Array(6)
		dayName[0]="Domingo ";
		dayName[1]="Lunes ";
		dayName[2]="Martes ";
		dayName[3]="Miércoles ";
		dayName[4]="Jueves ";
		dayName[5]="Viernes ";
		dayName[6]="Sábado ";
	var month = now.getMonth();
    var monthName = new Array(12)
      monthName[0]="enero ";
      monthName[1]="febrero ";
      monthName[2]="marzo ";
      monthName[3]="abril ";
      monthName[4]="mayo ";
      monthName[5]="junio ";
      monthName[6]="julio ";
      monthName[7]="agosto ";
      monthName[8]="septiembre ";
      monthName[9]="octubre ";
      monthName[10]="noviembre ";
      monthName[11]="diciembre ";
	
	 $("#printHora").html(dayName[days]+today+" de "+monthName[month] +" <span>"+hour+"</span>");
}

function dateUpdater(time,divId) {
	var runtime = (time*1000);
	writeDate(divId);
	setInterval("writeDate(\'"+divId+"\')",runtime);
}


function desplegar_opciones(menu,accion, elm){
	var pos = 0;
	if(elm) {
		pos = $(elm).offset();
		pos = pos.left;
	}


	if(menu == 'servicios') {
		if(accion == 'ocultar') $('#menu-servicios').hide();
		if(accion == 'mostrar' && !$('#menu-servicios').is(":visible")) $('#menu-servicios').show().css({left: pos + "px"});
	}
	if(menu == 'clasificados') {
		if(accion == 'ocultar') $('#menu-clasificados').hide();
		if(accion == 'mostrar' && !$('#menu-clasificados').is(":visible")) $('#menu-clasificados').show().css({left: pos + "px"});
	}
	if(menu == 'opciones') {
		if(accion == 'ocultar') $('#menu-opciones').hide();
		if(accion == 'mostrar' && !$('#menu-opciones').is(":visible")) $('#menu-opciones').show().css({left: pos + "px"});
	}
}

function abrir_popup(url,width,height){
	if (width == 0) width=790;
	if (height == 0) height=600;
	window.open(url,'Detalle','width='+width+',height='+height+',top=100,left=512,location=0,menubar=0,toolbar=0,scrollbars=1,resizable=0')
}

function visitaItem(nota){
	$.ajax({ type: "POST", url: "/action/votos.php", data: "action=visitas&nota="+nota,
			success: function(msg){
		}
	});

}

function tiempoPartidoEnJuego(partido){
	if ( $('#tiempoAct'+partido).length>0) {
			var tiempo = $('#tiempoAct'+partido).html();
			var aTiempo = tiempo.split(':');
			if (aTiempo[1]==59){
				aTiempo[1] = '00';
				aTiempo[0]++;
				if (aTiempo[0]<10) aTiempo[0]= '0'+parseInt(aTiempo[0],10);
			}
			else {
				aTiempo[1]++;
				if (aTiempo[1]<10) aTiempo[1]= '0'+parseInt(aTiempo[1],10);
				if (aTiempo[0]<10) aTiempo[0]= '0'+parseInt(aTiempo[0],10);
			}
			$('#tiempoAct'+partido).html(aTiempo[0]+':'+aTiempo[1]);
	}
}

var aPartidos = new Array();

function verMarcadorNota(partido,hora,objeto,muestra,tipo){
	var horaComienzo = '00:00';
	if (muestra==1) {
		$.ajax({ type: "POST", async:false, url: "/action/hora_partido.php", data: 'hora='+hora+'&deporte='+tipo,
			success: function(msg){
				horaComienzo = msg;
				
			}
		});
	}
	
	$.ajax({ type: "GET", url: "/adjuntos/marcadores/marcador_nota_"+partido+".html?rd="+(new Date()).getTime(),
		success: function(msg){
			$('#marcador_nota'+objeto).html(msg);
			if (horaComienzo == '00:00')  { $('#tiempoAct'+partido).hide(); } //para que no aparezcan NAN o -53 por ejemplo 
			else  $('#tiempoAct'+partido).show(); //porque ya no da mas NAN
			$('#tiempoAct'+partido).html(horaComienzo);
			$('.slide').list_ticker({
				speed:6000,
				effect:'slide'
			});
		}
	});
	if (muestra==1 && tipo==1) {
		if (aPartidos[partido] == undefined){
			setInterval("tiempoPartidoEnJuego("+partido+")",1000);
			aPartidos[partido] = 1;
		}
	}
}

function verMarcadorChico(partido,hora,objeto,muestra,tipo){
	var horaComienzo = '00:00';
	if (muestra==1) {
		$.ajax({ type: "POST", async:false, url: "/action/hora_partido.php", data: 'hora='+hora+'&deporte='+tipo,
			success: function(msg){
				horaComienzo = msg;
				
			}
		});
	}
	
	$.ajax({ type: "GET", url: "/adjuntos/marcadores/marcador_chico_"+partido+".html?rd="+(new Date()).getTime(),
		success: function(msg){
			$('#marcador'+objeto).html(msg);
			if (horaComienzo == '00:00')  { $('#tiempoAct'+partido).hide(); } //para que no aparezcan NAN o -53 por ejemplo 
			else  $('#tiempoAct'+partido).show(); //porque ya no da mas NAN
			$('#tiempoAct'+partido).html(horaComienzo);
			$('.slide').list_ticker({
				speed:6000,
				effect:'slide'
			});
		}
	});
	if (muestra==1 && tipo==1) {
		if (aPartidos[partido] == undefined){
			setInterval("tiempoPartidoEnJuego("+partido+")",1000);
			aPartidos[partido] = 1;
		}
	}
}

function verMarcadorGrande(partido,hora,objeto,muestra,tipo){
	var horaComienzo='00:00';
	if (muestra==1) {
		$.ajax({ type: "POST", async:false, url: "/action/hora_partido.php", data: 'hora='+hora+'&deporte='+tipo,
			success: function(msg){
				horaComienzo = msg;
			}
		});
	}
	
	$.ajax({ type: "GET",  url: "/adjuntos/marcadores/marcador_"+partido+".html?rd="+(new Date()).getTime(),
		success: function(msg){
			$('#marcador'+objeto).html(msg);
			if (horaComienzo == '00:00')  { $('#tiempoAct'+partido).hide(); } //para que no aparezcan NAN o -53 por ejemplo 
			else  $('#tiempoAct'+partido).show(); //porque ya no da mas NAN
			$('#tiempoAct'+partido).html(horaComienzo);
			$('.slide').list_ticker({
				speed:10000,
				effect:'slide'
			});
		}
	});
	if (muestra==1 && tipo==1) {
		if (aPartidos[partido] == undefined){
			setInterval("tiempoPartidoEnJuego("+partido+")",1000);
			aPartidos[partido] = 1;
		}
	}
}

function cambiarFecha(fecha){
	$.ajax({ type: "GET",  url: "/static/marcadores/fixture_"+fecha+".html?rd="+(new Date()).getTime(),
		success: function(msg){
			$('#fixture-ver').html(msg);
		}
	});
}

function cambiarFechaModificado(fecha){
	$.ajax({ type: "GET",  url: "/static/marcadores/fixture_gral_"+fecha+".html?rd="+(new Date()).getTime(),
		success: function(msg){
			$('#fixture-ver-general').html(msg);
		}
	});
}

var infobae_usar_flash = -1;


function abrirVideo(url_video, url_imagen, ancho, alto, url_swf) {
	if(!url_swf) url_swf = "infobae_video";
	if(infobae_usar_flash == -1) {
		infobae_usar_flash = false;

		// Primer método para validar si el navegador es tiene Adobe Flash
		if(navigator.plugins && navigator.plugins.length) for(var i= 0;i<navigator.plugins.length;i++) {
			if(navigator.plugins[i].name.indexOf('Shockwave Flash') != -1) {
				infobae_usar_flash = true;
				break;
			}
		}

		// Segundo método (IE) para validar la compatibilidad con Flash
		if(window.ActiveXObject) for(i=10;i<=50;i++) {
			try {
				var objFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");
				if(objFlash) {
					infobae_usar_flash = true;
					break;
				}
			}
			catch(e) {}
		}
	}

	if(infobae_usar_flash) {
		/*
		var div = $('div').attr('id', 'videoswfobject')
		
		var flashvars = {
			pathVideo: url_video,
			pathImg:   url_imagen
		};
		var params = {};
		var attributes = {};
		
		swfobject.embedSWF("/media/swf/" + url_swf + ".swf", "videoswfobject", ancho, alto, "10.0.0", "expressInstall.swf", flashvars, params, attributes);
		
		return div;
		*/
		return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + ancho + '" height="' + alto + '">'+
			'<param name="allowScriptAccess" value="always" />'+
			'<param name="movie" value="/media/swf/' + url_swf + '.swf?pathVideo=' + url_video + '&amp;pathImg=' + url_imagen + '" />'+
			'<param name="quality" value="high" />'+
			'<param name="allowFullScreen" value="true" />'+
			'<param name="wmode" value="transparent" />'+
			'<embed allowScriptAccess="always" wmode="transparent" src="/media/swf/' + url_swf + '.swf?pathVideo=' + url_video + '&amp;pathImg=' + url_imagen + '" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + ancho + '" height="' + alto + '"></embed>'+
			'</object>';
	} else {
		var id_rand = parseInt(100000000 * Math.random());
		var salida = '<a href="#" onclick="iniciarVideoHTML5(\'' + url_video + '\', ' + id_rand + '); return false" id="thumbnail-infobae-' + id_rand + '" style="display: inline-block">';
		salida += '<img src="/media/img/static/play_t.png" style="margin-top: ' + (alto / 2 - ancho /6) + 'px; margin-left: ' + ((ancho / 2) - (ancho / 6)) + 'px; width: ' + (ancho / 3) + 'px; position: absolute" alt="Reproducir" title="Haga click para ver el video">';
		salida += '<img src="' + url_imagen + '" style="width: ' + ancho + 'px; height: ' + alto + 'px" alt="Haga click para ver el video" title="Haga click para ver el video">';
		salida += '</a>';
		salida += '<video id="video-infobae-' + id_rand + '" preload="false" controls="controls" style="width: ' + ancho + 'px; height: ' + alto + 'px; display: none" poster="' + url_imagen + '"></video>';
		return salida;
	}
}
function iniciarVideoHTML5(url_video, id) {
	$("#thumbnail-infobae-" + id).remove();
	$("#video-infobae-" + id).show().attr("src", url_video);
	document.getElementById("video-infobae-" + id).play();
}

function votarEncuestaNota(id,opcion){
	window.open("/action/encuesta.php?id="+id+"&opcion=" + opcion, "votar", "width=580,height=330,resizable=yes,scrollbars=yes");
}

function ocultarVideoTeleshow(){alert('Ocultar!!');}
function mostrarVideoTeleshow(){alert('Mostrar!!');}
