<!--
/*
*	Autor: Pablo Salaberri
*	Descripción:
*		Módulo gestor de imagenes pop dentro del navegador
*
*
*
*/
/**
 * 	Función de búsqueda de objetos
 */
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1);
var isNN=(navigator.appName=="Netscape")?1:0;
//Fix event handler
function fixE(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
}
function pxToInt(pixels){
	integer = pixels.toString();
	integer.replace('px','');
	integer = parseInt(integer);
	return integer;
}
function mousePosition(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return [posx,posy];
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}
/*
 * 	funciones de mensajes
 * 
 * */
function center_floating(_name){

		var qheight = Element.getHeight($(_name));
		
		var qwidth =  Element.getWidth($(_name));
		
		var bheight = Element.getHeight(document.body);
		var bwidth = Element.getWidth(document.body);
		
		qheight = bheight/2-(qheight);
		qwidth = bwidth/2-(qwidth/2);
		
		//style= ';top:'+querydims.height+'px;'+'left:'+querydims.width+'px;position:absolute;';
		 $(_name).setStyle({top:qheight+'px',
		 			left:qwidth+'px',
		 			position:'absolute'});
		 			
		 
		 
		//alert(style);
		
		

}
var hint_timer;
function _show_hint(){
	var div = findObject('hint_div');
	if (div!==null)
	div.style.display='inline';
}
function show_hint(tag, e,hint){
		e = fixE(e);
		
		var div = findObject('hint_div');
		var created = false;
		if (div==null){
			div = document.createElement('div');
			div.id = 'hint_div';
			created = true;
		}
		div.innerHTML=hint;
		posxy = mousePosition(e);
		
		
		set_css_style(div,'display:none;position:absolute;z-index:11;' +
				'top:'+(posxy[1]+15)+'px;left:'+(posxy[0]+15)+'px;' +
				'font-size:11px;' +
				'font-family: Verdana, Arial, Helvetica, sans-serif;color:#333333;padding:5px;' +
				'border:1px #888888 solid; background-color:#f0f0f0;');
		
		if (created){
			document.body.appendChild(div);
		}
		setTimeout(_show_hint,500);
		tag.onmouseout=hide_hint;
}
function hide_hint(){
	var hint = findObject('hint_div');
	if (hint !=undefined){
		del_DOM_element(hint);
	}	
}
function getObject(obj){
	
	var el = isIE ? eval('document.all.'+obj) : document.getElementById(obj);
	return el;
}

function findPos(obj) {
	var curleft =0; var curtop = 0;
	
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	return [curleft,curtop];
}	
function getObjectCarac(obj){
	var object = getObject(obj);
	var position = findPos(obj);
	return Array(position[0],position[1],object.width,object.height);
}



function findObject(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  
  if(!(foundObj = theDoc[theObj]) && theDoc.all){ foundObj = theDoc.all[theObj];}
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = theDoc.getElementById(theObj);
  
  return foundObj;
}
function findObjectPos(_obj) {
	var curleft =0; var curtop = 0;
	var obj;
	if(typeof(_obj)=='string') obj = findObject(_obj);
	else obj=_obj;
	if (obj!==null){
	
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
	}
	return [curleft,curtop];
}	
//******************************* LIBRERÍA

function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

var nmm='';
var sssnd='';
function get_ss(){
	nmm = findObj('nmm');
	sssnd = findObj('sssnd');
}
function set_ssn_action(action){
	get_ss();
	if ((nmm!=null)&&(sssnd!=null)){
		
		ssn_action = action + '&nmm='+nmm.value+'&sssnd='+sssnd.value;
	}
	else ssn_action = action;
	
	return ssn_action;
}


//Function get_window_size
var winW;
var winH;
function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
}
function getWindowWidth() {
			var windowWidth = 0;
			if (typeof(window.innerWidth) == 'number') {
				windowWidth = window.innerWidth;
			}
			else {
				if (document.documentElement && document.documentElement.clientWidth) {
					windowWidth = document.documentElement.clientWidth;
				}
				else {
					if (document.body && document.body.clientWidth) {
						windowWidth = document.body.clientWidth;
					}
				}
			}
			return windowWidth;
}

