/* Copyright 2009 Simply Extras Ltd */
var g_prod;function g_prod_init(c,b,d,a){g_prod=new ProductPage(c,b,d,a);g_prod.init_tabs();g_prod.fetch_prices()}function ProductPage(d,c,g,b){var f=this;f.product_id=d;f.do_load_prices=c;f.num_tabs=g;f.tab_string=b;f.gosajax=new GOSAjax("/prod_ajax.php");f.fetch_params=[f.product_id,"",0,0,0,0];f.init_tabs=function(){if(f.num_tabs>0){tabsinit(f.tab_string,0)}};f.sort=function(){var h=document.getElementById("sortby");if(h){f.fetch_params[1]=h.value;f.fetch_params[3]=0;f.fetch_prices()}};f.filter_size=function(h){f.fetch_params[4]=h;f.fetch_params[3]=0;f.fetch_prices()};f.filter_option=function(h){f.fetch_params[5]=h;f.fetch_params[3]=0;f.fetch_prices()};f.filter_none=function(){f.fetch_params[4]=0;f.fetch_params[5]=0;f.fetch_params[3]=0;f.fetch_prices()};f.perpage=function(){var h=document.getElementById("perpage");if(h){f.fetch_params[2]=h.value;f.fetch_params[3]=0;f.fetch_prices()}};f.fetch_prices_from=function(h){f.fetch_params[3]=h;f.fetch_prices();loc=document.location;loc.replace(loc.href.substr(0,loc.href.length-(loc.hash.length))+"#tabstop");return};f.fetch_prices=function(){if(!c){return}f.gosajax.call("fetch_prices",f.fetch_params,a)};function a(i,j,k){var l="";var h=0;if(j==-1){l="Sorry, the request to fetch the product prices has timed out."}if(j==0){l="Sorry, there was an error fetching the product prices."}if(l==""){document.getElementById("pricesTabBody").innerHTML=i}GOSAjax.done(l)}f.swap_img=function(h){document.mainimg.src=h};f._cookies=function(){if(document.cookie){var h=new Date();document.cookie="test=test";document.cookie="test=;expires=Thu, 01-Jan-1970 00:00:01 GMT"}return true};f.add_to_basket=function(m,x,w){var l;var n=document.getElementById("qty"+x);var r=document.getElementById("order_limit"+x);var p=document.getElementById("qty_in_basket"+x);var u=document.getElementById("stop_sale"+x);var o=document.getElementById("available"+x);var i=0;var h=0;var k=0;var j=0;if(!f._cookies()){alert("Cookies are not enabled")}else{if(r){i=parseInt(r.value,10)}if(p){h=parseInt(p.value,10)}if(u){k=parseInt(u.value,10)}if(o){j=parseInt(o.value,10)}if(n){var v=n.value;if(v==""){l=true}else{if(v.length>4){l=true}else{if(!v.match(/^ *[0-9]+ *$/)){l=true}}}v=parseInt(v,10);if(v<1||v>9999){l=true}if(l){alert("Please enter a quantity (1 to 9999) to add this item to your basket.");return}if(i>0){if((v+h)>i){alert("There is a limit of "+i+" of this item per order.");return}}if(k==1){if((v+h)>j){alert("This is not enough stock available.");return}}if(p){p.value=h+v}var t=document.getElementById("addbutton"+x);t.disabled=true;var s=document.getElementById("added"+x);if(w!="popup"){change_opacity(100,"added"+x);var q=(v==1)?"item":"items";s.innerHTML="Adding "+v+" "+q+"...";s.style.display="block"}f.gosajax.call("add_to_basket",[m,x,v,"PP"],function(y,z,A){ka_response=json_parse(y);if(e(ka_response.html,z,A)){if(ka_response.popup_html){s.style.display="none";f.popup_modal(ka_response.popup_html)}else{s.innerHTML="Added "+v+" "+q;setTimeout("fadeout_element('added"+x+"', 500)",1000)}t.disabled=false}else{s.style.display="none";t.disabled=false}})}}};f.popup_modal=function(j){shadow=f.create_shadow();popupWrapper=document.createElement("div");popupWrapper.id="popup-wrapper";document.body.appendChild(popupWrapper);popup=document.createElement("div");popup.id="popup-div";shadow.popupWrapper=popupWrapper;popupWrapper.shadow=shadow;hidePopup=document.createElement("div");hidePopup.id="hide-popup-div";hidePopup.onclick=f.close_popup;hidePopup.innerHTML='<img src="/img/icons/close-pop-up.png" class="pngme" width="46" height="46" />';popup.appendChild(hidePopup);popupWrapper.appendChild(popup);popupContent=document.createElement("div");popupContent.innerHTML=j;popupContent.id="popup-content";ia_closebuttons=f.find_eles_by_id(popupContent,"close-button");for(var h=0;h<ia_closebuttons.length;h++){ia_closebuttons[h].onclick=this.close_popup}popupContent.closeFunction=this.close_popup;popup.appendChild(popupContent);popup.style.top="20px"};f.find_eles_by_id=function(k,o){var n=k.childNodes;var h=[];for(var m=0;m<n.length;m++){ia_matching=f.find_eles_by_id(n[m],o);for(var l=0;l<ia_matching.length;l++){h.push(ia_matching[l])}if(n[m].id=="close-button"){h.push(n[m])}}return h};f.create_shadow=function(){shadow=document.createElement("div");shadow.id="popup-shadow";document.body.appendChild(shadow);shadow.onclick=this.close_popup;return shadow};f.close_popup=function(h){if(h==null){h=window.event}if(h!=null){if(h.target==null){ele=h.srcElement}else{ele=h.target}}if(ele.id=="popup-shadow"){popupWrapper=ele.popupWrapper;popupWrapper.parentNode.removeChild(popupWrapper);ele.parentNode.removeChild(ele)}else{while(ele.id!="popup-wrapper"){ele=ele.parentNode}if(ele.id=="popup-wrapper"){popupWrapper=ele;shadow=popupWrapper.shadow;popupWrapper.parentNode.removeChild(popupWrapper);shadow.parentNode.removeChild(shadow)}}g_prod.fetch_prices()};f.destroy_element=function(h){h.parentNode.removeChild(h)};function e(j,k,l){var m="";var h=0;if(k==-1){m="Sorry, the request to add to your basket has timed out."}if(k==0){m="Sorry, there was an error adding to your basket."}if(m==""){document.getElementById("basketsummary").innerHTML=j;var i=document.getElementById("edit-basket-link");if(i){i.style.visibility="visible"}}GOSAjax.done(m);return(m=="")}f.add_to_basket_single=function(k){var m=document.forms.basket_form;var i=m.elements["product"+k].value;var n=m.elements.qty.value;var l=false;if(i=="0"||i==""){return}else{if(n==""){l=true}else{if(n.length>4){l=true}else{if(!n.match(/^ *[0-9]+ *$/)){l=true}}}if(n<0||n>9999){l=true}if(l){alert("Please select a quantity to add this item to your basket.")}}if(!l){var j=document.getElementById("addedfader");change_opacity(100,"addedfader");var h=(n==1)?"item":"items";j.innerHTML="Adding "+n+" "+h+"...";j.style.display="block";f.gosajax.call("add_to_basket",[k,i,n,"PP"],function(o,p,q){if(e(o,p,q)){j.innerHTML="Added "+n+" "+h;setTimeout("fadeout_element('addedfader', 500)",1000)}else{j.style.display="none"}})}}}function fadeout_element(b,a){var e=Math.round(a/100);var f=0;for(var d=100;d>=0;--d){var c=(d==0)?1:0;setTimeout("change_opacity("+d+",'"+b+"',"+c+")",(f*e));f++}}function change_opacity(b,a,c){var d=document.getElementById(a).style;d.opacity=(b/100);d.MozOpacity=(b/100);d.KhtmlOpacity=(b/100);d.filter="alpha(opacity="+b+")";if(c){d.display="none"}};
