var appDisabled = false;

function stripHTML(htmlString)
{
    //This pattern Matches everything found inside html tags;
    //(.|\n) - > Look for any character or a new line
    // *?  -> 0 or more occurences, and make a non-greedy search meaning
    // it will return the stripped text without any html code
    // first it strips the html code then it strips all the excess whitespace
    var pattern = /<(.|\n)*?>/g; // remove all html
    htmlString = htmlString.replace(pattern," ");
    pattern = /\s+/g; // remove all whitespace
    alert( htmlString.replace(pattern," "));
}

function validateChars(e){
    var re = /[a-zA-Z0-9_\- ]+$/;
    var keycode;
    if(!e) e=window.event;
    if (window.event) { 
        keycode = e.keyCode;
	if(String.fromCharCode(keycode).match(re) != null)
        	e.returnValue=""+(String.fromCharCode(keycode).match(re));
	else
        	e.returnValue=(String.fromCharCode(keycode).match(re));
    } else {
        keycode = e.which;
        return (String.fromCharCode(keycode).matches(re));
    }
    return true;
}

function trim(str) { 
    var newstr = str.replace(/^\s+/, '').replace(/\s+$/, ''); 
    return newstr;
} 

//	function: hideApp
//		Build or get a div tag, make it the same size as the window, and put it above all components.
//	Usage: 
//		hideApp()
//	Parameters:
//		None
//	Returns:
//		None

function hideApp(showTimer,showDim){
	try{
                openMaskDiv(showDim);
		appDisabled=true;
                if(showTimer) {
                    var timerObj = document.getElementById('animTimer');
                    if(timerObj) {
                        var len = (getViewportWidth() / 2) - 150;
                        timerObj.style.left=len;
                        timerObj.style.top='250px';
                        timerObj.style.display = 'block'; 
                    }
                }
		
	}catch(err){
		alert("Error in hideApp: " + err);
	}
}

//	function: showApp
//		Get the div tag above the screen and disable it. 
//	Usage: 
//		showApp()
//	Parameters:
//		None
//	Returns: 
//		None  

function showApp(){
		closeMaskDiv();
		appDisabled=false;
                var timerObj = document.getElementById('animTimer'); 
                if(timerObj) 
                    timerObj.style.display = 'none'; 
}

//	function: getViewportHeight
//		Gets and returns the height of the screen.
//	Usage: 
//		getViewportHeight()
//	Parameters:
//		None
//	Returns: 
//		Returns the height of the screen.

function getViewportHeight() {
	if (document.body) { 
		var h = (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
                h = (document.documentElement.clientHeight > h) ? document.documentElement.clientHeight : h;
		return h;
	} else {
                var h = window.innerHeight;
                return h;
	}
	return window.undefined;
}

//	function: getViewportWidth
//		Returns the width of the screen.
//	Usage: 
//		getViewportWidth()
//	Parameters:
//		None
//	Returns: 
//		Returns the width of the screen.
	
function getViewportWidth() {
	if (document.body) { 
		var w = (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
                w = (document.documentElement.clientWidth > w) ? document.documentElement.clientWidth : w;
		return w;
	} else {
                var w = window.innerWidth;
                return w;
        }
	return window.undefined;
}

//	function: openMaskDiv
//		Disables the screen by putting a div tag over it .
//	Usage: 
//		openMaskDiv()
//	Parameters:
//		sdim = determines if the background is dimmed or transparent
//	Returns: 
//		None
		
function openMaskDiv(sdim) {
		gPopupMask = document.getElementById("popupMask");
		if(gPopupMask==null){
                     document.body.insertAdjacentHTML('beforeEnd','<div id="popupMask" style="display:none;"><img src="/support/images/spacer.gif"></div>');
                    gPopupMask = document.getElementById("popupMask");
                    //addEvent(window, "resize", openMaskDiv);
		}
                if(sdim) {
                    gPopupMask.style.backgroundColor = "#c0c0c0";
                    if(document.getElementById('contentview:fileExchangeBodyView:fileExchangeForm:sitesTable-nb')) {
                    	document.getElementById('contentview:fileExchangeBodyView:fileExchangeForm:sitesTable-nb').style.visibility='hidden';
                    }
                    hideCat();
                }
                else
                    gPopupMask.style.backgroundColor = "transparent";
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		var theBody = document.documentElement;
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.height = fullHeight + "px";
		gPopupMask.style.width = fullWidth + "px";
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
                gPopupMask.style.position="absolute";
                gPopupImage = gPopupMask.firstChild;
                if(gPopupImage) {
                    gPopupImage.style.height = fullHeight + "px";
                    gPopupImage.style.width = fullWidth + "px";
                }
		gPopupMask.style.display = "block";
}

//	function: closeMaskDiv
//		Enables the creen if it was disabled by hidding div tag over it .
//	Usage: 
//		closeMaskDiv()
//	Parameters:
//		None
//	Returns: 
//		None

function closeMaskDiv() {
	gPopupMask = document.getElementById("popupMask");
		if(gPopupMask!=null)
			gPopupMask.style.display = "none";
                    if(document.getElementById('contentview:fileExchangeBodyView:fileExchangeForm:sitesTable-nb'))
                    	document.getElementById('contentview:fileExchangeBodyView:fileExchangeForm:sitesTable-nb').style.visibility='visible';
                    showCat();
        //removeEvent(window, "resize", openMaskDiv);
}

//	function: addEvent
//		Attach an event to the specified object
//	Usage: 
//		addEvent(obj, evType, fn)
//	Parameters:
//		obj - the object to attach event to
//		evType - name of the event - DONT ADD "on", pass only "mouseover", etc
//		fn - function to call
//	Returns: 
//		None
		
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}

//	function: removeEvent
//		detach an event to the specified object
//	Usage: 
//		removeEvent(obj, evType, fn)
//	Parameters:
//		obj - the object to attach event to
//		evType - name of the event - DONT ADD "on", pass only "mouseover", etc
//		fn - function to call
//	Returns: 
//		None
		
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()

if(typeof HTMLElement!="undefined") {
    if(!HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)
                            this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
            }
	}

    if(!HTMLElement.prototype.insertAdjacentHTML){
	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}
    }

    if(!HTMLElement.prototype.insertAdjacentText){
	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
    }
}



function deactivateProgressIndicators(closeWhenComplete)
{

  if (_pollManager)
  {
    if (document.getElementById('keepAliveView:keepAliveForm:fileUploadStatus').value=="noUpload")
    {
      _pollManager.deactivateAll();
      if(closeWhenComplete)
        window.close();
    }
  } else if(!_pollManager.active)
    reactivateProgressIndicators();
}

function reactivateProgressIndicators()
{

  if (_pollManager)
  {
    _pollManager.reactivateAll();
  }
}


// Typo3 Code
var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var version="";var msie4=(browserName=="Microsoft Internet Explorer"&&browserVer>=4);if((browserName=="Netscape"&&browserVer>=3)||msie4||browserName=="Konqueror"||browserName=="Opera"){version="n3";}else{version="n2";}
function blurLink(theObject){if(msie4){theObject.blur();}}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,-2);}