/**
 *  Most of the scripts below were found at
 *  www.alistapart.com and related sites.  They are used
 *  here because they are web standards compliant.  These
 *  scripts are all free to reuse and are not licensed as
 *  part of the software core.
 *
 *  All onload() events go at the bottom of this file.
 */

/**
 *  Function DisableSubmit() used to disable submit buttons
 *  after then have been depressed.  This is implemented to
 *  stop multiple click submissions of forms.
 */

var submitted = false;

function DisableSubmit(formname) {

     if (submitted == true) { return; }
     document.forms[formname].submit();

          var subid = document.getElementById(formname + '--SUBMIT');

     subid.value = 'Please Wait...';
     subid.disabled = true;
     submitted = true;

}

/**
 *  Function externalLinks() used to provide a standards
 *  compliant way of producing a pop-up link to another
 *  page.
 */

function externalLinks() {

     if (!document.getElementsByTagName) return;
     var anchors = document.getElementsByTagName("a");
     for (var i=0; i<anchors.length; i++) {
     var anchor = anchors[i];
     if (anchor.getAttribute("href") &&
     anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
     }

}

/**
 *  Function to add multiple onload() events to a page. 
 *  Authored by Scott Andrew.  Visit www.scottandrew.com
 *  for info.
 */

function addWindowEvent(elm, evType, fn, useCapture) {

     if (elm.addEventListener) {
     elm.addEventListener(evType, fn, useCapture);
     return true;
     } else if (elm.attachEvent) {
     var r = elm.attachEvent('on' + evType, fn);
     return r;
     } else {
     elm['on' + evType] = fn;
     }

}

/**
 *	Whatever:hover - V1.42.060206 - hover & active
 *	------------------------------------------------------------
 *	(c) 2005 - Peter Nederlof
 *	Peterned - http://www.xs4all.nl/~peterned/
 *	License  - http://creativecommons.org/licenses/LGPL/2.1/
 *
 *	Whatever:hover is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	Whatever:hover is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *	Lesser General Public License for more details.
 *
 *	Credits and thanks to:
 *	Arnoud Berendsen, Martin Reurings, Robert Hanson
 *
 *	howto: body { behavior:url("csshover.htc"); }
 *	------------------------------------------------------------
 */

var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,

currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:'onmouseover', off:'onmouseout'},
onactive:{on:'onmousedown', off:'onmouseup'}
}

function parseStylesheets() {

     if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
     window.attachEvent('onunload', unhookHoverEvents);
     var sheets = doc.styleSheets, l = sheets.length;
     for(var i=0; i<l; i++) 
     parseStylesheet(sheets[i]);

}

function parseStylesheet(sheet) {

     if(sheet.imports) {
     try {
     var imports = sheet.imports, l = imports.length;
     for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
     } catch(securityException){}
     }
     try {
     var rules = (currentSheet = sheet).rules, l = rules.length;
     for(var j=0; j<l; j++) parseCSSRule(rules[j]);
     } catch(securityException){}

}

function parseCSSRule(rule) {

     var select = rule.selectorText, style = rule.style.cssText;
     if(!csshoverReg.test(select) || !style) return;
     var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
     var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
     var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
     var affected = select.replace(/:(hover|active).*$/, '');
     var elements = getElementsBySelect(affected);
     if(elements.length == 0) return;
     currentSheet.addRule(newSelect, style);
     for(var i=0; i<elements.length; i++)
     new HoverElement(elements[i], className, activators[pseudo]);

}

function HoverElement(node, className, events) {

     if(!node.hovers) node.hovers = {};
     if(node.hovers[className]) return;
     node.hovers[className] = true;
     hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
     hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });

}

function hookHoverEvent(node, type, handler) {

     node.attachEvent(type, handler);
     hoverEvents[hoverEvents.length] = { 
     node:node, type:type, handler:handler 
     };

}

function unhookHoverEvents() {

     for(var e,i=0; i<hoverEvents.length; i++) {
     e = hoverEvents[i]; 
     e.node.detachEvent(e.type, e.handler);
     }
}

function getElementsBySelect(rule) {

     var parts, nodes = [doc];
     parts = rule.split(' ');
     for(var i=0; i<parts.length; i++) {
     nodes = getSelectedNodes(parts[i], nodes);
     }
     return nodes;

}

