/* script.js */


function setCart(){
  var form = document.forms['cart'];
  var maker = form.elements['maker'].value;
  var type = form.elements['code'];
  var qt = form.elements['qt'].value.replace(/[^\d]+/g,'');
  form.elements['qt'].value = qt;
  if(Number(qt) > 0){
    var code = (type.length > 1)? type[type.selectedIndex].value: type.value;
    viewCart('cart',maker,code,qt);
  }
  return false;
}

function backCart(){
  self.window.parent.hideCartWindow();
  return false;
}

function setBodyObject(id){
  var div = document.createElement('div');
  div.setAttribute('id',id);
  document.body.appendChild(div);
}

function setMaskSize(){
  var obj = document.getElementById('cartMask');
  obj.style.width = (document.body.scrollWidth || document.documentElement.scrollWidth) + 'px';
  obj.style.height = (document.body.scrollHeight || document.documentElement.scrollHeight) + 'px';
  setCartWindow();
}

function hideCartWindow(){
  document.getElementById('cartMask').style.display = 'none';
  document.getElementById('cartWindow').style.display = 'none';
  document.getElementById('cartWindow').innerHTML = '';
}

function orderCart(){
  return viewCart('order');
}

function viewCart(mode,maker,code,qt){
  document.getElementById('cartMask').style.display = 'block';
  var obj = document.getElementById('cartWindow');
  setCartWindow();
  mode = (mode && mode == 'order')? 'order': 'cart';
  maker = (maker)? '&maker=' + maker: '';
  code = (code)? '&code=' + code: '';
  qt = (qt)? '&qt=' + qt: '';
  var url = location.href.replace(/^https?:\/\/([^\/]+).*$/,'$1');
//  var http = ('https:' == document.location.protocol)? 'https' : 'http';
  var http = 'https';
  url = (url == 'www.1023world.net')? http + '://' + url: '';
  var html = '';
  html += '\u304A\u8CB7\u3044\u7269\u3092\u7D9A\u3051\u308B\u306B\u306F\u3053\u306E\u30AB\u30FC\u30C8\u7A93\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044';
  html += '<img src="/shop/img/close.png" width="17" height="17" alt="\u9589\u3058\u308B" title="\u9589\u3058\u308B" onclick="hideCartWindow();" /><br />';
  html += '<iframe src="' + url + '/shop/?mode=' + mode + maker + code + qt + '" width="590" height="508" frameborder="0" scrolling="auto"></iframe>';
  obj.innerHTML = html;
  obj.style.display = 'block';
  return false;
}

function setCartWindow(){
  var obj = document.getElementById('cartWindow');
  var w = 600;
  var h = 540;
  obj.style.left = ((document.documentElement.scrollLeft || document.body.scrollLeft) + 
                  Math.floor(((document.documentElement.clientWidth || document.body.clientWidth) - w) / 2)) + 'px';
  obj.style.top = ((document.documentElement.scrollTop || document.body.scrollTop) + 
                  Math.floor(((document.documentElement.clientHeight || document.body.clientHeight) - h) / 2)) + 'px';
}

function setOnLoad(func){
  (window.addEventListener)? window.addEventListener('load',func,false):
  (window.attachEvent)? window.attachEvent('onload',func):
  window.onload = func;
}

function setOnResize(func){
  (window.addEventListener)? window.addEventListener('resize',func,false):
  (window.attachEvent)? window.attachEvent('onresize',func):
  window.onresize = func;
}

function onLoads(){
  setBodyObject('cartMask');
  setBodyObject('cartWindow');
  setOnResize(setMaskSize);
  setMaskSize();
}

setOnLoad(onLoads);

