	/* _enterprise mod 0811090543 - don't permit PO boxes to be selected or entered as a shipping address during checkout - tell them to call customer service # */
		var Enterprise = {
			noPOBoxesMessage: 'Sorry, UPS does not ship to PO boxes. Please either adjust your street address, or please contact customer service to ship by alternate means.',

			IsAPOBox: function(address)	//called below at two points in the code: 1. after selection of an existing address, 2. after entry of a new address
			{
				//var regPOBox =/((\b[G|g][p|P][o|O|0])|(\b[a|A][p|P][o|O|0])|(\b[f|F][p|P][o|O|0])|(\b[P|p]([o|O|0][s|S][t|T])?\.?\s?[O|o|0]([f|F][f|F][i|I][c|C][e|E])?([S|s][T|t][A|a][L|l])?\.?)\b|([B|b][O|o|0][X|x]))\s?(\d+)/i; 
                //var regPOBox = /((\bPrivate bag)|(\b[D|F|G|A]P[O|0])|(\bP([o|0]st)?\.?\s?[O|o|0](ffice)?([S|s][T|t][A|a][L|l])?\.?)\b|(B[o|0]x))\s?(\d+)/i;
                //var regPOBox = /\b[(]?(abonenty yashik|Apdo|AA|BP|Buzon|CP|Casilla|Apartado|Apartado de Correos|Apartado Aereo|Apartat|Apartat de Correus|Boite Privee|Bosca Poist|Bureau de Poste|Case Postale|Casella Postale|Casilla de Avonados|Casilla de Correos|Casilla Correo|Codi Postale|Entrega General|Kaxxa Postali|Kutia Postare nr|Kotak Pos|Casuta Postala|PO Private|pastas|bag|[D|F|G|A]P[O|0]|(P([o|0]st)?\.?\s?[O|o|0](ffice)?([S|s][T|t][A|a][L|l])?\.?)|(B[o|0]x))[)]?\s*\d+[)]?/i;
                var regPOBox = /\b[(]?(abonenty yashik|Apdo|AA|BP|Buzon|CP|Casilla|Apartado|Apartado de Correos|Apartado Aereo|Apartat|Apartat de Correus|Boite Privee|Bosca Poist|Bureau de Poste|Case Postale|Casella Postale|Casilla de Avonados|Casilla de Correos|Casilla Correo|Codi Postale|Entrega General|Kaxxa Postali|Kutia Postare nr|Kotak Pos|Casuta Postala|PO Private|pastas|bag|[D|F|G|A]P[O|0]|(P([o|0]st)?\.?\s?[O|o|0](ffice)?([S|s][T|t][A|a][L|l])?\.?)|(B[o|0]x))[)]?[)]?\s+/i;
				return (address.search(regPOBox) > -1);
			}
		};
	/* _enterprise_end */
	
	/* _enterprise mod 0730091011 - add tell a friend functionality to the product page */
		function newWindow(mypage,myname,w,h,features) {

		  if(screen.width){
			  var winl = (screen.width-w)/2;
			  var wint = (screen.height-h)/2;
		  } else {winl = 0;wint =0;}
		  if (winl < 0) winl = 0;
		  if (wint < 0) wint = 0;
		  var settings = 'height=' + h + ',';
		  settings += 'width=' + w + ',';
		  settings += 'top=' + wint + ',';
		  settings += 'left=' + winl + ',';
		  settings += features;
		  win = window.open(mypage,myname,settings);
		  win.window.focus();
		}

		/* Modified to support Opera */
		function bookmarksite(title,url){
			if (window.sidebar) // firefox
				window.sidebar.addPanel(title, url, "");
			else if(window.opera && window.print){ // opera
				var elem = document.createElement('a');
				elem.setAttribute('href',url);
				elem.setAttribute('title',title);
				elem.setAttribute('rel','sidebar');
				elem.click();
			}
			else if(document.all)// ie
				window.external.AddFavorite(url, title);
		}
	/* _enterprise_end */

	/* _enterprise mod 0118100603 - automatically retry failed calls again */
		$(document).ready(function(){
			if (typeof(ExpressCheckout) != 'undefined') {

				/**
				 *	Support settings for ajax calls:
				 *		retryLimit = number of retries to permit
				 *		reportErrorsToAdmin = whether to report ajax error details to an admin if all retries fail (we're forecd to ultimately give up)
				 *  	countErrorsInStats =  whether to report the error for stats purposes if all retries fail
				 *		alertUsersIfAllRetriesFail = whether to show javascript alert to user if all retries fail 
				 ***/
				ExpressCheckout.TryToResubmit = function(request, settings) 
				{
					// determine how many times we're allowed to retry the request (default is 2), and incremement how many we've done so far. Specify a value for retryLimit in your $.ajax settings if you want a different value
					if (typeof settings.retryLimit=='undefined') {
						settings.retryLimit = 2; 
					}
					if (typeof settings.retryCount=='undefined') {
						settings.retryCount = 0;
					}
					settings.retryCount++;

					// if we're still below the retry limit, try the call again; otherwise give up and do appropriate error handling
					if (settings.retryCount <= settings.retryLimit) {
						settings.data += '&retrycount='+settings.retryCount;
						$.ajax(settings);
						return;
					}

					/* _enterprise mod 0625102317 */
						//unless told otherwise, incremement stats for this error (true by default)
						if (typeof(settings.countErrorsInStats)=='undefined' || settings.countErrorsInStats!=false) {
							errorcategory = 'Other';
							if (typeof(ExpressCheckout)!='undefined') {
								errorcategory = ExpressCheckout.currentStep;
							}
							$.ajax({type: 'POST', url: 'index.php', data:{incstatmetricid:'AjaxErrors'+errorcategory}, retryLimit: 0, countErrorsInStats: 0, reportErrors: false});
						}
					/* _enterprise_end */
					
					/* _enterprise mod 0111102018 */		
						//unless told otherwise, report the error to an admin after the number of retries have been exhausted (true by default)
						if (typeof(settings.reportErrorsToAdmin)=='undefined' || settings.reportErrorsToAdmin!=false) 
						{
							var info =  "response.status" + request.status + request.statusText + "<br />" +
										"settings.url" + settings.url + "<br />" +
										"settings.retryLimit" + settings.retryLimit + "<br />" +
										"settings.retryCount" + settings.retryCount + "<br />";											

							if (settings.data.indexOf('_ccno=') < 0) {
								info += "request.data" + settings.data + "<br />";
							}
							ReportCheckoutAJAXError(info);
						}
					/* _enterprise_end */

					//unless told otherwise, report the error to the user (true by default)
					if (typeof(settings.alertUsersIfAllRetriesFail)=='undefined' || settings.alertUsersIfAllRetriesFail!=false) {
						alert(lang.ExpressCheckoutLoadError);
					}
				};
			};
		});
	/* _enterprise_end */
	
	/* _enterprise mod 0925091507 - add ability to edit existing addresses during express checkout */
		function EditCheckoutAddress(selectid) {
			id = $(selectid).val();
			if (id) {
				window.location = '/account.php?action=edit_shipping_address&address_id='+id+'&from=checkout.php'; //note: assumes we're already using https://			
			}
		}
		function DeleteCheckoutAddress(selectid) {
			id = $(selectid).val();
			if (id && confirm("Are you sure you want to delete this address?")) {
				window.location = '/account.php?action=delete_shipping_address&address_id='+id+'&from=checkout.php'; //note: assumes we're already using https://			
			}
		}
		$(document).ready(function() {
			$('html').ajaxStart(function() {
				$('.sectionbutton').attr('disabled', 'disabled');
			});

			$('html').ajaxComplete(function() {
				$('.sectionbutton').removeAttr('disabled');
			});
		});
	/* _enterprise_end */

	/* _enterprise mod 1006090102 */
		$(document).ready(function() {
			if (window.location.toString().indexOf('#write_review') > 0 && typeof show_product_review_form == 'function') { 
				show_product_review_form();
				if ($.fn.scrollTo) {
					$.scrollTo('#write_review', {offset:-35, duration:500});
				}
			}
		});
	/* _enterprise_end */
	
	/* _enterprise mod 1218090337 - replace no rating image with link enabling them to rate it */
		$(document).ready(function() {
			$('.Rating0:has(img:visible)').each(function (i) {
				prodlink = $(this).parent().parent().find('a:first').attr('href');
				if (typeof prodlink!=undefined) {	
					if (window.location.toString().indexOf(prodlink) < 0) {
						$(this).html('<a href="'+prodlink+'#write_review?">Be the first to rate this product</a>');
					}
					else {
						$(this).html('<a href="&nbsp" onclick="show_product_review_form();if($.fn.scrollTo) {$.scrollTo(\'#write_review\', {offset:-35, duration:500});};return false;">Be the first to rate this product</a>');
					}
				}
			});			
		});
	/* _enterprise_end */

	/* _enterprise mod 1218090431 - adstream - specify OAS_sitepage, OAS_url, OAS_listpos, and OAS_query before calling OAS_AD below */
	        var OAS_sitepage = document.URL.replace('http://','').replace('https://','');
	        var OAS_url = 'http://oasc04011.247realmedia.com/RealMedia/ads/';
	        var OAS_listpos = 'Top,Left,Right';
	        var OAS_query = document.URL; //recommendation from adstream to set this to blank
	
		var OAS_target = '';
		var OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
		function OAS_NORMAL(pos) {
			document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' +
			OAS_rns + '@' +
			OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>');
			document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' +
			OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
		}
		window.OAS_version = 11;
		if (navigator.userAgent.indexOf('Mozilla/3') != -1 || navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1) {
			window.OAS_version = 10;
		}
		if (document.location.toString().indexOf('https') < 0) {
			if (OAS_version >= 11) {
				document.write('<SCR' + 'IPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIPT>');
			}
		}
		function OAS_AD(pos) {
			if (document.location.toString().indexOf('https') < 0) {
				if (window.OAS_version >= 11) {
				  OAS_RICH(pos);
				}
				else {
				  OAS_NORMAL(pos);
				}
			}
		}
	/* _enterprise_end */
	
	/* _enterprise mod 1211091046 */
		$(document).ready(function() {
			topimg = $('li.TopSeller1 .ProductImage img').attr('src');
			tophref = $('li.TopSeller1 .ProductImage a').attr('href');
			var html = '';
			html += '<div class="TopSellingImage">';
			html += '<a href="'+tophref+'"><img src="'+topimg+'" /></a>';
			html += '</div>';
			$('#SideTopSellers .BlockContent').prepend(html);
		});
	/* _enterprise_end */
	
	/* _enterprise mod 0106101034 */
		function limitText(limitField, limitCount, limitNum) {
			if (limitField.value.length > limitNum) {
				limitField.value = limitField.value.substring(0, limitNum);
			} else {
				limitCount.value = limitNum - limitField.value.length;
			}
		}
	/* _enterprise_end */

	/* _enterprise mod 0111102018 */
		function ReportCheckoutAJAXError(info) 	{
			info += "request.cookieinfo" + document.cookie + "<br />";
			var data = {title:  "An AJAX error has occurred during checkout",
						body:	"Details about the error, if available:<br /><br />"+info,
						type:  	"defaulttechnical",
						seccode: "2023"};
			//$.post("enterprise.php?action=emailadmin", data);
		}
	/* _enterprise_end */	
	
	/* _enterprise mod 020210240 - Navigation drop down */
	
		var timeout	= 500;
		var closetimer	= 0;
		var ddmenuitem	= 0;
		
		// open hidden layer
		function mopen(id)
		{	
			// cancel close timer
			mcancelclosetime();
		
			// close old layer
			if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
		
			// get new layer and show it
			ddmenuitem = document.getElementById(id);
			ddmenuitem.style.visibility = 'visible';
		}
		// close showed layer
		function mclose()
		{
			if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
		}
		
		// go close timer
		function mclosetime()
		{
			closetimer = window.setTimeout(mclose, timeout);
		}
		
		// cancel close timer
		function mcancelclosetime()
		{
			if(closetimer)
			{
				window.clearTimeout(closetimer);
				closetimer = null;
			}
		}
		
		// close layer when click-out
		document.onclick = mclose; 
	
	/* _enterprise_end */

	/* _enterprise mod 0604101435 */
		// preload the minus icon
		$(document).ready(function () {
			 //pic1= new Image(100,25); 	
			// pic1.src=config.ImagePath+"/enterprise/buttons/minusicon.gif"; 
		});

		function TogglePackageProgressDetails(showhidelink, shipmentid, retry) 
		{
			// delete any prior result for this shipment
			$('#progress'+shipmentid).remove();

			// get the tracking number 
			trackingnumber = $(showhidelink).next('.trackingno').html();

			// toggle show/hide icon
			loaddetails = $('img', showhidelink).attr('src').indexOf('plus') > 0 || retry;
			if (loaddetails) {

				// toggle the show/hide icon
				var src = $('img', showhidelink).attr('src').replace('plus','minus');
				$('img', showhidelink).attr('src', src);
				
				// add the new result row
				newhtml = '<tr><td colspan="4" id="progress'+shipmentid+'" class="packageprogressrow">&nbsp;&nbsp;&nbsp;Loading ...</td></tr>';
				$(showhidelink).parents('tr:first').after(newhtml);

				$.ajax({
					url: 'enterprise.php?action=getshipmentprogressdetails',
					type: 'post',
					async: false,
					dataType: 'xml',
					data: 'shipmentid='+shipmentid,
					success: function(xml) {
								// could not retrieve progress info?
								if (!$('status', xml).text() || $('status', xml).text()=="0") {
									var data = {title:  "Could not retrieve detailed package progress info via AJAX for shipment "+shipmentid,
												body:	"The response from the server, if any, was status "+$('status', xml)+' error message '+$('error', xml),
												type:  	"defaulttechnical",
												seccode: "2023"};
									$.post("/emailadmin", data);
									result = 'Detailed package progress info could not be retrieved. Please <a href="/pages/contact">notify customer service</a> if this issue persists.';
									$('#progress'+shipmentid).html(result);
									return false;
								}

								// display package progress results and change toggle to hide
								result = $('progressdetails', xml).text();
								$('#progress'+shipmentid).html(result);
							},
					error: function(xml) {	
								var data = {title:  "Could not retrieve detailed tracking info via AJAX for shipment"+shipmentid,
											body:	"The response from the server, if any, was status "+$('status', xml)+' error message '+$('error', xml),
											type:  	"defaulttechnical",
											seccode: "2023"};
								result = 'Detailed package progress info could not be retrieved. Please <a href="/pages/contact">notify customer service</a> if this issue persists.';
								$('#progress'+shipmentid).html(result);
							}
				});
			}
			else {
				var src = $('img', showhidelink).attr('src').replace('minus','plus');
				$('img', showhidelink).attr('src', src); //
			}
			
		}
		
		function HidePackageProgressDetails(showhidelink, shipmentid, originalcontent)
		{
			// delete the tracking results
			$('#progress'+shipmentid).remove();
			
			// restore the original 'view results' link
			showlink = '<a href="&nbsp;" onclick="LoadPackageProgressDetails(this, '+shipmentid+');return false;">'+originalcontent+'</a>';
			$(showhidelink).replaceWith(showlink);
		}
		
		function LoadPackageProgressDetails(showhidelink, shipmentid) 
		{
			// get the show/hide link cell
			showhidecell = $(showhidelink).parents('td:first');
			originalcontent = $(showhidelink).html();
			hidelink = '<a href="&nbsp;" onclick="HidePackageProgressDetails(this, '+shipmentid+', \''+originalcontent+'\');return false;">hide details...</a>';

			// delete any prior result for this shipment
			$('#progress'+shipmentid).remove();

			// show loading message, and save the tracking number
			trackingnumber = $(showhidelink).html();
			$(showhidecell).html(hidelink.replace('hide details...', 'loading ...'));

			$.ajax({
				url: 'enterprise.php?action=getshipmentprogressdetails',
				type: 'post',
				async: false,
				dataType: 'xml',
				data: 'shipmentid='+shipmentid,
				success: function(xml) {
							// could not retrieve progress info?
							if (!$('status', xml).text()) {
								var data = {title:  "Could not retrieve detailed package progress info via AJAX for shipment "+shipmentid,
											body:	"The response from the server, if any, was status "+$('status', xml)+' error message '+$('error', xml),
											type:  	"defaulttechnical",
											seccode: "2023"};
								$.post("/emailadmin", data);
								message = 'Detailed tracking info could not be retrieved. <a href="&nbsp;" onclick="LoadPackageProgressDetails($this,'+shipmentid+'); return false;">Please click here to try again</a>, or notify customer service if this issue persists.';								
								$('#progress'+shipmentid).html(message);
								$(showhidecell).html(hidelink);
								return false;
							}

							// display package progress results and change toggle to hide
							newhtml = '<tr><td colspan="4" id="progress'+shipmentid+'" class="packageprogressrow">'+$('progressdetails', xml).text()+'</td></tr>';
							$(showhidecell).parents('tr:first').after(newhtml);
							$(showhidecell).html(hidelink);
						},
				error: function(xml) {	
							var data = {title:  "Could not retrieve detailed tracking info via AJAX for shipment"+shipmentid,
										body:	"The response from the server, if any, was status "+$('status', xml)+' error message '+$('error', xml),
										type:  	"defaulttechnical",
										seccode: "2023"};
							message = 'Detailed tracking info could not be retrieved. <a href="&nbsp;" onclick="LoadPackageProgressDetails($this,'+shipmentid+'); return false;">Please click here to try again</a>, or notify customer service if this issue persists.';
							$('#'+"progress"+shipmentid).html(message);
							$(showhidecell).html(hidelink);
						}
			});
		}
	/* _enterprise_end */
	
	/* _enterprise mod 0625102317 */
		// Increment a statistic
		function IncStat(metricid) {
			if (metricid.length > 0) {
				$.ajax({type: 'POST', url: 'index.php', data:{incstatmetricid:metricid}, retryLimit: 0, reportErrorsToAdmin: false, alertUsersIfAllRetriesFail: false});
			}
		}
	/* _enterprise_end */
		
	/* _enterprise mod 0907101522 */
		function ReportBrokenLink() 	{
			info = document.URL;
			var data = {title:  "A site user has clicked the 'Report broken link' hyperlink",
						body:	"The url was "+info,
						type:  	"defaultfunctional",
						seccode: "2023"};
			$.post("/emailadmin", data);
			alert('Thank you. An administrator has been notified.');
		}
	/* _enterprise_end */	

	/* _enterprise mod 1109101537 - activate google analytics event tracking for selected links */
		function doTrackLink(link, category, action, label, value) {
			try {
				if (typeof(_gaq) != 'undefined'){
					_gaq.push(['_trackEvent', category, action, label, value]);
					//setTimeout('window.open("' + link + '")', 1000);	//delay
					//return false;
					return true;
				}
			} catch(err){}
		}

		$(document).ready(function() {
			$('a.gatracklink').click(function() {
				var label = $(this).attr('rel');
				if (label) {
					return doTrackLink($(this).attr('href'), 'ExtLink', 'Click', label, 2);
				}
			});	
		});
	/* _enterprise_end */	

    /* _enterprise mod 0603111405 */
        function isValidEmail(email)  {
           var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/   
           return email.match(re)  
        }      
    /* _enterprise_end */    

	/******************************************************************************
	 * 
	 * BELOW: PROJECT-SPECIFIC ENHANCEMENTS
	 *
	 ******************************************************************************/
    /* _sappress mod 0111111626  - classify user as reader segment user if they cross the oas library gate  */
        $(document).ready(function(){
            $('.oas-library-link', '#PDD').click(function(){
                _gaq.push(['_setCustomVar', 1, 'User Type', 'reader', 2]); 
                _gaq.push(['_trackPageview']); 
		//_gaq.push(['_trackEvent', 'OnlineLibrary', 'GoTo']); 
            });
        });
    /* _sappress_end */
	
