
function moveFocus(num,fromform,toform)
{
	var str = fromform.value.length;
	if(str == num)
		toform.focus();
}
function checkSpace( str )
{
     if(str.search(/\s/) != -1){
     	return 1;
     }

     else {
         return "";
     }
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function goList(){
   sform.exclude.value="1";
   sform.submit();
}

var timer_clear_num = 0;
var timer;

var g_BrowserWidth	= window.innerWidth;
var g_hasLayers		= (document.layers);
var g_hasAll		= (document.all);
var g_hasGetElement = (document.getElementById);

var IE40 = (navigator.appVersion.indexOf("MSIE 4.0") >= 0);
var IE45 = (navigator.appVersion.indexOf("MSIE 4.5") >= 0);
var NS7  = ((navigator.userAgent.indexOf("Netscape/7") >= 0) || (navigator.userAgent.indexOf("Safari") >= 0));
var NS6  = (!g_hasAll && g_hasGetElement);	// this test is positive for NS7 also

var g_sepText;
if (g_hasGetElement || g_hasAll) {
	if (IE40)
		g_sepText = "<font color='#999999' size='1'>&nbsp;|&nbsp;</font>";
	else
		g_sepText ="<span class='subNav' style='color:#999999'>&nbsp;|&nbsp;</span>";
} else if (g_hasLayers) {
	g_sepText = "&nbsp;|&nbsp;";
}

function showDDNav(itemId) { 
	var obj = document.getElementById(itemId);
	obj.style.display = 'block'
}

function hideDDNav(itemId) {
	var obj = document.getElementById(itemId);
	obj.style.display = 'none';
}

function reSize() 
{
	try{
			var objBody = Category.document.body;
			var objFrame = document.all["Category"];
			ifrmHeight = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);

			if (ifrmHeight > 10) 
			{
			   objFrame.style.height = ifrmHeight
			}
			else
			{
			   objFrame.style.height = 10;
			}
			objFrame.style.width = '180';
        }catch(e){}
}

function init_iframe() 
{
	reSize();

	if(timer_clear_num >= 100) {		// 1초 후 타이머 clear
		clearTimeout(timer);
	} else {
		timer_clear_num++;
		timer = setTimeout('init_iframe()',100);
	}
}
init_iframe();

function window_open(width, height, name, url)
{
     window.open(url,name,"width="+width+" height="+height+" left=0 top=0 scrollbars=1"); 
}



function window_open_detail( url, name, width, height, left, top, menubar, toolbar, locate, status, scrollbars, resize ){

	var vEnvOption = "";

	if( left != "" ){ vEnvOption += " ,left=" + left; }
	if( top != "" ){	 vEnvOption += " ,top=" + top; }
	if( menubar != "" ){ vEnvOption += " ,menubar=" + menubar; }
	if( toolbar != "" ){ vEnvOption += " ,toolbar=" + toolbar; }
	if( locate != "" ){ vEnvOption += " ,location=" + locate; }
	if( status != "" ){ vEnvOption += " ,status=" + status; }
	if( scrollbars != "" ){ vEnvOption += " ,scrollbars=" + scrollbars; }
	if( resize != "" ){ vEnvOption += " ,resize=" + resize; }


	window.open( url, name, "width=" + width + " height=" + height + " " + vEnvOption ); 
}



var ck_mode = 0;
function all_select()
{
    var form = document.forms.list_form;
	if(ck_mode == 0)
	{
		flage1 = false;
		flage2 = true;
		this.btn_display.src="/common/images/img/btn_lbox_unlock.gif";
		this.btn_display2.src="/common/images/img/btn_lbox_unlock.gif";
		ck_mode = 1;
	}
	else
	{
		flage1 = true;
		flage2 = false;
		this.btn_display.src="/common/images/img/btn_allselec.gif";
		this.btn_display2.src="/common/images/img/btn_allselec.gif";
		ck_mode = 0;	
	}
    for(var i=0; i< form.length; i++)
	{
		if(form[i].checked == flage1)
		{
			form[i].checked=flage2;
		}
	}	
}

