//alert(top.location.pathname);

var regId = /^[a-zA-Z]{1}[a-zA-Z0-9_-]{1,20}$/;		// 아이디

var regPhone =/^[0-9]{2,4}-[0-9]{3,4}-[0-9]{3,4}$/; 
var regMail =/^[_a-zA-Z0-9-]+@[.a-zA-Z0-9-]+\.[a-zA-Z]+$/; 
var regEmailId = /^[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+)*$/;		// 이메일 아이디
var regEmailDomain =/^[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*$/;		// 이메일 도메인
//var regEmailId = /^[a-z0-9]{1}[a-z0-9_-]{2,20}$/;		// 이메일 아이디
//var regEmailDomain =/^[a-z0-9\-]+(\.[a-z]+)+$/;		// 이메일 도메인

var regDomain =/^[.가-힣a-zA-Z0-9]+.[a-zA-Z\./@~?&=_]+$/;		// 도메인
var regHost =/^[a-zA-Z-]+$/;									// 호스트

var regSearch = /[가-힣a-zA-Z!@#\$%^&\*]/;		// 검색어

var regNum =/^[0-9]+$/; 
var regAlpha =/^[a-zA-Z]+$/;									// 영문
var regHangul =/[가-힣]/;										// 한글
var regHangulEng =/[가-힣a-zA-Z]/;						// 한글영문
var regHangulOnly =/^[가-힣]*$/;								// 한글만

var regDate =/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;			// 날짜

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1; // 브라우저 종류

/*=============================================================================* 
 * 앞뒤 공백을 제거한다.
 * 
 * param : sVal
 *
 * return : String
 *============================================================================*/
function Trim(sVal)
{
  return(LTrim(RTrim(sVal)));
}

/*=============================================================================*
 * 앞 공백을 제거한다.
 * 
 * param : sVal
 *
 * return : String
 *============================================================================*/
function LTrim(sVal)
{
  var i;
  i = 0;
  while (sVal.substring(i,i+1) == ' ')
  {
    i++;
  }
  return sVal.substring(i);
}

/*=============================================================================* 
 * 뒤 공백을 제거한다.
 * 
 * param : sVal
 *
 * return : String
 *============================================================================*/
function RTrim(sVal)
{
  var i = sVal.length - 1;
  while (i >= 0 && sVal.substring(i,i+1) == ' ') 
  {
    i--;
  }
  return sVal.substring(0,i+1);
}

function chkPatten(fieldvalue, patten) 
{
	patten = eval(patten); 
	if(!patten.test(fieldvalue)){ 
		return false; 
	} 
	return true; 
}

/*=============================================================================*
 * 한글을 2바이트 씩 계산하여 입력받은 문자열이 DB에 저장될 때 총 몇바이트를 차지하는지 계산한다.
 * 엔터(\r\n)는 2바이트를 차지한다.
 * @param val : 입력받은 문자열
 *============================================================================*/
function cal_length(val)
{
  // 입력받은 문자열을 escape() 를 이용하여 변환한다.
  // 변환한 문자열 중 유니코드(한글 등)는 공통적으로 %uxxxx로 변환된다.
  var temp_estr = escape(val);
  var s_index   = 0;
  var e_index   = 0;
  var temp_str  = "";
  var cnt       = 0;

  // 문자열 중에서 유니코드를 찾아 제거하면서 갯수를 센다.
  while ((e_index = temp_estr.indexOf("%u", s_index)) >= 0)  // 제거할 문자열이 존재한다면
  {
	temp_str += temp_estr.substring(s_index, e_index);
	s_index = e_index + 6;
	cnt ++;
  }

  temp_str += temp_estr.substring(s_index);

  temp_str = unescape(temp_str);  // 원래 문자열로 바꾼다.
 
  // 유니코드는 2바이트 씩 계산하고 나머지는 1바이트씩 계산한다.
  return ((cnt * 2) + temp_str.length) + "";
}

function btnSearch_Click() {
	var doc = document.frmSearch;
	var keyword = doc.keyword.value;

	if (keyword.length < 2 || keyword.length > 100) {
		alert("검색어는 2자이상, 100자이내로 입력하세요.");
		doc.keyword.focus();
		doc.keyword.select();
		return false;
	}

	var SearchPattenChk = chkPatten(keyword, regSearch);
	if (!SearchPattenChk) {
		alert("입력하신 검색어는 유효하지 않습니다.\r\n검색 가능한 특수문자는 !@#$%^&* 입니다.");
		doc.keyword.focus();
		doc.keyword.select();
		return false;
	}
}

function btnLogin_Click() {
	var doc = document.frmLogin;

	var UsrId = Trim(doc.txtUSRID.value);
	if (UsrId == "") {
		alert("아이디를 입력 하세요.");
		doc.txtUSRID.focus();
		return false;
	} else {
		if (UsrId.length > 50) {
			alert("이메일은 50자이내로 입력하세요.");
			doc.txtUSRID.focus();
			doc.txtUSRID.select();
			return false;
		}

		var EmailPattenChk = chkPatten(UsrId, regMail);
		if (!EmailPattenChk) {
			alert("이메일 형식이 올바르지 않습니다.");
			doc.txtUSRID.focus();
			doc.txtUSRID.select();
			return false;
		}
	}

	var password = Trim(doc.txtPASS.value);
	if (password == "") {
		alert("비밀번호를 입력하세요.");
		doc.txtPASS.focus();
		return false;
	}
}

function Cartoon_Delete(url) {
	if (confirm("정말 삭제하시겠습니까?")){
		location.href = url;
	}
}

// 발툰 실행
function BaltoonApp_Open() {
	var tmp1 = document.frmTT.v1.value;
	if (tmp1 == "") {
		location.href = "/login/loglog_m_d01.php";
	} else {
		var FilePath = "/common/launchBaltoon.php";
		var BaltoonApp = window.open(FilePath,'baltoonapp','left=10, top=10, width=1000, height=670, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
	}
}

function BaltoonApp_Open2() {
	var tmp1 = document.frmTT.v1.value;
	if (tmp1 == "") {
		location.href = "/login/loglog_m_d01.php";
	} else {
		var FilePath = "/common/launchBaltoon2.php";
		var BaltoonApp = window.open(FilePath,'baltoonapp','left=10, top=10, width=1000, height=670, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
	}
}

// 발툰 체험하기 창 오픈
function Guest_BaltoonApp_Open() {
	var FilePath = "/customer/expe_list_01.php";
	var GuestBaltoon = window.open(FilePath,'baltoonappguest','left=10, top=10, width=860, height=670, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=no, resizable=no');
}

// 발툰 체험하기 실행
function Guest_BaltoonApp_Exe(AppURL) {
	var FilePath = AppURL;
	var GuestBaltoonExe = window.open(FilePath,'baltoonappguestexe','left=10, top=10, width=1000, height=670, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
}

// 이벤트 발툰 실행
function Story_BaltoonApp_Exe(story) {
	var FilePath = "/common/launchBaltoon.php?story="+story;
	var EventBaltoonExe = window.open(FilePath,'baltoonappguestexe','left=10, top=10, width=1000, height=670, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
}

function clearbg(id) {
	document.getElementById(id).style.background="#efefef";
}

function btnManagak_Click() {
	var FilePath = "sertot_p_d01.php";
	var ManagakRegister = window.open(FilePath,'managakregister','left=300, top=300, width=400, height=175, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
}

function loginpage_load() {
	location.href = "/login/loglog_m_d01.php";
}

/*======================================================================================*/

// 좌우 슬라이딩

var func=null;
var tOBJ=null;
var SlidingLayer =	function(element)
{
	this.OBJ						= document.getElementById(element);

	this.arrayOBJ					= document.getElementById('chBestData[1]');


	this.wrapperWidth				= this.OBJ.parentNode.style.width;
	this.containerWidth				= 204;
	this.visibleDataCnt				= 3;
	this.visibleDataWidth			= this.containerWidth / this.visibleDataCnt;
	this.containedData 				= new Array();
	this.move 							= this.visibleDataWidth * this.visibleDataCnt;									 

	for (var i = 0; i < this.OBJ.childNodes.length; i++) {
		if (this.OBJ.childNodes[i].nodeType == 1){
			this.containedData.push(this.OBJ.childNodes[i]);
		}
	}
	this.OBJ.style.width			= (this.visibleDataWidth * this.containedData.length)+"px";
	this.OBJ.style.left				= 0+"px";
	this.width							= parseInt(this.OBJ.style.width);
	this.left								= parseInt(this.OBJ.style.left);
}

SlidingLayer.prototype.goLeft = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJ=evt.target}
	else{tOBJ=evt.srcElement}					 	
	
	func= tOBJ.onclick;
	tOBJ.onclick=null;
	var move = this.move;	
	var i= null;
	var left = parseInt(this.OBJ.style.left);

	//alert(move);
	//alert(left);

	if( this.width - move  + left < move){move= this.width - move + left;}

	for(i=0;i<move;i++)
	{	
		setTimeout("chBestSlider.slide('left');",i/3);
	}

	setTimeout("setEvent();",i/3); 	
}

SlidingLayer.prototype.goRight = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJ=evt.target}
	else{tOBJ=evt.srcElement}					 	
	
	func= tOBJ.onclick;
	tOBJ.onclick=null;
	var move = this.move;	
	var left = parseInt(this.OBJ.style.left);
	if( -left < move){move = -left;}

	for(i=0;i<move;i++)
	{					
		setTimeout("chBestSlider.slide('right');",i/3);
	}
	setTimeout("setEvent();",i/3); 			
}


SlidingLayer.prototype.slide 	= function(direction)
{
	var move;
	if(direction=='left'){move=-1;}
	else{move=1;}
	this.OBJ.style.left=(parseInt(this.OBJ.style.left) + move) +"px";								 
}	 	

var setEvent = function (){tOBJ.onclick=func;}	

/*======================================================================================*/
/* Object 태그 삽입 */

var ActiveObjSrc;

function addActiveObject(objName, objSrc) {
  var tmpObj;

  tmpObj = eval("document.getElementById('"+objName+"')");
  tmpObj.innerHTML = "" + objSrc + "";
}

/*======================================================================================*/
/* 카툰 이미지 주소 복사 */

function ctrl_c(objid) {
    var range, obj;

    obj = document.getElementById(objid);
    obj.select();
	
	if ( !document.all ) {
        //alert("파이어폭스는 지원하지 않습니다.\r\n키보드에서 Ctrl+c 를 누르면 복사됩니다.");
		alert("파이어폭스는 지원하지 않습니다.");
    } else {
		range = obj.createTextRange();
		range.execCommand("Copy")

		alert("클립보드에 복사되었습니다. ctrl+v를 눌러 붙여넣기 하세요.");
	}

	obj.focus();
	obj.select();

	return;
}

/*======================================================================================*/
/* 휴대폰 전송 창 오픈 */

function Mobile_Transfer(no) {
	var FilePath = "../common/mobile_transfer.php?no="+no;
	var MobileTransfer = window.open(FilePath,'mobiletransfer','left=300, top=300, width=400, height=190, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
}




/*======================================================================================*/
// 메인 화면 좌우 슬라이딩

var funcMain=null;
var tOBJMain=null;
var SlidingLayerMain =	function(element)
{
	this.OBJ						= document.getElementById(element);

	this.arrayOBJ					= document.getElementById('chBestData[1]');


	this.wrapperWidth				= this.OBJ.parentNode.style.width;
	this.containerWidth				= 622;
	this.visibleDataCnt				= 5;
	this.visibleDataWidth			= this.containerWidth / this.visibleDataCnt;
	this.containedData 				= new Array();
	this.move 							= this.visibleDataWidth * this.visibleDataCnt;

	for (var i = 0; i < this.OBJ.childNodes.length; i++) {
		if (this.OBJ.childNodes[i].nodeType == 1){
			this.containedData.push(this.OBJ.childNodes[i]);
		}
	}
	this.OBJ.style.width			= (this.visibleDataWidth * this.containedData.length)+"px";
	this.OBJ.style.left				= 0+"px";
	this.width							= parseInt(this.OBJ.style.width);
	this.left								= parseInt(this.OBJ.style.left);
}

SlidingLayerMain.prototype.goLeft = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJMain=evt.target}
	else{tOBJMain=evt.srcElement}					 	
	
	funcMain= tOBJMain.onclick;
	tOBJMain.onclick=null;
	var move = this.move;	
	var i= null;
	var left = parseInt(this.OBJ.style.left);

	//alert(move);
	//alert(left);

	if( this.width - move  + left < move){move= this.width - move + left;}

	for(i=0;i<move;i++)
	{	
		setTimeout("chBestSlider.slide('left');",i/3);
	}

	setTimeout("setEventMain();",i/3); 	
}

SlidingLayerMain.prototype.goRight = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJMain=evt.target}
	else{tOBJMain=evt.srcElement}					 	
	
	funcMain= tOBJMain.onclick;
	tOBJMain.onclick=null;
	var move = this.move;	
	var left = parseInt(this.OBJ.style.left);
	if( -left < move){move = -left;}

	for(i=0;i<move;i++)
	{					
		setTimeout("chBestSlider.slide('right');",i/3);
	}
	setTimeout("setEventMain();",i/3); 			
}


