/***************************************************************
*
* JS 스크립트 펑션 모음
*
* 2007.03.07 
* 이재은(delight7@hanmail.net)
*
***************************************************************/

/*******************************************************
*
* Function : imgResize
* Introduce: 이미지가 입력된 사이즈보다 클 경우 
*            입력 사이즈로 조정해주는 함수
* param    : obj(해당 이미지-함수 호출시에 this로 참조)
*            width(0일 경우 조정하지 않음)
*            height(0일 경우 조정하지 않음)
*
*******************************************************/
function imgResize(obj,width,height)
{
         if (width>0)  if (obj.width>width) obj.width = width;
         if (height>0) if (obj.height>height) obj.height = height;

		 return;
}

/*******************************************************
*
* Function : viewImg
* Introduce: 파일 선택폼에서 이미지가 선택될 경우 
*            그 이미지를 보여줌
* param    : obj(해당 이미지-함수 호출시에 this로 참조)
*            target(이미지를 보여줄 영역 - 이미지명이 사용됨)
*
*******************************************************/
function viewImg(obj, img_name)
{
         var img_path = eval("document.all."+img_name);
         alert(obj.value);
         img_path.src = obj.value;

         return;
}

/*******************************************************
*
* Function : flashView
* Introduce: 플래시 무비 삽입 함수
* param    : fURL(플래시 경로)
*            pWidth (플래시 가로 사이즈)
*            fHeight(플래시 세로 사이즈)
*
*******************************************************/
function flashView(fURL,pWidth,fHeight)
{
	var str = '';
	str += '<OBJECT width="'+ pWidth +'" height="'+ fHeight +'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="middle" id="flashview">';
	str += '<PARAM name="movie"   value="'+ fURL +'" />';
	str += '<PARAM name="quality" value="high" />';
	str += '<PARAM name="menu"    value="false" />';
	str += '<PARAM name="allowScriptAccess"    value="always" />';
	str += '<PARAM name="wmode"   value="transparent"> ';
	str += '<EMBED id="flashview" width="'+ pWidth +'" height="'+ fHeight +'" src="'+ fURL +'" quality="high" bgcolor="#ffffff" swLiveConnect="true" allowScriptAccess="always" align="middle" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />';
	str += '</OBJECT>';

	document.write(str);
}
/*******************************************************
*
* Function : flvflashView
* Introduce: 플래시 무비 삽입 함수
* param    : fURL(플래시 경로)
*            pWidth (플래시 가로 사이즈)
*            fHeight(플래시 세로 사이즈)
*
*******************************************************/
function flvflashView(fURL,pWidth,fHeight)
{
	var str = '';
	str += '<OBJECT width="'+ pWidth +'" height="'+ fHeight +'" type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="middle">';
	str += '<PARAM name="movie"   value="'+ fURL +'" />';
	str += '<PARAM name="allowScriptAccess"   value="sameDomain" />';
	str += '<PARAM name="scale"   value="noScale" />';
	str += '<PARAM name="quality" value="high" />';
	str += '<PARAM name="menu"    value="false" />';
	str += '<PARAM name="wmode"   value="transparent"> ';
	str += '<PARAM name="flashvars"   value="baseURL=http://www.i-challenge.co.kr&videoFile=/flv_player/flv/tooth.flv&loop=false&splashImageFile=/flv_player/preview.jpg"> ';
	str += '<EMBED width="'+ pWidth +'" height="'+ fHeight +'" src="'+ fURL +'" quality="high" allowscriptaccess="sameDomain" bgcolor="#ffffff" align="middle" scale="noScale" wmode="transparent" flashvars="baseURL=http://www.i-challenge.co.kr&videoFile=/flv_player/flv/tooth.flv&autoPlay=false&splashImageFile=/flv_player/preview.jpg" />';
	str += '</OBJECT>';

	document.write(str);
}


function mncast_move(fURL,pWidth,fHeight)
{
	var str = '';
	str += '<EMBED width="'+ pWidth +'" height="'+ fHeight +'" src="'+ fURL +'" allowScriptAccess="never" type="application/x-shockwave-flash" />';

	document.write(str);
}


/*******************************************************
*
* Function : wmvView
* Introduce: wmv 무비 삽입 함수
* param    : wURL(무비파일 경로)
*            wWidth (가로 사이즈)
*            wHeight(세로 사이즈)
*
*******************************************************/
function wmvView(wURL,wWidth,wHeight)
{
	var str = '';
	str += '<OBJECT ID="Player" standby="Loading Windows Media Player components..." width="'+ wWidth +'" height="'+ wHeight +'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT>';
	//str += '<OBJECT id="Player" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,0701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="'+ wWidth +'" height="'+ wHeight +'">';
	str += '<PARAM name="URL"   value="'+ wURL +'" />';
	//str += '<PARAM name="filename"   value="'+ wURL +'" />';
	str += '<PARAM name="autoStart" value="1" />';
	str += '<PARAM name="playCount" value="3" />';
	str += '<PARAM name="uiMode" value="mini"> ';
	str += '<PARAM name="stretchToFit" value="1"> ';
	str += '<PARAM name="fullScreen" value="0"> ';
	str += '<PARAM name="displaySize" value="0"> ';
	str += '<PARAM name="enabled" value="1"> ';
	str += '<PARAM name="enableContextMenu" value="1"> ';
	str += '</OBJECT>';

	document.write(str);
}

