// -------------------------------------------------------------------------- \\
/*
	 Class: ExtraInfoPopUp
	 
	 Author: scante
	 
	 Precondition the singleton WDSCommon should previously be loaded before 
	 calling the 'generatesPopUp' and the 'redirectToAnExternalPopUp'
	 method.
	 
	 This class should be used as this for simple popup or be extended for more custom popup.
	 
	 http://www.kevlindev.com/tutorials/javascript/inheritance/ for futher
	 infomation about javascript inheritance
*/
// -------------------------------------------------------------------------- \\
// -------------------------------------------------------------------------- \\

//		group: ATTRIBUTES
 
//		var: htmlDirection      
//		The language direction ('ltr' or 'rtl').

//		var: lang
//		The language from the locale.

//		var: charset
//		The charset that is set in the HTML content time.

//		var: baseUrl
//    The base url that is set in the HTML base tag, example 'http://localhost:80/zephyr/santaclaus/200501071013/static/'.

//		var: headerTitleString
//    The string that will be displayed in the title window.

//		var: bodyTitleString
//	  The string that will be displayed in the title of the body.

//		var: closeString
//    The internationalized 'close' label.

//		var: width
//    width of the window.

//    var: height
//   	height of the window.
  
// -------------------------------------------------------------------------- \\
/*
		group: METHODS
		
		subgroup: object methods
		
		method: ExtraInfoPopUp
		
			Constructor
		
		Parameters:
		 
				htmlDirection - The language direction ('ltr' or 'rtl').
				lang - The language from the locale.
				charset - The charset that is set in the HTML content time.
				baseUrl - The base url that is set in the HTML base tag.
				headerTitleString - The string that will be displayed in the title window.
				bodyTitleString - The string that will be displayed in the title of the body.
				closeString - The internationalized 'close' label.
				width - width of the window.
				height - height of the window.
				defaultCss - The full path and file of the default CSSes.
                strCustomCSSes - custom CSS files full path.

		 Return:

				none.
		
*/
function ExtraInfoPopUp (htmlDirection, lang, charset, baseUrl, headerTitleString, bodyTitleString, closeString, width, height, defaultCss, strCustomCSSes) {
	if ( arguments.length > 0 ) {
        this.init(htmlDirection, lang, charset, baseUrl,headerTitleString, bodyTitleString, closeString, width, height, defaultCss, strCustomCSSes);       
    }	
}

// -------------------------------------------------------------------------- \\
// ExtraInfoPopUp init method
//	Initialiwe the common attributes (internationalizated, sizing variables ) 
//	before generating the pop up it self
/*
	 method: init
	 
	 same as constructor <ExtraInfoPopUp>
*/
ExtraInfoPopUp.prototype.init = function(htmlDirection, lang, charset, baseUrl, headerTitleString, bodyTitleString, closeString, width, height, defaultCss, strCustomCSSes){
  this.htmlDirection     = htmlDirection;	
  this.lang              = lang;	
  this.charset           = charset;		
  this.baseUrl           = baseUrl;
  this.headerTitleString = headerTitleString;
  this.bodyTitleString   = bodyTitleString;
  this.closeString       = closeString;
  this.width             = width;
  this.height            = height;
  this.defaultCss        = defaultCss;
  this.strCustomCSSes    = strCustomCSSes;  
}

