/* 기본상수 잡기 */
/* 추후 설정에 맞춰 변경해주세요. */
// -----------------------------------------------------------------------------

var default_image_path = "/images/v1/";

// -----------------------------------------------------------------------------



/* 마우스 오버, 아웃시 이미지 변경 */
function imageOver(obj, folder, image_file, mouse_action)
{
	var arr_file = image_file.split(".");
	var file_name = "";

	// 마우스오버 파일명 잡기
	for (i = 0; i < arr_file.length - 1; i++)
	{
		if (file_name == "")
			file_name = arr_file[i];
		else
			file_name += "." + arr_file[i];
	}

	// 폴더명이 '/'로 끝나지 않을 경우 예외처리
	if (folder.substring(folder.length - 1, folder.length) != "/")
		folder += "/";

	var over_image_file = file_name + "_ov." + arr_file[arr_file.length - 1];

	if (mouse_action == "over")
		obj.src = default_image_path + folder + over_image_file;
	else if (mouse_action == "out")
		obj.src = default_image_path + folder + image_file;
}

/* 마우스 오버, 아웃시 이미지 변경 */
function imageOver2(obj, folder, image_file, mouse_action)
{
	var arr_file = image_file.split(".");
	var file_name = "";

	// 마우스오버 파일명 잡기
	for (i = 0; i < arr_file.length - 1; i++)
	{
		if (file_name == "")
			file_name = arr_file[i];
		else
			file_name += "." + arr_file[i];
	}

	// 폴더명이 '/'로 끝나지 않을 경우 예외처리
	if (folder.substring(folder.length - 1, folder.length) != "/")
		folder += "/";

	var over_image_file = file_name + "_on." + arr_file[arr_file.length - 1];

	if (mouse_action == "over")
		obj.src = "/images/" + folder + over_image_file;
	else if (mouse_action == "out")
		obj.src = "/images/" + folder + image_file;
}