function getSelectedNodes(select, elements) {

     var result, node, nodes = [];
     var identify = (/\#([a-z0-9_-]+)/i).exec(select);
     if(identify) {
     var element = doc.getElementById(identify[1]);
     return element? [element]:nodes;
     }
     var classname = (/\.([a-z0-9_-]+)/i).exec(select);
     var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
     var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
     for(var i=0; i<elements.length; i++) {
     result = tagName? elements[i].all.tags(tagName):elements[i].all; 
     for(var j=0; j<result.length; j++) {
     node = result[j];
     if(classReg && !classReg.test(node.className)) continue;
     nodes[nodes.length] = node;
     }
     }	
     return nodes;

}

/**
 *  Function to show or hide an id within an XHTML page.
 */

function idShowHide(obj) {

     var el = document.getElementById(obj);
     if ( el.style.display != "none" ) {
     el.style.display = 'none';
     } else {
     el.style.display = 'block';
     }

}

/**
 *  WYSIWYG Editors.
 */

function wysiwygLoad(id) {

     var pid = id + '--wysiwyglink';
     var el  = document.getElementById(pid);

     if ( el.style.display != "none" ) {
     el.style.display = 'none';
     $(id).mooEditable({buttons: 'bold,italic,underline,strikethrough,|,insertunorderedlist,insertorderedlist,indent,outdent,|,undo,redo,|,toggleview'});
     }

}



/**
 *  Function to view a section within an XHTML page.  Closes other
 *  sections when a new section is opened.
 */

function toggleView(obj,arr) {

     if (arr) {for (var i = 0; i < arr.length; i++) {

          var svael = document.getElementById(arr[i]);
          svael.style.display = 'none';

     }}

     var el           = document.getElementById(obj);
     el.style.display = 'block';

}


/**
 *  Function to view hide all sections within an XHTML page.
 */

function toggleHideAll(arr) {

     if (arr) {for (var i = 0; i < arr.length; i++) {

          var svael = document.getElementById(arr[i]);
          svael.style.display = 'none';

     }}

}


/**
 *  Function to highlight a div within an XHTML page.
 */

function toggleHighlight(obj,arr) {

     if (arr) {for (var i = 0; i < arr.length; i++) {

          var svael                 = document.getElementById(arr[i]);
          svael.style.background    = 'url("skins/Default/media/taboff.png")';
          svael.style.color         = '#FFFFFF';

     }}

     var el                    = document.getElementById(obj);
     el.style.background       = 'url("skins/Default/media/tabon.png")';
     el.style.color            = '#000000';

}


/**
 *  Update price
 */

function updatePrice(p_prodid,p_tabid,p_formid,p_sid) {

     if (!p_prodid)    {return;}
     if (!p_tabid)     {return;}
     if (!p_formid)    {return;}
     if (!p_sid)       {return;}

     prodid   = p_prodid;
     pricediv = 'pricediv_' + p_tabid;
     mrrpdiv  = 'mrrpdiv_' + p_tabid;
     discdiv  = 'discdiv_' + p_tabid;
     savediv  = 'savediv_' + p_tabid;
     bpnumdiv   = 'bpnum_' + p_tabid;
     bpworthdiv = 'bpworth_' + p_tabid;
     bpfulldiv  = 'bpfulldiv_' + p_tabid;
     voldiv     = 'voldiv_' + p_tabid;

     formid   = p_formid;
     sid      = p_sid;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          $('#' + formid + '--tooltipaddcartconf').qtip('hide');

     }, 0);

     setTimeout( function() {

          pricedivORIG = document.getElementById(pricediv + '--ORIG').innerHTML;
          mrrpdivORIG  = document.getElementById(mrrpdiv + '--ORIG').innerHTML;
          discdivORIG  = document.getElementById(discdiv + '--ORIG').innerHTML;
          savedivORIG  = document.getElementById(savediv + '--ORIG').innerHTML;
          bpnumdivORIG  = document.getElementById(bpnumdiv + '--ORIG').innerHTML;
          bpworthdivORIG  = document.getElementById(bpworthdiv + '--ORIG').innerHTML;
          bpfulldivORIG  = document.getElementById(bpfulldiv + '--ORIG').innerHTML;

          document.getElementById(pricediv).innerHTML = '<img src="media/scripts/small_loading_bkwt.gif" height="13" />';
          document.getElementById(mrrpdiv).innerHTML = '<img src="media/scripts/small_loading_bkwt.gif" height="13" />';
          document.getElementById(discdiv).innerHTML = '<img src="media/scripts/small_loading_bkwt.gif" height="13" />';
          document.getElementById(savediv).innerHTML = '<img src="media/scripts/small_loading_bkwt.gif" height="13" />';
          document.getElementById(bpnumdiv).innerHTML = 'TBD';
          document.getElementById(bpworthdiv).innerHTML = 'TBD';
          document.getElementById(bpfulldiv).innerHTML = '<img src="media/scripts/small_loading_bkwt.gif" height="13" />';

          if (prodid == 'Voucher-Custom') {

               customvoucherdivORIG = document.getElementById('customvoucheramt--ORIG').innerHTML;

               document.getElementById('customvoucheramt').innerHTML = '<img src="media/scripts/small_loading_bkgn.gif" />';

          }

     }, 100);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("POST","index.php",false);
          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

          var extrafields = '';

          var frm_element = document.getElementById(formid + '--' + prodid);

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'sid')      {oktoadd = 0;}
               if (frm_element.elements[i].name == 'app')      {oktoadd = 0;}
               if (frm_element.elements[i].name == 'ns')       {oktoadd = 0;}
               if (frm_element.elements[i].name == 'SUBMIT')   {oktoadd = 0;}
               if (frm_element.elements[i].name == 'WISHLIST') {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    var quanfield = formid + '--' + prodid + '--quantity';

                    if (frm_element.elements[i].name == quanfield) {

                         if (frm_element.elements[i].value < 1) {fieldvalue = 1;}

                         var minquanid = formid + '--' + prodid + '--minquan';

                         if (document.getElementById(minquanid)) {

                              var minquanval = document.getElementById(minquanid).innerHTML;

                              if (parseInt(fieldvalue) < parseInt(minquanval)) {

                                   fieldvalue = document.getElementById(minquanid).innerHTML;

                                   frm_element.elements[i].value = fieldvalue;

                              }

                         }

                    }

                    extrafields = extrafields + '&' + frm_element.elements[i].name + '=' + $.url.encode(fieldvalue);

               }

          }}

          xmlhttp.send('app=ecom&ns=ajaxpriceupdate&sid=' + sid + '&prodid=' + prodid + extrafields);

          var AJAXresponseText = 'ERROR';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          if (AJAXresponseText == 'ERROR') {

               document.getElementById(pricediv).innerHTML   = pricedivORIG;
               document.getElementById(mrrpdiv).innerHTML    = mrrpdivORIG;
               document.getElementById(discdiv).innerHTML    = discdivORIG;
               document.getElementById(savediv).innerHTML    = savedivORIG;
               document.getElementById(bpnumdiv).innerHTML   = bpnumdivORIG;
               document.getElementById(bpworthdiv).innerHTML = bpworthdivORIG;
               document.getElementById(bpfulldiv).innerHTML  = bpfulldivORIG;

               if (prodid == 'Voucher-Custom') {

                    document.getElementById('customvoucheramt').innerHTML  = customvoucherdivORIG;

               }

          } else {

               var ResponseText = AJAXresponseText.split('|');

               document.getElementById(pricediv).innerHTML = ResponseText[0];
               document.getElementById(mrrpdiv).innerHTML  = ResponseText[1];
               document.getElementById(discdiv).innerHTML  = ResponseText[2];
               document.getElementById(savediv).innerHTML  = ResponseText[3];

               if (prodid == 'Voucher-Custom') {

                    if (ResponseText[4]) {document.getElementById('customvoucheramt').innerHTML  = ResponseText[4];}
                    else                 {document.getElementById('customvoucheramt').innerHTML  = customvoucherdivORIG;}

               } else {

                    var pricedivFULL = pricediv + '-FULL';
                    document.getElementById(pricedivFULL).style.display = 'block';

               }

               var discamt = ResponseText[2];
               discamt     = discamt.replace(/^(.*?)\;/,'');

               if (discamt > 0) {$('#' + discdiv + '-FULL').css({'display': 'block'});}
               else             {$('#' + discdiv + '-FULL').css({'display': 'none'});}

               document.getElementById(bpnumdiv).innerHTML   = ResponseText[5];
               document.getElementById(bpworthdiv).innerHTML = ResponseText[6];
               document.getElementById(bpfulldiv).innerHTML  = ResponseText[7];

               document.getElementById(voldiv).innerHTML  = ResponseText[8];

          }

     }, 400);

     return;

}



