//--------------------------------------------------------------------------------------
// Function: SetChangeFlag
// Set Cookie to indicate a change has occured
//--------------------------------------------------------------------------------------
function SetChangeFlag() {
	document.cookie = "SetupChange=1";
}

//--------------------------------------------------------------------------------------
// Function: ClearChangeFlag
// ReSet Cookie to indicate a change has NOT occured
//--------------------------------------------------------------------------------------
function ClearChangeFlag() {
	document.cookie = "SetupChange=0";
}

//--------------------------------------------------------------------------------------
// Function: exitSetup
// Determine action when Exiting a set-up page
//--------------------------------------------------------------------------------------
function exitSetup(strButton, strAction) {
	
	//-------------------------------------
	// User has indicated a SAVE function
	//-------------------------------------
	if (strButton == 'Save') {
		var x = 'yes';
	}	
	
	//-------------------------------------
	// User has indicated a RANK function
	//-------------------------------------
	else if (strButton == 'Rank') {
		var x = 'no';
	}	

	//--------------------------------------------------
	// User has NOT indicated a SAVE or RANK function,
	// Display a message box to allow the user
	// to indicate a SAVE function
	//--------------------------------------------------
	else {

		//-----------------------------
		// Has the user made changes?
		//-----------------------------
		var allcookies = document.cookie;
		var pos = allcookies.indexOf("SetupChange=");
		if (pos != -1) {
			var blnSetupChange = allcookies.substr(pos + 12,1);
		}
		else {
			var blnSetupChange = 0;
		}

		//----------------------------------------------
		// If there have been changes, prompt the user
		//----------------------------------------------
		if (blnSetupChange == 1) {	
			if (((strPageName == 'Catalogs') || 
				 (strPageName == 'CatalogsConfirm') ||
				 (strPageName == 'CatalogsRank') ||
				 (strPageName == 'Warehouses') ||
				 (strPageName == 'WarehousesRank') ||
				 (strPageName == 'PricesList') ||
				 (strPageName == 'PricesSell') ||
				 (strPageName == 'PricesPD') ||
				 (strPageName == 'PricesPart')
				) &&
				(document.all)
			   )  	
			{
				var x=showModalDialog('Confirm.asp','Do you want to save your changes before exiting?','dialogWidth:350px;dialogHeight:100px;status:no;resizable:no');
			}
			else {
				var x='no';
			}
		}
		else {
			var x='no';
		}
	}
							
	//----------------------
	// Determine next page
	//----------------------
	switch (x) {
	
		//------------------------------------
		// SAVE the changes before moving on
		//------------------------------------
		case 'yes':
			switch (strPageName) {
				case 'Catalogs':
					document.frmSetup.action = "../setup/catalogsconfirm.asp";
					break;
				case 'CatalogsConfirm':
					document.frmSetup.action = "../setup/catalogssave.asp";
					break;
				case 'CatalogRank':
					buildCatidString();
					document.frmSetup.action = "../setup/catalogranksave.asp";
					break;					
				case 'Warehouses':
					document.frmSetup.action = "../setup/warehousessave.asp";
					break;					
				case 'WarehouseRank':
					buildWdcibusidString();
					document.frmSetup.action = "../setup/warehouseranksave.asp";
					break;
				case 'PricesList':
					document.frmSetup.action = "../setup/pricesListsave.asp";
					break;																												
				case 'PricesSell':
					document.frmSetup.action = "../setup/pricesSellsave.asp";
					break;																																	
				case 'PricesPD':
					document.frmSetup.action = "../setup/pricesPDsave.asp";
					break;																																	
				case 'PricesPart':
					document.frmSetup.action = "../setup/pricesPartsave.asp";
					break;																																						
				default:
					break;
			}
			document.frmSetup.hdnAction.value = strAction;
//			document.frmSetup.target = "_top";
			document.frmSetup.submit();
			break;
			
		//-------------------------------------------	
		// Do not save the changes before moving on
		//-------------------------------------------	
		case 'no':
			ClearChangeFlag();
			eval(strAction);
			break;
		default:
			break;	
	}
}

//--------------------------------------------------------------------------------------
// Function: Feedback
// Go to Feedback
//--------------------------------------------------------------------------------------	
function Feedback()
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	var wndSub1 = window.open("","wndFeedback","resizable=yes,location=no,height=550,width=800,left=0,top=20");
//	var wndSub1 = window.open("","wndFeedback","");
	document.frmHidden.action = "/_Members/other/feedback1.asp?type=1&pg=" + strPageName;
	document.frmHidden.target = "wndFeedback";

	document.frmHidden.hdnFB.value = "";
	// Divide Feedback into multiple form values
	if (typeof(document.all) !== 'undefined')
	{
		var FormLimit = 102399;
		var strOuterHTML = new String;
		strOuterHTML = document.all[0].outerHTML;
		
		//alert(document.all[1].outerHTML);
		
		document.frmHidden.hdnFB.value = strOuterHTML.substr(0, FormLimit);
		strOuterHTML = strOuterHTML.substr(FormLimit);			
		while (strOuterHTML.length > 0)
		{
			var objINPUT = document.createElement("INPUT");
			objINPUT.type = "hidden";
			objINPUT.name = "hdnFB";
			objINPUT.value = strOuterHTML.substr(0, FormLimit);
			document.frmHidden.appendChild(objINPUT);
			strOuterHTML = strOuterHTML.substr(FormLimit);
		}
	}
	document.frmHidden.submit();		
}

