//Browser °ËÁõ

if (document.getElementById && !document.all){
	var isNS = true;
	var isIE = false;
} else {
	var isIE = true;
	var isNS = false;
}

//MSIE¿¡¼­ captureEvent¸¦ »ç¿ëÇÒ °æ¿ì È£È¯
if(!window.event && window.captureEvents) {
	// set up event capturing for mouse events (add or subtract as desired)
	window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
	// set window event handlers (add or subtract as desired)
	window.onmouseogover = WM_getCursorHandler;
	window.onmouseout = WM_getCursorHandler;
	window.onclick = WM_getCursorHandler;
	window.ondblclick = WM_getCursorHandler;
	// create an object to store the event properties 
	window.event = new Object;
}

//MSIE¿Í NETSCAPEÀÇ EVENT HANDLER È£È¯
function WM_getCursorHandler(e) {
	// set event properties to global vars (add or subtract as desired)
	window.event.clientX = e.pageX;
	window.event.clientY = e.pageY;
	window.event.x = e.layerX;
	window.event.y = e.layerY;
	window.event.screenX = e.screenX;
	window.event.screenY = e.screenY;
	// route the event back to the intended function
	if ( routeEvent(e) == false ) {
		return false;
	} else {
		return true;
	}
}

// ÀÛ¾÷Áß ÀÌ¹ÌÁö1
var loading = "&nbsp;<span><img src='/images/loading.gif' style='width:15px;height15px;' /><span>";

function a()
{
	alert("test");
}
// ÇÊ¼ö ÀÔ·Â°ª È®ÀÎ
function validateRequired(field) {
    var bValid = false;
    if (field.type == 'text' ||
	    field.type == 'hidden' ||
        field.type == 'textarea' ||
        field.type == 'file' ||
        field.type == 'select-one' ||
        field.type == 'radio' ||
        field.type == 'password') {
        
        var value = '';
		// °ªÀ» °¡Á®¿Â´Ù.
		if (field.type == "select-one") {
			var si = field.selectedIndex;
			if (si >= 0) {
				value = field.options[si].value;
			}
		} else {
			value = field.value;
		}
          
        if (value == '') {
        	alert(field.title + "(À»)¸¦ ÀÔ·ÂÇÏ½Ê½Ã¿À.");
        	if (field.type != 'hidden')
        		field.focus();
        	bValid = false;
        } else {
        	bValid = true;
        }
    }
    return bValid;
}

// ¼Ò½º ÇÊµåÀÇ °ª¿¡¼­ °ø¹éÀ» ¾ø¾Ø µÚ ´ë»ó ÇÊµåÀÇ °ªÀ¸·Î Ä¡È¯ÇÑ´Ù.
function makeShort(src, dest) {
	var str;
	str = src.value;
	str = trim(str);
	dest.value = str;
}

// ¹®ÀÚ¿­ÀÇ °ø¹é Á¦°Å
function trim(str) {
	var len, index;
	if (str.length > 0) {
		while(true){
			index = str.indexOf(" ");
			if (index == -1) break;
			len = str.length;
			str = str.substring(0, index) + str.substring((index+1),len);
		}
	}
	return str;
}
function ltrim(str) {
	var len, index;
	if (str.length > 0) {
		while(true){
			index = str.indexOf(" ");
			if (index != 0) break;
			len = str.length;
			str = str.substring(0, index) + str.substring((index+1),len);
		}
	}
	return str;
}
// ¼ýÀÚ ¿©ºÎ È®ÀÎ
function isNumber(obj) {
	if (isNaN(obj.value)) {
		alert("¼ýÀÚ¸¸ ÀÔ·ÂÇÏ½Ê½Ã¿À.");
		obj.select();
		return false;
	}
	return true;
}

 // Email Check
  function isEmailAddress(strEmail, strName)
 {
     var regDoNot = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
     var regMust = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})$/;
      if ( !regDoNot.test(strEmail) && regMust.test(strEmail) ) {
       } else {
         msg = "[" + strName + "] À» Àß¸ø ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù.";
         alert(msg);
         return false;
       }
    return true;
}




