var openDiv = null;
var hiddenObjects = new Array();
var currentContentDiv = null;
var currentMarkerDiv = null;
var currentMarkerBackDiv = null;

//Extra
//adicionado dado que nao é usado o formValidation.js
function trim(stringToTrim){
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

function hasWhiteSpace(s){
    reWhiteSpace = new RegExp(/\s/);
    if (reWhiteSpace.test(s)) {
        testresults = true;
    }
    else {
        testresults = false;
    }
    return (testresults);
}

function isEmailAddr(email){
    var str = email
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str)) {
        testresults = true;
    }
    else {
        testresults = false;
    }
    return (testresults);
}
//Extra

function resizeContents(delta){
    var height = 0;

    if (window.innerWidth) {//if browser supports window.innerWidth
        height = window.innerHeight;
    }
    else if (document.all) {//else if browser supports document.all (IE 4+)
       	height = document.body.clientHeight;
	}
    height = height - delta;
	var markerHeight = Math.max(currentMarkerDiv.offsetTop, currentMarkerBackDiv.offsetTop);

	//alert(height + " > marker: " + currentMarkerDiv.offsetTop + ", background: " + currentMarkerBackDiv.style.height+ ", content: " + currentContentDiv.style.height);
    if (height > markerHeight) {
        currentContentDiv.style.height = height + 'px';
    }
	else {
		currentContentDiv.style.height = markerHeight + 'px';
	}
}


function showDiv(object, width, height){
    window.scrollTo(0, 0);

    var objects = document.getElementsByTagName('object');
    for (var i = 0; i != objects.length; i++) {
        if (objects[i].style.visibility != 'hidden') {
            objects[i].style.visibility = 'hidden';
            hiddenObjects[hiddenObjects.length] = objects[i];
        }
    }

    //centrar o popup na horizontal
    if (window.innerWidth) {
        document.getElementById(object).style.left = ((window.innerWidth / 2) - (width / 2)) + 'px';
    }
    else {
        document.getElementById(object).style.left = ((document.body.offsetWidth / 2) - (width / 2)) + 'px';
    }

    document.getElementById(object).style.top = '150px';

    document.getElementById('overlay_popup').style.display = 'block';
    document.getElementById(object).style.display = 'block';

    openDiv = object;
}

function showMessageDiv(object, text, title, width, height){
    window.scrollTo(0, 0);

    var objects = document.getElementsByTagName('object');
    for (var i = 0; i != objects.length; i++) {
        if (objects[i].style.visibility != 'hidden') {
            objects[i].style.visibility = 'hidden';
            hiddenObjects[hiddenObjects.length] = objects[i];
        }
    }

    if (window.innerWidth) {
        document.getElementById(object).style.left = ((window.innerWidth / 2) - (width / 2)) + 'px';
    }
    else {
        document.getElementById(object).style.left = ((document.body.offsetWidth / 2) - (width / 2)) + 'px';
    }

    document.getElementById(object).style.top = '150px';

    document.getElementById('overlay_popup').style.display = 'block';
    document.getElementById(object).style.display = 'block';

    document.getElementById(object + 'Title').innerHTML = title;
    document.getElementById(object + 'Text').innerHTML = text;

    openDiv = object;
}

function hideDiv(object){
    document.getElementById(object).style.display = 'none';

    if (document.getElementById('overlay_popup')) {
        document.getElementById('overlay_popup').style.display = 'none';
    }
    for (var i = 0; i != hiddenObjects.length; i++) {
        hiddenObjects[i].style.visibility = 'visible';
    }
    openDiv = null;
}

var lastChapter;

function toggle (objecto) {
	if (document.getElementById(objecto).style.display == 'none') {
		document.getElementById(objecto).style.display = 'block';
		lastChapter = objecto;
	} else {
		document.getElementById(objecto).style.display = 'none';
	}
}

var page = new Array();
var lastpage = new Array();
function abre(div){
    var prefixDiv = div.substring(0, div.indexOf('_', 0));
    var sufixDiv = div.substring(div.indexOf('_', 0) + 1, div.length);

    if (document.getElementById(div) != null) {
        if (document.getElementById(div).style.display == 'block') {
            document.getElementById(div).style.display = 'none';
        }
        else {
            document.getElementById(div).style.display = 'block';
        }
    }

    //fechar todas as divs do mesmo nivel
    if (prefixDiv != 'lasterpage') {
        if (prefixDiv == 'page') {
            for (i in page) {
                if (sufixDiv != page[i]) {
                    element = prefixDiv + '_' + page[i];
                    if (document.getElementById(element) != null) {
                        document.getElementById(element).style.display = 'none';
                    }

                }
            }
        }
        else
            if (prefixDiv == 'lastpage') {
                for (i in lastpage) {
                    if (sufixDiv != lastpage[i]) {
                        element = prefixDiv + '_' + lastpage[i];
                        if (document.getElementById(element) != null) {
                            document.getElementById(element).style.display = 'none';
                        }
                    }
                }
            }
    }
}

