function choice_className(obj){
	(obj.value.replace(/^\s+|\s+$/g,""))? obj.className="search_text_focus":obj.className="search_text_blur";
}

function deal_main_tab(idx){
	var idx=idx;
	var array=new Array();
	array[0]="main_tab_1";
	array[1]="main_tab_2";
	array[2]="main_tab_3";
	array[3]="main_tab_4";
	array[4]="main_tab_5";

	for(i=0;i<array.length;i++){
		obj=document.getElementById(array[i]);	
		if(i==idx) {
			obj.className="main_banner_hit";
		}else {
			obj.className="main_banner_unhit";
		}
	}
}

/** quick menu ½ºÅ©·Ñ **/
window.onload=function(){
	setInterval("move_quick()",50);
}

var current_top=0;
function move_quick(){
	var obj=document.getElementById("quick_absolute");
	if(obj){
		var obj_height=obj.offsetHeight;
		if (document.body.scrollTop == 0) {
			var move_top = document.documentElement.scrollTop;
			var total_move_height;
			if(move_top<current_top){ 	
				total_move_height=current_top-move_top;
				move_height=Math.round(total_move_height*0.7) - 1;
						
				current_top=current_top-move_height;
				if(current_top==0) obj.style.top=current_top;
				else obj.style.top=current_top+"px";

				if(move_height>0) {
					return;
				}
			}
			else if(move_top>current_top){
				total_move_height=move_top-(current_top);
				move_height=Math.round(total_move_height*0.7) - 1;
						
				current_top=current_top+move_height;
				obj.style.top=current_top+"px";
			
				if(move_height>0) {
					return;
				}
			}else{
				return;
			}	
		} else {
			var move_top = document.body.scrollTop;
			var total_move_height;
			if(move_top<current_top){ 	
				total_move_height=current_top-move_top;
				move_height=Math.round(total_move_height*0.7) - 1;
						
				current_top=current_top-move_height;
				if(current_top==0) obj.style.top=current_top;
				else obj.style.top=current_top+"px";

				if(move_height>0) {
					return;
				}
			}
			else if(move_top>current_top){
				total_move_height=move_top-(current_top);
				move_height=Math.round(total_move_height*0.7) - 1;
						
				current_top=current_top+move_height;
				obj.style.top=current_top+"px";
				
				if(move_height>0) {
					return;
				}
			}else{
				return;
			}
		} 
	}
}
/** quick menu ½ºÅ©·Ñ **/


/** Äü¸Þ´º ÀÌÀü ´ÙÀ½ ¹öÆ® Å¬¸¯ ÀÌº¥Æ® Ã³¸® **/
var start_index=0;
function quick_prev(quickcount,showcount){
	if(quickcount<3 || start_index==0){
		return;
	}else{
		start_index=start_index-1;
		var s_idx=start_index;
		for(i=0;i<showcount;i++){
			var id="quick_id_"+s_idx;
			var obj=document.getElementById(id);
			obj.style.display="block";
			s_idx++;
		}
		var id="quick_id_"+s_idx;
		var obj=document.getElementById(id);
		obj.style.display="none";
	}	
}
function quick_next(quickcount,showcount){
	if(quickcount<3 || (start_index==(quickcount-showcount)) ){
		return;
	}else{
		var id="quick_id_"+start_index;
		var obj=document.getElementById(id);
		obj.style.display="none";

		start_index=start_index+1;
		var s_idx=start_index;
		for(i=0;i<showcount;i++){
			var id="quick_id_"+s_idx;
			var obj=document.getElementById(id);
			obj.style.display="block";
			s_idx++;
		}
		
	}
}
/** Äü¸Þ´º ÀÌÀü ´ÙÀ½ ¹öÆ® Å¬¸¯ ÀÌº¥Æ® Ã³¸® **/


function delivery_search_form(){
	d_url = document.getElementById("trans_search").value;
	d_no = document.getElementById("trans_search1").value;
	if(!d_url) {alert("ÅÃ¹èÈ¸»ç¸¦ ¼±ÅÃÇØÁÖ¼¼¿ä");	return;}
	if(!d_no) {alert("¼ÛÀå¹øÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä");	return;}
	d_url += d_no;
	window.open(d_url,"delivery_search");
}



/** ÇÏ´Ü Àå¹Ù±¸´Ï ¿À´Ãº» »óÇ° °ü·Ã**/
var show_state=false;
function show_detail(){
	var obj=document.getElementById("sub_content_02");
	var img=document.getElementById("cart_btn");
	if(show_state) {
		obj.style.display="none";
		img.src="/img/main/cart_btn_show.jpg";
		show_state=false;
	}else {
		obj.style.display="block";
		img.src="/img/main/cart_btn_hide.jpg";
		show_state=true;
	}
}