// Á¤·Ä
function Sort(obj) {
	var str = obj.value;
	var arr = new Array();
	var tmp = new Array();
	
	// ',' ¾Õ µÚÀÇ °ø¹éÀ» Á¦°ÅÇÑ´Ù.
	str = str.replaceAll(", ", ",");
	str = str.replaceAll(" ,", ",");
	// ½ºÆ®¸µÀ» ',' ´ÜÀ§·Î ºÐ¸®
	arr = str.split(",");
	// ½ºÆ®¸µÀ» Á¤·Ä
	tmp = arr.sort();
	// ¹è¿­ÀÇ ½ºÆ®¸µÀ» ÇÏ³ªÀÇ ½ºÆ®¸µÀ¸·Î °áÇÕ
	obj.value = tmp.join(",");
}

// ÆË¾÷ Ã¢ ¶ç¿ì±â
 function divSetVisible(divRef , ifRef , state) {
//	var divRef = document.getElementById(div);
//	var ifRef = document.getElementById(ifr);
	if(state) {
		divRef.style.display = "block";
		ifRef.style.width = divRef.style.width;
		ifRef.style.height = divRef.style.height;
		ifRef.style.top = divRef.style.top;
		ifRef.style.left = divRef.style.left;
		ifRef.style.zindex = divRef.style.zindex - 1;
		ifRef.style.display = "block";
	}
	else {
		divRef.style.display = "none";
		ifRef.style.display = "none";
	}
}
function popup_window(top, width, height, url, exec, fixleft) {
	var div = $('popup_window');

	//alert("ok -" + fixleft);
/*
	var alphaDiv = $('alphaDiv');
	var alphaDiv_opacity = 15;
	var alphaDiv_color = '#000';
	
	alphaDiv.style.background = alphaDiv_color;
	setOpacity(alphaDiv,alphaDiv_opacity);
	Position.clone(document.body,alphaDiv);
	*/
		
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.style.zIndex = 1000;
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "visible"; //"auto";

		if(fixleft)
			div.style.left = fixleft + "px";	
		else
			div.style.left = (document.body.clientWidth - width)/2 + "px";
		
		document.body.appendChild(div);
		
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "visible"; //"auto";
		div.style.zIndex = 1000;

		if(fixleft)				
			div.style.left = fixleft + "px";
		else
			div.style.left = (document.body.clientWidth - width)/2 + "px";
		Element.show(div);
	}
	
	/*
	var startupInfo = "['center']";
	var dlgPos = new Array(2);
	var dlgSize = new Array(2);
	if ( !startupInfo || !startupInfo[0] ) startupInfo = new Array('center', new Array(2), new Array(2));
	if ( !startupInfo[1] ) startupInfo[1] = new Array(2);
	
	    // set size
	if ( !startupInfo[2] || startupInfo[2][0] < 1 || startupInfo[2][1] < 1 || startupInfo[2][0] == 'undefined' || startupInfo[2][1] == 'undefined' || !startupInfo[2][0] || !startupInfo[2][1] ) {
	    div.style.display = 'block';
	    var tmp=Element.getDimensions(div);
	    dlgSize[0]=tmp.width; dlgSize[1]=tmp.height;
	    div.style.display = 'none';
	}
	else
	{
	    dlgSize=startupInfo[2];
	}
	
	Position.prepare();
	// set position
	if ( startupInfo[0]=='center' ) {
		var scrPos=new Array(Position.deltaX,Position.deltaY);
		var scrSize=getViewport();
	
	    startupInfo[1][0]=scrPos[0]+scrSize[0]/2-dlgSize[0]/2;
	    startupInfo[1][1]=scrPos[1]+scrSize[1]/2-dlgSize[1]/2;
	}
	else if ( startupInfo[0]=='absolute' )
	{
	}
	else if ( startupInfo[0]=='relative' )
	{
	    var scrPos=new Array(Position.deltaX,Position.deltaY);
	
	    startupInfo[1][0]+=scrPos[0];
	    startupInfo[1][1]+=scrPos[1];
	}
	
	// drawing dialogBox
	if ( startupInfo[1] && startupInfo[1][0] && startupInfo[1][1] )
	{
	    dlgPos=startupInfo[1];
	
	    div.style.left=dlgPos[0]+'px';
	    div.style.top=dlgPos[1]+'px';
	    if(dlgSize[0]>0 && dlgSize[1]>0)
	    {
	        div.style.width=dlgSize[0]+'px';
	        div.style.height=dlgSize[1]+'px';
	    }
	}
   	
	alphaDiv.style.display='block';
	div.style.display='block';
	*/
	go(url, div, exec);
		
	
}
function popup_window4(top, width, height, url, exec) {
	var div = $('popup_window');
	/*
	var alphaDiv = $('alphaDiv');
	var alphaDiv_opacity = 15;
	var alphaDiv_color = '#000';
	
	alphaDiv.style.background = alphaDiv_color;
	setOpacity(alphaDiv,alphaDiv_opacity);
	Position.clone(document.body,alphaDiv);
	*/
	
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.style.zIndex = 100;
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";
		
		document.body.appendChild(div);
		document.body.appendChild(ifRef);
		
		//document.body.appendChild(theHandle);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";
		Element.show(div);
	}


	go(url, div, exec);
	
	
}