/**
 *  cartAddConfirm
 */

function cartAddConfirm (p_prodid,p_formid,p_sid) {

     if (!p_prodid) {return;}
     if (!p_formid) {return;}
     if (!p_sid)    {return;}

     prodid  = p_prodid;
     formid  = p_formid;
     sid     = p_sid;

     tooltipid = '#' + formid + '--' + prodid + '--tooltipaddcartconf';

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          if ($(tooltipid).data('qtip')) {$(tooltipid).qtip('hide');}

          $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcartconfdd.png")'});

          ContentOverlay('ON');

          cartdivORIG = document.getElementById('skinshoppingcart').innerHTML;
          document.getElementById('skinshoppingcart').innerHTML = 'Adding to Shopping Basket...';

          ajaxcartdivORIG = document.getElementById('ajaxminicartdispcontentwrap').innerHTML;
          document.getElementById('ajaxminicartdispcontentwrap').innerHTML = 'Updating Shopping Basket...';

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("POST","index.php",false);
          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

          var extrafields = '';

          var frm_element = document.getElementById(formid + '--' + prodid);

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'SUBMIT')   {oktoadd = 0;}
               if (frm_element.elements[i].name == 'WISHLIST') {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].name == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].type == undefined) {oktoadd = 0;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    extrafields = extrafields + '&' + frm_element.elements[i].name + '=' + $.url.encode(fieldvalue);

               }

          }}

          xmlhttp.send('ajax=1' + extrafields);

          var AJAXresponseText = 'ERROR';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          if (AJAXresponseText == 'ERROR') {

               $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcarterror.png")'});

               document.getElementById('skinshoppingcart').innerHTML            = cartdivORIG;
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = ajaxcartdivORIG;

               if (prodid == 'Voucher-Custom') {$('#' + formid + '--' + prodid + '--customvoucheramt').css({'background-color': '#FAC0C2', 'border-color': '#FF0000'});}

          } else {

               $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcartconf.png")'});

               var AJAXresponseTextParts = AJAXresponseText.split('AJAXCARTCONTENTS:');
               document.getElementById('skinshoppingcart').innerHTML = AJAXresponseTextParts[0];
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = AJAXresponseTextParts[1];

               if (prodid == 'Voucher-Custom') {$('#' + formid + '--' + prodid + '--customvoucheramt').css({'background-color': '#FFFFFF', 'border-color': '#B4D666'});}

               if ($('#ajax_customjstodo').length > 0) {

                    eval(document.getElementById('ajax_customjstodo').innerHTML);
                    $('#ajax_customjstodo').remove();

               }

          }

     }, 100);

     setTimeout( function() {

          if (!($(tooltipid).data('qtip'))) {

               $(tooltipid).qtip({
                    id: tooltipid,
                    content: {text: $(tooltipid + 'content'), prerender: true},
                    style: {classes: 'ui-tooltip-tooltipaddcartconf ui-tooltip-rounded', width: 271, tip: false},
                    show: {event: false, delay: 500, effect: function() {$(this).show('blind', { direction: 'left'}, 600);}},
                    hide: {event: false, inactive: 3000, effect: function() {$(this).hide('blind', { direction: 'right'}, 600);}},
                    position: {my: 'left middle', at: 'right middle', adjust: {x: -24, y: -3}}
               });

          }

          $(tooltipid).qtip('show');

     }, 400);

     setTimeout( function() {

          ReloadImages();

          ToolTips();

          ContentOverlay('OFF');

     }, 500);

     return false;

}


