function showDiv(id) {
	if(document.getElementById(id)) document.getElementById(id).style.display='block';
}

function hideDiv(id) {
	if(document.getElementById(id)) document.getElementById(id).style.display='none';
}

function selMenuItem(id) {
	if(document.getElementById(id)) document.getElementById(id).style.backgroundColor='#e8d4b9';
}

function deselMenuItem(id) {
	if(document.getElementById(id)) document.getElementById(id).style.backgroundColor='';
}

function mapSubtree(imEl,divElStr) {
	if(document.getElementById(divElStr)) {
		if(document.getElementById(divElStr).style.display=='none') {
			document.getElementById(divElStr).style.display='block';
			imEl.src='images/minus.gif';
		}
		else if(document.getElementById(divElStr).style.display=='block') {
			document.getElementById(divElStr).style.display='none';
			imEl.src='images/plus.gif';
		}
	}
}

function detectIE6() {
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer"){
		var b_version = navigator.appVersion;
		var re = /\MSIE\s+(\d\.\d\b)/;
		var res = b_version.match(re);
		if(res[1]<=6){
			return true;
		}
	}
	return false;
}

function swapDisplayProperty(divElStr) {
	if(document.getElementById(divElStr)) {
		if(document.getElementById(divElStr).style.display=='none') {
			document.getElementById(divElStr).style.display='block';
			if(document.getElementById('img_'+divElStr)) document.getElementById('img_'+divElStr).src='images/minus.gif';
		}
		else if(document.getElementById(divElStr).style.display=='block') {
			document.getElementById(divElStr).style.display='none';
			if(document.getElementById('img_'+divElStr)) document.getElementById('img_'+divElStr).src='images/plus.gif';
		}
	}
}

function mapTreeRevealAll() {
	var a=document.getElementsByTagName('table');
	var imTdEl;
	
	for(var i=0;i<a.length;i++) {
		if(a[i].id.match(/^mapSubtree/)) {
			imTdEl=a[i].parentNode.previousSibling;
			while(imTdEl.nodeType!=1 && imTdEl.previousSibling) {
				imTdEl=imTdEl.previousSibling;
			}
			if(imTdEl.nodeType==1 && imTdEl.hasChildNodes()) {
				imTdEl=imTdEl.firstChild;
				while(!imTdEl.src && imTdEl.nextSibling) {
					imTdEl=imTdEl.nextSibling;
				}
				if(imTdEl.src) {
					a[i].style.display='block';
					imTdEl.src='images/minus.gif';
				}
			}
		}
	}
}

function mapTreeCollapseAll() {
	var a=document.getElementsByTagName('table');
	var imTdEl;
	
	for(var i=0;i<a.length;i++) {
		if(a[i].id.match(/^mapSubtree/)) {
			imTdEl=a[i].parentNode.previousSibling;
			while(imTdEl.nodeType!=1 && imTdEl.previousSibling) {
				imTdEl=imTdEl.previousSibling;
			}
			if(imTdEl.nodeType==1 && imTdEl.hasChildNodes()) {
				imTdEl=imTdEl.firstChild;
				while(!imTdEl.src && imTdEl.nextSibling) {
					imTdEl=imTdEl.nextSibling;
				}
				if(imTdEl.src) {
					a[i].style.display='none';
					imTdEl.src='images/plus.gif';
				}
			}
		}
	}
}

function getClientWidth()
{
  //return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	var a = document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	return parseInt(a);
}

function getClientHeight()
{
  //return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	var a = document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;
	return parseInt(a);
}

function getBodyScrollTop()
{
  var a = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
  return parseInt(a);
}

function getBodyScrollLeft()
{
  var a = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
  return parseInt(a);
}

function showTooltip(event,insText) {
	var ttObj = document.getElementById('divTooltip');
	if(ttObj) {
		if(arguments[2]) var w=arguments[2]; else w=250;
		if(arguments[3]) var h=arguments[3];
		if(typeof w == 'number') ttObj.style.width=w+'px';
		if(typeof h == 'number') ttObj.style.height=h+'px';
		ttObj.style.overflow='hidden';
		ttObj.innerHTML=insText;
		ttObj.style.left='-1000px';
		ttObj.style.top='-1000px';
		ttObj.style.display='block';
		repositionElement(event,ttObj);
	}
}

function hideTooltip() {
	var ttObj = document.getElementById('divTooltip');
	if(ttObj) {
		ttObj.style.display='none';
		ttObj.innerHTML='';
	}
}

function moveTooltip(event) {
	var ttObj = document.getElementById('divTooltip');
	repositionElement(event,ttObj);
	
}

