// Used in Model.asp.

//if (mybug){alert('DEBUG: hello world!\nmodel.js is called.');}

// GLOBALS:
var timer_id;
var orderHTML = '';
var quoteHTML = '';
// DIV managment memvars
	var posx = 0;
	var posy = 0;
	var boolDivHasTable = false;

function badImageRepair(theControl, optionalURL, optionalText){
  /*
<img src="myimage.jpg" id="modelImage1" align="right"
onError="JavaScript:badImageRepair(this,'http://www.disney.com','Hello?');"><span id="spn_modelImage1" class="normal_small_text"></span>
  */
	var optionalSpan;
	var strSpan;
	if (theControl.src == undefined){
		// alert('theControl.src is Undefined. theControl Name is: ' + theControl.name);
	return;}
	// NOTE: For below to work, the IMG tag must have a defined ID!
	// alert(' badImageRepair theControl.src is: ' + theControl.src + '\ntheControl ID is: ' + theControl.id  + '"\nTEST for blank.gif. RESULT IS: ' + theControl.src.indexOf("/blank.gif") ) ;
	if (theControl.src.indexOf("/blank.gif") != -1) { // IF blank.gif is found.
		theControl.OnError = null;
		// alert('set theControl.OnError to NULL');
		return;
	} // FAST OUT if blank.gif gives error!
	theControl.src = blankImage; // Set it to blank image.
        // NOW test for optional text link, if spn_(ID for control) was created.
	 // alert('optionalURL is ' + optionalURL + ', and optionalText is ' + optionalText + '\ntheControl ID is: ' + theControl.id);
	if (optionalURL != undefined){
           optionalSpan = document.getElementById('spn_' + theControl.id);
           if (optionalSpan == undefined) {optionalURL = undefined;} // Make it so.
        } // First exam for optionalURL
	// alert('SECOND report: optionalURL is ' + optionalURL + ', and optionalText is ' + optionalText);
	if (optionalURL != undefined){
           strSpan = '<a href="' + optionalURL + '">';
           if (optionalText.length > 0) {
              strSpan = strSpan + optionalText;
           } else {strSpan = strSpan + 'Click Here';}
           strSpan = strSpan + '</a>';
           optionalSpan.innerHTML = strSpan;
           // alert('optionalSpan.innerHTML is\n' + optionalSpan.innerHTML);
        } // optionalURL != undefined exam- is it there?
} // END badImageRepair

// SHARED: SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
function OpenLinkWindow(aURL){
  var myWin = window.open(aURL,'SC_Link','location=no,status=no,scrollbars,resizable');
  myWin.focus();
  } // end OpenLinkWindow
 // function OpenImageWindow(URL){window.open(URL,'ImageWindow','location=no,status=yes');}
