function lTrim(inStr) {
	i = 0;
	while ( inStr.substring(i, i+1) == " " || inStr.substring(i, i+1) == "　" ) i = i + 1;
	return inStr.substring(i);
}
function rTrim(inStr) {
	i = inStr.length - 1;
	while ( i >= 0 && (inStr.substring(i, i+1) == " " || inStr.substring(i, i+1) == "　") ) i = i - 1;
	return inStr.substring(0, i+1);
}
function trim(inStr) {
	return lTrim(rTrim(inStr));
}
function isEmpty(inStr) {
	if ( trim(inStr) == "" ) return true;
	return false;
}
function isAlphNum(str){
	var snLength = str.length;
	for ( i = 0 ; i < snLength ; i++){
		charAt = str.substring(i, i+1);
		if( charAt < "0" || ( charAt > "9" && charAt < "A" ) || ( charAt > "Z" && charAt < "a" ) || charAt > "z" ){
			return false;
		}
	}
	return true;
}

function isNum(str){
	var snLength = str.length;
	for( i = 0 ; i < snLength ; i++){
		temp = str.substring(i,i+1);
		if( temp < "0" || temp > "9" ){
			return false;
		}
	}
	return true;
}

function isCurrency(str){
	var snLength = str.length;
	var underDotCnt = 0;
	var dotCnt = 0;
	for( i = 0 ; i < snLength ; i++){
		temp = str.substring(i,i+1);
		if( temp < "0" || temp > "9" ){
			if ( temp == "." ) {
				dotCnt++;
				if ( dotCnt > 1 ) return false;
			} else {
				return false;
			}
		} else {
			if ( dotCnt == 1 ) {
				underDotCnt++;
				if ( underDotCnt > 2 ) return false;
			}
		}
	}
	return true;
}

function isAlph(str){
	var snLength = str.length;
	for ( i = 0 ; i < snLength ; i++){
		charAt = str.substring(i, i+1);
		if( charAt < "A"  || ( charAt > "Z" && charAt < "a" ) || charAt > "z" ){
			return false;
		}
	}
	return true;
}
function isEmail(strEmail){
	var lengthOfEmail = strEmail.length;
	var posOfAt = strEmail.indexOf("@");
	var posOfDot = strEmail.substring(posOfAt+1).indexOf(".") ;

	if( posOfAt < 1 ||  posOfAt > lengthOfEmail -2 || posOfDot < 1 || posOfDot == lengthOfEmail-1)
		return false;

	for( var i = 0 ; i < lengthOfEmail ; i++){
		var comChar = strEmail.charAt(i) ;
        if( comChar == '@' ){
			if( i != posOfAt)
				return false;
	    }else if( comChar == ' ' || comChar == ',' || comChar == ';' ){
	        return false;
	    }
	}
	return true;

}

// sourceVal이 objectVal의 substring인지 check
function isSubString( sourceVal, objectVal){
        var srcLength = sourceVal.length;
        var objLength = objectVal.length;

        for( i = 0 ; i < srcLength - objLength + 1 ; i ++){
                if( sourceVal.substring(i, i+objLength) == objectVal )
                        return true ;
        }
        return false;
}

// 같은 문자가.. sequenceMaxCount이상이면 true리턴.
function isSequenceString(sequenceMaxCount, strVal ){
	if( strVal.length < 1 )
		return false;

        var strLength = strVal.length;
	var beforeChar = strVal.substring(0, 1);
        var sequenceCount = 1 ;
        for( var i = 1 ; i < strLength ; i ++ ){
                if( beforeChar == strVal.substring( i , i+1 )){
                	sequenceCount ++ ;
                        if( sequenceCount >= sequenceMaxCount )
                               return true;
                }
                else{
                	beforeChar = strVal.substring( i, i +1) ;
                        sequenceCount = 1 ;
                }
        }

        return false;
}

function numberFormat(numstr) {
	return numberFormatNew(numstr, false);
}

//숫자입력시 콤마 붙여주기
function numberFormatNew(numstr, resetYn) {
	if ( resetYn )
		numstr = numberFormatReset(numstr);

	var reg = /(^[+-]?\d+)(\d{3})/;
	numstr += "";
	while(reg.test(numstr))
		numstr = numstr.replace(reg, '$1' + ',' + '$2');

	return numstr;
}

