<?php
error_reporting(0);
echo "document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"/tpl/comm/css/lang_select.css\" />');";
//====================================================================
//
// 기본 언어 설정 by chris choi 20090417
//
// Default Language 우선 순위대로 적용해야 함.
//
// 1. 쿠키 있을 경우, 쿠키(path : baseUrl 적용/20090423)
// 2. 관리자 설정 기본 언어(20090424)
// (3. 브라우저)
//====================================================================
	require_once($_SERVER['DOCUMENT_ROOT']."/tpl/comm/php/default.php");

	$basePath = $_GET['bp'];
	$Shop_ID = $_GET['si'];
	

?>

/*
var url = parent.document.location.toString();
if (url.indexOf('board.html') !== -1)
{
    var urlArr = new Array();
    urlArr = url.split("/");
    var lang =urlArr.length - 2;
    
    if (url.indexOf('lang') == -1)
    {
        parent.document.location.href = '../'+ urlArr[lang] +'/board.html';
    }
}
*/



//alert('<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>');

/*
if (parent.location.href.indexOf('/en/') < 0) alert(parent.location.href);
else if (parent.location.href.indexOf('/en/') >= 0) alert('en');
else if (parent.location.href.indexOf('/ko/') < 0) alert(parent.location.href);
else if (parent.location.href.indexOf('/ko/') >= 0) alert('ko');
else if (parent.location.href.indexOf('/zh_cn/') < 0) alert(parent.location.href);
else if (parent.location.href.indexOf('/zh_cn/') >= 0) alert('zh_cn');
*/
//if (parent.location.href.indexOf('/ko/') >= 0) alert('ko');

function changeLang(url){
	//alert(t);
    //return;

	// 다국어 주소 정책 적용 by chris 20090605
	//url = eval("document.getElementById('"+t+"')").value;
	if(url) {
		//setCookie('hLANG',lang,null);
			
		window.top.location.href = url;
        
		//parent.location.href = url; 

	}

	// 쿠키 이용한 기존 언어 선택
	//lang = eval("document.getElementById('"+t+"')").value;
	//if(lang) {
	//	setCookie('hLANG',lang,null);
    //window.top.location.reload();
	//	parent.location.replace(parent.location.href); 
	//}
}

function setLang() {
	el = document.getElementById('v-wdg-chglang');
	// 예외처리 : el에 해당 값이 없을 경우 getCookie()의 getDefaultLang()에서 처리
	var lang = getCookie('hLANG');
	// 예외처리 : 쿠키값이 el에 있는지 체크
	var chk = 0;
	var i;
	for (i = el.length - 1; i>=0; i--) {
		if (el.options[i].value) {
			//alert(el.options[i].value);
			if (lang == el.options[i].value) el.value = lang;
			chk = 1;
		}
	}

	// 예외처리 : 쿠키값이 el에 없을 경우
	if (chk != 1) 
	{
		// 예외처리 1 : 첫번째 값 보여주기
		el.value = el.options[0];

		// 예외처리 2 : 쿠키값 삭제 후, 리로드
		alert('hLANG:<?php echo $basePath; ?>');
		deleteCookie('hLANG','<?php echo $basePath; ?>');
		parent.location.replace(parent.location.href); 
	}
}

function setCookie(c_name,value,expiredays)
{
	if (value == "") value = getDefaultLang();
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	//document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ "; path=/";
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+ "; path=<?php echo $basePath; ?>";
}

function getCookie(c_name)
{
// 우선 순위 1. 쿠키 있을 경우, 쿠키(path : baseUrl 적용)
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			//alert('[1]'+unescape(document.cookie.substring(c_start,c_end)));
			var lang = unescape(document.cookie.substring(c_start,c_end));
			if (lang == "undefined") lang = getDefaultLang(); // DEFAULT;
		}
		else
		{
			lang = getDefaultLang(); // DEFAULT;
		}
	}
	else
	{
		lang = getDefaultLang(); // DEFAULT;
	}
        return lang;
}

function deleteCookie(c_name,path)
{
	var expireDate = new Date();
	expireDate.setDate( expireDate.getDate() - 1 );
	document.cookie = c_name + "= " + "; expires=" + expireDate.toGMTString() + "; path=" + path;
}

