function preloadImages() 
{
     if (document.images) 
	 {
          for (var i = 0; i < preloadImages.arguments.length; i++) 
		  {
               (new Image()).src = preloadImages.arguments[i];
          }
     }
}



function validateNumericTest(data, inputType)
{
	// allow ONLY alphanumeric keys, no symbols or punctuation
	// this can be altered for any "checkOK" string

	var checkOK = "0123456789";
	var checkStr = data.value;

	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;

			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	}

	if (!allValid)
	{
		alert("Only numbers are allowed for "+ inputType +", please check your input.");
		theForm.Alias.focus();
		return (false);
	}

	else
		return (true);
}



function validateForm(form)
{
	return false;
}



// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
function validateOnSubmitExample() 
{
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    // set to the first one in error.
    if (!validateTelnr  (document.forms.demo.telnr, 'inf_telnr', true)) errs += 1; 
    if (!validateAge    (document.forms.demo.age,   'inf_age',  false)) errs += 1; 
    if (!validateEmail  (document.forms.demo.email, 'inf_email', true)) errs += 1; 
    if (!validatePresent(document.forms.demo.from,  'inf_from'))        errs += 1; 

    if (errs>1)  alert('There are fields which need correction before sending');
    if (errs==1) alert('There is a field which needs correction before sending');

    return (errs==0);
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will loop through all input boxes on the inline ordering form
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function validateInlineOrdering(theForm) 
{
	var errs = 0;
	if (theForm.elements.length > 0)
	  {
		//for (i = 0; i < theForm.elements.length - 5; i++)
		//{
		//	if (!validateNumeric(theForm.elements[i], 'message_'+ theForm.elements[i].id.substring(13), false))        
		//		errs += 1; 		
		//}

		if (errs >= 1)
		{
			alert('Please correct all fields marked with an exclaimation point (!) before continuing.');
			return false;
		}	

		else
			return true;
	  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will loop through all input boxes on the inline ordering form
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function validateCart(theForm, shipweek) 
{
	var errs = 0;
	if (theForm.elements.length > 0)
	  {
		for (i = 0; i < theForm.elements.length-1; i++)
		{
			if (!validateNumericCart(theForm.elements[i], 'message_'+ theForm.elements[i].id, false, shipweek))        
				errs += 1; 		
		}

		if (errs >= 1)
		{
			alert('Please correct all fields marked with an exclaimation point (!) before continuing.');
			return false;
		}	

		else
			return true;
	  }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



 // ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
//
// Simple routines to quickly pick up obvious typos.
// All validation routines return true if executed by an older browser:
// in this case validation must be left to the server.
//
// Update Aug 2004: have tested that IE 5.0 and IE 5.5 both support DOM model
// sufficiently well, so innerHTML option removed (redundant).
//
// Update Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
//
// Update Oct 2005: minor tidy-up: unused parameter removed
// ----------------------------------------------------------------------

var nbsp = 160;    // non-breaking space char
var node_text = 3; // DOM text node-type
var emptyString = /^\s*$/
var glb_vfld;      // retain vfld for timer thread

// -----------------------------------------
//                  trim
// Trim leading/trailing whitespace off string
// -----------------------------------------

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};


// -----------------------------------------
//                  setfocus
// Delayed focus setting to get around IE bug
// -----------------------------------------

function setFocusDelayed()
{
  //glb_vfld.focus()
}

function setfocus(vfld)
{
  // save vfld in global variable so value retained when routine exits
  glb_vfld = vfld;
  //setTimeout( 'setFocusDelayed()', 100 );
}


// -----------------------------------------
//                  msg
// Display warn/error message in HTML element
// commonCheck routine must have previously been called
// -----------------------------------------

function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  // setting an empty string can give problems if later set to a 
  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 
  // simply use a space, but IE demands something more, like a non-breaking space.)
  var dispmessage;
  if (emptyString.test(message)) 
    dispmessage = String.fromCharCode(nbsp);    
  else  
    dispmessage = message;

  //alert(fld);

  var elem = document.getElementById(fld);
  elem.innerHTML = dispmessage;  
  
  elem.className = msgtype;   // set the CSS class to adjust appearance of message
};

// -----------------------------------------
//            commonCheck
// Common code for all validation routines to:
// (a) check for older / less-equipped browsers
// (b) check if empty fields are required
// Returns true (validation passed), 
//         false (validation failed) or 
//         proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck    (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(ifld);
  if (!elem.firstChild)
    return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text)
    return true;  // ifld is wrong type of node  

  if (emptyString.test(vfld.value)) {
    if (reqd) {
      msg (ifld, "error", "ERROR: required");  
      setfocus(vfld);
      return false;
    }
    else {
      msg (ifld, "warn", "");   // OK
      return true;  
    }
  }
  return proceed;
}