//숫자입력시 콤마제거하기
function numberFormatReset(numstr) {
	var price = numstr; // 넘어온 값을 변수에 할당
	var len = numstr.length;  // 넘어온값의 길이를 구함

	for(i=0;i<len;i++) {
		price = price.replace(",","");
	}

	return price;
}

/*************************************************
event가 발생된 위치에 레이어가 그려진다.
margin을 이용하여 left위치를 변경한다.
*************************************************/
function relativLayerFrame(id, _leftMargin, _topMargin){
	var divObj     = document.getElementById(id);

	if(!_leftMargin) {
		_leftMargin = 0;
	}

	if(!_topMargin) {
		_topMargin = 0;
	}

	var vTop  = 0;
	var vLeft = 0;

	vLeft = parseInt(divObj.clientLeft,10) + parseInt(_leftMargin,10)
	vTop = parseInt(divObj.clientTop,10) + parseInt(_topMargin,10) ;

	divObj.style.left   = vLeft + "px";
	divObj.style.top    = vTop + "px";
	divObj.style.display= "block";

}

//오브젝트 절대좌표 구하기
function getAbsolutePos(obj) {
	var position = new Object;
	position.x = 0;
	position.y = 0

	if ( obj ) {
		position.x = obj.offsetLeft;
		position.y = obj.offsetTop;

		if ( obj.offsetParent ) {
			var parentpos = getAbsolutePos(obj.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
		}
	}
	 return position;
}

//신분증번호 유효성 체크 - chinese
function residentNoChk(rNo) {
	if ( isEmpty(rNo) ) return false;
	
	if ( isAlph(rNo.charAt(0)) && rNo.length == 9 ) {
		return true; // for foreigners
	} else {
		if ( rNo.length == 18 ) {
			var chk01 = 0;
			var chk02 = 0;
			var chk03 = "A";
	
			chk01 = parseInt(rNo.substr(0, 1)) * 7 + parseInt(rNo.substr(1, 1)) * 9 +
					parseInt(rNo.substr(2, 1)) * 10 + parseInt(rNo.substr(3, 1)) * 5 +
					parseInt(rNo.substr(4, 1)) * 8 + parseInt(rNo.substr(5, 1)) * 4 +
					parseInt(rNo.substr(6, 1)) * 2 + parseInt(rNo.substr(7, 1)) * 1 +
					parseInt(rNo.substr(8, 1)) * 6 + parseInt(rNo.substr(9, 1)) * 3 +
					parseInt(rNo.substr(10, 1)) * 7 + parseInt(rNo.substr(11, 1)) * 9 +
					parseInt(rNo.substr(12, 1)) * 10 + parseInt(rNo.substr(13, 1)) * 5 +
					parseInt(rNo.substr(14, 1)) * 8 + parseInt(rNo.substr(15, 1)) * 4 +
					parseInt(rNo.substr(16, 1)) * 2;
	
			chk02 = (chk01 % 11);
	
			if ( chk02 == 0 ) chk03 = "1";
			if ( chk02 == 1 ) chk03 = "0";
			if ( chk02 == 2 ) chk03 = "x";
			if ( chk02 == 3 ) chk03 = "9";
			if ( chk02 == 4 ) chk03 = "8";
			if ( chk02 == 5 ) chk03 = "7";
			if ( chk02 == 6 ) chk03 = "6";
			if ( chk02 == 7 ) chk03 = "5";
			if ( chk02 == 8 ) chk03 = "4";
			if ( chk02 == 9 ) chk03 = "3";
			if ( chk02 == 10 ) chk03 = "2";
	
			if ( rNo.substr(17, 1).toLowerCase() == chk03 ) return true;
		} else if ( rNo.length == 15 ) {
			var chk01 = rNo.substr(6, 2);
			var chk02 = rNo.substr(8, 2);
			var chk03 = rNo.substr(10, 2);
	
			if ( chk01 >= "00" && chk01 <= "99" &&
				chk02 >= "01" && chk02 <= "12" &&
				chk03 >= "01" && chk03 <= "31" ) return true;
		}
	}
	return false;
}

//윤년체크
function isLeapYear(yy) {
	 if ( (yy % 4 == 0 && yy % 100 != 0) || yy % 400 == 0 ) return true;
	 return false;
}

//해당월의 총일자 구하기 - mm : 0 ~ 11
function totalDays(yy, mm) {
	var tempDay = new Array( 31,28,31,30,31,30,31,31,30,31,30,31 );

	if ( mm == 1 && isLeapYear(yy) )
		return 29;
	return tempDay[mm];
}

//현재일의 N일 전 날짜 구하기 - YYYYMMDD
function getDateBeforeN(N) {
	var now = new Date();

	var pre_date = now.getTime() - (N * 24 * 60 * 60 * 1000);
	now.setTime(pre_date);

	var beforeYY = now.getFullYear();
	var beforeMM = now.getMonth() + 1;
	var beforeDD = now.getDate();

	beforeMM = "00" + beforeMM;
	beforeMM = beforeMM.substring(beforeMM.length - 2);

	beforeDD = "00" + beforeDD;
	beforeDD = beforeDD.substring(beforeDD.length - 2);

	return beforeYY + beforeMM + beforeDD;
}

//return XML file path for flash
function getXMLPath(menuCode) {
//	alert(menuCode);
	var xmlHome = document.forMenuID.xmlHome.value;
	if ( menuCode == "01" ) {
		return xmlHome + "/xml/navi.xml";
	} else if ( menuCode == "02" ) {
		return xmlHome + "/xml/navi.xml";
	} else if ( menuCode == "03" ) {
		return xmlHome + "/xml/main_event.xml";
	} else if ( menuCode == "04" ) {
		return xmlHome + "/xml/navi.xml";
	} else if ( menuCode == "05" ) {
		return xmlHome + "/xml/main_product.xml?timestamp=" + ((new Date()).getTime());
	} else if ( menuCode == "06" ) {
		return xmlHome + "/xml/centerNavi.htm";
	} else if ( menuCode == "07" ) {
		return xmlHome + "/xml/myzoneNavi.htm";
	} else if ( menuCode == "08" ) {
		return xmlHome + "/xml/communityNavi.htm";
	} else if ( menuCode == "09" ) {
		return xmlHome + "/xml/tvNavi.htm";
	} else if ( menuCode == "10" ) {
		return xmlHome + "/xml/brandShop.xml?timestamp=" + ((new Date()).getTime());
	} else if ( menuCode == "11" ) {
		return xmlHome + "/xml/brandShop2.xml";
	} else if ( menuCode == "12" ) {
		return xmlHome + "/xml/familyBar.xml";
	} else if ( menuCode == "13" ) {
		return xmlHome + "/xml/topLeftNavi.xml";
	} else if ( menuCode == "14" ) {
		return xmlHome + "/xml/indexCategory1.xml?timestamp=" + ((new Date()).getTime());
	} else if ( menuCode == "15" ) {
		return xmlHome + "/xml/indexCategory2.xml?timestamp=" + ((new Date()).getTime());
	} else if ( menuCode == "16" ) {
		return xmlHome + "/xml/quickMenu.htm?timestamp=" + ((new Date()).getTime());
	} else if ( menuCode == "17" ) {
		return xmlHome + "/xml/eventMain.htm";
	}
}

function reSizeNavi(gb, no) {
	if ( gb == '01' ) {
		document.getElementById("main_menu").style.height = no + "px";
	} else 	if ( gb == '02' ) {
		document.getElementById("disp_menu").style.height = no + "px";
	} else	if ( gb == '04' ) {
		document.getElementsByName("category")[0].style.height = no + "px";
	} else	if ( gb == '06' ) {
		document.getElementById("qna_LeftMenu").style.height = no + "px";
	} else	if ( gb == '07' ) {
		document.getElementById("myzone_m").style.height = no + "px";
	} else	if ( gb == '08' ) {
		document.getElementById("community_m").style.height = no + "px";
	} else	if ( gb == '09' ) {
		document.getElementById("tv_menu").style.height = no + "px";
	} else	if ( gb == '16' ) {
		document.getElementById("right_banner").style.height = no + "px";
	}
}

function resetdispNavi() {
	try {
		if ( menuID == "main" || menuID == "disp" ) {
			document.getElementById(fName).resetNavi();
		}
	} catch(e) {
	}
}

function resetmainNavi() {
	try {
		document.getElementById("main_menu").resetNavi();
	} catch (e) {
	}
}
function resetCateNavi() {
	try {
		document.getElementById("category").resetNavi();
	} catch(e){
	}
}


//login
function login() {
	window.top.location.href = HTTP_HOME + "/mall/customer/login.htm";
}

//login from pop
function loginPop() {
	try {
		opener.window.top.location.href = HTTP_HOME + "/mall/customer/login.htm";
		opener.focus();
	} catch ( exception ) {
		// do Nothing... : has no opener
	}
	self.close();
}

//logout
function logout() {
	window.top.location.href = HTTP_HOME + "/mall/customer/logout.htm";
}

//password change pop
function changeMyPwd() {
	var popprop = "scrollbars=no, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open(HTTP_HOME + "/mall/myzone/changeMyPwd.htm", "changeMyPwd", popprop);
	pop.focus();
}

//increase order qty
function incNumber(obj, label, currencyYn) {
	if ( !chkNumField(obj, label, currencyYn) ) return;
	obj.value = parseInt(obj.value) + 1;
}

//decrease order qty
function decNumber(obj, label, currencyYn) {
	if ( !chkNumField(obj, label, currencyYn) ) return;
	if ( parseInt(obj.value) <= 0 ) return;
	obj.value = parseInt(obj.value) - 1;
}

//order detail pop
function viewOrderDetail(orderNo) {
	f = document.frm;

	f.orderNo.value = orderNo;

	var popprop = "width=100, height=100, scrollbars=yes, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open("", "orderDetail", popprop);

	f.action = HTTP_HOME + "/mall/order/orderDetail.htm";
	f.target = "orderDetail";
	f.method = "post";
	f.submit();

	pop.focus();
}

//delivery pop
function viewDelivery(orderNo, orderGSeq) {
	f = document.frm;

	f.orderNo.value = orderNo;
	f.orderGSeq.value = orderGSeq;

	var popprop = "width=100, height=100, scrollbars=no, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open("", "delivery", popprop);

	f.action = HTTP_HOME + "/mall/order/delivery.htm";
	f.target = "delivery";
	f.method = "post";
	f.submit();

	pop.focus();
}

//review pop
function writeReview(reviewNo, sitemCode) {
	var popprop = "width=100, height=100, scrollbars=yes, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open("/mall/community/review.htm?reviewNo=" + reviewNo + "&itemCode=" + sitemCode, "review", popprop);
	pop.focus();
}

//let pop position center
function setPositionCenter() {
	var LeftPosition = (screen.width) ? (screen.width - popWidth)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height - popHeight)/2 : 0;
	window.moveTo(LeftPosition, TopPosition);
}