function wmvView5(wURL,wWidth,wHeight)
{
	var str = '';
	str += '<OBJECT id="Player" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,0701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="'+ wWidth +'" height="'+ wHeight +'">';
	str += '<PARAM name="filename"   value="'+ wURL +'" />';
	str += '<PARAM name="AutoStart" value="true" />';
	str += '<PARAM name="AutoSize" value="true" />';
	str += '<PARAM name="ShowControls" value="true" />';
	str += '<PARAM name="ClickToPlay" value="true" />';
	str += '<PARAM name="ShowTracker" value="true" />';
	str += '<PARAM name="ShowDisplay" value="false" />';
	str += '<PARAM name="ShowStatusBar" value="false" />';
	str += '<PARAM name="EnableContextMenu" value="true" />';
	str += '<PARAM name="AutoRewind" value="true" />';
	str += '<PARAM name="PlayCount" value="-1" />';
	str += '</OBJECT>';

	document.write(str);
}

/*******************************************************
*
* Function : onlyNumber
* Introduce: 숫자만 입력받게하는 함수
* param    : 
* tip      : 해당 기능을 사용할 form에 아래와 같은 문구 삽입
*            onkeypress=onlyNumber() style="IME-MODE:disabled"
*
*******************************************************/
function onlyNumber() 
{
         var whichCode = (window.Event) ? event.which : event.keyCode;
         if (((whichCode<48)||(whichCode>57)) && whichCode!=44 && whichCode!=8 && whichCode!=46)
         {
             event.returnValue=false;
         }
}

/*****************************************************
*
* Function : validNumber
* Introduce: 주민등록번호 유효성 체크
* param    : sno1 (주민번호 앞자리)
*            sno2 (주민번호 뒷자리)
*
*****************************************************/
function validNumber(sno1,sno2) 
{ 
         var false1,false2,false3;
         var serialValue        = sno1 + "-" + sno2; 

         //날짜 유효성 검사 
         birthYear         = (serialValue.charAt(7) <= "2") ? "19" : "20"; 
         birthYear        += serialValue.substr(0, 2); 
         birthMonth        = serialValue.substr(2, 2) - 1; 
         birthDate         = serialValue.substr(4, 2); 

         var birth         = new Date(birthYear, birthMonth, birthDate); 

         if ((birth.getYear() % 100 != serialValue.substr(0, 2)) || 
             (birth.getMonth() != birthMonth) || (birth.getDate() != birthDate)) 
         { 
            return false; 
         } 

         //코드 유효성 검사 
         var buf = new Array(13); 
         for (var i = 0; i < 6; i++) buf[i] = parseInt(serialValue.charAt(i)); 
         for (var i = 6; i < 13; i++) buf[i] = parseInt(serialValue.charAt(i + 1)); 

         var multipliers = [2,3,4,5,6,7,8,9,2,3,4,5]; 

         for (var i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]); 

         if ((11 - (sum % 11)) % 10 != buf[12]) return false; 

         return true;
}

/*****************************************************
*
* Function : validEmail
* Introduce: 올바른 이메일인지를 체크 틀리면 0을 리턴
* param    : string (이메일입력값)
*
*****************************************************/
function validEmail(string)
{
         var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
         var check=/@[\w\-]+\./;
         var checkend=/\.[a-zA-Z]{2,4}$/;

         if(((string.search(exclude) != -1)||(string.search(check)) == -1)||(string.search(checkend) == -1))
         {
            return 0;
         }
		 else 1;
}

String.prototype.trim = function() {
	return this.replace(/\s/g, "");
}


var intValue = '0123456789.';
var upperValue = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var lowerValue = 'abcdefghijklmnopqrstuvwxyz';
var etcValue = ' ~`!@#$%%^&*()-_=+\|[{]};:\'\",<.>/?';

// 한 글자가 영문 대문자인지 체크
function isUpper(value) {    
	var i;
	
	for(i = 0; i< upperValue.length; i++) {        
		if(value == upperValue.charAt(i)) {
			return true;
		}
	}
	
	return false;
}

// 한 글자가 영문 소문자인지 체크
function isLower(value) {    
	var i;
	
	for(i = 0; i < lowerValue.length; i++) {
		if(value == lowerValue.charAt(i)) {
			return true;
		}
	}
	
	return false;
}

// 한 글자가 숫자인지 체크
function isInt(value) {    
	var j;
	
	for(j = 0; j < intValue.length; j++) {
		if(value == intValue.charAt(j)) {
			return true;
		}
	}
	
	return false;
}

// 한 글자가 특수문자인지 체크
function isEtc(value) {    
	var j;
	
	for(j = 0; j < etcValue.length; j++) {
		if(value == etcValue.charAt(j)) {
			return true;
		}
	}
	
	return false;
}


function getBytes(str) {    
	var i, ch, bytes;
	var app, isNe = 0;

	if(str == '') {
		return 0;
	}

	app = navigator.appName;
	
	if(app == 'Netscape') {
		isNe = 1;
	}

	for(i = 0, bytes = 0; i < str.length; i++) {
		ch = str.charAt(i);

		if(isInt(ch)) {
			bytes++;            
		} else if(isLower(ch)) {
			bytes++;
		} else if(isUpper(ch)) {
			bytes++;
		} else if(isEtc(ch)) {
			bytes++;
		} else {
			bytes += 2;
		  
			if(isNe) {
				i++;
			}
		}
	}
	
	return bytes;
}