// -----------------------------------------
//            validatePresent
// Validate if something has been entered
// Returns true if so 
// -----------------------------------------

function validatePresent(vfld,   // element to be validated
                         ifld )  // id of element to receive info/error msg
{
  var stat = commonCheck (vfld, ifld, true);
  if (stat != proceed) return stat;

  msg (ifld, "warn", "");  
  return true;
};

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) {
    msg (ifld, "error", "ERROR: not a valid e-mail address");
    setfocus(vfld);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
  if (!email2.test(tfld)) 
    msg (ifld, "warn", "Unusual e-mail address - check if correct");
  else
    msg (ifld, "warn", "");
  return true;
};


// -----------------------------------------
//            validateTelnr
// Validate telephone number
// Returns true if so (and also if could not be executed because of old browser)
// Permits spaces, hyphens, brackets and leading +
// -----------------------------------------

function validateTelnr  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var telnr = /^\+?[0-9 ()-]+[0-9]$/
  if (!telnr.test(tfld)) {
    msg (ifld, "error", "ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +");
    setfocus(vfld);
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<6) {
    msg (ifld, "error", "ERROR: " + numdigits + " digits - too short");
    setfocus(vfld);
    return false;
  }

  if (numdigits>14)
    msg (ifld, "warn", numdigits + " digits - check if correct");
  else { 
    if (numdigits<10)
      msg (ifld, "warn", "Only " + numdigits + " digits - check if correct");
    else
      msg (ifld, "warn", "");
  }
  return true;
};

// -----------------------------------------
//             validateAge
// Validate person's age
// Returns true if OK 
// -----------------------------------------

function validateAge    (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);
  var ageRE = /^[0-9]{1,3}$/
  if (!ageRE.test(tfld)) {
    msg (ifld, "error", "ERROR: not a valid age");
    setfocus(vfld);
    return false;
  }

  if (tfld>=200) {
    msg (ifld, "error", "ERROR: not a valid age");
    setfocus(vfld);
    return false;
  }

  if (tfld>110) msg (ifld, "warn", "Older than 110: check correct");
  else {
    if (tfld<7) msg (ifld, "warn", "Bit young for this, aren't you?");
    else        msg (ifld, "warn", "");
  }
  return true;
};



// -----------------------------------------
//             validateNumeric
// Validates an input for numeric input only
// Returns true if OK 
// -----------------------------------------
function validateNumeric    (vfld,   // element to be validated
							ifld,   // id of element to receive info/error msg
							reqd)   // true if required
{
  //var stat = commonCheck (vfld, ifld, reqd);
  var stat = proceed;

  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);
  var ageRE = /^[0-9]{1,3}$/
  if (!ageRE.test(tfld)) 
  {
    msg (ifld, "error", "!");
	msg ("message", "error", "Please enter only numbers for order amounts. Values requiring updates are marked with an exclaimation point (!).");
    setfocus(vfld);
    return false;
  }
  return true;
};



// -----------------------------------------
//            validateNumericCart
// Validates an input for numeric input only
// Returns true if OK 
// -----------------------------------------
function validateNumericCart    (vfld,  // element to be validated
								ifld,   // id of element to receive info/error msg
								reqd,	// true if required
								shipweek)   
{
  //var stat = commonCheck (vfld, ifld, reqd);
  var stat = proceed;

  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);
  var ageRE = /^[0-9]{1,3}$/
  if (!ageRE.test(tfld)) 
  {
    msg (ifld, "error", "!");
	msg ("message_"+ shipweek, "error", "Please enter only numbers for order amounts. Values requiring updates are marked with an exclaimation point (!).");
    setfocus(vfld);
    return false;
  }
  return true;
};




//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Some AJAX stuff I picked up to control select boxes... we may be able to use this for many 
// more things down the road, it is really nice.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


/* The following function creates an XMLHttpRequest object... */

