// JavaScript Document
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function agregarObjeto(origen,codTema, usuario){
    var url='';
    var codigoTema=codTema;
    if(codTema==''){
        codigoTema=document.getElementById('idFoto').value;
    }
    url='/GENERAL/PAQUETES/clases/blog/objetoFavorito.php?opcion=temaFavorito&codTema='+ codigoTema +'&usuario='+ usuario+'&origen='+origen;
    location.href=url;
}

function cargarPagina(tabPresionado,pagina){
	var i=0;
	for(var i=1; i<=6; i++){
		 var tab = document.getElementById(i);
		 tab.className = '';
	 }
	document.getElementById(tabPresionado).className="item_active";
	cargarPaginaPhp('cuerpoAjax',pagina);
}

function cargarPaginaDesdeUnMenu(btnPresionado,pagina,cantBotones,classSelect,classNoSelect,divReemplazar){
//document.write("<LINK REL='stylesheet' HREF='/WEB/CONFIGURAR_BLOGS/js/chrome.js' TYPE='text/css'>");
var i=0;
for(var i=1; i<=cantBotones; i++){
	 var tab = document.getElementById(i);
	 tab.className = classNoSelect;
 }
document.getElementById(btnPresionado).className = classSelect;
cargarPaginaPhp(divReemplazar,pagina);
}

