<!--
/* ********************************************************************************* 
   COPYRIGHT('(C) CMS MANUFACTURING SYSTEMS INC. - 1993, 1997')
   File Name:  CMSEasy_navigation.js                                                          
   Description:  This script will control the navigation for the CMSEasy pages.
  
   Insturctions:
   1) Include this script in all of the CMSEasy-Main HTML documents.
      script language="JavaScript" src="/script/CMSEasy_navigation.js"
  
   _________________________________________________________________________________ 
   Modification History:                                                             
   2001-04-16  Michael Victor    Created script                             
   2001-06-01  Michael Victor    Added EZ018-Shipping Schedules 
   2001-06-01  Michael Victor    Added EZ020-Order Entry 
   2001-08-20  Michael Victor    The Navigation, PageContents and Footer divisions,
                                 are now written using document.writeln, instead of
                                 using the .innerHTML methods.  (this should resolve
                                 the header section expanding and contracting when
                                 rendering the page)
   2001-10-19  Michael Victor    /M05 Fixed sizing of the navigation buttons 
   2001-10-23  Michael Victor    /M06 Added EZ036-ASN
   2001-12-11  Michael Victor    /M07 Added support for new sales rep user type ('4')
                                      and brokers ('5')
   2002-03-27  Michael Victor    /M08 Place the URL for the portal & main signon in
                                      variables.  Note the hard-coded ip has been 
                                      removed from the url as a relative refernce 
                                      will work.
   2002-05-28  Michael Victor    Release 2.0 mods
   2002-06-26  Michael Victor    /M10 Mods to handle the new select user for
                                 sales reps and brokers
   2003-03-11  Michael Victor    /M11 Added EZ042-PO Inquiry
   2006-05-08  HW                /101 add EZ048 (register warranty product)
   2006-06-06  HW                /102 do not show 'Main Signon' for generic consumer
   2007-03-07  HCT               Added EZ051 (supplier inventory inquiry)
   2010-06-14  HCT               added sessionId
   2010-06-14  HCT               added userName, 
   							     removed user, ACTID, ACTUSER from form
   2010-06-28  HCT   			 added sign off button when active session exists -
                                  replaced signon screen. 	     
   2010-07-05  HCT   			 added EZ060 = change plants for remote user                              
   2010-10-13  Helen Wen Added netLocation
   2010-10-28  JB                added .. prefix to relative paths
   2010-11-15  Michael Victor    Modifications for non IE browser support.  Navigations links are
                                 now displayed as a <UL>.
   2010-11-25  Michael Victor   Changed .navTabLink to .navAnchor.  Applied .navAnchor to anchors that are part of the navigation.
   2010-12-07  HCT              re-added welcome username message
   2011-03-02  YZ               add EZ063-Customer Reports & EZ064-Receipt History
   2011-08-15  DC               add EZ072-Price & Availability (CP03040)
   2011-10-05  IAMIN - Disable navAnchors on mutiple clicks, so it does not make more than one request to server.
  *********************************************************************************  */
   
/* /M08 navigation values */
portalURL     = '../net/ez001'
mainSignonURL = "parent.location='../net/ez001'"

var netLocation = '../net'

/* prefetch image */
var procImage = new Image();
procImage.src = "../gifs/processing.gif";

/* supplier programs */
var EZ003="N"
var EZ011="N"
var EZ018="N"
var EZ036="N" /* /M06 */
var EZ042="N" /* /M11 */
var EZ051="N"

/* customer programs */
var EZ013="N"
var EZ014="N"
var EZ015="N"
var EZ016="N"
var EZ017="N"
var EZ020="N"
var EZ063="N"
var EZ064="N"
var EZ072="N"  //3040

/* /M07 Sales Rep programs, in addition to thes pgms, the customer programs will also be made available */
var EZ039="N"

/* admin programs */
var EZ009="N"
var EZ010="N"

/* /101 generic consumer programs */
var EZ048="N"

/* general programs */
var EZ004="N"
var EZ025="N"
var EZ060="N"

