// submits a form
function submitForm(theForm, actionProperty) {
	
	if (theForm.actionName && actionProperty)
	{
	    setActualValue(theForm,actionProperty);
		theForm.actionName.value = actionProperty;
	}
	if (theForm.formPreviousPage)
	{
		var currentUrl = window.location.href;
    	var formPreviousPage = base64Encode(currentUrl);
    	theForm.formPreviousPage.value = formPreviousPage;
	}
	theForm.submit();
}

function selectUltimateDestination(theForm) 
{
	var value = theForm.ultimateDestination.value;
	var page = getPreviousPage();
	var url = "/ultimatedestination.do?ultdest="+value+"&page="+page;
	window.location.replace(url);
}

function selectUltimateDestinationAjax (theForm, callbackSuccess, callbackFailure) {
	var value = theForm.ultimateDestination.value;
	var page = getPreviousPage();
	var url = "/ultimatedestination.do?ultdest="+value+"&page="+page;
	
	new Ajax.Request(url , {
		method: 'get',
		onComplete: callbackSuccess, 
		onFailure: callbackFailure
	});
}

function getProductPricing(skuCss, priceCss) 
{
	if (!skuCss)
	{
		skuCss = ".sku";
	}
    var skus = $$(skuCss);
    var skuList = "";
    if (skus) 
    {
        for (var i = 0; i < skus.length; i++)
        {
            skuList += skus[i].innerHTML
            if (i < skus.length - 1)
            {
                skuList += ";";
            }
        }
        if (!priceCss)
        {
            priceCss =".price";
        }
        new Ajax.Request(adjustRelativePath() + "/pages/home/searchresults/display_product_price.jsp", {
            onSuccess : displayProductPricing,
            onFailure : displayProductPricingError,
            parameters : { skus:skuList,'priceCss':priceCss }
        });
    }
}

function displayProductPricing(resp) 
{
	var priceData = resp.responseText.split("|");
    var prices = $$(priceData[0]);
    var priceList = priceData[1].split(";");
    for (var i = 0; i < prices.length; i++) 
    {
        prices[i].innerHTML = priceList[i];
    }
}

function displayProductPricingError(resp) 
{
	var priceData = resp.responseText.split("|");
    var prices = $$(priceData[0]);

    for (var i = 0; i < prices.length; i++) 
    {
    	var id = "will_quote_" + Math.random();
        prices[i].innerHTML = '<div id="' + id + '"></div>';
    	getTranslation(id, "will_quote");
    }
}

