var bBrandsDisable = true;
var bCatgnoDisable = true;
var bHasValidDate = false;
var bHasReason = false;
var bProdnoDisable = true;
var intDate = 0;
var intEnd = 0;
var intStart = 0;
var strReason = "";			// reason date validation fails.
var strDate = "";			// replacement date string whenever Y2K conversion.
var strEnd = "";			// replacement date string whenever Y2K conversion.
var strStart = "";			// replacement date string whenever Y2K conversion.

var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
var NS4 = (document.layers) ? true : false;
var IEmac = ((document.all)&&(isMac)) ? true : false;
var IE4plus = (document.all) ? true : false;
var IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
var IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
var ver4 = (NS4 || IE4plus) ? true : false;
var NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

		
function passSelection()  {
	// pass the chain-account customer to the refreshed screen form
theForm.thecorp.value = theForm.select1.options[theForm.select1.selectedIndex].value;
top.location = "product_usage.asp?idx=" + 
	theForm.select1.options[theForm.select1.selectedIndex].value;
}

function passChosen() {
	//check that user has entered valid dates and the date range is correct.
	// and allow page to be submitted or rejected upon this verification.
	//Also, if product entry or category entry was chosen, but contains zero (0)
	// entries, stop the user from submitting until they correct their problem.
	var theDate = theForm.startdate.value;
	intStart = 0;
	intEnd = 0;
	isValidDate(theDate);
	if (bHasValidDate) {
		strStart = strDate;
		intStart = intDate;
		theDate = theForm.enddate.value;
		isValidDate(theDate);
		}
	if (bHasValidDate) {
		strEnd = strDate;
		intEnd = intDate;
		if (intEnd < intStart) {
		bHasValidDate = false;
		bHasReason = true;			//don't show date format instruction.
		strReason = "Invalid date range.";
		}
		}
	if (bHasValidDate) {
		theForm.startdate.value = strStart;	//Y2K start date replacement.
		theForm.enddate.value = strEnd;		//Y2K end date replacement.
		}
	else {
		if (bHasReason) {
		alert(strReason + "  Please correct the date(s).");
		}
		else {
		alert(strReason + "  Please correct the dates.  Valid date format is MM/DD/CCYY.");
		}
		}
	bHasReason = false;
		
	if (bHasValidDate)  {
		if (theForm.prodchoice[0].value == "1")  {
		if (theForm.prodno.value == "no entries")  {
			alert("At least one Product Number must be entered for Prod# entry!");
			bHasValidDate = false;
		}
		}
		if (theForm.catgchoice[0].value == "1")  {
		if (theForm.catgno.value == "no entries")  {
			alert("At least one Category Number must be entered for Catg# entry!");
			bHasValidDate = false;
		}
		}
		//SR#33720 Added following to verify user chose at least one brand.  (This 
		//		only tightens-up the application like above code did for original
		//		user selections.
		if (theForm.brandchoice[0].value == "1")  {
		if (theForm.brands.value == "no entries")  {
			alert("At least one Brand choice must be entered for Brands entry!");
			bHasValidDate = false;
		}
		}
	}
	if (bHasValidDate)  {
		/*
		var strMessage = "Processing, please wait...";
		theForm.Submit.style.backgroundColor = "red";
		//theForm.Submit.style.fontSize = "medium";
		theForm.Submit.style.borderStyle = "double";
		theForm.Submit.value = strMessage;
		theForm.Submit.disabled = "true";
		theForm.reset.style.backgroundColor = "white";
		//theForm.reset.style.color = "white";
		theForm.reset.style.borderStyle = "none";
		theForm.reset.value = "use [Back button] upon completion";
		//theForm.reset.disabled = "true";
		setTimeout("refreshParent()",2000);		//refresh page in 2 seconds.
		*/
	}
	return bHasValidDate;
	}

	function refreshParent()  {
	//document.location.href = "./reports.asp";	//sends user to "reports".
	window.history.back();		//sends user back one step (usually menu).
	}

	function setDefaultButtons()  {
	setChoice(2);			// set for ALL products.
	setChoice(4);			// set for ALL categories.
	setChoice(6);			// set for ALL brands.		//SR15591
	}

	function checkChoice(elem)  {
		//ii will be set to 1-prod# entry, 2-All prod#, 3-catg# entry, 4-All catg#,
		//    5-Brand entry, 6-All brands.
	var ii = 0;
	if (!NS4 && !NS6)  {
		
		// alert(elem.name);		
		// alert(elem.value);
		
		if (elem.name == "prodchoice" && elem.value == 1) {
  			//radio button chosen for Product number(s) popup (disabled for Netscape).
			ii = 1;				//this is for product number entry.
			//theForm.prodchoice[0].value = true;
			theForm.prodno.value = "no entries";
			theForm.prodnumbers.value = "";
			theForm.catgchoice[1].checked = true;	//default to all catgs.
			//theForm.catgchoice[0].value = "0";
			theForm.catgno.value = "no entries";
			theForm.catgnumbers.value = "";
			//SR15591 Start-----------------------------------------
			theForm.brandchoice[1].checked = true;
			//theForm.brandchoice[0].value = "0";
			theForm.brands.value = "no entries";
			theForm.brandnumbers.value = "";
			//SR15591 End-------------------------------------------
		}
		else if (elem.name == "prodchoice" && elem.value == 0)  {
			//radio button chosen for ALL products.
			ii = 2;				//this is the "default" button for product.
			//theForm.prodchoice[0].value = "0";
			theForm.prodno.value = "no entries";
			theForm.prodnumbers.value = "";
		}
		else if (elem.name == "catgchoice" && elem.value == 1)  {
			// radio button chosen for Category number(s) popup (disabled for Netscape).
			ii = 3;				//this is for category number entry.
			theForm.prodchoice[1].checked = true;	//default to all prods.
			//theForm.prodchoice[0].value = "0";
			theForm.prodno.value = "no entries";
			theForm.prodnumbers.value = "";
			//theForm.catgchoice[0].value = "1";
			theForm.catgno.value = "no entries";
			theForm.catgnumbers.value = "";
				//SR15591 Start-------------------------------------------
			theForm.brandchoice[1].checked = true;
			//theForm.brandchoice[0].value = "0";
			theForm.brands.value = "no entries";
			theForm.brandnumbers.value = "";
			//SR15591 End---------------------------------------------
		}
		else if (elem.name == "catgchoice" && elem.value == 0)  {
				// radio button chosen for ALL categories.
			ii = 4;				//this is the "default" button for category.
			//theForm.catgchoice[0].value = "0";
			theForm.catgno.value = "no entries";
			theForm.catgnumbers.value = "";
		}
		//SR15591 Start------------------------------------------
		else if (elem.name == "brandchoice" && elem.value == 1)  {
			// radio button chosen for Brands popup (disabled for Netscape).
			ii = 5;				//this is for category number entry.
			theForm.prodchoice[1].checked = true;	//default to all prods.
			//theForm.prodchoice[0].value = "0";
			theForm.prodno.value = "no entries";
			theForm.prodnumbers.value = "";
			theForm.catgchoice[1].checked = true;
			//theForm.catgchoice[0].value = "0";
			theForm.catgno.value = "no entries";
			theForm.catgnumbers.value = "";
			//theForm.brandchoice[0].value = "1";
			theForm.brands.value = "no entries";
			theForm.brandnumbers.value = "";
		}
		else if (elem.name == "brandchoice" && elem.value == 0)  {
			// radio button chosen for ALL Brands.
			ii = 6;				//this is the "default" button for Brands.
			//theForm.brandchoice[0].value = "0";
			theForm.brands.value = "no entries";
			theForm.brandnumbers.value = "";
		}
		//SR15591 End--------------------------------------------
		setChoice(ii);
	}						//end of !NS4, !NS6
}

