﻿String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.padLeft = function(len, padStr)
{
    var args = arguments;
    var len = args[0];
    
    if( args.length == 1 ) padStr = " ";
    else padStr = args[1];
    var returnString = "";
    var padCnt = Number(len) - String(this).length;
    for(var i=0; i<padCnt; i++) returnString += String(padStr);
    returnString += this;
    return returnString.substring(returnString.length-len);
}

String.prototype.endsWith = function(str)
{ return (this.match(str + "$") == str) }

String.prototype.startsWith = function(str)
{ return (this.match("^" + str) == str) }

function calculateBytes(szValue) {
	var tcount = 0;
	var tmpStr = new String(szValue);
	var temp = tmpStr.length;
	var onechar;
	for (k = 0; k < temp; k++) {
		onechar = tmpStr.charAt(k);
		if (escape(onechar).length > 4) {
			tcount += 2;
		}
		else {
			tcount += 1;
		}
	}
	return tcount;
}

function isNumber(s) {
	// 문자열로 변환
	s += '';
	// 좌우 공백 제거
	s = s.replace(/^\s*|\s*$/g, '');
	if (s == '' || isNaN(s)) return false;
	return true;
}

function AlertNotReady() {
	alert("서비스 준비중입니다");
}

function showHideLayer(layerName) {

	if (document.getElementById(layerName).style.display == "block") {
		document.getElementById(layerName).style.display = "none";
	}
	else {
		document.getElementById(layerName).style.display = "block"
	}
}

function closeLayer(layerName) {
	document.getElementById(layerName).style.display = "none";
}

function cutOffString(str, num, doWrite) {
	var i, sum, title_one;
	var result = "";
	var sumByte = 0;
	if (lengthOfString(str) <= num) {
		if (doWrite) {
			document.write(str);
			return;
		}
		else {
			return str;
		}
	}

	num -= 3;
	for (i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) >= 1000) {
			//영문 또는 숫자
			sumByte += 2;
		}
		else {
			//2Byte문자
			sumByte++;
		}

		if (sumByte > num) {
			break;
		}
		else {
			result += str.substr(i, 1);
		}
	}

	if (doWrite) {
		document.write('' + result + '...' + '');
		return;
	}
	else {
		return '' + result + '...' + '';
	}
}

function lengthOfString(str) {
	var i;
	var sumByte = 0;
	for (i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) < 1000) {
			//영문 또는 숫자
			sumByte++;
		}
		else {
			//2Byte문자
			sumByte += 2;
		}
	}
	return sumByte;
}

function onEnterClickEvent(obj) {
	var enterKey = 13;
	var obj_ID = getObj$(obj);
	if (obj_ID != null) {
		if (event.keyCode == enterKey) {
			obj_ID.focus();
		}
	}
}

function encodeURL(str) {
	var s0, i, s, u;
	s0 = "";                // encoded str

	for (i = 0; i < str.length; i++) {   // scan the source
		s = str.charAt(i);
		u = str.charCodeAt(i);          // get unicode of the char

		if (s == " ") { s0 += "+"; }       // SP should be converted to "+"
		else {
			if (u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))) {       // check for escape
				s0 = s0 + s;            // don't escape
			}
			else {                  // escape
				if ((u >= 0x0) && (u <= 0x7f)) {     // single byte format
					s = "0" + u.toString(16);
					s0 += "%" + s.substr(s.length - 2);
				}
				else if (u > 0x1fffff) {     // quaternary byte format (extended)
					s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
					s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
					s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
					s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
				else if (u > 0x7ff) {        // triple byte format
					s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
					s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
					s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
				else {                      // double byte format
					s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
					s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
				}
			}
		}
	}

	return s0;
}

function isContainsSpecialChars(str) {
	var chars = "'[]`~!@#$%^&*(),:;";

	for (var inx = 0; inx < str.length; inx++) {
		if (chars.indexOf(str.charAt(inx)) != -1) return true;
	}

	return false;
}