/*
	 method: writeBodyHeader
	 
	 Write the header table contained in the body with the given popup window object 
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 	
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeBodyHeader = function (popUpWindow){
	popUpWindow.document.writeln('<table cellpadding="0" cellspacing="0" width="100%" class="tableHeader"><tr><td>' + this.bodyTitleString + '</td><td align="right"><a href="javascript:close()" class="textSmall2">' + this.closeString + '</a></td></tr></table>');
}

/*
	 method: writeBodyFooter
	 
	 Write the footer table contained in the body with the given popup window object 
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 	
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeBodyFooter = function (popUpWindow){
	popUpWindow.document.writeln('<div class="lineSeparator"></div><table cellspacing="0" cellpadding="0" class="tablePopUp"><tr><td class="footer"><a href="javascript:close()">' + this.closeString + '</a></td></tr></table>');
}

/*
	 method: writeEmptyLineInContentTable
	 
	 Write a empty line <tr> 
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeEmptyLineInContentTable = function (popUpWindow){	
	popUpWindow.document.writeln('<tr><td width="10px">&nbsp;</td><td>&nbsp;</td></tr>');	
}
/*
	 method: writeHeader
	 
	 Write the header of the document : doctype, <head> and the start of the body tag
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeHeader = function(popUpWindow) {	    
  popUpWindow.document.writeln('<?xml version="1.0" encoding="iso-8859-1"?>');
  popUpWindow.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  popUpWindow.document.writeln('<html dir="'+this.htmlDirection+'" lang="'+this.lang+'" xmlns="http://www.w3.org/1999/xhtml">');
  popUpWindow.document.writeln("<head>");
  popUpWindow.document.writeln('   <meta http-equiv="Content-Type" content="text/html; charset='+this.charset+'"/>');  
  popUpWindow.document.writeln('   <base href="'+this.baseUrl+'"/>');
  popUpWindow.document.writeln('   <title>'+this.headerTitleString+'</title>');
  /*Load default CSSes?*/
  if (this.defaultCss && this.defaultCss.length > 0)  
    popUpWindow.document.writeln("   "+this.defaultCss);  
  /*Load custom ones?*/      
  if (this.strCustomCSSes && this.strCustomCSSes.length > 0)    
    popUpWindow.document.writeln("   "+this.strCustomCSSes);    
  popUpWindow.document.writeln("</head>");
  popUpWindow.document.writeln("<body>");
  popUpWindow.document.writeln('<div class="divBGRD">');
}

/*
	 method: writeOverallHeader
	 
	 Gathers for inheritance purpose, all header methods until the begining of the content table (included)
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeOverallHeader = function (popUpWindow){	
	this.writeHeader(popUpWindow);
	//header
	this.writeBodyHeader(popUpWindow);
	// description table
	popUpWindow.document.writeln('<table cellspacing="0" cellpadding="0" class="tablePopUp">');
	this.writeEmptyLineInContentTable(popUpWindow);
}

/*
	 method: writeOverallFooter
	 
	 Gathers for inheritance purpose, all footer methods until the begining of the content table (included)
	 
	 @mockUpversion from version 2 - dlang - 21/11/04 
	 
	 Parameters:
		 
				popUpWindow - The popUp window object to write in.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.writeOverallFooter = function (popUpWindow){	
	this.writeEmptyLineInContentTable(popUpWindow);
	popUpWindow.document.writeln('</table>');
	// footer table
	this.writeBodyFooter(popUpWindow);
	popUpWindow.document.writeln('</div></body></html>');
}

/*
	 method: redirectToAnExternalPopUp
	 
	 Display an external url in a pop up.
	 
	 Parameters:
		 
				url - The external url
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.redirectToAnExternalPopUp = function (url){
	WDSCommon.popSizedWin(url,this.width,this.height);
}

/*
	 method: generatesPopUp
	 
				Open a pop up window to display an extra information based on this object attributes.
				
				The popup displayed is just intented to display a single description.
				
				Please override this method for more complex popup.
				
				@mockUpversion from version 2 - dlang - 21/11/04 	
	 
	 Parameters:
		 
				description - The description to display.
	 			
	 Return:
	 
	 			none.
*/
ExtraInfoPopUp.prototype.generatesPopUp = function (description){
	
	popUp = WDSCommon.popSizedWin('', this.width, this.height);
	this.writeOverallHeader(popUp)
	// insert the description in a <td>
	popUp.document.writeln('<tr><td>&nbsp;</td><td>'+description+'</td></tr>');	
	this.writeOverallFooter(popUp);
	popUp.document.close();
}

/*********************************************************
*            S T A T I C   F U N C T I O N S
**********************************************************/
/*********************************************************
* FUNC: openBasicWindow
* DESC: This function enables UI to open 
*     : a basic popup
* ARG.: strURL       , the URL of the page to be displayed
*     : strWndName   , the window title
*     : strWndOptions, the window options
* RET.: Opened window handle if OK, null otherwise
*     : This function CANNOT be called from a <A> tag name
*     : (href especially) because of the RETURN statement
**********************************************************/
function openBasicWindow(strURL,strWndName,strWndOptions) {
  var theOpenedWindow = null;
  
  /*Open basic window*/
  theOpenedWindow = window.open(strURL,strWndName,strWndOptions);
  /**Netscape navigator?*/
  if (theOpenedWindow != null && navigator.appName.toLowerCase() == "netscape") {
    /**Make sure to focus window!*/
    theOpenedWindow.focus();
  } 
  
  return theOpenedWindow;
}

