/**
 * ocsp js main object
 *
 * @since pk-08-01-17
 *
 * @requires jQuery
 *
 * @version $Id: jOCSP.js,v 1.51 2011/05/25 20:49:37 pitlinz Exp $
 */
 
if (!window.jOCSP)
{
	/**
	 * cache for requirements which has to be loaded after jOCSP
	 *
	 * @var array jOCSP_requireCache
	 */
	if (typeof(window.jOCSP_requireCache) == "undefined")
	{
		jOCSP_requireCache = new Array();
	}

	/**
	 * package to hold all jOCSP objects and values
	 *
	 * @static
	 */
	jOCSP = new function(ocspSystemUrl,ocspAdminUrl) 
	{
		/**
		 * ocsp-system root URL
		 * @var string
		 */
		if (ocspSystemUrl)
		{
			this.systemUrl = ocspSystemUrl;
			this.sysimgUrl = ocspSystemUrl + 'sysimages/';
		} else {
			this.systemUrl = '/ocsp-system/';
			this.sysimgUrl = '/ocsp-system/sysimages/';	
		}	

		if (ocspAdminUrl)
		{
			this.adminUrl = ocspAdminUrl;
		} else {
			this.adminUrl = '/ocsp-admin/';
		}


		this.debug = false;

		// ---------------------------------------------------
		// security request of the current page 
		// ---------------------------------------------------
	
		/**
		 * pcfmd5_encrypt encrypted and serialized security check array 
		 *
		 * @var string mySecReq
		 */
		this.mySecReq = null;
		           	    
		// ---------------------------------------------------
		// httpRequest 
		// ---------------------------------------------------
			
		/**
		 * indicates that a syncronus request is running
		 * 
		 * @var requestWaitLimit 
		 *
		 * values:
		 * - &gt; 0 request is running
		 * - -1 requested url could not be opened
		 * - -2 returned script could not be evaluated
		 * - -3 timeout
		 */
		this.requestWaitLimit = 0;
			
		/**
		 * state of the current sync request
		 * @var int requestState
		 */
		this.requestState = 0;	
		
		// ---------------------------------------------------
	    // ajax calls
	    // ---------------------------------------------------	
		
	    /**
	     * array of stored ajax requests
	     * @staticvar array ajaxHistory 
	     */
		this.ajaxHistory = new Array();		

		// ---------------------------------------------------
		// errors 
		// ---------------------------------------------------
	
		/**
		 * array holding errors
		 * @var array myErrors
		 */
		this.myErrors = new Array();

		
		/**
		 * form modes
		 */
		this.FRM_MODE_READONLY 	= 0;
		this.FRM_MODE_NEW		= 1;
    	this.FRM_MODE_EDIT		= 2;
    	this.FRM_MODE_HIDDEN	= 3;
    	this.FRM_MODE_LIST		= 4;
    	this.FRM_MODE_SEARCH	= 5;
    	this.FRM_MODE_DELETE	= 6;
    	this.FRM_MODE_COPY		= 7;
	
    	/**
    	 * session
    	 */
    	this.sessionName		= '';
    	this.sessionId			= '';
	}
		
	// ---------------------------------------------------
	// security request of the current page 
	// ---------------------------------------------------
		
		
	/**
	 * sets mySecReq
	 * 
	 * @param string cryptSerArr 
	 */	
	jOCSP.setSecReq = function(cryptSerArr)
	{
		jOCSP.mySecReq=cryptSerArr;
	}
		
	/**
	 * returns mySecReq
	 * @return string
	 */
	jOCSP.getSecReq = function()
	{
		return jOCSP.mySecReq;
	}			
						
	// ---------------------------------------------------
    // ajax calls
    // ---------------------------------------------------	
	    
    /**
     * an ajax request object
     * 
     * @class ajaxHistoryObj
     * 
     * @since pk-08-02-03
     */
    jOCSP.ajaxHistoryObj = function(url,ocspOpt)
    {
        this.url     = url;
        this.ocspOpt = ocspOpt;
    }	 
	    

	// ---------------------------------------------------
	// errors 
	// ---------------------------------------------------
	
		
	/**
	 * adds an error msg to this.myErrors
	 * @param string aError
	 */
	jOCSP.addError = function(aError)
	{
		if (aError)
		{
			jOCSP.myErrors.push(aError);
		}
	}
		
	/**
	 * returns the error Array
	 * @return array
	 */
	jOCSP.getErrors = function()
	{
		return jOCSP.myErrors;
	}	    
		
	/**
	 * alerts the attributes of an object
	 * 
	 * @param object aObj
	 * 
	 * @since pk-08-07-29
	 */
	jOCSP.debugObj = function(aObj)
	{
		str_debug = "";
		for (i in aObj)
		{			
			if (aObj[i])
			{
				str_debug += i + ": ";
				switch(typeof(aObj[i]))
				{
					case "function":
						str_debug += "funciton()";
						break;
					case "object":
						str_debug += "object";
						break;
					default:
						str_debug += aObj[i];
						break;
				}
				str_debug += "\n";
			}
		} 
		
		alert(str_debug);
	}
		
		
    // ---------------------------------------------------
    // simple dom functions 
    // ---------------------------------------------------

	jOCSP.setDOMinnerHTML = function (domId,content)
	{
		if( obj_node = document.getElementById(domId))
		{
			obj_node.innerHTML = content;
			return true;
		} else {				
			var errMsg = 'no dom object with id: ' + domId;
			this.addError({msg: errMsg,debugInfo: content,reqURI: this.ajaxGetCurrentScriptUrl()});
			return false;
		}
	}
		
    /**
      * returns a current (calculated) style value
      *
      * @param string domId
      * @param string styleName
      *
      * @return string
      * @since pk-08-02-03
      *
      */
    jOCSP.getDOMStyleById = function (domId,styleName)
    {
        if( obj_node = document.getElementById(domId) )
        {
            return this.getDOMStyle(obj_node,styleName);
        }
        return null;
    }		

    /**
      * returns a current (calculated) style value
      *
      * @param object domNode
      * @param string styleName
      *
      * @return string
      * @since pk-08-02-03
      *
      */
    jOCSP.getDOMStyle = function (domNode,styleName)
    {
        if (!domNode || !domNode.style || !styleName) 
        {
            return null;
        }
        try {
            if( window.getComputedStyle )
            {
                return window.getComputedStyle(domNode, '' ).getPropertyValue( styleName );
            } else if( domNode.currentStyle ) {
                return domNode.currentStyle.getAttribute( styleName.replace(/-/g, '') );
            } else if (domNode.style) {
                jOCSP.getDOMStyle_TmpNode =domNode;
                jOCSP.getDOMStyle_TmpStyle=null;
                eval ("jOCSP.getDOMStyle_TmpStyle = jOCSP.getDOMStyle_TmpNode.style." + styleName.replace(/-/g, ''));
                return jOCSP.getDOMStyle_TmpStyle; 
            }
            return null;
        } catch(e) {
            alert("jOCSP.getDOMStyle: \n" + e);
            return null;
        }
    }
	
	/**
	 * sets the parent height to the height of aDomId + padding if lower
	 * 
	 * @param string aDomId
	 * @param int padding
	 * 
	 */
	jOCSP.fixParentHeight = function(aDomId,padding)
	{
	    try {
	      if (obj_node = document.getElementById(aDomId))
	      {
	          if (obj_parent = obj_node.parentNode)
	          {		              
	              var l = obj_parent.childNodes.length;	
	              if (padding)
	              {	              	              
	                  var chkHeight = parseInt(padding);
	              } else {
	                  var chkHeight = 0;
	              }
	              
	              for (i = 0;i < l;i++)
	              {
	                  if (int_nodeHeight = parseInt(this.getDOMStyle(obj_parent.childNodes[i],'height')))
	                  {
	                      chkHeight += int_nodeHeight;
	                  }
	              }
	              	
	              if (parseInt(this.getDOMStyle(obj_parent,'height')) < chkHeight)
	              {
	                  obj_parent.style.height = chkHeight + "px";
	              }                      		              
	          } 
	      }
	    } catch(e) {
	        alert("jOCSP.fixParentHeight: \n" + e);
	        return;
	    }
	}		

		
	jOCSP.requireBase64 = function()
	{
		if (typeof(window.base64DecodeChars) == "undefined")
		{
			jQuery.getScript(this.systemUrl + 'javascript/base64.js');
		} 
	}
	

	// ---------------------------------------------------
	// httpRequest 
	// ---------------------------------------------------

	/**
	 * timeout call to count down this.requestWaitLimit
	 */
	jOCSP.requestWait = function()
	{
		if (jQuery.requestWaitLimit > 1)
		{
			jQuery.requestWaitLimit--;
			window.setTimeout("jOCSP.requestWait()",2);
		} else if (jQuery.requestWaitLimit > 1) {
			jQuery.requestWaitLimit = -3;
		}
	}
	
	jOCSP.sleep = function (ms)
	{
		var startTime = (new Date()).getTime();
		var stoppTime = startTime+ms;
		while((new Date()).getTime() < stoppTime){};
	}	 
	
	/**
	 * returns a http request
	 * 
	 * @return XMLHttpRequest
	 */	
	jOCSP.getAjaxRequest = function()
	{		
		var obj_req = null;
		if(window.XMLHttpRequest) // Mozilla, Safari,... 
		{
			obj_req = new XMLHttpRequest();
		} else if(window.ActiveXObject) { // IE
	        var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
			var l=msxmlhttp.length;	
			var i=0;				        
	        while (!obj_req && i < l )
	        {
	            try 
	            {
	                obj_req = new ActiveXObject(msxmlhttp[i]);
	            } catch (e) {
	                obj_req = null;
	                i++;
	            }
	        }
	    }
	    return obj_req;		
	}
		
	/**
	 * simple http request for loading a javascript with get
	 *
	 * if sync this.requestWaitLimit will be set to 
	 * timeout (default 1000) / 2 and checked if the
	 * request returns with a stats < 400
	 *
	 * always return true if !sync
	 *
	 * if this.requestWaitLimit < 0 an error has happend
	 *
	 * @param string url
	 * @param boolean sync (wait for loading script)
	 * @param int timeout (milisecounds default 1000)
	 *
	 * @return boolean 
	 */
	jOCSP.requestScript = function(url,sync,reqTimeout)
	{
		if (!url || url.length < 1)
		{
			return false;			
		}
		
		if (sync == 'head') 
		{
			// sync include 
			var head 	= document.getElementsByTagName("head")[0];
			var script 	= document.createElement("script");
			
			script.type		= "text/javascript";
			script.language ="javascript";
			script.src 		= url;
			
			
			head.appendChild(script);			
			return true;
		} 
		
		if (this.requestWaitLimit > 0)
		{
			jOCSP_requireCache[jOCSP_requireCache.length] = {url: url,sync: sync,timeout: timeout};  
		} else {
			this.requestWaitLimit = 0;
		}
	
	    if (!(reqObj=this.getAjaxRequest())) 
	    {
	    	this.addError('Could init HttpRequest object');
	    	return false;
	    }
		    	
		if (!sync)
		{	    	    				    
		  	reqObj.onreadystatechange = function() 
		  	{	  		
		  		if (reqObj.readyState != 4) 
		  		{
		  			return;
		  		}
				if (reqObj.status < 400)
	 			{
	 				if (reqObj.debug)
	 				{
		 				var str_msg = "\n";
		 				for (str_attrName in this)
		 				{
		 					str_msg += str_attrName + ", ";
		 				}
		 				alert('reqObj status: ' + reqObj.status + str_msg);
	 				}
	 				
	 				try 
	 				{
	 					try {      		
	 						var data = reqObj.responseText.replace(/^\s*|\s*$/g,"");
   							eval(data);
	 					} catch(e) {
	 						alert('error in response: ' + e);
	 					}
	   					
	        			if (jOCSP.requestWaitLimit > 0)
	        			{
	        				jOCSP.requestWaitLimit=0;
	        			}       					
	    			} catch(e) {
	    				jOCSP.addError('loading jQuery: ' + e);
	        			if (jOCSP.requestWaitLimit > 0)
	        			{
	        				jOCSP.requestWaitLimit=-2;
	        			}
	    			}
	    		} else {
	    			jOCSP.addError('loading jQuery returned status: ' + this.status);        			
	    			if (jOCSP.requestWaitLimit > 0)
	    			{
	    				jOCSP.requestState = this.status;
	    				jOCSP.requestWaitLimit=-1;
	    			}
	    		}       			 
			} // reqObj.onreadystatechange()
		
			reqObj.open('get',url,true);
			reqObj.send(null);
			return true;
		} else {
			reqObj.open('get',url,false);
			reqObj.send(null);
			try {      		
				var data = reqObj.responseText.replace(/^\s*|\s*$/g,"");			       					
				eval(data);
				return true;
			} catch(e) {
				alert('error in response: ' + e);
			}			
			return false;					
		}						
	}
			
    // ---------------------------------------------------
    // ajax calls
    // ---------------------------------------------------	

    /**
     * returns the last call of url 
     * 
     * @return jOCSP.ajaxHistoryObj
     * 
     * @since pk-08-02-03
     */
    jOCSP.ajaxHistoryGet = function(url)
    {
        var l=jOCSP.ajaxHistory.length;
        while (l >= 0)
        {
            if (jOCSP.ajaxHistory[l] && jOCSP.ajaxHistory[l].url)
            {
                if (jOCSP.ajaxHistory[l].url == url)
                {
                    return jOCSP.ajaxHistory[l]; 
                }
            }
            l--;
        }
    }
	    
    /**
     * returns the src of the current js script
     * 
     * @see http://feather.elektrum.org/book/src.html for detail information
     * 
     * @retrun string
     * 
     * @since pk-08-02-03 
     */
    jOCSP.ajaxGetCurrentScriptUrl = function()
    {
        var scripts = document.getElementsByTagName('script');
        
        if (scripts && scripts.length && scripts[ scripts.length - 1 ].src)
        {
        	 return scripts[ scripts.length - 1 ].src;
        }        
        return document.location.href;                     
    }
	    
    /**
     * returns an array of the query string params 
     * 
     * @see http://feather.elektrum.org/book/src.html for detail information
     * 
     * @param string url
     * 
     * @return object (vector)
     * 
     * @since pk-08-02-03
     */
    jOCSP.ajaxGetQueryStringParams = function(url)
    {
        try {
	        if (!url || (url.length < 1))
	        {
	            url = document.location.href;
	        }
        } catch(e) {
            return new Object();
        }	        
        
        try {
            var str_query = url.replace(/^[^\?]+\??/,'');

            var Params = new Object ();
            if ( ! str_query ) return Params; // return empty object
   			   		
   			alert ("jOCSP.js: jOCSP.ajaxGetQueryStringParams: \n" + str_query);	
            var Pairs = str_query.split(/[;&]/);
            var l=Pairs.length;
            for ( var i = 0; i < l; i++ ) {
                var KeyVal = Pairs[i].split('=');
                if ( ! KeyVal || KeyVal.length != 2 ) continue;
                var key = unescape( KeyVal[0] );
                var val = unescape( KeyVal[1] );
                val = val.replace(/\+/g, ' ');
                Params[key] = val;
            }
            return Params;	                        
        } catch(e) {
            alert(e);
        }	        
    }
    
    /**
     * changes the get param value in an url 
     * 
     * @param string pName
     * @param string pVal
     * @param string aUrl
     * 
     * @return string
     */
    jOCSP.changeGetParam = function(pName,pVal,aUrl)
    {
    	aUrl = aUrl || document.location.href;
    	arr_url = aUrl.split(/[\#]/);
    	if (arr_url[1])
    	{
    		var str_ankor = '#' + arr_url[1]; 
    	} else {
    		var str_ankor = '';
    	}
    	
    	arr_url = arr_url[0].split(/[\?]/);
    	    	
    	str_ret = arr_url[0];
    	if ( ! arr_url[1] )
    	{
    		str_ret += '?' + pName + '=' + escape(pVal) + str_ankor;
    		return str_ret;    		
    	}
    	
    	cha_sep = '?';
    	
    	arr_params = arr_url[1].split(/\&/);
    	
    	var i = 0;
    	var l = arr_params.length;    	
    	
    	while ( i < l) 
    	{
    		var arr_kv = arr_params[i].split('=');
    		if (arr_kv[0] != pName)
    		{
    			str_ret += cha_sep + arr_params[i];
				cha_sep = '&';    				
    		}
    		
    		i++;
    	}
    	
    	return str_ret + cha_sep + pName + '=' + escape(pVal) + str_ankor;
    	    	
    	//alert(arr_url[0] + ' QS:' + arr_url[1]);
    	
    	  
    }
	    
    /**
     * Loads, and executes, a remote JavaScript file using an HTTP GET request.
     * 
     * @param string url
     * @param function callback
     * @param object ocspOpt
     * 
     * @return XMLHttpRequest
     * 
     */
    jOCSP.getScript = function(url,callback,ocspOpt)
    {
        if (!ocspOpt)
        {
            ocspOpt = {type: 'getScript' };
        } else if (!ocspOpt.type) {
            ocspOpt.type = 'getScript';
        }
        
        var l=jOCSP.ajaxHistory.length;	        	        
        jOCSP.ajaxHistory[l] = new jOCSP.ajaxHistoryObj(url,ocspOpt);
        	        
		if (jOCSP.mySecReq && (url.indexOf("SecReq") == -1)) 
		{        	        
	        if (url.indexOf("?") == -1)
	            { url += "?SecReq=" + escape(jOCSP.mySecReq); }
	        else
	            { url += "&SecReq=" + escape(jOCSP.mySecReq); }
		}	 
		       
        return jQuery.getScript(url,callback);        
    }
    
    /**
     * loads a content (HTML Output !!) into a div
     * by calling jQuery(divObj).load(url,params,callback)
     * 
     * @param string divId
     * @param string url
     * @param object params
     * @param function callback
     * 
     * @since pk-08-05-22
     */
	jOCSP.load = function(divId,url,params,callback)
	{
		if (objDiv = document.getElementById(divId))
		{
			this.loadDiv(objDiv,url,params,callback);
		} else {
			this.addError('jOCSP.load: DIV with ID: ' + divId + 'not found (url: '+url + ')');
		}
	}
	
	jOCSP.loadDiv = function(objDiv,url,params,callback)
	{
		if (jOCSP.mySecReq && (url.indexOf("SecReq") == -1)) 
		{        	        
	        if (url.indexOf("?") == -1)
	            { url += "?SecReq=" + escape(jOCSP.mySecReq); }
	        else
	            { url += "&SecReq=" + escape(jOCSP.mySecReq); }
		}	
		if((url.indexOf("inToDiv") == -1) && (objDiv.id))
		{
			if (url.indexOf("?") == -1)
			{
				url += "?inToDiv=" + escape(objDiv.id);
			} else {
				url += "&inToDiv=" + escape(objDiv.id);
			}				
		}	
		jQuery(objDiv).load(url,params,callback);		
	}
	
	/**
	 * posts data to url
	 * 
	 * @param string url
	 * @param object data
	 * 
	 */
	jOCSP.post = function(url, data, callback, type)
	{
		if (jOCSP.mySecReq && (url.indexOf("SecReq") == -1)) 
		{        	        
	        if (url.indexOf("?") == -1)
	            { url += "?SecReq=" + escape(jOCSP.mySecReq); }
	        else
	            { url += "&SecReq=" + escape(jOCSP.mySecReq); }
		}
		
		jQuery.post(url, data, callback, type);
	}
	
	
    /**
     * loads a jason object
     * by calling getJSON(url,params,callback)
     * 
     * @param string url
     * @param object params
     * @param function callback
     * 
     * @since pk-08-05-22
     * @version pk-08-07-30
     */
	jOCSP.getJSON = function(url,params,callback)
	{
		if (jOCSP.mySecReq && (url.indexOf("SecReq") == -1)) 
		{        	        
	        if (url.indexOf("?") == -1)
	            { url += "?SecReq=" + escape(jOCSP.mySecReq); }
	        else
	            { url += "&SecReq=" + escape(jOCSP.mySecReq); }
		}	
		
		if (typeof(callback) == "function")
		{
			jQuery.getJSON(url,params,callback);
		} else {
			// do a sync request and get the json object
			 
			if (!(obj_req=this.getAjaxRequest())) 
	    	{
	    		this.addError('Could init HttpRequest object');
	    		return false;
	    	}
	
			obj_req.open('get',url,false);
			obj_req.send(null);
			try {      		
				var data = obj_req.responseText.replace(/^\s*|\s*$/g,"");		       					
				eval("obj_ret=" + data);
				return obj_ret;
			} catch(e) {
				alert('error in response: ' + e);
			}			
			return false;				
		}
	}
	
	/**
	 * appends a css file
	 * 
	 * @param target
	 * @param src
	 */
	jOCSP.loadCss = function(src,target)
	{
		if (!target) target = document.getElementsByTagName('head').item(0);
		
		obj_css =  document.createElement('link');
		obj_css.setAttribute('rel',"stylesheet");
		obj_css.setAttribute('href',src);
		obj_css.setAttribute('type',type="text/css");
		
		target.appendChild(obj_css);
	}

	/**
	 * adds a new layer over the body
	 */
	jOCSP.shadowBody = function()
	{
        if (!(obj_shadow = document.getElementById('bodyShadow')))
        {
            obj_shadow = document.createElement('DIV');        
            obj_shadow.id           = "bodyShadow";
            document.body.appendChild(obj_shadow);
            
            obj_shadow.attachedElements = {};
        }
        
        obj_shadow.style.top    = '0px';
        obj_shadow.style.left   = '0px';
        
        try {
        	if (int_width = document.clientWidth)
        	{
        		obj_shadow.style.width  = int_width + "px";
        	} else if (int_width = document.body.offsetWidth){
        		obj_shadow.style.width  = int_width + "px";
        	} else {
        		obj_shadow.style.width  =  "1024px";
        	}		
        } catch(e) {
        	obj_shadow.style.width  =  "1024px";
        }
        
        try {
        	if (int_height = document.clientHeight)
        	{
        		obj_shadow.style.height  = int_height + "px";
        	} else if (int_height = document.body.offsetHeight){
        		obj_shadow.style.height  = int_height + "px";
        	} else {
        		obj_shadow.style.height  =  "1000px";
        	}	
        } catch(e) {
        	obj_shadow.style.height = "1000px";	
        }
         
        obj_shadow.style.visibility = 'visible';
        obj_shadow.style.display    = 'block';
        obj_shadow.style.position   = 'absolute';
        
        obj_shadow.style.backgroundColor = "#000000";
        obj_shadow.style.opacity         = "0.5";
        obj_shadow.style.zIndex          = "9000";  
        obj_shadow.style.position   	 = 'fixed';
        obj_shadow.onclick	= function()
        {
        	jOCSP.unshadowBody();
        }		
        
        return obj_shadow;
	}
	
	/**
	 * removes the body shadow
	 */
	jOCSP.unshadowBody = function()
	{
		if ((obj_shadow = document.getElementById('bodyShadow')))
		{
			if (obj_shadow.attachedElements)
			{
				for (i in obj_shadow.attachedElements)
				{
					try {
						switch(typeof(obj_shadow.attachedElements[i]))
						{
							case 'function':	
								try {
									obj_shadow.attachedElements[i]();
								} catch(e) {
									if (jOCSP.debug) {alert(e);}
								}
								break;
							case 'object':
								if (obj_shadow.attachedElements[i].style)
								{
									obj_shadow.attachedElements[i].style.visibility = 'hidden';
									obj_shadow.attachedElements[i].style.display 	= 'none';
								}
								break;
						}
					} catch(e) {
						if (jOCSP.debug) alert(e);
					}
				}
			}
			
	        obj_shadow.style.visibility = 'hidden';
	        obj_shadow.style.display    = 'none';
	        obj_shadow.attachedElements = {};
		}		
	}
	
	/**
	 * attaches an element to the shadow
	 * 
	 * @param string aId (DomId)
	 * @param object aObj (function or DOMObject)
	 * 
	 */
	jOCSP.shadowAttacheElement = function(aId,aObj)
	{
		if ((obj_shadow = document.getElementById('bodyShadow')))
		{
			obj_shadow.attachedElements[aId] = aObj;
		} else {
			return false;
		}
	}
	
	/**
	 * openens a shadow overlay
	 * 
	 * @param string domId
	 * @param int width
	 * @param int height
	 * 
	 * @return DOM div
     */
	jOCSP.getShadowOverlayDiv = function(domId,width,height)
	{
		if (!(obj_dom = document.getElementById(domId)))
		{
			obj_dom    = document.createElement('DIV');
			obj_dom.id = domId; 
			document.body.appendChild(obj_dom);
		}	

		
		obj_dom.style.width  = width + 'px';
		obj_dom.style.height = height+ 'px';
				
		obj_dom.style.visibility = 'visible';
		obj_dom.style.display    = 'block';
		obj_dom.style.position   = 'fixed';
		obj_dom.style.zIndex	 = '9001';
			
		
		if ((obj_shadow = document.getElementById('bodyShadow')))
		{
			try {
				int_sWidth = parseInt(obj_shadow.style.width);
				if (width < int_sWidth)
				{
					obj_dom.style.left = Math.floor((int_sWidth - width) / 2) + 'px';
				} else {
					obj_dom.style.left = '10px';
					obj_shadow.style.width = (width + 20) + 'px';
				}
			} catch(e) {
				alert(e);
			}

			try {
				int_sHeight= parseInt(obj_shadow.style.height);
				if (height < int_sHeight)
				{
					obj_dom.style.top = Math.floor((int_sHeight - height) / 2) + 'px';
				} else {
					obj_dom.style.top = '10px';
					obj_shadow.style.height = (height + 20) + 'px';
				}
			} catch(e) {
				alert(e);				
			}
			
			obj_shadow.attachedElements[domId] = obj_dom;
		}
		
		return obj_dom;		
	}

	
    /**
     * shows a simple login form
     * 
     * @param string targetUrl
     * @param json params
     * 
     * 
     */
    jOCSP.loginForm = function(targetUrl,params)
    {
      
      	jOCSP.shadowBody();
        
        if (!(obj_login = document.getElementById('loginPannel')))
        {
            obj_login       = document.createElement('DIV');
            obj_login.id    = 'loginPannel';
            document.body.appendChild(obj_login);
        }
        
        int_top = ((document.body.offsetHeight / 2) - 90);
        if (int_top < 5) int_top = 5;
        
        obj_login.style.top     = int_top + "px";
        obj_login.style.left    = ((document.body.offsetWidth / 2) - 180) + "px";
        obj_login.width         = "400px";
        obj_login.height        = "200px";
        
        obj_login.style.visibility          = 'visible';
        obj_login.style.display             = 'block';
        obj_login.style.position            = 'absolute';        
        obj_login.style.zIndex              = "9001"; 
        obj_login.style.backgroundColor     = "#FFFFFF";
        obj_login.style.backgroundImage		= "url(" + jOCSP.sysimgUrl + 'openCSP/bg_wp1_200x200.jpg)';
        obj_login.style.opacity             = "1";

		str_url = jOCSP.systemUrl + "tools/loginDiv.php";
		str_url+= "?SUBMITURL=" + encodeURIComponent(targetUrl);
		
		if (targetUrl.indexOf('LOGIN=1'))
		{
			str_url += "&LOGIN=1";
		}
		if (params)
		{
			for (j in params)
			{
				str_url += "&" + j + "=" + encodeURIComponent(params[j]);				
			}
		} 

		jQuery(obj_login).load(str_url);       
    }
	
	jOCSP.getScrollXY = function () {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		    scrOfY = window.pageYOffset;
		    scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		    //DOM compliant
		    scrOfY = document.body.scrollTop;
		    scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		    //IE6 standards compliant mode
		    scrOfY = document.documentElement.scrollTop;
		    scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}	
	
	
	jOCSP.hideAlertBox = function()
	{
		if (obj_dom = document.getElementById('jOCSP_alertBox'))
		{
	        obj_dom.style.visibility='hidden';
	        obj_dom.style.display='none';			
		}
	}
	
	
    // --------------------------------------------------
    // browser window functions
    // ---------------------------------------------------  
	
	
	/**
	 * opens a new browser window (popup)
	 * 
	 * @param string name
	 * @param string location
	 * @param int width
	 * @param int height
	 * @param string myCmd
	 * 
	 * @return windowobject
	 * 
	 */
    jOCSP.openWindow = function(name,location,width,height,myCmd)
    {
        if (!myCmd) 
        {
            myCmd = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes";
        }
        
        if (width != "")
        {
            myCmd = myCmd + ",width="+width;
        }
        
        if (height != "")
        {
            myCmd = myCmd + ",height="+height;
        }
    
        var myWnd = window.open(location,name,myCmd);
        myWnd.focus();
        return myWnd;
    }
 

	jOCSP.alertMsg = function(aMsg,delay,posObj,offsetX,offsetY,width,height,alertId)
	{ 
		if (!alertId) {
			alertId = 'jOCSPAlertBox';
		}
		
		if (!(obj_dom = document.getElementById(alertId)))
		{
            obj_dom       = document.createElement('DIV');
            obj_dom.id    = alertId;
            document.body.appendChild(obj_dom);
            obj_dom.style.display='none';	
            obj_dom.style.width  = '400px';
            obj_dom.style.height = '300px';
            obj_dom.style.position = 'absolute';            				
		}
		
		if (width) {
			obj_dom.style.width = width + 'px';
		}
		
		if (height) {
			obj_dom.style.height = height + 'px';
		}
		
		obj_dom.style.zIndex = "9999";

		if (posObj)
		{
			int_left = posObj.offsetLeft;
			int_top  = posObj.offsetTop;
			
			try {
				obj_pos = posObj
				while (obj_pos.offsetParent)
				{
					obj_pos = obj_pos.offsetParent
					if (obj_pos.offsetLeft) {
						int_left += obj_pos.offsetLeft;
					}
					if (obj_pos.offsetTop) {
						int_top += obj_pos.offsetTop;
					}
				}
			} catch(e) {
				if (this.debug) alert(e);
			}			
		} else {
			int_left = 20;
			int_top  = 20;
		}
		
		if (offsetX)
		{
			int_left = int_left + offsetX;
		}
		
		if (offsetY)
		{
			int_top = int_top + offsetY;
		}

		obj_dom.style.left 	= int_left+"px";
		obj_dom.style.top 	= int_top+"px";
		obj_dom.className 	= "jOCSPAlertBox";	
		obj_dom.onclick 	= function() {jQuery('#' + alertId).fadeOut("slow")};

						
		obj_dom.innerHTML = aMsg;  
		jQuery('#'  + alertId).fadeIn("slow")

		if ((typeof(delay) == 'undefined') || (parseInt(delay) == 'NaN'))
		{ 
			delay = 4000;
		} else {
			delay = parseInt(delay)
		}
		if (delay > 0)
		{ 
			str_cmd = "jQuery('#" + alertId + "').fadeOut('slow')";
			setTimeout(str_cmd, delay);
		} 		
		
	}

    // --------------------------------------------------
    // simple dom functions
    // ---------------------------------------------------  

	jOCSP.getDomAttribut = function(domObj,attrName)
	{
		if (domObj && domObj.attributes)
		{
			for(var i = 0; i < domObj.attributes.length; i++)
			{
				if (domObj.attributes[i].nodeName == attrName)
				{
					return domObj.attributes[i].nodeValue;
				}
			}
		}
		return null;
	}

	// --------------------------------------------------
	// events
	// --------------------------------------------------
	
	jOCSP.keyPressed = function(e,letters)
	{
		var key;
		var keychar;

		if (window.event)
		   key = window.event.keyCode;
		else if (e)
		   key = e.which;
		else
		   return true;
		keychar = String.fromCharCode(key);

		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		{
			return true;
		} else if (((letters).indexOf(keychar) > -1)) {
   			return true;
   		} 
   		return false;
	}


	//
	// String extensions
	//
	
	String.prototype.leftTrim = function () {
	    return (this.replace(/^\s+/,''));
	};
	String.prototype.rightTrim = function () {
	    return (this.replace(/\s+$/,''));
	};
	//kombiniert leftTrim und rightTrim;
	String.prototype.basicTrim = function () {
	    return (this.replace(/\s+$/,'').replace(/^\s+/,''));
	};
	//dampft leerzeichen(-sequenzen) innerhalb einer zeichenkette auf ein einzelnes space ein;
	String.prototype.superTrim = function () {
	    return(this.replace(/\s+/g,' ').replace(/\s+$/,'').replace(/^\s+/,''));
	};
	
	//zugabe: entfernt alle leerzeichen aus einer zeichenkette;
	String.prototype.removeWhiteSpaces = function () {
	    return (this.replace(/\s+/g,''));
	};

}
