function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

/**
 * Si docWrite=false no hace el document.write pero devuelve el HTML equivalente.
 */
function AC_Generateobj(objAttrs, params, embedAttrs, docWrite)
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';
  if(docWrite==true || typeof(docWrite)=="undefined") //indica si hará el document.write del objeto
	 document.write(str);
  return str;
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs, ret.docWrite);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){

  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  ret.docWrite = true; //indica si hará el document.write del objeto
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();
    switch (currArg){
      case "classid":
        break;
      case "name":
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "id":
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
		case "docwrite":
		   ret.docWrite = args[i+1];
		   break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
//-------------------------------------------------

// Parche para los parametros que se envian al swf
function runParametros(parametros){
	var i, aux, str="", pos_igual;
	
	parametros=parametros.split("&");
	for (i=0;i<parametros.length;i++){
		aux = [];
		if ( (pos_igual = parametros[i].indexOf("=")) != -1) {
			aux[0] = parametros[i].substring(0,pos_igual);
			aux[1] = parametros[i].substring(pos_igual+1, parametros[i].length);
		} else {
			aux[0] = parametros[i];
		}
		if (aux[1]){
			aux[1]=escape(aux[1])
			parametros[i]=aux.join("=")
		}
		/*
		aux=parametros[i].split("=")
		if (aux[1]){
			aux[1]=escape(aux[1])
			parametros[i]=aux.join("=")
		}
		*/
	}
	parametros=parametros.join("&")
	return parametros
}

/**
 * Si docWrite=false no hace el document.write pero devuelve el HTML equivalente.
 */
function runSWF(archivo, ancho, alto, version, bgcolor, id, menu, FlashVars, quality, allowScriptAccess,wmode, docWrite)
{ 
	FlashVars=FlashVars+"&idUnicoPagina="+idUnicoPaginaGet()
	// Prueba del nuevo listado
	if (FlashVars.indexOf("&idConexion=")==-1){
		FlashVars=FlashVars+"&idConexion="+idConexionGet(window)
	}
        if ( 'listado' in top ){
			archivo=archivo.replace("/listado.swf","/listado."+top.listado+".swf")
			archivo=archivo.replace("/catalogo_telecor.swf","/catalogo_telecor."+top.listado+".swf")
	}
	// fin prueba 
	var version_data = (version!="") ? version : "6,0,0,0";
	var menu_data = (menu!="") ? menu : false;
	var bgcolor_data = (bgcolor!="") ? bgcolor : "#FFFFFF";
	var id_data = (id!="") ? id : "flashMovie";
	var quality_data = (quality!="" && quality!="hihg") ? quality : "high"; 
	var allowScriptAccess_data = (allowScriptAccess!="") ? allowScriptAccess : "always";
	

	var nombreArchivo=archivo.split("/")
	nombreArchivo=nombreArchivo[nombreArchivo.length-1]
	
	if (nombreArchivo=="listado.swf" && typeof wmode=="undefined"){
		//wmode="window"
	}
	if (nombreArchivo=="controlador.swf"){
		wmode=""
	}else{
		if (typeof wmode=="undefined"){
			wmode="transparent"
		}else{
			if (wmode==""){
				wmode="transparent"		
			}
		}
	}
	
	if (archivo.indexOf("chatlistener.swf")!=-1){
		wmode="window"
	}

	if(typeof docWrite=="undefined"){ //indica si hará el document.write del objeto
		docWrite=true;
	}
		
	FlashVars=FlashVars.replace(/"/g, escape('"'))
	return AC_FL_RunContent('wmode',wmode,'width',ancho,'height',alto,'FlashVars',FlashVars,'quality',quality_data,"bgcolor",bgcolor_data,'menu',menu_data,'allowScriptAccess',allowScriptAccess_data,'codebase',"","id",id_data,'movie',archivo,'allowfullscreen','true','pluginspage','','src',archivo,'swLiveConnect','true','name',id_data, 'docWrite', docWrite);
}

function Parametro(nombre, valor)
{
	this.nombre = nombre;
	this.valor = valor;
}


function writeApplet(name, id, code, codebase, cabbase, archive, 
	width, height, ALIGN, hspace, vspace, alt, TITLE, MAYSCRIPT, BORDER, parametros, docWrite)
{
        var contenido='<APPLET ';
	// el name y el id los igualo
	if(name == null || name == undefined || name == "")
		name = id;

	if(name != null && name != undefined && name != "")
		contenido += ' NAME="' + name + '" ID="' + name + '"';

	if(code != null && code != undefined && code != "")
		contenido += ' CODE="' + code + '"';

	if(codebase != null && codebase != undefined && codebase != "")
		contenido += ' CODEBASE="' + codebase + '"';

	if(cabbase != null && cabbase != undefined && cabbase != "")
		contenido += ' CABBASE="' + cabbase + '"';

	if(archive != null && archive != undefined && archive != "")
		contenido += ' ARCHIVE="' + archive + '"';

	if(MAYSCRIPT != null && MAYSCRIPT != undefined && MAYSCRIPT != "")
		contenido += ' MAYSCRIPT="' + MAYSCRIPT + '"';
	else
		contenido += ' MAYSCRIPT="yes"'; // por defecto lo activamos

	if(alt != null && alt != undefined && alt != "")
		contenido += ' ALT="' + alt + '"';

	if(TITLE != null && TITLE != undefined && TITLE != "")
		contenido += ' TITLE="' + TITLE + '"';

	if(BORDER != null && BORDER != undefined && BORDER != "")
		contenido += ' BORDER=' + BORDER;

	if(width != null && width != undefined && width != "")
		contenido += ' WIDTH=' + width;

	if(height != null && height != undefined && height != "")
		contenido += ' HEIGHT=' + height;

	if(ALIGN != null && ALIGN != undefined && ALIGN != "")
		contenido += ' ALIGN="' + ALIGN + '"';

	if(hspace != null && hspace != undefined && hspace != "")
		contenido += ' HSPACE=' + hspace;

	if(vspace != null && vspace != undefined && vspace != "")
		contenido += ' VSPACE=' + vspace;


	contenido += '>';
	
	for(var i=0; i < parametros.length; i++)
		contenido += '<param name=' + parametros[i].nombre + ' value="' + parametros[i].valor + '">';

	contenido += '\n</APPLET>';
        
	if(typeof docWrite=="undefined"){ //indica si hará el document.write del objeto
		docWrite=true;
	}
        if (docWrite){
                document.write(contenido);
        } else {
                return contenido;
        }
}

function writeAppletObject(name, id, code, codebase, cabbase, archive, 
	width, height, ALIGN, hspace, vspace, alt, TITLE, MAYSCRIPT, BORDER, parametros)
{
	var sEmbed = "<embed type=\"application/x-java-applet;version=1.4\"	";
	document.write('<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" type="application/x-java-applet;version=1.4" ');
	// el name y el id los igualo
	if(name == null || name == undefined || name == "")
		name = id;

	if(name != null && name != undefined && name != "")
	{
		document.write(' NAME="' + name + '" ID="' + name + '"');
		sEmbed += ' NAME="' + name + '" ID="' + name + '"';
	}

	if(code != null && code != undefined && code != "")
	{
		document.write(' CODE="' + code + '"');
		sEmbed += ' CODE="' + code + '"';
	}

	if(codebase != null && codebase != undefined && codebase != "")
	{
		document.write(' CODEBASE="' + codebase + '"');
		sEmbed += ' CODEBASE="' + codebase + '"';
	}

	if(cabbase != null && cabbase != undefined && cabbase != "")
	{
		document.write(' CABBASE="' + cabbase + '"');
		sEmbed += ' CABBASE="' + cabbase + '"';
	}

	if(archive != null && archive != undefined && archive != "")
	{
		document.write(' ARCHIVE="' + archive + '"');
		sEmbed += ' ARCHIVE="' + archive + '"';
	}

	if(MAYSCRIPT != null && MAYSCRIPT != undefined && MAYSCRIPT != "")
	{
		document.write(' MAYSCRIPT="' + MAYSCRIPT + '"');
		sEmbed += ' MAYSCRIPT="' + MAYSCRIPT + '"';
	}
	else
	{
		document.write(' MAYSCRIPT="yes"'); // por defecto lo activamos
		sEmbed += ' MAYSCRIPT="yes"';
	}

	if(alt != null && alt != undefined && alt != "")
	{
		document.write(' ALT="' + alt + '"');
		sEmbed += ' ALT="' + alt + '"';
	}

	if(TITLE != null && TITLE != undefined && TITLE != "")
	{
		document.write(' TITLE="' + TITLE + '"');
		sEmbed += ' TITLE="' + TITLE + '"';
	}

	if(BORDER != null && BORDER != undefined && BORDER != "")
	{
		document.write(' BORDER=' + BORDER);
		sEmbed += ' BORDER=' + BORDER;
	}

	if(width != null && width != undefined && width != "")
	{
		document.write(' WIDTH=' + width);
		sEmbed += ' WIDTH=' + width;
	}

	if(height != null && height != undefined && height != "")
	{
		document.write(' HEIGHT=' + height);
		sEmbed += ' HEIGHT=' + height;
	}

	if(ALIGN != null && ALIGN != undefined && ALIGN != "")
	{
		document.write(' ALIGN="' + ALIGN + '"');
		sEmbed += ' ALIGN="' + ALIGN + '"';
	}

	if(hspace != null && hspace != undefined && hspace != "")
	{
		document.write(' HSPACE=' + hspace);
		sEmbed += ' HSPACE=' + hspace;
	}

	if(vspace != null && vspace != undefined && vspace != "")
	{
		document.write(' VSPACE=' + vspace);
		sEmbed += ' VSPACE=' + vspace;
	}


	document.write('>');
	
	for(var i=0; i < parametros.length; i++)
		document.write('<param name=' + parametros[i].nombre + ' value="' + parametros[i].valor + '">');
		
	sEmbed += "></embed>";

	document.write('\n' + sEmbed + '\n</object>');
}

function writeObject(id, classid, codebase, width, height, params){
	document.write('<OBJECT');
	document.write(' ID="'+id+'"');
	document.write(' CLASSID="'+classid+'"');
	document.write(' CODEBASE="'+codebase+'"');
	if(width)
		document.write(' WIDTH="'+width+'px"');
	if(height)
		document.write(' HEIGHT="'+height+'px"');
	document.write('>');
	if(params&&params.length>0){
		for(var i=0; i < params.length; i++){
			document.write('<param name=' + params[i].nombre + ' value="' + params[i].valor + '">');
		}
	}
	document.write('</OBJECT>');
}

function aleatorio(inferior,superior){ 
	var  numPosibilidades, aleat
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.round(aleat) 
    return parseInt(inferior) + aleat 
}

function idUnicoGet(){
	var fecha=new Date()
	return fecha.getTime()+"_"+aleatorio(1,1000)
}

function idConexionGet(ventana){
	try
	{
		if (typeof ventana.opener=="undefined" || ventana.opener==null){
                        if ( !('idConexion' in ventana.top) ) {
				ventana.top.idConexion=idUnicoGet();
			}
			return ventana.top.idConexion
		}else{
			return idConexionGet(ventana.opener)
		}
	}
	catch(e)
	{
		return idUnicoGet();
	}
}

function idUnicoPaginaGet(){
	return location.href.split("/").pop()
}