/**
 *  DiscountDoublesConfirm
 */

function DiscountDoublesConfirm (p_sid) {

     sid      = p_sid;

     tooltipid = '#discountdoubles--tooltipaddcartconf';

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          if ($(tooltipid).data('qtip')) {$(tooltipid).qtip('hide');}

          $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcartconfdd.png")'});

          ContentOverlay('ON');

          cartdivORIG = document.getElementById('skinshoppingcart').innerHTML;
          document.getElementById('skinshoppingcart').innerHTML = 'Adding to Shopping Basket...';

          ajaxcartdivORIG = document.getElementById('ajaxminicartdispcontentwrap').innerHTML;
          document.getElementById('ajaxminicartdispcontentwrap').innerHTML = 'Updating Shopping Basket...';

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("POST","index.php",false);
          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

          var extrafields = '';

          var frm_element = document.getElementById(prodone_formid + '--' + prodone_prodid);

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'SUBMIT')   {oktoadd = 0;}
               if (frm_element.elements[i].name == 'WISHLIST') {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].name == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].type == undefined) {oktoadd = 0;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    var fieldname  = frm_element.elements[i].name;
                    fieldname      = fieldname.replace(prodone_formid,'ecom--prodaddtocartM')

                    extrafields = extrafields + '&' + fieldname + '=' + $.url.encode(fieldvalue);

               }

          }}

          var frm_element = document.getElementById(prodtwo_formid + '--' + prodtwo_prodid);

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'SUBMIT')   {oktoadd = 0;}
               if (frm_element.elements[i].name == 'WISHLIST') {oktoadd = 0;}
               if (frm_element.elements[i].name == 'app')      {oktoadd = 0;}
               if (frm_element.elements[i].name == 'ns')       {oktoadd = 0;}
               if (frm_element.elements[i].name == 'sid')      {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].name == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].type == undefined) {oktoadd = 0;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    var fieldname  = frm_element.elements[i].name;
                    fieldname      = fieldname.replace(prodtwo_formid,'ecom--prodaddtocartM')

                    extrafields = extrafields + '&' + fieldname + '=' + $.url.encode(fieldvalue);

               }

          }}

          xmlhttp.send('ajax=1' + extrafields);

          var AJAXresponseText = 'ERROR';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          if (AJAXresponseText == 'ERROR') {

               $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcarterrordd.png")'});

               document.getElementById('skinshoppingcart').innerHTML            = cartdivORIG;
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = ajaxcartdivORIG;

          } else {

               $('.tooltipaddcartwrap').css({'background-image': 'url("skins/Default/media/addcartconfdd.png")'});

               var AJAXresponseTextParts = AJAXresponseText.split('AJAXCARTCONTENTS:');
               document.getElementById('skinshoppingcart').innerHTML = AJAXresponseTextParts[0];
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = AJAXresponseTextParts[1];

               if ($('#ajax_customjstodo').length > 0) {

                    eval(document.getElementById('ajax_customjstodo').innerHTML);
                    $('#ajax_customjstodo').remove();

               }

          }

     }, 100);

     setTimeout( function() {

          if (!($(tooltipid).data('qtip'))) {

               $(tooltipid).qtip({
                    id: tooltipid,
                    content: {text: $(tooltipid + 'content'), prerender: true},
                    style: {classes: 'ui-tooltip-tooltipaddcartconf ui-tooltip-rounded', width: 271, tip: false},
                    show: {event: false, delay: 500, effect: function() {$(this).show('blind', { direction: 'left'}, 600);}},
                    hide: {event: false, inactive: 3000, effect: function() {$(this).hide('blind', { direction: 'right'}, 600);}},
                    position: {my: 'left middle', at: 'right middle', adjust: {x: -24, y: -3}}
               });

          }

          $(tooltipid).qtip('show');

     }, 400);

     setTimeout( function() {

          ReloadImages();

          ToolTips();

          ContentOverlay('OFF');

     }, 500);

     return false;

}