var ck_mode = 1;
function all_select_cart()
{
    var form = document.forms.list_form;
	if(ck_mode == 0)
	{
		flage1 = false;
		flage2 = true;
		this.btn_display.src="/common/images/sound/sound_bt_cancel.jpg";
		this.btn_display2.src="/common/images/sound/sound_bt_cancel.jpg";
		ck_mode = 1;
	}
	else
	{
		flage1 = true;
		flage2 = false;
		this.btn_display.src="/common/images/sound/sound_bt_selec.jpg";
		this.btn_display2.src="/common/images/sound/sound_bt_selec.jpg";
		ck_mode = 0;	
	}
    for(var i=0; i< form.length; i++)
	{
		if(form[i].checked == flage1 && form[i].name != "chkTextCopy")
		{
			form[i].checked=flage2;
		}
	}	
}

function all_select_one()
{
    var form = document.forms.list_form;
	if(ck_mode == 0)
	{
		flage1 = false;
		flage2 = true;
		this.btn_display.src="/images/common/select_all_off.gif";
		ck_mode = 1;
	}
	else
	{
		flage1 = true;
		flage2 = false;
		this.btn_display.src="/images/common/select_all_on.gif";
		ck_mode = 0;	
	}
    for(var i=0; i< form.length; i++)
	{
		if(form[i].checked == flage1)
		{
			form[i].checked=flage2;
		}
	}
}
function del_select(act_url)
{
	var form = document.forms.list_form;
	var cnt = 0;

	for(var i=0; i< form.length; i++)
	{
		if(form[i].checked == true)
		{
			cnt++;
		}
	}
	if(cnt==0)
	{
		alert("컨텐츠를 선택하세요.");
	}
	else
	{
		 var mycon = confirm("선택한 컨텐츠를 삭제하겠습니까?");
		 if(mycon == true)
		 {
			document.list_form.target = "hiddenframe";
			document.list_form.action = act_url;
			document.list_form.submit();
		 }
	}
}


function all_input(cnt)
{
	var form = document.forms.list_form
	var check_cnt = 0;
    for(var i=0; i< form.length; i++)
	{
		//if(eval("form.check"+i+".checked") == true)
		if(form[i].checked==true)
		{
			check_cnt++;
		}
	}
	if(check_cnt == 0)
	{
		alert("이미지를 체크하세요.");
		return;
	}
        list_form.target = "pop_result";
	    list_form.action="./pop_result.php/?cnt="+cnt;
        win=window.open(list_form.action,list_form.target,"width=540 height=350 left=0 top=0 scrollbars=yes");
        list_form.submit();
		win.window.focus();
}



// 컨텐츠 프리뷰 창
function cont_detail(cmd, cont_seq, cont_code, mem_flag, cont_group, cont_type, cont_flag, premium_flag, offset, SearchSort, search, SearchFilter, tot_count, update_seq, mode, PanelNumber)
{
	if( PanelNumber == undefined )
		PanelNumber = 0;

	// 사운드 상품일 경우 창 크기를 작게 만들어 준다.
	if( cont_group == "unitsound" ){

		//win=window.open(url, 'it_cont_detail_unisound', 'left=20, top=20, width=670, height=382, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0');
		fncUnitSoundDetail( cont_seq );

	}else{

		url = '/search/preview.php?cmd='+cmd+'&cont_seq=' + cont_seq + '&cont_code='+cont_code+'&mem_flag=' + mem_flag + '&cont_group=' + cont_group + '&cont_type=' + cont_type + '&cont_flag='+cont_flag+'&premium_flag='+premium_flag+'&offset='+offset+'&SearchSort='+SearchSort+'&SearchFilter='+SearchFilter+'&search='+search + '&tot_count=' + tot_count + '&update_seq=' + update_seq + '&mode=' + mode + '&PanelNumber=' + PanelNumber;

		win=window.open(url, 'it_cont_detail', 'left=20, top=20, width=950, height=747, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1');
		win.window.focus();
	}

}

