



var portalScripts = (function() {
   // Private members

  function getParameter(url, name) {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( url );
    if( results == null )
      return "";
    else
      return results[1];
  }

   // Public members
   return {
      "getFromSSEDocument": function(elementName) {		
	  
		var result = null;
		try {			
			result = parent.document[elementName]; // search on parent document
		} catch (ex) {;}
		
		if((result != null) && (result != undefined) ){
			return result; // if found, return
		}else{
			try {	
				result = top.document[elementName]; // search on top document
			} catch (ex) {;}
		}
		
		if((result != null) && (result != undefined) ){
			return result; // if found, return
		}else{
			for (var i = 0; i < parent.frames.length; i++) { // search on all frames of parent document
			  try {	
				result = parent.frames[i].document[elementName];
				if((result != null) && (result != undefined) ){												
					return result; // if found, return
				}
			  } catch (ex) {;}
			}
		}
		
		// search on all frames of top window
		for (var i = 0; i < top.frames.length; i++) {
		  try {	
			result = top.frames[i].document[elementName];
			if((result != null) && (result != undefined) ){
				return result; // if found, return
			}
		  } catch (ex) {;}
		}	
		alert("Find not found the function:" + elementName + " on the document");
        return result;
      },
      
      "getFromSSEWindow": function(elementName) {	  	  
		var result = null;
		
		try {			
			result = parent.window[elementName]; // search on parent window
		} catch (ex) {;}
		
		
		if((result != null) && (result != undefined) ){
			return result; // if found, return
		}else{
			try {	
				result = top.window[elementName]; // search on top window
			} catch (ex) {;}
		}
		
		if((result != null) && (result != undefined) ){
			return result; // if found, return
		}else{
			for (var i = 0; i < parent.frames.length; i++) { // search on all frames of parent window
			  try {	
				result = parent.frames[i].window[elementName];
				if((result != null) && (result != undefined) ){
					return result; // if found, return
				}
			  } catch (ex) {;}
			}
		}	
		
		// search on all frames of top window
		for (var i = 0; i < top.frames.length; i++) {
		  try {	
			result = top.frames[i].window[elementName];
			if((result != null) && (result != undefined) ){
				return result; // if found, return
			}
		  } catch (ex) {;}
		}			
		
		alert("Find not found the function:" + elementName + " on the window");		
        return result;
      },
      
      "getParameterFromURL": function(name) {
        return (getParameter(window.location.href, name))
      },
      
      "getParameterFromReferrer": function(name) {
        return (getParameter(document.referrer, name))
      },
      
      "replaceAll": function (string,text,by) {
        // Replaces text with by in string
        var strLength = string.length, txtLength = text.length;
        if ((strLength == 0) || (txtLength == 0)) return string;

        var i = string.indexOf(text);
        if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;

        var newstr = string.substring(0,i) + by;

        if (i+txtLength < strLength)
            newstr += this.replaceAll(string.substring(i+txtLength,strLength),text,by);

        return newstr;
      }
   };
})();

var StringUtils = (function() {
   // Private members


   // Public members
   return {
    
      "replaceAll": function (string,text,by) {
        // Replaces text with by in string
        var strLength = string.length, txtLength = text.length;
        if ((strLength == 0) || (txtLength == 0)) return string;

        var i = string.indexOf(text);
        if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;

        var newstr = string.substring(0,i) + by;

        if (i+txtLength < strLength)
            newstr += this.replaceAll(string.substring(i+txtLength,strLength),text,by);

        return newstr;
      },
      "unescapeXML": function (string) {
        var newstr = string;
        
        newstr = this.replaceAll(newstr, "&gt;", ">");
        newstr = this.replaceAll(newstr, "&lt;", "<");
        return newstr;
      }
      
      
   };
})();