﻿<!--
/*
	*******************************************************************
	File: 			fedex.js
	Created:		02/20/2007
	Created by:		Terri Ilaria
	*******************************************************************
	Last Update:		04/09/2007
				Added try{}catch{} blocks to the functions
	*******************************************************************
	Last Update:		04/11/2007
	Functions Modified:	EC_oSelect_change()
	*******************************************************************
*/

// *********************************************************************************************************
// GLOBAL VARIABLES
// *********************************************************************************************************
var fdx_isIE = (navigator.userAgent.indexOf('MSIE') == -1) ? false : true;		// Internet Explorer?
var fdx_isSafari = (navigator.userAgent.indexOf('Safari') == -1) ? false : true;	// Safari?
var fdx_isFirefox = (navigator.userAgent.indexOf('Firefox') == -1) ? false : true;	// Firefox?
var fdx_isOpera = (navigator.userAgent.indexOf('Opera') == -1) ? false : true;		// Opera?
var fdx_cnt = 0;									// fedEx attempt counter
var fdx_max = 3;									// fedEx max attempts
var fdx_httpreq;									// fedex http request

// *********************************************************************************************************
// String Prototypes
// *********************************************************************************************************
String.prototype.ltrim = function() {return this.replace(/^\s*/, '');};
String.prototype.rtrim = function() {return this.replace(/\s*$/, '');};
String.prototype.trim = function() {return this.ltrim().rtrim();};

/* 	*******************************************************************
	mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
	Code licensed under Creative Commons Attribution-ShareAlike License 
	http://creativecommons.org/licenses/by-sa/2.5/
	*******************************************************************
	05/09/2007 : TYI: below document.implementation.hasFeature code was
	retrieved from my javascript notepad web site as noted above
	*******************************************************************
*/
if(document.implementation.hasFeature("XPath", "3.0"))
{
	// TYI: 06/11/2008: opera compatibility
	if(window.Document && !window.XMLDocument) window.XMLDocument = window.Document;

	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}

function EC_GetShipping()
{
	fdx_cnt++;					// increment the counter by one
	var tsfile;

	try
	{
		var weight = document.LANSA.FDX_WGHT.value;
		var state = document.LANSA.FDX_ST.value;
		var zip = document.LANSA.FDX_ZIP.value;
		var country = document.LANSA.FDX_CTRY.value;
		var catalog = document.LANSA.FDX_CLOG.value;
		var billctry = document.LANSA.LW3HCNTRY.value;
		var webusr = document.LANSA.STDWEBUSR.value;
		var part = document.LANSA.elements['_PARTITION'].value;

		tsfile = '/images/fedexts/fedex_' + part + '.asp?weight=' + weight + '&state=' + state + '&zip=' + zip + '&country=' + country + '&catalog=' + catalog + '&billctry=' + billctry + '&err_cnt=' + fdx_cnt + '&err_max=' + fdx_max + '&webusr=' + webusr;

		var TS = GetXMLDoc('fdx');		// create an XML Document

		if(TS && !fdx_isIE)
		{
			TS.load(tsfile);		// load the fedex xml document
		}
		else if(TS && fdx_isIE)
		{
			TS.load(tsfile);		// for IE, load the xml document
			EC_LoadFedXml(TS);		// then call the load function
		}
		else
		{
			alert('The TS file has not been initialized');
		}
	}
	catch(e)
	{
		// for browsers that don't support XMLDOM, try the XMLHttpRequest (Safari)
		try
		{
			fdx_httpreq = new XMLHttpRequest();
			fdx_httpreq.onreadystatechange = EC_LoadFedExRequest;
			fdx_httpreq.open("GET",tsfile,false);
			fdx_httpreq.send("");
		}
		catch(fe)
		{
			var msg = 'We were unable to get the available Shipping Methods for your order';
			msg += '\nSupported browsers are Internet Explorer 6+, FireFox 2.0+, and Safari 3.0+';
			msg += '\nPlease make sure that you are using one of the supported browsers and try again.';
			alert(msg);
		}
	}
}

function EC_LoadFedExRequest()
{
	if(fdx_httpreq.readyState == 4)
	{
		if(fdx_httpreq.status == 200)
		{
			var TS = fdx_httpreq.responseXML;
			EC_LoadFedXml(TS)
		}
	}
}

function GetXMLDoc(v_function)
{
	var xmldom = null;

	if(window.ActiveXObject)
	{
		xmldom = new ActiveXObject("Microsoft.XMLDOM");
		xmldom.async = false;

	}
	else if(document.implementation && document.implementation.createDocument)
	{
		xmldom = document.implementation.createDocument("","",null);

		switch(v_function)
		{
			case 'fdx':
				xmldom.onload = function(){EC_LoadFedXml(xmldom);};
				break;
		}
	}
	else
	{
		alert('This site uses XML HTTP.  Please upgrade to IE 6.0+ or equivalent.');
	}

	return xmldom;
}

