/*
# File: js/main.js
#
# Purpose:
#
# History:
# 17-Apr-11 fhk; Init
# 22-Apr-11 fhk; Added form submit to get_product_type()
#--------------------------------------------------
*/

window.main_jso = {

  onload: function() {

    jQuery.each(jQuery('.startshopping img'), function() {
     if ( this.src.match(/\/shopping.png$/) )
       jQuery(this).click(function(event) {
         var productref = jQuery('body').attr('class').replace(/-scenes$/,'');
         window.main_jso._setcookie('startshopping',productref);
       });
    });

  },

  get_product_type: function(o,e,r,f) {
    if ( r || ! jQuery.cookie("startshopping") ) {
      window.main_jso._href = o.parentNode.getAttribute('href');
      if ( ! window.main_jso._href ) window.main_jso._href = o.getAttribute('Xhref');
      if ( window.main_jso._href && window.main_jso._href == 'uselocation' ) window.main_jso._href = document.location.href;
      window.main_jso._form = f;
      jQuery('#getproducttypedialog').dialog( {
        title: "Please Select The Product Type",
        modal: true,
        width: 600,
        buttons: { 
                   "CANCEL": function() { jQuery(this).dialog("close"); },
                   "OK": function() {
                     if ( jQuery.cookie("startshopping") && window.main_jso._href ) document.location.href=window.main_jso._href;
                     else if ( jQuery.cookie("startshopping") && window.main_jso._form ) window.main_jso._form.submit();
                   }
                 },
        'end': 'end'
      });
      return false;
    }
    return true;
  },

  set_product_type: function(o) {
    var v = o.getAttribute('Xvalue');
    if ( !v || v == '' || v == undefined ) v = o.value;
    window.main_jso._setcookie('startshopping',v);
  },

  _setcookie: function(name,value) {
     // jQuery.cookie(name, value, { path: '/' });
     var date = new Date();
     date.setTime(date.getTime()+(30*24*60*60*1000));
     var expires = "; expires="+date.toGMTString();
     document.cookie = name+"="+value+expires+"; path=/";
  }

}

if (typeof jQuery != 'undefined') {  
  jQuery(document).ready(function() {
    window.main_jso.onload();
  });
}

