
/*----------------------------------------------------------------------------\
|                            Misc Aergo JS Helpers                            |
|-----------------------------------------------------------------------------|
|                                               							  |
|-----------------------------------------------------------------------------|
| Useful functions used by Aergo                                              |
|-----------------------------------------------------------------------------|
|                  Copyright (c) 2004 e-travel                   			  |
|-----------------------------------------------------------------------------|
| 2004-03-01 | First version                                                  |
|-----------------------------------------------------------------------------|
| Created 2004-03-01 | By Roland Pellegrin  				 				  |
\----------------------------------------------------------------------------*/

MiscHelpers = function() {};

/****f* MiscHelpers/openBrWindow
* NAME
* openBrWindow: function to open a popupwindow (was included in BEA's original portal.jsp).
* USAGE
* openBrWindow(theURL,winName,features)
* FUNCTION
* This function opens a popup window with the URL given as parameter.
* PARAMETERS
* theURL - URL corresponding to the content of the popup window.
* winName - name of the popup window that will be opened.
* features - parameters of the popup window (position, dimensions,...)
* RETURN VALUE
* window instance
***
*/

var openerURL="";
var popupWindow;
var ariaDialogWindow;
window.popupPointer=null;
function openBrWindow(theURL,winName,features, externalContent, bReturnWindowInstance)
{ //v2.0
  var oCreatedWindow = null;
  // CR 1634569 ESC JavaScript Inline Popup
  if (isInlinePopUp!='Y') {
    if (features.indexOf("left=") < 0) {
      features += ",left=100,top=50";
    }
    if (features.indexOf("resizable=") < 0) {
      features += ",resizable=yes";
    }

    if (externalContent != null && externalContent == true) {
      popupURL=theURL;
    } else {
      // popupURL is set before in portal.jsp
      popupURL=makeRelativeURL(theURL);
    }

    if ((popupWindow!=null) && (!popupWindow.closed)) {
      popupWindow.close();
    }
    popupWindow = window.open(popupURL,winName,features);
    if (popupWindow) {
      window.popupPointer=popupWindow;
      popupWindow.focus();
      oCreatedWindow = popupWindow;
    }
  } else {
    // CR 1634569 ESC JavaScript Inline Popup
    openerURL=makeRelativeURL(theURL);
    displayInlinePopup(openerURL,winName,features);
  }
  return bReturnWindowInstance?oCreatedWindow:undefined;
}

function openAriaWindow(theURL,winName,features,args){
    if(ariaDialogWindow){
        ariaDialogWindow.destroy();
    }

    ariaDialogWindow = c.dialog(winName,"about:blank","IFrame", features);
    ariaDialogWindow.show();
    $$("iframe", ariaDialogWindow.getDom())[0].src = makeRelativeURL(theURL);
    $$("iframe", ariaDialogWindow.getDom())[0].iFrameDialogReference = ariaDialogWindow;
    $$("iframe", ariaDialogWindow.getDom())[0].args = args;
    $$("iframe", ariaDialogWindow.getDom())[0].context = this;
    ariaDialogWindow.center();
    return ariaDialogWindow;
}

/****f* MiscHelpers/makeRelativeURL
* NAME
* makeRelativeURL: function to convert url to a relative one.
* USAGE
* makeRelativeURL(theURL)
* FUNCTION
* This function converts the url given as parameter to a relative one (used for http/https).
* PARAMETERS
* theURL - URL that will be changed to a relative one.
* RETURN VALUE
* string : the relative URL.
***
*/
function makeRelativeURL(theURL)
{ //v2.0
  var webAppName = '/portalApp/';
  var webAppIndex = theURL.indexOf(webAppName);

  // If we find the web application name in the URL, we remove it and everything prior to it
  if (webAppIndex!=-1) {
    return theURL.substring(webAppIndex+webAppName.length);
  }

  // else we return the original URL
  return theURL;
}