function EC_LoadFedXml(TS)
{
	// declare the select object for this function
	var oSelect;
	
	try
	{
		// check for the existence of an error in the return xml
		var err_node = TS.getElementsByTagName('Error')[0];
		
		// get a handle on the shipping element: set the onchange event and clear any options
		oSelect = document.LANSA.FDX_SHIP;
		oSelect.onchange = function(){EC_oSelect_change(oSelect,false);};
		oSelect.length = 0;

		if(err_node)
		{
			if(fdx_cnt > fdx_max)
			{
				var ext_err;
				try
				{
					ext_err = err_node.getElementsByTagName('ExtendedError')[0].firstChild.data;
				}
				catch(ext_e)
				{
					ext_err = '';
				}

				// add a blank shipping type option
				oSelect.options[0] = new Option('Unable to get Shipping Rate','0');
				oSelect.options[0].setAttribute('FDX_MTHD','');

				// call the onchange function so that the hidden FDX_MTHD field is set
				EC_oSelect_change(oSelect,true);

				alert('[FedEx Error]\n' + ext_err + '\nMessage: ' + err_node.getElementsByTagName('Message')[0].firstChild.data);
			}
			else
			{
				EC_GetShipping();
			}
		}
		else
		{
			var curr_symbol;
			try
			{
				curr_symbol = unescape(((TS.getElementsByTagName('CurrencySymbol')) ? TS.getElementsByTagName('CurrencySymbol')[0].firstChild.data : ''));
			}
			catch(ex)
			{
				curr_symbol = '';
			}
			
			// add a blank shipping type option
			oSelect.options[0] = new Option('Select a Shipping Method','0');
			oSelect.options[0].setAttribute('FDX_MTHD','');

			var entries = TS.getElementsByTagName('Entry');

			if(entries.length == 0)
			{
				var price = (TS.getElementsByTagName('ExchangedCustomerCharge')[0]) ? TS.getElementsByTagName('ExchangedCustomerCharge')[0] : ((TS.getElementsByTagName('TotalCustomerCharge')[0]) ? TS.getElementsByTagName('TotalCustomerCharge')[0] : null);
				var svc = (TS.getElementsByTagName('Service')[0]) ? TS.getElementsByTagName('Service')[0] : null;
				var svc_dsp = (svc && svc.getElementsByTagName('Display')[0]) ? svc.getElementsByTagName('Display')[0] : null;
				var svc_mthd = (svc && svc.getElementsByTagName('Method')[0]) ? svc.getElementsByTagName('Method')[0] : null;

				if(price && svc && svc_dsp && svc_mthd)
				{
					oSelect.options[1] = new Option(svc_dsp.firstChild.data + '  [' + curr_symbol + price.firstChild.data + ']',price.firstChild.data);
					oSelect.options[1].setAttribute('FDX_MTHD',svc_mthd.firstChild.data);
				}
			}
			else
			{
				for(var i = 0; i < entries.length; i++)
				{
					var price = (entries[i].getElementsByTagName('ExchangedCustomerCharge')[0]) ? entries[i].getElementsByTagName('ExchangedCustomerCharge')[0] : ((entries[i].getElementsByTagName('TotalCustomerCharge')[0]) ? entries[i].getElementsByTagName('TotalCustomerCharge')[0] : null);
					var svc = (entries[i].getElementsByTagName('Service')[0]) ? entries[i].getElementsByTagName('Service')[0] : null;
					var svc_dsp = (svc && svc.getElementsByTagName('Display')[0]) ? svc.getElementsByTagName('Display')[0] : null;
					var svc_mthd = (svc && svc.getElementsByTagName('Method')[0]) ? svc.getElementsByTagName('Method')[0] : null;

					if(price && svc && svc_dsp && svc_mthd)
					{
						var index = oSelect.options.length;
						oSelect.options[index] = new Option(svc_dsp.firstChild.data + '  [' + curr_symbol + price.firstChild.data + ']',price.firstChild.data);
						oSelect.options[index].setAttribute('FDX_MTHD',svc_mthd.firstChild.data);
					}
				}
			}

			// call the onchange function so that the hidden FDX_MTHD field is set
			EC_oSelect_change(oSelect,true);
		}
	}
	catch(e)
	{
		EC_HandleError('EC_LoadFedXml()',e);
	}
}