function iframeToFit(iframe){
	if (iframe.contentDocument){
		var theight = 0;
		var twidth = 0;
		var bodynodes =(iframe.contentDocument.body.childNodes);
		for (var i=0; i<bodynodes.length;i++){
			//alert('Nodo typo'+bodynodes[i].nodeType+' altura '+bodynodes[i].clientHeight);
			var ttheight= (bodynodes[i].clientHeight);
			var ttwidth = (bodynodes[i].clientWidth);
			if (typeof(ttheight)!=='undefined') theight+=parseInt(ttheight);
			if (typeof(ttwidth)!=='undefined') twidth+=parseInt(ttwidth);
		}

		return;
	}
	if (iframe.document){
		//alert(iframe.document);
		return;
	}
	alert('No se encontró el iframe');
}

function getDocumentScrollTop(){
		var ScrollTop = 0;
		if (document.documentElement && document.documentElement.scrollTop) {
					ScrollTop = document.documentElement.scrollTop;
				}
				else {
					if (document.scrollTop) {
						ScrollTop = document.body.scrollTop;
					}
				}
		return ScrollTop;
		
}

function getWindowCenter(){
	
	winH = getWindowHeight();
	winW = getWindowWidth()/2;
	//Scrolles 
	
	
		
	winH = winH/2+getDocumentScrollTop();
	
	
	return Array(winW,winH);
}

function get_win_size(doc){
	if (typeof(doc)=='undefined') doc = document;
	if (parseInt(navigator.appVersion)>3) {

	 if (navigator.appName=="Netscape") {
		  winW = doc.body.clientWidth;
	  	  winH =  doc.body.clientHeight;
	  	 
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  	winW = doc.body.offsetWidth+16;
	  	winH = doc.body.offsetHeight+16;
	 }
	}
	return Array(winW,winH);
}
function getElementWidth(element){
	var height=0;
	for (var i = 0; i <element.childNodes.length;i++){
		var cheight = (element.childNodes[i].clientWidth);
		if (cheight!==undefined){
			var h=parseInt(cheight);
			height+=h;
		}
	}
	return height;
}
function getElementHeight(element){
	var height=0;
	
	for (var i = 0; i <element.childNodes.length;i++){
		var cheight;
		if (window.clientHeight){
		cheight = (element.childNodes[i].clientHeight);
		}
		else{
			cheight = element.offsetHeight;
		}
		if (cheight!==undefined){
			var h=parseInt(cheight);
			height+=h;
		}
	}
	return height;
}
function get_dom_size(_window){
	
	if (parseInt(navigator.appVersion)>3) {

	 if (navigator.appName=="Netscape") {
		 _winW = _window.width;
		 _winH = getElementHeight(_window.body);
		 _winW = _window.height;
		// alert(_winW);
	  	
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	 	//alert(_window.document.body.firstChild.id);
	  	_winW = _window.document.body.clientWidth-16;
	  	_winH = _window.document.body.scrollHeight;
	  	
	 }
	}
	
	return new Array(_winW,_winH);
}
function Cget_win_size(){
	if (parseInt(navigator.appVersion)>3) {

	 if (navigator.appName=="Netscape") {
		  _winW = window.innerWidth;
	  	  if(navigator.userAgent.indexOf('Safari')) _winH = window.innerHeight;
	  	  else _winH = window.innerHeight;
	  	  
	  	
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	 	
	  	_winW = document.body.clientWidth-16;
	  	_winH = document.body.clientHeight-2;
	  	
	 }
	}
	
	return new Array(_winW,_winH);
}
var timeout_error;
function set_error_debug(){
	var errordiv = findObject('errordiv');
	if (errordiv==null)return false;
	errordiv.style.visibility = 'visible';
	
	return true;
}
function set_error(){
	var errordiv = findObject('errordiv');
	if (errordiv==null)return false;
	errordiv.style.visibility = 'visible';
	timeout_error = window.setTimeout(hide_error,2000);
	return true;
}
function hide_error(){
	window.clearTimeout(timeout_error);
	
	var errordiv = findObject('errordiv');
	if (errordiv==null)return false;
	errordiv.style.visibility = 'hidden';
	
}
function getFlashObj(movie){
   if (window.document[movie]) {
      return window.document[movie];
   }
   if (navigator.appName.indexOf("Microsoft Internet")==-1) {
      if (document.embeds && document.embeds[movie]) {
         return document.embeds[movie]; 
      }
   } else {
      return document.getElementById(movie);
   }
}
function getFlashDimensions(movie) {
   var movieObj = getFlashObj(movie);
   
   if (movieObj.TGetProperty("/", 8)) {
	   var width = movieObj.TGetProperty("/", 8);
	   var height= movieObj.TGetProperty("/", 9);
	   movieObj.style.width = width;
	   movieObj.style.height = height;
	
   }
}
function redim_window(){
	
	get_win_size();
	
	if (parseInt(navigator.appVersion)>3) {

	 if (navigator.appName=="Netscape") {
	  window.outerWidth= window.innerWidth;
	  window.outerHeight = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth+16;
	  winH = document.body.offsetHeight+16;
	 }
	}	
}
//******************************* LIBRERÍA