/* div 영역 Toggle Display */
function toggleDisplay(obj_nm)
{
	var obj = document.getElementById(obj_nm);

	if (obj.style.display == "none"){
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
}


/* PNG24 이미지 제대로 보여주기 (IE 6.0 이하 버그 해결) */
function setPng24(obj)
{
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter =
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='';
	return '';
}


/* 플래시 */
function flash(width, height, path, file)
{
 var url = String(document.location);
 var protocol = url.split(":")[0].toLowerCase();
 if (protocol != "https")
  protocol = "http";

  var flash_tag = "";
  flash_tag =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
 flash_tag += 'id="fla_' + file + '" width="'+width+'" height="'+height+'" ';
 flash_tag += 'codebase="'+protocol+'://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> ';
 flash_tag += '<param name="movie" value="'+path+'/'+file+'.swf" /> ';
 flash_tag += '<param name="quality" value="high" /> ';
 flash_tag += '<param name="wmode" value="transparent">';
 flash_tag += '<param name="allowScriptAccess" value="always" /> ';
 flash_tag += '<embed src="'+path+'/'+file+'.swf?pageNum=3&subNum=1" quality="high" wmode="transparent" ';
 flash_tag += 'width="'+width+'" height="'+height+'" name="fla_'+ file +'" align="middle" ';
 flash_tag += 'play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" ';
 flash_tag += 'pluginspage="'+protocol+'://www.adobe.com/go/getflashplayer"> ';
 flash_tag += '</embed>';
 flash_tag += '</object>';

 document.write(flash_tag);
}


/* 플래시 */
function flashParam(width, height, path, file, params)
{
	 var url = String(document.location);
	 var protocol = url.split(":")[0].toLowerCase();
	 if (protocol != "https")	protocol = "http";


 	var flash_tag = "";
 	flash_tag =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	flash_tag += 'id="fla_' + file + '" width="'+width+'" height="'+height+'" ';
	flash_tag += 'codebase="'+protocol+'://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> ';
	flash_tag += '<param name="movie" value="'+path+'/'+file+'.swf'+params+'" /> ';
	flash_tag += '<param name="quality" value="high" /> ';
	flash_tag += '<param name="wmode" value="transparent">';
	flash_tag += '<param name="allowScriptAccess" value="always" /> ';
	flash_tag += '<embed src="'+path+'/'+file+'.swf'+params+'" quality="high" wmode="transparent" ';
	flash_tag += 'width="'+width+'" height="'+height+'" name="fla_'+ file +'" align="middle" ';
	flash_tag += 'play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" ';
	flash_tag += 'pluginspage="'+protocol+'://www.adobe.com/go/getflashplayer"> ';
	flash_tag += '</embed>';
	flash_tag += '</object>';

	document.write(flash_tag);
}


/* menu scroll */
	var scleft = 0;
	var nowscroll = 0;
	var scroll_gap = 20;

	function main_scroll(stype,list_main) {
		if (stype == "R")
		{
			scleft = -550;
			scroll_right(list_main);
			document.getElementById("lbtn").src = "/images/button/btn_goleft_on.png";
			document.getElementById("rbtn").src = "/images/button/btn_goright_on.png";
		}
		else if (stype == "L")
		{
			scleft = 0;
			scroll_left(list_main);
			document.getElementById("lbtn").src = "/images/button/btn_goleft.png";
			document.getElementById("rbtn").src = "/images/button/btn_goright.png";
		}
	}

	function scroll_right(list_main) {
		nowscroll = nowscroll - scroll_gap;
		document.getElementById(list_main).style.left = nowscroll+"px";
		if (nowscroll > scleft)
		{
			setTimeout(function() {scroll_right(list_main);},10);
		}
		else {
			document.getElementById(list_main).style.left = scleft+"px";
			nowscroll = -740;
		}
	}

	function scroll_left(list_main) {
		nowscroll = nowscroll + scroll_gap;
		document.getElementById(list_main).style.left = nowscroll+"px";
		if (nowscroll < scleft)
		{
			setTimeout(function() {scroll_left(list_main);},10);
		}
		else {
			document.getElementById(list_main).style.left = scleft+"px";
			nowscroll = 0;
		}
	}

/* mouseover script. only class=have_mouseover/ _on.png */
 function have_mouseover()    {
        var srcs = document.getElementsByTagName("img");
        for(var i=0; i<srcs.length;i++)     {
            if(srcs[i].className == "have_mouseover")    {
                srcs[i].onmouseover = function()    {
                        var src_string = this.getAttribute("src");
                        var src_string_split = src_string.split(".png");
                        var src_string_split_ov = src_string_split[0].concat("_on").concat(".png");
                        this.src = src_string_split_ov;
                }
                srcs[i].onmouseout = function()    {
                        var src_string = this.getAttribute("src");
                        var src_string_split = src_string.split("_on.png");
                        var src_string_split_out = src_string_split[0].concat(".png");
                        this.src = src_string_split_out;
                }
            }
        }
    }

window.onload = function() {
	have_mouseover();
}



/* 매장정보 플래시 */
function loadLocation(location_no){
	var str_url = "list.jsp?SHOP_AREA=";
	switch (location_no)
	{
		case "01": shop_area = "2"; break;
		case "02": shop_area = "4"; break;
		case "03": shop_area = "1"; break;
		case "04": shop_area = "14"; break;
		case "05": shop_area = "10"; break;
		case "06": shop_area = "12"; break;
		case "07": shop_area = "11"; break;
		case "08": shop_area = "7"; break;
		case "09": shop_area = "15"; break;
		case "10": shop_area = "16"; break;
		case "11": shop_area = "3"; break;
		case "12": shop_area = "13"; break;
		case "13": shop_area = "9"; break;
		case "14": shop_area = "17"; break;
		case "15": shop_area = "8"; break;
		case "16": shop_area = "5"; break;
	}

	location.href = str_url + shop_area;
}



//이미지 크기 조절하여 img 태그 출력 ******************************************
function change_image_size2(imgFile, limit_width, limit_height)
{
	var real_width			= imgFile.width;
	var real_height			= imgFile.height;

	if (limit_width == 0)
		limit_width			= real_width;
	if (limit_height == 0)
		limit_height		= real_height;

	if (real_width >= real_height)
	{
		if (real_width <= limit_width)
		{
			result_width	= real_width;
			result_height	= real_height;
		}
		else
		{
			result_width	= limit_width;
			result_height	= parseInt((real_height * limit_width) / real_width);
		}
	}
	else
	{
		if (real_height <= limit_height)
		{
			result_width	= real_width;
			result_height	= real_height;
		}
		else
		{
			result_width	= parseInt((real_width * limit_height) / real_height);
			result_height	= limit_height;
		}
	}

	imgFile.width			= result_width;
	imgFile.height			= result_height;
	imgFile.style.visibility	= "visible";
}




/* 메뉴 링크 */
function LeftmenuLink(b_no, m_no, s_no)
{
	b_no = Number(b_no);
	m_no = Number(m_no);
	s_no = Number(s_no);

	var url = "";
	var target= "";
	var open_vars = "";

	if (b_no == 0) {
		url = "/Front/Main/main.jsp";
	}

	// Brand
	if (b_no == 1)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Brand/Intro/default.jsp"; break;								//Introduce 회사소개
			case 2	: url = "/Front/Brand/History/default.jsp"; break;								//History 연혁
			case 3	: url = "/Front/Brand/BI/default.jsp"; break;									//BI -> Descente BI
		}
	}

	//Product
	else if(b_no == 2)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Expression/Inspired/default.jsp"; break;						//Inspired
