function viewdetail(brandcode){
   showdetail('visible',brandcode);
}

var optionJsonData = null;
var stockInfo = null;

function viewlayerbasket(temp,item,type){
   if(temp=='visible'){
      var pars = 'item='+item+'&type=' + type;

      if (typeof jQuery == 'undefined') { 
          new Ajax.Updater('basketpage','/shop/gobasket.layer.html', {
                method:'post',
                evalScripts:true,
                parameters:pars

            });
      } else {
          jQuery.ajax({
            url: '/shop/gobasket.layer.html',
            type: 'POST',
            dataType: 'html',
            data: {item : item, type : type},
            success: function(data) {
                jQuery('#basketpage').show();
                jQuery('#basketpage').html(data);
                jQuery('#basketpage').html();
            }
          });
      }

      if(typeof(document.getElementById('basketpage'))!='undefined'){
         var _x = document.body.clientWidth/2 + document.body.scrollLeft -250;
         var _y = document.body.clientHeight/2 + document.body.scrollTop - 200;

         basketpage.style.width=380;
         basketpage.style.height=200;
         basketpage.style.posLeft=_x;
         basketpage.style.posTop=_y;
         basketpage.style.zIndex='20000';
      }
   }

   if(typeof(document.getElementById('basketpage'))!='undefined'){
       basketpage.style.visibility=temp;
       if(temp=="hidden" && (typeof showdetail)!='undefined') {
           showdetail('hidden');
       }
   }
}

var Items = {};
var check_multi_img = false;
function showdetail(temp, brandcode){
    Items = {};
    if(temp=='visible') {
        var pars = 'request=ajax&brandcode=' + brandcode;
   
        new Ajax.Request('/shop/multi_image.html', {
            method : 'post',
            asynchronous : false,
            parameters : pars,
            onSuccess : function(req) {
               tmp = eval('(' + req.responseText + ')');
    
               if (tmp.uid) {
                   Items = {
                        '0' : {
                           uid : tmp.uid,
                           name : "'" + tmp.brandname + "'",
                           desc : "'" + tmp.brandname + "'",
                           images : tmp.multi_image
                       }
                   };

               }
            }
        });

        var response = '';
        new Ajax.Request('/shop/detailpage.html', {
            method : 'post',
            asynchronous : false,
            parameters : pars,
            onSuccess : function(req, json) {
                response = req.responseText;
                if (json != null) {
                    optionJsonData = json.optionJsonData;
                    stockInfo = json.stockInfo;
                }
                loadJs("/js/option_validate.js");

                if (req.responseText.match('<!-- MULTI_IMAGE -->') != null) {
                    if (!check_multi_img) {
                        loadJs("/js/jquery.js");
                        setTimeout(function() {
                            loadJs("/js/multi_image.js");
                        }, 100);
                    }
                    check_multi_img = true;
                }
            }
        });

        if (response.match('<!-- MULTI_IMAGE -->') != null) {
            setTimeout(function() {
                jQuery('#detailpage').html(response);
                jQuery.imageShow();
            }, 250);
        } else {
            response.evalScripts();
            document.getElementById('detailpage').innerHTML = response;
        }

        if(typeof(document.getElementById('detailpage'))!='undefined'){
            var _x = document.body.clientWidth/2 + document.body.scrollLeft -250;
            var _y = document.body.clientHeight/2 + document.body.scrollTop - 200;

            detailpage.style.posLeft=_x;
            detailpage.style.posTop=_y;
            detailpage.style.zIndex='10000';
        }
    }
    if(typeof(document.getElementById('detailpage'))!='undefined'){
        detailpage.style.visibility=temp;
    }
}

function imageview(temp,type) {
   var url;
   var n4;
   
   var windowprops = "height=350,width=450,toolbar=no,menubar=no,resizable=no,status=no";
   if (type=="1"){
      windowprops+=",scrollbars=yes";
      imgsc="yes";
   }else imgsc="";
   if (temp.length==0) { alert("Å«ÀÌ¹ÌÁö°¡ ¾ø½À´Ï´Ù."); return ; }
   n4=(document.layers)?true:false;
   if (n4)
      url = "/shop/image_view.html?scroll="+imgsc+"&image=/shopimages/"+db+"/" + escape(temp);
   else
      url = "/shop/image_view.html?scroll="+imgsc+"&image=/shopimages/"+db+"/" + temp;
             
   window.open(url, "win", windowprops);
 }