/**
 *  ToolTips
 */

function ToolTips() {

     $('.tooltip img[title]').qtip({
          content: {text: false},
          position: {my: 'left middle', at: 'right middle', viewport: $(window)},
          style: {classes: 'ui-tooltip-tooltipdisp ui-tooltip-shadow ui-tooltip-rounded', width: 280}
     });

}

$(document).ready(function() {ToolTips();});

/**
 *  AjaxCartCheckoutPost
 */

function AjaxCartCheckoutPost (p_formid, p_destns, p_cartinfourl) {

     if (!p_formid) {return;}

     formid      = p_formid;
     destns      = p_destns;
     cartinfourl = p_cartinfourl;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          cartdivORIG = '';

          if (cartinfourl) {

               cartdivORIG = document.getElementById('skinshoppingcart').innerHTML;
               document.getElementById('skinshoppingcart').innerHTML = 'Updating Shopping Basket...';

               ajaxcartdivORIG = document.getElementById('ajaxminicartdispcontentwrap').innerHTML;
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = 'Updating Shopping Basket...';

          }

          ContentOverlay('ON');

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("POST","index.php",false);
          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

          var extrafields = '';

          var frm_element = document.getElementById(formid);

          var ajax_seen = 0;

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'SUBMIT')       {oktoadd = 0;}
               if (frm_element.elements[i].name == 'WISHLIST')     {oktoadd = 0;}
               if (frm_element.elements[i].name == 'ns' && destns) {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].name == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].type == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].name == 'ajax') {ajax_seen = 1;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    extrafields = extrafields + '&' + frm_element.elements[i].name + '=' + $.url.encode(fieldvalue);

               }

          }}

          extrafields = extrafields.replace(/^\&/,'');

          var ajaxfield = ''; if (!(ajax_seen)) {ajaxfield = 'ajax=1&';}

          var fielddestns = ''; if (destns) {fielddestns = 'ns=' + destns + '&';}

          xmlhttp.send(ajaxfield + fielddestns + extrafields);

          var AJAXresponseText = '';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          document.getElementById('skin_content_div').innerHTML = AJAXresponseText;

          if ($('#ajax_customjstodo').length > 0) {

               eval(document.getElementById('ajax_customjstodo').innerHTML);
               $('#ajax_customjstodo').remove();

          }

     }, 200);

     if (cartinfourl) {

          setTimeout( function() {

               if (window.XMLHttpRequest) {

                    var xmlhttp = new XMLHttpRequest();

               } else {

                    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

               }

               xmlhttp.open("GET", cartinfourl, false);

               xmlhttp.send(null);

               var AJAXresponseText = 'ERROR';
               if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

               if (AJAXresponseText == 'ERROR') {

                    document.getElementById('skinshoppingcart').innerHTML        = cartdivORIG;
                    document.getElementById('ajaxminicartdispcontentwrap').innerHTML = ajaxcartdivORIG;

               } else {

                    var AJAXresponseTextParts = AJAXresponseText.split('AJAXCARTCONTENTS:');
                    document.getElementById('skinshoppingcart').innerHTML = AJAXresponseTextParts[0];
                    document.getElementById('ajaxminicartdispcontentwrap').innerHTML = AJAXresponseTextParts[1];

                    if ($('#ajax_customjstodo').length > 0) {

                         eval(document.getElementById('ajax_customjstodo').innerHTML);
                         $('#ajax_customjstodo').remove();

                    }

               }

          }, 400);

     }

     setTimeout( function() {

          ReloadImages();

          ToolTips();

          ContentOverlay('OFF');

     }, 500);

     setTimeout( function() {
          
          ScrollToTop();

     }, 510);

     return false;

}

/**
 *  RenderGenAjax
 */