function createRequestObject()
{
	var request_o;									//declare the variable to hold the object.
	var browser = navigator.appName;				//find the browser name

	if(browser == "Microsoft Internet Explorer")
	{
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	else
	{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}

	return request_o;								//return the object
}


/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 


/* Function called to get the product categories list */
function getSelectItems(action, requestedPage)
{
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 

		ex. 	http.open('get', 'printView.html?action='+ action +'&page=loadSelectBoxes.html&id=' 
			+ document.ReportCriteria.districtid.options[document.ReportCriteria.districtid.selectedIndex].value);
	*/

	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. 
	
		ex. http.onreadystatechange = handleSalesmanSelectBox; 
	*/

	if (action == "loadDistricts")
	{
		http.open('get', 'printView.html?action='+ action +'&page=loadSelectBoxes.html&requestedPage='+ requestedPage +'&id=' 
			+ document.getElementById('regionid').options[document.getElementById('regionid').selectedIndex].value);

		http.onreadystatechange = handleDistrictSelectBox; 
	}

	if (action == "loadSalesman")
	{
		http.open('get', 'printView.html?action='+ action +'&page=loadSelectBoxes.html&requestedPage='+ requestedPage +'&id=' 
			+ document.getElementById('districtid').options[document.getElementById('districtid').selectedIndex].value);

		http.onreadystatechange = handleSalesmanSelectBox; 
	}

	if (action == "loadCustomers")
	{
		http.open('get', 'printView.html?action='+ action +'&page=loadSelectBoxes.html&id=' 
			+ document.getElementById('salesmanid').options[document.getElementById('salesmanid').selectedIndex].value);

		http.onreadystatechange = handleCustomerSelectBox; 
	}

	if (action == "loadImagesFromServer")
	{
		FreezeScreen('Now Downloading Your Images, please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		http.open('get', 'printView.html?action='+ action +'&page=loadProductImages.html');

		http.onreadystatechange = handleGetDataFromServer; 
	}

	if (action == "loadSoftwareUpdatesFromServer")
	{
		FreezeScreen('Now Downloading Your Code Updates, please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		http.open('get', 'printView.html?action='+ action +'&page=loadSoftwareUpdates.html');

		http.onreadystatechange = handleGetDataFromServer; 
	}

	if (action == "loadDataUpdatesFromServer")
	{
		FreezeScreen('Now Syncing Your Data, please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		http.open('get', 'printView.html?action='+ action +'&page=loadDataUpdates.html');

		http.onreadystatechange = handleGetDataFromServer; 
	}

	if (action == "loadActivationKeyFromServer")
	{
		FreezeScreen('Now Generating Your Activation Key, please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		http.open('get', 'printView.html?action='+ action +'&page=loadActivation.html');

		http.onreadystatechange = handleGetDataFromServer; 
	}

	

	if (action == "loadShoppingCartQuickView")
	{
		FreezeScreen('Now Loading Shopping Cart Quick View, please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		http.open('get', 'printView.html?action='+ action +'&page=loadShoppingCartQuickView.html');

		http.onreadystatechange = handleGetQuickCartDataFromServer; 
	}

	if (action == "loadQuickSearch")
	{
		FreezeScreen('Searching for your item(s), please wait ...<BR><BR><IMG SRC="images/ajaxLoaderBar.gif" width="300" height="19"><BR><IMG SRC="images/spacer.gif" width="1" height="10"><BR>');

		var searchItem = document.getElementById('searchItem').value;
		var searchDescr = document.getElementById('searchDescr').value;

		http.open('get', 'printView.html?action='+ action +'&page=loadQuickSearch.html&searchItem='+ searchItem +'&searchDescr='+ searchDescr);		

		http.onreadystatechange = handleGetQuickSearchDataFromServer; 
	}


	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}



/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleSalesmanSelectBox()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		
		document.getElementById('salesmanList').innerHTML = response;
	}
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleDistrictSelectBox()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		
		document.getElementById('districtList').innerHTML = response;
	}
}


/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleCustomerSelectBox()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		
		document.getElementById('customerList').innerHTML = response;
	}
}


/* Function called to handle informing the user that the images are done downloading from the server */
function handleGetDataFromServer()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		document.getElementById('dataResponse').innerHTML = response;

		toggleTRbody('loading_data', '');
		toggleTRbody('done_loading', '');

		// If this is the AJAX for the activation key then we also want to hide the activation messages and buttons, etc
		//if (action == "loadActivationKeyFromServer")
		if (true)
		{
			toggleTRbody('display_message_text', '');
			toggleTRbody('display_message_spacer', '');
			toggleTRbody('display_message_buttons', '');
			toggleTRbody('display_message_spacer_2', '');
		}

		// Hide the loading pane
		var outterPane = document.getElementById('FreezePane');
		if (outterPane) outterPane.className = 'FreezePaneOff';

		// Re-enable the window scroll bars
		window.document.body.scroll = 'yes';
	}
}



/* Function called to handle informing the user that the images are done downloading from the server */
function handleGetQuickSearchDataFromServer()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		if (response.match("~Many Results~") == "~Many Results~")
		{
			window.location = "searchResults.html?searchItem=checkSession&searchDescr=checkSession";
		}

		else
		{
			ShowQuickSearch();
			document.getElementById('InnerFreezePane').innerHTML = "";
			document.getElementById('InnerQuickSearchResultsPane').innerHTML = response;

			document.getElementById(document.getElementById("quickSearchAutoFocus").value).focus();
		}
	}
}


