//전역변수 선언
//var SERVER_URL="http://www.pongdang.com";
var SERVER_URL="http://report.mappers.kr/";


function returnObject(frmIndex,eleIndex,errMessage){
	if(errMessage!='')
		alert(errMessage);
	document.forms[frmIndex].elements[eleIndex].focus();
}

function submitFrm(frmIndex){
	document.forms[frmIndex].submit();
}

function checkAll(frmIndex){
	var totalCount=document.forms[frmIndex].chkID.length;	
	if(totalCount>1){
		if(document.forms[frmIndex].chkID[0].checked){
			for(i=0;i<totalCount;i++){
				document.forms[frmIndex].chkID[i].checked=false;
			}
		}else{
			for(i=0;i<totalCount;i++){
				document.forms[frmIndex].chkID[i].checked=true;
			}
		}
	}else{
		if(document.forms[frmIndex].chkID.checked)
			document.forms[frmIndex].chkID.checked=false;
		else
			document.forms[frmIndex].chkID.checked=true;
	}
	return;
}

function checkAllS(frmIndex){
	var totalCount=document.forms[frmIndex].chkID.length;
	var nChkID;
	if(totalCount>1){
		if(document.forms[frmIndex].CACheckBox.checked){
			for(i=0;i<totalCount;i++){
				nChkID=document.forms[frmIndex].chkID[i];
				if(nChkID.disabled==true){
					nChkID.checked=false;
				}else{
					nChkID.checked=true;
				}
			}
		}else{
			for(i=0;i<totalCount;i++){
				nChkID=document.forms[frmIndex].chkID[i];
				nChkID.checked=false;
			}
		}
	}else{
		if(document.forms[frmIndex].CACheckBox.checked){
			nChkID=document.forms[frmIndex].chkID;
			if(nChkID.disabled==true){
				nChkID.checked=false;
			}else{
				nChkID.checked=true;
			}
		}else{
			document.forms[frmIndex].chkID.checked=false;
		}
	}
	return;
}

function movePage(mPage,sURL){
	setValue();
	document.actFrm.action=sURL;
	document.actFrm.nowPage.value=mPage;
	document.actFrm.submit();
}

function chkMove(mPage,totalPage,sURL){
	if(mPage.value==''){
		alert("페이지 번호를 입력해 주세요");
		mPage.focus();
		return;
	}
	if(mPage.value*1>totalPage*1){
		alert("이동하려는 페이지 범위를 넘어섰습니다");
		mPage.focus();
		return;
	}
	setValue();
	document.actFrm.action=sURL;
	document.actFrm.nowPage.value=mPage.value;
	document.actFrm.submit();
}

function openWin(oURL,wwidth,wheight,pName){	//스크롤바 있는 새창
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=yes,resizable=yes,menubar=no,status=no,toolbar=no,location=no");
}
function openWinNR(oURL,wwidth,wheight,pName){	//스크롤바 있는 새창, 크기조절 불가능
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=yes,resizable=no,menubar=no,status=no,toolbar=no,location=no");
}
function openWinS(oURL,wwidth,wheight,pName){	//스크롤바 없음
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=no,resizable=yes,menubar=no,status=no,toolbar=no,location=no");
}
function openWinSNR(oURL,wwidth,wheight,pName){	//스크롤바 없음 크기조절 불가능 새창 띄운다
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=no,resizable=no,menubar=no,status=no,toolbar=no,location=no");
}


function openWinFullScreen(oURL,wwidth,wheight,pName){	//스크롤바 없음 크기조절 불가능 새창 띄운다
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=no,resizable=no,menubar=no,status=no,toolbar=no,location=no,fullscreen");
}


function openWinSTheme(oURL,wwidth,wheight,pName){
	var popName;
	if(pName&&pName!=""){
		popName=pName;
	}else{
		popName="popWindow";
	}
	window.open(oURL,popName,"left=0,top=0,width="+wwidth+",height="+wheight+",scrollbars=yes,resizable=no,menubar=no,status=no,toolbar=no,location=no");
}
function dataClear(i){
	opener.document.actFrm.applyData1.value='';
	opener.document.actFrm.applyData2.value='';
	opener.document.actFrm.applyData3.value='';
	opener.document.actFrm.applyData4.value='';
	opener.document.actFrm.applyType[i].checked=true;
}