function OpenImageWindow(TheURL){
  // OLD:  var PopupWindow = sw_environment + '/swchannel/productcatalogcf_v2/internet/productcatalogviewlargeimage.asp';
  var furl = ''; // PopupWindow + '?DisplayName=High Resolution - Click to close&ImageURL=';
  var myWin = window.open(furl + TheURL,'SC_Link','location=no,status=no,scrollbars=no,resizeable');
  myWin.focus();
} // END OpenImageWindow
function scroll_iframe(frm,inc,dir) {
  if (timer_id) {clearTimeout(timer_id);}
  if (window.frames[frm]) {
    if (dir == "v") {window.frames[frm].scrollBy(0, inc);
    } else{ window.frames[frm].scrollBy(inc, 0);
    timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 50);
    } // dir == "v"
  } // window.frames[frm]
}
   function stopScroll() { if (timer_id) clearTimeout(timer_id); }


			// Keystroke Javascript in Quantity field.
			function entsuborder(myform, theField, ipackage) { 
				if (mybug){alert('DEBUG entsuborder entered. myform is ' + myform.name + ', ipackage is: ' + ipackage);}
			
			
				var key;
				var keychar;
				var bSubmit;
				bSubmit = false;
				// Below tests for RETURN KEY HIT in Quantity Field!
				if (window.event && window.event.keyCode == 13){
					if (ipackage > 0){
						if (!validateQuantityOrder(theField,ipackage)){return true;}
					}
				  if(ValidateNumericOrder()){
                                    if (mybug){alert('ValidateNumericOrder returned TRUE');}
					// NO! Done each option change; recalc'd on submit. AJAX_UpdatePricing(ipackage);
				    myform.submit();
				  } else {
                                    if (mybug){alert('ValidateNumericOrder returned FALSE');}
                                    return false;
                                   }// End ValidateNumericOrder Result
				} else { // NOT Return Key. Evaluate for Number
					if (window.event) {
					   key = window.event.keyCode;}
					// else if (e) { // NO EVENT submitted to this routine.
					//   key = e.which;
					else {
					   return true;} // Not a Key?
					keychar = String.fromCharCode(key);
					// control keys - NO.
					if ((key==null) || (key==0) || (key==8) ||
					    (key==14) || (key==27))
					    {return false;} // NOT a valid key
					else if ((("0123456789").indexOf(keychar) > -1)) // numbers
					   {
                				// WARNING: Check for 10000 max quantity is made in three places, all with alerts.
                				// Once here, once in validateQuantityOrder, and once in ValidateNumericOrder.
                				if (theField.value.length > 4) {
                				   alert('Maximum quantity for any one item is 10,000.\nThe entered quantity of "' + theField.value + keychar + '"\n is too large.');
                				   theField.value = 10000;
                				   return false;
                                                } // theField.value.length > 5
                                             return true;}
					else {return false;} // NO Decimal evaluation for Quantity field.
				} // NO return key. Eval for numer
			} // END entsuborder

			function validateQuantityOrder(theField, ipackage) {
                        // OnChange event for Quantity field; runs for both Order and Quote!
                        var boolGoodToOrder = false;
                        var productid = 0
                        var arrP;
                        var disquote = 0;
                        arrP = theField.name.split('_');
                        if (arrP[2] != undefined){productid = arrP[2];}
                        // alert('TEST Productid is now ' + productid + ', theField.name is ' + theField.name);
			if (mybug){alert('DEBUG validateQuantityOrder entered. theField.value is ' + theField.value + ', ipackage is: ' + ipackage);}
				// Good to go?
				if (isNaN(parseInt(theField.value))){
                                      if (theField.value.length < 1) {return false;} // Fast Out
					alert('Invalid entry for Quantity field.\nQuantity can only be a number.');
					theField.value = ''; // bad value in Quantity field.
					return false;
				} else {
				if (mybug){alert('DEBUG validateQuantityOrder theField.value PASSED isNaN Exam: ' + theField.value );}
				   var hidChargePrice = document.getElementById('chargeprice_' + productid);
				   var disquote = document.getElementById('disquote_' + productid);
				  if (disquote > 0){
                                    if (hidChargePrice == undefined){
                                       // if(mybug){alert('DEBUG validateQuantityOrder hidChargePrice is undefined: chargeprice_' + productid);}
                                       // FAIL SILENTLY.
                                       if(mybug){alert('Error: validateQuantityOrder hidChargePrice is undefined: chargeprice_' + productid);}
                                       boolGoodToOrder = true;
                                    } else {
                                      if (!isNaN(parseFloat(hidChargePrice.value))){
                                        if (parseFloat(hidChargePrice.value) > 0){
                                           boolGoodToOrder = true;
                                        }
                                      } // Not IsNaN exam
                                    } // Not Undefined exam.
                                    if (!boolGoodToOrder){
                                      theField.value = '';
                                      alert('This item has no price listed.\nItems without a price cannot be ordered.');
                                    }
                                  } // disquote exam - ONLY run above check if Disable Quote is set ON.
				} // isNaN exam for a value in Quantity PASSED.
				if (ipackage > 0){
					theField.focus();
				}
                                // alert('TEST boolGoodToOrder = ' + boolGoodToOrder);
                                if (!isNaN(parseInt(theField.value))){ // IF a number
                                  if (parseInt(theField.value) > 10000) {
                                    alert('Maximum quantity for any one item is 10,000.\nThe entered quantity of "' + theField.value + '"\n is too large.');
                                    theField.value = 10000;
                                  }
                                }
				return boolGoodToOrder; // true or false.
			} // END validateQuantityOrder
/*********************************/

			function validateOrder() { // Add to cart button
			if (mybug){alert('validateorder entered');}
			// chargeprice_
				//if (!ValidateNumericOrder()){return;}
				var myform;
					myform = document.frmProductSKUOrder;
				if(ValidateNumericOrder()){ // Also run by FORM as OnSubmit event
				// alert('debug validateOrder add to cart button-\nabout to run ValidatePriceOrder');
                                  if(!ValidatePriceOrder()){return;} // Out of here.
				  if (mybug){alert('arrValidatePackages.length is ' + arrValidatePackages.length);}
				  myform.hidQuoteSubmit.value = ''; // CLEAR THIS FLAG for Submit response.
				  if (arrValidatePackages.length < 1){
				    myform.submit(); // Normal Submit.
				    return;
				  }
					myform.submit();
				} else {return;}
			} // END validateOrder
/*********************************/
			function validateQuote() { // Add to Quote button
			if (mybug){alert('validateQuote entered');}
				var myform;
					myform = document.frmProductSKUOrder;
				if(ValidateNumericOrder()){ // Also run by FORM as OnSubmit event
				// alert('debug validateOrder add to cart button-\nabout to run ValidatePriceOrder');
                                  // NOT FOR QUOTE! if(!ValidatePriceOrder()){return;} // Out of here.
				  if (mybug){alert('arrValidatePackages.length is ' + arrValidatePackages.length);}
				  myform.hidQuoteSubmit.value = 1; // SET THIS FLAG for Submit response.
				  // alert('hidQuoteSubmit value is: ' + myform.hidQuoteSubmit.value);
				  if (arrValidatePackages.length < 1){
				    myform.submit(); // Normal Submit.
				    return;
				  }
					myform.submit();
				} else {return;}
			} // END validateQuote