/* Function called to handle informing the user that the images are done downloading from the server */
function handleGetQuickCartDataFromServer()
{
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */

	if(http.readyState == 4)	//Finished loading the response
	{ 
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;

		ShowQuickCart();
		document.getElementById('InnerFreezePane').innerHTML = "";
		document.getElementById('InnerQuickCartResultsPane').innerHTML = response;
	}
}


function clearCustomerSelectBox()
{
	// set the customer list to the default setting when the salesman select box is filled
		document.getElementById('customerList').innerHTML = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH='100%' class=pageText><TR><TD align=center valign=middle><B>Customer:</B>&nbsp;&nbsp;<SELECT NAME='customerid' style='width:250px'><OPTION value=''>&lt;All&gt;</OPTION></SELECT></TD></TR><TR><TD align=center><IMG SRC='images/spacer.gif' WIDTH=1 HEIGHT=10></TD></TR></TABLE>";
}


/* Function called to handle toggle the vendor invoice pdf download button from disabled to enabled */
function enableVendorInvoiceDownloadButton(form, mainColor)
{
	// Disabled state
	if (form.options[form.selectedIndex].value == "")
	{
		document.getElementById('report_pdf_download_td').style.backgroundColor = "#959090";
		document.getElementById('report_pdf_download_td').style.cursor = "";
		document.getElementById('report_pdf_download').onclick = function() {};
		
		document.getElementById('report_pdf_download_left_td').style.cursor = "";
		document.getElementById('report_pdf_download_left').onclick = function() {};

		document.getElementById('report_pdf_download_div').className = "buttonTextDisabled";
		document.getElementById('report_pdf_download_div').innerHTML = document.getElementById('report_pdf_download_hdn_text').value;
	}

	// Enabled state
	else
	{
		// Need to specify this here because of the way the onClick on the image has to be set
		var formAction = document.getElementById('report_pdf_download_hdn_form_action').value;

		document.getElementById('report_pdf_download_td').style.backgroundColor = mainColor;
		document.getElementById('report_pdf_download_td').style.cursor = "pointer";
		document.getElementById('report_pdf_download').onclick = function() { document.getElementById('ReportCriteria').action = formAction; document.getElementById('ReportCriteria').target=''; document.getElementById('ReportCriteria').submit(); };

		document.getElementById('report_pdf_download_left_td').style.cursor = "pointer";
		document.getElementById('report_pdf_download_left').onclick = function() { document.getElementById('ReportCriteria').action = formAction; document.getElementById('ReportCriteria').target=''; document.getElementById('ReportCriteria').submit(); };
		
		document.getElementById('report_pdf_download_div').className = "buttonText";
		document.getElementById('report_pdf_download_div').innerHTML = "<A HREF=\"javascript: "+ document.getElementById('report_pdf_download_hdn_click').value +";\" class='buttonText'>"+ document.getElementById('report_pdf_download_hdn_text').value +"</A>";
	}
	
}


/* Function called to handle toggle the vendor invoice pdf download button from disabled to enabled */
function enableImageSubmitButton(form, mainColor)
{
	//if (document.getElementById('fileNameText').innerHTML != "")
	if (document.getElementById('image').value != "")
	{
		document.getElementById('imageSubmitButton_td').style.backgroundColor = mainColor;
		document.getElementById('imageSubmitButton_td').style.cursor = "pointer";
		document.getElementById('imageSubmitButton').onclick = function() { document.getElementById('updateItemDetails').submit(); };

		document.getElementById('imageSubmitButton_left_td').style.cursor = "pointer";
		document.getElementById('imageSubmitButton_left').onclick = function() { document.getElementById('updateItemDetails').submit(); };
		
		document.getElementById('imageSubmitButton_div').className = "buttonText";
		document.getElementById('imageSubmitButton_div').innerHTML = "<A HREF=\"javascript: "+ document.getElementById('imageSubmitButton_hdn_click').value +";\" class='buttonText'>"+ document.getElementById('imageSubmitButton_hdn_text').value +"</A>";
	}
}


/* Function called to handle toggle the vendor invoice pdf download button from disabled to enabled */
function enableLabelSubmitButton(form, mainColor)
{
	//if (document.getElementById('labelNameText').innerHTML != "")
	if (document.getElementById('imagelabel').value != "")
	{
		document.getElementById('labelSubmitButton_td').style.backgroundColor = mainColor;
		document.getElementById('labelSubmitButton_td').style.cursor = "pointer";
		document.getElementById('labelSubmitButton').onclick = function() { document.getElementById('updateItemLabel').submit(); };

		document.getElementById('labelSubmitButton_left_td').style.cursor = "pointer";
		document.getElementById('labelSubmitButton_left').onclick = function() { document.getElementById('updateItemLabel').submit(); };
		
		document.getElementById('labelSubmitButton_div').className = "buttonText";
		document.getElementById('labelSubmitButton_div').innerHTML = "<A HREF=\"javascript: "+ document.getElementById('labelSubmitButton_hdn_click').value +";\" class='buttonText'>"+ document.getElementById('labelSubmitButton_hdn_text').value +"</A>";
	}
}


