function countdown() {
	if (count > 0) {
		count--;
		if(count <= 0) {
			$('#downloadBtn').show();
			$('#counter').hide();
			$('.btn2').show(500);
		}
		if(count > 0){
			$('#downloadMsg').hide();
			$('#downloadBtn').hide();
			$('#counter').text(count);
			setTimeout('countdown()',1000);
		}
	}
}

function getKey() {
	if(!$("#downloadKey").val()) {
		$("#downloadMsg").text('비회원과 일반회원은 체크숫자를 입력하셔야 합니다.');
		$("#downloadKey").focus();
	} else {
		$.post("/bin/checkdownload.php","downloadKey="+$("#downloadKey").val()+"&fileKey="+$("#fileKey").val(),function(data) {
			if(data != 'error') {
				$("#downloadKey2").val(data);
				countdown();
			} else {
				$("#downloadMsg").text('체크 숫자가 일치하지 않습니다. 다시 입력해주세요');
				$("#downloadKey").focus();
			}
		});
	}
	return false;
}

function goDown() {

	exefield.location.replace("/null.html");
	
	if( $("#downloadDirectKey").val() ) {
		exefield.location.href='http://download.filenavi.com/filenavi.php?file='+$("#downloadDirectKey").val();
		//$("#downloadBtn").hide();
		$('#downloadMsg').text('다운로드 중입니다').show();
	} else {
		$("#downloadMsg").text('오류입니다. 다시 시작해주십시오').show();
	}
}

function goDownLink() {

	exefield.location.replace("/null.html");

	if( $("#downloadDirectKey").val() ) {
//		exefield.location.href='http://download.filenavi.com/filenavi.php?file='+$("#downloadKey2").val();
		exefield.location.replace('http://download.filenavi.com/filenavi.php?file='+$("#downloadDirectKey").val());
		//$("#downloadBtn").hide();
		$('#downloadMsg').text('다운로드 중입니다').show();
	} else {
		$("#downloadMsg").text('다운받을 파일을 선택해주십시오').show();
	}
}


function checkFileNo(vals) {
	$("#downloadKey2").val( vals);
}


function Go_down(val) {
	exefield.location.replace("/null.html");
	exefield.location.href='http://download.filenavi.com/filenavi.php?file='+val;
	$('#downloadMsg').text('다운로드 중입니다').show();
}

function multi_down() {
	if(!$.browser.msie ) {
		alert('죄송합니다.\n\n멀티 다운로드는 MS 인터넷 익스플로러에서만 사용가능합니다.');
	} else {
		var f = $("#folder_move")[0];
		f.target = "exefield";
		f.action = "/ax/call.php";
		f.submit();
	}
}

function chk_direct_pass(link) {
	if(!$("#direct_pass").val()){
			alert('비밀번호를 입력하세요!!');
			$("#direct_pass").focus();
			return;
	}

	$.post("/download_direct_chk.php", { pass : $("#direct_pass").val() , link : link } , function(data){
			var data_array = data.split('||');
			if(data_array[0] == 'ok'){
				$("#ok_pass").html(data_array[1]);
			}else{
				alert('비밀번호가 다릅니다!!');
				$("#direct_pass").val("");
				$("#direct_pass").focus();
			}
	});
}

function check_m_pass(mlink) {
	if(!$("#m_pass").val()){
			alert('비밀번호를 입력하세요!!');
			$("#m_pass").focus();
			return;
	}

	var f = $("#folder_move")[0];
	f.submit();
	
}

$(function(){
	$('#chkall').click(function(){
		if( $(this).attr('checked') == '' )
			$('.download_table input[type=checkbox]').attr('checked','');
		else
			$('.download_table input[type=checkbox]').attr('checked','checked');
	});
});