SlidingLayerMain.prototype.slide 	= function(direction)
{
	var move;
	if(direction=='left'){move=-1;}
	else{move=1;}
	this.OBJ.style.left=(parseInt(this.OBJ.style.left) + move) +"px";								 
}	 	

var setEventMain = function (){tOBJMain.onclick=funcMain;}	

// 로그인한 회원의 통계정보를 원격요청하고 레이어에 출력한다.
function User_Active_Step1() {
	var ActiveInfoTimeoutID = null;
	var RequestUrl = "../common/cartoon_total_info.php?id="+activeuseremail;

	if (blnRequestsState2) {
		var ReturnValue = AjaxUpdate("GET", RequestUrl, true, "");
	}

	if (result != "") {
		if (ActiveInfoTimeoutID) {
			clearTimeout(ActiveInfoTimeoutID);
		}

		document.getElementById("ActiveInfo").innerHTML = result;

		blnRequestsState2 = true;
		result = "";

		User_Active_Step2();
	} else {
		blnRequestsState2 = false;
		ActiveInfoTimeoutID = setTimeout("User_Active_Step1()", 50);
	}
}

// 로그인한 회원의 랭킹과 호응도를 원격요청하고 출력한다.
function User_Active_Step2() {
	var RankTimeoutID = null;
	var RequestUrl = "../common/cartoon_view_rank.php?id="+activeuseremail;

	if (blnRequestsState2) {
		var ReturnValue = AjaxUpdate("GET", RequestUrl, true, "");
	}

	if (result != "") {
		if (RankTimeoutID) {
			clearTimeout(RankTimeoutID);
		}

		blnRequestsState2 = true;

		User_ActiveInfo_Display(); // 랭킹 및 호응도 출력
	} else {
		blnRequestsState2 = false;
		RankTimeoutID = setTimeout("User_Active_Step2()", 50);
	}
}