function onlyEng(str) {
	var ret;

	for (i = 0; i < str.length; i++) {
		ret = str.charCodeAt(i);
		if ((ret > 122) || (ret < 48) || (ret > 57 && ret < 65) || (ret > 90 && ret < 97)) {
			return false;
		}
	}

	return true;
}


function onPopupWindow(theURL, winName, w, h, scroll, resize) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	var features = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',noresizable';

	if (resize == "yes")
		features = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable'
	var win = window.open(theURL, winName, features)

	if (win == null) {
		alert("팝업창이 차단되었습니다. 팝업창을 허용으로 변경해주세요.");
		return;
	}

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function getRadioValue(obj) {
	var len = obj.length;
	if (!len && obj.checked) {
		return obj.value;
	}

	for (var i = 0, m = obj.length; i < m; i++) {
		if (obj[i].checked) {
			return obj[i].value;
		}
	}
}

/* 세자리마다 콤마 , 기호를 넣은 통화단위 문자열로 변환 */
function convertCurrencyType(val) {
	var szVal = "" + val;
	var Remainder, Share, strtmp

	Share = Math.floor(szVal.length / 3);
	Remainder = (szVal.length) % 3;

	if (Remainder == 0) {
		Remainder = 3;
		Share--;
	}
	strtmp = szVal.substr(0, Remainder);
	for (var i = 0; i < Share; i++) {
		strtmp = strtmp + ",";
		strtmp = strtmp + szVal.substr(3 * i + Remainder, 3);
	}
	return strtmp;
}

//function setCookie(c_name, value) {
//	setCookie(c_name, value, 365);
//}

function setCookie(c_name, value, expiredays) 
{ 
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = c_name + "=" + escape(value) + "; expires=" + todayDate.toGMTString() + "; path=/";
}
function deleteCookie(cookieName) {
    var expireDate = new Date();

    //어제 날짜를 쿠키 소멸 날짜로 설정한다.
    expireDate.setDate(expireDate.getDate() - 1);
    document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}

 


function getCookie(c_name) {
	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;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return null;
}

//rounds the input number to the desired precision
//and returns the rounded number
function roundToPrecision(inputNum, desiredPrecision) {
	var precisionGuide = Math.pow(10, desiredPrecision);
	return (Math.round(inputNum * precisionGuide) / precisionGuide);
}

// 이메일주소 정규식 체크
function checkEmailFormat(email) {
	// 이메일 주소를 판별하기 위한 정규식
	var regExp = /^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-z]{2,5}$/;
	// 인자 email_address를 정규식 format 으로 검색
	return regExp.test(email);
}

// 비밀번호 정규식 체크
function checkPasswordFormat(passwd) {
	var chk1 = /[a-z\d]{4,12}$/i;
	var chk2 = /[a-z]/i;
	var chk3 = /\d/;
	return chk1.test(passwd) && chk2.test(passwd) && chk3.test(passwd);
}

/*************************************************************************
함수명 : containsCharsOnly
기  능 : 특정문자가 존재하는지 체크
인  수 : input, chars - 객체, 찾고자하는 문자
리턴값 : 존재하면 true
**************************************************************************/
function containsCharsOnly(input, chars) {
	for (var inx = 0; inx < input.length; inx++) {
		if (chars.indexOf(input.charAt(inx)) == -1)
			return false;
	}
	return true;
}

function copy_clip(text) {
	if (window.clipboardData) {

		// the IE-manier
		window.clipboardData.setData("Text", text);

		// waarschijnlijk niet de beste manier om Moz/NS te detecteren;
		// het is mij echter onbekend vanaf welke versie dit precies werkt:
	}
	else if (window.netscape) {

		// dit is belangrijk maar staat nergens duidelijk vermeld:
		// you have to sign the code to enable this, or see notes below
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		// maak een interface naar het clipboard
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// maak een transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specificeer wat voor soort data we op willen halen; text in dit geval
		trans.addDataFlavor('text/unicode');

		// om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig om het in op te slaan
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

		var copytext = text;

		str.data = copytext;

		trans.setTransferData("text/unicode", str, copytext.length * 2);

		var clipid = Components.interfaces.nsIClipboard;

		if (!clip) return;

		clip.setData(trans, null, clipid.kGlobalClipboard);

	}
	alert("복사되었습니다. 원하는 곳에 붙여넣기하세요.");
}