/****f* MiscHelpers/makeWebAppURL
* NAME
* makeWebAppURL: function to extract the web app URL from a URL.
* USAGE
* makeWebAppURL(theURL)
* FUNCTION
* This function extracts from the url given as parameter the web app URL.
* PARAMETERS
* theURL - URL from which we extract the web app URL.
* EXAMPLE
* theURL = http://book.e-travel.com/portalApp/application?origin=hnav_bar.jsp
* returns : http://book.e-travel.com/portalApp/
* RETURN VALUE
* string : the extracted web app URL.
***
*/
function makeWebAppURL(theURL)
{
  var webAppName = '/portalApp/';
  var webAppIndex = theURL.indexOf(webAppName);

  // If we find the web application name in the URL, we return it and everything prior to it
  if (webAppIndex!=-1) {
    return theURL.substring(0, webAppIndex+webAppName.length);
  }

  // else we return the original URL
  return theURL;
}

/****f* MiscHelpers/makeAbsoluteURL
* NAME
* makeAbsoluteURL: function to build dynamically a URL to a non-static resource
* USAGE
* makeAbsoluteURL(theURL, resourcePath)
* FUNCTION
* This function builds a URL to a non-static resource based on the url given as parameter.
* PARAMETERS
* theURL - URL from which we build the URL to a non-static resouce.
* resourcePath - relative path to the non-static resource.
* EXAMPLE
* theURL = http://book.e-travel.com/portalApp/application?origin=hnav_bar.jsp
* resourcePath = pages/business/rail/LightRailRedirect.jsp
* returns : http://book.e-travel.com/portalApp/APF/pages/business/rail/LightRailRedirect.jsp
* RETURN VALUE
* string : The absolute path to the non-static resource given as parameter.
***
*/
function makeAbsoluteURL(theURL, resourcePath)
{
  var webAppURL = makeWebAppURL(theURL);

  // If resourcePath starts with a /, remove it
  if (resourcePath.charAt(0) == '/') {
    resourcePath = resourcePath.substring(1, resourcePath.length);
  }

  return webAppURL + resourcePath;
}


/**
** variables and methods used for browser Back support
**/
var aFnLoad=new Array();
var aFnResize=new Array();
var isBrowserRefresh=false;

/****f* MiscHelpers/subscribeOnLoad
* NAME
* subscribeOnLoad: used to add a function to a list that must be called at loading time
* USAGE
* subscribeOnLoad(fn)
* FUNCTION
* This function adds a function to an array. This array contains functions that have
* to be called at the loading of the page.
* PARAMETERS
* fn - function to add in the array.
* RETURN VALUE
* void
***
*/
function subscribeOnLoad(fn){
	aFnLoad.push(fn);
}

/****f* MiscHelpers/subscribeOnResize
* NAME
* subscribeOnResize: used to add a function to a list that must be called at the time
* the page is resized.
* USAGE
* subscribeOnResize(fn)
* FUNCTION
* This function adds a function to an array. This array contains functions that have
* to be called at the resizing of the page.
* PARAMETERS
* fn - function to add in the array.
* RETURN VALUE
* void
***
*/
function subscribeOnResize(fn){
	aFnResize.push(fn);
}

/****f* MiscHelpers/propagateOnLoad
* NAME
* propagateOnLoad: used to call the functions registered to be called at the loading of the page.
* USAGE
* propagateOnLoad()
* FUNCTION
* This function goes through the array containing the functions that have
* to be called at the loading of the page, and calls these functions.
* PARAMETERS
* no parameter.
* RETURN VALUE
* void
***
*/
function propagateOnLoad()
{
	// set a variable indicating browser refresh or not
	var o = document.getElementById("idBrowserRefreshFlag");
	if (o) {
	isBrowserRefresh = (o.value!=0);
	o.value=1;
	} else {
	  isBrowserRefresh = false;
	}

	for(var i=0;i<aFnLoad.length;i++)
		aFnLoad[i]();
}

/****f* MiscHelpers/propagateOnResize
* NAME
* propagateOnResize: used to call the functions registered to be called at the resizing of the page.
* USAGE
* propagateOnResize()
* FUNCTION
* This function goes through the array containing the functions that have
* to be called at the resizing of the page, and calls these functions.
* PARAMETERS
* no parameter.
* RETURN VALUE
* void
***
*/
function propagateOnResize(){
	for(var i=0;i<aFnResize.length;i++)
		aFnResize[i]();
}

/****f* MiscHelpers/reloadPage
* NAME
* reloadPage: Method used to load an URL in the current browser.
* USAGE
* reloadPage(URL)
* FUNCTION
* This function reload the page with the URL given as parameter.
* PARAMETERS
* URL - the redirection URL.
* RETURN VALUE
* void
***
*/
function reloadPage(URL){
	document.location=URL;
}

