
// JAVASCRIPT para popup de AUDIO EN VIVO 

// Sniffer based on http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var uagent    = navigator.userAgent.toLowerCase();
var is_safari = ( (uagent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc.") );

var is_moz    = (navigator.product == 'Gecko');
var is_ns4    = ( (is_ns) && (parseInt(navigator.appVersion) == 4) );
var is_opera  = (uagent.indexOf('opera') != -1);
var is_kon    = (uagent.indexOf('konqueror') != -1);
var is_webtv  = (uagent.indexOf('webtv') != -1);

var is_ie     = ( (uagent.indexOf('msie') != -1) && (!is_opera) && (!is_safari) && (!is_webtv) );
var is_ie4    = ( (is_ie) && (uagent.indexOf("msie 4.") != -1) );
var is_ns     = ( (uagent.indexOf('compatible') == -1) && (uagent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) );

var is_win    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
var is_mac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
var ua_vers   = parseInt(navigator.appVersion);

// para el mp3 player
var UniqueID = 314 // Make each link open in a new window.

SMALLEST_FONTSIZE = 9;
LARGEST_FONTSIZE = 23;

actual_fontsize=11;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}

function PopUp(url, name, width,height,center,resize,scroll,posleft,postop) {
	if (posleft != 0) { x = posleft }
	if (postop  != 0) { y = postop  }

	if (!scroll) { scroll = 1 }
	if (!resize) { resize = 1 }

	if ((parseInt (navigator.appVersion) >= 4 ) && (center)) {
	  X = (screen.width  - width ) / 2;
	  Y = (screen.height - height) / 2;
	}
	if (scroll != 0) { scroll = 1 }

	var Win = window.open( url, name, 'width='+width+',height='+height+',top='+Y+',left='+X+',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}

// Elimina ENTER de un string
function killEnter(elem) {
    var elem2 = "";
    
    while (elem.value.indexOf("\n") != -1){
    	n = elem.value.indexOf("\n");
    	if (is_moz)
	    	elem.value = elem.value.substr(0,n) + elem.value.substr(n+1);
    	else
	    	elem.value = elem.value.substr(0,n-1) + elem.value.substr(n+1);
    }
  

}

// Evita que un text pase de tantos caracteres
function countChars(elem, limite, divMsg) {
    var totalMensaje = elem.value.length;
    
    if (totalMensaje > limite) {
        elem.value = elem.value.substring(0, limite);
        totalMensaje = elem.value.length;
    }
    divMsg.innerHTML = "Caracteres restantes: " + (limite-totalMensaje);
    return false;
};	


// varias de estas funciones obtenidas en pcnews.com

function FindObj(n, d) {
    var p,i,x;  
    if(!d) d=document; 
    if((p=n.indexOf("?"))>0 && parent.frames.length) { 
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
    }
    if( !(x=d[n])  && d.all) x=d.all[n]; 
    for (i=0;!x&&i<d.forms.length;i++) 
        x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
        x=FindObj(n,d.layers[i].document);
    if(!x && d.getElementById) 
        x=d.getElementById(n); 
        
    return x;
}

function SaveActualFontSize() 
{
	var expire = new Date ();
	expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
	expire = expire.toGMTString();
	document.cookie="fontSize="+actual_fontsize+"; path=/; expires="+expire;
}

// consulta el valor de una cookie
function consultarcookie(nombre) 
{
    var buscamos = nombre + "=";
    
    if (document.cookie.length > 0) {
        i = document.cookie.indexOf(buscamos);
    
        if (i != -1) {
            i += buscamos.length;
            j = document.cookie.indexOf(";", i);
            if (j == -1)
                j = document.cookie.length;
            
            return unescape(document.cookie.substring(i,j));
        }
    }
}

function LoadActualFontSize() 
{
    tempArray = document.cookie.split(";");
    for (tA = 0; tA < tempArray.length; tA++)
    {
        if (tempArray[tA].indexOf('fontSize') > -1)
        {
            fontSizeValue = tempArray[tA].split("=")
            actual_fontsize = parseInt(fontSizeValue[1]);
        }
    }
}

function aumentar_fuente() {

  actual_fontsize = parseInt(actual_fontsize)+2;
  if (actual_fontsize > LARGEST_FONTSIZE) { 
  	actual_fontsize = LARGEST_FONTSIZE 
  }
  setStyleByClass('span','postcolor','fontSize',actual_fontsize);
  setStyleByClass('div','QUOTE','fontSize',actual_fontsize);

  SaveActualFontSize();
}


function disminuir_fuente() {
  actual_fontsize = parseInt(actual_fontsize)-2;
  if (actual_fontsize < SMALLEST_FONTSIZE)
        { actual_fontsize = SMALLEST_FONTSIZE };
  setStyleByClass('span','postcolor','fontSize',actual_fontsize);
  setStyleByClass('div','QUOTE','fontSize',actual_fontsize);
  SaveActualFontSize();
}

// ------------------------------
// script por developer.apple.com
// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value

function setStyleByClass(t,c,p,v){

	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (is_ie) ? document.all : document.getElementsByTagName('*');
	} else {
		if (is_opera) {
			elements = document.all;
		}		
		else {
			elements = document.getElementsByTagName(t);
		}
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class' || node.attributes.item(j).nodeName == 'CLASS') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
} 




// MP3 player q funciona en windows y mac
// No funciona en Linux :'(
// obtenido de http://digitalmedia.oreilly.com/pub/a/oreilly/digitalmedia/2005/02/23/mp3_embed.html

function mp3Player(soundfiledesc,soundfilepath) {
	ancho = 340;
	alto = 200;
	
	if ((parseInt (navigator.appVersion) >= 4 )) 
	{
	  X = (screen.width  - ancho ) / 2;
	  Y = (screen.height - alto) / 2;
	}
		
	PlayWin = window.open('',UniqueID,'width='+ancho+',height='+alto+',top='+Y+',left='+X+',resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');
	
	var winContent = "<HTML><HEAD><TITLE>" + soundfiledesc + "</TITLE></HEAD><BODY bgcolor='#FFFFFF'>";
	winContent += "<div align='center' style='font-size:14px; font-family:Verdana,sans-serif;line-height:1.5'><b>" + soundfiledesc + "</b></div>";
	
	winContent += "<OBJECT width='300' height='42'>";
	winContent += "<param name='SRC' value='" +  soundfilepath + "'>";
	winContent += "<param name='AUTOPLAY' VALUE='true'>";
	winContent += "<param name='CONTROLLER' VALUE='true'>";
	winContent += "<param name='BGCOLOR' VALUE='#FFFFFF'>";
	winContent += "<EMBED SRC='" + soundfilepath + "' AUTOSTART='TRUE' LOOP='FALSE' WIDTH='300' HEIGHT='42' CONTROLLER='TRUE' BGCOLOR='#FFFFFF'></EMBED>";
	winContent += "</OBJECT>";
	
	winContent += "<p style='font-size:10px;font-family:Verdana,sans-serif;text-align:center'>Si no puede escuchar el MP3 o si quiere descargarlo, <a href='"+soundfilepath+"'>haga click aquí con el botón derecho </a>  y seleccione 'Guardar destino como...'</p>";
	
	winContent += "<FORM><DIV align='center'><INPUT type='button' value='Cerrar ventana' onClick='javascript:window.close();'></DIV></FORM>";
	winContent += "</BODY></HTML>";
	PlayWin.document.write(winContent);
	PlayWin.focus(); 
	PlayWin.document.close(); 
	UniqueID = UniqueID + 1
}



