var objPopUp = null;
var popupCancel = false;
var cancelMaterialCompExport = false;

function popupData(objectID)
{
  if (popupCancel) {
  	popupCancel=false;
  	return;
  }
  if (objPopUp!=null) {
  	return;
  }
  objPopUp = document.getElementById(objectID);
  if (objPopUp==null) {
  	return;
  }
  var xPos = xMousePos + 5;
  var yPos = yMousePos;
  var popupCoords = getCoords(objPopUp);
  if (xPos + objPopUp.clientWidth > document.documentElement.clientWidth)
    xPos = document.documentElement.clientWidth - objPopUp.clientWidth - 10;  
  xPos += document.documentElement.scrollLeft;    
  if (yPos + objPopUp.clientHeight > document.documentElement.clientHeight)
    yPos = document.documentElement.clientHeight - objPopUp.clientHeight - 10;  
  yPos += document.documentElement.scrollTop;
  yPos -= popupCoords.height + 5;
  objPopUp.style.left = xPos + 'px';
  objPopUp.style.top = yPos + 'px';
  objPopUp.style.visibility = 'visible';
}

function popHide() {
  if (objPopUp != null) {
    objPopUp.style.visibility = 'hidden';
    objPopUp = null;
  }
}

function popupBlock(objectID)
{
  objPopUp = document.getElementById(objectID);
  if (objPopUp==null) {
  	return;
  }
  objPopUp.style.display = 'block';
}

function hideBlock(objectID)
{
  objPopUp = document.getElementById(objectID);
  if (objPopUp==null) {
  	return;
  }
  objPopUp.style.display = 'none';
}

function partListRowOver(rowid)
{
//   origClass = document.getElementById(rowid).className;
   appendClass(document.getElementById(rowid),"listItemOver");   
}

function tableTwoRowOver(rowid)
{
//   origClass = document.getElementById(rowid).className;
   appendClass(document.getElementById(rowid),"listItemOver");  
   appendClass(document.getElementById(rowid + "_2"),"listItemOver");   
}

function partListRowOut(rowid)
{
//   document.getElementById(rowid).className= origClass;
	switchClass(document.getElementById(rowid),"listItemOver","");  
}

function tableTwoRowOut(rowid)
{
//   document.getElementById(rowid).className= origClass;
//   document.getElementById(rowid + "_2").className= origClass;
	switchClass(document.getElementById(rowid),"listItemOver","");  
	switchClass(document.getElementById(rowid + "_2"),"listItemOver","");  
}

function processAction(action, actionData)
{
  document.forms["fState"].elements["action"].value = action;
  document.forms["fState"].elements["actionData"].value = actionData;
  document.forms["fState"].submit();
}

function popupText(text, displayDivId)
{
  if (popupCancel) {
  	popupCancel=false;
  	return;
  }
  objPopUp = document.getElementById(displayDivId);
  objPopUp.innerHTML = text;
  objPopUp = null;
  popupData(displayDivId);
}

function navigateIframe(iframeName, selectName)
{
  iframe = document.getElementById(iframeName);
  select = document.getElementById(selectName);
  iframe.src = select.options[select.selectedIndex].value;
}

function cancelPopup() {
	popupCancel=true;
}

var checkFulltext = true;

function pollFulltext(keyword) {
	myIframe = document.getElementById("buffer");
	menuTarget = parent.document.getElementById("fulltext");
	//alert("Keyword: " + keyword);
	
	myIframe.src = "/PowerSolutions/fulltextStatus.do?searchKey="+keyword;
	//alert("Getting there");
	st = myIframe.contentWindow.document.body.innerHTML; //document.getElementById("status").innerHTML;
	//alert("Status extracted: " + st);

	if (st.indexOf("progress") == -1 && st != "") {
		//alert("Setting menu: " + status);
		if (menuTarget != null) {
			menuTarget.innerHTML = st;
			alert("loading fulltext");
			fulltextFrame = document.getElementById("fulltextFrame");
			if (fulltextFrame != null)
				fulltextFrame.src = "/PowerSolutions/home.do"; //"javascript:processAction('reloadFulltext','')";
			else
				alert("Cannot load Fulltext Frame");
		} else {
			//alert("Menu Target is null");
		}
		checkFulltext = false;
	}
}

function timerStart(keyword) {
	pollFulltext(keyword);
	//alert("Check Fulltext: " + checkFulltext);
	if (checkFulltext) {
		//alert("Setting another run");
		self.setTimeout('timerStart("'+keyword+'")', 2000);
	} else {
		//alert("No other run");
	}
}

function cancelExport() {
	cancelMaterialCompExport = true;
}

function materialCompExport(opnId) {
	if (cancelMaterialCompExport) {
		cancelMaterialCompExport = false;
		return;
	}
	var exportType = document.getElementById("additionalData");
	if (exportType!=null) {
			window.location='/PowerSolutions/MaterialComposition.do?export=' + exportType.value + '&opnId=' + opnId;
			return;
	}
}

function saveExportType(element) {
	var exportType = document.getElementById("additionalData");
	if (exportType!=null) {
		exportType.value = element.value;
	}
}