function getTranslation(divId, key, dbName, args, sepToken, isMultiValue, alt)
{
	var paramStr = "";
	if (dbName) { paramStr += "&dbName=" + dbName; }
	if (args) { paramStr += "&args=" + args;}
	if (sepToken) { paramStr += "&sepToken=" + sepToken; }
	if (isMultiValue) { paramStr += "&isMultiValue=" + isMultiValue; }
	if (alt) { paramStr += "&alt=" + alt; }
	
	new Ajax.Updater(divId, adjustRelativePath() + "/pages/home/translate.jsp?key=" + key + paramStr, {});
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
		{ 
		    return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function setActualValue(form,act)
{
	 if(act && act == 'cart_delete_items')
	 {
		var allQty = form.disp_quantity;
		if (typeof(allQty.length)!="undefined")
		{
			for(var i=0; i<allQty.length; i++)
			{
				singleQty = allQty[i].value;
				if(singleQty.indexOf(',')>0)
				{
					form.quantity[i].value = getVal(singleQty)
				}
				else
				{
					form.quantity[i].value = singleQty;
				}
			}
		}
		else
		{
		 	singleQty = form.disp_quantity.value;
			if(singleQty.indexOf(',')>0)
			{
				form.quantity.value = getVal(singleQty)
			}
			else
			{
				form.quantity.value = singleQty;
			}
		}
	 }
}

function isArray(obj)
{
	return obj &&
		typeof obj === 'object' &&
		typeof obj.length === 'number' &&
		typeof obj.splice === 'function' &&
		!(obj.propertyIsEnumerable('length'));
}

function getVal(val)
{
	 var temp = val.split(',');
	 var num = "";
	 for(var i=0;i<temp.length;i++)
	 {
	  num+=temp[i];
	 }
	 
	 return num;
}

function codeDisplay(display,id)
{
if (display=='show'){
document.getElementById(id).style.display="block";
}else if (display=='hide'){
document.getElementById(id).style.display="none";
}
}

function classSwitch(obj,fromClass,toClass)
{
	removeClass(obj,fromClass);
	addClass(obj,toClass);
}

// Use Billing as Shipping
function ConvertAllFields(form) {
  if (form.SameAddress.checked) {
	form.SameAddress.value = "1"
    form.shipToContactName.value = form.billToContactName.value
    form.shipToContactPhone.value = form.billToContactPhone.value
    form.shipToContactEmail.value = form.billToContactEmail.value
	form.buildingShipping.value = form.buildingBilling.value
	form.departmentShipping.value = form.departmentBilling.value
	form.address1Shipping.value = form.address1Billing.value
	form.address2Shipping.value = form.address2Billing.value
	form.cityShipping.value = form.cityBilling.value
	form.stateShipping.value = form.stateBilling.value
	form.zipShipping.value = form.zipBilling.value
	form.countryShipping.selectedIndex = form.countryBilling.selectedIndex
  }
  else {
	form.shipToContactName.value = ""
	form.shipToContactPhone.value = ""
	form.shipToContactEmail.value = ""
    form.buildingShipping.value = ""
  	form.departmentShipping.value = ""
	form.address1Shipping.value = ""
	form.address2Shipping.value = ""
	form.cityShipping.value = ""
	form.stateShipping.value = ""
	form.zipShipping.value = ""
	form.countryShipping.value=""
	form.countryShipping.selectedIndex = ""
  }
}
 
// Removes leading whitespaces
function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}
// Removes ending whitespaces
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}
// Removes leading and ending whitespaces
function trim( value ) {	
	return LTrim(RTrim(value));	
}