function implode(glue,array){
	var newarray = '';
	for (var i=0 ; i < (array.length-1); i++ ){
		newarray += array[i]+glue;
	}
	newarray +=array[array.length-1];
	return newarray;
}
function set_css_style(item,style){
	
	if (isIE){
		item.style.cssText = style;
		return true;
	}
	else item.setAttribute('style',style);
	return true;
} 
function setClassId(id,classn){
	var element = findObject(id);
	setClass(element,classn);
}
function setClass(item,classn){
	
	if (!isIE){
		item.setAttribute('class',classn);
	}
	else{
		item.className=classn;
		
	}
}
function _getClass(item){
	
	if (item.className){
		return item.className;
	}
	
	return null;
}
//Get scrolling top
function get_win_top_scroll(){
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	return dsoctop;
	
}


//Ficheros
function basename(path) {

	
    return path.replace( /.*\//, "" );
}
function dirname(path) {
	
    return path.match( /.*\// );
}

function get_pathbase(actualdir){
	var loc_ = window.location.toString();
	loc_ = loc_.split('?');
	var dir = loc_[0].toString();
	dir = dir.replace('http://','');
	dir = dir.split('/');
	dir.shift();
	var path=new Array();
	while(dir.length){
		var curdir = dir.shift();
		if (curdir==actualdir) break;
		path.push(curdir);
	}
	ipath = implode('/',path);
	
	return '/'+ipath;
	
}
function set_DOM_elem_value(idelement,valueof){
	var domel = findObj(idelement);
	
	if (domel!==null){
		domel.value=valueof;
	}
	
}
function del_DOM_childs(idelement){
	
	//Buscamos en document.windows para eliminar este elemento
	while(idelement.firstChild){
		idelement.removeChild(idelement.firstChild);
	}
	
}
function del_DOM_element(idelement){
	
	//Buscamos en document.windows para eliminar este elemento
	while(idelement.firstChild){
		idelement.removeChild(idelement.firstChild);
	}
	
	idelement.parentNode.removeChild(idelement);
	
}
//Elementos a eliminar de aqui...
function set_hiperlink(hiperlink){
 	var link = parent.document.getElementById('url');
 		link.value=hiperlink;
}
function set_imageurl(hiperlink){
 	var link = parent.document.getElementById('imageurl');
 		link.value=hiperlink;
}

//Gestión de envio de GET
var getvalue = new Array();
function set_get_value(variable,valor){
	var nueva = true;
	
	for (var i=0; i<getvalue.length;i++){
		if(getvalue[i][0]==variable){
	
			nueva = false;
			getvalue[i][1]=valor;
		}
	}
	if (nueva){
	
		getvalue[getvalue.length] =variable+'='+valor;
	}
	
	return void(0);
}

function go_get(){
	var current = window.location;
	var uri_path = current.toString();
	var path = uri_path.split("?");
	//Obtenemos el elemento _file_
	var get=implode('&',getvalue);
	var new_path=path[0]+'?'+get;
	
	window.location = new_path.toString();
	return true;
	
	
}
//Inhabilita el enter en los formularios 
function disableEnterKey(e)
{
     return true;
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}
//Creación de un elemento de carga de archivos independiente y que se cargue solo
function create_formupload(formname,nombre){
	
	if ((eval('typeof(document.'+nombre+')')) !=='undefined'){
		if (eval('document.'+nombre+'==true')) return;
		
	}
	else eval('document.'+nombre+"=true");
	
	var div = document.createElement('div');
		div.id='uploadcontainer';
		set_css_style(div,'float:right;position:relative;z-index:10;padding:5px;background-color:#cccccc;border:1px #a3a3a3 solid;' +
				'font-family: Verdana, Arial;	font-size: 10px;	font-style:normal;');	
	var input =document.createElement('input');
		input.type='file';
		input.id = 'archivo';
		set_css_style(input,'font-family: Verdana, Arial;	font-size: 10px;	font-style:normal;');	
		div.appendChild(input);
		main = findObject(formname);
	var input2 =document.createElement('input');
		input2.type='submit';
		input2.id = 'upload';
		input2.value='ok';
		set_css_style(input2,'font-family: Verdana, Arial;	font-size: 10px;	font-style:normal;');
		div.appendChild(input2);
	var input3 =document.createElement('input');
		input3.type='button';
		input3.id = 'cancelarup';
		input3.value='cancelar';
		set_css_style(input3,'font-family: Verdana, Arial;	font-size: 10px;	font-style:normal;');
		input3.padre = div;
		input3.onclick = function(){
			
			del_DOM_element(this.padre);
		}			
		div.appendChild(input3);
		
		main = findObject(formname);
		main.appendChild(div);
}
function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // %          note: Table from http://www.the-art-of-web.com/html/character-codes/
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    useTable      = (table ? table.toUpperCase() : 'HTML_SPECIALCHARS');
    useQuoteStyle = (quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT');
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
    
    // Map numbers to strings for compatibilty with PHP constants
    if (!isNaN(useTable)) {
        useTable = constMappingTable[useTable];
    }
    if (!isNaN(useQuoteStyle)) {
        useQuoteStyle = constMappingQuoteStyle[useQuoteStyle];
    }
    
    if (useQuoteStyle != 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
 
    if (useQuoteStyle == 'ENT_QUOTES') {
        entities['39'] = '&#039;';
    }
 
    if (useTable == 'HTML_SPECIALCHARS') {
        // ascii decimals for better compatibility
        entities['38'] = '&amp;';
        entities['60'] = '&lt;';
        entities['62'] = '&gt;';
    } else if (useTable == 'HTML_ENTITIES') {
        // ascii decimals for better compatibility
      entities['38']  = '&amp;';
      entities['60']  = '&lt;';
      entities['62']  = '&gt;';
      entities['160'] = '&nbsp;';
      entities['161'] = '&iexcl;';
      entities['162'] = '&cent;';
      entities['163'] = '&pound;';
      entities['164'] = '&curren;';
      entities['165'] = '&yen;';
      entities['166'] = '&brvbar;';
      entities['167'] = '&sect;';
      entities['168'] = '&uml;';
      entities['169'] = '&copy;';
      entities['170'] = '&ordf;';
      entities['171'] = '&laquo;';
      entities['172'] = '&not;';
      entities['173'] = '&shy;';
      entities['174'] = '&reg;';
      entities['175'] = '&macr;';
      entities['176'] = '&deg;';
      entities['177'] = '&plusmn;';
      entities['178'] = '&sup2;';
      entities['179'] = '&sup3;';
      entities['180'] = '&acute;';
      entities['181'] = '&micro;';
      entities['182'] = '&para;';
      entities['183'] = '&middot;';
      entities['184'] = '&cedil;';
      entities['185'] = '&sup1;';
      entities['186'] = '&ordm;';
      entities['187'] = '&raquo;';
      entities['188'] = '&frac14;';
      entities['189'] = '&frac12;';
      entities['190'] = '&frac34;';
      entities['191'] = '&iquest;';
      entities['192'] = '&Agrave;';
      entities['193'] = '&Aacute;';
      entities['194'] = '&Acirc;';
      entities['195'] = '&Atilde;';
      entities['196'] = '&Auml;';
      entities['197'] = '&Aring;';
      entities['198'] = '&AElig;';
      entities['199'] = '&Ccedil;';
      entities['200'] = '&Egrave;';
      entities['201'] = '&Eacute;';
      entities['202'] = '&Ecirc;';
      entities['203'] = '&Euml;';
      entities['204'] = '&Igrave;';
      entities['205'] = '&Iacute;';
      entities['206'] = '&Icirc;';
      entities['207'] = '&Iuml;';
      entities['208'] = '&ETH;';
      entities['209'] = '&Ntilde;';
      entities['210'] = '&Ograve;';
      entities['211'] = '&Oacute;';
      entities['212'] = '&Ocirc;';
      entities['213'] = '&Otilde;';
      entities['214'] = '&Ouml;';
      entities['215'] = '&times;';
      entities['216'] = '&Oslash;';
      entities['217'] = '&Ugrave;';
      entities['218'] = '&Uacute;';
      entities['219'] = '&Ucirc;';
      entities['220'] = '&Uuml;';
      entities['221'] = '&Yacute;';
      entities['222'] = '&THORN;';
      entities['223'] = '&szlig;';
      entities['224'] = '&agrave;';
      entities['225'] = '&aacute;';
      entities['226'] = '&acirc;';
      entities['227'] = '&atilde;';
      entities['228'] = '&auml;';
      entities['229'] = '&aring;';
      entities['230'] = '&aelig;';
      entities['231'] = '&ccedil;';
      entities['232'] = '&egrave;';
      entities['233'] = '&eacute;';
      entities['234'] = '&ecirc;';
      entities['235'] = '&euml;';
      entities['236'] = '&igrave;';
      entities['237'] = '&iacute;';
      entities['238'] = '&icirc;';
      entities['239'] = '&iuml;';
      entities['240'] = '&eth;';
      entities['241'] = '&ntilde;';
      entities['242'] = '&ograve;';
      entities['243'] = '&oacute;';
      entities['244'] = '&ocirc;';
      entities['245'] = '&otilde;';
      entities['246'] = '&ouml;';
      entities['247'] = '&divide;';
      entities['248'] = '&oslash;';
      entities['249'] = '&ugrave;';
      entities['250'] = '&uacute;';
      entities['251'] = '&ucirc;';
      entities['252'] = '&uuml;';
      entities['253'] = '&yacute;';
      entities['254'] = '&thorn;';
      entities['255'] = '&yuml;';
    } else {
        throw Error("Table: "+useTable+' not supported');
        return false;
    }
    
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}
function htmlspecialchars_decode(string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Mateusz "loonquawl" Zalega
    // +      input by: ReverseSyntax
    // +      input by: Slawomir Kaniecki
    // +      input by: Scott Cariss
    // +      input by: Francois
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
    // *     returns 1: '<p>this -> &quot;</p>'
 	if (string==undefined) return '';
 	if (string=='') return '';
 	
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
        return false;
    }
 
    // &amp; must be the last character when decoding!
    delete(histogram['&']);
    histogram['&'] = '&amp;';
 
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    
    return tmp_str;
}
function htmlentities (string, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: nobbler
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: get_html_translation_table
    // *     example 1: htmlentities('Kevin & van Zonneveld');
    // *     returns 1: 'Kevin &amp; van Zonneveld'
    // *     example 2: htmlentities("foo'bar","ENT_QUOTES");
    // *     returns 2: 'foo&#039;bar'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
    
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(symbol).join(entity);
    }
    
    return tmp_str;
}
function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, tmp_arr = [], unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}
function openwindow(src,where){
	//src = urlencode(src);
	window.open(src,where);		
}

