//
// OS ¹× WebBrowser Check.
//
var agent = navigator.userAgent.toLowerCase();

isWIN   = ( agent.indexOf('win') != -1 ) ? true : false;
isMAC   = ( agent.indexOf('mac') != -1 ) ? true : false;
isWINXP = ( agent.indexOf('windows nt 5.1') != -1) ? true : false;

isNS4   = (document.layers) ? true : false;
isIE4   = (document.all  && !document.getElementById) ? true : false;
isIE5   = (document.all  && document.getElementById ) ? true : false;
isNS6   = (!document.all && document.getElementById ) ? true : false;

//
// °´Ã¼ ¸®ÅÏ
//
function getObj(idname)
{
	if( isNS4 )
	{
		objElement = document.layers[idname];
	}
	else if( isIE4 )
	{
		objElement = document.all[idname];
	}
	else if( isIE5 || isNS6 )
	{
		objElement = document.getElementById(idname);
	}

	return objElement;
}

function onlynum(val){
	var inText = val.value;
	var ret;
	

	for (var i = 0; i < inText.length; i++) {
		ret = inText.charCodeAt(i);
		if (!((ret > 47) && (ret < 58)))  {
			alert("¼ýÀÚ¸¸À» ÀÔ·ÂÇÏ¼¼¿ä");
			val.value = "";
			val.focus();
			return false;
		}
	}
	return true;
}


function ChkNext(val,elem, next) {
	if (val.value.length==elem)
	{
		next.focus();
	}
}

	var oldText="";
 function CheckLen(val, lenchk, nm, count)
{
    var temp;
    var memocount;
	var lenchk;
	lenchk = parseInt(lenchk);
    memocount = 0;
    len = val.value.length;
    
    for(k=0;k<len;k++){
	    temp = val.value.charAt(k);
	    if(escape(temp).length > 4)
		    memocount += 2;
	    else
		    memocount++;
    }
	getObj(count).innerHTML = memocount;
    
	
    if (memocount/2>lenchk) {	
		alert( nm+" "+lenchk+"ÀÚ±îÁö¸¸ ¾²½Ç ¼ö ÀÖ½À´Ï´Ù.");
		val.value = oldText;		
		getObj(count).innerHTML = oldCount;
		return;
    }else{
		oldText = val.value;
		oldCount = memocount;
    }
    
   // return memocount/2;
}


 function CheckLenReal(val, lenchk, nm, count)
{
    var temp;
    var memocount;
	var lenchk;
	lenchk = parseInt(lenchk);
    memocount = 0;
    len = val.value.length;
    
    for(k=0;k<len;k++){
	    temp = val.value.charAt(k);
	    if(escape(temp).length > 4)
		    memocount += 2;
	    else
		    memocount++;
    }
	
    if (memocount>lenchk) {	

		alert( nm+" "+lenchk+"ÀÚ±îÁö¸¸ ¾²½Ç ¼ö ÀÖ½À´Ï´Ù.");
		val.value = oldText;		
		return;
    }else{
		oldText = val.value;
		oldCount = memocount;
    } 
}



	function chkStr( str, val )
	{

		if(str == "")
		{
			//document.all.title.focus();
			alert(val+"À» ÀÔ·ÂÇÏ¼¼¿ä.");
			return 0;
		}
	     var retVal = checkSpace( str ); 
	             
	     if( retVal != "" ) {
	         alert("ÇÑ±Û ¹× ¼ýÀÚ, ¿µ¹®¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÕ´Ï´Ù.");
	         return 0; 
	     } 

		for(i=0;i<str.length;i++)
		{
			moji = escape(str.substring(i, i+1));
			if( ((str.charAt(i) < "a") || (str.charAt(i) > "z")) && ((str.charAt(i) < "A") || (str.charAt(i) > "Z")) && ((str.charAt(i) < "0") || (str.charAt(i) > "9")) )
			{
				//alert(moji.substring(2, 6));
				if(moji.length < 6 || moji.substring(2, 6) < "AC00" || moji.substring(2, 6) > "D7AF" || moji.substring(2, 6) < 3131 || moji.substring(2, 6) > 3162)
				//if (!((str.charCodeAt(i) > 0x3130 && str.charCodeAt(i) < 0x318F) || (str.charCodeAt(i) >= 0xAC00 && str.charCodeAt(i) <= 0xD7A3)))
				{
					alert("ÇÑ±Û ¹× ¼ýÀÚ, ¿µ¹®¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÏ¸ç °¢°¢ ÃÊ¼º, Áß¼º Á¾¼º¸¸ ÀÔ·ÂÇÏ´Â °ÍÀº Çã¿ëµÇÁö ¾Ê½À´Ï´Ù.");
					return 0;
				}
			}
		}
		return 1;
	}


	function checkSpace( str )
	{
		if(str.search(/\s/) != -1){
			return 1;
	    }
	
	    else {
			return "";
	    }
	}



	function checkChars(val) {
		var i;
		var j = 0;
		var s = eval(val).value;
		for (i=0; i<s.length; i++) {
			if (s.substring(i, i+1) != " ") {
				j = j + 1;
			}
		}
		return j;
	}

