function XautoIframe(id,b){//v1.0
    var altox,anchox,altoc,anchoc,c,x;
	//capturamos el objeto
	c=top.document.getElementById('principal');
	x=c.contentWindow.document.getElementById(id);
	//verificamos que usar dependiendo del navegador y luego definimos el ancho y el alto del documento que contiene
	if (x.contentDocument && x.contentDocument.body.offsetHeight){//firefox
		altox=x.contentDocument.body.offsetHeight;
		anchox=x.contentDocument.body.offsetWidth;
	}else if(x.Document && x.Document.body.scrollHeight){//ie
		altox=x.Document.body.scrollHeight;
		anchox=x.Document.body.scrollWidth;
	}
	//cambiamos el ancho y alto del iframe
    x.style.height=(altox)+"px";
	//si no se quiere modificar el ancho, solo comentar la linea de abajo
    //x.width= (ancho) + "px";
	if(b){
		if (c.contentDocument && c.contentDocument.body.offsetHeight){//firefox
			altoc=c.contentDocument.body.offsetHeight;
			anchoc=c.contentDocument.body.offsetWidth;
		}else if(c.Document && c.Document.body.scrollHeight){//ie
			altoc=c.Document.body.scrollHeight;
			anchoc=c.Document.body.scrollWidth;
		}
		c.style.height=(altoc)+"px";
		//c.width= (ancho) + "px";
	}
}

function dyniframesize(name) {
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	var FFextraHeight=getFFVersion>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers
	var iframeids=[name];
	var dyniframe=new Array();
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById){ //begin resizing iframe procedure
			dyniframe[dyniframe.length] = top.document.getElementById(iframeids[i]);
			if (dyniframe[i] && !window.opera){
				dyniframe[i].style.display="block";
				if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
					dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight+FFextraHeight; 
				else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
					dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
			}
		}
	}
	if (window.addEventListener)
		window.addEventListener("load", dyniframesize, false);
	else if (window.attachEvent)
		window.attachEvent("onload", dyniframesize);
}

function promo(id){
    top.parent.frames['principal'].location.href = 'listar_tonos.php?promo=' + id;
}

function editar(id)
{
  if(id<0)
  {
    show('editar');
    hide('ver');
  }
  else
  {
    show('editar'+id);
    hide('ver'+id);
  }
}

function check_hide_error(){
    if(top.document.getElementById('msg')){
        m = top.document.getElementById('msg');
        if(m.contentWindow.document.getElementById('msg_span')){
            span = m.contentWindow.document.getElementById('msg_span');
            if(span.innerHTML != 'No estas logueado' && span.innerHTML != 'Gracias por utilizar el servicio Ring Back Tones de TIGO !')
				hide_error();
        }
    }
}

function cancelar(id,back)
{
  if(back) window.history.back();
  else
  {
    if(id<0)
    {
      show('ver');
      hide('editar');
    }
    else
    {
      show('ver'+id);
      hide('editar'+id);
    }
  }
}

function cancelar2(){
        window.location = 'listar_contactos.php';
}
function show(obj) 
{
	x = document.getElementById(obj);
	x.style.display='';
  //eval("document.all." + obj + ".style.display='block'");
}
function hide(obj) 
{
	x = document.getElementById(obj);
	x.style.display='none';
  //eval("document.all." + obj + ".style.display='none'");
}

function borrar_num(id,nombre)
{
  var borrar = confirm("Estas seguro de borrar '"+nombre+"' ?");
  if(borrar)
    window.location = 'editar_grupos.php?borrar_num='+id
}

function borrar_grup(id,nombre)
{
  var borrar = confirm("Estas seguro de borrar el grupo '"+nombre+"' ?");
  if(borrar)
    window.location = 'editar_grupos.php?borrar='+id
}

function borrar_asig(id,nombre)
{
  var borrar = confirm("Estas seguro de borrar a '"+nombre+"' ?");
  if(borrar)
    window.location = 'editar_asignados.php?borrar='+id
}

function borrar(id,nombre)
{
  var borrar = confirm("Estas seguro de borrar el tono '"+nombre+"' ?");
  if(borrar)
    window.location = 'mis_tonos.php?borrar='+id
}

function buscautor(d){
        var param='?aut='+d;
        top.parent.frames['principal'].location.href = 'listar_tonos.php?aut='+d+'&ver=1';
}

function buscautor2(d){
        var param='?aut='+d;
        parent.frames['tonos'].location.href = 'tonos.php?aut='+d+'&ver=1';
}

function buscapromo(d){
        var param='?promo='+d;
        parent.frames['tonos'].location.href = 'tonos.php?promo='+d;
}

function buscat(cat){
        top.parent.frames['principal'].location.href = 'listar_tonos.php?cat=' + cat;
}

function check_iframes(ifr){
	f=top.document.getElementById('principal');
	frame=f.contentWindow.document.getElementById(ifr);
	innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	objToResize = (frame.style) ? frame.style : frame;
	objToResize.height = innerDoc.body.scrollHeight;
	objToResize.width  = innerDoc.body.scrollWidth;
	innerDoc = (f.contentDocument) ? f.contentDocument : f.contentWindow.document;
	objToResize = (f.style) ? f.style : f;
	objToResize.height = innerDoc.body.scrollHeight;
	objToResize.width  = innerDoc.body.scrollWidth;
}