function isInteger(value)  {
var bTrueFalse = false;
var allowed = "1234567890";
if (value != "")  {
	bTrueFalse = parseInt(value);
	if (bTrueFalse)  {
	for (var ii=0; ii < value.length; ii++)  {
		if (allowed.indexOf(value.charAt(ii)) == -1)  {
		bTrueFalse = false;
		}
	}
	}
	if (!bTrueFalse)
	alert("Numeric entry required!");
}
return bTrueFalse;
}

function getIndex(what)  {
	//step thru each entry and return which prod/catg/brand radio-button chosen.
for (var ii = 0; ii < theForm.elements.length; ii++)
	if (what == theForm.elements[ii])  {
	//SR#33720 Following line changed, adding test for chain vs. non-chain to
	//		tighten-up the verification.
	//SR#33720  if (ii >= 17 && ii <= 28)
	var bhavechain = false;										//SR#33720.
	if (theForm.elements.length == 30)
		bhavechain = true;
	if (bhavechain == false && ii >= 16 && ii <= 24  ||
		bhavechain == true && ii >= 19 && ii <= 27)
		what.click();
	return ii;
	}
return -1;
}

function setChoice(which)  {
	//once which radio button was determined, now disable the other fields.
var ii = which;
if (ii == 1)  {				//the Product number(s) was chosen.
	//this section creates a pop-up window for product number entry, thus
	// the accompanying field on this screen is not accessible but will be 
	// used for information from the pop-up's entry.
	bProdnoDisable = true;		//pop-up window replaces this field.
	bCatgnoDisable = true;
	EnableDisable();			//enable/disable fields and set background color.
	//theForm.prodno.disabled = false;		//pop-up window replaces.
	//theForm.prodno.focus();
}
else if (ii == 2)  {			//the ALL products (default) was chosen.
	bProdnoDisable = true;
	EnableDisable();			//enable/disable fields and set background color.
}
else if (ii == 3)  {			// the Category number(s) was chosen.
	bProdnoDisable = true;		//this field is replaced by the category pop-up.
	bCatgnoDisable = true;		//so is this field.
	EnableDisable();			//enable/disable fields and set background color.
}
else if (ii == 4)  {			//the ALL categories (default) was chosen.
	bCatgnoDisable = true;
	EnableDisable();			//enable/disable fields and set background color.
}
	//SR15591 Start------------------------------------------------
else if (ii == 5)  {			// the Brands selection was chosen.
	bProdnoDisable = true;		//this field is replaced by the brands pop-up.
	bCatgnoDisable = true;		//so is this field.
	bBrandsDisable = true;
	EnableDisable();			//enable/disable fields and set background color.
}
else if (ii == 6)  {			//the ALL Brands (default) was chosen.
	bBrandsDisable = true;
	EnableDisable();			//enable/disable fields and set background color.
}
	//SR15591 End--------------------------------------------------
}