//			case 2	: url = "/Front/Expression/Performance/default.jsp"; break;						//Performance
			case 3	: url = "/Front/Innovation/Apparel/apparel_01.jsp"; break;						//Product Story
			case 4	: url = "/Front/Expression/catalog.jsp"; break;						//Catalog
//			case 4	: target = "catalog"; open_vars = "width=1000, height=720"; url = "/Front/Expression/catalog.jsp"; break;
		}
	}

	//Media
	else if(b_no == 3)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Media/Media_movie/list.jsp"; 	break;			//CF -> UCC
//			case 2	: url = "/Front/Media/Star_Gallery/list.jsp"; 	break;			//STAR GALLERY -> STAR
			case 3	: url = "/Front/Media/Magazine/list.jsp"; 	break;				//Magazine
//			case 4	: url = "/Front/Media/Media_Gallery/list.jsp"; 	break;			//PRESS
			case 5	: url = "/Front/Media/Download/default.jsp"; 	break;			//Download(이 링크는 TOPMENU에는 없지만, FOOTER에서 LeftmenuLink(3,5)식으로 불러쓰기위함
		}
	}


	//Sponsor Ship
	else if(b_no == 4)
	{
//		target = "sponsor";
//		open_vars = "width=1000, height=720, left=0, top=0";
//		url = "/Front/Sponsor/Choo/profile.jsp";
//		alert("운영하지 않는 페이지입니다");
	}


	//Event
	else if(b_no == 5)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Event/Event/list.jsp"; 	break;					//Event 이벤트
			case 2	: url = "/Front/Event/Winner/list.jsp"; 	break;				//Winner 당첨자 게시판
		}
	}

	//-------------------------------------------------------
	// 공통
	//-------------------------------------------------------

	//고객센터
	else if(b_no == 6)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Customer/Notice/list.jsp"; break;			//공지사항
			case 2	: url = "/Front/Customer/FAQ/list.jsp"; break;				//FAQ
			case 3	: url = "http://www.descente.co.kr/Front/Main/main.jsp"; break;				//1:1문의
			case 4	: url = "/Front/Customer/ShopInfo/list.jsp"; break;			//매장 정보

		}

	}

	//로그인 / Join
	else if(b_no == 12)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/User/login.jsp"; break;			//로그인
			case 2	: url = "/Front/User/idSearch.jsp"; break;		//아이디 찾기
			case 3	: url = "/Front/User/pwSearch.jsp"; break;		//비번 찾기
			case 4	: url = "/Front/Join/join.jsp"; break;			//회원가입

		}
	}

	//MyPage
	else if(b_no == 13)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Mypage/Info/modify.jsp"; break;					//회원정보수정
			case 2	: url = "/Front/Mypage/MyQNA/list.jsp"; break;					//1:1문의 현황
			case 3	: url = "/Front/Mypage/MyEvent/list.jsp"; break;				//이벤트참여현황
		}
	}

	//ETC
	else if(b_no == 14)
	{
		switch (m_no)
		{
			case 1	: url = "/Front/Etc/PersonPolicy/default.jsp"; break;						//개인정보 보호정책
			case 2	: url = "/Front/Etc/Pervision/default.jsp"; break;				//이용약관
			case 3	: url = "/Front/Etc/SiteMap/default.jsp"; break;				//사이트맵
		}
	}


	//alert("b_no : " + b_no +" / m_no : " + m_no + " / s_no : " + s_no);

	if (url == "")
	{
		alert("운영하지 않는 페이지입니다");
	}
	else
	{
		if (target != "")
			window.open(url, target, open_vars);
		else
			location.href = url;
	}
}


/* Flash Xml 경로 선언 */
function getFlashXmlPath()
{
	return "/common/flash/xml/";
}


/* 메인페이지 배너 링크 */
function mainFlashBannerLink(link_no)
{
	link_no = Number(link_no);
	var url = "";
	var target = "_blank";

	switch (link_no)
	{
	}

	if (url != "")
	{
		if (target == "_self")
			location.href = url;
		else
			window.open(url, target);
	}
}

