// (c)2008 uShip, Inc.

var AuctionOptions_old=function(rbNotAuctionId,rbIsAuctionId,ddAuctionTypeId,ebayValue,conAuctionOptionsId,conEbayOptionsId){me={};me.rbNotAuction=$(rbNotAuctionId);me.rbIsAuction=$(rbIsAuctionId);me.ddAuctionType=$(ddAuctionTypeId);me.conAuctionOptions=$(conAuctionOptionsId);me.conEbayOptions=$(conEbayOptionsId);me.ebayValue=ebayValue;function init(){me.rbNotAuction.observe('click',me.run);me.rbIsAuction.observe('click',me.run);me.ddAuctionType.observe('change',handleAuctionTypeChange);me.run();}
me.run=function(){if(me.rbIsAuction.checked){me.conAuctionOptions.show();if(me.ddAuctionType.options[me.ddAuctionType.selectedIndex].value==me.ebayValue){me.conEbayOptions.show();}
else{me.conEbayOptions.hide();}}
else{me.conAuctionOptions.hide();me.conEbayOptions.hide();}}
function handleAuctionTypeChange(e){me.rbIsAuction.checked=true;me.run();}
init();return me;}
var AuctionOptions=function(rbNotAuctionId,rbIsAuctionId,rbLinkedAuctionId,rbNotLinkedAuctionId,ddAuctionTypeId,ebayValue,conAuctionOptionsId,conEbayOptionsId,conLinkedEbayId,conNotLinkedEbayId,auctionStatus){me={};me.rbNotAuction=$(rbNotAuctionId);me.rbIsAuction=$(rbIsAuctionId);me.rbLinkedAuction=$(rbLinkedAuctionId);me.rbNotLinkedAuction=$(rbNotLinkedAuctionId);me.ddAuctionType=$(ddAuctionTypeId);me.conEbayOptions=$(conEbayOptionsId);me.conLinkedEbay=$(conLinkedEbayId);me.conNotLinkedEbay=$(conNotLinkedEbayId);me.ebayValue=ebayValue;me.conAuctionOptions=$(conAuctionOptionsId);me.auctionStatus=$('auctionStatus');function init(){if(me.rbNotAuction!=null){me.rbNotAuction.observe('click',me.run);me.rbIsAuction.observe('click',me.run);me.rbLinkedAuction.observe('click',me.run2);me.rbNotLinkedAuction.observe('click',me.run2);me.ddAuctionType.observe('change',handleAuctionTypeChange);me.run();me.run2();}else{me.conAuctionOptions.show();}}
me.run=function(){if(me.rbIsAuction.checked){me.conAuctionOptions.show();if(me.ddAuctionType.options[me.ddAuctionType.selectedIndex].value==me.ebayValue){me.conEbayOptions.show();me.auctionStatus.hide();}
else{me.conEbayOptions.hide();me.auctionStatus.show();}}
else{me.conAuctionOptions.hide();me.conEbayOptions.hide();}}
me.run2=function(){if(me.rbLinkedAuction.checked){me.conLinkedEbay.show();me.conNotLinkedEbay.hide();me.auctionStatus.hide();}
else{me.conLinkedEbay.hide();me.conNotLinkedEbay.show();me.auctionStatus.show();}}
function handleAuctionTypeChange(e){me.rbIsAuction.checked=true;me.run();}
init();return me;}
var EBayImporter=function(btnLaunchId,btnRefreshId,containerId,conLoadingId,importUrl){this.btnLaunch=$(btnLaunchId);this.btnRefresh=$(btnRefreshId);this.container=$(containerId);this.conLoading=$(conLoadingId);this.EBAY_IMPORT_URL=importUrl;}
EBayImporter.prototype={launch:function(){if(this._w){this._w.focus();}
else{this._w=window.open(this.EBAY_IMPORT_URL,'','toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=600');this._w.focus();}},complete:function(){if(this._w){this._w.close();}
Position.clone(this.container,this.conLoading);new Effect.Opacity(this.container,{duration:0,transition:Effect.Transitions.linear,from:1,to:.2});this.conLoading.show();this.btnLaunch.disabled=true;this.btnRefresh.click();}}
var YearInput=function(inputId){var elem=$(inputId);var TEXT='Year';function run(){if(elem.value==''){elem.value=TEXT;}
else if(elem.value==TEXT){elem.value='';}}
elem.observe('focus',run);elem.observe('blur',run);run();}
var TimeframeOptions=function(rbFlexibleId,rbSpecificId,conSpecificId){this.rbFlexible=$(rbFlexibleId);this.rbSpecific=$(rbSpecificId);this.conSpecific=$(conSpecificId);this.rbFlexible.observe('click',this.run.bind(this));this.rbSpecific.observe('click',this.run.bind(this));this.run();}
TimeframeOptions.prototype={run:function(){if(this.rbSpecific.checked){this.conSpecific.show();}
else{this.conSpecific.hide();}}}
function setDropdown(dropDown,value){var numOptions=dropDown.options.length;for(i=0;i<numOptions;i++){if(dropDown.options[i].value==value){dropDown.options[i].selected=true;}}}
var CategorySelector=Class.create();CategorySelector.prototype={initialize:function(comArr,conElementList,txtCommodity1,txtCommodity2,conCommodityName,btnContinue){this.commodityList=comArr;this.conElementList=conElementList;this.btnContinue=btnContinue;this.hidCommodity1=txtCommodity1;this.hidCommodity2=txtCommodity2;this.conCommodityName=conCommodityName;this.elemCollection=[];this.elemCollection.push($('dlist1'));this.btnContinue.disabled=true;if(this.hidCommodity1.value>0){this.prefillSelection(parseInt(this.hidCommodity1.value,10));}},createListBox:function(level,callingElement){this.clearListBoxes(level)
var option=this._getSelectedElement(callingElement);var parentId=option.value;if(option.readAttribute('leaf')==1){var commodity=this.commodityList.find(function(commodity){return(commodity.id==parentId);});this.btnContinue.disabled=false;this.setCommodityName(commodity.n);this.hidCommodity1.value=commodity.id;$A(this.conElementList.getElementsByTagName('select')).each(function(select){var tag=this._getSelectedElement(select).readAttribute('tag');if(tag&&tag.length>0){this.hidCommodity2.value=tag;}}.bind(this));}
else if(option.readAttribute('leaf')==0){var nextLevel=level+1;this.btnContinue.disabled=true;this.setCommodityName(undefined);this.hidCommodity1.value='';this.hidCommodity2.value='';var htmlOptions=this.commodityList.select(function(commodity){return(commodity.p==parentId);}).map(function(commodity){var name=commodity.n;if(name.length>40){name=name.substring(0,40)+'...';}
if(commodity.l==0){name+=' >';}
return['<option value="',commodity.id,'" title="',commodity.n,'" leaf="',commodity.l,'" tag="',commodity.t,'" r="',commodity.r,'">',name,'</option>'].join('');});var newElem=document.createElement('div');newElem.id='dlist'+nextLevel;newElem.className='commodity-select';newElem.innerHTML+='<div class="q"><span class="req">*</span>Please specify:</div><select id="list'+nextLevel+'" size="12" onchange="myCategorySelector.createListBox('+nextLevel+', this)">'+htmlOptions.join('')+'</select>';this.conElementList.appendChild(newElem);this.elemCollection.push($(newElem));}},clearListBoxes:function(level){if(!level||level<1){level=1;}
this.elemCollection=this.elemCollection.select(function(elem,i){if(i>=level){elem.parentNode.removeChild(elem);}
return(i<level);});},setCommodityName:function(name){if(name&&name.length>0){this.conCommodityName.innerHTML='You have selected <strong>'+name+'</strong>';this.conCommodityName.style.visibility='visible';}
else{this.conCommodityName.style.visibility='hidden';this.conCommodityName.innerHTML='';}},prefillSelection:function(commodityId){var ids=this._getParents(commodityId);this.clearListBoxes();for(var i=0,len=ids.length;i<len;i++){if(i>0){this.createListBox(i,$('list'+i));}
var listBox=$('list'+(i+1));var isSelected=false;for(var j=0,len2=listBox.options.length;j<len2&&!isSelected;j++){if(listBox.options[j].getAttribute("r")==ids[i]){listBox.options[j].selected=true;isSelected=true;}}}
this.createListBox(ids.length,$('list'+ids.length));},_getParents:function(commodityId,arr){if(!arr){arr=[];}
arr.unshift(commodityId);var parentId=(this.commodityList.find(function(commodity){return(commodity.r==commodityId);})).p;if(parentId==0){return arr;}
else{return this._getParents(parentId,arr);}},_getSelectedElement:function(elemSelect){return $(elemSelect.options[elemSelect.selectedIndex]);}}
var ExpirationOptions=function(containerId,pickupObj,deliveryObj){this.container=$(containerId);this.pickup=pickupObj;this.delivery=deliveryObj;this.run();}
ExpirationOptions.prototype={run:function(){if(this.isSet(this.pickup)||this.isSet(this.delivery)){this.container.hide();}
else{this.container.show();}
setTimeout(this.run.bind(this),500);},isSet:function(tf){return(tf.checkbox.checked&&tf.latest.value.length>0)}}
var Location=Class.create();Location.prototype={initialize:function(CountryName,CountryChangeLink,CountryDropDown,ZipcodeName,ProvinceGroup,ProvinceDropDown,ProvinceTextBox,ProvinceHiddenInput,StateLabel,FillStates){this.countryName=$(CountryName);this.countryChangeLink=$(CountryChangeLink);this.countryDropDown=$(CountryDropDown);this.zipcodeName=$(ZipcodeName);this.provinceGroup=$(ProvinceGroup);this.provinceDropDown=$(ProvinceDropDown);this.provinceTextBox=$(ProvinceTextBox);this.provinceHiddenInput=$(ProvinceHiddenInput);this.stateLabel=$(StateLabel);if(FillStates==undefined||FillStates==""||FillStates=="false"){this.fillStates=false;}
else{this.fillStates=true;}
this.populateCountries();},showCountryList:function(){Element.hide(this.countryName);Element.hide(this.countryChangeLink);Element.show(this.countryDropDown);},hideCountryList:function(){Element.show(this.countryName);Element.show(this.countryChangeLink);Element.hide(this.countryDropDown);},changeCountry:function(){this.setSelectedProvince(-1);this.provinceTextBox.value='';this.populateCountries();},changeProvince:function(){this.setSelectedProvince(this.getSelectedProvince());},setCountryName:function(country){this.countryName.innerHTML=country;},setZipcodeName:function(zipname){this.zipcodeName.innerHTML=zipname+':';},setStateLabel:function(label){this.stateLabel.innerHTML=label+':';},setSelectedProvince:function(provinceID){this.provinceHiddenInput.value=provinceID},getSelectedCountry:function(){return this.countryDropDown.options[this.countryDropDown.selectedIndex].value;},getSelectedProvince:function(){return this.provinceDropDown.options[this.provinceDropDown.selectedIndex].value;},getProvinces:function(countryID){id3Solutions.UShip.Web.PickupDropoff.GetStates(countryID,this.provinceDropDown.id,this.provinceHiddenInput.value,this.populateProvinces);},populateCountries:function(){var val=this.getSelectedCountry();this.setCountryName(this.countryDropDown.options[this.countryDropDown.selectedIndex].text);this.hideCountryList();if(val==1){if(this.fillStates){Element.show(this.provinceDropDown);Element.hide(this.provinceTextBox);this.getProvinces(val);Element.show(this.provinceGroup);}
else{Element.hide(this.provinceGroup);}
this.setZipcodeName('Zipcode');this.setStateLabel('State');}
else if(val==2){Element.show(this.provinceDropDown);Element.hide(this.provinceTextBox);this.getProvinces(val);Element.show(this.provinceGroup);this.setZipcodeName('Postal Code');this.setStateLabel('Province');}
else if(val==3){Element.show(this.provinceDropDown);Element.hide(this.provinceTextBox);this.getProvinces(val);Element.show(this.provinceGroup);this.setStateLabel('Province');}
else{Element.show(this.provinceTextBox);Element.hide(this.provinceDropDown);Element.show(this.provinceGroup);this.setZipcodeName('Postal Code');this.setStateLabel('Province/Region');}},populateProvinces:function(response){var drop=$(response.value.target);drop.innerHTML='';response.value.values.each(function(val){var isSelected=(response.value.selected==val.k);drop.options[drop.options.length]=new Option(val.v,val.k,isSelected,isSelected);});}}
var Timeframe=Class.create();Timeframe.prototype={initialize:function(date1,date2,date3,date4,cal,today){this.date1=$(date1);this.date2=$(date2);this.date3=$(date3);this.date4=$(date4);this.curr=null;this.today=today;this.calElem=$(cal);this.cal=new YAHOO.widget.Calendar('cal1',cal,{close:true});this.cal.selectEvent.subscribe(this.handleSelect.bind(this),this.cal1,true);this.cal.render();this.cal.hide();Event.observe(this.date1,'click',this.handleShow.bind(this));Event.observe(this.date2,'click',this.handleShow.bind(this));Event.observe(this.date3,'click',this.handleShow.bind(this));Event.observe(this.date4,'click',this.handleShow.bind(this));Event.observe(this.date1,'focus',this.handleShow.bind(this));Event.observe(this.date2,'focus',this.handleShow.bind(this));Event.observe(this.date3,'focus',this.handleShow.bind(this));Event.observe(this.date4,'focus',this.handleShow.bind(this));},handleSelect:function(type,args,obj){var dates=args[0];var date=dates[0];var year=date[0],month=date[1],day=date[2];this.curr.value=month+"/"+day+"/"+year;this.handleClose();},handleShow:function(e){this.curr=Event.element(e);if(!this.isValidFormat(this.curr.value)){this.curr.value=''}
if(this.curr==this.date1){this.cal.cfg.setProperty('mindate',this.today)}
else if(this.curr==this.date2){if(this.isValidFormat(this.date1.value)){this.cal.cfg.setProperty('mindate',this.date1.value)}}
else if(this.curr==this.date3){if(this.isValidFormat(this.date1.value)){this.cal.cfg.setProperty('mindate',this.date1.value)}
else{this.cal.cfg.setProperty('mindate',this.today)}}
else if(this.curr==this.date4){if(this.isValidFormat(this.date3.value)){this.cal.cfg.setProperty('mindate',this.date3.value)}}
if(this.isValidFormat(this.curr.value)){this.cal.select(this.curr.value);}
this.cal.render();this.cal.show();this.calElem.style.position='absolute';var p=YAHOO.util.Dom.getXY(this.curr);p[0]+=this.curr.offsetWidth+5;YAHOO.util.Dom.setXY(this.cal.oDomContainer,p,true);},handleClose:function(){this.cal.hide();},isValidFormat:function(date){return(date.length>0&&date.split('/')==3);}}
var AddressOptions=function(rbPreviousId,rbNewId,ddPreviousId,conNewId){this.rbPrevious=$(rbPreviousId);this.rbNew=$(rbNewId);this.ddPrevious=$(ddPreviousId);this.conNew=$(conNewId);Event.observe(this.rbPrevious,'click',this.handleRadioClick.bind(this));Event.observe(this.rbNew,'click',this.handleRadioClick.bind(this));Event.observe(this.ddPrevious,'click',this.handleDropdownClick.bind(this));Event.observe(this.ddPrevious,'change',this.handleDropdownChange.bind(this));Event.observe(this.conNew,'click',this.handleAreaClick.bind(this));Event.observe(this.conNew,'keypress',this.handleAreaKeyPress.bind(this));this.run();}
AddressOptions.prototype={run:function(){if(this.rbPrevious.checked){this.ddPrevious.removeClassName('deselected');this.conNew.addClassName('deselected');}
else if(this.rbNew.checked){this.ddPrevious.addClassName('deselected');this.conNew.removeClassName('deselected');}
else{this.ddPrevious.removeClassName('deselected');this.conNew.removeClassName('deselected');}},handleRadioClick:function(e){this.run();},handleDropdownClick:function(e){this.rbPrevious.checked=true;this.run();},handleDropdownChange:function(e){this.rbPrevious.checked=true;this.run();},handleAreaClick:function(e){this.rbNew.checked=true;this.run();},handleAreaKeyPress:function(e){this.ddPrevious.checked=true;this.run();}}
var PricingSelect=function(options){this.options=options;var noneSelected=false;for(var i=0,len=this.options.length;i<len;i++){this.options[i].radio.observe('click',this.handleRadioClick.bind(this));if(this.options[i].textbox){this.options[i].textbox.observe('click',this.handleTextboxClick.bind(this));}
if(!noneSelected){noneSelected=!this.options[i].radio.checked;}}
this.run(undefined,noneSelected);}
PricingSelect.prototype={run:function(click,noneSelected){for(var i=0,len=this.options.length;i<len;i++){if(!this.options[i].radio.checked&&this.options[i].textbox&&!noneSelected){this.options[i].textbox.addClassName('deselected');}
else if(this.options[i].textbox){this.options[i].textbox.removeClassName('deselected');if(click){this.options[i].textbox.focus();}}}},handleRadioClick:function(e){this.run(true);},handleTextboxClick:function(e){var elem=Event.element(e);for(var i=0,len=this.options.length;i<len;i++){var textbox=this.options[i].textbox;if(textbox&&textbox==elem){this.options[i].radio.checked=true;break;}}
this.run();}}
var PricingOption=function(radioId,textboxId){return{radio:$(radioId),textbox:$(textboxId)}}
var SelectOnType=function(chkNotifyId,txtMobileId){this.chkNotify=$(chkNotifyId);this.txtMobile=$(txtMobileId);this.length=this.txtMobile.value.length
Event.observe(this.txtMobile,'keyup',this.handleKeyPress.bind(this));}
SelectOnType.prototype={handleKeyPress:function(e){var len=this.txtMobile.value.length;if(this.txtMobile.value.length>0&&len>this.length){this.chkNotify.checked=true;}
this.length=len;}}
var MoneyHelper=function(txtAmountId){this.txtAmount=$(txtAmountId);Event.observe(this.txtAmount,'blur',this.handleBlur.bind(this));}
MoneyHelper.prototype={handleBlur:function(e){if(this.txtAmount.value.length>0){this.txtAmount.value=this.txtAmount.value.replace('$','');}}}
var HomeAddressOptions=function(rbPickupId,rbDeliveryId,rbNewId,conNewId){this.rbPickup=$(rbPickupId);this.rbDelivery=$(rbDeliveryId);this.rbNew=$(rbNewId);this.conNew=$(conNewId);Event.observe(this.rbPickup,'click',this.handleRadioClick.bind(this));Event.observe(this.rbDelivery,'click',this.handleRadioClick.bind(this));Event.observe(this.rbNew,'click',this.handleRadioClick.bind(this));Event.observe(window,'load',this.run.bind(this));this.run();}
HomeAddressOptions.prototype={run:function(){if(this.rbNew.checked){this.conNew.show();}
else{this.conNew.hide();}},handleRadioClick:function(e){Event.element(e).checked=true;this.run();}}
var uShipDefaultButton;var SetFocus=function(formId){var inputs=$$('td.form-nav input');if(inputs&&inputs.length>0){uShipDefaultButton=inputs[inputs.length-1];}
if(uShipDefaultButton!=undefined){Event.observe($('form1'),'keypress',function(e){if(e.keyCode==Event.KEY_RETURN){Event.stop(e);uShipDefaultButton.click();}});}}