function post_form(form){
	var form = findObject(form);
	if (form!==null){
		form.submit();
	}	
}
function set_post_action(form,action){
	//Obtenemos el elemento _file_
	
	var form = findObject(form);
	
	var urlaction ;
	var mod_sel = findObject('mod_sel');
	
	if (mod_sel == null){
		mod_sel = document.createElement('input');
		mod_sel.style.visibility = 'hidden';
		mod_sel.style.display='none';
		mod_sel.id = 'mod_sel';
		mod_sel.name = 'mod_sel';
		form.appendChild(mod_sel);
	}
	
	mod_sel.value = action;
	//Obtenemos el elemento _file_
	
	
	form.submit();
	
	
	return false;
	
}
function set_input_value(formname){
	
	var form = findObject(formname);
	var a= set_input_value.arguments;
	if (form==null) return;
	if (a.length>1){
		for (var i = 1; i < a.length;i=i+2){
			var mod_sel = findObject(a[i]);
			
			var append = mod_sel==null?true:false;
			if (mod_sel==null){
				var mod_sel = document.createElement('input');
				mod_sel.style.visibility = 'hidden';
				mod_sel.style.display='none';
				mod_sel.id = a[i];
				mod_sel.name = a[i];
			}
			
			mod_sel.value= a[i+1];
			
			if (append){
			
				 form.appendChild(mod_sel);
			}
		}
	}
	
		

	
}
function form_submit(formname){
	
	var form = findObject(formname);
	var a= form_submit.arguments;
	if (form==null) return;
	if (a.length>1){
		for (var i = 1; i < a.length;i=i+2){
			
			var mod_sel = findObject(a[i]);
			if (mod_sel==null){
				var mod_sel = document.createElement('input');
				mod_sel.style.visibility = 'hidden';
				mod_sel.id = a[i];
				mod_sel.name = a[i];
			}
			mod_sel.value= a[i+1];
			form.appendChild(mod_sel);
		}
	}
	
		

	if(form!==null){
		form.submit();
	}
}
function set_redim_flash(where,nombre,path,width,height){
	var dnombre = findObject(nombre);
	var dpath = findObject(path);
	var dwidth = findObject(width);
	var dheight = findObject(height);
	
	dheight.path=dwidth.path = dpath.value;
	dheight.nombre=dwidth.nombre=dnombre.value;
	dheight.dwidth = dwidth;
	dwidth.dheight = dheight;
	dwidth.onkeydown=function(e){
		redim_flash(where,this.nombre,this.path,this.value,dheight.value);
		return disableEnterKey(e);
	}
	dheight.onkeydown=function(e){
		redim_flash(where,this.nombre,this.path,dheight.value,this.value);
		return disableEnterKey(e);
	}
}
//GEstión de un flash... redimensionado
function redim_flash(where,nombre,path,width,height){
			var dwhere = findObject(where);
			var code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="index"'+
						' width="'+width+'" height="'+height+'" align="middle">'+
						' <param name="allowScriptAccess" value="sameDomain" />'+
						' <param name="movie" value="'+nombre+'" />'+
						'<param name="quality" value="high" />	<param name="bgcolor" value="#ffffff" />'+
						'<embed src="'+path+'" quality="high" bgcolor="#cccccc"'+
						'width="'+width+'" height="'+height+'" swLiveConnect=true '+
						'id="index" name="index" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
			dwhere.innerHTML = code;
}