function getDefaultLang() {

// 우선 순위 2. 관리자 설정 기본 언어

<?php
	$defaultLang = getDefaultLang($Shop_ID);
	if ($defaultLang != "auto")
	{
?>
	var lang = '<?php echo $defaultLang; ?>';
<?php
	}
	else
	{
?>
	// debug용
	var default_lang = '<?php echo $defaultLang; ?>';

// 우선 순위 3. 브라우저
	var lang = navigator.language || navigator.browserLanguage;
<?php
	}
?>
	setCookie('hLANG',lang,null);
	return lang;
}



function getoffset(e) 
{  
	var t=e.offsetTop;  
	var l=e.offsetLeft;  
	while(e=e.offsetParent) 
	{
	  if (e.id !== 'v_home_dft'){
		  t+=e.offsetTop;  
		  l+=e.offsetLeft;
	  }
	}
	return Array(t,l);
}


var userAgent = navigator.userAgent.toLowerCase();  
browser={  
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],  
	safari: /webkit/.test( userAgent ),  
	opera: /opera/.test( userAgent ),  
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),  
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )  
}


window.onload = function(){

	if (browser.version < 7){
		var menu = document.getElementsByTagName('ul');
		for (var i=0; i < menu.length; i++ ){
			if (menu(i).className.indexOf("mainmenu") != -1){
				mainmenu = 	menu(i);
				var m = mainmenu.childNodes;
				for (var n=0; n < m.length; n++ ){

					m(n).onmouseover = function(){
						for (var x =0; x < this.childNodes.length ; x++ )
						{
							
							if (this.childNodes(x).tagName == 'UL')
							{
								//alert(this.childNodes(x).tagName);
								this.childNodes(x).style.visibility  = "visible";
							}
						}
					}

					m(n).onmouseout = function(){
						for (var x =0; x < this.childNodes.length ; x++ )
						{
							
							if (this.childNodes(x).tagName == 'UL')
							{
								//alert(this.childNodes(x).tagName);
								this.childNodes(x).style.visibility  = "hidden";
							}
						}
					}
					
				}
			}
		}
	}




if (getId("v-wdg-chglang")) {
	var obj = getId("v-wdg-chglang");
	pos = getoffset(obj);
	var objv = getId("v_home_dft");
	objv.appendChild(obj);
	var obj = getId("v-wdg-chglang");
	obj.style.top = pos[0] + 'px';
	obj.style.left = pos[1] + 'px';
}



if (getId("hns_footer_content")) {
	if (getId("board_list")) getId("board_list").style.height = 'auto'
	//getId("hns_footer").style.display = "none";
	var max_top = 0;
	var max_id = '';
	var max_height  = 0;
	var divs  =document.getElementsByTagName("div");
	for (var i=0;i < divs.length;i++)
	{
    	if (divs[i].id != 'hns_footer_content')
        {
            max_height = divs[i].offsetTop + divs[i].offsetHeight;
            if (max_height > max_top){ 
                max_top = max_height;
                max_id = divs[i].id;
            }
        }
	}
	getId("hns_footer_content").style.top = (max_top + 20)+"px";
}

//var lang = getCookie('hLANG');
//setLang();
}


function getId(id)
{
	return document.getElementById(id);
}


/*
document.ondragstart = function()  {
	return false;
}

document.onselectstart = function() {
	return false;
}
*/
//document.onmousedown = function(){
//	if (event.button==2 || event.button==3){ //오른쪽 마우스
		// IE(6,7)용. 텍스트 드래그 이상현상 방지(임시)
		//alert("상품 상세설명 무단 도용 방지를 위하여\n\n마우스 오른쪽 버튼은 사용하실 수 없습니다.");
//	}
//} 

/*
var Common =
{
	baseUrl: null
	, setBaseUrl: function(url) 
	{
		alert(url);
		Common.baseUrl = url;
	}
	
	, url: function(url)
	{
		return this.baseUrl+url.replace(/^\/+/, '');
	}
}
Common.setBaseUrl();
*/