function EnableDisable()  {
	//for IE, grey the disabled fields and white the enabled fields.
var grey = "#EEEEEE";
var white = "#FFFFFF";
if (!NS4 && !NS6)  {			// colorize (grey out) the disabled fields.
	theForm.prodno.disabled = bProdnoDisable;
	if (bProdnoDisable)
	theForm.prodno.style.backgroundColor = grey;
	else
	theForm.prodno.style.backgroundColor = white;
	
	theForm.catgno.disabled = bCatgnoDisable;
	if (bCatgnoDisable)
	theForm.catgno.style.backgroundColor = grey;
	else
	theForm.catgno.style.backgroundColor = white;
	
	//SR15591 Start------------------------------------------------
	theForm.brands.disabled = bBrandsDisable;
	if (bBrandsDisable == true)
	theForm.brands.style.backgroundColor = grey;
	else
	theForm.brands.style.backgroundColor = white;
	//SR15591 End--------------------------------------------------
}
}

function checkPopup(elem)  {
if (!NS4 && !NS6)  {
	var element = elem;			//need to pass element along!
	checkChoice(element);
	//following opens popup for Prod# or Catg# or Brands depending on button.
	//var bhavechain = false;
	//SR#30250-2 .CvM Reduced following element counts by one now that I have 
	//SR#30250-2	removed the "Product Numbering: Corp or as-ordered variables.
	//SR#15592 .CvM Changed chain element to 33, was 30
	//if (theForm.elements.length == 33)
	//bhavechain = true;
	if (elem.name == "prodchoice" && elem.value == 1) 
	openPopup('./Product_Usage_Window.aspx?idx=0');
	else  if(elem.name == "catgchoice" && elem.value == 1)
	openPopup('./Product_Usage_Window.aspx?idx=1');
	//SR15591 Start------------------------------------------------
	else  if(elem.name == "brandchoice" && elem.value == 1)
	openPopup('./Product_UsageBrand_Window.aspx');
	//SR15591 End--------------------------------------------------
	//SR#30250-2 .CvM End of Reduced following element count by one...
}
else  {
	var message = "This option is available to Internet Explorer users only.  ";
	message = message + "If you would like to use this option, ";
	message = message + "you MUST ugrade to the free Internet Explorer (IE) ";
	message = message + "available from Microsoft.";
	alert(message);
	document.location.reload();		//for Netscape, reload page to clear problems.
}
}

function openPopup(url)  {		//creates pop-up numbers entry window.
	//this option is NOT available to Netscape (non-IE) users!!!
if (!NS4 && !NS6)  {
	var myOptions = 'dependent=yes,resizable=yes,width=500,height=450'
	myOptions += ',scrollbars=yes'
	var myPopup = window.open(url,'popupWindow',myOptions);
	if (myPopup.opener == null)
	myPopup.opener = self;
	myPopup.focus();
}
else
	document.location.reload();		//for Netscape, just reload the page!
}

function onSubmit()
{

	if (theForm.fileformat[0].checked){
		theForm.target = "_blank";
		theForm.action = "./processing_data.asp";		 
		theForm.submit();
	}else{		
		theForm.target = "_self";
		theForm.action = "./processing_data.asp";		 
		theForm.submit();
	}
}
// -->