//Gestión de datos de un formulario cualquiera
function set_floating_input(form,input_title,input_name,input_type){
		set_modal_mask();
		var div_outer = document.createElement('div');
		var div_inner = document.createElement('div');
		var div_text = document.createElement('div');
		var input_title = document.createTextNode(input_title);
		var input = document.createElement('input');
			input.type = input_type;
			input.name = input_name;
			input.id = input_name;
			setClass(div_outer,'floating_input_outer');
			setClass(div_inner,'floating_input_inner');
			setClass(div_text,'floating_input_text');

			div_text.appendChild(input_title);
			div_text.appendChild(input);
			
			
			var submit= document.createElement('input');
					submit.type ='submit';
					submit.name='post';
					submit.id = 'post';
					submit.value="Aceptar";
					setClass(submit,'floating_input_input');
					div_text.appendChild(submit);
			div_inner.appendChild(div_text);
			div_outer.appendChild(div_inner);
			if (document.forms){
				document.forms[form].appendChild(div_outer);
				
			}
}
function common_submit(formulario){
	
	for(i=0; i<submit_handler.get_f_count();i++){
		
		if (!submit_handler.exec_f(i))
			return false;
	}
	var form;
	if (typeof(formulario)!=='undefined'){
		form = findObject(formulario);
	}
	else{
		form = findObject('formulario');
	}
	form.submit();
	return true;

}
function add_submit_function(_function){
	
	submit_handler.add_submit_function(_function);
	return true;
}

