//브라우저 종류 출력
function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';

	if (agt.indexOf('\/') != -1) {
	   if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
		  return navigator.userAgent.substr(0,agt.indexOf('\/'));
	   else
		  return 'Netscape';

	} else if (agt.indexOf(' ') != -1){
		  return navigator.userAgent.substr(0,agt.indexOf(' '));
	} else {
		  return navigator.userAgent;
	}
}

//오른쪽 마우스 클릭 방지 
function blockRightClick(){

	// Capture right click
	$("html").rightClick( function(e) {});		
	// Capture right mouse down  
	$("html").rightMouseDown( function(e) {});		
	// Capture right mouseup
	$("html").rightMouseUp( function(e) {});		
	// Disable context menu on an element
	$("html").noContext();
    
 }


/***************************************
* 플래쉬 로드
***************************************/
function flashLoad2(swf_url, id, iWidth, iHeight)
{
	var str = '';

	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + iWidth + '" height="' + iHeight + '" id="' + id + '" align="middle">';
	str += '<param name="allowScriptAccess" value="always" />';
	str += '<param name="movie" value="' + swf_url + '" />';
	str += '<param name="loop" value="false" />';
	str += '<param name="quality" value="high" />';
	str += '<param name="wmode" value="transparent" />';
	str += '<param name="bgcolor" value="#ffffff" />';
	str += '<embed src="' + swf_url + '" loop="false" quality="high" bgcolor="#ffffff" width="' + iWidth + '" height="' + iHeight + '" name="' + id + '" align="middle" allowScriptAccess="always"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';

	document.write(str);
}

function flashLoad1(swf_url, id, iWidth, iHeight)
{
	var str = '';
	
	str += "<iframe id='swf_iframe' src='/common/func/flashLoad.asp?swf_url=" + swf_url + "&id=" + id + "&iWidth=" + iWidth + "&iHeight=" + iHeight + "' width="+ iWidth +" height="+ iHeight +" marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0'/></iframe>";
	
	document.write(str);
}

/***************************************
* 배경깜박임 제어
***************************************/
(function(){ 
/*Use Object Detection to detect IE6*/ 
var m = document.uniqueID /*IE*/ 
document.compatMode /*>=IE6*/ 
!window.XMLHttpRequest /*<=IE6*/ 
document.execCommand ; 
try{ 
if(!!m){ 
m("BackgroundImageCache", false, true) /* = IE6 only */ 
} 
}catch(oh){};
})();
/*
css html { filter: expression(document.execCommand("BackgroundImageCache", false, true));}
*/


/***************************************
* 투명 png 치환
***************************************/
function setPng24(obj,switche) {
		obj.width=obj.height=1;
		obj.className=obj.className.replace(/\bpng24\b/i,'');
		obj.style.filter =
		"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
		obj.src='';
		return '';
}

/***************************************
* 화면사이즈 조절
***************************************/
var nowZoom = 100; // 현재비율
var maxZoom = 200; // 최대비율(500으로하면 5배 커진다)
var minZoom = 80; // 최소비율

//화면 키운다.
function zoomIn() {
	if (nowZoom < maxZoom) {
		nowZoom += 25; //25%씩 커진다.
	} else {
		return;
	}
	document.getElementById("wrapperAll").style.zoom = nowZoom + "%";
}

//화면 줄인다.
function zoomOut() {
	if (nowZoom > minZoom) {
		nowZoom -= 25; //25%씩 작아진다.
	} else {
		return;
	}
	document.getElementById("wrapperAll").style.zoom = nowZoom + "%";
}
	
/***************************************
* 접근성 고려 팝업 스크립트
***************************************/
function popWin(loc,Name,w,h){
        window.open(loc, Name, 'width='+w+',height='+h); 
}


/***************************************
* input over effect
***************************************/
// dafault input focus
function mkOver(){
    $("input[type=text], input[type=password], input[type=file], textarea").focus(function(){
        $(this).addClass("ihover");
    });
    $("input[type=text], input[type=password], input[type=file], textarea").blur(function(){
        $(this).removeClass("ihover");
    });
    
}
// myinfo input focus 
function mkOverMy(){
    $("input[type=text], input[type=password], input[type=file], textarea").focus(function(){
        $(this).addClass("myhover");
    });
    $("input[type=text], input[type=password], input[type=file], textarea").blur(function(){
        $(this).removeClass("myhover");
        /*if (this.value = '') {
            $(this).removeClass();
        } else {
            $(this).removeClass("myhover");
        }*/
    });
    
}