// 슬라이드 창
function view_slideshow(cont_group, cont_type, cont_flag, offset, SearchSort, search, SearchFilter, cmd, update_seq, mode)
{
	url = '/search/slideshow_full.php?cont_group=' + cont_group + '&cont_type=' + cont_type + '&cont_flag='+cont_flag+'&offset='+offset+'&SearchSort='+SearchSort+'&SearchFilter='+SearchFilter+'&search='+search+'&cmd='+cmd+'&update_seq='+update_seq+'&mode='+mode;
	win=window.open(url, 'slidershow', 'left=20, top=20, width=1210, height=928, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1');
	//win=window.open(url, 'slidershow', 'fullscreen=yes,menubar=no,status=no,toolbar=no,titlebar=no,scrollbar=no,location=no,directories=no');
	win.window.focus();
}




//------------------------------------------------------------------------
// 사운드 재생 관련 함수

var nowTime;
var totalTime;
var isInterval = false;
var Player;
var id;
var p_list_cont_idx;
var sound_status;

// 음악 재생
function playMusic()
{

	var sound_bg = document.getElementById("sound_bg_" + p_list_cont_idx);
	var sound_bt = document.getElementById("sound_bt_" + p_list_cont_idx);
	var sound_ico = document.getElementById("sound_ico_" + p_list_cont_idx);
	var sound_time = document.getElementById("sound_time_" + p_list_cont_idx);
	
	sound_bg.style.background = 'url( /common/images/img/sound_bg_play.gif )';
	sound_bt.src = '/common/images/img/btn_s_hear_off.gif';
	sound_ico.src = '/common/images/img/ico_sound_stop.gif';
	sound_time.style.display = '';

	Player.Play();
}


// 음악 정지
function stopMusic()
{
	if (p_list_cont_idx)
	{
		var sound_bg = document.getElementById("sound_bg_" + p_list_cont_idx);
		var sound_bt = document.getElementById("sound_bt_" + p_list_cont_idx);
		var sound_ico = document.getElementById("sound_ico_" + p_list_cont_idx);
		var sound_time = document.getElementById("sound_time_" + p_list_cont_idx);
		
		sound_bg.style.background = 'url( /common/images/img/sound_bg_stop1.gif )';
		sound_bt.src = '/common/images/img/btn_s_hear_on.gif';
		sound_ico.src = '/common/images/img/ico_sound_play.gif';
		sound_time.style.display = 'none';

		clearInterval( id );
		Player.Stop();
	}
	return false;
}

function startPlay(v_list_cont_idx)
{
	Player = document.all.Player;
	stopMusic();

	p_list_cont_idx = v_list_cont_idx;

	addr = document.getElementById("FileName_" + p_list_cont_idx).value;

	Player.Filename = addr;

	// 노래 제목 삽입
	//titleDiv.innerHTML = Player.currentMedia.name;

	// 변경된 프로그레스바 크기 지정
	//progressBarWidth = document.getElementById("progress_td").clientWidth;

	// 프로그레스바 초기화
	//showProgressBar(0);

	// 음악 재생
	playMusic();

	// 볼륨조절 슬라이더 셋팅
	//slider.setValue( getVolume() );

	// 반복 체크 값 true
	isInterval = true;

	startTimeInterval(); // 재생시간 보기
}


// 반복적으로 재생시간을 보여주는 함수를 실행
function startTimeInterval()
{
	id = setInterval( "showPlayTime()", 1000 );
}