/* 풋터 링크 */
function footerLink(link_no)
{
	link_no = Number(link_no);
	var url = "";
	var target = "_blank";

	switch (link_no)
	{
	//풋터의 첫번째 줄링크는 E-SHOP:직접걸기,BLOG:직접걸기, SPONSORSHIP,DOWNLOAD: LeftmenuLink()로 걸어서 넘어간다고함
		case 1 : url = "http://www.descentekorea.co.kr"; break;
		case 2 : url = "/Front/Customer/ShopInfo/list.jsp"; target="_self"; break;
		case 3 : window.open("/Front/Etc/privacy.jsp", "agree", "width=450, height=355"); break;
		case 4 : window.open("/Front/Etc/agreement.jsp", "agree", "width=450, height=355"); break;
		case 5 : url = "/Front/Customer/Notice/list.jsp"; target="_self"; break;
		case 6 : url = "/Front/Etc/SiteMap/default.jsp"; target="_self"; break;
	}

	if (url != "")
	{
		if (target == "_self")
			location.href = url;
		else
			window.open(url, target);
	}
}

/* 풋터 글로벌 링크*/
function bottomFlashLink(link_no){

	link_no = Number(link_no);
	var url = "";
	var target = "_blank";


	switch (link_no)
	{
		case 0 : url = "http://www.lecoqsportif.com"; break;		//LECOQSPORTIF USA
		case 1 : url = "http://www.lecoqgolf.com"; break;			//LECOQGOLF USA
		case 2 : url = "http://www.munsingwear-jp.com"; break;		//MSW JAPAN
		case 3 : url = "http://www.munsingwear-jp.com"; break;		//DST JAPAN
		case 4 : url = "http://www.ridedna.com/"; break;			//DST USA
		case 5 : url = "http://www.descente.com/"; break;			//DST NORTH AMERICA
		case 6 : url = "http://www.descenteathletic.com"; break;	//DWT VELTEC
	}

	if (url != "")
	{
		if (target == "_self")
			location.href = url;
		else
			window.open(url, target);
	}



}

/* 글로벌사이트 링크 */
function globalLink(link_no)
{
	link_no = Number(link_no);
	var url = "";
	var target = "_blank";

	switch (link_no)
	{
	case 1 : url = "http://www.lecoqsportif.com"; break;
	case 2 : url = "http://www.lecoqgolf.com"; break;
	case 3 : url = "http://www.munsingwear-jp.com"; break;
	case 4 : url = "http://www.descente.co.jp"; break;
	case 5 : url = "http://www.ridedna.com"; break;
	case 6 : url = "http://www.descente.com"; break;
	case 7 : url = "http://www.descenteathletic.com"; break;
	}

	if (url != "")
	{
		if (target == "_self")
			location.href = url;
		else
			window.open(url, target);
	}
}


