/*
 * Author	scchoi < scchoi@bb.co.kr>
 * Date		2009. 03. 25
 * Subject	»óÇ°¸®½ºÆ®¿¡¼­ »ç¿ëµÇ´Â JS Script
 */

/*
 * »óÇ°¸®½ºÆ®ÀÇ Á¤·Ä 
 */
function bar_setting( name, value, gview )
{
	document.getElementById("gview").value = gview;

	set_cookie( name, value );

}


/*
 * COOKIE Setting
 */
function set_cookie( name, value )
{
	document.cookie = name + "=" + value +"; path=/; domain=.bb.co.kr";

	call_submit();
}

/*
 * ÅÇ ÀÌµ¿
 */
function move_tab( mode )
{

	document.getElementById("view").value = mode;

	call_submit()
}

function chk_enter( type, obj, event )
{
	switch( event.keyCode )
	{
		case 13:
			if ( obj.value != "" )
			{
				research( type );
			}
		break;
	}
}

/*
 * °á°ú³» Àç°Ë»ö ¹× ÀüÃ¼º¸±â
 */
function research( mode )
{
	if ( mode == 0 || mode == 1 )
	{
		if ( mode == 0 )
		{
			document.getElementById("cate_qry").value = "";
			document.getElementById("cate_qry_not").value = "";
		}

		call_submit()
	}
	else
	{
		var cid = document.getElementById("cid").value;
		var search_keyword = document.getElementById("cate_qry").value;

		if ( !search_keyword )
		{
			alert( '°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿ä.' );
			return;
		}

		//var url = "http://renewal.bb.co.kr/main/search/search.php?searchcategory=total&movetype=on&qry="+ search_keyword ;
		//url += "&cid="+ cid;
		//surl = escape( url );
		window.open('' , "search", '' );

		var tobj = document.createElement("input");
		tobj.type = "hidden";
		tobj.name = "qry";
		tobj.value = search_keyword;

		var f = document.variable;

		f.appendChild( tobj );

		f.target = "search";
		f.method = "GET";
		f.action = "/main/search/search.php";
		f.submit();
	}
}

function qna_search()
{
	cs.form_submit();
}

/*
 * Á¶°Ë°Ë»öÀÇ form submit È£Ãâ
 */
function call_submit()
{

	cs.form_submit();
}


// °¡°Ý¸®½ºÆ®
// djshin Test
// º»·¡ Link.js ¿¡ ÀÖ´Â °ÍÀÎµ¥ ÀÓ½Ã·Î ¿Å°ÜµÒ
function PdInfo( pd_id, tab_mode )
{
	var addstr = "";

	if( tab_mode )
	{
		addstr = "&tab_mode="+tab_mode;	
	}

	var url = "http://" + window.location.hostname + "/main/model/model.php?model_id=" + pd_id + addstr;
	var target = "_blank";
	var option = "width=1020,height=" + screen.availHeight + ",top=0,left=0,status=0,scrollbars=yes,resizable=yes";

    window.open( url, target, option );

	if( location.hostname == "renewal.bb.co.kr")
	{
    	window.open( "/price.php?model_id="+pd_id, target, option );
	}
}

var lyr = "";
var x_cordinate = 0;
var y_cordinate = 0;
var lyr_class = "";
//div ¾È¿¡ ³»¿ë ±×¸®´Â ºÎºÐ
function write_detail_1( content, div_name)
{
	if( div_name )
	{
		lyr = getObject( div_name );
	}
	else
	{
		lyr = getObject("over_div");
	}

	if(lyr)
	{
		lyr.innerHTML = content
		//¸¶¿ì½º ¿òÁ÷ÀÓ ÀÌº¥Æ® ¹ß»ý
		x_cordinate = 10;
		y_cordinate = 20;
		lyr.style.display = "block";
		document.onmousemove = mouseMove;
	}
}

function hide_detail_1( div_name )
{
	if( div_name )
	{
		lyr = getObject( div_name );
	}

	lyr.style.display = "none";
	//¸¶¿ì½º ¿òÁ÷ÀÓ ÀÌº¥Æ® ³¡
	document.onmousemove = "";

}