/*********************************/

				function ValidatePriceOrder(){
                                        // alert('ValidatePriceOrder entered');
					if (!orderbutton){return false;} // GLOBAL memvar, when button is hit.
					var strFormType = 'order';
                                        var c = 0;
					var myPField;
					var myPrice;
					var boolGoodToOrder = false;
					var boolSaidNoPriceError = false;
					var intRequired;
					var intEntered;
					var errormsg = '';
					var myproductsku;
						for(c=0;c<arrValidateNumOrd.length;c++){ // Filled as form loads, Productid
						    boolGoodToOrder = false;
							// myField = document.getElementById (arrValidateNumOrd[c] ); // Quantity ID IS JUST PRODUCTID!
							// id of productid is NOT UNIQUE; used by Quotes and Order. USE THE NAME.
							myPField = eval('document.frmProductSKUOrder.Product_O_' + arrValidateNumOrd[c]);
							myPrice = eval('document.frmProductSKUOrder.chargeprice_' + arrValidateNumOrd[c]);
                                                  //alert('FIRST CHECK ValidatePriceOrder: myprice value is ' + myPrice.value + ', FIELD NAME: chargeprice_' + arrValidateNumOrd[c]);
							// alert('myPField id is: "' +  arrValidateNumOrd[c] + '".');
							// alert('myPField.value is ' + myPField.value);
							if (myPField != undefined) {
								  if (!isNaN(parseInt(myPField.value))) { // Not Not-A-Number?
									// if (mybug){alert('DEBUG ValidateNumericOrder Quantity myPField.value\nfor ProductID: "' + arrValidateNumOrd[c] + '" is: "' + myField.value + '".');}
									if (myPField.value > 0) {
                                                                            // NOW CHECK FOR PRICE.
                                                                            if (myPrice != undefined) {
                                                                              if (!isNaN(parseInt(myPrice.value))){
                                                                                if (parseFloat(myPrice.value) > 0){
                                                                                  // alert('ValidatePriceOrder myprice value is ' + myPrice.value);
                                                                                  boolGoodToOrder = true; // NIKE
                                                                                }
                                                                              }
                                                                            } else {
                                                                            // FAIL SILENTLY.
                                                                              if(mybug){alert('Error in ValidatePriceOrder: Field chargeprice_' + arrValidateNumOrd[c] + ' is undefined.');}
                                                                              boolGoodToOrder = true; // Success if UNDEFINED.
                                                                            }
                                                                            if (!boolGoodToOrder){
                                                                              if (!boolSaidNoPriceError){
                                                                                boolSaidNoPriceError = true;
                                                                                alert('One of the items selected in this order has a quantity but no price.\nItems without a price can be included on a quote,\nbut cannot be ordered.');
                                                                              } // Only say once boolSaidNoPriceError = true
                                                                              myPField.value = ''; // BLANK quantity.
                                                                            } // NOT boolGoodToOrder exam ends.
									} else { // Myfield.value > 0
                                                                   // alert('DEBUG ValidatePriceOrder myField.value NOT GREATER THAN 0 ValidatePriceOrder myField.value: ' + myField.value + '".');
                                                                        } // Myfield.value > 0 or not ends
								  } else {
                                                                    // alert('DEBUG ValidatePriceOrder ISNAN myField.value. ValidatePriceOrder NAN myField.value: ' + myField.value + '".');
                                                                  } // isNaN(parseInt(myField.value)) exam.
							 } else {
							  if (mybug){alert('DEBUG myPField == undefined. ValidateNumericOrder UNDEFINED myPField: ' + arrValidateNumOrd[c] + '".');}
							  return false; // fatal error.
							 } // End of eval for undefined field name
						  } // Loop thru arrValidateNumOrd
					      if (boolSaidNoPriceError) {
                                                 return false;
                                              } else {return true;}
				} // END ValidatePriceOrder
