/***********************************************************
	Description	: Ajax통신을 위한 HttpRequest를 반환.
	Result			: xmlHttpRequest object
	Parameter
***********************************************************/
var xmlHttp = null;

function getXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(ea) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(eb) {
				return null;
			}
		}
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}

/***********************************************************
	Description	: 화면 (1/2, 1/2 중앙) 팝업창 열기
	Result			: void
	Parameter
		width		: 팝업 넓이 파라미터
		height		: 팝업 높이 파라미터
		url			: 팝업 주소 파라미터
		name		: 팝업 이름 파라미터
		popWidth, popHeight, popUrl, popName : 파라미터 바인딩 변수
		popPosLeft	: Y좌표 (가로위치)
		popPosTop	: X좌표 (세로위치)
		popResult	: 위치지정
***********************************************************/
function openCenterPopUp(width, height, url, name){
	var popWidth 	= width;
	var popHeight 	= height;
	var popURL 		= url;
	var popName 	= name;
	var popPosLeft 	= (screen.width-popWidth)/2;
	var popPosTop 	= (screen.height-popHeight)/2;
	var popResult 	= "width="+popWidth+",height="+popHeight+",top="+popPosTop+",left="+popPosLeft;
	window.open (popURL, popName, popResult + "");
}

/***********************************************************
	Description	: 명시한 필드의 스타일 색상을 변경 (document ID)
	Result			: void
	Parameter
		id		: 색생을 변경할 HTML 태그 ID 명
		color	: 변경 색 (컬러코드)
***********************************************************/
function changeIdColor(id, color){
	document.getElementById(id).bgColor = color;
}

/***********************************************************
	Description	: 쿠키명, 쿠키값 저장
	Result		: void
	Parameter
		name	: 쿠키명
		value	: 쿠키값
***********************************************************/
function setCookie(name, value){
	document.cookie = name+ "=" +escape(value);
}

/***********************************************************
	Description	: 쿠키명, 쿠키값, 만료기간 저장
	Result			: void
	Parameter
		sName			: 쿠키명
		sValue		: 쿠키값
		sExpires	: 만료기간
		dToDate		: 현재시간(만료기간)
		ex) '2000-01-01' = String형 일 경우 해당일을 저장
			  1, 7, 10... = Number형 일 경우 현재일+1, 7, 10... 일을 가산하여 저장
		Excepriont : 만료기간을 제외한 쿠키값을 저장
***********************************************************/
function setExpiresCookie(sName, sValue, sExpires){
	if (typeof(sExpires) == "string"){
		document.cookie = sName+ "=" +escape(sValue)+ ";expires=" +sExpires+ ";";
	}else if (typeof(sExpires) == "number"){
		var dToDate = new Date();
		dToDate.setDate(dToDate.getDate() + sExpires);
		document.cookie = sName+ "=" +escape(sValue)+ ";expires=" +dToDate.toGMTString()+ ";";
	}else{
		document.cookie = sName+ "=" +escape(sValue);
	}
}

/***********************************************************
	Description	: 쿠키명, 쿠키값 출력
	Result			: 쿠키값
	Parameter
		cookie		: document.cookie 오브젝트
		name		: 쿠키명
		sCookieName	: 쿠키명=
		start		: 쿠키값 시작인덱스
		end			: 쿠키값 종료인덱스
		lastCookie	: 마지막 쿠키값 인덱스
***********************************************************/
function getCookie(name){
	var cookie		= document.cookie;
	var sCookieName	= name + "=";
	var start		= 0;
	var end			= 0;
	var lastCookie	= 0;

	while (start <= cookie.length){
		end = start + sCookieName.length;
		if (cookie.substring(start, end) == sCookieName){
			lastCookie = cookie.indexOf(";", end)
			if (lastCookie == -1){
				lastCookie = cookie.length;
			}
			return unescape(cookie.substring(end, lastCookie));
		}
		start = cookie.indexOf(" ", start) + 1;
		if (start == 0){
			break;
		}
	}
	return "Not exist cookie";
}

/***********************************************************
	Description	: 쿠키값 삭제 후 만료기간을 -1로 설정 (쿠키삭제)
	Result		: void
	Parameter
		name	: 쿠키명
		today	: 현재시간(만료기간)
***********************************************************/
function delCookie(name){
	var today = new Date();
	today.setDate(today.getDate() - 1);
	document.cookie = name+ "=" +false+ ";expires=" +today.toGMTString()+ ";";
}


/***********************************************************
	Description	: 플래시 사용 공통 direct 스크립트
	Result		: void
	Parameter
***********************************************************/
function direct(url) {
	document.dirForm.action = url;
	document.dirForm.submit();
}


/***********************************************************
	Description	: 이메일 도메인 셋팅
	Result		: void
	Parameter
***********************************************************/
function setEmailDomain(type) {
	if (type == "stf") {
		var form = document.modForm;

		if (form.stfEmail2.value == "etc") {
			form.stfEmail1.value = "";
			form.stfEmail1.focus();
		} else {
			form.stfEmail1.value = form.stfEmail2.value;
		}
	} else if (type == "ort") {
		var form = document.recruitForm;

		if (form.ortEmail2.value == "etc") {
			form.ortEmail1.value = "";
			form.ortEmail1.focus();
		} else {
			form.ortEmail1.value = form.ortEmail2.value;
		}
	} else if (type == "stf2") {
		var form = document.writeForm;

		if (form.stfEmail2.value == "etc") {
			form.stfEmail1.value = "";
			form.stfEmail1.focus();
		} else {
			form.stfEmail1.value = form.stfEmail2.value;
		}
	} 
}

/***********************************************************
	Description	: 지정된 체크박스를 모두 선택, 모두 해제
	Result			: void
	Parameter
		sFlagfield	: [선택/해제] 전체선택 체크박스 HTML 필드 태그 명
		sCheckbox		: 체크박스 HTML 필드 태그 명
		oFlagfield		: sFlagfield의 document 이름
		oCheckbox		: sCheckbox의 document 이름
		checkYN			: 전체선택/해제 구별자 (Y=전체선택, N=해제)
***********************************************************/
function checkAllCheckBox(sFlagfield, sCheckbox){
	var oFlagfield	 	= document.all[sFlagfield];
	var oCheckbox	 	= document.all[sCheckbox];
	var checkYN		 	= (oFlagfield.checked) ? true : false;

	for (var i=0; i<oCheckbox.length; i++){
		oCheckbox[i].checked = checkYN;
	}
}


/***********************************************************
	Description	: 달력 div를 출력 및 삭제
	Result		: void
	Parameter
***********************************************************/
function showCalendar(id, evnet) {
	calendarFrame.document.calForm.setField.value = id;
	document.getElementById("calendarDiv").style.left = document.body.scrollLeft + event.clientX;
	document.getElementById("calendarDiv").style.top  = document.body.scrollLeft + event.clientY;
	document.getElementById("calendarDiv").style.display = "block";
}
function noneCalendar() {
	document.getElementById("calendarDiv").style.display = "none";
}

function goMain() {
	location.href='/shop/index.asp';
}

/***********************************************************
	Description	: 로그인 경고창 출력
	Result		: void
	Parameter
***********************************************************/
function alertLogin() {
	alert("로그인이 필요합니다.");
	return;
}