function EC_oSelect_change(obj_select,bln_init)
{
	try
	{
		// get the selected index of the select element and the FDX_MTHD object
		var i = obj_select.selectedIndex;
		var obj_mthd = document.LANSA.FDX_MTHD;

		// if the FDX_MTHD object value was set and the bln_init variable is true - the page is loading or reloading
		if(obj_mthd.value != '' && bln_init)
		{
			// deselect all option elements before selecting one - Safari...
			for(var x = 0; x < obj_select.length; x++)
			{
				obj_select.options[x].selected = false;
			}

			// iterate through all of the select options and check for the FDX_MTHD value
			for(var x = 0; x < obj_select.length; x++)
			{
				// if the method is found
				if(obj_select.options[x].getAttribute('FDX_MTHD').indexOf(obj_mthd.value) == 0)
				{
					// set the option as selected, change i to this option's index and exit the loop
					obj_select.options[x].selected = true;
					i = x;
					break;
				}
			}
		}

		// based on the selected option, set the FDX_MTHD value
		if(i == -1)
		{
			obj_mthd.value = '';
		}
		else
		{
			// set the shipping method value
			document.LANSA.FDX_MTHD.value = obj_select.options[i].getAttribute('FDX_MTHD');

			// TYI : 04/11/2007
			// if the page is not loading 
			// and the selected option has a value, submit the page up to the server for recalculation

			if((!(bln_init)) && (obj_select.options[i].value != ''))
			{
				// make the Lansa calls so that the page is handled as normal
				InsertHidden(document.LANSA, 'STDRENTRY','S');
				document.LANSA.STDRENTRY.value = 'S';
				document.LANSA.btnplcord.disabled = true;
				document.getElementById('chgshpbtn').disabled = true
				HandleEvent('WCHKOUT2', 'LWBOD06D1', document.LANSA, null);
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_oSelect_change()',e);
	}
}

// *********************************************************************************************************
//                                     END FEDEX FUNCTIONS
// *********************************************************************************************************

// *********************************************************************************************************
//                                  PRODUCT LOCATOR FUNCTIONS
// *********************************************************************************************************
var EC_MNUTO = null;
var EC_MNUOBJ = null;
var EC_MNUSW = true;

function EC_ShowMenu(obj)
{
	var id;
	var elem;
	var pDiv;

	try
	{
		EC_ClearMenuTimeout();
		if(EC_MNUSW)
		{
			if(EC_MNUOBJ)
			{
				EC_MNUOBJ.style.visibility = 'hidden';
			}
			id = obj.id.split('_')[1];
			elem = document.getElementById('menu_' + id);
			elem.style.left = ((fdx_isIE || fdx_isSafari || fdx_isOpera) ? 0 : document.getElementsByTagName('table')[0].offsetLeft) + 200;
			elem.style.visibility = 'visible';
			elem.onmouseover = function(){EC_ClearMenuTimeout();this.style.visibility = 'visible';};
			elem.onmousemove = function(){EC_ClearMenuTimeout();this.style.visibility = 'visible';};
			obj.onmouseout = function(){EC_SetMenuTimeout(document.getElementById('menu_' + id));};
		}
	}
	catch(e)
	{
		EC_HandleError('EC_ShowMenu()',e);
	}
}

function EC_SetMenuTimeout(obj)
{
	EC_MNUOBJ = (obj) ? obj : EC_MNUOBJ;
	EC_MNUTO = setTimeout("EC_MNUOBJ.style.visibility = 'hidden'",750);
}

function EC_ClearMenuTimeout()
{
	if(EC_MNUTO)
	{
		clearTimeout(EC_MNUTO);
		EC_MNUTO = null;
	}
}

function EC_GetFamily(fid,tid,f,o,r)
{
	/*
	Function Parameters:
	fid = Family ID
	tid = Type ID
	f = the Form to act on
	o = Show Overview (true or false)
	r = STDRENTRY value
	*/

	try
	{
		var fam_id = (fid) ? fid : 0;
		var type_id = (tid) ? tid : 0;
		var frm = (f) ? f : document.LANSA;
		var show_overview = (o) ? o : false;
		var rentry = (r) ? r : '';
		var webapp = 'PRDLOC001';
		var wam = 'PRDLOC_FAM';

		frm.elements['WRKPRFID'].value = fam_id;
		frm.elements['WRKPRTID'].value = type_id;
		frm.elements['SHOWOVRVW'].value = show_overview;

		// set the re-entry value
		InsertHidden(frm, 'STDRENTRY',rentry);
		frm.elements['STDRENTRY'].value = rentry;

		HandleEvent(webapp,wam,frm,null);

		EC_MNUSW = false;

		// IE workaround for anchor tags using onclick instead of href
		// http://support.microsoft.com/kb/190244/en-us
		if(fdx_isIE)
		{
			window.event.returnValue = false
		}
		// don't show the menu
		if(document.getElementById('menu_' + fam_id))
		{
			EC_SetMenuTimeout(document.getElementById('menu_' + fam_id));
			document.getElementById('menu_' + fam_id).style.visibility = 'hidden';
		}
	}
	catch(e)
	{
		EC_HandleError('EC_GetFamily()',e);
	}
}

function EC_LansaURL(v_webapp,v_webrtn)
{
	this.url = '';

	try
	{
		// define the url - get the current protocol, host and form action
		// TYI:06/11/2008: Opera includes the protocol and host with the form action
		var f_act = document.LANSA.getAttribute('action');

		if(f_act.indexOf('http') == -1)
		{
			this.url = window.location.protocol + '//' + window.location.host + f_act;
		}
		else
		{
			this.url = f_act;
		}

		// add the web app
		this.url += 'webapp=' + v_webapp;

		// add the web routine
		this.url += '+webrtn=' + v_webrtn;

		// add the lansa technology service
		this.url += '+ml=LANSA:XHTML';

		// append the partition and language
		this.url += '+partition=' + document.LANSA.elements['_PARTITION'].value;
		this.url += '+language=' + document.LANSA.elements['_LANGUAGE'].value;

		// append the session key last, if is exists
		this.url += EC_GetSessionId();
	}
	catch(e)
	{
		alert('EC_LansaURL = ' + this.url);
		this.url = '';
	}
}

function EC_DrilldownChange(obj)
{
	try
	{
		var frm = (obj.form) ? obj.form : document.LANSA;
		var fld_qrystring = '';

		// get the ec_family table cell and all select elements within it
		var select_arr = document.getElementById('ec_family').getElementsByTagName('select');

		// iterate through the select elements and append the result url
		for(var i = 0; i < select_arr.length; i++)
		{
			// if the selected option has a value, append the name/value pair to the field query string
			if((select_arr[i].value != '') && (select_arr[i].value != 0))
			{
				fld_qrystring += '+f(' + select_arr[i].name + ')=' + select_arr[i].value;
			}
			
			// default the updlst to false
			select_arr[i].updlst = false;

			// if the select element is not the one being acted on, set the updlst to true and disable the select object
			if(select_arr[i].name != obj.name)
			{
				select_arr[i].updlst = true;
				select_arr[i].disabled = true;
			}
		}

		// iterate through the select elements again, and update the lists that need updated
		for(var i = 0; i < select_arr.length; i++)
		{
			if(select_arr[i].updlst)
			{
				if((select_arr[i].getAttribute('vlwam')!='')&&(select_arr[i].getAttribute('vlwebrtn')!=''))
				{
					select_arr[i].l_url = new EC_LansaURL(select_arr[i].getAttribute('vlwam'),select_arr[i].getAttribute('vlwebrtn'));
					select_arr[i].l_url.url += '+f(WRKPRFID)=' + ((frm.elements['WRKPRFID']) ? frm.elements['WRKPRFID'].value : '0');
					select_arr[i].l_url.url += '+f(PRBKDSC)=' + ((frm.elements['PRBKDSC']) ? frm.elements['PRBKDSC'].value : 'FDUS');
					select_arr[i].l_url.url += fld_qrystring;
					select_arr[i].l_url.url += '+lxml=yes';
					select_arr[i].rsltAjax = new EC_XMLHTTP('GET',select_arr[i].l_url.url,true,'EC_UpdateList',select_arr[i]);
				}
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_DrilldownChange()',e);
	}
}

var fd_cart_btn = null;			// the add to cart button that was clicked

function EC_AddToCart(item,qty,obj)
{
	try
	{
		var qty_obj = document.getElementsByName(qty)[0];
		var frm = (qty_obj.form) ? qty_obj.form : document.LANSA;

		if(isNaN(parseInt(qty_obj.value)))
		{
			qty_obj.focus();
			qty_obj.select();
			alert('Quantity must be a numeric value.');
		}
		else if(parseInt(qty_obj.value)<=0)
		{
			qty_obj.focus();
			qty_obj.select();
			alert('Quantity must be greater than 0');
		}
		else
		{
			// get the default lansa url for the result list
			var l_url = new EC_LansaURL('PRDLOC001','PRDLOC_ATC');

			// append the field values, empty values are handled by the WAM
			l_url.url += '+f(LW3SESORD)=' + ((frm.elements['LW3SESORD']) ? frm.elements['LW3SESORD'].value : '0');
			l_url.url += '+f(STDWEBUSR)=' + ((frm.elements['STDWEBUSR']) ? frm.elements['STDWEBUSR'].value : '0');
			l_url.url += '+f(STDSESSID)=' + ((frm.elements['STDSESSID']) ? frm.elements['STDSESSID'].value : '0');
			l_url.url += '+f(C_USRCTRY)=' + ((document.getElementById('C_USRCTRY')) ? document.getElementById('C_USRCTRY').value : '0');
			l_url.url += '+f(LW3HCNTRY)=' + ((document.getElementById('LW3HCNTRY')) ? document.getElementById('LW3HCNTRY').value : '0');

			// append the item id and quantity being added
			l_url.url += '+f(IMLITM)=' + item;
			l_url.url += '+f(LW3QTYRQS)=' + parseInt(qty_obj.value);

			// get the xml result
			l_url.url += '+lxml=yes';

			// disable the cart button to avoid double clicks
			obj.disabled = true;
			
			// reference the button object - may be used in EC_UpdateCart
			fd_cart_btn = obj;

			// start the AJAX function to refine the search results
			var rsltAjax = new EC_XMLHTTP('GET',l_url.url,true,'EC_UpdateCart',qty_obj.parentNode);
		}
	}
	catch(e)
	{
		EC_HandleError('EC_AddToCart()',e);
	}
}

function EC_UpdateCart(x_doc,x_obj)
{
	try
	{
		var cartqty = x_doc.selectNodes("/lxml:data/lxml:fields/lxml:field[@name='LW3SITCNT']/lxml:value");
		var itemqty = x_doc.selectNodes("/lxml:data/lxml:fields/lxml:field[@name='LW3COLQTY']/lxml:value");
		var messages = null;
		try{messages = x_doc.selectNodes("/lxml:data/lxml:messages/lxml:message");}catch(me){}
		var atc_id = x_obj.getAttribute('id');
		var atc_id2 = atc_id.replace(/.2$/,'');
		var incart_id = atc_id.replace(/^atc./,'ic.');
		var incart_id2 = incart_id.replace(/.2$/,'');

		// if there are error messages returned
		if(messages && messages.length)
		{
			var msg = '';
			for(var i = 0; i < messages.length; i++)
			{
				msg += messages[i].firstChild.data + '\n';
			}

			// display them
			alert(msg);

			// re-enable the clicked cart button
			if(fd_cart_btn)
			{
				fd_cart_btn.disabled = false;
			}
		}

		// update the cart info
		document.getElementById('cartqty').firstChild.data = cartqty[0].firstChild.data;
		document.getElementById('cartinfo').style.visibility = 'visible';

		// set the item quantity
		document.getElementById(incart_id).getElementsByTagName('span')[0].firstChild.data = itemqty[0].firstChild.data;

		if(itemqty[0].firstChild.data > 0)
		{
			// hide the add to cart block
			x_obj.style.display = 'none';
	
			// display the in cart block
			document.getElementById(incart_id).style.display = 'block';

			if(document.getElementById(atc_id2))
			{
				// set the item quantity
				document.getElementById(incart_id2).getElementsByTagName('span')[0].firstChild.data = itemqty[0].firstChild.data;

				// hide the add to cart block
				document.getElementById(atc_id2).style.display = 'none';

				// display the in cart block
				document.getElementById(incart_id2).style.display = 'block';
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_UpdateCart()',e);
	}
}

function EC_GetSessionId()
{
	// default the return value
	var ret_val = '';

	try
	{
		// if the session key is stored in a hidden field, get it
		var sKey = (document.LANSA.elements['_SESSIONKEY']) ? document.LANSA.elements['_SESSIONKEY'].value : '';
		
		// if the hidden field was not found, look in the URL
		if(sKey == '')
		{
			// split the url at the point where the sid is defined
			var url_arr = location.href.split('sid=');
			// if the sid was found, get the 40 character sid
			sKey = (url_arr[1]) ? url_arr[1].substr(0,40) : '';
		}

		// if the session key value was found, set the return value
		if(sKey != '')
		{
			ret_val = '+sid=' + sKey;
		}
	}
	catch(e)
	{

	}
	
	// return the function value
	return ret_val;
}

// ****** TYI : 04/20/2007 : MM_ functions added for product locator main page content ******

function MM_findObj(n, d)
{
	//v4.01
	var p,i,x;
	try
	{
		if(!d) d=document;
		if((p=n.indexOf("?"))>0&&parent.frames.length)
		{
			d = parent.frames[n.substring(p+1)].document;
			n=n.substring(0,p);
		}
		if(!(x=d[n])&&d.all) x=d.all[n];
		for(i=0;!x&&i<d.forms.length;i++)
		{
			x=d.forms[i][n];
		}
		for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		{
			x=MM_findObj(n,d.layers[i].document);
		}
		if(!x && d.getElementById) x=d.getElementById(n);
	}
	catch(e)
	{
	}
	finally
	{
		return x;
	}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{
	try
	{
		//v3.0
		var d = document;
		if(d.images)
		{
			if(!d.MM_p)
			{
				d.MM_p=new Array();
			}
	   		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
			for(i=0; i<a.length; i++)
			{
				if(a[i].indexOf("#")!=0)
				{
					d.MM_p[j]=new Image;
					d.MM_p[j++].src=a[i];
				}
			}
		}
	}
	catch(e)
	{
	}
}

function EC_openWindow(url, w, h) {
	try
	{
		var options = 'width=' + w + ',height=' + h + ',';
		options += 'resizable=no,scrollbars=yes,status=no,';
		options += 'menubar=no,toolbar=no,location=no,directories=no';
		var newWin = window.open(url, 'newWin', options);
		newWin.focus();
	}
	catch(e)
	{
	}
}

// *********************************************************************************************************
//                                 END PRODUCT LOCATOR FUNCTIONS
// *********************************************************************************************************
// *********************************************************************************************************
//                                   ERROR HANDLING FUNCTION
// *********************************************************************************************************
function EC_HandleError(str_func,v_e)
{
	// for testing, display the exception...
	var str_desc = (v_e.description) ? v_e.description : v_e.message;
	alert('[' + str_func + '] JavaScript Error\nDescription: ' + str_desc);
	try
	{
		var jserr = '[' + str_func + ']: ' + str_desc;
		var jserr_url = '/images/fedexts/js_error.asp?jserr=' + jserr;
		
		var js_doc = GetXMLDoc('');		// create an XML Document

		if(js_doc)
		{
			js_doc.load(jserr_url);		// load the xml document
		}
	}
	catch(err)
	{
		// do nothing
	}
}
// *********************************************************************************************************
// **************** ERROR HANDLING FOR xml ************************

function EC_FormatErrorCode(rc) {
    if (rc < 0) rc = (65536*65536) + rc;
    return "0x" + rc.toString(16).toUpperCase();
}

function EC_HandleXMLError(xDoc) {
    var err = xDoc.parseError;
    var msg = 'Error reading XML:\r\n';
    //msg += '\r\n' + err.reason
    msg += '\r\nFile: ' + err.url;
    msg += '\r\nLine: ' + err.line;
    msg += '\r\nPosition: ' + err.linepos;
    msg += '\r\nErrorCode: ' + EC_FormatErrorCode(err.errorCode);
    
    var code = "";
    if (err.linepos > 0 && err.srcText != "")
    {
        code = err.srcText.replace(/\t/g," ") + "\n";
        for (var i = 1; i < err.linepos; i++)
        {
            code += "-";
        }
        code += "^";
    }
    
    msg += '\r\nError Source:\r\n' + code;

    alert(msg);
}

// ************** END ERROR HANDLING FOR xml **********************

// ************** AJAX FUNCTIONS **********************************
function EC_XMLHTTP(v_mthd,v_url,v_async,v_function,v_obj,v_xmlhtml)
{
	var xmlHttp;
	var obj = (v_obj) ? v_obj : null;
	var xmlhtml = (v_xmlhtml) ? v_xmlhtml : 'xml';

	try
	{    
		// Firefox, Opera 8.0+, Safari, IE 7+
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// Internet Explorer 6-
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert('Your browser does not support AJAX!');
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange = function()
		{
			if((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
			{
				if(obj)
				{
					if(xmlhtml == 'xml')
					{
						eval(v_function + '(xmlHttp.responseXML,obj)');
					}
					else
					{
						eval(v_function + '(xmlHttp.responseText,obj)');
					}
				}
				else
				{
					if(xmlhtml == 'xml')
					{
						eval(v_function + '(xmlHttp.responseXML)');
					}
					else
					{
						eval(v_function + '(xmlHttp.responseText)');
					}
				}
			}
		};

	try
	{
		xmlHttp.open(v_mthd,v_url,v_async);
		if(fdx_isOpera)xmlHttp.send();
		if(!fdx_isOpera)xmlHttp.send(null);
	}
	catch(e)
	{
		EC_HandleError('EC_XMLHTTP()',e + 'v_mthd=[' + v_mthd + ']: v_url=[' + v_url + ']');
	}
}

function EC_UpdateList(x_doc,x_obj)
{
	try
	{
		if(x_doc && x_obj)
		{
			var entries = x_doc.selectNodes("/lxml:data/lxml:lists/lxml:list[@name='" + x_obj.getAttribute('vllist') + "']/lxml:list-entries/lxml:entry");

			if(entries.length>0)
			{
				// get the current value of the select object
				var cur_val = x_obj.value;

				// clear the select object's options
				x_obj.options.length = 0;

				// iterate through the found entries and add them to the select object
				for(var i = 0; i < entries.length; i++)
				{
					var opt_value = '';
					try
					{
						opt_value = entries[i].selectNodes("lxml:column[@name='" + x_obj.getAttribute('vllistval') + "']")[0].firstChild.data;
					}
					catch(eo)
					{
					}
					var opt_text = entries[i].selectNodes("lxml:column[@name='" + x_obj.getAttribute('vllisttxt') + "']")[0].firstChild.data;
					x_obj.options[x_obj.options.length] = new Option(opt_text,opt_value);

					// if the current value matches the new option value, select it
					if(cur_val == opt_value)
					{
						x_obj.options[x_obj.options.length-1].selected = true;
					}
				}

				// enable the select object after options have been refreshed
				x_obj.disabled = false;
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_UpdateList()',e);
	}
}

// ************** END AJAX FUNCTIONS **********************************

function EC_QuickSearch(v_btn,v_obj)
{
	try
	{
		// if there is something entered to search for
		if((v_obj.value.trim() != '')&&(v_obj.value != v_obj.getAttribute('defval')))
		{
			var frm = (v_obj.form) ? v_obj.form : document.LANSA;
			var keyfld = v_btn.getAttribute('vlkeyfld');

			// if using keyword search, construct the where statement to pass in
			var msg = '';
			if(v_btn.getAttribute('vlkeyword') && (v_btn.getAttribute('vlkeyword')=='true'))
			{
				var keyword_arr = v_obj.value.trim().split(' ');

				for(var i = 0; i < keyword_arr.length; i++)
				{
					if(keyword_arr[i].trim() != '')
					{
						var kw = keyword_arr[i].trim().toUpperCase().replace(/'/g,'\'\'');
						msg += ((msg=='') ? 'IN (\'' : ',\'') + kw + '\'';
					}
				}

				// append the closing parentheses
				msg += (msg=='') ? '' : ')';

			}
			else
			{
				msg = v_obj.value.trim();
			}

			// set the search text
			frm.elements[keyfld].value = msg;

			// insert the re-entry value
			InsertHidden(frm, v_btn.getAttribute('vlrentryfld'),v_btn.getAttribute('vlrentryval'));
			frm.elements[v_btn.getAttribute('vlrentryfld')].value = v_btn.getAttribute('vlrentryval');

			EC_StartSearch();

			// submit the page to get the search results
			HandleEvent(v_btn.getAttribute('vlwam'),v_btn.getAttribute('vlwebrtn'), frm, null);
		}
	}
	catch(e)
	{
		EC_HandleError('EC_QuickSearch()',e);
	}
}

function EC_QSFocus(v_obj)
{
	if(v_obj && (v_obj.value == v_obj.getAttribute('defval')))
	{
		v_obj.value = '';
		v_obj.className = 'hasval';
	}
}

function EC_QSBlur(v_obj)
{
	if(v_obj && (v_obj.value.trim() == ''))
	{
		v_obj.value = v_obj.getAttribute('defval');
		v_obj.className = 'noval';
	}
}

function EC_SelectRegion(s_region)
{
	try
	{
		alert(s_region);
	}
	catch(e)
	{
		EC_HandleError('EC_SelectRegion()',e);
	}
}

function EC_ShowShippingInfo(obj)
{
	try
	{
		var ship_tbl = document.getElementById('shipping.info');

		if(obj.checked)
		{
			ship_tbl.style.display = 'none';
			obj.value = 'Y';
		}
		else
		{
			ship_tbl.style.display = 'block';
			obj.value = 'N';
		}
	}
	catch(e)
	{
		EC_HandleError('EC_ShowShippingInfo()',e);
	}
}

// ************** COOKIE FUNCTIONS ************************************
function EC_SetStoredCookie(n,v)
{
	var expDate = (v && (v != '')) ? setExpDate(true) : setExpDate(false);

	document.cookie = n + '=' + escape(v) + '; expires=' + expDate + ';path=/;domain=' + document.location.host.split(':')[0];

	if(v=='')
	{
		document.cookie = n + '=' + escape(v) + '; expires=' + expDate + '; path=/';
	}
}

function EC_SetSessionCookie(n,v)
{
	// n = name of the cookie
	// v = value of the cookie

	document.cookie = n + '=' + escape(v);
	
}

function EC_GetCookie(n,obj)
{
	// n = name of the cookie
	// obj = form object to recieve value of cookie

	var cookieData = document.cookie;
	if(cookieData.length > 0)
	{
		var s = EC_GetCookieData(n);
		if(s != '')
		{
			obj.value=s;
		}
	}
}

function EC_GetCookieData(lbl)
{
	// gets cookie data based on the label passed
	// got this function from the Javascript Bible, p. 353
	var lblLen = lbl.length;
	var cData = document.cookie;
	var cLen = cData.length;
	var i = 0;
	var cEnd;
	while(i < cLen)
	{
		var j = i + lblLen;
		if(cData.substring(i,j)==lbl)
		{
			cEnd = cData.indexOf(";",j);
			if(cEnd==-1)
			{
				cEnd = cData.length;
			}
			return unescape(cData.substring(j+1, cEnd));
		}
		i++;
	}
	return "";
}

function setExpDate(bln_save)
{
	// sets the expiration date of a cookie
	// bln = a true or false boolean that indicates whether or not to save the cookie

	var curDt = new Date();		// get the current date
	var myYr = curDt.getFullYear();	// get the 4 digit year of the current date

	if (bln_save) {
		myYr++;			// if saving the cookie, add 1 year
	} else {
		myYr--;			// if not saving the cookie, subtract 1 year
	}

	curDt.setFullYear(myYr);	// set the year of the expiration date

	return curDt.toGMTString();	// return the universal date string		

}
// ************** END COOKIE FUNCTIONS ********************************

function EC_SetCtryOptions(c_obj,c_obj_i,s_obj_id)
{
	/*
	Function    : EC_SetCtryOptions
	Description : Changes the available shipping countries based on the selected billing country
	Date Added  : 06/06/2007
	Added By    : Terri Ilaria
	Called From : Create Account
	*/

	try
	{
		var s_obj = document.getElementsByName(s_obj_id)[0];
		var bk_id = c_obj.options[c_obj_i].getAttribute('tag_PRBKID');
		var bk_index = -1;

		for(var x = 0; x < arr_book.length; x++)
		{
			if(arr_book[x] == bk_id)
			{
				bk_index = x;
				break;
			}
		}

		if(bk_index != -1)
		{
			s_obj.options.length = 0;

			for(var x = 0; x < arr_country[bk_index].length; x++)
			{
				s_obj.options[x] = arr_country[bk_index][x];
				// default to the selected value of the c_obj
				if(arr_country[bk_index][x].value == c_obj.value)
				{
					s_obj.options[x].selected = true;
				}
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_SetCtryOptions()',e);
	}
	
}

function EC_GetOrdDet(v_ord,v_fld,v_wam,v_rtn)
{
	/*
	Function    : EC_GetOrdDet
	Description : Inserts the order number to retrieve and then calls the order detail page
	Date Added  : 06/06/2007
	Added By    : Terri Ilaria
	Called From : Order History
	*/

	try
	{
		InsertHidden(document.LANSA,v_fld,v_ord);
		document.LANSA.elements[v_fld].value = v_ord;
		HandleEvent(v_wam, v_rtn, document.LANSA, null);
		
	}
	catch(e)
	{
		EC_HandleError('EC_GetOrdDet()',e);
	}

	// must return false due to function being called from an anchor
	return false;
}


function EC_PlaceOrder()
{
	/*
	Function    : EC_PlaceOrder
	Description : Hides the buttons on the check out page to avoid havoc
	Date Added  : 06/15/2007
	Added By    : Terri Ilaria
	Called From : Check Out Place Order button
	*/

	try
	{
		document.getElementById('process_warn').style.display = 'none';
		document.getElementById('process_msg').style.display = 'inline';
		document.getElementById('process_btns').style.display = 'none';
		document.getElementById('chgshpbtn').disabled = true;
	}
	catch(e)
	{
		EC_HandleError('EC_PlaceOrder()',e);
	}
}

function EC_CheckMessages()
{
	/*
	Function    : EC_CheckMessages
	Description : Displays an alert message if there are any messages
			returned from the server
	Dependency  : The server messages must be in hidden fields named 'messages'
	Date Added  : 06/15/2007
	Added By    : Terri Ilaria
	Called From : Any body onload event 
	*/

	try
	{
		var msg_arr = document.getElementsByName('messages');
		var msg = '';
		for(var i = 0; i < msg_arr.length; i++)
		{
			if(msg_arr[i].value != '(0302) - Invalid data input into a numeric only field')
			{
				msg += msg_arr[i].value + '\n';
			}
		}
		
		if(msg != '')
		{
			alert(msg);
		}
	}
	catch(e)
	{
		EC_HandleError('EC_CheckMessages()',e);
	}
}

function EC_CtryChange(obj)
{
	/*

	*/
	try
	{
		var frm = (document.LANSA) ? document.LANSA : obj.form;
		var ctry_id = obj.options[obj.selectedIndex].value;
		EC_SetStoredCookie('C_USRCTRY',ctry_id);
		// move focus from the country drop down
		SetFocus();
		HandleEvent(frm.elements['_WEBAPP'].value,frm.elements['_WEBROUTINE'].value,frm);
		
	}
	catch(e)
	{
		EC_HandleError('EC_CtryChange()',e);
	}
}

function EC_StartSearch()
{
	try
	{
		// get the ec_search and ec_content elements
		var div_search = (document.getElementById('ec_search')) ? document.getElementById('ec_search') : null;
		var div_content = (document.getElementById('ec_content')) ? document.getElementById('ec_content') : null;

		if(div_search && div_content)
		{
			div_content.style.display = 'none';
			div_search.style.display = 'block';
		}
	}
	catch(e)
	{
		EC_HandleError('EC_StartSearch()',e);
	}
}

function EC_ChangeLocation()
{
	try
	{
		EC_SetStoredCookie('C_USRCTRY','');
		var frm = (document.LANSA) ? document.LANSA : null;
		InsertHidden(frm, 'C_USRCTRY','');
		frm.elements['C_USRCTRY'].value = '';
	}
	catch(e)
	{
		EC_HandleError('EC_ChangeLocation()',e);
	}
}

function EC_WK_CNCTUS_CHANGE(obj)
{
	try
	{
		var num_option = obj.options[obj.selectedIndex].value;
		var id_tag = obj.options[obj.selectedIndex].getAttribute('tag_LSF_CTAG1');
		var arr_div = new Array('prdinfo','ordinfo','comments');

		// loop to hide all div elements
		for(var x=0; x < arr_div.length; x++)
		{
			document.getElementById(arr_div[x]).style.display='none';
		}

		// if id tag not blank, show section
		if(id_tag != '')
		{
			document.getElementById(id_tag).style.display = ((id_tag=='ordinfo') ? 'inline' : 'block');
		}

		// if contact reason selected, show comments box
		if(parseInt(num_option) > 0)
		{
			document.getElementById('comments').style.display='block';
			if(id_tag=='ordinfo')
			{
				obj.form.WK_ORDNUM.focus();
			}
			else if(id_tag=='')
			{
				obj.form.WK_CMNT.focus();
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_WK_CNCTUS_CHANGE()',e);
	}
}

function EC_WK_CNTRY_CHANGE(obj_ctry,str_fld)
{
	try
	{
		var f = (obj_ctry.form) ? obj_ctry.form : document.LANSA;		// get the form object
		var obj_state = f.elements[str_fld];					// get the state dropdown object
		var obj_state_h = f.elements[str_fld + 'H'];				// get the state hidden object
		var obj_zip = f.elements['WK_POSTC'];					// get the postal code object
		var i = obj_ctry.selectedIndex;						// get the selected country index
		var str_dsp = '';							// the display value of the state dropdown
		var str_class = 'std_dropdown';						// the class value of the state dropdown
		var str_zipclass = 'utext';						// the class value of the postal code field
		var str_state_h_val = obj_state_h.value;				// get the current value of the hidden state object

		if((i == -1) || (obj_ctry.options[i].value.trim() == ''))		// if there is no country selected
		{
			obj_state.options.length = 0;					// clear the state dropdown options
			obj_state.options[0] = new Option('Select Country','');		// add a blank informational option
			str_dsp = 'inline';						// show the state dropdown
			str_state_h_val = '';						// clear the hidden state object value
		}
		else if(arr_state[i] && arr_state[i].length)				// if the country has state options
		{
			var str_cur_val = obj_state.value;				// get the current value of the state dropdown
			obj_state.options.length = 0;					// clear the state dropdown options
			str_dsp = 'inline';						// show the state dropdown
			str_class += ' required';					// add the required class to the state dropdown
			str_zipclass += ' required';					// add the required class to the postal field
			for(var x = 0; x < arr_state[i].length; x++)			// loop through the state options
			{
				obj_state.options[x] = arr_state[i][x];			// add them to the state dropdown
				if(str_cur_val==arr_state[i][x].value)			// if the current option value equals the current value
				{
					obj_state.options[x].selected = true;		// set the selected state
				}
				else
				{
					obj_state.options[x].selected = false;		// set the selected state
				}
			}
			str_state_h_val = '';						// clear the hidden state object value
		}
		else									// otherwise
		{
			obj_state.options.length = 0;					// clear the state dropdown options
			str_dsp = 'none';						// hide the state dropdown;
		}
		obj_state.style.display = str_dsp;					// set the display for the state dropdown
		obj_state.className = str_class;					// set the class for the state dropdown
		obj_zip.className = str_zipclass;					// set the class for the postal code field
		obj_state_h.value = str_state_h_val;					// set the value for the state input element
		obj_state_h.style.display = (str_dsp=='inline') ? 'none' : 'inline';	// set the display for the state input element
	}
	catch(e)
	{
		EC_HandleError('EC_WK_CNTRY_CHANGE()',e);
	}
}

function EC_ValidateCntc(obj)
{
	var ret_val = true;

	try
	{
		var frm = (obj.form) ? obj.form : document.LANSA;
		var arr_required = new Array('WK_FNAME','WK_LNAME','WK_ADDR1','WK_CITY','WK_CNTRY','WK_PHONE','WK_EMAIL','WK_CNCTUS');
		var msg = '';
		for(var x = 0; x < arr_required.length; x++)
		{
			if(frm.elements[arr_required[x]].value.trim() == '')
			{
				frm.elements[arr_required[x]].style['backgroundColor'] = '#ff0000';
				frm.elements[arr_required[x]].style['background-color'] = '#ff0000';
				msg = 'Required data is missing. Please correct and try again.';
			}
			else
			{
				frm.elements[arr_required[x]].style['backgroundColor'] = '';
				frm.elements[arr_required[x]].style['background-color'] = '';
			}
		}

		if(msg == '')
		{
			ret_val = EC_isValidEmail(frm.elements['WK_EMAIL']);
		}
		else
		{
			ret_val = false;
			alert(msg);
		}
	}
	catch(e)
	{
		EC_HandleError('EC_ValidateCntc()',e);
		ret_val = true;
	}
	finally
	{
		return ret_val;
	}
}

function EC_isValidEmail(obj)
{
	var ret_val = true;

	try
	{
		var str_email = obj.value.trim();

		if(str_email != '')
		{
			/* email expression for testing
				^(.+) 		= Any combination of characters at the beginning (^)
			 	@		= Followed by an @ symbol
			 	(.+)		= Followed by any combination of characters
				\.		= Followed by a dot
				(.{2,4})$	= Followed by a 2 - 4 character combination at the end ($)
			*/
			var exp_email = /^(.+)@(.+)\.(.{2,4})$/;

			// set the return value to the result of the test (true or false)
			ret_val = exp_email.test(str_email);

			// if the test fails, prompt to enter a valid email address
			if(!ret_val)
			{
				alert('You have entered an invalid email format');
				obj.style['backgroundColor'] = '#ff0000';
				obj.style['background-color'] = '#ff0000';
			}
			else
			{
				obj.style['backgroundColor'] = '';
				obj.style['background-color'] = '';
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_isValidEmail()',e);
		ret_val = true;
	}
	finally
	{
		return ret_val;
	}
}

function FD_isNumber(e)
{
	// this function was taken from a W3SCHOOLS example
	// URL Reference: http://www.w3schools.com/jsref/jsref_onkeypress.asp

	var keynum;
	var keychar;
	var numcheck;

	// IE
	if(window.event)
	{
		keynum = e.keyCode;
	}
	// Netscape/Firefox/Opera
	else if(e.which)
	{
		keynum = e.which;
	}

	// allow backspace, and delete for firefox / safari
	if((fdx_isFirefox) && ((keynum == 8) || (keynum == undefined) || (keynum == 9)))
	{
		return true;
	}
	else if((fdx_isSafari) && ((keynum == 8) || (keynum == 0) || (keynum == 9)))
	{
		return true;
	}
	else
	{
		keychar = String.fromCharCode(keynum);

		// regular expression to test for number
		numcheck = /\d/;

		// return the evaluation test as to whether or not the character is a number
		return numcheck.test(keychar);
	}
}

// ************** INTERCHANGE FUNCTIONS ************************************
function EC_II_Init(str_name)
{
	if(fdx_isIE)
	{
		document.body.onload=function()
		{
			EC_II_OnLoad(str_name);
		}
	}
	else
	{
		document.body.onload=EC_II_OnLoad(str_name);

		if(fdx_isSafari || fdx_isFirefox)
		{
			try{document.body.onpageshow=EC_II_ShowPage(str_name)}
			catch(e){}
		}
	}
}

function EC_II_OnLoad(str_name)
{
	EC_II_ShowPage(str_name);
	EC_CheckMessages();
}

function EC_II_ShowPage(str_name)
{
	EC_II_ShowHide(document.getElementById(str_name));
}

function EC_II_ShowHide(obj)
{
	try
	{
		// get the parent table
		var tbl = document.getElementById('ec_ii_tbl');
		var elem_arr = tbl.getElementsByTagName('span');
		for(var x = 0; x < elem_arr.length; x++)
		{
			if(elem_arr[x].getAttribute('showhide'))
			{
				if(elem_arr[x].getAttribute('showhide') == obj.value)
				{
					elem_arr[x].style.display = 'block';
				}
				else
				{
					elem_arr[x].style.display = 'none';
				}
			}
		}
	}
	catch(e)
	{
		EC_HandleError('EC_II_ShowHide()',e);
	}
}
// ************** END INTERCHANGE FUNCTIONS ********************************
//-->