function RenderGenAjax (p_divid, p_title, p_cssclass) {

     if (!p_divid)  {return;}
     if (!p_title)  {return;}

     divid       = p_divid;
     title       = p_title;
     cssclass    = p_cssclass;

     if (!cssclass) {cssclass = 'ui-tooltip-genajax';}

     setTimeout( function() {

          if (!(document.getElementById(divid + 'orig').innerHTML)) {

               document.getElementById(divid + 'orig').innerHTML = $.url.encode(document.getElementById(divid + 'content').innerHTML);

          } else {

               document.getElementById(divid + 'content').innerHTML = $.url.decode(document.getElementById(divid + 'orig').innerHTML);

          }

          if (!($('#' + divid + 'link').data('qtip'))) {

               $('#' + divid + 'link').qtip({
                    id: divid + 'link',
                    content: {text: $('#' + divid + 'content'), prerender: true, title: {text: title}},
                    style: {classes: cssclass + ' ui-tooltip-shadow ui-tooltip-rounded', width: 710, tip: {width: 12, height: 24}},
                    show: {event: false},
                    hide: {event: 'unfocus'},
                    position: {my: 'bottom center', at: 'top center', viewport: $(window)}
               });


          }

          $('#' + divid + 'link').qtip('show');

    }, 0);

    return false;

}

/**
 *  GenAjax
 */

function GenAjax (p_formid, p_divid) {

     if (!p_formid) {return;}
     if (!p_divid)  {return;}

     formid      = p_formid;
     divid       = p_divid;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("POST","index.php",false);
          xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

          var extrafields = '';

          var frm_element = document.getElementById(formid);

          var genajax_seen = 0;

          if (frm_element) {for(i=0; i < frm_element.elements.length; i++) {

               var oktoadd = 1;

               if (frm_element.elements[i].name == 'SUBMIT')       {oktoadd = 0;}

               if (frm_element.elements[i].type == 'checkbox' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].type == 'radio' && frm_element.elements[i].checked != true) {oktoadd = 0;}
               if (frm_element.elements[i].name == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].type == undefined) {oktoadd = 0;}
               if (frm_element.elements[i].name == 'genajax') {genajax_seen = 1;}

               if (oktoadd) {

                    var fieldvalue = frm_element.elements[i].value;

                    extrafields = extrafields + '&' + frm_element.elements[i].name + '=' + $.url.encode(fieldvalue);

               }

          }}

          extrafields = extrafields.replace(/^\&/,'');

          var genajaxfield = ''; if (!(genajax_seen)) {genajaxfield = 'genajax=1&';}

          xmlhttp.send(genajaxfield + extrafields);

          var AJAXresponseText = '';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          document.getElementById(divid + 'content').innerHTML = AJAXresponseText;

          if ($('#genajax_customjstodo').length > 0) {

               eval(document.getElementById('genajax_customjstodo').innerHTML);
               $('#genajax_customjstodo').remove();

          }

     }, 100);

     setTimeout( function() {

          ReloadImages();

          ToolTips();

     }, 500);

     return false;

}

/**
 *  AjaxURL
 */

function AjaxURL (p_ajaxurl, p_cartinfourl) {

     if (!(p_ajaxurl)) {return;}

     ajaxurl     = p_ajaxurl;
     cartinfourl = p_cartinfourl;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          cartdivORIG = '';

          if (cartinfourl) {

               cartdivORIG = document.getElementById('skinshoppingcart').innerHTML;
               document.getElementById('skinshoppingcart').innerHTML = 'Updating Shopping Basket...';

               ajaxcartdivORIG = document.getElementById('ajaxminicartdispcontentwrap').innerHTML;
               document.getElementById('ajaxminicartdispcontentwrap').innerHTML = 'Updating Shopping Basket...';

          }
 
          ContentOverlay('ON');

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("GET", ajaxurl, false);

          xmlhttp.send(null);

          var AJAXresponseText = '';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          document.getElementById('skin_content_div').innerHTML = AJAXresponseText;

          if ($('#ajax_customjstodo').length > 0) {

               eval(document.getElementById('ajax_customjstodo').innerHTML);
               $('#ajax_customjstodo').remove();

          }

     }, 200);

     if (cartinfourl) {

          setTimeout( function() {

               if (window.XMLHttpRequest) {

                    var xmlhttp = new XMLHttpRequest();

               } else {

                    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

               }

               xmlhttp.open("GET", cartinfourl, false);

               xmlhttp.send(null);

               var AJAXresponseText = 'ERROR';
               if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

               if (AJAXresponseText == 'ERROR') {

                    document.getElementById('skinshoppingcart').innerHTML        = cartdivORIG;
                    document.getElementById('ajaxminicartdispcontentwrap').innerHTML = ajaxcartdivORIG;

               } else {

                    var AJAXresponseTextParts = AJAXresponseText.split('AJAXCARTCONTENTS:');
                    document.getElementById('skinshoppingcart').innerHTML = AJAXresponseTextParts[0];
                    document.getElementById('ajaxminicartdispcontentwrap').innerHTML = AJAXresponseTextParts[1];

                    if ($('#ajax_customjstodo').length > 0) {

                        eval(document.getElementById('ajax_customjstodo').innerHTML);
                        $('#ajax_customjstodo').remove();

                    }

               }

          }, 400);

     }

     setTimeout( function() {

          ReloadImages();

          ToolTips();

          ContentOverlay('OFF');

     }, 500);


     setTimeout( function() {
          
          ScrollToTop();

     }, 510);

     return false;

}