/****f* MiscHelpers/makeCssUrl
* NAME
* makeCssUrl: Method used to load an URL in the current browser.
* USAGE
* makeCssUrl()
* FUNCTION
* This function reload the page with the URL given as parameter.
* PARAMETERS
* URL - the redirection URL.
* RETURN VALUE
* void
***
*/
function makeCssUrl() {

var webAppName = '\/\/';
var webAppName2 = '/css/';
var tagCol = document.getElementsByTagName("LINK");
i = 0;
var urlRet='';
var base='';

	while((i<tagCol.length) && ((urlRet = tagCol[i].getAttribute("href")).indexOf(webAppName2)== -1))
		{
			i+=1;
		};
	if (i<tagCol.length){
		var webAppIndex = urlRet.indexOf("http");
		webAppIndex2 = urlRet.indexOf(webAppName2);
		if (webAppIndex !=-1) {
			return urlRet.substring(0,webAppIndex2+webAppName2.length);
		} else {
			base = document.URL;
			webAppIndex = base.indexOf(webAppName);
			webAppIndex = base.indexOf("\/",webAppIndex+webAppName.length);

		    // If we find the web application name in the URL, we remove it and everything prior to it
    		if (webAppIndex!=-1) {
    				base = base.substring(0,webAppIndex);
					return base+urlRet.substring(0,webAppIndex2+webAppName2.length);
			}
		}
	}
	// else we return the original URL
    return base;
}

/*----------------------------------------------------------------------------\
|                            Browser Detection Utilities	                  |
|-----------------------------------------------------------------------------|
|                                               							  |
|-----------------------------------------------------------------------------|
| Utilities to detect browser versions                                        |
|-----------------------------------------------------------------------------|
|                  Copyright (c) 2003 e-travel                   			  |
|-----------------------------------------------------------------------------|
| 2003-10-08 | First version                                                  |
|-----------------------------------------------------------------------------|
| Created 2003-10-08 | By Roland Pellegrin						 			  |
\----------------------------------------------------------------------------*/

// Browser Detect Lite  v2.1.4
// http://www.dithered.com/javascript/browser_detect/index.html