// 재생시간 출력
function showPlayTime() {
	try
	{
		nowTime   = Player.currentPosition; // 현재 재생시간 추출
		totalTime = Player.duration; // 총 재생시간 추출

		if (nowTime == 0) {
			stopMusic();
		}

		document.getElementById("nowTimeDiv_" + p_list_cont_idx).innerHTML  = changeTimeType( nowTime );
		document.getElementById("fullTimeDiv_" + p_list_cont_idx).innerHTML = changeTimeType( totalTime );

		// 재생바 출력
		//percentage = Math.floor( ( nowTime / totalTime ) * 100 );
		//showProgressBar( percentage );
	}
	catch( e )
	{
		if( isInterval == true )
		{
			stopMusic(p_list_cont_idx);
			alert("재생 가능한 파일이 아닙니다.");

			clearInterval( id );
			isInterval = false;
		}
	}
}

/*
	초로 되어있는 시간을 분/초 나눠서 보여줌
	@param time 초단위의 재생시간
*/
function changeTimeType( time ) {

	var result;

	// 시간이 1분 초과했을 경우
	if( time >= 0 ) {
		result = Math.floor( time / 60 ) + ":";

		if( time % 60 != 0 ) result += Math.round(time % 60);

	} else {

		result = time;
	}

	return result;
}

function soundProc(v_list_cont_idx) {

	if(sound_status == 'Y'){
		if(v_list_cont_idx == p_list_cont_idx)
			stopMusic(v_list_cont_idx);
		else
			startPlay(v_list_cont_idx);

		sound_status = 'N';
	} else {
		startPlay(v_list_cont_idx);
		sound_status = 'Y';
	}
}
//------------------------------------------------------------------------












//------------------------------------------------------------------------
// 사운드 - 퀵타임 플레이어 재생 관련 함수
var movie = null;
var duration = 0;
var readyInitialized = false;

var status = null;
var vIntervalID = null;


function initList() {
  movie = new pfQuicktime(document.mymovie);
}

function loopList( Seq ) {

  status = movie.getStatus();
//alert(status);
	if(status == 'ready') {
    if(!readyInitialized) {
      duration = getFormattedTimeString( movie.getDuration() );
      movie.setVolume(100);
      readyInitialized = true;
    }
    status = getFormattedTimeString( movie.getTime() );
		//alert(status);
    //document.getElementById('playback-display').innerHTML = status + " / " + duration + "  (Buffered: " + movie.getBufferStatus() + "%)";
    //document.getElementById('playback-display').innerHTML = status + " / " + duration;
    document.getElementById('playback-display-status_' + Seq).innerHTML = status;
    //document.getElementById('playback-display-duration_' + Seq).innerHTML = duration;
  } 
}



function loadVideoList( Seq ) {

	var vMovieURL = document.getElementById( 'movie-url' );
	vMovieURL.value = document.getElementById( 'movie-url_' + Seq ).value;


  movie.loadURL( document.getElementById( 'movie-url' ).value );
  readyInitialized = false;

}




// 사운드 박스 플레이어 플레이
function fncQuickPlayerPlay( Seq ){

	fncQuickPlayerStop();
	p_list_cont_idx = Seq;


	if( vIntervalID ){
		clearInterval( vIntervalID );
	}


  status = movie.getStatus();


  if( status == "ready" || status == "error" ){

    document.getElementById( "btQuickPlayerPlay_" + Seq ).style.display = "none";
    document.getElementById( "btQuickPlayerStop_" + Seq ).style.display = "";

  }else{

    document.getElementById( "btQuickPlayerPlay_" + Seq ).style.display = "";
    document.getElementById( "btQuickPlayerStop_" + Seq ).style.display = "none";

  }
//alert( movie );
  loadVideoList( Seq );
  movie.playVideo();


	vIntervalID = window.setInterval("loopList( '" + Seq + "' )", 1000);
}


// 사운드 박스 플레이어 Stop
function fncQuickPlayerStop(){

	if (p_list_cont_idx){

		status = movie.getStatus();

		if( status == "ready" || status == "error" ){

			document.getElementById( "btQuickPlayerPlay_" + p_list_cont_idx ).style.display = "";
			document.getElementById( "btQuickPlayerStop_" + p_list_cont_idx ).style.display = "none";

		}else{

			document.getElementById( "btQuickPlayerPlay_" + p_list_cont_idx ).style.display = "none";
			document.getElementById( "btQuickPlayerStop_" + p_list_cont_idx ).style.display = "";

		}

		clearInterval( vIntervalID );
		document.getElementById('playback-display-status_' + p_list_cont_idx).innerHTML = "00:00";

		movie.stopVideo();
		//movie.pauseVideo();

	}

}
//------------------------------------------------------------------------