//auto fit for small pop
function setSmallCenterPop() {
	var popWidth = document.body.scrollWidth + 10;
	var popHeight = document.body.scrollHeight + 80;
	window.self.resizeTo(popWidth, popHeight);

	var LeftPosition = (screen.width) ? (screen.width - popWidth)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height - popHeight)/2 : 0;
	window.moveTo(LeftPosition, TopPosition);
}

//auto fit for large pop
function setLargeCenterPop() {
	var popWidth = document.body.scrollWidth + 28;
	var popHeight = document.body.scrollHeight + 80;
	window.self.resizeTo(popWidth, popHeight);

	var LeftPosition = (screen.width) ? (screen.width - popWidth)/2 : 0;
    var TopPosition = (screen.height) ? (screen.height - popHeight)/2 : 0;
	window.moveTo(LeftPosition, TopPosition);
}

//updated image viewer
var cnj_img_view = null;
function cnj_win_view(img){
	img_conf1= new Image();
	img_conf1.src=(img);
	cnj_view_conf(img);
}
function cnj_view_conf(img){
	if((img_conf1.width!=0)&&(img_conf1.height!=0)){
		cnj_view_img(img);
	} else {
	funzione="cnj_view_conf('"+img+"')";
	intervallo=setTimeout(funzione,20);
	}
}
function cnj_view_img(img){
	if(cnj_img_view != null) {
		if(!cnj_img_view.closed) { cnj_img_view.close(); }
	}
	cnj_width=img_conf1.width+20;
	cnj_height=img_conf1.height+20;
	str_img="width="+cnj_width+",height="+cnj_height;
	cnj_img_view=window.open(img,"cnj_img_open",str_img);
	cnj_img_view.focus();
	return;
}