var user = ""
var userName = ""
var sessionId = ""
var userType=""
var lng  = ""
var XXSLIB =""
var XXACTID ="" /* /M07 variable to hold the selected customer */
var XXACTUSER ="" /* /M10 variable to hold the selected user */
var XXVERS = ""
var newline = "\n"
var navigationHtml = ""
var welcomeMsg = ""

function setUser(xxuser)
{
	user=xxuser
}

function setUserName(value)
{
	userName=value
}

function setSession(xxsesId)
{
	sessionId=xxsesId
}

function setUserType(value)
{
	userType=value
}
function setLng(xxlng)
{
	lng=xxlng
}

function setXXSLIB(value)
{
	XXSLIB=value
}

/* /M07 */
function setXXACTID(value)
{
	XXACTID=value
}

/* /M10 */
function setXXACTUSER(value)
{
	XXACTUSER=value
}


/* set Location */
function setlocation(location)
{
	netLocation = location
}


function callPgm(pgm)
{
	nForm = document.navForm
	nForm.XXACTN.value = pgm
	nForm.submit()
}

function enablePgm(pgm)
{	
	switch (pgm)
	{
	case 'EZ003':
		EZ003 = 'Y'
		break

	case 'EZ004':
		EZ004 = 'Y'
		break
	
	case 'EZ009':
		EZ009 = 'Y'
		break
		
	case 'EZ010':
		EZ010 = 'Y'
		break
		
	case 'EZ011':
		EZ011 = 'Y'
		break
		
	case 'EZ013':
		EZ013 = 'Y'
		break
		
	case 'EZ014':
		EZ014 = 'Y'
		break
		
	case 'EZ015':
		EZ015 = 'Y'
		break
		
	case 'EZ016':
		EZ016 = 'Y'
		break
		
	case 'EZ017':
		EZ017 = 'Y'
		break
		
	case 'EZ018':
		EZ018 = 'Y'
		break
	
	case 'EZ020':
		EZ020 = 'Y'
		break
		
	case 'EZ025':
		EZ025 = 'Y'
		break
		
	/* /M06 */	
	case 'EZ036':
		EZ036 = 'Y'
		break
	
	/* /M07 */	
	case 'EZ039':
		EZ039 = 'Y'
		break
		
	/* /M11 */	
	case 'EZ042':
		EZ042 = 'Y'
		break

	/* /101 */
	case 'EZ048':
		EZ048 = 'Y'
		break

	case 'EZ051':
		EZ051 = 'Y'
		break
		
	case 'EZ060':
		EZ060 = 'Y'
		break	

	case 'EZ063':
		EZ063 = 'Y'
		break	

	case 'EZ064':
		EZ064 = 'Y'
		break

	//3040 BEGIN
	case 'EZ072':
		EZ072 = 'Y'
		break
	//3040 END
		
	}
}



function crtNavButton(type, action, altText)
{
	var classId="" /* /M05 */
	var overClassId =""
    var navSrc = "";
    var anchor = ""

	if (type == 'S') /* submit button */
	{
		/* /M05 if the button is for contact us or change password, then it's in
		   the link section of the navigation, and therefore it's height is different,
		   use the appropriate class name */
		if (action=='EZ025' || action=='EZ004' || action=='EZ059' || action=='EZ060')
		{
			classId="navlink2"
		}
		else
		{
			classId="navlink"
		}
		overClassId = classId + '_over'
		
		
        anchor = '<a class="navAnchor"'
		
		if (action != null)
		{
            anchor += 'onClick="callPgm(' + "'" + action + "'" + ')" '
		}
		
        anchor += '>' + altText + '</a>' + newline
        navSrc = '<li ' + buttonClasses(classId, overClassId) + '>' + anchor + '</li>'
	navigationHtml += navSrc;
	}
	
	if (type == 'L' && action != ' ')
	{
		classId="navlink2"
		overClassId = classId + '_over'
		
        anchor += '<a class="navAnchor" onClick="' + action + '">' + altText + '</a>' + newline
        navSrc = '<li ' + buttonClasses(classId, overClassId) + '>' + anchor + '</li>'
	navigationHtml += navSrc;

	}
		
}