/* Function called to handle toggle the vendor invoice pdf download button from disabled to enabled */
function enableIngredientSubmitButton(form, mainColor)
{
	//if (document.getElementById('ingredientlNameText').innerHTML != "")
	if (document.getElementById('imageingredient').value != "")
	{
		document.getElementById('ingredientSubmitButton_td').style.backgroundColor = mainColor;
		document.getElementById('ingredientSubmitButton_td').style.cursor = "pointer";
		document.getElementById('ingredientSubmitButton').onclick = function() { document.getElementById('updateItemIngredient').submit(); };

		document.getElementById('ingredientSubmitButton_left_td').style.cursor = "pointer";
		document.getElementById('ingredientSubmitButton_left').onclick = function() { document.getElementById('updateItemIngredient').submit(); };
		
		document.getElementById('ingredientSubmitButton_div').className = "buttonText";
		document.getElementById('ingredientSubmitButton_div').innerHTML = "<A HREF=\"javascript: "+ document.getElementById('ingredientSubmitButton_hdn_click').value +";\" class='buttonText'>"+ document.getElementById('ingredientSubmitButton_hdn_text').value +"</A>";
	}
}


/* This will toggle the display of a div, send "" if there is no image to change */
function showHideDiv(div, imageName)
{
	var visibility;
	var display;
	var imageSrcString;
	
	// Setup a visibility variable to toggle the visibility property to the opposite of its current value
	if (document.getElementById(div).style.visibility == "visible")
	{
		visibility = "hidden";
	}
	
	else
	{
		visibility = "visible";
	}     
	
	// Setup a display variable to toggle the display property to the opposite of its current value
	if (document.getElementById(div).style.display == "block")
	{
		display = "none";
	}
	
	else
	{
		display = "block";
	}                                      
	
	// Removed this because it doesn't seem necessary to check for the browser type
	/*
	// Check for Firefox
	if (navigator.appName == 'Netscape') 
	{
		if (navigator.userAgent.indexOf('Firefox') != -1)
		{
			document.getElementById(div).style.visibility = visibility;
			document.getElementById(div).style.display = display;
		}                                               
	}     
	*/

	document.getElementById(div).style.visibility = visibility;
	document.getElementById(div).style.display = display;

	if (imageName != "")
	{
		if (document.getElementById(div).style.visibility == "visible")
		{

			imageSrcString = "images/collapse.gif";
		}

		else
		{
			imageSrcString = "images/expand.gif";			
		}

		document.getElementById(imageName).src = imageSrcString;
	}
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will toggle all simular DIVs, DIVs in a group
//
// Parameters:
//
// action			"expand" or "collapse" all of the DIVs
// divGroup			first starting string of the group of DIVs that are related
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function toggleAllDiv(action, divGroup)
{
	var divs = document.getElementsByTagName('div');

	for (var i = 0; i < divs.length; i++) 
	{
		var div = divs[i];

		// Only toggle the DIVs that match the parameter descriptions, ignore the rest
		if (div.id.substring(0, divGroup.length) == divGroup)
		{
			if (action == "expand" && document.getElementById(div.id).style.visibility == "hidden")
			{
				showHideDiv(div.id, "toggleImageCategories" + div.id.substring(9, div.id.length));
			}

			else if (action == "collapse" && document.getElementById(div.id).style.visibility == "visible")
			{
				showHideDiv(div.id, "toggleImageCategories" + div.id.substring(9, div.id.length));
			}
		}
	}
}


// Used for the table elements <TR> in the menu
function toggleTRbody(id, imageName) 
{
	var trs = document.getElementsByTagName('tr');
	var imageSrcString;
	var keepmenuOption;

	for (var i = 0; i < trs.length; i++) 
	{
		var tr = trs[i];

		// Only toggle the TRs that match the parameter description, ignore the rest
		if (tr.id.substring(0, id.length) == id)
		{
			if (tr && typeof tr.className == 'string') 
			{
				if (tr.className == 'off') 
				{
					tr.className = 'on';
					imageSrcString = "images/collapse.gif";
					keepMenuOption = true;
				} 
				
				else 
				{
					tr.className = 'off';
					imageSrcString = "images/expand.gif";
					keepMenuOption = false;
				}
			}

			if (imageName != "")
			{
				document.getElementById(imageName).src = imageSrcString;
			}

			var expires = new Date();
			expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 
			document.cookie = id +'='+ keepMenuOption +'; expires='+ expires.toGMTString() +';';
		}
	}
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will toggle all simular DIVs, DIVs in a group
//
// Parameters:
//
// action			"expand" or "collapse" all of the DIVs
// divGroup			first starting string of the group of DIVs that are related
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function toggleAllTR(action, trGroup)
{
	var trs = document.getElementsByTagName('tr');
	var id;
	var menuSectionIdArray;
	var imageSrcString = "images/expand.gif";	// Default value needed in case the user clicks the "Hide All" before anything else

	for (var i = 0; i < trs.length; i++) 
	{
		var tr = trs[i];		

		// Only toggle the TRs that match the parameter descriptions, ignore the rest
		if (tr.id.substring(0, trGroup.length) == trGroup)
		{
			// Get the menu section ID for the individual TR	
			menuSectionIdArray = tr.id.split("_");
			id = menuSectionIdArray[0] +"_"+ menuSectionIdArray[1] +"_"+ menuSectionIdArray[2];

			if (action == "expand" && document.getElementById(tr.id).className == 'off')
			{
				toggleTRbody(id, "");
				imageSrcString = "images/collapse.gif";

				var expires = new Date();
				expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 
				document.cookie = id +'='+ true +'; expires='+ expires.toGMTString() +';';
			}

			else if (action == "collapse" && document.getElementById(tr.id).className == 'on')
			{
				toggleTRbody(id, "");
				imageSrcString = "images/expand.gif";

				var expires = new Date();
				expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 30));     //set it 30 days ahead 
				document.cookie = id +'='+ false +'; expires='+ expires.toGMTString() +';';
			}
		}
	}

	var imgs = document.getElementsByTagName('img');

	for (var i = 0; i < imgs.length; i++) 
	{
		var img = imgs[i];

		// Only toggle the IMGs that match the parameter descriptions, ignore the rest
		if (img.id.substring(0, trGroup.length + 12) == "toggleImage_" + trGroup)
		{
			document.getElementById(img.id).src = imageSrcString;
		}
	}
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will move the selected value from a select box as a comma delimited item of a text box.
// First used by the messaging system page to move an item from the contacts list to the "To" 
// part of a message when sending one.
//
// Parameters:
//
// select			the name of the select box element on the page
// text				the name of the text box element on the page
// formName			the name of the form the elements are in
// valueType		the attribute of the select box to copy over, "name" or "value"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function addSelectItemToTextbox(select, text, form, valueType)
{
	  selectList = eval('document.forms["'+ form +'"].' + select);
	  
	  for (i = 0; i < selectList.options.length; i++)
	  {
		var current = selectList.options[i];

		if (current.selected)
		{
		  txt = current.text;
		  val = current.value;
		  
		  if (document.getElementById(text).value != "")
		  {
			  document.getElementById(text).value += ", ";
		  }

		  if (valueType == "value")
		  {
			  document.getElementById(text).value += val;
		  }

		  else
		  {
			  document.getElementById(text).value += txt;
		  }		  
		}
	  }
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will clear the values in a text box
//
// Parameters:
//
// textBox			the name of the text box element on the page
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function clearTextbox(textBox)
{
	  document.getElementById(textBox).value = "";
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will do absolutely nothing, used to toggle the disabled buttons now that they are
// customizable
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function doNothing()
{
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will populate a div named fileNameText with the value fromt he hidden input box for 
// product image uploading
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function displayUploadedImageName() 
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);

	if (!W3CDOM) return;

	var x = document.getElementsByTagName('input');
	for (var i = 0; i < x.length; i++) 
	{
		if (x[i].type != 'file') continue;

		if (x[i].value != '' && document.getElementById('image').value != '')
			document.getElementById('fileNameText').innerHTML = document.getElementById('image').value;
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will populate a div named labelNameText with the value fromt he hidden input box for 
// product image uploading
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function displayUploadedLabelName() 
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);

	if (!W3CDOM) return;

	var x = document.getElementsByTagName('input');
	for (var i = 0; i < x.length; i++) 
	{
		if (x[i].type != 'file') continue;

		if (x[i].value != '' && document.getElementById('imagelabel').value != '')
			document.getElementById('labelNameText').innerHTML = document.getElementById('imagelabel').value;
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will populate a div named ingredientNameText with the value fromt he hidden input box for 
// product image uploading
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function displayUploadedIngredientName() 
{
	var W3CDOM = (document.createElement && document.getElementsByTagName);

	if (!W3CDOM) return;

	var x = document.getElementsByTagName('input');
	for (var i = 0; i < x.length; i++) 
	{
		if (x[i].type != 'file') continue;

		if (x[i].value != '' && document.getElementById('imageingredient').value != '')
			document.getElementById('ingredientNameText').innerHTML = document.getElementById('imageingredient').value;
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will clear out the default value of "**********" when the password field is clicked on
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function clearPassword(myfield)
{
	if (myfield.value == "**********")
	{
	   myfield.value = "";
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This will clear out the default value of "**********" when the password field is clicked on
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

window.onerror = null;
var menuActive = 0;
var menuOn = 0;
var onLayer = null;
var timeOn = null;
var aa = null;

function showLayer(layerName,aa)
{
	if (aa != '') 
	{
		hideLayer(aa);
	}

	if(document.getElementById)
	{
		var elementRef = document.getElementById(layerName);
		if((elementRef.style)&& (elementRef.style.visibility!=null))
		{
			elementRef.style.visibility = 'visible';
			elementRef.style.display = 'block';
		}
	}

	onLayer = layerName;
}

function hideLayer(layerName)
{
	if (menuActive == 0)
	{
		if(document.getElementById)
		{
			var elementRef = document.getElementById(layerName);

			if((elementRef.style)&& (elementRef.style.visibility!=null))
			{
				elementRef.style.visibility = 'hidden';
				elementRef.style.display = 'none';
			}
		}
	}
}

function btnTimer() 
{
	timeOn = setTimeout("btnOut()",600);
}

function btnOut(layerName)
{
	if (menuActive == 0)
	{
		hideLayer(onLayer);
	}
}

var item;

function menuOver(itemName,ocolor)
{
	item=itemName;
	itemName.style.backgroundColor = ocolor; //background color change on mouse over 
	clearTimeout(timeOn);
	menuActive = 1;
}

function menuOut(itemName,ocolor)
{
	if(item)
		itemName.style.backgroundColor = ocolor;

	menuActive = 0;
	timeOn = setTimeout("hideLayer(onLayer)", 100);
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Displays the freeze screen for loading data
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function FreezeScreen(msg) 
{
	// Remove the window scroll bars
	//window.document.body.scroll = 'no';

	//scroll(0,0);
    var outterPane = document.getElementById('FreezePane');
    var innerPane = document.getElementById('InnerFreezePane');
    if (outterPane) outterPane.className = 'FreezePaneOn';
    if (innerPane) 
	{
		innerPane.innerHTML = msg;
		innerPane.className = 'InnerFreezePane';
	}

	setDivToWindowSize('FreezePane');
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Displays the Quick Search Div
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function ShowQuickSearch() 
{
    var innerPane = document.getElementById('InnerFreezePane');
    if (innerPane) 
	{
		innerPane.className = 'InnerFreezePaneHidden';
	}

	var innerPane = document.getElementById('QuickSearchResultsPane');
    if (innerPane) innerPane.className = 'QuickSearchPaneOn';
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Displays the Quick Cart Div
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function ShowQuickCart() 
{
    var innerPane = document.getElementById('InnerFreezePane');
    if (innerPane) 
	{
		innerPane.className = 'InnerFreezePaneHidden';
	}

	var innerPane = document.getElementById('QuickCartResultsPane');
    if (innerPane) innerPane.className = 'QuickCartPaneOn';
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Hides the Quick Search Div
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function HideQuickSearch() 
{
    var innerPane = document.getElementById('QuickSearchResultsPane');
    if (innerPane) innerPane.className = 'QuickSearchPaneOff';

	var innerPane = document.getElementById('InnerFreezePane');
    if (innerPane) innerPane.className = 'InnerFreezePane';

    var outterPane = document.getElementById('FreezePane');
    if (outterPane) outterPane.className = 'FreezePaneOff';

	document.getElementById('InnerQuickSearchResultsPane').innerHTML = "";

	// Add Back the window scroll bars
	window.document.body.scroll = 'yes';
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Hides the Quick Cart Div
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function HideQuickCart() 
{
    var innerPane = document.getElementById('QuickCartResultsPane');
    if (innerPane) innerPane.className = 'QuickCartPaneOff';

	var innerPane = document.getElementById('InnerFreezePane');
    if (innerPane) innerPane.className = 'InnerFreezePane';

    var outterPane = document.getElementById('FreezePane');
    if (outterPane) outterPane.className = 'FreezePaneOff';

	document.getElementById('InnerQuickCartResultsPane').innerHTML = "";

	// Add Back the window scroll bars
	window.document.body.scroll = 'yes';
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Sets a given div to the current window size, height and width
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function setDivToWindowSize(divName)
{
	var outterPane = document.getElementById(divName);

	if (outterPane)
	{
		var windowDimensions = getWindowSize();

		outterPane.style.width = windowDimensions.width;
		outterPane.style.height = windowDimensions.height;
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Gets the current window size
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function getWindowSize()
{
	/*
	var viewportwidth;
	var viewportheight;	 

	// all but Explorer Mac
	if (document.body.scrollHeight > document.body.offsetHeight) 
	{
		viewportheight = document.body.scrollHeight; 
		viewportwidth = document.body.scrollWidth;
	}

	// Explorer Mac;
	else
	{
		viewportheight = document.body.offsetHeight; 
		viewportwidth = document.body.offsetWidth;
	}
	*/


	var iWidth = 0, iHeight = 0, iHeight2 = 0;

	// all but Explorer Mac
	if (document.documentElement && document.documentElement.clientHeight)
	{
       iWidth = parseInt(window.scrollWidth, 10);
       iHeight = parseInt(document.body.scrollHeight, 10);
	}

	// Explorer Mac
	else if (document.body)
	{
       iWidth = parseInt(document.body.offsetWidth, 10);
       iHeight = parseInt(document.body.offsetHeight, 10);
	   iHeight2 = parseInt(document.body.scrollHeight, 10);

	   if (iHeight2 > iHeight)
	   {
		   iHeight = iHeight2;
	   }
	}

	return {width:iWidth, height:iHeight};
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Change the background color of an element
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function changeElementBackgroundColor(elementName, colorName)
{
	elementName.bgColor = colorName;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function submitproposal(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
	document.getElementById('submitORsave').value = 'Submit Proposals'; 
	document.dealProposal.submit();
   return false;
   }
else
   return true;
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function grayCounterInputs(productId,promotionId)
{
	var formElements = new Array(	"proposalSamples_" + productId, "proposalPrice_" + productId, "proposalPoints_" + productId, "proposalOffInvoice_" + productId, "proposalBillBack_" + productId, 
									"proposalWhAllowance_" + productId, "proposalWhBillback_" + productId, "proposalWhPercent_" + productId, "proposalRtAllowance_" + productId, 
									"proposalRtBillback_" + productId, "proposalRtPercent_" + productId, "proposalCmAllowance_" + productId, "proposalCmBillback_" + productId, 
									"proposalCmPercent_" + productId, "proposalText_" + productId, "showBooth_" + productId);

	var formElement;

	for (var i = 0; i < formElements.length; i++) 
	{
		formElement = formElements[i];

		if (document.getElementById(formElement))
		{
			document.getElementById(formElement).disabled = true; 
			document.getElementById(formElement).bgColor = "#dddddd";
		} 
	}

	var shipweekBoxName = "";

	for (var i = 0; i < 20; i++) 
	{
		shipweekBoxName = "product_shipdate_" + promotionId + "_" + productId + "["+ i +"]"

		if (document.getElementById(shipweekBoxName))
		{
			document.getElementById(shipweekBoxName).disabled = true; 
			document.getElementById(shipweekBoxName).bgColor = "#dddddd"; 
		}
	}

	return true;
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function ungrayCounterInputs(productId,promotionId)
{
	var formElements = new Array(	"proposalSamples_" + productId, "proposalPrice_" + productId, "proposalPoints_" + productId, "proposalOffInvoice_" + productId, "proposalBillBack_" + productId, 
									"proposalWhAllowance_" + productId, "proposalWhBillback_" + productId, "proposalWhPercent_" + productId, "proposalRtAllowance_" + productId, 
									"proposalRtBillback_" + productId, "proposalRtPercent_" + productId, "proposalCmAllowance_" + productId, "proposalCmBillback_" + productId, 
									"proposalCmPercent_" + productId, "proposalText_" + productId, "showBooth_" + productId);

	var formElement;

	for (var i = 0; i < formElements.length; i++) 
	{
		formElement = formElements[i];

		if (document.getElementById(formElement))
		{
			document.getElementById(formElement).disabled = false; 
			document.getElementById(formElement).bgColor = "#ffffff";
		} 
	}
	
	var shipweekBoxName = "";

	for (var i = 0; i < 20; i++) 
	{
		shipweekBoxName = "product_shipdate_" + promotionId + "_" + productId + "["+ i +"]"

		if (document.getElementById(shipweekBoxName))
		{
			document.getElementById(shipweekBoxName).disabled = false; 
			document.getElementById(shipweekBoxName).bgColor = "#ffffff"; 
		}
	}

	return true;
}

function grayNewProductComment(productId)
{
if (document.getElementById("newCommentText_" + productId))
{
	document.getElementById("newCommentText_" + productId).disabled = true; 
	document.getElementById("newCommentText_" + productId).bgColor = "#dddddd"; 
}
return true;
}

function ungrayNewProductComment(productId)
{
if (document.getElementById("newCommentText_" + productId))
{
	document.getElementById("newCommentText_" + productId).disabled = false; 
	document.getElementById("newCommentText_" + productId).bgColor = "#ffffff"; 
}
return true;
}



// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}

	return vars;
}