function setOpacity(obj,value)
{
	if(typeof(obj)=='string') obj=document.getElementById(obj);
	obj.style.opacity = (value / 100);
	obj.style.MozOpacity = (value / 100);
	obj.style.KhtmlOpacity = (value / 100);
	obj.style.filter = "alpha(opacity=" + value + ")";
}

function getViewport(){
	var w=0;
	var h=0;

	if(window.innerWidth) w=window.innerWidth;
	if(document.documentElement.clientWidth){
		var w2 = document.documentElement.clientWidth;
		if(!w || w2 && w2 < w) w=w2;
	}else if(document.body){
		w=document.body.clientWidth;
	}

	if(window.innerHeight) h=window.innerHeight;
	if(document.documentElement.clientHeight) h=document.documentElement.clientHeight;
	else if(document.body) h=document.body.clientHeight;

	return [w,h];
}
// ÆË¾÷ Ã¢ ¶ç¿ì±â2
function popup_window2(top, left, width, height) {
	var div = $('popup_window');
	var alphaDiv = $('alphaDiv');
	var alphaDiv_opacity = 15;
	var alphaDiv_color = '#000';
	
	alphaDiv.style.background = alphaDiv_color;
	setOpacity(alphaDiv,alphaDiv_opacity);
	Position.clone(document.body,alphaDiv);
	
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		Element.show(div);
	}
	
	//Drag.init(document.getElementById("popup_window"));
}

// ÆË¾÷ Ã¢ ¶ç¿ì±â3
popup_window3 = function(top, left, width, height, url, exec) {
	var div = $('popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		Element.show(div);
	}
	go(url, div, exec);
	
	Drag.init(document.getElementById("popup_window"));
	
}

// ÆË¾÷ ³» »õ·Î¿î ÆË¾÷ Ã¢ ¶ç¿ì±â

function child_popup_window(top, left, width, height, url, exec) {
	var div = $('child_popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "child_popup_window";
		div.className = "child_popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		Element.show(div);
	}
	go(url, div, exec);
	
	//Drag.init(document.getElementById("child_popup_window"));
	
}

// Ä¶¸°´õ

function view_calendar(formNM, objNM, preDate, size, pos, year, month) {
	var top = "250";
	var width = "270";
	var height = "230";
	var url = "/admin/include/calendar.jsp?formNM=" + formNM + "&objNM=" + objNM + "&preDate=" + preDate + "&size=" + size + "&pos=" + pos + "&year=" + year + "&month=" + month;
	var exec = "";
	popup_window(top, width, height, url, exec);
}

// ÆË¾÷ ³»ÀÇ Ä¶¸°´õ

function view_child_calendar(formNM, objNM, preDate, size, pos, year, month) {
	var top = "250";
	var width = "270";
	var left = (document.body.clientWidth - width)/2 + "";
	var height = "230";
	var url = "/admin/include/childCalendar.jsp?formNM=" + formNM + "&objNM=" + objNM + "&preDate=" + preDate + "&size=" + size + "&pos=" + pos + "&year=" + year + "&month=" + month;
	var exec = "";
	child_popup_window(top, left, width, height, url, exec);
}