function buttonClasses(dftClass, overClass)
{
	var btnClasses =	
			'class="' + dftClass + '" '
		+	'onMouseOver="this.className=' + "'" + overClass + "'" + '" '  
		+	'onMouseOut="this.className='  + "'" + dftClass  + "'" + '" '
	return(btnClasses)
}

function popHeader()
{
	document.title="Easy e-business Suite"
	
	if (userType != '6' && userName != '')
	{
   	welcomeMsg = '<div><br />Welcome ' + userName + '<br /></div>' + newline
	}
	
	navigationHtml =
		  '<div class="Navigation" id="navigation">' + newline
		+ ' <form name="navForm" class="NavForm" action="' + netLocation +'/EZ006" method="post" target="_parent">' + newline
		+ '  <input type="hidden" name="XXSESID" value="' + sessionId + '"></input>' + newline
   	+ '  <input type="hidden" name="XXLNG"  value="' + lng  + '"></input>' + newline
   	+ '  <input type="hidden" name="XXACTN"  value=""></input>' + newline
 
   	
   	navigationHtml +=
   			'<img border="0" src="../gifs/companyhead.gif" width="460" height="70" alt="comphead"></img>' + newline
   		+	'<img border="0" src="../gifs/spacer.gif" style="width:28px, height:45px; position:absolute; top:15px; left:597px" alt="spacer" style="vertical-align:top"></img>' + newline
   	// Create a div section to hold the main signon, change password and contact us links
   		+	'<div id="generalLinks" class="generalLinks">' + newline 
    + '<ul>' + newline

	// 102 do not show main signon button for generic consumer or if already signed on
	if (userType != '6' && sessionId == '')
	{
   	crtNavButton('L', mainSignonURL, 'Main Signon')
	}
	
   	if (userType != '6' && sessionId != '')
	{
   	crtNavButton('S', 'EZ059', 'Sign Off')
	}	
	
   	if (EZ004=='Y')
   	{
   		crtNavButton('S', 'EZ004', 'Change Password')
   	}
	
		if (EZ025=='Y')
   	{
   		crtNavButton('S', 'EZ025', 'Contact Us')
   	}
   	
   	if (EZ060=='Y')
  	{
  		crtNavButton('S', 'EZ060', 'Change Plant')
  	}
  		
				
    navigationHtml += '</ul></div>' + newline + welcomeMsg 
		// Create a div section to hold the navigation row
    + '<div id="navRow" class="navRow"><ul>' + newline
	
	
	switch (userType)
	{
		case '1':
			supplierNavigation()
			break
			
		case '2':
			adminNavigation()
			break
		
		case '3':
			customerNavigation()
			break
		
		case '4': /* /M07 handle salesrep type */
			salesrepNavigation()
			break
			
		case '5': /* /M07 handle salesrep type */
			brokerNavigation()
			break

		case '6': /* /101 generic consumer type */
			consumerNavigation()
			break
	}
	
    navigationHtml += '</ul></div>' + newline + '</form>' + newline + '</div>' + newline + '<br/>' + newline

	document.writeln(navigationHtml)
}

function customerNavigation()
{

  	if (EZ020=='Y')
  	{
  		crtNavButton('S', 'EZ020', 'Order Entry')
  	}
  	
  	if (EZ013=='Y')
  	{
  		crtNavButton('S', 'EZ013', 'Order Inquiry')
  	}
  	
  	if (EZ016=='Y')
  	{
  		crtNavButton('S', 'EZ016', 'Price Inquiry')
  	}
	
  	if (EZ017=='Y')
  	{
  		crtNavButton('S', 'EZ017', 'Sales Order History')
  	}
  	
  	if (EZ014=='Y')
  	{
  		crtNavButton('S', 'EZ014', 'Inventory/Production')
  	}
	if (EZ063=='Y')
   	{
   		crtNavButton('S', 'EZ063', 'Reports')
   	}
	if (EZ064=='Y')
   	{
   		crtNavButton('S', 'EZ064', 'Receipt History')
   	}
	//3040 BEGIN
	if (EZ072=='Y')
   	{
   		crtNavButton('S', 'EZ072', 'Price & Availablity')
   	}
	//3040 END
   	
}