/*********************************/

				function ValidateNumericOrder(){
					var strFormType = 'order';
					if (!orderbutton){strFormType = 'quotation';} // GLOBAL memvar, when button is hit.
					var i,c;
					// var isOK = true;
					var myField;
					var isOK;
					var intRequired;
					var intEntered;
					var errormsg = '';
					var myproductsku;
					
						for(c=0;c<arrValidateNumOrd.length;c++){ // Filled as form loads, Productid
						    isOK = false;
							
							// id of productid is NOT UNIQUE; used by Quotes and Order. USE THE NAME.
							myField = eval('document.frmProductSKUOrder.Product_O_' + arrValidateNumOrd[c]);
							// alert('myField id is: "' +  arrValidateNumOrd[c] + '".');
							// alert('myField.value is ' + myField.value);
							if (myField != undefined) {								
									if (!isNaN(parseInt(myField.value))) { // Not Not-A-Number?
									// if (mybug){alert('DEBUG ValidateNumericOrder Quantity myField.value\nfor ProductID: "' + arrValidateNumOrd[c] + '" is: "' + myField.value + '".');}
										if (myField.value > 0) {
                                                                                    if (myField.value > 10000) {
                                                                                    alert('Maximum quantity for any one item is 10,000.\nThe entered quantity of "' + myField.value + '"\n is too large.');
                                                                                       myField.value = 10000;
                                                                                       return false; // fatal error.
                                                                                    } else {
                                                                                    isOK = true;
                                                                                    }
										} else {
                                                                        // alert('DEBUG myField.value NOT GREATER THAN 0 ValidateNumericOrder myField.value: ' + myField.value + '".');
                                                                                }
									} else {
                                                                          //alert('DEBUG ISNAN myField.value. ValidateNumericOrder NAN myField.value: ' + myField.value + '".');
                                                                        } // isNaN(parseInt(myField.value)) exam.

							 } else {
 							  if (mybug){alert('DEBUG myField == undefined. ValidateNumericOrder UNDEFINED myField: ' + arrValidateNumOrd[c] + '".');}
 							  return false; // fatal error.
							 } // End of eval for undefined field name
							
                                                   if(strFormType == 'order'){
							if (isOK) {
							
							 
							  myField = document.getElementById('packagereqnotselectcount_' + arrValidateNumOrd[c]);
							  if (myField != undefined) { // Test for options.
								intRequired = myField.value;
							
								if (!isNaN(parseInt(intRequired))){ // Not Not-A-Number?
								  if (intRequired > 0) {// Failure!
										myproductsku = document.getElementById('productsku_' + arrValidateNumOrd[c]).value;
										if (!mybug){
											alert('All Required Options were not selected\nfor Product SKU:\n\'' + myproductsku + '\'.\n' + intRequired + ' Required Options remain to be selected.');
											return false; // Out of here.
										} else {
										  alert('DEBUG ONLY! WILL CONTINUE BECAUSE THIS IS DEBUG.\nAll Required Options were not selected\nfor Product SKU:\n\'' + myproductsku + '\'.\n' + intRequired + ' Required Options remain to be selected.');
										} // MYBUG SUBMITS but shows error messages.
							      } // intRequired exam > 0 is failure.
								} // !isNaN(parseInt(intRequired))
							  } else {
							  if (mybug){alert('DEBUG- NOT A PACKAGE! ValidateNumericOrder myfield packageoptionreqcount_' + + arrValidateNumOrd[c] + ' UNDEFINED!');}
							    // DO NOTHING. NOT REQUIRED, unless this is a Package.
							  } // Second Myfield, options.
						    } // IsOK exam, check for Options?
                                                 } // strFormType exam, only do above if ORDER.
						  if (isOK) {return true;} // VICTORY, we have at least ONE PRODUCT with a quantity.
						  } // Loop thru arrValidateNumOrd
						 alert('Please enter a Quantity for any one product\nto add to ' + strFormType + '.');
						 return false;
				} // END ValidateNumericOrder
/*********************************/
				function IsNumeric(FieldName){
					var valid = "0123456789"
					var ok = "yes";
					var temp;
					for (var i=0; i < FieldName.value.length; i++)
					{temp = "" + FieldName.value.substring(i, i+1);
						if (valid.indexOf(temp) == "-1") ok = "no";
					}
					if (ok == "no")
					{	alert("Enter numbers only for quantity!");
						sOk = false;
						FieldName.focus();
						FieldName.select();
						return false;
					}
					else
					{
						return true;
					}

				}// END IsNumeric

				function MaxExceeded(FieldName, MaxAllowed){
					 var isOK;
					 isOK = true;
					 // < ' REMOVED. LimitOrder = -1 >
					 if (iLimitOrder > -1) {
						if(FieldName.value > iLimitOrder){
							alert('You can order a maximum of ' + iLimitOrder + ' only!');
							FieldName.focus();
							FieldName.select();
							isOK = false;
						}
					 } else {
						isOK = true;}
					return isOK;
				} // END MaxExceeded
// QUOTES: QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
// NO LONGER USED. REMOVE.
			function entsubquote(myform) {
				var bSubmit;
				bSubmit = false;
				if (window.event && window.event.keyCode == 13) {
				  SubmitQuote(myform);
				  if(ValidateNumericQuote()){
				   myform.submit();
				  }else {return true;}
				}
			} // END entsubquote
				function ValidateNumericQuote(){

					ValidateNumericQuote = true;

					/*
					var myForm;
					myForm = document.forms[2].elements;
					var i,c;

					var isOK;
					isOK = true;
					var myField;
					var myFieldName;
					var bHasAtLeastOneValue;
					for(i=0;i<myForm.length;i++){
						for(c=0;c<arrValidateNum.length;c++){
							//alert(myForm[i].name);
							//alert(eval("frmProductSKU." + myForm[i].name + ".value"));
							myField = eval("document.forms[2]." + myForm[i].name)
							myFieldName = myField.name;
							if(myFieldName.indexOf("Q") > 0){
								if(isOK) isOK = IsNumeric(myField);
								if(isOK){
									if(myField.value.length > 0){
										bHasAtLeastOneValue = true;
									}
								}
								if(!isOK) return false;
							}

						}//for(c=0;c<myArray....

					}

					if(!bHasAtLeastOneValue){
						alert("Please enter at least one numeric quantity for a product.");
						isOK = false;
						return isOK;
					}
					return isOK;
					*/
				} // END ValidateNumericQuote