function User_ActiveInfo_Display() {
	var RankDisplayTimeoutID = null;

	if (result != "" || loofcnt > 100) {
		if (RankDisplayTimeoutID) {
			clearTimeout(RankDisplayTimeoutID);
		}

		if (result != "") {
			document.getElementById("ActiveRankArea").innerHTML = result;
		}

		result = "";
		loofcnt = 1;
	} else {
		loofcnt++;
		RankDisplayTimeoutID = setTimeout("UserRankDisplay()", 50);
	}
}


function LockF5(){
	if (event.keyCode == 116) {
		event.keyCode = 0;
		return false;
	}
}


/*======================================================================================*/

// 좌우 슬라이딩

var funcSerial=null;
var tOBJSerial=null;
var SlidingLayerSerial =	function(element)
{
	this.OBJ						= document.getElementById(element);

	this.arrayOBJ					= document.getElementById('chBestData[1]');


	this.wrapperWidth				= this.OBJ.parentNode.style.width;
	this.containerWidth				= 560;
	this.visibleDataCnt				= 5;
	this.visibleDataWidth			= this.containerWidth / this.visibleDataCnt;
	this.containedData 				= new Array();
	this.move 							= this.visibleDataWidth * this.visibleDataCnt;

	for (var i = 0; i < this.OBJ.childNodes.length; i++) {
		if (this.OBJ.childNodes[i].nodeType == 1){
			this.containedData.push(this.OBJ.childNodes[i]);
		}
	}
	this.OBJ.style.width			= (this.visibleDataWidth * this.containedData.length)+"px";
	this.OBJ.style.left				= 0+"px";
	this.width							= parseInt(this.OBJ.style.width);
	this.left								= parseInt(this.OBJ.style.left);
}