function adminNavigation()
{
	if (EZ010=='Y')
   	{
   		crtNavButton('S', 'EZ010', 'View Scorecard/Action')
   	}
   	
   	if (EZ009=='Y')
   	{
   		crtNavButton('S', 'EZ009', 'Select Database')
   	}

}



function supplierNavigation()
{
	if (EZ003=='Y')
   	{
   		crtNavButton('S', 'EZ003', 'View Scorecard')
   	}
   	
   	if (EZ011=='Y')
   	{
   		crtNavButton('S', 'EZ011', 'Planning Schedules')
   	}
   	
   	if (EZ018=='Y')
   	{
   		crtNavButton('S', 'EZ018', 'Shipping Schedules')
   	}
   	
   	/* /M06 handle EZ036 */
   	if (EZ036=='Y')
   	{
   		crtNavButton('S', 'EZ036', 'ASN')
   	}
   	
   	/* /M11 handle EZ042 */
   	if (EZ042=='Y')
   	{
   		crtNavButton('S', 'EZ042', 'PO Inquiry')
   	}
   
   	if (EZ051=='Y')
   	{
   		crtNavButton('S', 'EZ051', 'Part Inquiry')
   	}
}

/* /101 generic consumer navigation */
function consumerNavigation()
{
	if (EZ048=='Y')
   	{
   		crtNavButton('S', 'EZ048', 'Register Warranty Product')
   	}
}


/* M07 handle salesrep navigation */
function salesrepNavigation()
{
	// if a customer has been selected, add all of the customer programs
  	if (XXACTID != '')
  	{
  		customerNavigation()	
  	}
  	
  	if (EZ039=='Y')
  	{
  		navigationHtml += '<br />' + newline
  		crtNavButton('S', 'EZ039', 'Select Customer')
 	}
}



/* M07 handle broker navigation */
function brokerNavigation()
{
	// if a customer has been selected, add all of the customer programs
  	if (XXACTID != '')
  	{
  		customerNavigation()
  	}
  	
  	if (EZ039=='Y')
  	{
  		navigationHtml += '<br />' + newline 
  		crtNavButton('S', 'EZ039', 'Select Customer')
  	}
}

/* This function changes onclick property of obj, which is a navAnchor object */
function disableClick(obj){
    obj.onclick = function(){
        alert("Please wait, while we process your request.")
    }
    obj.innerHTML = "<img src='"+ procImage.src +"' align='left'>Processing <br>Please Wait..."
    
}

/* this function returns the source for the Order Information Button.  A mode is passed to the
   function to indicate how the button should be displayed.  The values for the mode are as follows:
   		'1' = button is clickable, with mouseover effects
   		'2' = button is not clickable, as user is on this page
   		'3' = button is not clickable, and user is not on this page
*/
function crtNavTab(mode, onClick, text)
{
    var btnClasses = "";
    switch (mode)
    {
    case '1':
        btnClasses = buttonClasses("navTab", "navTabOver");
        break
    case '2':
        btnClasses = 'class="navTabOn"';
        break
    case '3':
        btnClasses = ' class="navTab"';
        break
    }

    var tabSrc = '<li ' + btnClasses + '>';
    if (mode == '1')
    {
        //var anchor = '<a class="navAnchor" onClick="disableAfterClick(this);' + onClick + '">' + text + '</a>'
        var anchor = '<a class="navAnchor" onClick="disableClick(this);' + onClick + '">' + text + '</a>'
        tabSrc += anchor;
    }
    else
    {
        tabSrc += text;
    }
    tabSrc += '</li>';

    return (tabSrc);
    }