function go(url, dest, exec){
	new Ajax.Updater(
					 dest, 
					 url, 
					 {
					  asynchronous: true, 
					  method: 'get', 
					  onLoading: Element.update(dest, loading), 
					  onComplete: function(result){
					          try
					          {
					            //if(console&&console.log)
					            //{
					            //  console.log(result);
					             // console.log(dest);
					            //}
					            dest.innerHTML = linkHttpReplace(result.responseText);
					          }catch(errobj){}
					  				eval( '(' + exec + ')' ); 
					  			  },
					  evalScripts: true 
					 }
					);

}

function linkHttpReplace(str){
	var retval = str;	
	try
	{			
		var virobj = document.createElement("DIV");
		virobj.innerHTML = str;	
		//log("pre html -> " + virobj.innerHTML);
		var atags = virobj.getElementsByTagName("A");
		for(var i=0;i<atags.length;i++)
		{
			if(atags[i].href)
			{
				//log("[" + i + "] : " + atags[i].href);
				//Ä¡È¯ (https -> http)
				atags[i].href = atags[i].href.replace(/https/gi,"http");
			}			
		}
		//log("result html -> " + virobj.innerHTML);
		retval = virobj.innerHTML;
	}catch(errobj)
	{
		if(console&&console.log){
			console.log("linkHttpReplace error.");
			console.info(errobj);
		}
	}
	return retval;
}

String.prototype.replaceAll = function( searchStr, replaceStr ) {
	var temp = this;
	while( temp.indexOf( searchStr ) != -1 ) {
		temp = temp.replace( searchStr, replaceStr );
	}
	return temp;
}



// ÀÌ¹ÌÁö ÀÚµ¿ Á¶Àý
resizeImgByHeight = function (img, height) {  
	if(img.height > height) {
		img.height = height;
	}
}

resizeImgByWidth = function (img, width) {
	if (img.width > width) {
		img.width = width;
	}
}

addComma = function(val) {
	tmpLen = val.length;
	c = Math.floor(tmpLen/3);
	d = tmpLen % 3;
	if ( d == 0 ) {
		d = 3;
		c--;
	}
	ee = val.substr(0,d)
	for( i = 0; i < c; i++) {
		ee+="," + val.substr( 3*i+d, 3 );
	}
		
	return ee;

}
	
delComma = function (inputNumber, sTargetStr, sReplaceStr) {
	var pos = 0;
	var preStr = "";
	var postStr = "";
	pos = inputNumber.indexOf(sTargetStr);
	while (pos != -1) {
		preStr  = inputNumber.substr(0,pos);
		postStr = inputNumber.substr(pos+1,inputNumber.length);
		inputNumber = preStr + sReplaceStr + postStr;
		pos = inputNumber.indexOf(sTargetStr);
	}
	return inputNumber;
}

function copyURL (sData,sMode) {
	switch(sMode) {
		case "link":
			var sMsg = '±Û ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù.\n';
			break;
		case "title":
			var sMsg = '±Û Á¦¸ñ°ú ÁÖ¼Ò°¡ ÇÔ²² º¹»çµÇ¾ú½À´Ï´Ù.\n';
			break;
		case "trackback":
			var sMsg = 'Æ®·¢¹é ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù.\n';
			break;
		case "rss":
			var sMsg = 'RSS ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù.\n';
			break;	
			default:
			var sMsg = 'º¹»çµÇ¾ú½À´Ï´Ù.\n';
	}
	sMsg += 'ºÙ¿©³Ö±â(Ctrl + V)¸¦ ÇØ¼­ »ç¿ëÇÏ¼¼¿ä.';
	window.clipboardData.setData('Text',sData);
	window.alert(sMsg);
}

var s_trackbackUrlCopied = "Æ®·¢¹é ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù";
var s_trackbackUrlCopyFailed = "Æ®·¢¹é ÁÖ¼Ò¸¦ º¹»çÇÏÁö ¸øÇß½À´Ï´Ù";			
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function copyUrl(url) {
	try {
		thisMovie('clipboardPoter').setClipBoard(url);
	} catch(e) {
		if(isIE) {
			window.clipboardData.setData('Text',url);
			window.alert(s_trackbackUrlCopied);
		}
	}
}

var maxwidth = 550;	
function varwidth(imgobj) {	
	if (imgobj.width>maxwidth)
		imgobj.width = maxwidth	
}	


//ÀÌ¹ÌÁö È®ÀåÀÚ Ã¼Å© 