// for Publishing Tool
function OpenWin(URL,WinName,x,y,Menu,cSize,scroll) 
{
	var features;
	
	var nTop = (screen.height - y) / 2 - 30;
	var nLeft = (screen.width - x) / 2;
	
	if (Menu == 0 )
		features = "toolbar=no,width=" + x + ",height=" + y + ",top=" + nTop + ",left=" + nLeft + ",status=no,menubar=no";
	else
		features = "toolbar=no,width=" + (x + 18) + ",height=" + y + ",top=" + nTop + ",left=" + nLeft + ",status=no,menubar=yes";
	
	if (cSize == 0)
		features = features + ",resizable=no";
	else
		features = features + ",resizable=yes";
	
	if (scroll == 0 )
		features = features + ",scrollbars=no";
	else
		features = features + ",scrollbars=yes";
	
	//alert(features);
	
	TheWindow = window.open(URL, WinName, features);
}


//-----------------------------------------------------------------------------------------
// 달력 팝업창 출력 관련 함수
//-----------------------------------------------------------------------------------------
var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
var doc = (ie)? document.all : document;

function callCalendar(datetime,field){
		dateField = field;
		__showCalendarPanel(datetime,'::');
} 

function __showCalendarPanel(type, param, title, x, y)
{
		if(param == null){
			alert("Javascript:__showCalendarPanel: You must specify the parameter");
			return;
		}
		var separator = ":";
		var pa = param.split(separator);
		
		if(pa.length != 3)	//<= 1 || (pa[0].length <= 0 && pa[1].length <= 0)) 
		{
			alert("Javascript:__showCalendarPanel: You must specify INPUT objects name to be set to local datetime or GMT one");
			return;
		}

		var left = 100;
		var top = 200;
		if(x != null) left = x;
		if(y != null) top = y;
		
		var url = "/include/common/calendar.asp?type=" + type + "&objLocalDate=" + pa[0] + "&objGMTDate=" + pa[1] + "&initDateTime=" + pa[2] + ( title != null ? "&title=" + title : "");
		var width  = (ie) ? "230":"240";
		if( type == "date" )
			var height = (ie) ? "288":"293";
		else
			var height = (ie) ? "318":"323";
		var ws  = "left=" + left + ",top=" + top + ",menubar = no,width=" + width + ",height=" + height + ",resizable=no,scrollbars=no";
		window.open(url, "__newWin", ws);
}
function setDateTime(local, gmt, type){
	if(type=='date'){
		dateField.value = local.substring(0, 4)
						+ "-" + local.substring(4, 6)
						+ "-" + local.substring(6, 8);
	}
	else{
		dateField.value = local.substring(0, 4)
						+ "-" + local.substring(4, 6)
						+ "-" + local.substring(6, 8)
						+ " " + local.substring(8, 10)
						+ ":" + local.substring(10, 12);
	}

}

function resize_pop() {
	var obj = navigator.appVersion;
	var hei = 29;
	if (navigator.appVersion.indexOf("NT") != -1) {
		os = obj.substr(obj.indexOf("NT"),6);
		if (os > "NT 5.0") {
			hei = 35;
		}
	}
	wid = document.body.scrollWidth+10;
	hei = document.body.scrollHeight+hei+22;
	self.resizeTo(wid,hei);
	this.focus();
}

function login(rurl){
	self.location="/login/login_frm.asp?redirectURL="+escape(rurl);
}

//새창 로그인. targetF에 1을 주면 로그인한 새창에서 다른 페이지로 넘어간다. 아무 인자를 주지 않으면 opener가 새로고침 된다
//url에 아무런 인자를 주지 않으면 페이지를 새로고침 한다
function loginPop(rurl,targetF){
	if(targetF&&targetF!=""){
		openWinS("/login/login_pop.asp?targetF="+targetF+"&redirectURL="+escape(rurl),400,300,"loginPopup");
	}else{
		openWinS("/login/login_pop.asp?redirectURL="+escape(rurl),400,300,"loginPopup");
	}
}

//퐁당가이드를 통한 검색
//출발지,목적지,여행테마,동반자유형,숙박유형
//여행테마 1여행,2레포츠,3비즈니스,4휴식
//동반자유형 1솔로,2가족,3연인,4친구/동료
//숙박유형 1당일,2숙박
function guideSearch(sVal,eVal,type1,type2,type3){
	alert("출발지:"+sVal+" 목적지:"+eVal+" 여행테마:"+type1+" 동반자:"+type2+" 숙박유형:"+type3);
}