// PACKAGE: PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
			function OpenPMPage(pmid, displaytemplate, parentid, ipackage, iproduct, gid) {
                          // Package ONLY. Open PM page for package SKU
			if (mybug){alert('DEBUG OpenPMPage Entered. PMID is  ' + pmid + ', displaytemplate: ' + displaytemplate + ', parentid: ' + parentid + ', iproduct: ' + iproduct + ', gid: ' + gid + ', ipackage: ' + ipackage);}
				  if (arrValidatePackages.length >= 1){
					if (trim(displaytemplate).length > 0) {
						if ((pmid > 0) && (parentid > 0)) {
                                                  // Fire AJAX call to stash Option Info in Session Memvar
                                                  if (AJAX_SaveOptions(ipackage, iproduct, gid)) {
							var aURL = rootURL + '/';
							aURL = aURL + displaytemplate + '?SWSESSIONID=' + zsessionid;
                                                        aURL = aURL + '&ProductMasterID=' + pmid;
  							aURL = aURL + '&parentid=' + parentid;
  							aURL = aURL + '&productid=' + iproduct;
                          	                        aURL = aURL + '&package=' + ipackage;
  							if (mybug){
                                                        if (!confirm('DEBUG CONTINUE?\nOpening in New Window aURL: ' + aURL)){return false;}
                                                        }
							// window.location = aURL;
							var myWin = window.open(aURL, 'ProductPage');
							myWin.focus();
							return true;
                                                   } // Test for  AJAX_SaveOptions(ipackage, iproduct, gid) returns TRUE.
						}
					}
				  }
				 return false;
			} // END OpenPMPage
// ***************************
// ************************************
function AJAX_SaveOptions(ipackage, iproduct, gid){ // Saves options in Session Values for use by ProductMaster
    if (mybug){alert('Debug AJAX_SaveOptions Started- PackageID: ' + ipackage + ', iproduct: ' + iproduct + ', GroupID: ' + gid);}
         if (iproduct == undefined){return false;}
         if (gid == undefined){return false;}
         if (ipackage == undefined){return false;}
      var strOptions = '';
      var hidOptions;
       		hidOptions = document.getElementById('hidOptions_' + ipackage);
  	        if (hidOptions == undefined){ // Made a match!
     if (mybug){alert('Debug AJAX_SaveOptions- hidOptions: hidOptions_' + ipackage + ' is undefined.');}
                 return false;}
                strOptions = hidOptions.value;
           // NO. Continue for Quantity.
           //  if (strOptions.length < 1){return true;} // FAST OUT, indicating success- No Options to save!

             var modelQuantity; // From model.asp
                 // MUST TAKE BY NAME!
		modelQuantity = eval('document.frmProductSKUOrder.Product_O_' + ipackage); // Very strange.
		if (modelQuantity == undefined){
         if (mybug){alert('AJAX_SaveOptions ERROR- modelQuantity: (just package lead ProductID!) ' + ipackage + ' is undefined.');}
		return false;}
	var iQuantity = modelQuantity.value;
        if (isNaN(parseInt(iQuantity))){iQuantity = 1;}
	if (parseInt(iQuantity) < 1) {iQuantity = 1;}
	iQuantity = parseInt(iQuantity);
	// if (mybug){alert('DEBUG AJAX_SaveOptions iQuantity is ' + iQuantity + ', iPackage is ' + ipackage);}

 if (mybug){alert('AJAX_SaveOptions INFO: PackageID: ' + ipackage + ', iQuantity: ' + iQuantity + ', and strOptions:\n' + strOptions );}

			var xmlhttp=false; //declare the httpxml and create object with browser sensitivity;
			/*@cc_on @*/
			/*@if (@_jscript_version >= 5)
			// JScript gives us Conditional compilation, we can cope with old IE versions.
			// and security blocked creation of the objects.
			 try {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			 } catch (e) {
			  try {
			   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (E) {
			   xmlhttp = false;
			  }
			 }
			@end @*/
			if (!xmlhttp && typeof XMLHttpRequest!= undefined) {
				try {
					xmlhttp = new XMLHttpRequest();
				} catch (e) {
					xmlhttp=false;
				}
			}
			if (!xmlhttp && window.createRequest) {
				try {
					xmlhttp = window.createRequest();
				} catch (e) {
					xmlhttp=false;
				}
			}
			if (!xmlhttp){
                           alert('Error Saving Options Options:\nYour browser does not appear to be AJAX compatible.');
                           return false;
                        }

			var qryvars; //store the query string vars here.
			qryvars = '?SWSESSIONID=' + zsessionid;
			qryvars = qryvars + '&P=' + ipackage; // ProductParentID
                        qryvars = qryvars + '&gid=' + gid;
			qryvars = qryvars + '&O=' + strOptions; // Group Product Member String
			qryvars = qryvars + '&PD=' + iproduct;
			qryvars = qryvars + '&Q=' + iQuantity;
			qryvars = qryvars + '&D=';
			if (mybug){qryvars = qryvars + 'true';}
			else {qryvars = qryvars + 'false';}

			var aURL; //URL to post to
			aURL = sw_environment + '/swchannel/productcatalogcf_v2/internet/package/package_saveoptions.asp' + qryvars;
	if (mybug){alert('Debug AJAX_SaveOptions aURL:\n' + aURL);}
			xmlhttp.open('POST', aURL, false);
			// NOT FIREFOX COMPATIBLE xmlhttp.send(null);
			if (parseInt(navigator.appVersion)>3) {
			 if (navigator.appName=="Netscape") {
        		  xmlhttp.send(''); // Firefox
			 }
			 if (navigator.appName.indexOf("Microsoft")!=-1) {
        		  xmlhttp.send(null); // IE (6 and 7)
			 }
			}
// NOT Expecting any returned response text.
			var aResponseText;
			aResponseText = xmlhttp.responseText;
if(mybug){alert('next dialog is Response Text from package_saveoptions.asp');}
if(mybug){
  alert(aResponseText);
  return true; // Mybug returns TRUE.
} // End of Mybug exam - SAY IT. - SHOULD BE BLANK.

     if (aResponseText == 'Success') {
        return true;
     } else {
       return false;
     } // Success?
} // END AJAX_SaveOptions
// **********************************************
 function hideShowGroup(gid){
   //alert('hideShowGroup entered. gid is: ' + gid);
  var tableGroup = document.getElementById('tableGroup_' + gid);
    if (tableGroup == undefined){return;} // Fast Out.
  var divShowGroup = document.getElementById('divShowGroup_' + gid);
  var divHideGroup = document.getElementById('divHideGroup_' + gid);
      if (tableGroup.style.display == 'none') {
          //alert('divGroup.style.display is NONE');
        tableGroup.style.display = "block";
        divHideGroup.style.display = "block";
	divShowGroup.style.display = "none";
      } else { // if divGroup is SHOWN, hide it.
          //alert('divGroup.style.display is BLOCK');
        tableGroup.style.display = "none";
        divHideGroup.style.display = "none";
	divShowGroup.style.display = "block";
      }
  return;
 } // END hideShowGroup
 /****************/