function _submit_handler(){
	this.submit_functions=new Array();
	if (typeof(_submit_handler_prototype_called) == 'undefined')
  
  {
     _submit_handler_prototype_called = true;
     _submit_handler.prototype.add_submit_function = add_submit_function;
     _submit_handler.prototype.get_f_count = get_f_count;
     _submit_handler.prototype.exec_f = exec_f;
     
  }
  function add_submit_function(_function){
  	this.submit_functions.push(_function);
  }
  function get_f_count(){
  	
  	return this.submit_functions.length;
  }
  function exec_f(i){
  	return this.submit_functions[i]();
  }
	
}
var submit_handler=new _submit_handler();

function get_full_base_path(){
	var path = document.URL?document.URL:document.location.href;
	
	path = path.split('/');
	host=Array();
	(path.shift());host.push(path.shift());host.push(path.shift());
	var base_path = Array();
	dir = path.shift();
	
	var i = 0;
	while((dir !='index.php')&&(dir!=='administrador')&&(typeof(dir)!=='undefined')){
		base_path.push(dir);
		dir = path.shift();
		i++;
		if (i==20) break; //Anti bloqueo
	}
	var directory='';
	if (base_path.length){
		directory='/'+implode('/',base_path);
	}
	
	return 'http:/'+implode('/',host)+directory;
}
function get_base_path(){
	var path = document.URL?document.URL:document.location.href;
	
	path = path.split('/');
	
	(path.shift());(path.shift());(path.shift());
	var base_path = Array();
	dir = path.shift();
	
	var i = 0;
	while((dir !='index.php')&&(dir!=='administrador')&&(typeof(dir)!=='undefined')){
		base_path.push(dir);
		dir = path.shift();
		i++;
		if (i==20) break; //Anti bloqueo
	}
	return '/'+implode('/',base_path);
	
}