//XML 연결을 통하여 해당 텍스트 데이터를 받아온다.
//자바스크립트로 실시간으로 데이터 가져올때 간단하게 사용하자
function getXMLTextData(src){
	var data;
	var url=src;
	var date=new Date();
	//동일한 URL을 보내면 캐싱이 먹어버린다. URL을 바꿔주자
	if(url.indexOf("?")>=0){
		url+="&timeoffset="+date.getTime();
	}else{
		url+="?timeoffset="+date.getTime();
	}
	if(document.implementation && document.implementation.createDocument){
		// XML 변수 로딩
		xmlReq = new XMLHttpRequest();
		// load the xml file
		xmlReq.open("GET", url, false);
		xmlReq.send(null);
		//totalCount = xmlReq.responseXML.getElementsByTagName("POI").length;
		data=xmlReq.responseText;
		return data;
	}else if(window.ActiveXObject){
		// XML 변수 로딩
		xmlReq = new ActiveXObject("MSXML2.XMLHTTP");
		// Load XML
		xmlReq.open("GET", url, false);
		xmlReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=euc-kr");
		xmlReq.send(null);
		//totalCount=xmlReq.responseXML.getElementsByTagName("POI").length;
		data=xmlReq.responseText;
		return data;
	}else{
		// Browser unknown
		return "";
	}
}

function copyToClipboard(name,data){
	window.clipboardData.setData("Text",data);
	alert(name+"가 복사되었습니다");
}

function pause(m){	//m동안 멈추기
	var now=new Date();
	var exitTime=now.getTime()+m;
	while(true){
		now=new Date();
		if(now.getTime()>exitTime)
			return;
	}
}

function ShowProgress(pid) {
	strAppVersion = navigator.appVersion;
				
	if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4) {
		winstyle = "dialogWidth=400px; dialogHeight:150px; center:yes";
		window.showModelessDialog("/include/common/upload_progress.asp?Progressid="+pid,null,winstyle);	  
	}
	else {
		winpos = "left=" + ((window.screen.width-380)/2) + ",top=" + ((window.screen.height-110)/2);
		winstyle="width=400,height=150,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
		window.open("/include/common/upload_progress.asp?Progressid="+pid,null,winstyle);	     
	}
	return true; 
}

function popDetailImageView(file,width,height){
	openWinS("/include/common/pop_image_detail.asp?file="+file,width+30,height+60,'enlageImageWindow');
}
function popDetailImageViewDesc(file,width,height,desc){
	openWinS("/include/common/pop_image_detail.asp?file="+file+"&desc="+desc,width+30,height+60,'enlageImageWindow');
}

function resizeFrame(Id){
	var obj = document.getElementById(Id);
	var Body;
	var H, Min;

	var scroll_height;

	// 최소 높이 설정 (너무 작아지는 것을 방지)
	Min = 500;
	
	// DOM 객체 할당
	try{
		if (!document.all && obj.contentWindow.document.location.href == 'about:blank') {
			setTimeout("resizeFrame('"+Id+"')", 10);
			return;
		}
		Body = obj.contentWindow.document.getElementsByTagName('BODY');
		Body = Body[0];
		if (this.Location != obj.contentWindow.document.location.href) {
			H = Body.scrollHeight + 5;
			obj.style.height =  (H<Min?Min:H) + 'px';
			this.Location = obj.contentWindow.document.location.href;
		}
	} catch(e) {
		setTimeout("resizeFrame('"+Id+"')", 10);
		return;
	}
//	setTimeout("resizeFrame('"+Id+"')", 100);

}

//테마 검색에서 길찾기나 닫기 클릭시 div태그만큼 iframe사이즈를 다시 설정한다.
function resizeFrame_theme(ifr_id,size_check, size){

	var ifr= document.getElementById(ifr_id) ;
	var innerBody = ifr.contentWindow.document.body;
	var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
	//iframe의 height이 변경되었다면 다시 height를 설정한다.
	if (ifr.style.height != innerHeight) 
	{
			ifr.style.height = innerHeight;
	}

}

function getPageSize(){  
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) { //firefox. 스크롤바 생겼을때
		xScroll = document.body.scrollWidth-16;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer,firefox
		windowWidth = self.innerWidth-16;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
  
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){ //firefox
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//내지점 담기 호출
function addUserPOI(pid,name,xpos,ypos,addr){
	openWinS("/search/poi_add_frm.asp?PID="+pid+"&POI_NAME="+escape(name)+"&XPOS="+xpos+"&YPOS="+ypos+"&ADDRESS="+escape(addr),400,300,'poiAddWindow');
}

//엔터를 쳤을 경우 지정된 함수(fName)을 실행한다. 파이어폭스 지원
function enterKeyChk(e,fName){
	var keynum;
	//alert (e);
	//alert (fName);
	if(window.event){
		keynum=e.keyCode;
	}else if(e.which){
		keynum = e.which;
	}
	if(keynum==13){
		eval(fName);
	}
}