//--------------------------------------------------------------------------------------
// Function: Suggestion Box
// Go to Suggestion Box
//--------------------------------------------------------------------------------------	
function SuggestionBox()
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	var wndSub1 = window.open("","wndFeedback","resizable=yes,location=no,height=550,width=800,left=0,top=20");
	document.frmHidden.action = "/_Members/other/feedback1.asp?type=2&pg=" + strPageName;
	document.frmHidden.target = "wndFeedback";

	document.frmHidden.hdnFB.value = "";
	// Divide Feedback into multiple form values
	if (typeof(document.all) !== 'undefined')
	{
		var FormLimit = 102399;
		var strOuterHTML = new String;
		strOuterHTML = document.all[0].outerHTML;
		document.frmHidden.hdnFB.value = strOuterHTML.substr(0, FormLimit);
		strOuterHTML = strOuterHTML.substr(FormLimit);			
		while (strOuterHTML.length > 0)
		{
			var objINPUT = document.createElement("INPUT");
			objINPUT.type = "hidden";
			objINPUT.name = "hdnFB";
			objINPUT.value = strOuterHTML.substr(0, FormLimit);
			document.frmHidden.appendChild(objINPUT);
			strOuterHTML = strOuterHTML.substr(FormLimit);
		}
	}	
	document.frmHidden.submit();		
}

//--------------------------------------------------------------------------------------
// Function: BeginNewLookup
// Prepare to do a new Lookup
//--------------------------------------------------------------------------------------	
function BeginNewLookup()
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	document.frmHidden.action = "/_Members/lookups/lookup.asp";
	document.frmHidden.hdnCK.value = "";
	document.frmHidden.hdnCAT.value = "";
	document.frmHidden.hdnLT.value = "";
	document.frmHidden.hdnSW.value = "";
	document.frmHidden.hdnMM.value = "";
	document.frmHidden.hdnVQ.value = "";
	document.frmHidden.hdnPN.value = "";
	document.frmHidden.hdnPQ.value = "";
	document.frmHidden.hdnAP.value = "";
	document.frmHidden.hdnPT.value = "";
	document.frmHidden.hdnFB.value = "";
//	document.frmHidden.target = "_top";
	document.frmHidden.submit();
}

//--------------------------------------------------------------------------------------
// Function: GotoPage
// Goto a new page; save session values in Hidden form
//--------------------------------------------------------------------------------------	
function GotoPage(strURL)
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	document.frmHidden.action = strURL;
	if (strURL.indexOf('/setup/') == 0)
	{
		document.frmHidden.hdnCK.value = "";
	}	
	document.frmHidden.hdnFB.value = "";
//	document.frmHidden.target = "_top";
	document.frmHidden.submit();
}

//--------------------------------------------------------------------------------------
// Function: GotoSecurePage
// Goto a secure page
//--------------------------------------------------------------------------------------	
function GotoSecurePage(strURL)
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	var wndSub1 = window.open("","wndSecure","resizable=yes,toolbar=yes,location=no,scrollbars,height=550,width=800,left=0,top=20");
	document.frmHidden.action = strURL;
//	document.frmHidden.target = "wndSecure";
	document.frmHidden.submit();
}

//--------------------------------------------------------------------------------------
// Function: Catalogs
// Display available catalogs
//--------------------------------------------------------------------------------------	
function Catalogs()
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	var wndSub1 = window.open("","wndCatalogs","resizable=yes,location=no,scrollbars,height=500,width=800,left=0,top=20");
	document.frmHidden.action = "../other/AvailCatalogs.asp";
	document.frmHidden.target = "wndCatalogs";
	document.frmHidden.submit();	
}

//--------------------------------------------------------------------------------------
// Function: WhatsNew
// Display what's new
//--------------------------------------------------------------------------------------	
function WhatsNew()
{
	if (typeof(document.all) !== 'undefined') {
		if (document.all.btnPlay) { Play(0); }	
	}	
	var wndSub1 = window.open("","wndWhatsNew","resizable=yes,location=no,scrollbars,height=550,width=800,left=0,top=20");
	document.frmHidden.action = "../support/whatsnew.asp";
	document.frmHidden.target = "wndWhatsNew";
	document.frmHidden.submit();	
}