function send_wish(temp, temp2, opt_type) {
    if (document.getElementById('option_type')) {
        wishvalidateSubmit(temp, document.detailform,baskethidden);
        return;
    }

   if(temp2!=""){
      document.detailform.opts.value="";
      for(i=0;i<temp2;i++){
         document.detailform.opts.value+=document.detailform.mulopt[i].selectedIndex+",";
		 document.detailform.optslist.value+=document.detailform.mulopt[i].value+"[||]";
      }
   }
   if(typeof document.detailform.spcode!="undefined" && document.detailform.spcode.selectedIndex<2){
       temp2=document.detailform.spcode.selectedIndex-1;
       if(typeof document.detailform.spcode2=="undefined" || document.detailform.spcode2.type == 'hidden') temp3=1;
       else temp3=document.detailform.spcode2.selectedIndex-1;
       /*
       if(num.length > 0 && num[(temp3-1)*10+(temp2-1)]==0){
           alert('¼±ÅÃÇÏ½Å »óÇ°ÀÇ ¿É¼ÇÀº Ç°ÀýµÇ¾ú½À´Ï´Ù. ´Ù¸¥ ¿É¼ÇÀ» ¼±ÅÃÇÏ¼¼¿ä');
           document.detailform.spcode.focus();
           return;
       }
       */
   }
   if (opt_type == 'NL' || opt_type == 'NU') {
       document.detailform.optslist.value = '';
       if (document.detailform.spcode.selectedIndex > 1) {
           document.detailform.optslist.value = document.detailform.spcode.options[document.detailform.spcode.selectedIndex].text+"[||]";
       }
       if (typeof document.detailform.spcode2!="undefined" && document.detailform.spcode2.selectedIndex > 1) {
           if (document.detailform.spcode2.type != 'hidden') document.detailform.optslist.value += document.detailform.spcode2.options[document.detailform.spcode2.selectedIndex].text+"[||]";
       }
   }

   if(typeof baskethidden!="undefined" && baskethidden=="Y"){
       document.detailform.ordertype.value+= "|parent.";
       document.detailform.target = "loginiframe";
   }else if(typeof baskethidden!="undefined" && baskethidden=="A"){
       document.detailform.ordertype.value+= "|parent.|layer";
       document.detailform.target = "loginiframe";
   }

   document.detailform.action = '/shop/shopdetail.html';
   document.detailform.mode.value = 'wish';
   document.detailform.optiontype.value = opt_type;
   //document.detailform.target  = "new";	
   
   document.detailform.submit();
}
function send(temp,temp2) {
    // ÆÄ¿ö¿É¼ÇÀÎ °æ¿ì¿¡ validate¸¦ ¾Æ·¡ ÇÔ¼ö·Î º¸³»¹ö¸²
    if (document.getElementById('option_type')) {
        validateSubmit(temp, document.detailform,baskethidden);
        return;
    }

   if (document.detailform.amount.value.length==0)
   {  alert("ÁÖ¹®¼ö·®À» ÀÔ·ÂÇÏ¼¼¿ä."); document.detailform.amount.focus();return; }
   if (isNaN(document.detailform.amount.value))
   {  alert("ÁÖ¹®¼ö·®¿¡ ¼ýÀÚ¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
      document.detailform.amount.focus(); return; }
   if(temp=="baro") document.detailform.ordertype.value='baro';
   if(temp2!=""){
      document.detailform.opts.value="";   
      for(i=0;i<temp2;i++){
         if(document.detailform.optselect[i].value==1 && document.detailform.mulopt[i].selectedIndex==0){
            alert('ÇÊ¼ö¼±ÅÃ Ç×¸ñÀÔ´Ï´Ù. ¿É¼ÇÀ» ¹Ýµå½Ã ¼±ÅÃÇÏ¼¼¿ä');
            document.detailform.mulopt[i].focus();
            return;
         }
         document.detailform.opts.value+=document.detailform.mulopt[i].selectedIndex+",";
      }
   }
   if(typeof document.detailform.spcode!="undefined" && document.detailform.spcode.selectedIndex<2){
      alert('¿É¼ÇÀ» ¼±ÅÃÇÏ¼Å¾ß ±¸¸Å°¡ °¡´ÉÇÕ´Ï´Ù.');
      document.detailform.spcode.focus();
      return;
   }
   if(typeof document.detailform.spcode2!="undefined" && document.detailform.spcode2.selectedIndex<2){
      alert('¿É¼ÇÀ» ¼±ÅÃÇÏ¼Å¾ß ±¸¸Å°¡ °¡´ÉÇÕ´Ï´Ù.');
      document.detailform.spcode2.focus();
      return;
   }
   if(typeof document.detailform.spcode!="undefined" && document.detailform.spcode.selectedIndex<2){
       temp2=document.detailform.spcode.selectedIndex-1;
       if(typeof document.detailform.spcode2=="undefined") temp3=1;
       else temp3=document.detailform.spcode2.selectedIndex-1;
       if(num[(temp3-1)*10+(temp2-1)]==0){
           alert('¼±ÅÃÇÏ½Å »óÇ°ÀÇ ¿É¼ÇÀº Ç°ÀýµÇ¾ú½À´Ï´Ù. ´Ù¸¥ ¿É¼ÇÀ» ¼±ÅÃÇÏ¼¼¿ä');
           document.detailform.spcode.focus();
           return;
       }
   }
   if(typeof baskethidden!="undefined" && baskethidden=="Y"){
       document.detailform.ordertype.value+= "|parent.";
       document.detailform.target = "loginiframe";
   }else if(typeof baskethidden!="undefined" && baskethidden=="A"){
       document.detailform.ordertype.value+= "|parent.|layer";
       document.detailform.target = "loginiframe";
   }
   document.detailform.submit();
 }
 function count_change(temp)
 {
   var test=document.detailform.amount.value;
   if(temp==0){
      test++;
   }else if(temp==1){
      if(test> 1) test--;
   }
   document.detailform.amount.value=test;
 }
  function login_chk(tmp){
     alert ("È¸¿ø¿¡°Ô¸¸ Á¦°øÀÌ µÇ´Â ¼­ºñ½ºÀÔ´Ï´Ù.\n¿ì¼± ·Î±×ÀÎÀ» ÇÏ¿© ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
     location.href="/shop/member.html?type=wish&brandcode="+tmp;
  }

function warehousing_call(temp) {
    win = window.open('/shop/soldout_sms_pop.html?branduid=' + temp, 'soldout_sms', 'width=450, height=330');
    win.focus();
}

function MS_CyScrap(shopurl, branduid, key, sid) {
    var xml_url = escape('http://' + shopurl + '/cy_scrap.html?branduid=' + branduid + '&key=' + key);
    var cyScrap_url = 'http://api.cyworld.com/openscrap/shopping/v1/?xu=' + xml_url + '&sid=' + sid;

    window.open(cyScrap_url, 'cyopenscrap', 'width=450,height=410');
}
function loadJs(filename) {
    var fileref = document.createElement('script');
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", filename);

    if (typeof fileref != "undefined") {
        document.getElementsByTagName("head")[0].appendChild(fileref);
    }
};

var changeOpt2value = function(num) {
   var optionIndex = optval = '';
   var optcnt=0;
   var oki=oki2='-1';
   if(typeof document.detailform.spcode!="undefined" && document.detailform.spcode.selectedIndex>1){
      temp2=document.detailform.spcode.selectedIndex-1;
      if(typeof document.detailform.spcode2=="undefined" || document.detailform.spcode2.type == 'hidden') temp3=1;
      else temp3 = document.detailform.spcode2.length;
      for(var i=2;i<temp3;i++){
         var len = document.detailform.spcode2.options[i].text.length;
         if(document.detailform.spcode2.options[i].text.substring(len-5,len)==" (Ç°Àý)") document.detailform.spcode2.options[i].text = document.detailform.spcode2.options[i].text.substring(0,len-5);
         if(num[(i-2)*10+(temp2-1)]==0){
            document.detailform.spcode2.options[i].text= document.detailform.spcode2.options[i].text+' (Ç°Àý)';
         }
      }
   }
};

