var browserIsSafari  = (navigator.userAgent.indexOf('Safari') != -1);
var browserIsIE  = (navigator.userAgent.indexOf('MSIE') != -1);



function removeHTMLTags(){
 	for(var i =0; document.getElementsByName("htmlSummary")!= null && i < document.getElementsByName("htmlSummary").length; i++) {
 		document.getElementsByName("htmlSummary")[i].innerHTML = document.getElementsByName("htmlSummary")[i].innerHTML.replace(/<\/?[^>]+(>|$)/g, "");
 		if(document.getElementsByName("htmlSummary")[i].innerHTML.length > 400) {
 			document.getElementsByName("htmlSummary")[i].innerHTML = document.getElementsByName("htmlSummary")[i].innerHTML.substring(0, 400).concat("...");
 		}
	}
}

function openSearchWindow(url, theKey,height,width) {
		if(height == '') height = '600';
		if(width == '') width = '800';
		window.open(url,theKey,'width=' + width + ',height=' + height + ',scrollbars=yes,status=yes,resizable=yes,top=20,left=20');
}

function openWindow(url, theKey,height,width) {
		if(height == '') height = '600';
		if(width == '') width = '800';
		window.open(url,theKey,'width=' + width + ',height=' + height + ',scrollbars=yes,status=no,resizable=yes,top=20,left=20');
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function sL(level,layerName){
	for(var i=1;i<=30;i++){
		if('submenu'+i != layerName){
			hL(i,'submenu'+i);
		}
	}
	if(document.getElementById(layerName)) {
		if(document.getElementById(layerName).style.display == 'block'){
			hL(level,layerName);
		}else{
			document.getElementById(layerName).style.display="block";
			img = document.getElementById("img-"+level);
			img.src = img.getAttribute("path") + '/d_menu_arrow.gif';
			img.alt = "Click to hide";
			//firefox title
			img.title = "Click to hide";
		}
	}
}

function hL(level, layerName){
	if(document.getElementById(layerName)){
		document.getElementById(layerName).style.display="none";
	}
	
	if(document.getElementById("img-"+level)) {
			img = document.getElementById("img-"+level)
			img.src = img.getAttribute("path") + '/menu_arrow.gif';
			img.alt = "Click to expand";
			//firefox title
			img.title = "Click to expand";
	}
}


function AF_detectMSOfficeLink(link) {
	var ext = link.href.substring(link.href.lastIndexOf('.')+1).toLowerCase();
	var oleProgId = null;
	var openByObject = null;
	var canActivate = false;
	switch (ext) {
		case 'doc':
			oleProgId = 'Word.Application';
			openByObj = 'Documents';
			canActivate = true;
                        break;
		case 'ppt':
			oleProgId = 'PowerPoint.Application';
			openByObj = 'Presentations';
			canActivate = true;
                        break;
		case 'xls':
			oleProgId = 'Excel.Application';
			openByObj = 'Workbooks';
                        break;
		case 'mpp':
			oleProgId = 'Project.Application';
			openByObj = 'Projects';	
                        break;
	}	

	if (oleProgId != null) {
		try {
			var appObj = new ActiveXObject(oleProgId);
			if (appObj != null) {
                appObj.visible=true;
				if (canActivate)
					appObj.Activate();
                openByObj = eval('appObj.'+openByObj);
				openByObj.Open(link.href);
				appObj.visible=true;
				
				return false;
			}
		} catch (e) {  
			if (appObj != null) {
				try {
					appObj.Quit();
				} catch (e) { /* Empty */ }
			}
			/* alert(oleProgId +' '+ e.message  ); */
		}
	}
    return true;
}


function historyBack(portlet,url, isMaximised) {
		//alert(portlet+" "+url+" "+isMaximised);
		
		// Portlet is maximised, a back should be window.reload() to get the last page state.
		if(isMaximised) {
			window.location = window.location;
			return false;
		}
		
		else if (portlet != null && url != null && url != "") portlet.openUrl(url,"",false);
		else history.back();
		return false;
}





// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
         //measure the html element's clientWidth
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
	
    return 0;
}

// Return the available content height space in browser window
function getInsideWindowHeight( ) {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}