SlidingLayerSerial.prototype.goLeft = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJSerial=evt.target}
	else{tOBJSerial=evt.srcElement}					 	
	
	funcSerial= tOBJSerial.onclick;
	tOBJSerial.onclick=null;
	var move = this.move;	
	var i= null;
	var left = parseInt(this.OBJ.style.left);

	//alert(move);
	//alert(left);

	if( this.width - move  + left < move){move= this.width - move + left;}

	for(i=0;i<move;i++)
	{	
		setTimeout("chBestSlider.slide('left');",i/3);
	}

	setTimeout("setEventSerial();",i/3); 	
}

SlidingLayerSerial.prototype.goRight = function(evt)
{
	var evt = (evt) ? evt : ((window.event) ? window.event : null);	
	if(evt.target){tOBJSerial=evt.target}
	else{tOBJSerial=evt.srcElement}					 	
	
	funcSerial= tOBJSerial.onclick;
	tOBJSerial.onclick=null;
	var move = this.move;	
	var left = parseInt(this.OBJ.style.left);
	if( -left < move){move = -left;}

	for(i=0;i<move;i++)
	{					
		setTimeout("chBestSlider.slide('right');",i/3);
	}
	setTimeout("setEventSerial();",i/3); 			
}


SlidingLayerSerial.prototype.slide 	= function(direction)
{
	var move;
	if(direction=='left'){move=-1;}
	else{move=1;}
	this.OBJ.style.left=(parseInt(this.OBJ.style.left) + move) +"px";								 
}	 	

var setEventSerial = function (){tOBJSerial.onclick=funcSerial;}	

/*======================================================================================*/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}