ultimoCapitulo = null;

function trocaMapa(objecto){
    if (document.getElementById(objecto).style.display != 'block') {
        document.getElementById(objecto).style.display = 'block';
        if (ultimoCapitulo != null){
            document.getElementById(ultimoCapitulo).style.display = 'none';
        }
        ultimoCapitulo = objecto;
    }
    else if (ultimoCapitulo != objecto){

        document.getElementById(objecto).style.display = 'none';
    }
}

ultimo = null;

function Mapa(objecto){
    if (document.getElementById(objecto).style.display != 'block') {
        document.getElementById(objecto).style.display = 'block';
        if (ultimo != null){
            document.getElementById(ultimo).style.display = 'none';
        }
        ultimo = objecto;
    }
    else if (ultimo != objecto){

        document.getElementById(objecto).style.display = 'none';
    }
}

function retrieveCountries(result){

	var divName = document.getElementById('CountryBox');

	for (var i = 0; i != result.length; ++i) {
		var item = document.createElement('p');

		item.className = "select";
		item.onmouseover = function(){
			this.className = 'selectOver';
		};
		item.onmouseout = function(){
			this.className = 'select';
		};

		item.onclick = function(){
			var inputName = document.getElementById('country');
			var inputIdentificator = document.getElementById('selectedCountry');
			inputIdentificator.value = this.zepp_id;
			inputName.innerHTML = this.innerHTML;
		};

		item.zepp_id = result[i].countryIdentificator;
		item.innerHTML = result[i].countryName;

		divName.appendChild(item);

	}
}

function retrieveFlavours(result){

	var divName = document.getElementById('FlavourBox');

	for (var i = 0; i != result.length; ++i) {
		var item = document.createElement('p');

		item.className = "select";
		item.onmouseover = function(){
			this.className = 'selectOver';
		};
		item.onmouseout = function(){
			this.className = 'select';
		};

		item.onclick = function(){
			var inputName = document.getElementById('flavour');
			var inputIdentificator = document.getElementById('selectedFlavour');
			inputIdentificator.value = this.zepp_id;
			inputName.innerHTML = this.innerHTML;
		};

		item.zepp_id = result[i];
		item.innerHTML = result[i];

		divName.appendChild(item);

	}
}

function toggleQuestion(id){
    var image = document.getElementById(id + '_img');
    var question = document.getElementById(id + '_question');
    var answer = document.getElementById(id + '_answer');

    if (answer.style.display == null || answer.style.display == 'none') {
        answer.style.display = 'block';
        image.src = 'images/bt_close_question.gif';
        question.style.color = '#e0003b';
    }
    else {
        answer.style.display = 'none';
        image.src = 'images/bt_open_question.gif';
        question.style.color = '#6e6e6e';
    }
}

function Centrar(pagina, titulo, w, h, scrollu, resize){
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
    settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scrollu + ',resizable=' + resize + '';
    win = window.open(pagina, titulo, settings)
}

function recoverPass(){
    document.getElementById('recoverPassForm').style.display = 'block';
    document.getElementById('loginBox').style.display = 'none';
}

function getXMLHttpRequest(){
    var httpRequest;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
    }
    else
        if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                }
            }
        }

    return httpRequest;
}

function openPageHighlight(pageHighlightID){
    var httpRequest = getXMLHttpRequest();

    httpRequest.open('GET', 'stats.php?contentType=PageHighlight&contentID=' + pageHighlightID, true);
    httpRequest.send(null);
}

function openSearch(searchString){
    var httpRequest = getXMLHttpRequest();

    httpRequest.open('GET', 'stats.php?contentType=Search&contentID=' + escape(searchString), true);
    httpRequest.send(null);
}

function openBannerPage(bannerID, pageID, baseURL){
    if (baseURL == null)
        baseURL = '';

    var httpRequest = getXMLHttpRequest();

    httpRequest.open('GET', baseURL + 'stats.php?contentType=BannerPage&contentID=' + bannerID + '&pageID=' + pageID, true);
    httpRequest.send(null);
}