//es usado este metodo por el metodo de arriba
function cargarPaginaPhp(divReemplazar,pagina){
	var contenedor;
	contenedor = document.getElementById(divReemplazar);
	ajax=nuevoAjax();
	ajax.open("GET",pagina,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.send(null)
}


function cargarPaginaDesdeUnMenuPostback(btnPresionado,pagina,cantBotones,classSelect,classNoSelect,divReemplazar){
//document.write("<LINK REL='stylesheet' HREF='/WEB/CONFIGURAR_BLOGS/js/chrome.js' TYPE='text/css'>");
var i=0;
for(var i=1; i<=cantBotones; i++){
	 var tab = document.getElementById(i);
	 tab.className = classNoSelect;
 }
document.getElementById(btnPresionado).className = classSelect;
document.formEncabezado.action="./WEB/CONFIGURAR_BLOGS/compositorPaginasConfigurar.php?pagina="+pagina;
document.formEncabezado.submit();
}
/*funciona bien*/
function votarEncuesta(){
	var usu='';
	if(document.getElementById('duenioBlog')!=null){
		usu=document.getElementById('duenioBlog').value;
	}else{
		jQuery.facebox('Ah ocurrido un error al votar intente mas tarde.');
	}
	var opt1=document.getElementById('option1').checked;
	var opt2=document.getElementById('option2').checked;
	var radioValue;
	if(opt1==true){
		radioValue=document.getElementById('option1').value;
	}else if(opt2==true){
		radioValue=document.getElementById('option2').value;
	}else {
		radioValue=document.getElementById('option3').value;
	}
	var url='./mando/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+radioValue+'&opcion=flog';
	abrirVentanaPopup(url,550,370,100,250);
}
function votarEncuestaFlog(clasico){
	var usu='';
	if(document.getElementById('duenioBlog')!=null){
		usu=document.getElementById('duenioBlog').value;
	}else{
		jQuery.facebox('Ah ocurrido un error al votar intente mas tarde.');
	}
	var opt1=document.getElementById('option1').checked;
	var opt2=document.getElementById('option2').checked;
	var radioValue;
	if(opt1==true){
		radioValue=document.getElementById('option1').value;
	}else if(opt2==true){
		radioValue=document.getElementById('option2').value;
	}else {
		radioValue=document.getElementById('option3').value;
	}
	var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+radioValue+'&opcion=flog';
	abrirVentanaPopup(url,550,370,100,250);
}
/*funciona bien*/
function verResultadoEncuesta(){
	var usu='';
	if(document.getElementById('duenioBlog')!=null){
		var usu=document.getElementById('duenioBlog').value;
	}else{
		jQuery.facebox('Ah ocurrido un error al votar intente mas tarde.');
	}
	var url='./mando/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=verEncuesta';
	abrirVentanaPopup(url,550,370,100,250);
}
/*funciona bien*/
function verResultadoEncuestaFlog(clasico){
	var usu='';
	if(document.getElementById('duenioBlog')!=null){
		var usu=document.getElementById('duenioBlog').value;
	}else{
		jQuery.facebox('Ah ocurrido un error al votar intente mas tarde.');
	}
	var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=verEncuesta';
	abrirVentanaPopup(url,550,370,100,250);
}

/*
*valida que un campo no contenga mas de una determinada cantidad de caracteres
*return true permitido
*/
function validarCantidadCaracteres(objeto,cantCaracteresPermitidos){
	if(objeto.value.length >= cantCaracteresPermitidos){
		return false;
	}else{
		return true;
	}

}
/*
*valida que un mail sea valido
*return true correcto
*/
function validaMailValido(objetoValidar){
	var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (!filter.test(objetoValidar.value)){
		return false;
	}else{
		return true;
	}
}
/*funciona bien*/
function verActualidad(codActualidad){
	var url='/mando/WEB/VERACTUALIDAD/actualidad.php?codActualidad='+ codActualidad;
	abrirVentanaPopup(url,664,570,100,50);
}
function loguear(origen,clasico){
	var duenioBlog='';
	var url='';
	if(origen=='flog'){
		duenioBlog= document.getElementById('duenioBlog').value;
		url='/'+clasico+'/PAQUETES/clases/logueo.php?duenioBlog='+duenioBlog+'&origen='+origen;
	}else{
		url='/'+clasico+'/PAQUETES/clases/logueo.php?origen='+origen;
	}
	document.frmLoginUsuario.action=url;
	document.frmLoginUsuario.submit();
}
function loguearForo(origen,idtema,pagina,clasico) {
	url='/'+clasico+'/PAQUETES/clases/logueo.php?origen='+origen+'&idtema='+idtema+'&pagina='+pagina;
	document.frmLoginUsuario.action=url;
	document.frmLoginUsuario.submit();
}
/*valida recomendar amigo*/
function recomendarAmigo(origen){
	var yo=document.getElementById('tunombre');
	var el=document.getElementById('nombreamigo');
	var emailYo=document.getElementById('tuemail');
	var emailEl=document.getElementById('emailamigo');
	if(yo.value=='' || el.value=='' || emailYo.value=='' || emailEl.value==''){
		jQuery.facebox('Los 4 campos deben contener informaci&oacute;n.');
		return;
	}
	if(validarCantidadCaracteres(yo,'50')==false || validarCantidadCaracteres(el,'50')==false || validarCantidadCaracteres(emailYo,'100')==false || validarCantidadCaracteres(emailEl,'100')==false){
		jQuery.facebox('Los campos tienen mas caracteres de los permitidos.');
		return;
	}
	if(validaMailValido(emailYo)==false || validaMailValido(emailEl)==false){
		jQuery.facebox('Los mail ingresados no son validos.');
		return;
	}

	var url="/mando/PAQUETES/clases/class.recomendarAmigo.php?origen="+origen;
	document.frmRecomendarAmigo.action=url;
	document.frmRecomendarAmigo.submit();
}
/*funciona bien*/
function votarEncuestaPortada(usu,idOption,origen,clasico){
    if(origen!='flog'){
        var textArea=document.getElementById('textAreaSugerencia');
        if(textArea.value!='Ingresa tu sugerencia'){
            registrarSugerencia();
        }
    }
    var opt1=document.getElementById(idOption+'1').checked;
	var opt2=document.getElementById(idOption+'2').checked;
	var radioValue;
	if(opt1==true){
		radioValue=document.getElementById(idOption+'1').value;
	}else if(opt2==true){
		radioValue=document.getElementById(idOption+'2').value;
	}else {
		radioValue=document.getElementById(idOption+'3').value;
	}
    if(origen=='actualidad'){
        var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+radioValue+'&origen='+origen;
    }else{
        var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+radioValue+'&origen='+origen;
    }
	abrirVentanaPopup(url,550,370,100,250);
}
////////////////****************************************************************terminar
function armarBtnEncuesta(valorOption,usu,origen,clasico,divContieneBtn,aHrefBtn){
    var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+valorOption+'&origen='+origen;
    var divContieneBtn=document.getElementById(divContieneBtn);
    var aHref=document.getElementById(aHrefBtn);
    aHref.innerHTML='';
    divContieneBtn.innerHTML='';
    aHref.setAttribute('href',url);
    var nodoTexto = document.createTextNode("Votar");
    aHref.appendChild(nodoTexto);
    divContieneBtn.appendChild(aHref);
}
/*funciona bien*/
function votarEncuestafLOG(usu,idOption,origen,clasico){
    if(origen!='flog'){
        var textArea=document.getElementById('textAreaSugerencia');
        if(textArea.value!='Ingresa tu sugerencia'){
            registrarSugerencia();
        }
    }
    var opt1=document.getElementById(idOption+'1').checked;
	var opt2=document.getElementById(idOption+'2').checked;
	var radioValue;
	if(opt1==true){
		radioValue=document.getElementById(idOption+'1').value;
	}else if(opt2==true){
		radioValue=document.getElementById(idOption+'2').value;
	}else {
		radioValue=document.getElementById(idOption+'3').value;
	}
	var url='/'+clasico+'/WEB/GRAFICO_ENCUESTAS/graficoEncuesta.php?usu='+ usu +'&accion=votarEncuesta&optValue='+radioValue+'&origen='+origen;
	abrirVentanaPopup(url,550,370,100,250);
}
//registra la sugerencia con ajax
function registrarSugerencia(){
	var textArea=document.getElementById('textarea');
    if(textArea.value==''){
        alert('Ingresa la descripcion de la sugerencia.');
        return;
    }
    document.frmSugeerencia.submit();
}
function onfocusTextArea(textArea){
    if(textArea.value=='Ingresa tu sugerencia'){
        textArea.value='';
    }
}
function abrirPaginaAjax(divReemplazar,paginaConParametros){
	var contenedor;
	contenedor = document.getElementById(divReemplazar);
	ajax=nuevoAjax();
	ajax.open("GET", paginaConParametros,true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.send(null);
}
//retorna true si es fecha correcta
function validaFecha(fecha){
	  if (fecha != undefined && fecha.value != "" ){
		  if (!/^\d{2}\/\d{2}\/\d{4}$/.test(fecha.value)){
			  return false;
		  }
	  var dia  =  parseInt(fecha.value.substring(0,2),10);
	  var mes  =  parseInt(fecha.value.substring(3,5),10);
	  var anio =  parseInt(fecha.value.substring(6),10);
	  switch(mes){
		  case 1:
		  case 3:
		  case 5:
		  case 7:
		  case 8:
		  case 10:
		  case 12:
			  numDias=31;
			  break;
		  case 4: case 6: case 9: case 11:
			  numDias=30;
			  break;
		  case 2:
			  if (comprobarSiBisisesto(anio)){ numDias=29 }else{ numDias=28};
			  break;
		  default:
			  return false;
	  }
	  if (dia>numDias || dia==0){
		  return false;
	  }
	  return true;
	  }
}

function terminos(tipo){
    if(tipo=='terminos'){
        var url = '/GENERAL/WEB/VARIOS/terminos.html';
    }else if(tipo=='privacidad'){
        var url = '/GENERAL/WEB/VARIOS/privacidad.html';
    }

    window.open(url,'Terminos','left=150,top=140,scrollbars=1,toolbar=0,location=0,directories=0,menubar=0');
}
function abrirNoticia(codNoticia){
   var url = '/GENERAL/WEB/RSS/ver-Noticias-Todas-las-Tecnologias.php?id='+codNoticia+'&noticia=si';
   window.open(url,'Terminos','width=655,height=500,left=150,top=140,scrollbars=1');
}

function recordarPass(){
    var txt = 'Ingresa tu e-mail:<br /><input type="text" id="alertName" name="myname" value="" />';
        function mysubmitfunc(v,m){
              an = m.children('#alertName');
              if(an.val() == ""){
                    an.css("border","solid #ff0000 1px");
                    return false;
              }
              var email=an.val();
              var url='./mando/PAQUETES/clases/class.recordarPass.php?email='+email;
              location.href=url;
              return true;
        }

$.prompt(txt,{
      submit: mysubmitfunc,
      buttons: { Recordar:true }
});
}
function limpiarCampos(objeto){
	if(objeto.value=='Deja tu comentario sobre el Post' || objeto.value=='Tu Nick' || objeto.value=='Deja tu comentario'){
		objeto.value='';
	}
}
function lostFocusInput(estilo,id){
	var inp=document.getElementById(id);
	if(inp.value==""){
		inp.className=estilo;
	}
}
function focusInput(id){
	var inp=document.getElementById(id);
	inp.className="inputTextFOCUSDU";
}
function cambiarFotoPopup(div,fotoAlta,usuario,clasico){
	/*cambio la imagen*/
	var divFoto=document.getElementById('divFotoCentral');
	divFoto.innerHTML="";
	var img=document.createElement('img');
	img.setAttribute('src','/'+clasico+'/imagenes/fotos-usuarios/'+fotoAlta);
	img.setAttribute('width','500px');
	img.setAttribute('height','500px');
	divFoto.appendChild(img);
	/*cambio el link del flog*/
	var divLink=document.getElementById('divLinkFlog');
	divLink.innerHTML="";
	var link = document.createElement('a');
	link.setAttribute('href', '/'+usuario);
	link.appendChild(document.createTextNode('Ver Flog de '+usuario));
	divLink.appendChild(link);
}
function abrirVideoFlog(codigoVideo,usuarioFlog){
    var url='/mando/WEB/VIDEOS/ver-videos-flog.php?codigoVideo='+codigoVideo+'&usuarioFlog='+usuarioFlog;
	abrirVentanaPopup(url,560,400,60,850);
}
function comoSumarSitioWeb(){
    var msj='<div class="tipsAlertJquery">Queres sumar tu sitio web en esta seccion?.</div> \n\
             <br/><div class="tipsAlertJquery">Mandanos un mail a redgeek3@gmail.com.</div> \n\
             <br/><div class="tipsAlertJquery">Escribinos la direccion de tu web.</div>\n\
             <br/><div class="tipsAlertJquery">En la brevedad te comunicaremos..</div> ';
    jQuery.facebox(msj);
}