function getHTTPObject()
{
	if (window.ActiveXObject)
	{
		var waystation = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest)
	{
		var waystation = new XMLHttpRequest();
	}
	else
	{
		var waystation = false;
	}
	return waystation;
}







function call_xml_txt(sURL){
	var oXMLHTTP = getHTTPObject();

	oXMLHTTP.open("POST", sURL, false);
	oXMLHTTP.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;");
	oXMLHTTP.send (null);
	var strv = oXMLHTTP.responseText;
	return strv;
}

function call_xml(sURL){
	var oXMLHTTP = getHTTPObject();
	oXMLHTTP.open("POST", sURL, false);
	oXMLHTTP.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;");
	oXMLHTTP.send (null);
}

function call_xml_JD(sURL, sPARAM){
	var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");

	oXMLHTTP.open("POST", sURL, false);
	oXMLHTTP.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;");
	oXMLHTTP.send (sPARAM);

	var strv = oXMLHTTP.responseBody;
	var httpmsg = BinDecode(strv);
	oXMLHTTP = "";
	return httpmsg;
}


function call_xml_post(sURL,svar){
	var oXMLHTTP = getHTTPObject();
	oXMLHTTP.open("POST", sURL, false);
	oXMLHTTP.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;");
	oXMLHTTP.send (svar);
}

function call_xml_post_txt(sURL,svar){
	var oXMLHTTP = getHTTPObject();
	oXMLHTTP.open("POST", sURL, false);
	oXMLHTTP.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded;");
	oXMLHTTP.send (svar);
	var strv = oXMLHTTP.responseText;
	return strv;

}


//À©µµ¿ìÃ¢¿­±â
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//À©µµ¿ìÃ¢¿­±â
function MM_openBrWindow_form(frm, targetnm, status, sURL) { //v2.0
	window.open("about:blank", targetnm, status);
	eval(frm).action = sURL;
	eval(frm).target = targetnm;
	eval(frm).submit();
}


function commachk(x)
{
	var xLen = x.length;

	var rtnStr = "";

	var str = x+'';
	var leng = str.length;
	var finalStr = '';
	var pos = 1;
	var comma = '';

	for(leng; leng>0; leng--){
		try{
			if(pos>3)
			{
				pos = 1;
			}

			if(pos==3){
				if(str.length>1){
					comma = ',';
				}
				else
				{
					comma = '';
				}
			}
			else
			{
				comma = '';
			}

			finalStr = comma+str.substr(str.length-1)+finalStr;
			str = str.substr(0,str.length-1);

			pos++;
		}catch (e){
			alert(e);
		}
	}
	return finalStr;
}

// Æ¯¼ö¹®ÀÚ Á¦°Å (°ª ¹Þ¾Æ¿Í¼­ ¿¹¿ÜÃ³¸®)
function filterKey(filter) 
{
  if(filter)
  {
      var sKey = String.fromCharCode(event.keyCode);
      var re = new RegExp(filter);
      if(!re.test(sKey)) event.returnValue=false;
  }
}

//½ºÆäÀÌ½º Á¦°Å
function space_no(){
 if(event.keyCode == 32)
 {
  event.returnValue=false;
 } 
}

// º¹»çºÙÀÌ±â ¾ÈµÇ°Ô
function keyControl(){
 if(event.ctrlKey || event.altKey ){event.returnValue=false;}
}


// °ø¹éÁ¦°ÅÇÔ¼ö
function trim(txt)
{
 return txt.replace(/(^\s*)|(\s*$)/g, "");
}



 //ÇØ»óµµ Å©±â¿¡ ¸Â°Ô Ã¢ ¶ç¿ì±â
function winMaximizer(url) {
	if (document.layers) {
		larg = screen.availWidth - 10;
		altez = screen.availHeight - 20;
	} else {
		var larg = screen.availWidth;
		var altez = screen.availHeight -40;
	}

	var fileView = window.open(url,'fileView','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,copyhistory=0,width=880,height='+altez+',left=10,top=1');
	fileView.focus();
}