function onCartAll(e){
	var main_idx = document.getElementsByName("main_idx[]");
	if(e.checked){
		for(var i = 0; i < main_idx.length; i++)
		{
			main_idx[i].checked = true;
		}	
	}
	else{
		for(var i = 0; i < main_idx.length; i++)
		{
			main_idx[i].checked = false;
		}
	}
}

function onMainCartDel(){
	var main_idx = document.getElementsByName("main_idx[]");
	var k = 0;
	for(var i = 0; i < main_idx.length; i++){
		if (main_idx[i].checked) k++;
	}

	if(k == 0){
		alert("»èÁ¦ÇÒ »óÇ°À» ÇÏ³ª ÀÌ»ó ¼±ÅÃÇØÁÖ¼Å¾ß µË´Ï´Ù.");
		return;
	}
	
	mainCartForm.action="main.php?menukey=cart6";
	mainCartForm.submit();
}

function onOrdNumChange(num){
	var ordnum = document.getElementById("main_ordnum"+num);
	var gcode = document.getElementById("main_gcode"+num);

	if(ordnum.value == ""){
		alert("±¸¸Å¼ö·®¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		return;
	}
	StatisticalGet("/shop/order_exec.php?gcode="+gcode.value+"&ordnum="+ordnum.value); 
    onPriceViewReset();
 }

function onPriceViewReset() {
	var ordnum_total = document.getElementById("main_ordnum_total"); 
	var price_total1 = document.getElementById("price_total1");
	var price_total2 = document.getElementById("price_total2");
	var juklip_total = document.getElementById("juklip_total");
	var taekbae_total = document.getElementById("taekbae_total");
	var money_total1 = document.getElementById("money_total1");
	var money_total2 = document.getElementById("money_total2");

	var main_idx = document.getElementsByName("main_idx[]");
	var juklip_ratio = document.getElementsByName("juklip_ratio[]");
	var main_jmcode = document.getElementsByName("main_jmcode[]");
	var taekbae_price = document.getElementsByName("taekbae_price[]");
	var main_ordnum = document.getElementsByName("main_ordnum[]");
	var d_price = document.getElementsByName("d_price[]");
	var prod_price = document.getElementsByName("prod_price[]");
	

	var price_total = 0;
	var price_sum = 0;
	var juklip_price = 0;
	var taekbae_sum = 0;
	var a_main_jmcode = new Array();
	var ordnum_sum = 0;
	
	for(var i = 0; i < main_idx.length; i++) {
		if (main_idx[i].checked) {
			price_sum = d_price[i].value * main_ordnum[i].value;
			price_total = price_total + price_sum;
			juklip_price = juklip_price + (price_sum * (juklip_ratio[i].value/100));

			prod_price[i].innerHTML = price_sum.toLocaleString().slice(0,-3);
			
			if(a_main_jmcode[main_jmcode[i].value] != main_jmcode[i].value) {
				a_main_jmcode[main_jmcode[i].value] = main_jmcode[i].value;
				taekbae_sum = taekbae_sum + Number(taekbae_price[i].value);
			}
			ordnum_sum = ordnum_sum + Number(main_ordnum[i].value);
		}
	}

    if(Number(price_total) >= 30000) taekbae_sum = 0;
	var money_total = Number(price_total) + Number(taekbae_sum);
	money_total1.innerHTML = money_total.toLocaleString().slice(0,-3);
	money_total2.innerHTML = money_total.toLocaleString().slice(0,-3);
	price_total1.innerHTML = price_total.toLocaleString().slice(0,-3);
	price_total2.innerHTML = price_total.toLocaleString().slice(0,-3);
	juklip_total.innerHTML = juklip_price.toLocaleString().slice(0,-3);
	taekbae_total.innerHTML = taekbae_sum.toLocaleString().slice(0,-3);
	ordnum_total.innerHTML = ordnum_sum.toLocaleString().slice(0,-3);
}


	/** AJAX **/
function getXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e1) { return null; }
		}
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}

var httpRequest=null;
function StatisticalGet(url) { 
    httpRequest=getXMLHttpRequest();
    if (httpRequest) { 
        httpRequest.onreadystatechange = processReqChange; 
        httpRequest.open("GET", url, true); 
        httpRequest.send(null); 
    } 
} 
function processReqChange() {
	var data=null;
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			data=httpRequest.responseText;
			//alert(data);
			//alert('¼öÁ¤µÇ¾ú½À´Ï´Ù');
		} else {
			
		}
	}
} 
	/** AJAX **/

/** ÇÏ´Ü Àå¹Ù±¸´Ï ¿À´Ãº» »óÇ° °ü·Ã**/