function showPopup() {
	var popupDivB=document.getElementById('divFSPopupBottom');
	var popupDivT=document.getElementById('divFSPopupTop');
	if(popupDivB && popupDivT) {
		popupDivB.style.display='block';
		popupDivT.style.display='block';
		repositionPopups();
	}
}

function hidePopupDiv() {
	var popupDivB=document.getElementById('divFSPopupBottom');
	var popupDivT=document.getElementById('divFSPopupTop');
	if(popupDivB && popupDivT) {
		popupDivB.style.display='none';
		popupDivT.style.display='none';
		popupDivT.innerHTML='';
	}
	var sdpPopup=document.getElementById('divSDPSelect');
	if(sdpPopup) {
		sdpPopup.style.display='none';
	}
}

function repositionPopups() {
	var popupDivB=document.getElementById('divFSPopupBottom');
	var popupDivT=document.getElementById('divFSPopupTop');
	var browserW=getClientWidth();
	var browserH=getClientHeight();
	if(popupDivB && popupDivB.style.display=='block') {
		popupDivB.style.width=browserW+'px';
		popupDivB.style.height=browserH+'px';
	}
	if(popupDivT && popupDivT.style.display=='block') {
		if(popupDivT.offsetWidth+40<browserW) popupDivT.style.left=parseInt((browserW-popupDivT.offsetWidth)/2)+20+getBodyScrollLeft()+'px';
		else popupDivT.style.left=20+getBodyScrollLeft()+'px';
		if(popupDivT.offsetHeight+40<browserH) popupDivT.style.top=parseInt((browserH-popupDivT.offsetHeight)/2)+20+getBodyScrollTop()+'px';
		else popupDivT.style.top=20+getBodyScrollTop()+'px';
	}
	var sdpPopup=document.getElementById('divSDPSelect');
	if(sdpPopup && sdpPopup.style.display=='block') {
		if(sdpPopup.offsetWidth+40<browserW) sdpPopup.style.left=parseInt((browserW-sdpPopup.offsetWidth)/2)+20+getBodyScrollLeft()+'px';
		else sdpPopup.style.left=20+getBodyScrollLeft()+'px';
		if(sdpPopup.offsetHeight+40<browserH) sdpPopup.style.top=parseInt((browserH-sdpPopup.offsetHeight)/2)+20+getBodyScrollTop()+'px';
		else sdpPopup.style.top=20+getBodyScrollTop()+'px';
	}
}

function resizePopup() {
	var popupDivB=document.getElementById('divFSPopupBottom');
	var popupDivT=document.getElementById('divFSPopupTop');
	if(popupDivB && popupDivT) {
		popupDivB.style.width=getClientWidth()+'px';
		popupDivB.style.height=getClientHeight()+'px';
	}
}

function trSelected(trObj) {
	if(trObj.hasChildNodes()) {
		for(i=0;i<trObj.childNodes.length;i++) {
			if(trObj.childNodes[i].nodeType==1) {
				trObj.childNodes[i].style.backgroundColor='#fdf5e9';
			}
		}
	}
}

function trUnselected(trObj) {
	if(trObj.hasChildNodes()) {
		for(i=0;i<trObj.childNodes.length;i++) {
			if(trObj.childNodes[i].nodeType==1) {
				trObj.childNodes[i].style.backgroundColor='#ffffff';
			}
		}
	}
}

function appendNewFileInput(tblId) {
	if(document.getElementById(tblId) && document.getElementById('img_count')) {
		var tblObj=document.getElementById(tblId);
		var newTr=document.createElement('tr');
		var newTd=document.createElement('td');
		var newInput=document.createElement('input');
		newTr.setAttribute('id','imgFileInput'+(parseInt(document.getElementById('img_count').value)+1));
		newInput.setAttribute('type','file');
		newInput.setAttribute('size','90');
		newInput.setAttribute('id','prPhoto'+(parseInt(document.getElementById('img_count').value)+1));
		newInput.setAttribute('name','prPhoto'+(parseInt(document.getElementById('img_count').value)+1));
		newTd.appendChild(newInput);
		newTr.appendChild(newTd);
		if(tblObj.hasChildNodes()) {
			var tbodyEl=tblObj.firstChild;
			while(tbodyEl.nodeType!=1 && (tbodyEl.nodeName!='TBODY' || tbodyEl.nodeName!='tbody') && tbodyEl.nextSibling) {
				tbodyEl=tbodyEl.nextSibling;
			}
			if(tbodyEl.nodeType==1 && (tbodyEl.nodeName=='TBODY' || tbodyEl.nodeName=='tbody')) {
				tbodyEl.appendChild(newTr);
			}
			else {
				tblObj.appendChild(newTr);
			}
		}
		else {
			tblObj.appendChild(newTr);
		}
		document.getElementById('img_count').value=parseInt(document.getElementById('img_count').value)+1;
	}
}