function buscar(cat)
{
   var param='?cat='+cat;
   var ifra='tonos';
   var dir='tonos.php';
   if(document.formbuscar)
   {
        if(cat==-1 || document.formbuscar.keyword.value=="") param="";
        else param = '?key='+document.formbuscar.keyword.value;
        ifra='principal';
        dir='listar_tonos.php';
   }
   parent.frames[ifra].location.href = dir+param;
}

function comprar(id)
{
    popup(id); //compatibilidad con flash de avatar
}

function popup(id)
{
    var w=330; var h=280;
    var winl = (screen.width-w)/2; if (winl < 0) winl = 0;
    var wint = (screen.height-h)/2; if (wint < 0) wint = 0;
    windowprops = "height="+h+",width="+w+",top="+ wint +",left="+ winl +",toolbar=no,directories=no,status=no,scrollbars=auto,resizable=no,menubar=no";
    hWnd=window.open('popup.php?tono='+id,'Comprar',windowprops);
    hWnd.focus();
}

function hide_error(){
	m = top.document.getElementById('msg').contentWindow.document.getElementById('msg_div');
	m.style.display='none';
}

var mytimeout;
function show_msg(mn,s){
	clearTimeout(mytimeout);
	if(top.document.getElementById('msg') && top.document.getElementById('msg').contentWindow.document.getElementById('msg_span')){
		m = top.document.getElementById('msg');
		div = m.contentWindow.document.getElementById('msg_div');
		span = m.contentWindow.document.getElementById('msg_span');
		span.innerHTML = mn;
		div.style.display='';
		if(mn == 'No estas logueado')top.frames['login'].location = 'login.php';
		if(s)mytimeout = setTimeout("div.style.display='none';",s*1000);
	}
}

function autoIframex(frameId)
{
    try
    {
        frame = top.document.getElementById(frameId);
        innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
        objToResize = (frame.style) ? frame.style : frame;
        objToResize.height = innerDoc.body.scrollHeight;
//        objToResize.width  = innerDoc.body.scrollWidth;
    }
    catch(err)
    {
        window.status = err.message;
    }
}

function ingresar(){
	x=document.form_ingresar.usuario;
	y=document.form_ingresar.clave;
    if(x.value == 'usuario' || y.value == 'pin' || x.value == '' || y.value == '')
        show_msg('Favor, completa tu n&uacute;mero y tu pin',10);
    else
        document.form_ingresar.submit();
}


function pin(){
	if(document.form_ingresar){
		x=document.form_ingresar.usuario;
	    if(x.value == '')
			show_msg('Por favor, ingresa tu usuario.',5);
		if(x.value.substring(0,1)!='7' || x.value.length != 8)
			show_msg('Por favor, ingresa un usuario v&aacute;lido.',5);
	    else
			show_msg("<a href=\"mensajes.php?renovar_pin=1&pin=1&usuario=" + x.value + "\">Para cambiar tu PIN hace click aqui y recibiras uno nuevo por SMS</a>",0);
	}else{
		show_msg("<a href=\"mensajes.php?renovar_pin=1&pin=1\">Para cambiar tu PIN hace click aqui y recibiras uno nuevo por SMS</a>",0);
	}
}

function mensaje(p,d)
{
    var w=300; var h=218;
    var winl = (screen.width-w)/2; if (winl < 0) winl = 0;
    var wint = (screen.height-h)/2; if (wint < 0) wint = 0;
    windowprops = "height="+h+",width="+w+",top="+ wint +",left="+ winl +",toolbar=no,directories=no,status=no,scrollbars=auto,resizable=no,menubar=no";
    hWnd=window.open('mensaje.php?mensaje='+p,'Mensaje',windowprops);
    hWnd.focus();
    if(d>0) hWnd.setTimeout("window.close()",d*1000);
}

function menu(m)
{
	if(m=='nuevos')
		top.document.getElementById('banner-top').contentWindow.document.getElementById('mainMenu_1').className="current";
	else
		top.document.getElementById('banner-top').contentWindow.document.getElementById('mainMenu_1').className="active-tab";
	for(var i=1;i<=4;i++){
		x=top.document.getElementById('banner-top').contentWindow.document.getElementById('sub_1_'+i);
		x.className='';
	}
//alert(top.document.getElementById('banner-top').contentWindow.document.getElementById('mainMenu_1').className+' - '+m);
    top.parent.frames['principal'].location.href = m+'.php?';
}

function autoIframe(frameId)
{
    try
    {
        frame = document.getElementById(frameId);
        innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
        objToResize = (frame.style) ? frame.style : frame;
        objToResize.height = innerDoc.body.scrollHeight;
         //       objToResize.width  = innerDoc.body.scrollWidth;
    }
    catch(err)
    {
        window.status = err.message;
    }
}


function compra(f,p)
{
        top.parent.frames['principal'].location="tonos_comprar.php?tono=" + f + "&promo=" + p;
}

function popup_publicidad()
{
    var w=400; var h=300;
    var winl = (screen.width-w)/2; if (winl < 0) winl = 0;
    var wint = (screen.height-h)/2; if (wint < 0) wint = 0;
    //windowprops = "height="+h+",width="+w+",top="+ wint +",left="+ winl +",toolbar=no,directories=no,status=no,scrollbars=auto,resizable=no,menubar=no";
    windowprops = "height="+h+",width="+w+",top="+ wint +",left="+ winl;
    hWnd=window.open('encuesta.php','Encuesta',windowprops);
    hWnd.focus();
}