/**
 *  AjaxMiniCartURL
 */

function AjaxMiniCartURL (p_ajaxurl, p_cartinfourl) {

     if (!(p_ajaxurl)) {return;}

     ajaxurl     = p_ajaxurl;
     cartinfourl = p_cartinfourl;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {

          cartdivORIG = '';

          if (cartinfourl) {

               cartdivORIG = document.getElementById('skinshoppingcart').innerHTML;
               document.getElementById('skinshoppingcart').innerHTML = 'Updating Shopping Basket...';

          }
 
          var content_width  = $('#ajaxminicartdispcontentwrap').width() + 'px';
          var content_height = $('#ajaxminicartdispcontentwrap').height() + 'px';

          $('#skin_ajaxminicart_overlay').css({'width': content_width, 'height': content_height, 'display': 'block'});
          $('#skin_ajaxminicart_loadwrap').css({'width': content_width, 'height': content_height, 'display': 'block', 'top': 0});

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          xmlhttp.open("GET", ajaxurl, false);

          xmlhttp.send(null);

     }, 200);

     if (cartinfourl) {

          setTimeout( function() {

               if (window.XMLHttpRequest) {

                    var xmlhttp = new XMLHttpRequest();

               } else {

                    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

               }

               xmlhttp.open("GET", cartinfourl, false);

               xmlhttp.send(null);

               var AJAXresponseText = 'ERROR';
               if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

               if (AJAXresponseText == 'ERROR') {

                    document.getElementById('skinshoppingcart').innerHTML = cartdivORIG;

               } else {

                    var AJAXresponseTextParts = AJAXresponseText.split('AJAXCARTCONTENTS:');
                    document.getElementById('skinshoppingcart').innerHTML = AJAXresponseTextParts[0];
                    document.getElementById('ajaxminicartdispcontentwrap').innerHTML = AJAXresponseTextParts[1];

                    if ($('#ajax_customjstodo').length > 0) {

                         eval(document.getElementById('ajax_customjstodo').innerHTML);
                         $('#ajax_customjstodo').remove();

                    }

               }

          }, 400);

     }

     setTimeout( function() {

          ReloadImages();

          ToolTips();

          var content_width  = $('#ajaxminicartdispcontentwrap').width() + 'px';
          var content_height = $('#ajaxminicartdispcontentwrap').height() + 'px';

          $('#skin_ajaxminicart_overlay').css({'width': content_width, 'height': content_height, 'display': 'none'});
          $('#skin_ajaxminicart_loadwrap').css({'width': content_width, 'height': content_height, 'display': 'none'});

     }, 500);

     return false;

}

/**
 *  PCToggleBuildingNumber
 */

function PCToggleBuildingNumber (p_fieldid) {

     if (!(p_fieldid)) {return;}

     fieldid     = p_fieldid;

     if ($('#' + fieldid + '--countrycode').val().length > 0) {

          if ($('#' + fieldid + '--countrycode').val() == 'GB') {

               $('#' + fieldid + '--pcbuildingnumberwrap').css({'display': 'none'});
               $('#' + fieldid + '--buildingnumber').val('');

          } else {

               $('#' + fieldid + '--pcbuildingnumberwrap').css({'display': 'block'});

          }

     }

     return false;

}

/**
 *  PCLookup
 */

function PCLookup (p_fieldid, p_ajaxurl) {

     if (!(p_fieldid)) {return;}

     fieldid     = p_fieldid;
     ajaxurl     = p_ajaxurl;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     setTimeout( function() {
 
          ContentOverlay('ON');

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          if ($('#' + fieldid).val().length > 0) {

              var fieldid_value_postalcode = $('#' + fieldid).val();

              ajaxurl += '&core--postcodeanywhere_lookupshow--postcode=' + fieldid_value_postalcode;

              var fieldid_value_countrycode = $('#' + fieldid + '--countrycode').val();

              ajaxurl += '&core--postcodeanywhere_lookupshow--countrycode=' + fieldid_value_countrycode;

              var fieldid_value_buildingnumber = $('#' + fieldid + '--buildingnumber').val();

              ajaxurl += '&core--postcodeanywhere_lookupshow--buildingnumber=' + fieldid_value_buildingnumber;

          }

          xmlhttp.open("GET", ajaxurl, false);

          xmlhttp.send(null);

          var AJAXresponseText = '';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          if (AJAXresponseText) {

               var jscontent = '';

               eval(AJAXresponseText);

               if (jscontent) {

                    $('#' + fieldid + '--pcresults').html(jscontent);

               }

          }

     }, 100);

     setTimeout( function() {

          ContentOverlay('OFF');

     }, 500);

     return false;

}