/***************************************
* mouse over effect
***************************************/
function mover(){
    $("a[rel=muOver]").hover(
	function()
	{
        var iobj = $(this).children();
         iobj.attr("src", iobj.attr("src").replace(".","on.") );
	},
	function()
	{
        var iobj = $(this).children();
         iobj.attr("src", iobj.attr("src").replace("on.",".") );
	});
}

/***************************************
// 메세지를 출력하고, Object로 focus를 돌려준다.
***************************************/
//얼럿경고창 대용 -  테이블
function checkForm( f , msg){
	for (var i=0; i<f.elements.length; i++) {
        if ( f.elements[i].getAttribute(msg) ) {
            if ( isEmpty( f.elements[i].value ) ) {
                
                var splitData = f.elements[i].getAttribute(msg).split("||");
                var msgData = "";

                if( splitData.length ) {
                    for( var kk = 0; kk < splitData.length; kk++ ){
                        msgData += splitData[kk] + "\n";
                    }
                }else{
                    msgData = f.elements[i].getAttribute(msg);
                }

                if( (f.elements[i].type && f.elements[i].type!="hidden") ){
                    ErrMsg2( f.elements[i], msgData );   
                }
                else{
                    alert( msgData  );
                }
                return false;
            }
        }
    }
	return true;
}

//얼럿경고창 대용 -  레이어
function checkForm2( f , msg){
	for (var i=0; i<f.elements.length; i++) {
        if ( f.elements[i].getAttribute(msg) ) {
            if ( isEmpty( f.elements[i].value ) ) {
                
                var splitData = f.elements[i].getAttribute(msg).split("||");
                var msgData = "";

                if( splitData.length ) {
                    for( var kk = 0; kk < splitData.length; kk++ ){
                        msgData += splitData[kk] + "\n";
                    }
                }else{
                    msgData = f.elements[i].getAttribute(msg);
                }

                if( (f.elements[i].type && f.elements[i].type!="hidden") ){
                    ErrMsg( f.elements[i], msgData );   
                }
                else{
                    alert( msgData  );
                }
                return false;
            }
        }
    }
	return true;
}

function ErrMsg( obj, msg ){
    try{
        alert( msg );

		if( obj.type == "select-one" ){
		  obj.focus();
		}else{
		  obj.focus();
		  obj.select();
		}
        return false;
    }
    catch(errorObject){
        var msg = errorObject.description + "\n\n"
               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
	    alert(msg);
        return false;
    }
}

//얼럿경고창 대용 -  테이블
function ErrMsg2( obj, msg ){
    try{
		$("#alert_msg").remove()
		$(obj).parent().parent().after("<tr id='alert_msg'><td  colspan='6' class='alert'><img src='/img2010/common/exclamation.gif' /> " + msg + "</td></tr>");

		if( obj.type == "select-one" ){
		  obj.focus();
		}else{
		  obj.focus();
		  obj.select();
		}
		return false;
        
    }catch(errorObject){
        var msg = errorObject.description + "\n\n"
               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
	    alert(msg);
        return false;
    }
}

//얼럿경고창 대용 -  레이어
function ErrMsg3( obj, msg ){
    try{
		$("#alert_msg").remove()
		$(obj).parent().after("<li id='alert_msg' class='alert '><img src='/img2010/common/exclamation.gif' /> " + msg + "</li>");

		if( obj.type == "select-one" ){
		  obj.focus();
		}else{
		  obj.focus();
		  obj.select();
		}
		return false;
        
    }catch(errorObject){
        var msg = errorObject.description + "\n\n"
               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
	    alert(msg);
        return false;
    }
}



/***************************************
// 팝업관련
***************************************/

