var oPriorItem;
var productSelected;
var querybuilderwindow = null;

function openAdhoc(oClickedItem) {

	var queryHeight;	// Height of Ad Hoc Query window in pixels.
	var queryWidth;	// Width of Ad Hoc Query window in pixels.
	var scrollBars;	// 'no' for screen sizes 1024 X 768 and greater

	if (oPriorItem != null) {
		oPriorItem.className = "clsNotSelected";
	}
	if (oClickedItem.className=="clsNotSelectedHover") {
		oClickedItem.className="clsSelectedHover";
	}
	else {
		oClickedItem.className="clsSelected";
	}
   window.status = "Query Builder is loading. . . . Please wait. . . .";

   // Use the existing screen dimensions minus a bit for Query Builder
   queryHeight = window.screen.height - 78;
   queryWidth = window.screen.width - 14;
   scrollBars = "no";

   // Scroll bars are needed for any screen size less than 1024 X 768
   if (queryHeight < 768) {
		scrollBars = "yes";
	}
   if (querybuilderwindow == null) {
   querybuilderwindow = window.open("gateway.jsp?method=crmsahqinit", "_blank", "height="
			+ queryHeight + ",width=" + queryWidth + ",scrollbars=" +  scrollBars
			+ ",left=0,top=0,resizable=yes,status=yes,toolbar=no,menubar=no,location=no");
	//window.status = "Query Builder has been loaded.";
    querybuilderwindow.focus();
   } else {
     try {
     querybuilderwindow.focus();
     } catch (e) {
   querybuilderwindow = window.open("gateway.jsp?method=crmsahqinit", "_blank", "height="
			+ queryHeight + ",width=" + queryWidth + ",scrollbars=" +  scrollBars
			+ ",left=0,top=0,resizable=yes,status=yes,toolbar=no,menubar=no,location=no");
	//window.status = "Query Builder has been loaded.";
    querybuilderwindow.focus();
     }
   }
	return false;
}

function changeTab(oClickedItem) {
	if (oPriorItem != null) {
		oPriorItem.className = "clsNotSelected";
	}

	if (oClickedItem.className=="clsNotSelectedHover") {
		oClickedItem.className="clsSelectedHover";
	}
	else {
		oClickedItem.className="clsSelected";
	}
	oPriorItem = oClickedItem;
}

function onClick(oClickedItem) {
        productSelected = oClickedItem.id;
	if (oPriorItem != null) {
		oPriorItem.className = "clsNotSelected";
	}

	if (oClickedItem.className=="clsNotSelectedHover") {
		oClickedItem.className="clsSelectedHover";
	}
	else {
		oClickedItem.className="clsSelected";
	}

//	top.setTitle(oClickedItem.innerText);


//alert(top.frames(1).name);
	if (oClickedItem.target=="top") {
		top.location.href=oClickedItem.href;
	}
	else {
		try {
			top.frames(oClickedItem.target).location.href=oClickedItem.href;
		} catch (e) {
//			top.frames("BODY").location.href="home.jsp";
		}
	}

	oPriorItem = oClickedItem;
}

function onMouseOver(oItem)
{
	if (oItem.className=="clsSelected") {
		oItem.className="clsSelectedHover";
	}
	else {
		oItem.className="clsNotSelectedHover";
	}
}

function onMouseOut(oItem)
{
	if (oItem.className=="clsSelectedHover") {
		oItem.className="clsSelected";
	}
	else {
		oItem.className="clsNotSelected";
	}
}

	var sTitle = "";	// Must initialize to blank
	var readyState;	// Current state of title bar

	function setTitle(sTitle) {
		this.sTitle = sTitle;
		readyState = top.frames("title").document.readyState;
		//alert("readyState is: '" + readyState + "'");
		//alert("sTitle is '" + sTitle + "'");

		if ((readyState == "complete") || (readyState == "interactive")) {
			top.frames("title").setTitle(sTitle);
		}
	}

	function getTitle() {
		//if (top.frames("center").document.readyState == "complete") {
			return sTitle;		// State is 'loading' at this point
		//}
		//else {
		//	return "";
		//}
	}


   var currentMethod = "none";
   var currentHelpPage = "Common5/co_home_page.htm"; // If set, this overrides currentMethod

   // setTitle is called by header.inc to set the current title.
   
   var tdTitle="IN IT TITLE";
   function setTitle(sTitle) {
		tdTitle.innerText = sTitle;
	}

   // setCurrentMethod is called by header.inc for help page retrieval.
	function setCurrentMethod(method) {
      currentMethod = method;
      currentHelpPage = "";   // Suppress previously specified help page
	}

   // setCurrentHelpPage is called by non-gateway JSPs.
   function setCurrentHelpPage(helpPage) {
      currentHelpPage = helpPage;
   }

	function showHelp() {

      if (currentHelpPage != "") {  // If help page specified explicitly
         var helpwindow = window.open("../html/help/helpset.htm#" + currentHelpPage, "help", "height=500"
               + ",width=600" + ",left=413, top=0,resizable=yes,status=yes,toolbar=yes,"
               + "menubar=yes,location=no");
         helpwindow.focus();
      }
      else {   // Show help page for the current method (rarely used)

         var helpwindow = window.open("../jsp/gateway.jsp?method=help-page&method-name="
               + currentMethod, "help", "height=600"
               + ",width=500" + ",left=500, top=0,resizable=yes,status=yes,toolbar=yes,"
               + "menubar=yes,location=no,scrollbars=yes");
         helpwindow.focus();
      }

	}

	function openUserMessages() {
		var args = new Array();
		args[0] = "Message Viewer";
		args[1] = window;
		//var messageIds = window.showModalDialog("../jsp/gateway.jsp?method=crmsgum","Message Viewer","dialogHeight:290px; dialogWidth: 500px; dialogTop: 200px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		var messageIds = window.showModalDialog("../jsp/gateway.jsp?method=crmsgum",args,"dialogHeight:290px; dialogWidth: 500px; dialogTop: 200px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		if (messageIds != null && messageIds != "") {
			document.frames("msgCheck").location.href = "../jsp/gateway.jsp?method=crmsrum&messageIds=" + messageIds;
		}
	}

	function showIcon(msg) {
		var date = new Date();
		//alert( "Time: " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "--" + msg );
		if( msg != null && msg != "" ) {
			document.images("msgReminder").style.display="block";
		} else {
			document.images("msgReminder").style.display="none";
		}
	}