function isNumeric(sText) {
   var ValidChars = '0123456789.';
   var isANumber=true;
   var Character;
   for (i = 0; i < sText.length && isANumber == true; i++) {
      Character = sText.charAt(i);
      if (ValidChars.indexOf(Character) == -1){isANumber = false;}
   } // Loop ends.
   return isANumber;
} // end isNumeric
/****************/

function mousePosition(e) {
	if (!e) var e = window.event;
	// DONE AS GLOBALS var posx = 0;
	// DONE AS GLOBALS var posy = 0;
	posx = 0;
	posy = 0;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
} // end mousePosition
/****************/
function roundNumber(anum, alength) { // num to round, count of Decimals to round to.
  var numResult = Math.round(anum*Math.pow(10,alength))/Math.pow(10,alength);
  return numResult;
} // end roundNumber
/****************/
function moveDiv(divName, keepVertical, keepHorizontal, fudgeX, fudgeY, roundDecimals){
  // THIS MOVES DIV TO MOUSE POSITION.
  // roundDecimals should be -1, to round to 10's.
  if(divName.length < 1){return;}
  var dN = document.getElementById(divName);
  if(dN == undefined){return;}
 // if (divName == 'order'){boolDivHasTable = boolOrderHasTable;} else {boolDivHasTable = boolQuoteHasTable;}
// boolDivHasTable = false; // DEBUG HACK
  if (!boolDivHasTable){
    var tableT = '';
    tableT = tableT + '<table width="100%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG5">'; // OUTER table.
    tableT = tableT + '<table width="100%" border="0" bordercolor="red" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG1" width="100%">';
    tableT = tableT + '</td><td valign="top" align="right" width="4px">';
    tableT = tableT + '<table border="0" bordercolor="red" cellspacing="0" cellpadding="1"><tr><td id="list_row_BG3">'; // OUTER table, with BG3!
    tableT = tableT + '<table width="100%" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG1">'
    tableT = tableT + '<span class="normal_error_text" onMouseover="this.style.cursor=\'pointer\'" onMouseout="this.style.cursor=\'\'" ';
    tableT = tableT + 'onclick="javascript:closeDiv(\'' + divName + '\');" ';
    tableT = tableT + 'style="font-weight=600;font-size=8;">X</span>';
    tableT = tableT + '</td></tr></table></td></tr></table>'; // Close X table.
    tableT = tableT + '</td></tr><tr><td id="list_row_BG2" colspan="2">'; // Back to regular tables.
    tableT = tableT + dN.innerHTML;
    tableT = tableT + '</tr></td></table></tr></td></table>';
    if (mybug){divShowHTML.innerHTML = '<textarea>' + tableT + '</textarea>';}
    dN.innerHTML = tableT;
    boolDivHasTable = true; // Reset this global flag.
    // if (divName == 'order'){boolOrderHasTable = true;} else {boolQuoteHasTable = true;} // ONLY install table code ONCE.
  }

    mousePosition(); // call this function - posx and posy are globals.
// alert('posx is: ' + posx + ', and posy is: ' + posy);
// USE BELOW to evaluate location on page.
// alert('posy is: ' + posy + ', roundDecimals: ' + roundDecimals + ',\nround test: ' + roundNumber(posx, roundDecimals) + ', fudgeY: ' + fudgeY);
   if (!isNaN(parseFloat(roundDecimals))){
     posx = roundNumber(posx, roundDecimals);
     posy = roundNumber(posy, roundDecimals);
   }

  var the_style = getStyleObject(divName);
  // var the_left = parseInt(the_style.left) + 100; // Incremental movement.
  // var the_top = parseInt(the_style.top) + 100;
  if (!isNaN(parseFloat(fudgeX))){posx = posx + fudgeX;}
  if (!isNaN(parseFloat(fudgeY))){posy = posy + fudgeY;}

  if (document.layers){
   if(!keepVertical){the_style.left = posx;}
   if(!keepHorizontal){the_style.top = posy;}
  } else {
    if(!keepVertical){the_style.left = posx + "px";}
    if(!keepHorizontal){the_style.top = posy + "px";}
  }
  the_style.position = 'absolute';
  if (the_style.display != 'block'){the_style.display = 'block';}
} // moveDiv
/****************/
function getStyleObject(objectId){
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject
/****************/
function closeDiv(divName){
  if(divName.length < 1){return;}
  var dN = document.getElementById(divName);
  if(dN == undefined){return;}
  var spanDescriptiveText= document.getElementById('spandescriptivetext');
  spanDescriptiveText.style.display = 'block';
  dN.style.display = 'none'; // CLOSE IT NOW.
  return;
} // end closeDiv
/****************/
function swapDivs(divName1, divName2, divToShow){
  return; // NOT being used.
    alert('swapDivs entered.');
  if(divName1.length < 1){return;}
  if(divName2.length < 1){return;}
  var d1;
  var d2;
  var d1 = document.getElementById(divName1); // ONLY using w3c DOM
  var d2 = document.getElementById(divName2);

    if(d1 == undefined){
      if (mybug) {alert('Error! Div Named: ' + divName1 + ' is UNDEFINED!');}
      return;}
    if(d2 == undefined){
      if (mybug) {alert('Error! Div Named: ' + divName2 + ' is UNDEFINED!');}
      return;}

  if (divName1 == divToShow) {
  alert('divToShow is: ' + divName1);
     if(d2.style.display=='block'){d2.style.display='none';}
     d1.style.display='block';
  } else { // divName2 is hot.
       // alert('divToShow is: ' + divName2);
     if(d1.style.display=='block'){d1.style.display='none';}
     d2.style.display='block';
  }
  return;
} // end swapDivs
/****************/
function moveOrderDiv(divOrderName, movedDivName, divTargetName, divShowName){
//  moveOrderDiv('divOrder','order','orderInfo','orderInfo');
// TO MOVE A DIV, we find the POSITION it is being moved to. (From TARGET DIV.)
// Then we apply this position to the DIV, and it is moved. Simple.
var divOrder = document.getElementById(divOrderName); // ONLY using w3c DOM
var divTarget = document.getElementById(divTargetName);
var divMoved = document.getElementById(movedDivName);
var spanDescriptiveText= document.getElementById('spandescriptivetext');
//var order_style = divOrder.style; // getStyleObject(divOrderName);

if (mybug){if (divOrder == undefined){alert('divOrder is Undefined');}}
if (mybug){if (divTarget == undefined){alert('divTarget is Undefined');}}

    if ((divTarget.innerHTML.length > 0) && (document.getElementById('orderTableText'))) {
      if (orderbutton){
        document.getElementById('orderTableText').innerHTML = '&nbsp;&nbsp;Order Now';
        document.getElementById('orderDESCText').innerHTML = 'Select the quantities that you are looking for and click the Add to Cart button.';
      } else {
        document.getElementById('orderTableText').innerHTML = '&nbsp;&nbsp;Request a Quote';
        document.getElementById('orderDESCText').innerHTML = 'Select the quantities that you are looking for and click the Add to Quote button.';
      }
    return;
    } // TEST to see if divTarget was already populated.

  if(divMoved.style.display=='block'){
      divMoved.style.display='none'; // hide the Order DIV.
      spanDescriptiveText.style.display = 'none';
  } // END divMoved IF

    var tableT = '';
    // Add a space
         // OUTER table.
        tableT = tableT + '<table border="0" bordercolor="red" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
        tableT = tableT + '<img src="' + blankImage + '" height="2" width="10" hspace="0" vspace="0">';
        tableT = tableT + '</td></tr></table>';
    tableT = tableT + '<table width="100%" border="0" bordercolor="red" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG5"';
    tableT = tableT + 'style="border: solid #000000 1px">';
     // INNER table 1.
    tableT = tableT + '<table width="100%" border="0" bordercolor="red" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG1" width="100%" align="left" valign="top">';
    tableT = tableT + '<span id="orderTableText" class="normal_bold_text">';
    if (orderbutton){
      tableT = tableT + '&nbsp;&nbsp;Order Now';
    } else {
      tableT = tableT + '&nbsp;&nbsp;Request a Quote';
    } // ORDER OR QUOTE EXAM?
    tableT = tableT + '</span>';
    tableT = tableT + '</td><td valign="center" align="right" width="4px">';
    tableT = tableT + '<table border="0" bordercolor="red" cellspacing="0" cellpadding="1"><tr><td id="list_row_BG3">'; // OUTER table, with BG3!
    tableT = tableT + '<table width="100%" cellspacing="0" cellpadding="0"><tr><td id="list_row_BG1">'; // CLOSE BOX TABLE
    tableT = tableT + '<span class="normal_error_text" onMouseover="this.style.cursor=\'pointer\'" onMouseout="this.style.cursor=\'\'" ';
    tableT = tableT + 'onclick="javascript:closeDiv(\'' + divShowName + '\');restoreOrderDIV(\'divOrder2\',\'' + movedDivName + '\',\'' + divOrderName + '\',\'' + divOrderName + '\',\'' + divTargetName + '\');" ';
    tableT = tableT + 'style="font-weight=600;font-size=8;">X</span>';
    tableT = tableT + '</td></tr></table></td></tr></table>'; // Close X table.
    // Add a spacer line.
    tableT = tableT + '</td></tr><tr><td colspan="2" valign="top" id="list_row_BG1">';
        tableT = tableT + '<table border="0" bordercolor="red" cellspacing="0" cellpadding="0" width="100%"><tr><td ';
        tableT = tableT + 'style="border-bottom: solid #000000 1px"> ';
        tableT = tableT + '<img src="' + blankImage + '" height="1" width="10" hspace="0" vspace="0">';
        tableT = tableT + '</td></tr></table>';
    tableT = tableT + '</td></tr><tr><td id="list_row_BG2" colspan="2">'; // Back to regular tables.
    // INNER Table 2
    tableT = tableT + '<table width="100%" border="0" bordercolor="red" cellspacing="1" cellpadding="0"><tr><td width="100%" align="left" valign="middle">';
    tableT = tableT + '<span id="orderDESCText" class="normal_bold_text">';
    if (orderbutton){
      tableT = tableT + 'Select the quantities that you are looking for and click the Add to Cart button.';
    } else {
      tableT = tableT + 'Select the quantities that you are looking for and click the Add to Quote button.';
    } // ORDER OR QUOTE EXAM?
    tableT = tableT + '</span>';
    tableT = tableT + '</td></tr><tr><td width="100%" align="left" valign="center">';
        tableT = tableT + '<table border="0" bordercolor="red" cellspacing="0" cellpadding="0" width="100%"><tr><td ';
        tableT = tableT + 'id="list_row_BG1"> ';
        tableT = tableT + '<img src="' + blankImage + '" height="1" width="10" hspace="0" vspace="0">';
        tableT = tableT + '</td></tr></table>';
    tableT = tableT + '</td></tr><tr><td width="100%" align="left" valign="top">';
    tableT = tableT + '<span id="orderTableText" class="normal_bold_text">';

    tableT = tableT + '<div id="divOrder2">';
    tableT = tableT + divOrder.innerHTML;
    tableT = tableT + '</div>';
    tableT = tableT + '</tr></td></table>';
    tableT = tableT + '</tr></td></table>';
    tableT = tableT + '</tr></td></table>';

divTarget.innerHTML = tableT; // divOrder.innerHTML;
divOrder.innerHTML = '';
   if (divShowName){
     // alert('divShowName has been Defined: ' + divShowName);
     var divShow = document.getElementById(divShowName);
     if(divShow.style.display=='none'){divShow.style.display='block';} // SHOW the "Show" DIV.
   } // Test for divShowName, additional DIV to show.
// DO IT AGAIN. Must refresh this after move.
   divMoved = document.getElementById(movedDivName);
     // alert('divMoved .style.display: ' + divMoved .style.display);
     if(divMoved.style.display=='none'){divMoved.style.display='block';} // SHOW the Order DIV in the new position.
} // end moveOrderDiv
/*********************************/
function restoreOrderDIV(divSourceName, movedDivName, divTargetName, divShowName, divHideName){
//  restoreOrderDIV('divOrder2','order','divOrder','divOrder','orderInfo');
//alert('restoreOrderDIV entered. divSourceName: ' + divSourceName + ', movedDivName: ' + movedDivName + ', divTargetName: ' + divTargetName + ', divShowName: ' + divShowName + ', divHideName: ' + divHideName);
var divSource = document.getElementById(divSourceName); // ONLY using w3c DOM
var divTarget = document.getElementById(divTargetName);
var divMoved = document.getElementById(movedDivName);
//var order_style = divOrder.style; // getStyleObject(divOrderName);

if (mybug){if (divSource == undefined){alert('divSource is Undefined');}}
if (mybug){if (divTarget == undefined){alert('divTarget is Undefined');}}
    if ((divSource.innerHTML.length < 1) && (divTarget.innerHTML.length > 0)) {
      if (mybug){alert('Error. Data was in TARGET but not in Source.');}
      return;
    } // TEST to see if divTarget was already populated.

  if(divMoved .style.display=='block'){divMoved .style.display='none';} // hide the Order DIV.

divTarget.innerHTML = divSource.innerHTML;
if (divHideName){document.getElementById(divHideName).innerHTML = '';} // Wipe it.

   if (divShowName){
    // alert('RESTORE. divShowName has been Defined: ' + divShowName);
     var divShow = document.getElementById(divShowName);
     if(divShow.style.display=='none'){divShow.style.display='block';} // SHOW the "Show" DIV.
   } // Test for divShowName, additional DIV to show.
   // DO IT AGAIN. Must refresh this after move.
   divMoved = document.getElementById(movedDivName);
     // alert('divMoved .style.display: ' + divMoved .style.display);
     if(divMoved.style.display=='none'){divMoved.style.display='block';} // SHOW the Order DIV in the new position.
} // end restoreOrderDIV


// END model.js *********************