//----------------------------공통 끝------------------------------------//


//function onSetCurrentArea(areaSeqNo, redirectUrl) {
//	if (redirectUrl.length > 0)
//		window.location.assign(redirectUrl);
//}


/* html 퍼블리싱 코드 시작 */
// IE6 PNG24
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 '';
}

// Layer View
function layShow(idObj) {
	$(idObj).fadeIn(700);
}
function layHide(idObj) {
	$(idObj).fadeOut(700);
}

// popup View
function popView(pUrl, pName, w, h) {
	var win = window.open(pUrl, pName, "width=" + w + ",height=" + h + ",scrollbars=no");
	if (win == null) {
		alert("팝업창이 차단되었습니다. 팝업창을 허용으로 변경해주세요.");
		return;
	}

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function popView2(pUrl, pName, w, h, left, top) {
	var win = window.open(pUrl, pName, "width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + ",scrollbars=no");
	if (win == null) {
		alert("팝업창이 차단되었습니다. 팝업창을 허용으로 변경해주세요.");
		return;
	}

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function popScroll(pUrl, pName, w, h) {
	var win = window.open(pUrl, pName, "width=" + w + ",height=" + h + ",scrollbars=yes");
	if (win == null) {
		alert("팝업창이 차단되었습니다. 팝업창을 허용으로 변경해주세요.");
		return;
	}

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function popScroll2(pUrl, pName, w, h, left, top) {
	var win = window.open(pUrl, pName, "width=" + w + ",height=" + h + ",left=" + left + ",top=" + top + ",scrollbars=yes");
	if (win == null) {
		alert("팝업창이 차단되었습니다. 팝업창을 허용으로 변경해주세요.");
		return;
	}

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

// popup Close
function popClose() {
	window.close();
}

// tab over
function tabOver(obj) {
	$(obj).hover(
    function() {
    	$(this).attr("src", $(this).attr("src").replace("off.gif", "on.gif"));
    },
    function() {
    	$(this).attr("src", $(this).attr("src").replace("on.gif", "off.gif"));
    }
  )
}

// 레프트 매뉴
function leftHover(a) {
	var b = a - 1;
	var imgObj = document.getElementById("lfNavi").getElementsByTagName("img");
	imgObj[b].src = imgObj[b].src.replace("_off", "_hover");
}

// 탑 매뉴
function topHover(a) {
	var b = a - 1;
	var imgObj = document.getElementById("topNavi").getElementsByTagName("img");

	if (parseInt(b) >= 0) imgObj[b].src = imgObj[b].src.replace("_off", "_on");
}

$(document).ready(function() {
	// 레프트 매뉴
	tabOver("#lfNavi li img");

//	$(".resView").click(function() {
//		alert('b');
//		layHide(".resWrite");
//		layHide(".resComp");
//		$(this).next(".resWrite").fadeIn(700);
//		return false;
//	});
	$(".resHide").click(function() {
		layHide(".resWrite");
		return false;
	});
//	$(".resOk").click(function() {
//		layHide(".resWrite");
//		layHide(".resComp");
//		$(this).parents("td:first").find(".resComp").fadeIn(700);
//		return false;
//	});
//	$(".resCompOk").click(function() {
//		layHide(".resComp");
//		return false;
//	});
	$(".dateWrite .res_cal").click(function() {
		alert('a');
		$(this).next(".calendar").fadeIn(700);
		$(".dateWrite select").hide();
		return false;
	});
//	$(".check_cal1").click(function() {
//		//$(this).next(".calendar:first").fadeIn(700);
//		return false;
//	});
	$(".check_cal2").click(function() {
		$(this).next(".calendar:first").fadeIn(700);
		return false;
	});
	$(".btnClose").click(function() {
		$(this).parents(".calendar").fadeOut(700);
		return false;
	});

	// 결제 수단 변경
	$(".payMethod :radio").click(function() {
		$(".payMethod div").removeClass("pOver");
		$(this).parents("div:first").addClass("pOver");
	});

	//FAQ
	$("#faqList a[href=#]").toggle(
		function() {
			$(this).parents("tr:first").addClass("fActive");
			$(this).parents("tr:first").next("tr").show();
			return false;
		},
		function() {
			$(this).parents("tr:first").removeClass("fActive");
			$(this).parents("tr:first").next("tr").hide();
			return false;
		}
	);

	// 마이페이지
	$("#familyBtn").mouseover(function() {
		layShow("#familyNum");
	});
	$("#familyNum").mouseout(function() {
		layHide("#familyNum");
	})

	// 지난 making
	$("#agoMaking td").hover(
		function() {
			if ($(this).hasClass("soldOut")) {
				$(this).removeClass("soldOut");
				$(this).addClass("aHover");
			}
		},
		function() {
			if ($(this).hasClass("aHover")) {
				$(this).removeClass("aHover");
				$(this).addClass("soldOut");
			}
		}
	);


		// 20110522
		$(".soldOut .sAgoWrap").hover(
		function() {
			$(this).addClass("aHover");
		},
		function() {
			$(this).removeClass("aHover");
		}
	);
		// 201106 지난 making:s
		$("#agoMaking .agdv").hover(
		function() {
			$(this).addClass("agdv_on");
		},
		function() {
			$(this).removeClass("agdv_on");
		}
	);
		// 201106 지난 making:e	
	

	$("#allPlaceWrap li").hover(
		function() {
			if ($(this).attr("class") != "comming") {
				$(this).addClass("apHover");
			}
		},
		function() {

		}
	);

	// 전체지역
	$(".aPlace").click(function() {
		if ($("#allPlace").css("display") == "none") {
			$("#allPlace").fadeTo(700, 0.98);
			onViewEntireAreaTodayMaking(0);
		} else {
			$("#allPlace").fadeOut(700);

		}
		return false;
	});
	$(".closeBTn a").click(function() {
		$("#allPlace").fadeOut(700);
		return false;
	});

	$(".tdRg a").toggle(
		function() {
			var hObj = parseInt($(".topToday ul li").size()) * 21;
			$(".topToday ul").animate({ 'height': hObj }, 200);
			return false;
		},
		function() {
			$(".topToday ul").animate({ 'height': '21' }, 200);
			return false;
		}
	);

	$(".tdLf").parent().toggle(
		function() {
			var hObj = parseInt($(".topToday ul li").size()) * 21;
			$(".topToday ul").animate({ 'height': hObj }, 200);
			return false;
		},
		function() {
			$(".topToday ul").animate({ 'height': '21' }, 200);
			return false;
		}
	);

	$("#allPlaceWrap li").hover(
		function() {
			if ($(this).attr("class") != "comming") {
				$(this).addClass("apHover");
			}
		},
		function() {
			$(this).removeClass("apHover");
		}
	);
	//친구추천 이벤트
	$(".aFriend").click(function() {
	    if ($("#allFriend").css("display") == "none") {
	        $("#allFriend").fadeTo(700, 0.98);
	        //onViewEntireAreaTodayMaking(0);
	    } else {
	        $("#allFriend").fadeOut(700);

	    }
	    return false;
	});
	
	$(".closeFriend a").click(function() {
	    $("#allFriend").fadeOut(700);
	    return false;
	});
});



//------------------------------------------------------------------------
// 주민등록번호의 유효성을 검증
//
//	ARGUMENTS
//		ssn = 대상 주민번호 ( ex. '8010142016147' )
//
//	RETURN
//		boolean
//---------------------------------------------------------------------------*/
function isSSN(ssn) {
	var msg = "올바른 주민등록번호가 아닙니다.";

	if (ssn.length == 13) {

		var str_jumin1 = ssn.substring(0, 6);
		var str_jumin2 = ssn.substring(6);
		var checkImg = '';
		var i3 = 0

		for (var i = 0; i < str_jumin1.length; i++) {
			var ch1 = str_jumin1.substring(i, i + 1);
			if (ch1 < '0' || ch1 > '9') { i3 = i3 + 1; }
		}

		if ((str_jumin1 == '') || (i3 != 0)) {
			alert(msg);
			return false;
		}

		var i4 = 0
		for (var i = 0; i < str_jumin2.length; i++) {
			var ch1 = str_jumin2.substring(i, i + 1);
			if (ch1 < '0' || ch1 > '9') { i4 = i4 + 1 }
		}

		if ((str_jumin2 == '') || (i4 != 0)) {
			alert(msg);
			return false;
		}

		if (str_jumin1.substring(0, 1) < 4) {
			alert(msg);
			return false;
		}

		if (str_jumin2.substring(0, 1) > 4) {
			alert(msg);
			return false;
		}

		if ((str_jumin1.length > 7) || (str_jumin2.length > 8)) {
			alert(msg);
			return false;
		}

		if ((str_jumin1 == '72') || (str_jumin2 == '18')) {
			alert(msg);
			return false;
		}

		var f1 = str_jumin1.substring(0, 1)
		var f2 = str_jumin1.substring(1, 2)
		var f3 = str_jumin1.substring(2, 3)
		var f4 = str_jumin1.substring(3, 4)
		var f5 = str_jumin1.substring(4, 5)
		var f6 = str_jumin1.substring(5, 6)
		var hap = f1 * 2 + f2 * 3 + f3 * 4 + f4 * 5 + f5 * 6 + f6 * 7
		var l1 = str_jumin2.substring(0, 1)
		var l2 = str_jumin2.substring(1, 2)
		var l3 = str_jumin2.substring(2, 3)
		var l4 = str_jumin2.substring(3, 4)
		var l5 = str_jumin2.substring(4, 5)
		var l6 = str_jumin2.substring(5, 6)
		var l7 = str_jumin2.substring(6, 7)
		hap = hap + l1 * 8 + l2 * 9 + l3 * 2 + l4 * 3 + l5 * 4 + l6 * 5
		hap = hap % 11
		hap = 11 - hap
		hap = hap % 10

		if (hap != l7) {
			alert(msg);
			return false;
		}

		return true;
	}

	alert(msg);
	return false;
}
function goSMS() {
    var pdtSeqNo = $("#ctl00_hdnPdtSeqNo").val();
    popView('/Popup/P_MainSendSMS.aspx?PdtSeqNo='+pdtSeqNo, '_blank', 490, 402);
   }
   function goIndex(PdtSeqNo, AreaSeqNo, AreaGrpSeqNo) {
   	//alert(PdtSeqNo);
   	//alert(AreaSeqNo);
   //	alert(AreaGrpSeqNo);
   	setCookie("GNBAreaSeqNo", AreaSeqNo,1);
   	setCookie("GNBAreaGrpSeqNo", AreaGrpSeqNo,1);
   	location.href = "/Index.aspx?PdtSeqNo="+PdtSeqNo;

   }
   function goIndexUrl(Url, AreaSeqNo, AreaGrpSeqNo) {
   	//alert(PdtSeqNo);
   	//alert(AreaSeqNo);
   	//	alert(AreaGrpSeqNo);
   	setCookie("GNBAreaSeqNo", AreaSeqNo, 1);
   	setCookie("GNBAreaGrpSeqNo", AreaGrpSeqNo, 1);
   	location.href = Url;

   }   


/* html 퍼블리싱 코드 끝 */