/****f* MiscHelpers/BrowserDetectLite
* NAME
* BrowserDetectLite: Method used to test the browser's parameters.
* USAGE
* BrowserDetectLite()
* FUNCTION
* This function retrieves all the navigator's parameters.
* PARAMETERS
* no parameter.
* RETURN VALUE
* void
***
*/
function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase();

   // browser name
   this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isMozilla   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) && (ua.indexOf('safari') == - 1));
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) );
   this.isSafari    = ( (ua.indexOf('safari') != -1) && (ua.indexOf('chrome') == -1));
   this.isOpera     = (ua.indexOf('opera') != -1);
   this.isKonqueror = ( (ua.indexOf('konqueror') != -1) && (ua.indexOf('safari') == -1) );
   this.isIcab      = (ua.indexOf('icab') != -1);
   this.isAol       = (ua.indexOf('aol') != -1);
   this.isFirefox   = (ua.indexOf('firefox') != -1);
   this.isChrome    = (ua.indexOf('chrome') != -1);

   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

   // browser version
   this.versionMinor = parseFloat(navigator.appVersion);

   // correct version number
   if (this.isNS && this.isGecko) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isOpera) {
      if (ua.indexOf('opera/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
      }
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isIcab) {
      if (ua.indexOf('icab/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
      }
   }
   else if (this.isFirefox) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('firefox/') + 8 ) );
   }
   else if (this.isChrome) {
       chromeMatch = ua.match(/chrome\/[0-9]+\.[0-9]/);
       // There should either be one element, or no element.
       var chromeMatchTokens = chromeMatch[0].split(/\//);
       // The first element is the browser name, second is the version (major.minor)
       this.versionMinor = chromeMatchTokens[1];
   }

   this.versionMajor = parseInt(this.versionMinor);
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);

   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin   = (ua.indexOf('win') != -1);
   this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isWin64 = (this.isWin && (ua.indexOf('nt') != -1 || ua.indexOf('win64') != -1 || ua.indexOf('64bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac   = (ua.indexOf('mac') != -1);
   this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux = (ua.indexOf('linux') != -1);

   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);

   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   this.isIE7x = (this.isIE && this.versionMajor == 7);
   this.isIE7up = (this.isIE && this.versionMajor >= 7);
   this.isIE8x = (this.isIE && this.versionMajor == 8);
   this.isIE8up = (this.isIE && this.versionMajor >= 8);
   this.isIE9x = (this.isIE && this.versionMajor == 9);
   this.isIE9up = (this.isIE && this.versionMajor >= 9);
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();



/****f* MiscHelpers/isNumeric
* NAME
* isNumeric: Method used to test if a variable is numeric or not.
* USAGE
* isNumeric(myNumber)
* FUNCTION
* This function tests if the parameter myNumber is a number or not.
* PARAMETERS
* myNumber - variable to test.
* RETURN VALUE
* boolean
***
*/
function isNumeric(myNumber){
  cmp = "0123456789";
  for(var i = 0; i < myNumber.length; i++){
    if(cmp.indexOf(myNumber.substring(i, i + 1)) < 0)
      return false;
  }
  return true;
}

/****f* MiscHelpers/hide
* NAME
* hide: Method used to hide an object.
* USAGE
* hide(divObj)
* FUNCTION
* This function retrieves the object which id is passed as a parameter, and hides it.
* PARAMETERS
* divObj - object to hide.
* RETURN VALUE
* void
***
*/
function hide(divObj)
{
	  DOM = (document.getElementById); // IE 5+ et NS 6+
	  IE4 = (document.all); // IE 4
	  NS4 = (document.layers); // NS 4
	  var state = "";

	  if (DOM) {
	    	if(document.getElementById(divObj)) {
	    		document.getElementById(divObj).style.display = "none";
	    	}
	  }
	  else if (IE4) {
	  	if(document.all.divObj) {
	    		document.all.divObj.style.display = "none";
	    	}
	  }
	  else if (NS4) {
		if(document.layers[divObj]) {
	    		document.layers[divObj].style.display = "none";
		}
	  }
}

/****f* MiscHelpers/show
* NAME
* show: Method used to show an object.
* USAGE
* show(divObj)
* FUNCTION
* This function retrieves the object which id is passed as a parameter, and shows it.
* PARAMETERS
* divObj - object to show.
* RETURN VALUE
* void
***
*/
function show(divObj)
{
	  DOM = (document.getElementById); // IE 5+ et NS 6+
	  IE4 = (document.all); // IE 4
	  NS4 = (document.layers); // NS 4
	  var state = "";

	  if (DOM) {
	     	if(document.getElementById(divObj)) {
	     		document.getElementById(divObj).style.display = "";
	     	}
	  }
	  else if (IE4) {
	  	if(document.all.divObj) {
	     		document.all.divObj.style.display = "";
	     	}
	  }
	  else if (NS4) {
	      	if(document.layers[divObj]) {
	      		document.layers[divObj].style.display = "";
	      	}
	  }
}

/****f* MiscHelpers/ShowHide
* NAME
* ShowHide: Method used to show/hide an object.
* USAGE
* ShowHide(divObj)
* FUNCTION
* This function retrieves the object which id is passed as a parameter,
* and shows it if it was hidden, or hides it if it was visible.
* PARAMETERS
* divObj - object to show/hide.
* RETURN VALUE
* void
***
*/
function ShowHide(divObj)
{
  DOM = (document.getElementById); // IE 5+ et NS 6+
  IE4 = (document.all); // IE 4
  NS4 = (document.layers); // NS 4
  var state = "";

  if (DOM) {
    state = document.getElementById(divObj).style.display;
    if(state == "none" && state != null) {
      document.getElementById(divObj).style.display = "";
    } else {
      document.getElementById(divObj).style.display = "none";
    }
  }
  else if (IE4) {
    state = document.all.divObj.style.display;
    if(state == "none" && state != null) {
      document.all.divObj.style.display = "";
    } else {
      document.all.divObj.style.display = "none";
    }
  }
  else if (NS4) {
    state = document.layers[divObj].style.display;
    if(state == "none" && state != null) {
      document.layers[divObj].style.display = "";
    } else {
      document.layers[divObj].style.display = "none";
    }
  }
}

/****f* MiscHelpers/isDisplayed
* NAME
* isDisplayed: Method used to now if an object is displayed or not on a page
* USAGE
* isDisplayed(divObj)
* FUNCTION
* This function retrieves the object which id is passed as a parameter,
* and returns true if it is displayed, false if not.
* PARAMETERS
* divObj - object to test.
* RETURN boolean
* void
***
*/
function isDisplayed(divObj)
{
	  DOM = (document.getElementById); // IE 5+ et NS 6+
	  IE4 = (document.all); // IE 4
	  NS4 = (document.layers); // NS 4
	  var state = "";

	  if (DOM) {
	    	if(document.getElementById(divObj) && document.getElementById(divObj).style.display != "none") {
	    		return true;
	    	}
	  }
	  else if (IE4) {
	  	if(document.all.divObj && document.all.divObj.style.display != "none") {
	    		return true;
	    	}
	  }
	  else if (NS4) {
		if(document.layers[divObj] && document.layers[divObj].style.display != "none") {
	    		return true;
		}
	  }
	  return false;
}

/****f* MiscHelpers/calculateOffset
* *****************************************************************************
* FUNCTION
* Calculate the offset of an object.
*
* USAGE
* calculateOffset(obj,attr)
*
* PARAMETERS
* obj   - The reference object.
* attr - The type of offset to calculate (offsetLeft, offsetRight, offsetTop...).
*
* RETURN VALUE
* The offset value.
******************************************************************************/
function calculateOffset(obj,attr,stopAbsolute,scrollTop){
	var kb=0;
	var i=0;

  	while(obj){
  		if (stopAbsolute) {
  			if (i>0 && obj.style.position=="absolute") {
  				return kb;
  			}
  		}
		kb+=obj[attr];
    		obj=obj.offsetParent;
    		i++;
  	}
	if (attr == "offsetTop" && scrollTop != null && scrollTop > 0) {
		if (!browser.isIE)
 	 		kb = kb - scrollTop;
 	 	else
 	 		kb = kb - 130;
	}
  	return kb
}

/****c* MiscHelpers/ProtectDiv
* *****************************************************************************
* DESCRIPTION
* HREF_FILE_NAME
* A known bug of Internet Explorer is that when an absolute positioned
* div is over a dropdown form element, the dropdown is showing on top of the div.
* ProtectDiv is an object used to fix a bug on IE.
*
* Example of usage:
* protectDiv = new ProtectDiv(div);
*
* PARAMETERS
* div - The DIV object to protect.
*
* UNIT TESTS
* href:UNIT_TEST_PATH/ProtectDiv/index.htm
******************************************************************************/

function ProtectDiv(div) {

	/****f* ProtectDiv/protect
	* *****************************************************************************
	* FUNCTION
	* When IE browser is detected, protect the div against dropdown element.
	* This method is called on initialisation, and each time the div is moving.
	*
	* USAGE
	* protect()
	*
	* RETURN VALUE
	* void
	******************************************************************************/
	ProtectDiv.prototype.protect = function protect() {
		if(browser.isIE && browser.versionMajor<7){
			var iframe = document.getElementById("protectDiv"+this.div.id);
			if(iframe==null){
				iframe = document.createElement("IFRAME");
				iframe.id = "protectDiv"+this.div.id;
				iframe.target = "_blank";
				iframe.src = "/portalApp/APF/pages/include/blank.jsp";
				iframe.style.position = "absolute";
				iframe.style.border = "0";
				document.body.appendChild(iframe);
			}
			iframe.style.left = this.div.offsetLeft;
			iframe.style.top = this.div.offsetTop;
			if(this.div.style.width)
				iframe.style.width = this.div.style.width;
			else
				iframe.style.width = this.div.clientWidth;

			var height = "";
			if(this.div.style.height){
				height = this.div.style.height;
			}else if(this.div.clientHeight){
				height = this.div.clientHeight;
			}

			height = height+"";
			if(height!=""){
				if(height.indexOf("px")>0)
					height = height.substring(0, height.indexOf("px"));
				height = (parseInt(height)+2)+'px'
				iframe.style.height = height;
			}
			iframe.style.visibility = this.div.style.visibility;
		}
	}

	this.div = div;
	div.protectDiv = this;
	if(browser.isIE && browser.versionMajor<7){
		// The Z-index of DIV must be greater than IFRAME
		if(div.style.zIndex == 0)
			div.style.zIndex = 1;
		// When the DIV move, move the IFRAME too.
		div.onmove=function(){
			this.protectDiv.protect();
		}

		// When the DIV visibility change, change the IFRAME visibility too.
		div.onpropertychange=function(){
			this.protectDiv.protect();
		}

		// Call the protect() method
		this.protect();
	}
}


/**
*
* str = "<input name="NAME" value="VALUE"/><input name="NAME2" value="VALUE2"/>..."
* returns "NAME=VALUE&NAME2=VALUE2"
*/
function createUrlFromHidden(str){

	var start=new RegExp('(<input name=\")', "g");
	var middle=new RegExp('(\" value=\")', "g");
	var end=new RegExp('(\"/>)', "g");
	var blank=new RegExp('(\r)', "g");
	var submit=new RegExp('(<input type=\"submit=&)', "g");

	str = str.replace(blank,"");
	str = str.replace(start,"");
	str = str.replace(middle,"=");
	str = str.replace(end,"&");
	str = str.replace(submit,"");

	return URLencode(str);
}

function URLencode(sStr) {
    return sStr.replace(/\+/g, '%2B').
             replace(new RegExp('( )', "g"), '%20').
             replace(/\"/g,'%22').
             replace(/\'/g, '%27').
             replace(/\//g,'%2F');
  }

/****f* MiscHelpers/expandDivAndIcon
* *****************************************************************************
* FUNCTION
* expandDivAndIcon: Expand a div object and update a gif arrow indicating that the part is expanded
*
* USAGE
* expandDivAndIcon(theIconDivName,theDivToExpand)
*
* PARAMETERS
* iconDivName - the div containing the gif image
* divName - the div to expand
*
* RETURN VALUE
* void
******************************************************************************/
MiscHelpers.expandDivAndIcon = function(iconDivName,divName) {
	var theDiv = document.getElementById(divName);
	var obj = document.getElementById(iconDivName);
	if(obj && obj.className) {
		show(divName);
		obj.className="arrowDown";
	}
}

/****f* MiscHelpers/collapseDivAndIcon
* *****************************************************************************
* FUNCTION
* collapseDivAndIcon: Collapse a div object and update a gif arrow indicating that the part is collapsed
*
* USAGE
* collapseDivAndIcon(theIconDivName,theDivToExpand)
*
* PARAMETERS
* iconDivName - the div containing the gif image
* divName - the div to collapse
*
* RETURN VALUE
* void
******************************************************************************/
MiscHelpers.collapseDivAndIcon = function(iconDivName,divName) {
	var theDiv = document.getElementById(divName);
	var obj = document.getElementById(iconDivName);
	if(obj && obj.className) {
		hide(divName);
		obj.className="arrowRight";
	}
}

/****f* MiscHelpers/expandCollapse
* *****************************************************************************
* FUNCTION
* expandCollapse: Expand or collapse a div object and update a gif arrow indicating if the part is expanded or collapsed
*
* USAGE
* expandCollapse(theIconDivName,theDivToCollapseOrExpand)
*
* PARAMETERS
* iconDivName - the div containing the gif image
* divName - the div to expand or collapse
*
* RETURN VALUE
* void
******************************************************************************/
MiscHelpers.expandCollapse = function(iconDivName,divName) {
	var theDiv = document.getElementById(divName);
	if(theDiv && theDiv.style && theDiv.style.display=="none") {
		MiscHelpers.expandDivAndIcon(iconDivName,divName)
	}
	else if (theDiv && theDiv.style && theDiv.style.display=="") {
		MiscHelpers.collapseDivAndIcon(iconDivName,divName)
	}
}

/****f* MiscHelpers/disableButtons
* *****************************************************************************
* FUNCTION
* disableButtons: disable buttons based on id
*
* USAGE
* disableButtons(buttonId)
*
* PARAMETERS
* buttonId - the id of the button to disable 
*
* RETURN VALUE
* void
******************************************************************************/
MiscHelpers.disableButtons = function (buttonId)
{
	var oButton = document.getElementById(buttonId);
	
	oButton.disabled = "disabled";
	oButton.className="buttonCoreDisabled";
	oButton.parentNode.className="buttonBorderDisabled";	
}


/****f* MiscHelpers/escapeSpecialChars
* *****************************************************************************
* NAME
* escapeSpecialChars: Convert special characters to their escape correspondent codes, in order to correctly display strings inside HTML tags.
* USAGE
* escapeSpecialChars(theString)
* FUNCTION
* This function converts special characters to their escape correspondent codes, in order to correctly display strings inside HTML tags.
*    Note: it doesn't work if we want to display with an alert() command
* PARAMETERS
* theString - string to escape the special characters
* EXAMPLE
* sStr = This is John's community called "SNCF Special"
* returns: This is John&#39;s community called &#34;SNCF Special&#34;
* RETURN VALUE
* string
***
*/

function escapeSpecialChars(sStr) {
	return sStr.replace("\'", "&#39;").replace(/\"/gi, "\\\"");
}

/**
* This functions looks for all the <script> tags contained in a div element,
* and it executes them using eval statement.
* It will ignore the "document.write" statements.
*/
function executeScriptTags(divId) {

	var oDiv = document.getElementById(divId);
	if (oDiv) {
		var scriptsArray = oDiv.getElementsByTagName('SCRIPT');
		var length = scriptsArray.length;
		for (var i=0; i<length; i++) {
			if (scriptsArray[i].innerHTML!="") {
				try {
					if (scriptsArray[i].innerHTML.indexOf("document.write")==-1 && scriptsArray[i].innerHTML.indexOf("DisplaySeatMapLink")==-1) {
						eval(scriptsArray[i].innerHTML);
					}
				} catch(ex) {}
			}
		}
	}

}


// Builds a form input field.
function addFormF(name, value)
{
	if (value==null || value=='')
		return '';

	return '<input name="'+name+'" value="'+value+'"/>';

}

/**
* Method added to the Array prototype.
* Useful to look for an element in an Array.
*/
Array.prototype.inArray = function inArray(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}

/**
 * For String trim. Usage s.trim()
 */
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/**
* Function to check that then max time for Via is 48h.
*/
function CheckMaxTime(inputHours){
	bound = inputHours.id.split("_")[1];
	idVia = inputHours.id.split("_")[2];
	inputMinutes = document.getElementById("VIA_" + bound + "_" + idVia + "_MINUTES");

	if(inputHours.value == 48){
		inputMinutes.options.length = 0;
		inputMinutes.options[0] = new Option('00','00');
	}
	if(inputHours.value != 48 && inputMinutes.options.length == 1){
		numLength = inputMinutes.options.length;
		for(var i = 1; i < 60; i++) {
		if(numLength<10){ numLength = '0' + numLength;}
		   inputMinutes.options[numLength] = new Option(numLength, numLength);
		   numLength++;
		}

	}
}

/**
 * helper function to create the form
 */
function getNewSubmitForm() {
  var submitForm = document.createElement("FORM");
  document.body.appendChild(submitForm);
  submitForm.method = "POST";
  return submitForm;
}

/**
 * helper function to add dynamically elements to the form
 */
function createNewFormElement (inputForm, elementName, elementValue){
    var newElement = document.createElement("input");
    newElement.name= elementName;
    newElement.type="hidden";
    inputForm.appendChild(newElement);
    newElement.value = elementValue;
    return newElement;
}

/**
 * Changes elem css class to the one provided
 * @param elem
 * @param cssClass
 * @return
 */
function changeCSSClass(elem, cssClass){
    var el = document.getElementById(elem);
    if(el){
        el.className = cssClass;
    }
}

/**
* Button with class 'buttonCore' is blurred on focus
* Fix for PTR 05062570
*/

//Fix for PTR 05062570
function blurButtonForIE(){
	if (browser.isIE) {
		var cntrElem = document.body;
		cntrElem.onfocusin = function(e) {
			var domElem;
			if(window.event){
				domElem = window.event.srcElement;
			}
			else {
				domElem = e.srcElement;
			}
			if (domElem && domElem.className == 'buttonCore') {
				domElem.blur();
			}
		};
	}
}

if(browser.isIE){
	window.attachEvent("onload", blurButtonForIE);
}