var navigate_to = null;
function showLogin(destino){
    navigate_to = destino;

    document.getElementById('login_form').style.display = 'block';
    document.getElementById('registo_form').style.display = 'none';
    document.getElementById('recuperar_form').style.display = 'none';

    showDiv('divLogin', 298, 177);
}

function submitForm(toSubmit){
    var httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = function(){
        receiveResponse(httpRequest, toSubmit);
    };

    var requestParameters = '';
    requestParameters += escape('__submited_action') + '=' + escape(toSubmit.__submited_action.value) + '&';
    if (toSubmit.username != null)
        requestParameters += escape('username') + '=' + escape(toSubmit.username.value) + '&';
    if (toSubmit.email != null)
        requestParameters += escape('email') + '=' + escape(toSubmit.email.value) + '&';
    if (toSubmit.password != null)
        requestParameters += escape('password') + '=' + escape(toSubmit.password.value) + '&';
    if (toSubmit.confpassword != null)
        requestParameters += escape('confpassword') + '=' + escape(toSubmit.confpassword.value) + '&';
    if (toSubmit.aceitar != null && toSubmit.aceitar.checked)
        requestParameters += escape('aceitar') + '=' + escape(toSubmit.aceitar.value) + '&';
    if (toSubmit.pageID != null)
        requestParameters += escape('pageID') + '=' + escape(toSubmit.pageID.value) + '&';

    httpRequest.open('POST', 'request.php', true);
    httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    httpRequest.send(requestParameters);

    return false;
}

function logout(){
    navigate_to = null;
    var httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = function(){
        receiveResponse(httpRequest, null);
    };

    var requestParameters = escape('__submited_action') + '=' + escape('Entity:Logout');

    httpRequest.open('POST', 'request.php', true);
    httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    httpRequest.send(requestParameters);
}

function receiveResponse(httpRequest, submitedForm){
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            if (httpRequest.responseText == 'ok') {
                if (navigate_to == null || navigate_to == '') {
                    window.location.reload(true);
                }
                else {
                    window.location.href = navigate_to;
                }
            }
            else {
                if (submitedForm != null) {
                    var htmlElement = document.getElementById(submitedForm.id + '_error');
                    if (htmlElement) {
                        htmlElement.innerHTML = httpRequest.responseText;
                        htmlElement.style.display = 'block';

                        var x = htmlElement.getElementsByTagName("script");
                        for (var i = 0; i < x.length; i++) {
                            eval(x[i].innerHTML);
                        }
                    }
                    else {
                        alert(httpRequest.responseText);
                    }
                }
                else {
                    alert(httpRequest.responseText);
                }
            }
        }
        else {
            alert(httpRequest.responseText);
            alert('There was a problem with the request.');
        }
    }
}

function sinopse(scheduleRecordLink){
    var httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = function(){
        receiveSinopse(httpRequest);
    };

    httpRequest.open('GET', scheduleRecordLink + '&version_id=1', true);
    httpRequest.send(null);
}

function receiveSinopse(httpRequest){
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            var htmlElement = document.getElementById('detalheProgramacao');
            if (htmlElement) {
                htmlElement.innerHTML = httpRequest.responseText;
            }

            showDiv('detalheProgramacao', 637, 300);
        }
        else {
            alert(httpRequest.responseText);
        }
    }
    else {
    }
}

/* função que altera a source de uma imagem */
function changeImgSource(target, newSource){
    document.getElementById(target).src = newSource;
}

/* função que altera o valor de um elemento */
function setFilePath(target, value){
    document.getElementById(target).value = value;
}

/* funcao que preenche os dados do postal para envio */
function fillPostcard(){
    document.getElementById('senderName').value = document.getElementById('preSenderName').value;
    document.getElementById('friendName').value = document.getElementById('preFriendName').value;
    document.getElementById('friendEmail').value = document.getElementById('preFriendEmail').value;
    document.getElementById('message').innerHTML = document.getElementById('preMessage').value;
}


function setHeader(header, section){

    targetHeader = document.getElementById(header);

    if (screen.width <= 1024) {
        targetHeader.style.backgroundImage = 'url(images/header/1024/' + section + '/1.jpg)';
    }
    else
        if (screen.width <= 1152) {
            targetHeader.style.backgroundImage = 'url(images/header/1152/' + section + '/1.jpg)';
        }
        else
            if (screen.width <= 1280) {
                targetHeader.style.backgroundImage = 'url(images/header/1280/' + section + '/1.jpg)';
            }
            else
                if (screen.width <= 1440) {
                    targetHeader.style.backgroundImage = 'url(images/header/1440/' + section + '/1.jpg)';
                }


}