function mouseMove(e)
{
	var evt = e ? e : window.event;
	var posx=0;
	var posy=0;

	if (evt.pageX || evt.pageY)
	{
		// pageX/Y Ç¥ÁØ °Ë»ç
		//posx = evt.pageX + x_cordinate;
		//posy = evt.pageY + y_cordinate;

		posx = evt.pageX - 140;//+ x_cordinate;
		posy = evt.pageY - 140;// + y_cordinate;

	}
	else if (evt.x || evt.y)
	{
		//clientX/Y Ç¥ÁØ °Ë»ç Opera
		//posx = evt.clientX + x_cordinate ;
		//posy = evt.clientY + y_cordinate ;

		posx = evt.x + x_cordinate ;
		posy = evt.y + y_cordinate ;

		if ( window.event )
		{ // IE ¿©ºÎ °Ë»ç
			//posx += document.documentElement.scrollLeft;
			//posy += document.documentElement.scrollTop;
		}
	}

	lyr.style.left = posx + "px";
	lyr.style.top = posy + "px";
	lyr.className = lyr_class;
}

function ChgAniImgStatus(st)
{
	// ESC Å° °ª 27
	if(st=="stop")
	{
		document.execCommand('Stop');

		getObject("aniImg_href").href = "javascript:ChgAniImgStatus();";
		getObject("aniImg_img").src = "/images/button/btn_sort_image_off.gif"; 

		set_status = "aniImg=0";	// ÀÌ¹ÌÁö ½ÇÇà ±ÝÁö
		document.cookie = set_status +";path=/";
		return;
	}
	else
	{
		set_status = "aniImg=1";	// ÀÌ¹ÌÁö ½ÇÇà
		document.cookie = set_status +";path=/";
		window.location.reload();
	}
}

function attachEvent_(obj, evt, fuc, useCapture)
{
	if(!useCapture) useCapture=false;
	if(obj.addEventListener)
	{ // W3C DOM Áö¿ø ºê¶ó¿ìÀú
		return obj.addEventListener(evt,fuc,useCapture);
	}
	else if(obj.attachEvent)
	{ // MSDOM Áö¿ø ºê¶ó¿ìÀú
		return obj.attachEvent("on"+evt, fuc);
	}
} 

function detachEvent_(obj, evt, fuc, useCapture)
{
	if(!useCapture) useCapture=false;
	if(obj.removeEventListener)
	{
		return obj.removeEventListener(evt,fuc,useCapture);
	}
	else if(obj.detachEvent)
	{
		return obj.detachEvent("on"+evt, fuc);
	}
} 

function previewShow(e, obj, pv)
{
	preview=pv;
	gobj=obj;
	attachEvent_(obj, "mousemove", previewMove, false);
	attachEvent_(obj, "mouseout", previewHide, false);
}

var preview="";
var gobj="";
  
function previewMove(e)
{
	var hb = document.getElementById(preview);
	hb.style.display="";

	var evt = e ? e : window.event;
	var posx=0;
	var posy=0;

	if (evt.pageX || evt.pageY)
	{ // pageX/Y Ç¥ÁØ °Ë»ç
		//posx = evt.pageX +10;
		//posy = evt.pageY +20;
		posx = evt.pageX - 140;//+ x_cordinate;
		posy = evt.pageY - 140;// + y_cordinate;
	}
	else if (evt.clientX || evt.clientY)
	{
		//clientX/Y Ç¥ÁØ °Ë»ç Opera
		//posx = evt.clientX +10;
		//posy = evt.clientY +20;

		posx = evt.x + x_cordinate ;
		posy = evt.y + y_cordinate ;

		if (window.event) { // IE ¿©ºÎ °Ë»ç
			//posx += document.body.scrollLeft;
			//posy += document.body.scrollTop;
		}
	}

	hb.style.left = posx + "px";
	hb.style.top = posy + "px";
} 

function previewHide()
{
	var hb = document.getElementById(preview);
	hb.style.display="none";

	detachEvent_(gobj,"mousemove", previewMove, false);
}


var PLorder = 1;
function ShowLpop(name)
{
	var area = document.getElementById(name);
	var area_ = document.getElementById(name+"_");
	/*var temp = document.all.tags("DIV");
	for(i=0; i<temp.length; i++)  
	{
		if(temp[i].id.substr(0,"mueja".length)=="mueja"){
			alert(temp[i].id);
			alert(temp[i].style.zIndex);
		}

	}*/
	//if(area.style.display=="none"){

	//area_.style.zIndex= PLorder;
	//PLorder++;
	//area.style.display= "";

	//}
	//else{
	//  area_.style.zIndex= 1;
	//  area.style.display= "none";
	//}
}

function HideLpop(name)
{
	var area = document.getElementById(name);
	var area_ = document.getElementById(name+"_");
	if(area.style.display=="none"){
	} 
	else
	{
		area.style.display= "none";
		area_.style.zIndex= 1;
	}
}

