LicencePanel=Behavior.create({initialize:function(options,QuestionMarkUrl){this.QuestionMarkUrl=QuestionMarkUrl;this.licensing=eval(options);this.licenceEntries=[];this.createLicences()},createLicences:function(){for(var a=0;a<this.licensing.licences.length;a++){this.createLicence()}},createLicence:function(){var a=$div({"class":"licenceEntry"});this.element.down(".licenceEntries").insert(a);this.licenceEntries.push(new LicenceEntry(a,this))},onclick:function(b){var a=Event.element(b);if($(a).hasClassName("changeLicence")){this.showLicencePanel();Event.stop(b)}if($(a).hasClassName("applyLicenceToAllClips")){this.applyLicenceToAllClips();Event.stop(b)}if($(a).hasClassName("addLicence")){this.addLicence();Event.stop(b)}if($(a).hasClassName("updateLicence")){this.saveLicence();Event.stop(b)}if($(a).hasClassName("updateCurrency")){this.saveCurrency();Event.stop(b)}if($(a).hasClassName("cancel")){this.cancel();Event.stop(b)}if($(a).hasClassName("cancelCurrency")){this.cancelCurrency();Event.stop(b)}if($(a).hasClassName("helpIcon")){this.openHelpWindow();Event.stop(b)}if($(a).hasClassName("changeCurrency")){this.showCurrencyPanel();Event.stop(b)}},openHelpWindow:function(a){window.open(this.QuestionMarkUrl,"ITNSourceQuestionMarkUrl","")},applyLicenceToAllClips:function(){that=this;this.applyLicenceToAllClipsRequest()},addLicence:function(a){this.createLicence()},saveLicence:function(a){this.licenceEntries.each(function(b){b.updateValues()});that=this;this.saveLicenceRequest()},saveCurrency:function(a){that=this;this.saveCurrencyRequest()},saveLicenceRequestCreate:function(){$("spinner").replace("<img src='/i/processing.gif' id='spinner' />")},saveCurrencyRequestCreate:function(){$("spinnerCurrency").replace("<img src='/i/processing.gif' id='spinnerCurrency' />")},saveLicenceRequestSuccess:function(b){that.licensing=b.responseText.evalJSON();that.licenceEntries.each(function(c){c.licence=that.licensing.licences[c.licenceIndex]});var a=that.getLicenceDescription(that.licensing);that.hideLicencePanel();that.element.select(".licenceText").invoke("update",a)},saveCurrencyRequestSuccess:function(b){that.licensing=b.responseText.evalJSON();that.licenceEntries.each(function(c){c.licence=that.licensing.licences[c.licenceIndex]});var a=that.getLicenceDescription(that.licensing);that.hideCurrencyPanel();that.element.select(".licenceText").invoke("update",a)},getLicenceDescription:function(b){var c="";var a="";b.licences.each(function(d){market=d.Market+(d.Market=="One Country"?" ("+d.Country+")":"");a=a+c+d.Media+", "+market+" for "+d.Duration;c="<br />"});return a},saveLicenceRequestComplete:function(){$("spinner").replace("<span id='spinner'></span>")},saveCurrencyRequestComplete:function(){$("spinnerCurrency").replace("<span id='spinnerCurrency'></span>")},cancel:function(c){this.hideLicencePanel();var b=this.licenceEntries.length-this.licensing.licences.length;for(var a=1;a<=b;a++){this.licenceEntries[this.licenceEntries.length-1].element.remove();this.licenceEntries.splice(this.licenceEntries.length-1,1)}this.licenceEntries.each(function(d){d.loadValues()})},cancelCurrency:function(a){this.hideCurrencyPanel()},showLicencePanel:function(a){this.element.down(".licenceOptions").show()},hideLicencePanel:function(a){this.element.down(".licenceOptions").hide()},showCurrencyPanel:function(a){this.element.down(".currencyOptions").show()},hideCurrencyPanel:function(a){this.element.down(".currencyOptions").hide()}});LicenceEntry=Behavior.create({initialize:function(a){this.licenceEntryPanel=a;this.licenceIndex=this.licenceEntryPanel.licenceEntries.length;this.total=0;this.currency="";this.licence=this.licenceEntryPanel.licensing.licences[this.licenceIndex];this.create();this.loadValues()},create:function(){var c="media_"+this.licenceIndex;var a="country_"+this.licenceIndex;var b="market_"+this.licenceIndex;var d=(this.licenceIndex>0)?'<a href="#" class="secondaryLink removeLicence">remove</a>':"";html='<fieldset><label>Licence:</label><select id="'+c+'" name="'+c+'" class="media">'+this.createOptions(LicenceEntry.MEDIA)+'</select><a href="javascript:;"><img src="/i/question_icon.gif" alt="Help" title="Help" class="helpIcon"/></a></fieldset><fieldset><label for="marketType">Market:</label><input type="radio" id="'+b+'0" name="'+b+'" value="One Country" class="market"><label for="'+b+'0">Country</label><input type="radio" id="'+b+'1" name="'+b+'" value="World" class="market"><label for="'+b+'1">World</label><select id="'+a+'" name="'+a+'" class="country">'+this.createOptions(LicenceEntry.COUNTRIES)+"</select>"+d+"</fieldset>";this.element.innerHTML=html},loadValues:function(){if(this.licence){var b=this.element.down('[id^="media"]');this.setListOption(this.licence.Media,b);var a=this.element.down('[id^="country"]');this.setListOption(this.licence.Country,a);if(this.licence.Market=="World"){this.element.down('input[value="World"]').checked=true}else{this.element.down('input[value="One Country"]').checked=true}}},updateValues:function(){if(this.licence==null){this.licence={};this.licenceEntryPanel.licensing.licences.push(this.licence)}this.licence.Media=this.element.down('[id^="media"]').getValue();if(this.element.down('input[value="World"]').checked){this.licence.Market="World";this.licence.Country=""}else{this.licence.Market="One Country"}this.licence.Country=this.element.down('[id^="country"]').getValue()},createOptions:function(c){var a="";for(var b=0;b<c.length;b++){a=a+'<option value="'+c[b]+'">'+c[b]+"</option>"}return a},setListOption:function(c,b){if(c){for(var a=0;a<b.options.length;a++){if(b.options[a].value==c){b.selectedIndex=a;break}}}},onclick:function(b){var a=Event.element(b);if(a.match('input[type="radio"]')){return}if($(a).hasClassName("removeLicence")){this.remove();Event.stop(b)}},remove:function(a){this.licenceEntryPanel.licensing.licences.splice(this.licenceIndex,1);this.element.remove();this.licenceEntryPanel.licenceEntries.splice(this.licenceIndex,1)}});var saveUserLicence=function(a){new Ajax.Request("/ajax/licencehandler.ashx",{parameters:{Licences:Object.toJSON(that.licensing),Currency:$j("#licenseCurrencyList").val()},onCreate:this.saveLicenceRequestCreate,onSuccess:function(b){that.saveLicenceRequestSuccess(b);that.element.down(".price").replace("<span class='price'>"+that.licensing.CurrencySymbol+""+that.licensing.Price+"</span>");that.element.down(".price").highlight({duration:2,endcolor:"#E7E7E7"});$$(".shotPrice").invoke("replace","<span class='smallPrice shotPrice'>"+that.licensing.CurrencySymbol+""+that.licensing.Price+"</span>");if($("totalPrice")){$("totalPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price*$$(".shotPrice").length)}that.element.down(".licenceText").highlight({duration:2,endcolor:"#E7E7E7"});$j("#currenciesList").val($j("#licenseCurrencyList").val())},onComplete:this.saveLicenceRequestComplete})};var saveUserCurrency=function(a){new Ajax.Request("/ajax/licencehandler.ashx",{parameters:{context:"currency",currency:$j("#currenciesList").val(),Licences:Object.toJSON(that.licensing)},onCreate:this.saveCurrencyRequestCreate,onSuccess:function(b){that.saveCurrencyRequestSuccess(b);that.element.down(".price").replace("<span class='price'>"+that.licensing.CurrencySymbol+""+that.licensing.Price+"</span>");that.element.down(".price").highlight({duration:2,endcolor:"#E7E7E7"});$$(".shotPrice").invoke("replace","<span class='smallPrice shotPrice'>"+that.licensing.CurrencySymbol+""+that.licensing.Price+"</span>");if($("totalPrice")){$("totalPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price*$$(".shotPrice").length)}that.element.down(".licenceText").highlight({duration:2,endcolor:"#E7E7E7"})},onComplete:this.saveCurrencyRequestComplete})};var saveBasketLicence=function(a){new Ajax.Request("/ajax/licencehandler.ashx",{parameters:{context:"basket",Licences:Object.toJSON(that.licensing)},onCreate:this.saveLicenceRequestCreate,onSuccess:function(b){that.saveLicenceRequestSuccess(b);that.element.down(".shotPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price);that.element.down(".shotPrice").highlight({duration:2});that.element.down(".licenceText").highlight({duration:2,endcolor:"#FFFFFF"});that.updateTotals()},onComplete:this.saveLicenceRequestComplete})};var saveClipbinLicence=function(b){var a=this.element.id.match(/\d+\.?\d*/);that=this;new Ajax.Request("/ajax/licencehandler.ashx",{parameters:{context:"clipbin",clipKey:a,Licences:Object.toJSON(that.licensing)},onCreate:this.saveLicenceRequestCreate,onSuccess:function(c){that.saveLicenceRequestSuccess(c);that.element.down(".shotPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price);that.element.down(".licenceText").highlight({duration:2,endcolor:"#FFFFFF"})},onComplete:this.saveLicenceRequestComplete})};var applyLicenceToAllClipsInBasket=function(b){that=this;var a=this.element.id.match(/\d+\.?\d*/);new Ajax.Request("/Ajax/LicenceHandler.ashx",{parameters:{context:"applyToAllInBasket",orderItemProductId:a,Licences:Object.toJSON(that.licensing)},onSuccess:function(c){that.total=0;LicencePanel.instances.each(function(h){h.licensing=c.responseText.evalJSON();h.licensing.Id="-"+h.element.id.match(/\d+\.?\d*/);h.licenceEntries=[];h.element.select(".licenceEntry").invoke("remove");h.createLicences();var g=h.getLicenceDescription(h.licensing);h.element.select(".licenceText").invoke("update",g);h.element.down(".shotPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price);h.element.down(".shotPrice").highlight({duration:2});that.total=that.total+parseFloat(that.licensing.Price);that.currency=that.licensing.CurrencySymbol});var f=$$("span[id=finalTotalPriceValue]");if(f!=undefined&&f.length>0){f[0].innerHTML=that.currency+that.total}var e=$$("span[id=finalDiscountTotalPriceValue]");var d=$$("span[id=DiscountValue]");if(e!=undefined&&e.length>0&&d!=undefined&&d.length>0){e[0].innerHTML=that.currency+""+(parseFloat(that.total)*parseFloat(d[0].innerHTML))}}})};var applyLicenceToAllClipsInClipbin=function(a){that=this;var b=this.element.id.match(/\d+\.?\d*/);new Ajax.Request("/Ajax/LicenceHandler.ashx",{parameters:{context:"applyToAllInClipbin",orderItemProductId:b,Licences:Object.toJSON(that.licensing)},onSuccess:function(c){LicencePanel.instances.each(function(e){e.licensing=c.responseText.evalJSON();e.licensing.Id="-"+e.element.id.match(/\d+\.?\d*/);e.licenceEntries=[];e.element.select(".licenceEntry").invoke("remove");e.createLicences();var d=e.getLicenceDescription(e.licensing);e.element.select(".licenceText").invoke("update",d);e.element.down(".shotPrice").update(that.licensing.CurrencySymbol+""+that.licensing.Price);e.element.down(".shotPrice").highlight({duration:2})})}})};var updateTotals=function(){new Ajax.Request("/ajax/BasketTotalHandler.ashx",{onSuccess:function(a){var b=a.responseText.evalJSON();$("finalTotalPrice").next().update(that.licensing.CurrencySymbol+""+b.total);$("finalDiscountTotalPrice").next().update(that.licensing.CurrencySymbol+""+b.discountTotal)}})};