function getResolution(){
    var today = new Date();
    var the_date = new Date("December 31, 2023");
    var the_cookie_date = the_date.toGMTString();
    var the_cookie = "users_resolution=" + screen.width + "x" + screen.height;
    var the_cookie = the_cookie + ";expires=" + the_cookie_date;
    document.cookie = the_cookie
	location.reload(true);
}



var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;

  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = -2;
    }
    else
    {
      element.FadeState = 2;
    }
  }

  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }
}

function animateFade(lastTick, eid)
{
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;

  var element = document.getElementById(eid);

  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }

  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';

  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function submitAJAXForm(formID, callback) {

	var httpRequest = getXMLHttpRequest();

	httpRequest.onreadystatechange = callback;

	var toSubmit = document.getElementById(formID);
	var inputs = toSubmit.getElementsByTagName('input');
	var texts = toSubmit.getElementsByTagName('textarea');
	var selects = toSubmit.getElementsByTagName('select');
	var requestParameters = '';

	for (i = 0; i != inputs.length; i++) {
		if ((inputs[i].attributes['name']) && (inputs[i].value)) {
			if (/file|text|password/.test(inputs[i].type)) {
				if (requestParameters.length != 0) {
					requestParameters += '&';
				}
				requestParameters += escape(inputs[i].attributes['name'].nodeValue) + '=' + escape(inputs[i].value);
			}
			else if (/radio|checkbox/.test(inputs[i].type)) {
				if (inputs[i].checked) {
					if (requestParameters.length != 0) {
						requestParameters += '&';
					}
					requestParameters += escape(inputs[i].attributes['name'].nodeValue) + '=' + escape(inputs[i].value);
				}
			}
			else if (/hidden/.test(inputs[i].type)) {
				if (requestParameters.length != 0) {
					requestParameters += '&';
				}
				requestParameters += escape(inputs[i].attributes['name'].nodeValue) + '=' + escape(inputs[i].value);
			}
		}
	}
	for (i = 0; i != texts.length; i++) {
		if ((texts[i].attributes['name']) && (texts[i].value)) {
			if (requestParameters.length != 0) {
				requestParameters += '&';
			}
			requestParameters += escape(texts[i].attributes['name'].nodeValue) + '=' + escape(htmlEntitiesDecode(texts[i].value));
		}
	}
	for (i = 0; i != selects.length; i++) {
		if ((selects[i].attributes['name']) && ((selects[i].selectedIndex != -1))) {
			if (requestParameters.length != 0) {
				requestParameters += '&';
			}
			requestParameters += escape(selects[i].attributes['name'].nodeValue) + '=' + escape(selects[i].options[selects[i].selectedIndex].value);
		}
	}

	var method = toSubmit.method.toUpperCase();
	httpRequest.open(method, toSubmit.action, true);
	if (method == 'POST') {
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType(((navigator.appName.indexOf("Microsoft") != -1) ? 'octetstream' : 'octet-stream') + ';');
		}
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

	httpRequest.send(requestParameters);
}

