﻿var admin_svr = "http://www.ipalazzo.com/Admin";
var local_svr = "http://www.ipalazzo.com";
var secure_svr = "https://www.ipalazzo.com:446";

//-----------------------------------------------------------------------------
// 플래시 점선없이 띄우기..
// @return : null
// ex) getFlashObject(플래시경로, 넓이, 높이, 전달변수, 플래시이름);
//-----------------------------------------------------------------------------
function getFlashObject(flashSrc, objWidth, objHeight, etcParam, flaName) {
	var tag = "";
	var baseFlashDir="";
	flashSrc = baseFlashDir + flashSrc;

	if ( etcParam != "" || etcParam != null ) {
		if ( etcParam.substr(0, 1) == "?" )
			flashSrc += etcParam;
		else
			flashSrc += "?" + etcParam;
	}

	tag += "<object id=\"" + flaName + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ";
	tag += "codebase=\"" + location.protocol + "//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,12,36\" ";
	tag += "width=\"" + objWidth + "\" height=\"" + objHeight + "\">";
	tag += "<param name=\"movie\" value=\"" + flashSrc + "\">";
	tag += "<param name=\"menu\" value=\"true\">";
	tag += "<param name=\"quality\" value=\"high\">";
	tag += "<param name=\"wmode\" value=\"transparent\">";
	tag += "<param name=\"allowScriptAccess\" value=\"sameDomain\">";
	tag += "<embed name=\"" + flaName + "\" src=\"" + flashSrc + "\" quality=\"high\" pluginspage=\"" + location.protocol + "//www.macromedia.com/go/getflashplayer\" ";
	tag += "type=\"application/x-shockwave-flash\" width=\"" + objWidth + "\" height=\"" + objHeight + "\" ";
//	tag += " allowScriptAccess=\"sameDomain\"></embed>";
	tag += "wmode=\"transparent\" allowScriptAccess=\"sameDomain\"></embed>";
	tag += "</object>";

	document.write(tag);
}

function goURL(url, target){
	var oElement = (target != null) ? target : self;
	oElement.location.href = url;
}

function $(id){
	return document.getElementById(id);
}

//-----------------------------------------------------------------------------
// 텍스트필드 널값체크..
// @return : null
// ex) chkNull(필드, 경고메세지);
//-----------------------------------------------------------------------------
function chkNull(oElement, strMessage){
	if(oElement.value.trim() == ""){
		alert(strMessage + " 입력해주세요.");
		oElement.value = "";
		oElement.focus();
		return true;

	} else{
		return false;
	}
}

//서버객체의 클라이언트 ID 값을 리턴
function returnInputID(inputName){
	var ID = $get(thisClientID + "_" + inputName);
	return ID;
}