//----------------------------------------------------------------------------------
//
//외부
//
//-----------------------------------------------------------------------------------
/***********************************************************************************************************************
* 이 function을 사용하기 위해선 form의 elements에 대해서 몇가지 특별한 마킹을 해야합니다.
*
* required="*" : 필수 여부 체크
*
* num="3.2" : 3 - 정수부 길이, 2 - 소수부 길이
*
* len="4-12" : 문자 길이 (4 - 최소 길이, 12 - 최대 길이)
*
* txtMsg : 필드에 값을 입력 안했을 경우 출력하는 메시지
*
* numMsg : 숫자 체크 시 출력하는 메시지
*
* lenMsg : 문자 길이 체크 시 출력하는 메시지
*
* 예시는 다음과 같다.
* ex: <input type="text" name="tmp_name" value="" required="*" num="3.2" len="4-12" txtMsg="임시필드를 입력해주세요." numMsg="임시필드는 정수 3자리 실수 2자리입니다." lenMsg="임시필드는 최소크기 4, 최대크기 12입니다.">
*
* 이 스크립트는 submit 시점에 전체 필드에 대한 체크를 하도록 사용하고 그 체크 순서는 객체의 순서임.
***********************************************************************************************************************/
function validateFrm(which){
  with(which){
      for(x = 0; x < length; x++){
          if(elements[x].getAttribute("required") == "*"){
              var fieldName = elements[x].name;
              if(!eval(fieldName).length){
                  if(elements[x].disabled == false && trimField(elements[x]) == ""){
                      eval(fieldName).focus();
                      alert(elements[x].getAttribute("txtMsg"));
                      return false;
                  }
                  if(elements[x].disabled == false && elements[x].getAttribute("num") != null && elements[x].num != ""){
                      var numVal = elements[x].getAttribute("num").split(".");
                      if(!numVal[1]){
                          if(checkInteger(eval(fieldName).value, numVal[0], 0) == false){
                              eval(fieldName).focus();
                              alert(elements[x].getAttribute("numMsg"));
                              return false;
                          }
                      }
                      else{
                          if(checkInteger(eval(fieldName).value, numVal[0], numVal[1]) == false){
                              eval(fieldName).focus();
                              alert(elements[x].getAttribute("numMsg"));
                              return false;
                          }
                      }
                  }
                  if(elements[x].disabled == false && elements[x].getAttribute("len") != null && elements[x].getAttribute("len") != ""){
                      var lenVal = elements[x].getAttribute("len").split("-");
                      if(!lenVal[1]){
                          if(checkLength(eval(fieldName).value, lenVal[0], lenVal[0]) == false){
                              eval(fieldName).focus();
                              alert(elements[x].getAttribute("lenMsg"));
                              return false;
                          }
                      }
                      else{
                          if(checkLength(eval(fieldName).value, lenVal[0], lenVal[1]) == false){
                              eval(fieldName).focus();
                              alert(elements[x].getAttribute("lenMsg"));
                              return false;
                          }
                      }
                  }
              }
              else{
                  if(!eval(fieldName)[0].length){
                      for(y = 0; y < eval(fieldName).length; y++){
                          if(eval(fieldName)[y].selected && trimField(eval(fieldName)[y]) == ""){
                              eval(fieldName).focus();
                              alert(eval(fieldName).getAttribute("txtMsg"));
                              return false;
                          }
                      }
                  }
                  else{
                      for(y = 0; y < eval(fieldName).length; y++){
                          if(eval(fieldName)[y].disabled == false && trimField(eval(fieldName)[y]) == ""){
                              eval(fieldName)[y].focus();
                              alert(eval(fieldName)[y].getAttribute("txtMsg"));
                              return false;
                          }
                          if(eval(fieldName)[y].disabled == false && eval(fieldName)[y].getAttribute("num") != null && eval(fieldName)[y].getAttribute("num") != ""){
                              var numVal = eval(fieldName)[y].getAttribute("num").split(".");
                              if(!numVal[1]){
                                  if(checkInteger(eval(fieldName)[y].value, numVal[0], 0) == false){
                                      eval(fieldName)[y].focus();
                                      alert(eval(fieldName)[y].getAttribute("numMsg"));
                                      return false;
                                  }
                              }
                              else{
                                  if(checkInteger(eval(fieldName)[y].value, numVal[0], numVal[1]) == false){
                                      eval(fieldName)[y].focus();
                                      alert(eval(fieldName)[y].getAttribute("numMsg"));
                                      return false;
                                  }
                              }
                          }
                          if(eval(fieldName)[y].disabled == false && eval(fieldName)[y].getAttribute("len") != null && eval(fieldName)[y].getAttribute("len") != ""){
                              var lenVal = eval(fieldName)[y].getAttribute("len").split("-");
                              if(!lenVal[1]){
                                  if(checkLength(eval(fieldName)[y].value, lenVal[0], lenVal[0]) == false){
                                      eval(fieldName)[y].focus();
                                      alert(eval(fieldName)[y].getAttribute("lenMsg"));
                                      return false;
                                  }
                              }
                              else{
                                  if(checkLength(eval(fieldName)[y].value, lenVal[0], lenVal[1]) == false){
                                      eval(fieldName)[y].focus();
                                      alert(eval(fieldName)[y].getAttribute("lenMsg"));
                                      return false;
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }

      return true;
  }
}

/*****************************************************
* 실수 자리수를 체크하는 함수
*
* val : 체크를 하는 실수
*
* intLen : 정수부 길이
*
* realLen : 실수부 길이
****************************************************/
function checkInteger(val, intLen, realLen){
  var valNum = val.split(".");

  if(isFloat(val)== false)
      return false
  else if(!valNum[0])
      return false;
  else if(realLen == 0){
      if(valNum[0].length > intLen)
          return false;
      else if(typeof(valNum[1]) != "undefined")
          return false;
      else
          return true;
  }
  else{
      if(valNum[0].length > intLen)
          return false;
      else if(typeof(valNum[1]) != "undefined" && valNum[1].length > realLen)
          return false;
      else
          return true;
  }
}

/*****************************************************
* 실수를 체크하는 함수
*
* val : 체크를 하는 실수
****************************************************/
function isFloat(val) {
  var count = 0;
  var ch;

  for(idx = 0; idx < val.length; idx++){
      ch = val.charAt(idx);

      if(isNaN(ch)){
          if(ch == ".")
              count ++;
          else
              return false;
      }
  }

  if(count > 1)
      return false;
  else
      return true;
}

/*****************************************************
* 문자 길이를 체크하는 함수
*
* val : 체크를 하는 문자
*
* minLen : 최소 길이
*
* maxLen : 최대 길이
****************************************************/
function checkLength(val, minLen, maxLen){
  var len = byteNum(val);

  if(len < minLen)
      return false;
  else if(len > maxLen)
      return false;
  else
      return true;
}

/*****************************************************
* trimField(form.field)
*  : 문자열 앞뒤의 공백을 지움 (' ', '\r', '\n', '\t')
* examples  :
*
* form.field = ' ha한글 '일 경우....
* trimField(form.field) -> 'ha한글'
*
* return : 대체된 새로운 문자열
* date   : 2007-01-05
****************************************************/
function trimField(input) {
  if (input == "") {
      return;
  }
  var str     = input.value;
  var len     = str.length;
  var iFrom   = 0;
  var iTo     = len;

  for(var i=0 ; i < len ; i++) {
      if( str.charAt(i) == ' ' || str.charAt(i) == '\r' || str.charAt(i) == '\n' || str.charAt(i) == '\t' )
          iFrom = i+1;
      else break;
  }
  for(var i=len-1 ; i > iFrom ; i--) {
      if( str.charAt(i) == ' ' || str.charAt(i) == '\r' || str.charAt(i) == '\n' || str.charAt(i) == '\t' )
          iTo = i;
      else break;
  }
  return str.substring(iFrom, iTo);
}

/*****************************************************
* ltrim(val)
*  : 문자열 왼쪽 공백 삭제
* examples  : ltrim(' abc')
*
* val    : 요청된 문자열
* return : 대체된 새로운 문자열
* date   : 2007-01-05
****************************************************/
function ltrim(val){
  var s = new String(val);
  if (s.substr(0,1) == " ") return ltrim(s.substr(1));
  else return s;
}

/*****************************************************
* rtrim(val)
*  : 문자열 오른쪽 공백 삭제
* examples  : rtrim('abc ')
*
* val    : 요청된 문자열
* return : 대체된 새로운 문자열
* date   : 2007-01-05
****************************************************/
function rtrim(val){
  var s = new String(val);
  if(s.substr(s.length-1,1) == " ") return rtrim(s.substring(0, s.length-1));
  else return s;
}

/*****************************************************
* trim(val)
*  : 문자열 오른쪽,왼쪽 공백 삭제
* examples  : trim(' abc ')
*
* val    : 요청된 문자열
* return : 대체된 새로운 문자열
* date   : 2007-01-05
****************************************************/
function trim(val){
  return ltrim(rtrim(val));
}

/*****************************************************
* 문자의 길이를 구하는 함수
*
* val : 길이를 구하는 문자
* date   : 2007-01-05
****************************************************/
function byteNum(val){
  var byteLength = 0;

  for(inx = 0; inx < val.length; inx++){
      var oneChar = escape(val.charAt(inx));
      if(oneChar.length == 1)
          byteLength ++;
      else if(oneChar.indexOf("%u") != -1)
          byteLength += 2;
      else if(oneChar.indexOf("%") != -1)
          byteLength += oneChar.length/3;
  }

  return byteLength;
}

/*********************************************************************
* alertMsg(form.field) : 주어진 문자열로 경고창을 띄운 뒤 입력객체에 포커스 됨.
* examples  :
*
* if (isValidPhone(form.field)) {
*      alertMsg(form.field, '입력값이 전화번호 형식이네요.');
* }
*
* return : 항상 False. -> 의미 없음.
* date   : 2007-01-05
*********************************************************************/
function alertMsg( input, msg ) {
  alert( msg );
  if (!isNullObj(input)) {
	    var preStat = input.disabled;
	    input.disabled = false;
	    input.focus();
	    input.select();
	    input.disabled = preStat;
  }
  return false;
}

/*****************************************************
* isNullObj(form.field) : 해당 오브젝트가 NULL인지 체크
* return : 해당오브젝트가 Null 이면 true
* date   : 2007-01-05
****************************************************/
function isNullObj( obj ) {
  if (obj == null || obj == "undefined") {
      return true;
  }
  return false;
}

/*****************************************************
* isNumber(form.field) : 입력값이 숫자로만 되어 있는지 체크
* 본 함수가 자주 호출될 경우에는 숫자 지역변수를 전역변수로
* 사용해도 좋다.
* examples  :
*
* if( isNumber(form.field) ) {
*   alert('입력값이 숫자로만 구성되어 있네요.');
* }
*
* return : 입력값이 숫자로만 이루어져 있으면 TRUE
* date   : 2007-01-05
****************************************************/
function isNumber(input) {
  var chars = "0123456789";
  return containsCharsOnly(input,chars);
}

/****************************************************************
* containsCharsOnly(form.field, chars) :
* 입력값이 특정 문자만으로 되어있는지 체크
* examples  :
*
* if( containsCharsOnly(form.field, "ABO") ) {
*   alert('입력값이 A or B or O 문자로만 구성되어 있네요.');
* }
*
* return : 입력값이 지정한 특정문자로만 되어 잇으면 TRUE
* date   : 2007-01-05
****************************************************************/
function containsCharsOnly(input,chars) {
  for (var inx = 0; inx < input.value.length; inx++) {
     if (chars.indexOf(input.value.charAt(inx)) == -1)
         return false;
  }
  return true;
}

/****************************************************************
* isNumComma(form.field, format) :
* 입력값이 사용자가 정의한 포맷 형식인지 체크
* 자세한 format 형식은 자바스크립트의 'regular expression(정규식)'을 참조
* 정규식에 대한 내용은 검색엔진을 통해 찾아보면 나옴.
* examples  :
*
* if (isValidFormat(form.field, "[xyz]")) {
*      alert('x-z 까지의 문자가 존재하네요.');
* }
*
* return : 입력값이 지정한 올바른 포맷으로 되어 있으면 TRUE
* date   : 2002-10-28
****************************************************************/
function isValidFormat(input, format) {
  if (input.value.search(format) != -1) {
      return true;
  }
  return false;
}

/****************************************************************
* isValidEmail(form.field) : 입력값이 이메일 형식인지 체크
* examples  :
*
* if (isValidEmail(form.field)) {
*      alert('입력값이 이메일 형식이네요.');
* }
*
* return : 입력값이 이메일 형식으로 되어있으면 TRUE
* date   : 2002-10-28
****************************************************************/
function isValidEmail(input) {
  /*--
  var format = /^(\S+)@(\S+)\.([A-Za-z]+)$/;
  --*/
  var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
  return isValidFormat(input,format);
}


function goUrl(argUrl){
	location.href=argUrl;
}

function multiSelectCheck(input, msg){
	var multiSelectCount = 0;
	for(var multiSelectCheckVar = 0 ; multiSelectCheckVar < input.length ; multiSelectCheckVar++){
		if(input[multiSelectCheckVar].checked == true){
			multiSelectCount++;
		}
	}
	if(multiSelectCount == 0){
		alert( msg );
		return false;
	}else{
		return true;
	}
}

/**
* <pre>
* </pre>
* @param str
* @param true, false)
* @return boolean
* ex)  jsp
*      function ue_retrieve(){
*          if (!isDate(document.searchForm.fromDate.value)) return;
*          if (!isDate(document.searchForm.toDate.value)) return;
*/
function isDate(str) {
  var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  var ymd = str.split("/");

  if(str.length != 10 || ymd.length != 3 || ymd[0].length != 4 || ymd[1].length != 2 || ymd[2].length != 2 ){
		alert("The date is incorrect.");
      return false;
  }

  if (ymd[0]%1000 != 0 && ymd[0]%4 == 0) days[1] = 29;
  if ((ymd[2] > days[ymd[1]-1] || ymd[2] < 1)
       ||(ymd[1] < 1 || ymd[1] > 12)
       ||(ymd[1]%1 != 0 || ymd[0]%1 != 0 || ymd[2]%1 != 0) ){
		alert("The date is incorrect.");
      return false;
  }else   return true;
}

/**
* <pre>
* </pre>
* @return boolean
* ex) if (!chkFromTo(document.searchForm.fromDate.value,document.searchFrom.toDate.value,'field name')) {
*         document.searchForm.fromDate.focus();
*         return;
*     }
*/
function chkFromTo(fromDate, toDate, FName) {
	var fDate = fromDate.split('/');
	var tDate = toDate.split('/');
	fDate = fDate[0]+fDate[1]+fDate[2];
	tDate = tDate[0]+tDate[1]+tDate[2];
  if ( fDate > tDate ) {
      alert("날짜를 바르게 입력해주세요. "+FName+"");
      return false;
  }

  return true;
}


/**
* <PRE>
* Scroll 이 없는 새 창을 띄운다
* </PRE>
* @param   theURL 새로 띄울 파일 이름이다
* @param   winName 새창 이름
* @param   winTitle 새창 title
* @param	width 새창 가로 크기
* @param	height 새창 세로 크기
* @param   param 추가적인 화면 argument
*/
function openNoScrollWin(theURL, winName, winTitle, width, height, param)
{
	var wid = (screen.width)/2 - width/2 ;
	var hei = (screen.height)/2 - height/2;
	var win = window.open(theURL + "?popupTitle=" + winTitle + "&tableWidth=" + width + param, winName, "menubar=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height+ ",top=" + hei + ",left=" + wid + "");
	win.focus();
}

function openNoScrollWin_2(theURL,  winName, winTitle, width, height)
{
	var wid = (screen.width)/2 - width/2 ;
	var hei = (screen.height)/2 - height/2;
	var win = window.open(theURL ,winName ,"menubar=no, scrollbars=yes, resizable=no, width=" + width + ", height=" + height+ ",top=" + hei + ",left=" + wid + "");
	win.focus();
}

function openNoScrollWinPost(theURL, winName, winTitle, width, height, param)
{
	var wid = (screen.width)/2 - width/2 ;
	var hei = (screen.height)/2 - height/2;
	var win = window.open("about:blank", winName, "menubar=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height+ ",top=" + hei + ",left=" + wid + "");
	win.focus();
}

/**
* 간단 상품 검색(ENTER KEY)
*/
function semiGoodsSearchGo(e,path_root){
	if(e.keyCode == '13'){
		semiGoodsSearch(path_root);
	}
}

/**
* 간단 상품 검색
*/
function semiGoodsSearch(path_root){
	var form = document.semiSearchFrm;
	if(validateFrm(form) == true){
		if(isNumber(form.searchValue) == true){
			form.searchMethod.value="code";
		}
		form.action = path_root+"/display/search.do";
		form.submit();
	}else{
		return false;
	}
}

function writeFlash(strSrc, strWid, strHei){
var str = "";
str += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
str += " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'";
str += " width='"+strWid+"' height='"+strHei+"'>";
str += "    <param name='movie' value='"+strSrc+"'>";
str += "    <param name='quality' value='high'>";
str += "    <param name='wmode' value='transparent'>";
str += "    <embed src='"+strSrc+"' quality='high'";
str += "     pluginspage='http://www.macromedia.com/go/getflashplayer'";
str += "     type='application/x-shockwave-flash' width='"+strWid+"' height='"+strHei+"'></embed>";
str += "</object>";

document.writeln(str);
}

/**
* <pre>
* 숫자나 문자열을 통화(Money) 형식으로 만든다.( 쉼표(,) 찍는다는 소리.. )
* &lt;input type="text" name="test" value="" onkeyup="this.value=toCurrency(this.value);"&gt;
* or
* var num = toCurrency(document.form[0].text.value);
* </pre>
* @param	amount	"1234567"
* @return	currencyString "1,234,567"
*/
function toCurrency(amount){
  var data = amount.split(".");
	var sign = "";
	var firstChar = data[0].substr(0,1);
	if(firstChar == "-"){
		sign = firstChar;
		data[0] = data[0].substring(1, data[0].length);
	}
	data[0] = data[0].replace(/\D/g,"");
	if(data.length > 1){
		data[1] = data[1].replace(/\D/g,"");
	}
	firstChar = data[0].substr(0,1);
	//0으로 시작하는 숫자들 처리
	if(firstChar == "0"){
		if(data.length == 1){
			return sign + parseFloat(data[0]);
		}
	}
	var comma = new RegExp("([0-9])([0-9][0-9][0-9][,.])");
	data[0] += ".";
	do {
		data[0] = data[0].replace(comma, "$1,$2");
	} while (comma.test(data[0]));

	if (data.length > 1) {
		//= 소수점  .00 붙이기
//	    if(data[1].length == 1) data[1] = data[1] + "0";
//		return sign + data.join("");
		//= 소수점 없애기
		return sign + data[0].split(".")[0];
	} else {
		return sign + data[0].split(".")[0];
	}
}

/**
* ,이 있는 숫자를 순수한 숫자로 바꿔준다. (+), (-) 허용
*
* @param num
* @return number
*/
function toNormalNum( num ) {
  num = num.replace(/,/g, "");
  var args = Number(num);
	return args;
}

//쿠키 찾기 *******************************************************************
function getCookie(name)
{
	var returnCookie		= "";
	var thisCookie			= document.cookie.split("; ") ;
	for (i = 0; i < thisCookie.length; i++)
	{
		// 쿠키가 발견될때까지 찾기
		if(thisCookie[i].split("=")[0] == name)
			returnCookie	= thisCookie[i].split("=")[1]; // 쿠키를 찾아서"=" 로 분리한후 변수로 저장
	}
	return returnCookie;
}

//인터넷 익스플로러 버전에 다른 모달창 사이즈 조절을 위한 flag
var useragent = navigator.userAgent;
var IE_version = '';
//IE7이 아니고 IE6일때는
if ((useragent.indexOf('MSIE 6') > 0) && (useragent.indexOf('MSIE 7') == -1) && (useragent.indexOf('MSIE 8') == -1)) {
	IE_version = '6';
} else {
	IE_version = '7';
}




//마이크로 사이트 이벤트 팝업
function microEvent(eventNo)
{
	switch(eventNo)
	{
		case 1:
			//window.open("/Front/Event/Micro/201004_TourDeKorea.jsp", "DescenteMicroEvent01", "status=no, resizable=no,scrollbars=yes,width=970,height=700,left=0, top=0")
			window.open("/Front/Event/Micro/201004_TourDeKorea.jsp");
			//location.href="/Front/Media/Media_Gallery/list.jsp";
			break;

	}
}