function openWin(url,winName,width,height,scroll)
{
    window.open( url , winName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=no,width=" + width + ",height=" + height);
    return ;
}

function openWinCenter(url,winName,width,height,scroll)
{
	var sw=screen.availWidth;
	var sh=screen.availHeight;

	 //열 창의 포지션
	var px=(sw-width)/2;
	var py=(sh-height)/2;

    window.open( url , winName,"toolbar=no,location=no,directories=no,status=no,menubar=no,left="+px+",top=" +py+ ",scrollbars=" + scroll + ",resizable=no,width=" + width + ",height=" + height);
    return ;
}


function isEmpty( data )
{
    for( var i = 0 ; i < data.length; i++ )
    {
        if( data.substring( i , i + 1 ) != " " )
        {
            return false;
        }
    }
    return true;
}

//숫자만 입력가능하게함 사용예<   OnKeyPress="numChk()"   >
function numChk()
{
    if ((event.keyCode<48) || (event.keyCode>57))
        event.returnValue=false;
}

/***********************************
설명 : ID/비밀번호 체크
***********************************/
function CheckID(obj){

	if (/^[a-zA-Z0-9]{5,16}$/.test(obj.value)) {
		return true;
	} else{
		ErrMsg2( obj, "영문 or 숫자 5~16자로 입력하세요." );
		return false;
	}
}

/***********************************
설명 : textbox에 엔터 쳤을때 callback 함수 호출
***********************************/
function comm_enter_callback(callback)
{
    if( event.keyCode == 13 )
    {
        callback();
    }
}

// 메일 체크
function checkEmail(strEmail)
{
	var arrMatch = strEmail.match(/^(\".*\"|[A-Za-z0-9_-]([A-Za-z0-9_-]|[\+\.])*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9][A-Za-z0-9_-]*)+)$/);
	if( arrMatch == null )
	{
		return false;
	}

	var arrIP = arrMatch[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if( arrIP != null )
	{
		for( var i = 1 ; i <= 4 ; i++ )
		{
			if( arrIP[i] > 255 )
			{
				return false;
     		}
   		}
	}
	return true;
}

// value가 숫자로만 되어있는지 체크한다.
function isDigitValue(value)
{
    if(!isEmpty( value ) )
    {
	    try{
	        inputStr = value;
	        for( var i = 0 ; i < inputStr.length ; i++ )
	        {
	            var oneChar = inputStr.charAt(i)
	            if (oneChar < "0" || oneChar > "9")
	            {
	                return false;
	            }
	        }
	        return true;
	    }
	    catch(errorObject){
	        var msg = errorObject.description + "\n\n"
	               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
		    alert(msg);
	        return false;
	    }
	}else{
		return false;
	}
}

function getReplaceEmpty (str) {
   return str.replace(/\s+$/g, '');
}


function isJumin(idno) 
{ 
	var idno = getReplaceEmpty(idno);
	//alert(idno);
    if ( idno.indexOf("-")!==-1 ) idno = idno.replace("-",""); 
    if ( idno.search(/\D/)!==-1 || idno.length!=13 ) { 
		return false;
    } 
    var yy = idno.substr(0,2)*1; var mm = idno.substr(2,2)*1; var dd = idno.substr(4,2)*1; 
    
    // 외국인등록번호는 걍 pass
    if (idno[6]==5 || idno[6]==6 || idno[6]==7 || idno[6]==8 || idno[6]==9) {
    	return true;
    }
    
    if ( idno[6]==0 || idno[6]==9 ) yy+=1800; 
    if ( idno[6]==1 || idno[6]==2 || idno[6]==5 || idno[6]==6 ) yy+=1900; 
    if ( idno[6]==3 || idno[6]==4 || idno[6]==7 || idno[6]==8 ) yy+=2000; 
    if ( mm<1 || mm>12 || dd<1 || dd>(new Date(yy,mm,0)).getDate() ) { 
		return false;
    } 
    for (i=s=0,n=2;i<12;i++,n=i%8+2) s+= parseInt(idno.substr(i,1))*n; 
    if ( parseInt(idno.substr(12,1))!=(11-s%11)%10 ) { 
		return false;
    } 
	return true;
} 




//사업자 번호 체크
function isBizNum (str) {
	var num = getReplaceEmpty(str);
	if(10 == num.length) {
		num = num.substring(0, 3) + "-" + num.substring(3, 5) + "-" + num.substring(5, 10);
	}
	else {
		return false;
	}
	num = num.match(/([0-9]{3})-?([0-9]{2})-?([0-9]{5})/);
	if(!num) return false;
	num = RegExp.$1 + RegExp.$2 + RegExp.$3;
	var cVal = 0;
	for (var i=0; i<8; i++) {
		var cKeyNum = parseInt(((_tmp = i % 3) == 0) ? 1 : ( _tmp  == 1 ) ? 3 : 7);
		cVal += (parseFloat(num.substring(i,i+1)) * cKeyNum) % 10;
	}
	var li_temp = parseFloat(num.substring(i,i+1)) * 5 + '0';
	cVal += parseFloat(li_temp.substring(0,1)) + parseFloat(li_temp.substring(1,2));
	return (parseInt(num.substring(9,10)) == 10 - (cVal % 10)%10) ? true : false;
}

//입력창 이동
function nextFocus(fromform,toform){
	var str = fromform.value.length;
	var num = fromform.maxLength;

	if(str == num) {
		toform.focus();
	}
}