/**
 *  PCUpdate
 */

function PCUpdate (p_fieldid, p_ajaxurl) {

     if (!(p_fieldid)) {return;}

     fieldid     = p_fieldid;
     ajaxurl     = p_ajaxurl;

     if (window.mytimeout) {window.clearTimeout(window.mytimeout);}

     if ($('#core--postcodeanywhere_changeinfo--seladdress').val().length == 0) {return;}

     setTimeout( function() {
 
          ContentOverlay('ON');

     }, 0);

     setTimeout( function() {

          if (window.XMLHttpRequest) {

               var xmlhttp = new XMLHttpRequest();

          } else {

               var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

          }

          if ($('#core--postcodeanywhere_changeinfo--seladdress').val().length > 0) {

              var seladdress_value = $('#core--postcodeanywhere_changeinfo--seladdress').val();

              ajaxurl += '&core--postcodeanywhere_changeinfo--seladdress=' + seladdress_value;

          }

          xmlhttp.open("GET", ajaxurl, false);

          xmlhttp.send(null);

          var AJAXresponseText = '';
          if (xmlhttp.responseText) {AJAXresponseText = xmlhttp.responseText;}

          if (AJAXresponseText) {

               var jscontent = '';

               eval(AJAXresponseText);

               if (jscontent) {

                    $('#' + fieldid + '--pcresults').html(jscontent);

               }

          }

     }, 100);

     setTimeout( function() {

          ContentOverlay('OFF');

     }, 500);

     return false;

}


/**
 *  ToggleTaxExemptNum
 */

function ToggleTaxExemptNum (p_formid) {

     if (!(p_formid)) {return;}

     formid     = p_formid;

     var company_val      = $('#' + formid + '--company').val().length;

     if (company_val == 0) {

          $('#' + formid + '--taxexemptnum--tr td div.formfield_toggle').css({'display': 'none'});
          $('#' + formid + '--taxexemptnum--tr td').css({'padding': '0px'});

          $('#' + formid + '--taxexemptnum').val('');

     } else {

          $('#' + formid + '--taxexemptnum--tr td div.formfield_toggle').css({'display': 'block'});
          $('#' + formid + '--taxexemptnum--tr td').css({'padding': '4px 2px 4px 2px'});

     }

     return false;

}


/**
 *  ReloadImages
 */

ImagesReloaded = 0;

function ReloadImages () {

     if (!(ImagesReloaded)) {ImagesReloaded = 1; preloadimgsrc();}

}

/**
 *  ContentOverlay
 */

function ContentOverlay(overlay_status) {

     if (!overlay_status) {return;}

     if (overlay_status == 'ON') {

          var content_width  = $('#skin_content_div').width() + 'px';
          var content_height = $('#skin_content_div').height() + 'px';

          var window_offset = 0;

          if (self.pageYOffset) {

               window_offset = self.pageYOffset;

          } else if (document.documentElement && document.documentElement.scrollTop) {

               window_offset = document.documentElement.scrollTop;

          } else if (document.body) {

               window_offset = document.body.scrollTop;

          }


          var target_offset = window_offset + loading_window_offset;

          $('#skin_content_overlay').css({'width': content_width, 'height': content_height, 'display': 'block'});
          $('#skin_content_loadwrap').css({'width': content_width, 'height': content_height, 'display': 'block', 'top': target_offset});

     } else {

          var content_width  = $('#skin_content_div').width() + 'px';
          var content_height = $('#skin_content_div').height() + 'px';

          $('#skin_content_overlay').css({'width': content_width, 'height': content_height, 'display': 'none'});
          $('#skin_content_loadwrap').css({'width': content_width, 'height': content_height, 'display': 'none'});

     }

     return;

}

/**
 *  ScrollToTop 
 */

function ScrollToTop() {

     var target_top    = 0;
     var target_offset = $('#skin_content_div').offset();
     var target_top    = target_offset.top - 50;

     if (target_top < 0) {target_top = 0;}

     var window_offset = 0;

     if (self.pageYOffset) {

          window_offset = self.pageYOffset;

     } else if (document.documentElement && document.documentElement.scrollTop) {

          window_offset = document.documentElement.scrollTop;

     } else if (document.body) {

          window_offset = document.body.scrollTop;

     }

     if (window.pageYOffset > target_top) {

          $('html, body').animate({scrollTop: target_top}, 'slow');

     }

     return;

}


/**
 *  LOAD EVENT
 */

addWindowEvent(window,'load',externalLinks,false);

/**
 *  LOAD EVENT
 */

var IE6   = false /*@cc_on || @_jscript_version < 5.7 @*/;

if ((IE6) && (window.MochaUI === undefined)) {addWindowEvent(window,'load',parseStylesheets,false);}

/**
 *  End.
 */