function toggleLayer( whichLayer ) {
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
	elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
	  elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
	elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function toggleDisplay (twistyAnchor, displayDiv, alternateText)
{
	var anchor = $(twistyAnchor);
	anchor.toggleClassName('open');
	anchor.toggleClassName('closed');
	if (alternateText)
	{
		var current = anchor.innerHTML;
		if (anchor.alternate)
		{
			alternateText = anchor.alternate;
		}
		anchor.alternate = current;
		anchor.update(alternateText);
	}
	$(displayDiv).toggle();
}

function billingchk()
{ if(document.getElementById("billing_fields") != null)
		{ toggleBillingFields(); }
		
}

// parses a string in mm/dd/yyyy format and converts to date object
function parseSimpleDate(dateStr)
{
	if (typeof dateStr === 'string' && dateStr.length > 0)
	{
		var date = new Date();
		var dateRA = dateStr.split("/");
		date.setMonth(dateRA[0] - 1); // months start at 0... e.g. January = 0, February = 1, etc.
		date.setDate(dateRA[1]);
		date.setYear(dateRA[2]);
		return date;
	}
}

// determine if a date falls between a start and end date.  If either
// the start or end date are undefined then they are considered to be
// infinitely far in the past for start date or infinitely far in the
// future for end date
function dateInRange(date, start, end)
{
	var result = false;
	if (!start && !end)
	{
		result = true;
	}
	else if (!start)
	{
		result = date < end;
	}
	else if (!end)
	{
		result = date > start;
	}
	else
	{
		result = date > start && date < end;
	}
	return result;
}

// makes a request to a URL and writes the response
// to the specified callback function
function callUrl(url, callbackFunction) {
	var req = getXMLHTTPRequest();
	req.onreadystatechange = callbackFunction;	
	req.open("GET", url, true);	
	req.send(null);
}

function callUrlWithRequest(requestObject, url, callbackFunction) {
	requestObject.onreadystatechange = callbackFunction;	
	requestObject.open("GET", url, true);	
	requestObject.send(null);
}

function callUrlWithRequestPost(url, urlparams, menuName, callback) {
		var ajax = new Ajax.Updater(menuName, url,
				 {
					method: 'post',
					postBody: urlparams,
					parameters: urlparams,
					onComplete: callback
				 }
		);
}

// get the URL up to the hash (#) for the URL specified or the
// current page URL if not specified.  This method is used for
// Ajax back-button issues
function getBaseURL(url)
{
    var baseUrl = url;
    if (!baseUrl)
    {
        baseUrl = window.location.href;
    }
    
    var hashIndex = baseUrl.toString().indexOf("#");
    if (hashIndex > 0)
    {
        baseUrl = baseUrl.toString().substring(0, hashIndex);
    }
    return baseUrl;
}

// returns the parsed components of a URL
function parseUrl(url)
{
	if (!url)
	{
		url = window.location.href;
	}
	
	var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
	var result = parse_url.exec(url);

	var output = new Object();
	output.url = result[0];
	output.scheme = result[1];
	output.slash = result[2];
	output.host = result[3];
	output.port = result[4];
	output.path = result[5];
	output.query = result[6];
	output.hash = result[7];
	return output;
}

function getUrlParams(url)
{
	var query = parseUrl(url).query;
	if (query)
	{
		return query.split('&');
	}
}

function getUrlParamValues(url, param)
{
	var values = new Array();
	var params = getUrlParams(url);
	if (params)
	{
		for (var i = 0; i < params.length; i++)
		{
			var nextParam = params[i].split("=");
			if (nextParam[0] == param)
			{
				values[values.length] = nextParam[1];
			}
		}
	}
	return values;
}

// This method gets the current state encoded in the URL
function getCachedState(url)
{
	var hash = parseUrl(url).hash
	return hash ? hash : "";
}

// This method gets the current state encoded in the URL as an 
// array of sate variables
function getCachedStateArgs(url)
{
	var args = new Array();
	var state = getCachedState(url);

	if ("" != state)
	{
		args = state.split(":");
	}
	
	return args;
}

function getTabIndex(url)
{
	var index = 0;
    var stateArgs = getCachedStateArgs(url);
    if (stateArgs && stateArgs.length > 0)
    {
        index = 1 * stateArgs[0];
    }

    return index;
}

function setParams(params, values, url)
{
	var base = getBaseURL(url);
	var state = getCachedState(url);
	
	if (typeof params === "string")
	{
		params = [params];
		values = [values];
	}
	if (isArray(params))
	{
		for (var i = 0; i < params.length; i++)
		{
			var regex = new RegExp("[&?]" + params[i] + "=[^&]*");
			var matches = base.match(regex);
			if (matches != null && matches.length > 0)
			{
				if (matches[0].charAt(0) === '?')
				{
					base = base.replace(regex, "?" + params[i] + "=" + values[i]);
				}
				else
				{
					base = base.replace(regex, "&" + params[i] + "=" + values[i]);
				}
			}
			else
			{
				if (base.indexOf("?") > -1)
				{
					base = base + "&" + params[i] + "=" + values[i];
				}
				else
				{
					base = base + "?" + params[i] + "=" + values[i];
				}
			}
		}
	}
	if (state && state.length > 0)
	{
		base = base + "#" + state;
	}
	return base;
}

function adjustRelativePath()
{
	var adj = "";
	var path = parseUrl().path;
	var lvls = path.split("/").length - 1;
	for (var i = 0; i < lvls; i++)
	{
		if (i > 0)
		{
			adj = adj + "/";
		}
		adj = adj + "..";
	}
	return adj;
}

// shows a loading message
// we should probably replace this with something nicer later
function showLoadingMessage(id) {
	document.getElementById(id).innerHTML = "Loading...";
	getTranslation(id, "loading");
}

// shows a loading message
// we should probably replace this with something nicer later
function showErrorMessage(id) {
	document.getElementById(id).innerHTML = "An error occurred while obtaining this data.";
}

/*
 *  ORIGINAL (NON-MODAL) ADD-TO-CART

function addToCart(sku, qty, returl, fromWhere) {
	var url = "/ec/order.do?item=" + sku;
	if (sku){
		if (returl) {
			url = url + "&cartPrevious=" + returl;
		}
		if (qty) {
			url +=  "&qty=" + qty; 
		}
		if (fromWhere) {
			url += "&fromWhere=" + fromWhere;
		}
		window.location.replace(url); 
	}
}
*/

/*
 * NEW (MODAL) ADD-TO-CART -- postponed to SPRINT 4
 *
 **/
function addToCart(sku, qty, returl, fromWhere) {
	indicatorShow();
	new Ajax.Request('/ec/order.do', {
        method : 'post',
        parameters: { 'item': sku,
                      'qty' : qty,
                      'fromWhere': fromWhere,
                      'usingAjax': 'true'},
        onComplete: function(transport) {
            $('modal_loading').hide();
            var errorMsg = "A server error occured.  Please try again later."
            if (transport.status == 200) {
                result = transport.responseJSON;
                if (result.status == 'ok') {
                	viewSiteModalMini("/pages/catalogue/added_to_cart.jsp");
                } else {
                	if (result.status && result.status.split("|").length > 1){
                		errorMsg = result.status.split("|")[1];
                	}
                	viewSiteModalMini("/pages/home/error_modal.jsp?errormsg=" + errorMsg);
                }
            } else {
            	viewSiteModal("/pages/home/error_modal.jsp?errormsg=" + errorMsg);
            }
        }
    });
}

function indicatorShow() {
	
	var indicator  = $('modal_loading');
	var container_dimensions = indicator.getDimensions();
	var viewport_clientHight = document.body.clientHeight;
	Position.prepare();
	var offset_top = (Position.deltaY + ((viewport_clientHight > container_dimensions.height) ? Math.floor((viewport_clientHight - container_dimensions.height) / 2) : 0));
	
	indicator.setStyle({
		top: (container_dimensions.height <= viewport_clientHight) ? ((offset_top != null && offset_top > 0) ? offset_top : 0) + 'px' : 0
	});	
	indicator.show();
	
}

// opens pop window
function openpopWindow(theURL,winName,features) {
    w = window.open(theURL,winName,features);
    w.focus();
}

// key vector for base 64 encoding/decoding
var key64Vec = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

// encode a string to base 64
// Based on public domain code written by Tyler Akins -- http://rumkin.com
function base64Encode(input)
{
   var output = "";
   var chrX, chrY, chrZ;
   var enc1, enc2, enc3, enc4;
   var i = 0;
     
   do 
   {
      chrX = input.charCodeAt(i++);
      chrY = input.charCodeAt(i++);
      chrZ = input.charCodeAt(i++);

      enc1 = (chrX >> 2) & 63;
      enc2 = ((chrX & 3) << 4) | ((chrY >> 4) & 15);
      enc3 = ((chrY << 2) & 63) | ((chrZ >> 6) & 3);
      enc4 = chrZ & 63;

      if (isNaN(chrY)) 
      {
         enc3 = enc4 = 64;
      } 
      else if (isNaN(chrZ)) 
      {
         enc4 = 64;
      }

      output = output + key64Vec.charAt(enc1) + key64Vec.charAt(enc2) + 
         key64Vec.charAt(enc3) + key64Vec.charAt(enc4);
   } 
   while (i < input.length);
   return output;
}

// decode a base 64 string
// Based on public domain code written by Tyler Akins -- http://rumkin.com
function base64Decode(input) 
{
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do 
   {
      enc1 = key64Vec.indexOf(input.charAt(i++));
      enc2 = key64Vec.indexOf(input.charAt(i++));
      enc3 = key64Vec.indexOf(input.charAt(i++));
      enc4 = key64Vec.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) 
      {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) 
      {
         output = output + String.fromCharCode(chr3);
      }
   } 
   while (i < input.length);
   
   return output;
}

	
	// test search term and submits the form
	var mainSearch = function() {
	  var theForm = document.search;
	  var searchvalue = trim(theForm.q.value);
	  if ( searchvalue == "" ) {
	    alert("Please enter a search keyword.");
	    theForm.q.focus();
	  } else {
	  	theForm.submit();
	  }
	}
	
	// test search term by Category 
	 var searchByCat = function(){
	  var theForm = document.search;
	  var searchvalue = trim(theForm.q.value);
	  var searchCat = theForm.tabValue;
	  var index = searchCat.selectedIndex ;
	  var tabVal = searchCat[index].value;
	  if(tabVal)
	  {
	   theForm.action = "/search.do";
	  }
	  theForm.submit();
	 }

	 var addItem = function(form,id,nameDisplayFlag){
		  
		  var theForm = form;
		  var sku = getSKU(form,id);
		  document.getElementById(id).value = sku;		  
		  submitForm(form,'cart_detail_addpart_text');
		 }
	 
	 var getSKU = function(form,id){
		  var theForm = form;
		  var selectedString = document.getElementById(id).value;
		  var index = selectedString.indexOf(":");
		  var sku = selectedString.substring(0, index);
		  //document.getElementById(id).value = sku;
		  return sku;
	 }
	 
	 // Helper function to get index of an element  
	 function getIndex(input) {
		    var index = -1, i = 0, found = false;
		    while (i < input.form.length && index == -1)
		    if (input.form[i] == input)index = i;
		    else i++;
		    return index;
		  }
		  
	 
	// user selected string has SKU and name. Parse 
	// it to get only the SKU
	 var displaySKU = function(form,id,displayNameFlag){
		 //alert ('keyCode is ' + g_listKeyCode);
		 //alert ( 'selected key is ' + g_notSelected);

		  var theForm = form;
		  var selectedString = document.getElementById(id).value;
		  var index = selectedString.indexOf(":");
		  var sku = selectedString.substring(0, index);

		  document.getElementById(id).value = sku;
		  /*form[(getIndex(document.getElementById(id))+1) % 
		       document.getElementById(id).form.length].focus();*/		  
		  if (displayNameFlag == true){
			  form.productName.value = 
				  selectedString.substring(index+1, selectedString.length);
		  }
		}

	 
	 var setCallBackParametersForSearch = function(id, value){
		 
		 // append the userInput
		 // append the view
		 // append the search key
		 // set the getDisplay flag
		 //append the language
		 var language = readCookie("lang");
		 var searchKey = language + "linktext";
		 var inputText = id.value;
		 var queryString = value+"&userInput=" +id.value + 
		 					"&view=qtcdatasppublished"+ 
		 					"&searchKey="+searchKey+
		 					"&getDescription=false"+ 
		 					"&language=" + language;
		 
		 // build fast query list 

		 var fastQueryString = "QUERY-and(meta.collection:\"TypeAhead\",navdoctype:\"TD\",moduleid:\"product_names\",enlinktext:starts-with(\""+inputText+"*\"))";
		 fastQueryString = fastQueryString + "QUERY-and(meta.collection:\"TypeAhead\",moduleid:\"product_types\"," + searchKey + ":starts-with(\""+inputText+"*\"),navdoctype:TD)";
		 fastQueryString = fastQueryString + "QUERY-and(meta.collection:\"TypeAhead\",moduleid:\"product_applications\"," + searchKey + ":starts-with(\""+inputText+"*\"),navdoctype:TD)";
		 if ( language != 'null' && (language == 'en' || language == 'EN')){
			 fastQueryString = fastQueryString + "QUERY-and(" + searchKey + ":starts-with(\""+inputText+"*\"),navdoctype:LC)";
		 }
		 fastQueryString = fastQueryString + "QUERY-and(meta.collection:\"TypeAhead\",moduleid:\"proteins\",enlinktext:starts-with(\""+inputText+"*\"),navdoctype:TD)"
		 // append the queries		 
		 queryString = queryString+"&queries=" + fastQueryString ;		 
		 //alert("FINAL QUERY is " + queryString);
		 return queryString;
	 }
	 
	 var setCallBackParametersForCatalogNumber = function(id, value){
		 
		 // append the userInput
		 // append the view
		 // append the search key
		 // set the getDisplay flag
		 //append the language
		 var language = readCookie("lang");
		 var queryString = value+"&userInput=" +id.value + 
		 					"&view=searchdatasppublished"+ "&searchKey=sku"+
		 					"&getDescription=true"+ 
		 					"&language=" + language;
		 
		 // build fast query list 

		 var fastQueryString = 
			 "QUERY-and(meta.collection:\"catalogue\",navdoctype:\"PC\",language:"
   		  + "\"" + language + "\"" + ",sku:starts-with(\""
		  + id.value+"*\"))";

		 // append the queries		 
		 queryString = queryString+"&queries=" + fastQueryString ;		 
		 //alert("FINAL QUERY is " + queryString);
		 return queryString;
	 }
	 
	 
	// get the previous page
	function getPreviousPage() 
	{
		var previousPage;
		var theForm = document.previouspage;
		if (theForm)
		{
		    previousPage = theForm.previousPage.value;
		}
		else
		{
		    // get the current URL
		    var currentURL = window.location.href;
		  
		    // strip off the domain
		    var loc = currentURL.replace(/https?:\/\/[\w\-]+\.millipore\.com/, "");
		    
		    // encode the location
			previousPage = base64Encode(loc);
		}
		return previousPage;
	}
	
	// set the previous page
	function setPreviousPage() 
	{
	    var theForm = document.previouspage;
	    if (theForm)
	    {
	  	    theForm.previousPage.value = previousPage;
	    }
	}
	
	// recalculate the previous page to account for AJAX manipulations
	// of the URL to preserve state info
	function recalculatePreviousPage()
	{
		var theForm = document.previouspage;
		if (theForm)
	    {
	    	// get the current URL
	    	var currentURL = window.location.href;
	    
	    	// strip off the domain
	        var loc = currentURL.replace(/https?:\/\/[\w\-]+\.millipore\.com/, "");
	        
	        // base 64 encode the location and save it to the previousPage hidden input
		    theForm.previousPage.value = base64Encode(loc);
	    }
	}
	
	function doOnEnter(evt, fnct, args) {
	
	  if (!fnct)
	  {
	  	fnct = searchByCat;
	  }
	  if(window.event)  // IE
	    {
		 if (evt.keyCode == 13 ) 
		 {
		   fnct(args);
		 }
		} 
	  else if(evt.which) // Netscape/Firefox/Opera
		{
		 if (evt.which == 13)
		  {
		    fnct(args); 
	    }
		}	 
	}
	
	function doSubmit(evt,evButton) {
	
	  if(window.event)  // IE
	    {
		 if (evt.keyCode == 13 ) 
		 {
		   document.getElementById(evButton).click();
		 }
		} 
	  else if(evt.which) // Netscape/Firefox/Opera
		{
		 if (evt.which == 13)
		  {
		    document.getElementById(evButton).click();
	      }
		}	 
	}
		
	function addWildcard(inputBox)
    {
        // This was a quick-and-dirty fix for T-071127-0501: Antibody Search needs to wildcard results - SWR
        var entered = inputBox.value;
        if (entered.length > 0 && entered.charAt(entered.length - 1) != '*' && entered.charAt(entered.length - 1) != '"')
        {
            inputBox.value = entered + "*";
        } 
    }
	

	function disableRightClick(e) {
		var rightClickIE = function (){
			if (event.button==2){
				return false;
			}
		}
		var rightClickNS = function (e) {
			if (document.layers||document.getElementById&&!document.all){
				if (e.which==2||e.which==3){
					return false;
				}
			}
		}
		if (document.layers){
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown=rightClickNS;
		}
		else if (document.all&&!document.getElementById){
			document.onmousedown= this.rightClickIE;
		}
		
		document.oncontextmenu=new Function("return false")
	}
	
	
	printModal = function(id) {
		var divId = id;
	    var theForm = document.printMe;
	    var printText = theForm.printText;
	    var winfeatures = "width=550,height=500,scrollbars=yes,resizable=yes,menubar=no,location=yes,status=no,toolbar=no";
	    var text = $(divId).innerHTML;
	    printText.value = text;
	    theForm.submit();
	}