function fncViewTv(tvUrl){
	var popprop = "width=600, height=450, scrollbars=no, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open(tvUrl, "tvPop", popprop);
	pop.focus();
}

function goItemDetail(sitemCode) {
	var url = "/mall/disp/itemInfo.htm?itemCode="+sitemCode;
	window.open(url);
	//location.href="/mall/disp/itemInfo.htm?itemCode="+sitemCode ;
}

function userPop(url, wh, hi, pName) {
	var popprop = "width=" + wh + ", height=" + hi + ", scrollbars=auto, resizable=no, status=no, toolbar=no, location=no";
	var pop = window.open(url, pName, popprop);
	pop.focus();
}

function tv_calendar() {
	var today = new Date(); //创建日期对象

	year = today.getYear(); //读取年份

	thisDay = today.getDate(); //读取当前日


	//创建每月天数数组

	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	//如果是闰年，2月份的天数为29天

	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
	daysOfCurrentMonth = monthDays[today.getMonth()]; //从每月天数数组中读取当月的天数

	firstDay = today;//复制日期对象

	firstDay.setDate(1); //设置日期对象firstDay的日为1号

	startDay = firstDay.getDay(); //确定当月第一天是星期几


	//定义周日和月份中文名数组

	var dayNames = new Array("SUMDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
	//创建日期对象

	var newDate = new Date();

	var calendarStr = "";

	//创建表格
	calendarStr += "<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0' ALIGN='CENTER' WIDTH='209' HEIGHT='161' STYLE='BACKGROUND:URL(http://image.ttcjmall.com/images/zh/tv/page_201010/tv_calendar_bg.jpg);' >";
	calendarStr += "<TR><TD ALIGN='CENTER' style='padding:0 10px 0 10px;'><TABLE border='0' cellspacing='0' cellpadding='0' align='center' width='189px' height='140px'>";
	calendarStr += "<TR align='left' valign='top' ><TH colspan='7' align='left' STYLE='padding:0 0 7px 0;'><TABLE border='0'><TR><TH align='left'>";

	//显示当前日期和周日

	calendarStr += "<FONT STYLE='font-size:21pt;Color:#fc0083;'>" + (newDate.getMonth()+1) + "</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH><TH>";
	calendarStr += "<FONT STYLE='font-size:9pt;Color:#fc0083;'>" + newDate.getYear() + "</FONT></TH><TH align='right'>";
	calendarStr += "<FONT STYLE='font-size:9pt;Color:#f4a3cd;'>" + dayNames[newDate.getDay()] + "</FONT></TH></TR></TABLE>";

	
	//显示月历表头

	calendarStr += "</TH></TR><TR>";

	//显示每月前面的"空日"

	column = 0;
	for (i=0; i<startDay; i++) {
	calendarStr += "<TD><FONT STYLE='font-size:9pt'> </FONT></TD>";
	column++;
	}

	//如果是当前日就突出显示(红色)，否则正常显示(黑色)
	
	for (i=1; i<=daysOfCurrentMonth; i++) {
		var nowDay = new Date(newDate.getYear(),(newDate.getMonth()+1),i).getDay();
		var nowDateYMD = "";
		if((newDate.getMonth()+1)<10){
			nowDateYMD = newDate.getYear() + "0" + (newDate.getMonth()+1);
		}else{
			nowDateYMD = newDate.getYear() + "" + (newDate.getMonth()+1);
		}
		if(i<10){
			nowDateYMD += "0" + i;
		}else{
			nowDateYMD += "" + i;
		}
		
		if (i == thisDay || nowDay == 0) {
			calendarStr += "<TD ALIGN='CENTER'><a href='javascript:fncTvScheduleSrch(\"" + nowDateYMD + "\");' ><FONT STYLE='font-size:8pt;font-weight:bold;Color:#fc0083'>";
		}else if(nowDay == 6){
			calendarStr += "<TD ALIGN='CENTER'><a href='javascript:fncTvScheduleSrch(\"" + nowDateYMD + "\");' ><FONT STYLE='font-size:8pt;font-weight:bold;Color:#10a548'>";
		}else {
			calendarStr += "<TD ALIGN='CENTER'><a href='javascript:fncTvScheduleSrch(\"" + nowDateYMD + "\");' ><FONT STYLE='font-size:8pt;font-family:Arial;font-weight:bold;Color:#000000'>";
		}
		
		calendarStr += i;
		calendarStr += "</a></FONT></TD>";
		column++;
		if (column == 7) {
		calendarStr += "</TR><TR>";
		column = 0;
		}
	}

	//显示当前时间

	calendarStr += "</TR></TABLE></TD></TR></TABLE>";

	document.write(calendarStr);
}