/*****
 * 		PARCHE PARA QUE NO SE PRODUZCAN PROBLEMAS AL CAMBIAR DE SECCIÓN
 * ******/
 function clear_patch(_formulario){
 	
 	var formulario = findObject(_formulario);
 	var find_items = new Array('page','edit','cancelf','editsection','orderkey','buscar');
 	
 	var a = clear_patch.arguments;
 	if (a.length>1){
 		for(var i= 1; i < a.length;i++) find_items.push(a[i]);
 	}
 	for (var i=0; i<find_items.length;i++){
 		
 		if (typeof(formulario.elements[find_items[i]])!=='undefined'){
 			var elemento = formulario.elements[find_items[i]];
 			
 			elemento = findObject(elemento.id);
 			
 			elemento.parentNode.removeChild(elemento);
 		}
 	}
 
 }
 /**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

/****BOLETINS******/
function see_curboletin(sssnd){
	var current_id = get_selected_list_elems();
	if (current_id.length){
		current_id = current_id[0];
		
		current_id_ = current_id.replace('id','');
		
		var header = '../newsletter/index.php?sssnd='+sssnd+'&dt='+current_id_;
		
		open_modal(header,'Boletin',600,800);
	}
	
}
/****BOLETINS******/
function see_sendboletin(sssnd){
	var current_id = get_selected_list_elems();
	if (current_id.length){
		current_id = current_id[0];
		
		current_id_ = current_id.replace('id','');
		
		var header = '../newsletter/index.php?sssnd='+sssnd+'&dt='+current_id_;
		alert('see');
		open_modal(header,'Envío',800,800);
	}
	
}