//한글만 가능
function onlyKorean() {
	var oElement = (arguments[0] != null) ? arguments[0] : this;
	var charChk;

	for(var i=0; i<oElement.value.length; i++){
		charChk = oElement.value.charCodeAt(i);

		if(charChk > 31 && charChk < 127) {
			alert("공백없이 한글로만 입력해주세요.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
}

//숫자만 가능
function onlyNumber() {
	var oElement = (arguments[0] != null) ? arguments[0] : this;
	var charChk;

	for(var i=0; i<oElement.value.length; i++){
		charChk = oElement.value.charCodeAt(i);

		if(charChk > 57 || charChk < 48){
			alert("공백없이 숫자로만 입력해주세요.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
}

//영문만 가능
function onlyEnglish() {
	var oElement = (arguments[0] != null) ? arguments[0] : this;
	var charChk;

	for(var i=0; i<oElement.value.length; i++){
		charChk = oElement.value.charCodeAt(i);

		if((charChk < 65 || charChk > 90) && (charChk < 97 || charChk > 122)){
			alert("공백없이 영문으로만 입력해주세요.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
}

//숫자와 영문만 가능
function onlyEngNum() {
	var oElement = (arguments[0] != null) ? arguments[0] : this;
	var charChk;

	for(var i=0; i<oElement.value.length; i++){
		charChk = oElement.value.charCodeAt(i);

		if( ((charChk < 65 || charChk > 90) && (charChk < 97 || charChk > 122)) && (charChk > 57 || charChk < 48) ){
			alert("공백없이 영문과 숫자로만 입력해주세요.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
}

//텍스트박스에 원하는 길이만큼 문자열이 채워지면 다음 객체로 포커스 이동
function NextObjectFocus(length, thisObj, nextObj){
	if (thisObj.value.length == length){
		nextObj.focus();
	}
}

// 공백을 제거
function trim(str) {
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

// selectbox의 날짜option을 채움
function fill_calendar() {
	var today = new Date();
	var i_year = today.getFullYear()+1;
	var f = $("aspnetForm");
	
	for (i=i_year - 100;i<i_year;i++)
		f.birthYear.options[f.birthYear.options.length] = new Option(i, i);
	for (i=1;i<13;i++)
		f.birthMonth.options[f.birthMonth.options.length] = new Option(i.toString().digits(2), i.toString().digits(2));
		
	for (i=1;i<32;i++)
		f.birthDay.options[f.birthDay.options.length] = new Option(i.toString().digits(2), i.toString().digits(2));
}

// 오늘날짜 선택
function set_date(y, m, d) {
	var f = $("aspnetForm");
	
	y = parseInt(y);
	//m = parseInt(m);
	//d = parseInt(d);
	
	for (i=0;i<f.birthYear.options.length;i++) {
		if (parseInt(f.birthYear.options[i].value.substring(2,4)) == y) {
			f.birthYear.options[i].selected = true;
			break;
		}
	}
	
	f.birthMonth.value = m;
	f.birthDay.value = d;
	
	/* for (i=0;i<f.birthMonth.options.length;i++) {
		if (parseInt(f.birthMonth.options[i].value) == m) {
			f.birthMonth.options[i].selected = true;
			break;
		}
	}
	
	for (i=0;i<f.birthDay.options.length;i++) {
		if (parseInt(f.birthDay.options[i].value) == d) {
			f.birthDay.options[i].selected = true;
			break;
		}
	}*/
}

// 날짜 자동선택
function reset_calendar(y, m) {
	var is_leap = false;
	var iday = 31;
	var f = $("aspnetForm");
	
	if (((y % 4 == 0) &&
		(y % 100 != 0)) ||
		(y % 400 == 0))
		is_leap = true;
		
	switch (parseInt(m)) {
		case 4:
		case 6:
		case 9:
		case 11:
			iday = 30;
			break;
		case 2:
			iday = is_leap ? 29 : 28;
			break;
		default:
			iday = 31;
			break;
	}
	
	for (i=f.birthDay.options.length;i>=0;i--)
		f.birthDay.options[i] = null;
	
	for (i=1;i<=iday;i++)
		f.birthDay.options[f.birthDay.options.length] = new Option(i.toString().digits(2), i.toString().digits(2));
}

//이메일 형식 확인
function isValid_email( str )
{
     if(str == ""){
     	alert("이메일 주소를 입력하세요.");
     	return false;
     }
     
     if( checkSpace( str ) ) {
         alert("이메일 주소를 빈공간 없이 넣으세요.");
         return false;
     }

     if( -1 == str.indexOf('.') ) {
     	alert("이메일 형식이 잘못 되었습니다.");
        return false;
     }

     /* checkFormat */
     var isEmail = /[-!#$%&'*+\/^_~{}|0-9a-zA-Z]+(\.[-!#$%&'*+\/^_~{}|0-9a-zA-Z]+)*@[-!#$%&'*+\/^_~{}|0-9a-zA-Z]+(\.[-!#$%&'*+\/^_~{}|0-9a-zA-Z]+)*/;
     if( !isEmail.test(str) ) {
         alert("이메일 형식이 잘못 되었습니다.");
         return false;
     }
     if( str.length > 60 ) {
         alert("이메일 주소는 60자까지 유효합니다.");
         return false;
     }

     return true;
}

// space 가 있으면 true, 없으면 false
function checkSpace( str )
{
     if(str.search(/\s/) != -1){
     	return true;
     } else {
        return false;
     }
}

//문자열을 원하는 길이만큼 자른다.
function cutTitle(str, strLen){
	var s = str;
	var len = 0;
	
	for(i=0; i<s.length; i++) {
		if(s.charCodeAt(i)>=0 && s.charCodeAt(i)<=127)
			len++;
		else 
			len += 2;
		
		if (strLen < len){
			s = s.substring(0,i) + "..";
			break;
		}
	}
	return s;
}

//주소창 오픈
function commonZipWindow(returnFunc){
	var func = "";
	if ( returnFunc != null)
		func = returnFunc;
	
	var win = window.open("/Web/ZipSearch.aspx?returnFunc=" + func,"zipSearch","width=480,height=460");
	win.focus();
	
	if (win == null){
		alert("팝업 차단 기능을 사용하시면 이기능을 이용하실 수 없습니다.");
		return;
	}
}


//-----------------------------------------------------------------------------
//	해당 노드의 모든 자식노드를 지운다.
// @return : null
// ex) removeAllNodes(부모노드)
//-----------------------------------------------------------------------------
function removeAllNodes(argElement){
	if(argElement != null){
		if(argElement.childNodes){
			var Len = argElement.childNodes.length;  
			for (i=0; i<Len; i++){
				argElement.removeChild(argElement.childNodes[0]);
			}
		}
	}
}

/* 텍스트 박스 Enter 막기 */
function PreventSubmitOnEnter(){
	if(event.keyCode==13)
		return false;
}

function Load(){
	var inputs = document.getElementsByTagName("INPUT")         
	for(var i = 0; i < inputs.length ; i++){               
		if(inputs[i].type == "text")
			inputs[i].attachEvent("onkeypress", PreventSubmitOnEnter);
	}
}

/*
	문자열 속성
*/
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};


String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

String.prototype.digits = function(cnt) {
	var digit = "";

	if (this.length < cnt) {
		for(var i = 0; i < cnt - this.length; i++) {
			digit += "0";
		}
	}

	return digit + this;
};
		
function resize_parentHeight(obj) {
	var pFrame = eval(obj + ".document.body");
	var iFrame = $(obj);

	iFrame.style.height = pFrame.scrollHeight + (pFrame.offsetHeight - pFrame.clientHeight);
}

function access_denial(){
	alert("이 기능을 이용할 권한이 없습니다.");
	return;
}

function totalSearch(){
	var thisForm = document.forms[0];
	var search = $("TotalSearch");
	
	if (search.value == ""){
		alert("검색어를 입력해 주세요");
		search.focus();
		return;
	}
	
	thisForm.action = "/Web/Etc/Search.aspx";
	thisForm.method = "post";
	thisForm.submit();
}

function enterTotalSearch(){
	if (event.keyCode == 13)
		totalSearch();
	
	return false;
}