function htmlEntitiesDecode(data){
	data = "" + data;
    data = data.replace(/&(\w+);/g, function(wholematch, match){
        switch (match) {
            case 'nbsp':
                return String.fromCharCode(32);

            case 'iexcl':
                return String.fromCharCode(161);

            case 'cent':
                return String.fromCharCode(162);

            case 'pound':
                return String.fromCharCode(163);

            case 'curren':
                return String.fromCharCode(164);

            case 'yen':
                return String.fromCharCode(165);

            case 'brvbar':
                return String.fromCharCode(166);

            case 'sect':
                return String.fromCharCode(167);

            case 'uml':
                return String.fromCharCode(168);

            case 'copy':
                return String.fromCharCode(168);

            case 'ordf':
                return String.fromCharCode(170);

            case 'laquo':
                return String.fromCharCode(171);

            case 'not':
                return String.fromCharCode(172);

            case 'shy':
                return String.fromCharCode(173);

            case 'reg':
                return String.fromCharCode(174);

            case 'macr':
                return String.fromCharCode(175);

            case 'deg':
                return String.fromCharCode(176);

            case 'plusmn':
                return String.fromCharCode(177);

            case 'sup2':
                return String.fromCharCode(178);

            case 'sup3':
                return String.fromCharCode(179);

            case 'acute':
                return String.fromCharCode(180);

            case 'micro':
                return String.fromCharCode(181);

            case 'para':
                return String.fromCharCode(182);

            case 'middot':
                return String.fromCharCode(183);

            case 'cedil':
                return String.fromCharCode(184);

            case 'sup1':
                return String.fromCharCode(185);

            case 'ordm':
                return String.fromCharCode(186);

            case 'raquo':
                return String.fromCharCode(187);

            case 'frac14':
                return String.fromCharCode(188);

            case 'frac12':
                return String.fromCharCode(189);

            case 'frac34':
                return String.fromCharCode(190);

            case 'iquest':
                return String.fromCharCode(191);

            case 'Agrave':
                return String.fromCharCode(192);

            case 'Aacute':
                return String.fromCharCode(193);

            case 'Acirc':
                return String.fromCharCode(194);

            case 'Atilde':
                return String.fromCharCode(195);

            case 'Auml':
                return String.fromCharCode(196);

            case 'Aring':
                return String.fromCharCode(197);

            case 'AElig':
                return String.fromCharCode(198);

            case 'Ccedil':
                return String.fromCharCode(199);

            case 'Egrave':
                return String.fromCharCode(200);

            case 'Eacute':
                return String.fromCharCode(201);

            case 'Ecirc':
                return String.fromCharCode(202);

            case 'Euml':
                return String.fromCharCode(203);

            case 'Igrave':
                return String.fromCharCode(204);

            case 'Iacute':
                return String.fromCharCode(205);

            case 'Icirc':
                return String.fromCharCode(206);

            case 'Iuml':
                return String.fromCharCode(207);

            case 'ETH':
                return String.fromCharCode(208);

            case 'Ntilde':
                return String.fromCharCode(209);

            case 'Ograve':
                return String.fromCharCode(210);

            case 'Oacute':
                return String.fromCharCode(211);

            case 'Ocirc':
                return String.fromCharCode(212);

            case 'Otilde':
                return String.fromCharCode(213);

            case 'Ouml':
                return String.fromCharCode(214);

            case 'times':
                return String.fromCharCode(215);

            case 'Oslash':
                return String.fromCharCode(216);

            case 'Ugrave':
                return String.fromCharCode(217);

            case 'Uacute':
                return String.fromCharCode(218);

            case 'Ucirc':
                return String.fromCharCode(219);

            case 'Uuml':
                return String.fromCharCode(220);

            case 'Yacute':
                return String.fromCharCode(221);

            case 'THORN':
                return String.fromCharCode(222);

            case 'szlig':
                return String.fromCharCode(223);

            case 'agrave':
                return String.fromCharCode(224);

            case 'aacute':
                return String.fromCharCode(225);

            case 'acirc':
                return String.fromCharCode(226);

            case 'atilde':
                return String.fromCharCode(227);

            case 'auml':
                return String.fromCharCode(228);

            case 'aring':
                return String.fromCharCode(229);

            case 'aelig':
                return String.fromCharCode(230);

            case 'ccedil':
                return String.fromCharCode(231);

            case 'egrave':
                return String.fromCharCode(232);

            case 'eacute':
                return String.fromCharCode(233);

            case 'ecirc':
                return String.fromCharCode(234);

            case 'euml':
                return String.fromCharCode(235);

            case 'igrave':
                return String.fromCharCode(236);

            case 'iacute':
                return String.fromCharCode(237);

            case 'icirc':
                return String.fromCharCode(238);

            case 'iuml':
                return String.fromCharCode(239);

            case 'eth':
                return String.fromCharCode(240);

            case 'ntilde':
                return String.fromCharCode(241);

            case 'ograve':
                return String.fromCharCode(242);

            case 'oacute':
                return String.fromCharCode(243);

            case 'ocirc':
                return String.fromCharCode(244);

            case 'otilde':
                return String.fromCharCode(245);

            case 'ouml':
                return String.fromCharCode(246);

            case 'divide':
                return String.fromCharCode(247);

            case 'oslash':
                return String.fromCharCode(248);

            case 'ugrave':
                return String.fromCharCode(249);

            case 'uacute':
                return String.fromCharCode(250);

            case 'ucirc':
                return String.fromCharCode(251);

            case 'uuml':
                return String.fromCharCode(252);

            case 'yacute':
                return String.fromCharCode(253);

            case 'thorn':
                return String.fromCharCode(254);

            case 'yuml':
                return String.fromCharCode(255);

            case 'quot':
                return String.fromCharCode(34);

            case 'lt':
                return String.fromCharCode(60);

            case 'gt':
                return String.fromCharCode(62);

            case 'amp':
                return String.fromCharCode(38);

        }
        return "";
    });
    return data;
}