/*************************************************************************************/  
/**
 * insao-hive-www 
 * @copyright 		(c) 2007-2008 PR23 Limited. All Rights Reserved
 * @author 			PAUL WINTERHALDER :: PR23
 * 
 * @category 		INSAO HIVE 6.0.0.2
 * @category 		/domain/
 * @subcategory		Default javascript functions
 *
 * ----------------------------------------------------------------
 *
 * @final			DO NOT EDIT THIS FILE
 *
 *					09.12.2008  PRW
 *
 /*************************************************************************************/
        

     /*************************************************************************************/  
     /**
     *
     **/
        function buildURL() {
           var   url='/ajaxIndex.php?final=true'
           return url 
        }
        
     /*************************************************************************************/  
     /**
     *
     **/
     whiteload = new Image(30,30);
     whiteload.src = '/-/view/img/cruiseline/loading/gif/'; 

     blueload = new Image(30,30);
     blueload.src = '/-/view/img/cruiseline/loading-grey/gif/'; 

        
        /*************************************************************************************/  
        /**
        *
        **/
        function pathToXsl(_type,_file,_dir) {
   	       var _dir = 	typeof(_dir) != 'undefined' 	? 	_dir 	: 	''	
            var url  = '/resources/xsl/default.php?type='+_type+'&file='+_file+'&dir='+_dir+''	
            return url 
        }
         
     /*************************************************************************************/  
     /**
     *
     **/
     function getImagePath(_path) {
   	    var _path = 	typeof(_path) != 'undefined' 	? 	_path 	: 	'loading-grey'	
         var url  = '/-/view/img/cruiseline/'+_path+'/gif/'	
         return url 
     }
 

	var _InsaoWWWDebug 	 		= 		false;
	var _InsaoWWWSupress	 	= 		false;
	var _www_coat_ui			=		"www_coat_ui"
	var _www_popbox_ui			=		"www_popbox_ui";
	var _www_popbox_ui			=		'www_popbox_ui'	
	var _www_popinner			=		'www_popinner';
	var _www_pophead			=		'www_pophead';
	var _www_popheadlft			=		'www_popheadlft';
	var _www_popheadrgt			=		'www_popheadrgt';
	var _www_popheadh1			=		'www_popheadh1';
	var _www_pophead_clear		=		'www_pophead_clear';
	var _www_popisingle_txt		=		"www_popinner_single_text";
	var _www_popbottom_txt		=		"www_popinner_single_btm_text";
	var _www_popinner_single	=		"www_popinner_single";
	var _www_editor				=		"plet_editor"
	var _www_inner_editor		=		"plet_inner_editor"
	
	var popupSafe				=		[];	
	
	/*******************************************************************************************************/
	/**
	* XMLHTTP call
	**/
	function GetXmlHttpObject(){
		var objXMLHttp=null
	
		if (window.XMLHttpRequest) {
			objXMLHttp=new XMLHttpRequest();
			
		} else if (window.ActiveXObject) {
			objXMLHttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		return objXMLHttp
	} 

	/*******************************************************************************************************/
	/**
	* Paint the browser window 
	**/
	function paintCanvas(setStyle) {
		var setStyle 		= 	typeof(setStyle) != 'undefined' 	? 	setStyle 	: 	_www_coat_ui;
		var bdp 			= 	document.createElement("div");
		bdp.id 				= 	setStyle;
		bdp.style.height 	= 	parseInt(document.documentElement.clientHeight) + 1000 +'px';
		
		document.body.appendChild(bdp);
	}
	
	/*******************************************************************************************************/
	/**
	* Reset the height of the blackout screen area for popups
	**/
	function recalpaintedcanvas(setStyle) {
		var setStyle 		= typeof(setStyle) 	!= 	'undefined' 	? 	setStyle 	: 	_www_coat_ui;
		
		if(document.getElementById(setStyle) != null) {
			document.getElementById(setStyle).style.height = parseInt(document.documentElement.clientHeight) + 1000 +'px';
		}
	}
	
	/*******************************************************************************************************/
	/**
	* Clear all the elements that cause overlaps for the popup
	**/
	function clearPopuphazrads() {
		
		// clear the embed tags
		var countembeds = document.getElementsByTagName("embed");
			
		for(i=0; i<countembeds.length;i++) {
			popupSafe.push(countembeds[i]);
 			countembeds[i].style.visibility="hidden";
		}
		
		// clear all the select tags
		var countselects	= document.getElementsByTagName("select");
		for(b=0; b<countselects.length;b++) {
			popupSafe.push(countselects[b]);
 			countselects[b].style.visibility="hidden";
		}
		
	}
	
	/*******************************************************************************************************/
	/**
	* On closing the popup put all the hidden items
	* back on the screen
	**/
	function reinitPopuphazrads() {
		for(i=0; i<popupSafe.length;i++) {
			if(popupSafe[i].style.visibility == 'hidden') {
 				popupSafe[i].style.visibility="visible";
			}
		}
	}

	/*******************************************************************************************************/
	/**
	*	
	**/
	function wwwPopup(paintui, style, canvasstyle) {
		
		var paintui 		=	typeof(paintui) 	!= 'undefined' 		? 	paintui 	: 	'true';
		var style 			= 	typeof(style) 		!= 'undefined' 		? 	style 		: 	_www_popbox_ui;
		var canvasstyle 	= 	typeof(canvasstyle) != 'undefined'	 	? 	canvasstyle : 	_www_coat_ui;
		
		clearPopuphazrads();
		if(paintui == 'true') {
			paintCanvas(canvasstyle);
		}
		
		var popup 			= 	document.createElement("div");
		popup.id 			= 	style;
		var popupi 			= 	document.createElement("div");
		popupi.id			= 	_www_popinner
		var popuph 			= 	document.createElement("div");
		popuph.id 			= 	_www_pophead;
		var popuphlft 		= 	document.createElement("div");
		popuphlft.id 		= 	_www_popheadlft;
		var popuph1 		= 	document.createElement("h1");
		popuph1.id			=	_www_popheadh1
		popuphlft.appendChild(popuph1);
		popuph.appendChild(popuphlft);
		var popuphrgt 		= 	document.createElement("div");
		popuphrgt.id 		= 	_www_popheadrgt
		var popclose 		= 	document.createElement("a");
		popclose.href		=	'#';
		popclose.onclick 	= 	new Function("return wwwPopClose('"+style+"','"+canvasstyle+"'); return false;");  
		var newClose 		= 	document.createTextNode("x");		
		popclose.appendChild(newClose);
		popuphrgt.appendChild(popclose);
		popuph.appendChild(popuphrgt);		
		var popuphclr = document.createElement("div");
		popuphclr.id = _www_pophead_clear;
		popuph.appendChild(popuphclr);	
		popupi.appendChild(popuph);
		popup.appendChild(popupi);	
		document.body.appendChild(popup);
	}
	
	/*******************************************************************************************************/
	/**
	* Add the loading status bar
	**/
	function wwwAddLoadingStatusBar() {
		
		 var eul = document.createElement("div");
			var popupimg 				= 	document.createElement("img");
			popupimg.src				=	getImagePath('loading');
			popupimg.height				=	"30";
			popupimg.width				=	"30";
			popupimg.style.marginTop 	=	"10px";
			popupimg.style.marginRight 	=	"10px";
			eul.appendChild(popupimg);

		 return eul;		 	 
	}
	
	/*******************************************************************************************************/
	/**
	*	
	**/
	function wwwSwapPopupToLoading(settitle, paintui, style, canvasstyle) {
		
		var paintui 		=	typeof(paintui) 	!= 'undefined' 		? 	paintui 	: 	'false';
		var style 			= 	typeof(style) 		!= 'undefined' 		? 	style 		: 	_www_popbox_ui;
		var canvasstyle 	= 	typeof(canvasstyle) != 'undefined'	 	? 	canvasstyle : 	_www_coat_ui;
		var settitle		=	typeof(settitle) 	!= 'undefined'	 	? 	settitle 	: 	"Loading";
		
		wwwPopClose(false,false,true);
		wwwPopupLoading(settitle, paintui, style, canvasstyle);
	}
	
	
	/*******************************************************************************************************/
	/**
	*	
	**/
	function wwwPopupLoading(settitle,paintui,style,canvasstyle) {
		
		var paintui 		=	typeof(paintui) 	!= 'undefined' 		? 	paintui 	: 	'true';
		var style 			= 	typeof(style) 		!= 'undefined' 		? 	style 		: 	_www_popbox_ui;
		var canvasstyle 	= 	typeof(canvasstyle)     != 'undefined'	 	? 	canvasstyle : 	_www_coat_ui;
		var settitle		=	typeof(settitle) 	!= 'undefined'	 	? 	settitle 	: 	"Loading";
		
		clearPopuphazrads();
		if(paintui == 'true' && (document.getElementById(canvasstyle) == null)) {
			paintCanvas(canvasstyle);
		}
	
		var popup 			= 	document.createElement("div");
		popup.id 			= 	style;	
		var popupi 			= 	document.createElement("div");
		popupi.id			= 	_www_popinner
		var popuph 			= 	document.createElement("div");
		popuph.id 			= 	_www_pophead;	
		var popuphlft 		= 	document.createElement("div");
		popuphlft.id 		= 	_www_popheadlft;	
		var popupimg 				= 	document.createElement("img");
		popupimg.src				=	getImagePath();
		popupimg.height				=	"30";
		popupimg.width				=	"30";
		popupimg.alt				=	settitle;
		popupimg.title				=	settitle;
		popupimg.style.marginTop 	=	"10px";
		popupimg.style.marginRight 	=	"10px";
		popuphlft.appendChild(popupimg);	
		var popuph1 				= 	document.createElement("h1");
		popuph1.id					=	_www_popheadh1
		popuph1.style.position		=	"relative";
		popuph1.style.top		  	=	"-10px";	
		popuphlft.appendChild(popuph1);
		popuph.appendChild(popuphlft);
		var popuphrgt 		= 	document.createElement("div");
		popuphrgt.id 		= 	_www_popheadrgt
		var popuphclr = document.createElement("div");
		popuphclr.id = _www_pophead_clear;
		popuph.appendChild(popuphclr);	
		popupi.appendChild(popuph);
		popup.appendChild(popupi);	
		document.body.appendChild(popup);	
		populatePopTitle(settitle+'...');
		positionPopup();
	}
	
	/*******************************************************************************************************/
	/**
	*	
	**/
	function positionPopup(setpos) {
		var setpos 				= 	typeof(setpos) 	!= 	'undefined' 	? 	setpos 	: 	_www_popbox_ui;
		window.location.hash	=	setpos;
	}
	
	/*******************************************************************************************************/
	/**
	*	
	**/
	function populatePopTitle(istr) {
		if(document.getElementById(_www_popheadh1) != null) {
			var newTitle 	= 	document.createTextNode(istr);
			document.getElementById(_www_popheadh1).appendChild(newTitle);
		}		
	}

	/*******************************************************************************************************/
	/**
	*	
	**/
	function populatePopSingleCell(iStr) {
		
		var iStr 		= 	typeof(iStr) 	!= 	'undefined' 	? 	iStr 	: 	null;
		var popinner 	= 	document.getElementById(_www_popinner);
		
		if(popinner != null) {	
			var popInnerSingle 		= 	document.createElement("div");
			popInnerSingle.id 		= 	_www_popinner_single;
			var popInnerText 		= 	document.createElement("div");
			popInnerText.id 		= 	_www_popisingle_txt;
			if(iStr	!= null) {
				var pinnerTxt 			=	 document.createTextNode(iStr);
				popInnerText.appendChild(pinnerTxt);
			}	
			var popBottomText 		= 	document.createElement("div");
			popBottomText.id 		= 	_www_popbottom_txt;
			
			popInnerSingle.appendChild(popInnerText);
			popInnerSingle.appendChild(popBottomText);
			popinner.appendChild(popInnerSingle);
		}
	}
	
	
	/*******************************************************************************************************/
	/**
	*	Close the popup box
	**/
	function wwwPopClose(a,b,c,d) {
		
		var a 		= 	(	(typeof(a) 	!= 'undefined')  && (a != false))	? 		a	 :	_www_popbox_ui;
		var b 		= 	(	(typeof(b) 	!= 'undefined')  && (b != false))	? 		b	 :	_www_coat_ui;
		var c 		= 	(	(typeof(c) 	!= 'undefined')  && (c != false))	? 		c	 :	false;
		var d 		= 	(	(typeof(d) 	!= 'undefined')  && (d != false)) 	? 		d	 :	false;
		
		var pop		= 	document.getElementById(a); 
		var canv 	=  	document.getElementById(b);
		
		if((canv != null) &&  (c != true) ) { 
			document.body.removeChild(canv); 
			reinitPopuphazrads();
		}
		
		if((pop != null) && (d != true) )  { 
			document.body.removeChild(pop); 
		}
		
		return false;
	}
		
	/*******************************************************************************************************/
	/**
	*	
	**/
	function loadXMLDoc(fname) {
		
		var xmlDoc;
		
		if (window.ActiveXObject){
	 		 xmlDoc 	= new ActiveXObject("Microsoft.XMLDOM");
			
		} else if (document.implementation && document.implementation.createDocument) {
 			 xmlDoc		=	document.implementation.createDocument("","", null);
		
		} else  {
  			alert('Your browser cannot correctly load this script');
		}
		
		xmlDoc.async			=	false;
		xmlDoc.validateOnParse 	= 	false;
		xmlDoc.resolveExternals = 	false;
		xmlDoc.load(fname);
		
		return(xmlDoc);
	}
	
	/*******************************************************************************************************/
	/**
	*	
	**/
	function serveXslt(theXML, theXSL) {

		xml 	= 	theXML;
		xsl		=	loadXMLDoc(theXSL);
		
		if (window.ActiveXObject) {
	  		resultDocument		=	xml.transformNode(xsl);
	  		
	  	} else if (document.implementation && document.implementation.createDocument) {
		  xsltProcessor		=	new XSLTProcessor();
		  xsltProcessor.importStylesheet(xsl);
		  resultDocument 	= 	xsltProcessor.transformToFragment(xml,document);
	  	}

	  	return resultDocument;
	}
		  	
	/*******************************************************************************************************/
	/**
	* Open a portlet Editor
	*
	* @param (str)	id
	* @param (str)	instance
	* @param (str)	ltxt
	* @param (str)	edtxt
	* @param (obj)	current
	*
	**/
	function portlet_editor_www_request(id,instance,ltxt,current) {
		
		var	id 			= 	typeof(id) 			!= 'undefined' 			? 	id 				: 	null;
		var	instance 	= 	typeof(instance) 	!= 'undefined' 			? 	instance 		: 	null;
		
		if((id != null) && (document.getElementById(_www_editor + '_' + id) != null) && (document.getElementById(_www_editor + '_' + id).style.textAlign	!= 'center') ) {
			
			try {
				var parentEditorNode	=	document.getElementById(_www_editor + '_' + id);

				if(document.getElementById(_www_inner_editor + '_' + id) != null) {
					parentEditorNode.removeChild(document.getElementById(_www_inner_editor + '_' + id));
				
				} else {
					document.getElementById('plet_'+id).style.height = 'auto';
					toAppendInt					=	document.getElementById(_www_editor + '_' + id)
					toAppendInt.style.textAlign	=	"center";
					var loadTxt 				=   wwwAddLoadingStatusBar();
					toAppendInt.appendChild(loadTxt);
			
					var xmlHttp		=	prepare_www_ajax_portlet_process_editor(id,instance,'editor','');
					xmlHttp.onreadystatechange=function() {
						if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete') {

							var insaoDebug		=	insaoDebugMethod()	
							var xmlDocument		=	xmlHttp.responseXML;
							var anyErrors		=	checkForAjaxErrors(xmlDocument);
							
							if(anyErrors.set == true) {
									toAppendInt.removeChild(loadTxt);
									alertError(anyErrors.status, anyErrors.etext);
							
							} else {
								try {
									toAppendInt.removeChild(loadTxt);
									toAppendInt.style.textAlign	=	"left";
							
									var toAppend 		= 	document.createElement("div");
									toAppend.id 		= 	_www_inner_editor + '_' + id;
									toAppend.className 	= 	_www_inner_editor;
									
									var xslpath		=	pathToXsl('portlet', 'www-editor',"_common");
									var transform	=	serveXslt(xmlDocument, xslpath);
									
									if (window.ActiveXObject) {
										toAppend.innerHTML	+=	transform;
										
								  	} else if (document.implementation && document.implementation.createDocument) {
									 	toAppend.appendChild(transform);
								  	}
								  	
								  	var toAppend2 		= 	document.createElement("div");
								  	toAppend2.id 		= 	'plet_inner_editor_2_'+id;
								  	
								  	var xslpath2		=	pathToXsl('portlet', instance+'-www-editor', instance);
									var transform2		=	serveXslt(xmlDocument, xslpath2);
									
								  	if (window.ActiveXObject) {
										toAppend2.innerHTML	+=	transform2;
								
								  	} else if (document.implementation && document.implementation.createDocument) {
									 	toAppend2.appendChild(transform2);
								  	}
								  	
								  	toAppend.appendChild(toAppend2)
								  	document.getElementById(_www_editor + '_' + id).appendChild(toAppend);
								  	
								} catch(err) {
									catchError(err)
								}
							}
						}
					}
				}
			} catch(e) {
				catchError(e);
			}
		}
	}
	
	/*******************************************************************************************************/
	/**
	*	
	*
	*
	**/
	function prepare_ajax_cmd(id,instance,cmdCall,cmd,appendposts,mode) {
		var	mode 			= 	 typeof(mode) 			!= 'undefined' 		? 	mode 			: 	'null';
		var id	 			=	 typeof(id) 			!= 'undefined' 		? 	id 				: 	'null';
		var instance	 	=	 typeof(instance)		!= 'undefined' 		? 	instance 		: 	'null';
		var	cmdCall			=	 typeof(cmdCall)		!= 'undefined' 		? 	cmdCall 		: 	'null';
		var	cmd				=	 typeof(cmd)			!= 'undefined' 		? 	cmd 			: 	'null';
		var	appendposts		=	 typeof(appendposts)	!= 'undefined' 		? 	appendposts 	: 	'';
		var xmlDocument		=	 null;
		
		xmlHttp=GetXmlHttpObject()
		url=buildURL()
		
		if ( xmlHttp==null ) {
			alert ('Browser does not support HTTP Request')
			return
		} 
		
		xmlHttp.open( 'POST', url, true )
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8')
		xmlHttp.send('mode='+mode+'&cmdcall='+cmdCall+'&cmd='+cmd+'&id='+id+'&instance='+instance+''+appendposts)
		return xmlHttp;
	}
	
	
	/*******************************************************************************************************/
	/**
	*	
	* @param (str)	id
	* @param (str)	instance
	* @param (str)	cmd
	* @param (str)	appendposts
	*
	**/
	function prepare_www_ajax_portlet_process_action(id,instance,cmd,appendposts) {

		var id	 			=	 typeof(id) 			!= 'undefined' 		? 	id 				: 	'null';
		var instance	 	=	 typeof(instance)		!= 'undefined' 		? 	instance 		: 	'null';
		var	cmd				=	 typeof(cmd)			!= 'undefined' 		? 	cmd 			: 	'null';
		var	appendposts		=	 typeof(appendposts)	!= 'undefined' 		? 	appendposts 	: 	'';
		
		return prepare_ajax_cmd(id,instance,'loadPortletAjax',cmd,appendposts,'portlet');
	}
	
	/*******************************************************************************************************/
	/**
	*	
	* @param (str)	id
	* @param (str)	instance
	* @param (str)	cmd
	* @param (str)	appendposts
	*
	**/
	function prepare_www_ajax_portlet_process_editor(id,instance,cmd,appendposts) {

		var id	 			=	 typeof(id) 			!= 'undefined' 		? 	id 				: 	'null';
		var instance	 	=	 typeof(instance)		!= 'undefined' 		? 	instance 		: 	'null';
		var	cmd				=	 typeof(cmd)			!= 'undefined' 		? 	cmd 			: 	'null';
		var	appendposts		=	 typeof(appendposts)	!= 'undefined' 		? 	appendposts 	: 	'';
		
		return prepare_ajax_cmd(id,instance,'loadPortletWWWEditor',cmd,appendposts,'portlet');
	}
	
	
	/*******************************************************************************************************/
	/**
	* FIND && SORT ERRORS
	* We only return the first error - we do not want to overload the user with errors 
	* @param (xml)	xmlDocument
	*
	**/
	function checkForAjaxErrors(xmlDocument) {
		
		try {
			var numoferrors 	= 	xmlDocument.getElementsByTagName('error').length
			if(numoferrors >= 1) {
				var seterrorStatus 		= 	xmlDocument.getElementsByTagName('error')[0].childNodes[0].childNodes[0].nodeValue
				var seterrorText 		= 	xmlDocument.getElementsByTagName('error')[0].childNodes[2].childNodes[0].nodeValue
				return {set:true, status:seterrorStatus, etext:seterrorText};
				
			} else {
				return {set:false, status:false, etext:false};
			}
		} catch(e) {
			return {set:true, status:'Warning', etext:e};
		}
	}
	
	/*******************************************************************************************************/
	/**
	* Alert any error
	* @param (str)	status
	* @param (str)	msg
	*
	**/
	function alertError(status,msg) {
		var	status 			= 	 ((typeof(status) 	!= 'undefined')	 	&&		(status != ''))		? 	status 			: 	'Warning';
		var msg	 			=	 typeof(msg) 		!= 'undefined' 									? 	msg 			: 	'Unknown error';
		
		wwwPopClose();
		alert(status + '\r\n' + msg);
	}
	
	/*******************************************************************************************************/
	/**
	* Catch exception error
	* @param 	(str)	msg
	* @return array
	*
	**/
	function catchError(msg) {
		if(_InsaoWWWDebug = true) {
			var msg	 			=	 typeof(msg) 		!= 'undefined' 		? 	msg 			: 	'Unknown error';
			wwwPopClose();
			alert(msg);
		}
	}
	
	/*******************************************************************************************************/
	/**
	*  Display any errors
	*
	* @param (arr)	xmlDocumentErrors
	* @return null
	*
	**/
	function displayErrorBox(xmlDocumentErrors) {
		alert(xmlDocumentErrors.status + '\r\n' + xmlDocumentErrors.etext)
	}
	
	/*******************************************************************************************************/
	/**
	* INSAO Debug Mode
	* @return null
	**/
	function insaoDebugMethod() {
		if(_InsaoWWWDebug == true) {
			alert(xmlHttp.responseText);
		}
	}

	/*******************************************************************************************************/
	/**
	* Close || Open a portlet
	*
	* @param (int)	initid
	* @param (obj)	thisObj
	
	* @return null
	**/
	function foldPortlet(initid,thisObj) {
		
		portletid 	= 'portlet_inner_'	+ initid
		editorid	= _www_editor + '_' + initid
		editorinner	= _www_inner_editor + '_' + initid
		
		if(document.getElementById(portletid) != null) {
			if(document.getElementById(portletid).style.visibility	!=	'hidden') {
				
				// ----------------------------------------
				// remove the editor
				if(document.getElementById(editorinner)	!=	null) {
					document.getElementById(editorid).removeChild(document.getElementById(editorinner));
				}
				
				document.getElementById(portletid).style.height		=	'1px'
				document.getElementById(portletid).style.visibility	=	'hidden'
				thisObj.childNodes[0].nodeValue	=	'>'
				
			} else {
				document.getElementById(portletid).style.height		=	'auto'
				document.getElementById(portletid).style.visibility	=	'visible'
				thisObj.childNodes[0].nodeValue	=	'v'
			}
		}
	}		