function ShowHideL(name)
{
	var area = document.getElementById(name);
	var area_ = document.getElementById(name+"_");
	if(area.style.display=="none")
	{
		area_.style.zIndex= PLorder;
		PLorder++;
		area.style.display= "";
	}
	else
	{
		area.style.display= "none";
		area_.style.zIndex= 1;
	}
}

//ÆÇ¸ÅÆäÀÌÁö·Î °¡±â
function PrInfo(pr_id,pr_type,ad_type)
{     
    
    var hit_id=0;
    
    //ºñ±³»óÇ°
    if( pr_type==0) hit_id="812";
    //°Ë»ö»óÇ°
    else    hit_id="877";

	if( ad_type == 1 ) // ½Å¼¼°è¸ô ¼öÀÍÄÚµå º¯°æ ¶§¹®¿¡ Ãß°¡(best100¿¡¼­ ad_type ³Ñ°ÜÁÜ)
	{
		window.open("http://"+window.location.hostname+"/mainhit.php?hit_id="+hit_id+"&link=/main/go_mall/go_mall.php?pr_id="+pr_id+"&pr_type="+pr_type+"&ad_type=1","_blank",'');
	}
	else
	{
		window.open("http://"+window.location.hostname+"/mainhit.php?hit_id="+hit_id+"&link=/main/go_mall/go_mall.php?pr_id="+pr_id+"&pr_type="+pr_type,"_blank",'');
	}
}  


function Login(query,hit,idpwd){
    if(idpwd){
        if(hit){
            window.open("http://"+window.location.hostname+"/mainhit.php?hit_id="+hit+"&link=/main/mypage/member/member_find_id.php?"+query,"login","width=494,height=368,top=100,left=100,status=no,scrollbars=no,resizable=yes");
        }else{
            window.open("/main/mypage/member/member_find_id.php?"+query,"login", "width=494,height=368,top=100,left=100,status=no,scrollbars=no,resizable=yes");
        }
    }else{
        if(hit){

            window.open("http://"+window.location.hostname+"/mainhit.php?hit_id="+hit+"&link=/main/login/login.php?"+query,"login", "width=494,height=368,top=100,left=100,status=no,scrollbars=no,resizable=yes");
		}else{
			popup_load( '/main/login/login.php?'+query, 450, 388, 'no' );
        }

    }
}


//»óÇ° ÂòÇÏ±â
// product_type [ 0 : ºñ±³, 1 : °Ë»ö ]
// product_id [ product_type + product_id ]
function MyinfoIns( product_id, is_login)
{
	if ( is_login && is_login != 0 )
	{
		var url = "/main/mypage/wishlist_register.php?product_id="+ product_id;
		var option = "width=500,height=450,status=no,scrollbars=no,resizable=yes";
		window.open( url, 'wishpop', option );
	}
	else
	{
		var go_url;
		if ( !product_id )
		{
			go_url = "";
		}
		else
		{
			go_url = "lpath="+ escape("/main/mypage/wishlist_register.php?product_id="+ product_id);
		}

		var url = "/main/login/login.php?self=1&"+ go_url ;
		var win_name = "login" ;
		var properties = "width=450,height=390,status=no,scrollbars=no,resizable=no" ;
		window.open( url, win_name, properties );
	}

	/*
    if(target)
        target= "&target="+target;
    else
        target= "";

    if(is_login){
        window.open("http://"+window.location.hostname+"/mainhit.php?hit_id=814&link=/main/mypage/myshop/zzim_pd_action.php?uni_id=" +uni_id+target, "zzim","width=433,height=270,status=no,scrollbars=no,resizable=yes");
    }
    else{
        Login("lpath=/main/mypage/myshop/zzim_pd_action.php&lqry="+escape("uni_id="+uni_id+target)+"&mode=14&kind=zzim","814");
    }
	*/
}

// 060 ºê·£µå Ä«Å×°í¸® select box script
function chg_brand( a )
{
	form = document.bnd_sel
	if(a==0){
	}
	else if(a=="all_brand"){
		form.bnd_cate.value=1;
		form.action="cate_list.php";
		form.submit();
	}else{
		form.bnd_cate.value="1";
		elem = a.split("^");
		form.action="pd_list_bnd.php";
		form.ckcomp.value=elem[0];
		if(elem[1]){
			form.ckbnd.value=elem[1];
		}
		form.submit();
	}
}


function PrRv_Pop( pr_id )
{
	window.open("/main/board/cm_review.php?pr_id="+pr_id,"rv","width=735,height=700,top=0,left=0,status=0,scrollbars=yes,resizable=yes");
}