function chkImgFile(FileName) {

	if(FileName.match(/\.(jpg|jpeg|bmp|gif|tif|tiff|png)$/i)) {
	return true;
	}
	
	else {
	alert("jpg,jpeg,bmp,gif,tif,tiff,png ÆÄÀÏ¸¸ ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù.");
	return false;
	}
}


//bmpÆÄÀÏ¸¸ È®ÀåÀÚÃ¼Å©ÇÏ¿© ¾÷·Îµå ºÒ°¡´ÉÇÏµµ·Ï Ã¼Å© 
function chkImgFileBmp(FileName) {

	//if(FileName.match(/\.(bmp)$/i)) {
	//	alert("bmp ÆÄÀÏÀº ¾÷·Îµå ºÒ°¡´ÉÇÕ´Ï´Ù.");
	//	return false;
	//}
	//else {
		return true;
	//}
}	
	


//µ¿¿µ»ó È®ÀåÀÚ Ã¼Å© 

function chkMovieFile(FileName) {

	if(FileName.match(/\.(wmv|avi|mpg|mov)$/i)) {
	return true;
	}
	
	else {
	alert("wmv,avi,mpg,mov ÆÄÀÏ¸¸ ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù.");
	return false;
	}

}

//UTF8 ÀÎÄÚµù
//@str
function utfEncoding(str)
{
  return encodeURIComponent(str);
}
   
//Unicode ÀÎÄÚµù
//@str 
function unicodeEncoding(str)
{
  return escape(str);
}

//ÆÄÀÏÃ¼Å©¸¦ À§ÇÑ ¸Þ¼Ò
function fileCheck(realFile,oldFile,msg)
{
	if(realFile.value == "" && oldFile == undefined)
	{
		alert(msg);
		return false;
	}
	return true;
}
//·Î±×ÀÎ
function login(top, width, height, url){
	
	//var top = document.body.scrollTop + 100;//"250";
	//var left = "500";
	//var width = "600";
	//var height = "291";
	//var url = "<%=contextPath%>/Member.do?action=loginForm";
	var exec = "$('MemberNo').focus()";
	
	popup_window(top, width, height, url, exec);
}

//calendar.jsp ·¡ÀÌ¾îÆË¾÷À» ±¸ÇöÇÔ
function Layer(top, width, height, url){
	
	//var top = document.body.scrollTop + 100;//"250";
	//var left = "500";
	//var width = "600";
	//var height = "291";
	//var url = "<%=contextPath%>/Member.do?action=loginForm";
	var exec = "";
	
	popup_window(top, width, height, url, exec);
}


//htmlÅÂ±×¸¦ Á¦°ÅÇØÁÖ´Â ÀÚ¹Ù½ºÅ©¸³Æ® ¸Þ¼Òµå
function stripHTMLtag(string) {
    var objStrip = new RegExp();
    objStrip = /[<][^>]*[>]/gi;
    return string.replace(objStrip, "");
}

function loginCheck(){
	alert("·Î±×ÀÎÀÌ ÇÊ¿äÇÕ´Ï´Ù");	
	//var width = "470";
	//var height = "210";
	//var top ="";
	
	//var scleft = document.documentElement.scrollLeft;
	//var sctop = document.documentElement.scrollTop;
	//var screenwidth = document.documentElement.clientWidth ;
	//var screenheight = document.documentElement.clientHeight;
	//var left = parseInt((screenwidth - width)/2) + scleft;
	//top = parseInt((screenheight - height)/2) + sctop;
	////top = "250";
	
	////var url = "/sigongsa/Member.do?action=loginForm";
	//var url = "http://www.sigongsa.com/Member.do?action=loginForm";

	//var exec = "";
	//popup_window(top, width, height, url, exec);	
// 2009³â 3¿ù 19ÀÏ °ü¸®ÀÚ ¿äÃ»¿¡ µû¸¥ ·ÎÀÎÀÎ ÆäÀÌÁö·Î Æ÷¿öµù Ã³¸®
	eval("document.location.href='https://www.sigongsa.com/Member.do?action=loginForm_new'");
 }

function myFavorite(url, name) {
    window.external.AddFavorite(url, name)
}

function varwidth_new(imgobj, mwidth) {	
	if (imgobj.width> mwidth)
		imgobj.width = mwidth	
}