// 유료 사운드 상세보기 창 오픈.
function fncUnitSoundDetail( arrayContSeq ) {

	//alert(p_list_cont_idx);
	//url = "/search/preview_unitsound.php?arrayContSeq=" + arrayContSeq;

	url = "/search/preview_unitsound.php";


	var f = document.createElement('form');
	var objs, value;
	value = arrayContSeq;


	objs = document.createElement('input');
	objs.setAttribute('type', 'hidden');
	objs.setAttribute('name', 'arrayContSeq');
	objs.setAttribute('value', value);
	f.appendChild(objs);


	f.setAttribute('target', 'it_cont_detail_unisound');
	f.setAttribute('method', 'post');
	f.setAttribute('action', url);

	document.body.appendChild(f);

	win = window.open( '', 'it_cont_detail_unisound', 'left=20, top=20, width=660, height=352, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0');

	f.submit();

	win.window.focus();


	//alert(p_list_cont_idx);

	if( p_list_cont_idx != null && movie != null ){
		//window.location.reload();
		//alert(movie);
		//movie.stopVideo();

		if( typeof( window["fncSoundBoxPlayerStop"] ) == "function" ){
			//alert("함수 존재");
			fncSoundBoxPlayerStop();
		}else{
			//alert("함수 존재 안함");
			fncQuickPlayerStop();
		}

	}

}





function all_check(index){
	var form = document.forms.list;
	if(index=="c"){
		for(var i = 0; i < form.length; i++) {
		//alert( form[i].name );
			if(form[i].type == "checkbox" && form[i].name != "chkTextCopy" ) {
				form[i].checked=true;
			}
		}
	}else{
		for(var i = 0; i < form.length; i++) {
			if(form[i].type == "checkbox" && form[i].name != "chkTextCopy" ) {
				form[i].checked=false;
			}
		}		
	}
}







// 장바구니 담기
function fncGoCart(cont_seq,cont_code,cmd,login_chk) {
	
	if(window.parent.bottomFrame)
	{
		if(!login_chk) {	// 로그인 체크
			alert('하단에서 로그인후 이용하세요.');
			resizeFrame_subhome('');
			return;
		}

		
		parent.bottomFrame.document.location.href="/mypage/to_cart.php?mode=search&cont_seq="+cont_seq+"&cont_code="+cont_code+"&cmd="+cmd;

	} else {
		var v_location = "/mypage/to_cart.php?mode=search&cont_seq="+cont_seq+"&cont_code="+cont_code+"&cmd="+cmd;
		document.all.master.src = v_location;
	}
}






function fncPixelToInteger( strPixel ){

	return strPixel.replace(/[^0-9]/g, '') * 1;

}



function follow_banner(div_id, origin_top, limit_top, margin_top){

	var d, t, s, g, target_height;
  origin_top *= 1;
  limit_top *= 1;
  margin_top *= 1;
  
  d = document.getElementById(div_id);
  s = document.body.scrollTop + "";
 
 target_height = fncPixelToInteger(s) + margin_top;
  if(target_height < limit_top) {
   target_height = origin_top;
  }
  
  t = fncPixelToInteger( d.style.top );
  
  if(t != target_height) {
   g = Math.ceil((t - target_height) / 5);
   if(g > 50) {
    g = 50;
   } else if (g < -50) {
    g = -50;
   }
   d.style.top = (t - g) + "px";
  }
  
  setTimeout("follow_banner('" + div_id + "', " + origin_top + ", " + limit_top + ", " + margin_top + ");", 1);
}