/*********************************************************
* FUNC: openBasicPopup
* DESC: This function enables UI to open 
*     : a basic popup
* ARG.: strURL       , the URL of the page to be displayed
*     : strWndName   , the popup window title
*     : strWndOptions, the popup window options
* RET.: None
**********************************************************/
function openBasicPopup(strURL,strWndName,strWndOptions) {
  /*Open basic popup*/
  openBasicWindow(strURL,strWndName,strWndOptions);
}

/*
	 method: redirectToAnExternalPopUp
				
				Display an external url in a pop up via the WDSCommon lib.
				
				(static method - can be called without the instance)
				 
	 Parameters:

				url - url to be opened.
				width - width of the window.
				height - height of the window.
                bNoScroll - display popup WINDOW with no scroll bar 
                            if true or defined, with scroll bar otherwise
	 			
	 Return:
	 
	 			none.
*/
function redirectToAnExternalPopUp(url,width,height,bNoScroll) {
  /**Popup WINDOW does not need to be displayed with scroll bar?*/
  if (bNoScroll) {
    /**Yes, then make sure to force a no scroll bar display*/
    WDSCommon.popSizedWinNoScroll(url,width,height);
  }
  else {
    /**Make sure to force a scroll bar display then*/
    WDSCommon.popSizedWin(url,width,height);
  }
}

/*********************************************************
* FUNC: submitFormToPopup
* DESC: This function enables application to open a 
*     : popup window and then submit the given form
* ARG.: theForm      , the form to submit
*     : strWndName   , the popup window title
*     : strWndOptions, the popup window options
* RET.: None
**********************************************************/
function submitFormToPopup(theForm,strWndName,strWndOptions) {
  /**Various checks*/
  if (!theForm || theForm == null)
    return;

  var strURL = "";
  /**Http secure?*/
  if (location.protocol == "https:") { 
    /**Open a fake page only for https cause MSIE pops up an undesired 
       warning that the user is leaving a secure area*/
    var theBase = document.getElementsByTagName("base");
    if (theBase != null && theBase.length) {
      /**Load fake page before form submit*/
      strURL = theBase[0].href+"html/web/blank.html"; 
    }
  }

  /**Open popup window*/
  var thePopSizedWin = openBasicWindow(strURL,strWndName,strWndOptions);
  if (thePopSizedWin == null)
    return;
    
  /**IE hack wait the popup has been loaded and is ready*/
  while (!thePopSizedWin) {}
  /**Make sure to submit the form*/
  theForm.submit(); 
}


/*
	 method: submitFormToNewPopUp
				
				Submit the given form given as paremeter to a popup window.
				
				(static method - can be called without the instance)
				
	 pre-conditions:
	 			
	 			the form should set the same target that the 'windowName' parameter.
				 
	 Parameters:

				form - the form to submit (transmitted as object) (as String example :document.purchaseConditionsFromFarePopUpForm).
				windowName - the window name targeted.
				width - width of the window.
				height - height of the window.
	 			
	 Return:
	 
	 			none.
*/
function submitFormToNewPopUp(form,windowName,width,height){
  var url='';
  if(location.protocol == "https:"){ // open a fake page only for https 
  						// cause IE pops up a undesired warning that the user
  						// is leaving a secure area
  	var baseObj = document.getElementsByTagName('base');
  	if(baseObj && baseObj.length){
  		url= baseObj[0].href + 'html/web/blank.html' // load fake page before form submit
  	}
  }

  var thePopSizedWin = openBasicWindow(url,windowName,'scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=50,top=50');
  if (thePopSizedWin == null)
    return;

  // IE hack wait the popup has been loaded and is ready
  while(!thePopSizedWin) {}
  /**Has a valid form?*/
  if (form && form != null) {
    /**Make sure to submit the form*/
    form.submit(); 
  }  
}