//½ºÅ©·Ñ
function itemScroll(name,cnt,vcnt,width) {	
	this.name = name+'Div';
	this.obj = document.getElementById(name).style;
	this.count = 0;
	this.cnt = cnt;  
	this.vcnt = vcnt;  
	this.destination = '';
	this.width = width;  
	this.tid = null;
	this.stop = false; // Á¤Áö À¯¹«
	this.speed = 10; // °£°Ý Á¶Á¤(¼Óµµ)
	this.pauseDelay = 1500; // Á¤Áö ½Ã°£
	this.pauseMouseover = true; //¸¶¿ì½º¸¦ ¿Ã·ÈÀ»¶§ Á¤Áö À¯¹«
	this.autoplay = true; //ÀÚµ¿ÇÃ·¹ÀÌ
	
	this.scroll = function() {
        if(this.cnt<1) return;
		var xOffset, destination, timeoutNextCheck;		
		timeoutNextCheck = this.speed;			        

		if (!this.stop && this.autoplay) { 
			if(!this.destination) {
				if(this.count > (this.cnt*2)) this.count = 1;
				if(this.count <= this.cnt) this.destination =  -(this.count*this.width);	
				else this.destination =  -(this.cnt*this.width) + ((this.count-this.cnt)*this.width);	
			}
		
		 	xOffset = Math.ceil(Math.abs(this.destination - parseInt(this.obj.left)) / 15);  
			
			if(this.count <= this.cnt) xOffset = -xOffset;

			this.obj.left = parseInt (this.obj.left, 10) + xOffset + 'px';
            			
			if (parseInt(this.obj.left) == this.destination)  { 						
				this.count++; 
				this.destination ='';

				timeoutNextCheck = this.pauseDelay; 
			}					
		} 
		window.setTimeout(this.name+".scroll()",timeoutNextCheck);
	}    

	this.mover = function() {
		if (this.pauseMouseover) this.stop = true;
	}
       
	this.mout = function() {
		this.stop = false;
	}

	this.left = function() {
		if (this.pauseMouseover) this.stop = true;
		if(this.count > (this.cnt-1)) this.count++;
		if(this.count > (this.cnt*2)) this.count = 1;
		if(this.count <= this.cnt) this.count--;
		if(this.count < 1) this.count = 0;
		this.destination = '';
		this.move();
	}
	this.right = function() {
		if (this.pauseMouseover) this.stop = true;
		if(this.count > (this.cnt*2)) this.count = 1;
		if(this.count <= this.cnt) this.count++;
		if(this.count >= (this.cnt+1)) this.count--;
		this.destination = '';
		this.move();
	}

	this.imover = function(num) {
		if(this.cnt<1) return;
		if (this.pauseMouseover) this.stop = true;				
		if(num>this.cnt + 1) {
			num = this.cnt + 1 - ((this.cnt+this.vcnt) - eval(num));
			if(num<1) num = this.cnt;
		}		

		this.count = eval(num-1);	
		this.destination = '';
		this.move();
	}

	this.imout = function() {
		this.stop = false;			
	}

	this.move = function() {
		if(!this.destination) {
			if(this.count > (this.cnt*2)) this.count = 1;			
			if(this.count <= this.cnt) this.destination =  -(this.count*this.width);	
			else this.destination =  -(this.cnt*this.width) + ((this.count-this.cnt)*this.width);	
		}		

		if(parseInt(this.obj.left) > this.destination) {
			xOffset = Math.ceil(Math.abs(parseInt(this.obj.left) - this.destination) / 15);  		
			xOffset = -xOffset;
		} else {
			xOffset = Math.ceil(Math.abs(parseInt(this.obj.left) - this.destination) / 15);  					
		}
		this.obj.left = parseInt (this.obj.left, 10) + xOffset + 'px';

		if (parseInt(this.obj.left) == this.destination)  {
			this.destination = '';	
			if(this.tid) clearTimeout(this.tid);	
		} 
		else this.tid = window.setTimeout(this.name+".move()",this.speed);		
	}

}

function divTap(name,tabLen,img_loc) {
	this.name = name+'_Div';
	this.btn = name+'_btn';
	this.tabLen = tabLen;
	this.tabNum = 1;
	this.tabBtn_gap = -1;

	for(k=0; k<tabLen; k++) {
		div_btn=eval(document.getElementById(this.btn+parseInt(k+1)));

		A_tag =div_btn.getElementsByTagName("a");
		A_tag.item(0)._num=k+1;
		A_tag.item(0).onmouseover = A_tag.item(0).onfocus = function () {
			eval(name+'_Div').show(this._num);
		}
	}

	this.show = function(num) {
		if (num) this.tabNum = num;
		for(k=0; k<tabLen; k++) {
			div_btn=eval(document.getElementById(this.btn+parseInt(k+1)));
			A_tag =div_btn.getElementsByTagName("a");
			IMG_tag =div_btn.getElementsByTagName("img");

			if (parseInt(k+1)==parseInt(this.tabNum)) {
				IMG_tag.item(0).src = img_loc + eval(k+1) +"_on.jpg";
				eval(document.getElementById(name+parseInt(k+1))).style.display="block";
			}else{
				IMG_tag.item(0).src = img_loc + eval(k+1) +"_off.jpg";
				eval(document.getElementById(name+parseInt(k+1))).style.display="none";
			}
		}
	}
}
