// JavaScript Document For NJ Acedemy

// INDEX FUNCTIONS
	var is_banner_folded = false;
	
	function banner_toggle()
	{
		var banner = document.getElementById("main_banner");
		var banner_showing = banner.style.display;
		
		if (banner_showing == "none")
		{
			banner.style.display = "block";
			window.name = "showing";
		}
		else
		{
			banner.style.display = "none";
			window.name = "not_showing";
		}
	}
	
	function banner_check()
	{
		var banner = document.getElementById("main_banner");
		if(window.name == "not_showing")
		{
			banner.style.display = "none";
		}
		else
		{
			banner.style.display = "block";
		}
	}		
	function showBanner(theBannerId)
	{
		document.getElementById("nja_banner_default").style.display = "none";
		document.getElementById("nja_banner_handle").style.display = "none";
		
		document.getElementById("nja_ew").style.display = "none";
		document.getElementById("nja_rf_jei").style.display = "none";
		document.getElementById("nja_rf_music").style.display = "none";
		
		if(theBannerId == "nja_banner_default")
		{
			document.getElementById("nja_banner_handle").style.display = "block";
			document.getElementById("nja_content").style.top = "150px";
			is_banner_folded = true;
		}
		else
		{
			document.getElementById(theBannerId).style.display = "block";
			document.getElementById("nja_content").style.top = "363px";
		}
		
		return;
	}
	
	function foldBanner()
	{
		if(is_banner_folded)
		{
			document.getElementById("nja_banner_default").style.display = "block";
			document.getElementById("nja_banner_handle").style.display = "none";
			document.getElementById("nja_content").style.top = "363px";
			is_banner_folded = false;
		}
		else
		{
			document.getElementById("nja_banner_default").style.display = "none";
			document.getElementById("nja_banner_handle").style.display = "block";
			document.getElementById("nja_content").style.top = "150px";
			is_banner_folded = true;
		}
		return;
	}
	
	function showCalendar(theRoot)
	{
		document.write('<iframe src="'+theRoot+'calendar/index.php" class="nja_calendar_iframe" frameborder="0"></iframe>');
		return;
	}
/* BULLETIN INDEX TAB ROTATION */

	var nja_index_rotiation;
	var bulletin_current_tab_index = 0;
	
	function bulletin_tab_rotation()
	{
		bulletin_show_next_tab(bulletin_current_tab_index);
		nja_index_rotiation = setTimeout("bulletin_tab_rotation()", 3000);
		return;
	}
	
	function stop_bulletin_tab_rotation(theTabIndex)
	{
		clearTimeout(nja_index_rotiation);
		showBulletinTab(theTabIndex);
		return;
	}
	
	function bulletin_show_next_tab(theTabIndex)
	{
		showBulletinTab(theTabIndex);
		bulletin_current_tab_index++;
		bulletin_current_tab_index = bulletin_current_tab_index % bulletin_tab_id_array.length;
		return;
	}
	
	function showBulletinTab(tabIndex)
	{
		
		for(var i in bulletin_tab_id_array)
		{
			document.getElementById(bulletin_tab_id_array[i]).style.zIndex = 2;
			document.getElementById(bulletin_tab_id_array[i]+"_content").style.zIndex = 2;
		}
		
		document.getElementById(bulletin_tab_id_array[tabIndex]).style.zIndex = 4;
		document.getElementById(bulletin_tab_id_array[tabIndex]+"_content").style.zIndex = 3;
		
		bulletin_current_tab_index = tabIndex;
		bulletin_current_tab_index = bulletin_current_tab_index % bulletin_tab_id_array.length;
	}
	
/* FORM MAIL CHECK FUNCTION */
	
	function checkFormMail(theForm)
	{
		// CHECK NAME
		if(theForm.fm_name.value.length <= 0)
		{
			alert("Please enter your name.");
			theForm.fm_name.focus();
			return false;
		}
		
		// CHECK E-MAIL ADDRESS
		if(theForm.fm_email.value.length <= 0)
		{
			alert("Please enter your e-mail address.");
			theForm.fm_email.focus();
			return false;
		}
		
		// CHECK PHONE NUMBER
		if(theForm.fm_phone.value.length <= 0)
		{
			alert("Please enter your phone number.");
			theForm.fm_phone.focus();
			return false;
		}
		
		// CHECK CONTENT
		if(theForm.fm_content.value.length <= 0)
		{
			alert("Please enter your questions or comments.");
			theForm.fm_content.focus();
			return false;
		}
		
		return true;
	}
	
/*
	JAVASCRIPT FUNCTION FOR USING PNG-24 IMAGE IN IE6
	
	TO USE PNG-24 IMAGE IN <IMG> TAG, USE THIS FUNCTION WITH CLASS STYLE BELOW:
	.(CLASSNAME) {
		tmp:expression(setPng24(this));
	}
	
	TO USE PNG-24 IMAGE AS BACKGROUND, USE CLASS STYLE BELOW:
	.(TARGET CLASSNAME) {
		background:url(PNG24_PATH);
		_background:none;
		_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='PNG24_PATH',sizingMethod='crop');
	}
*/
	
	function setPng24(obj)
	{
		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 '';
	}
	
/* FORM FIELD CHECK */

	function checkFormFields(theForm, bbs_code)
	{
		if(theForm.bd_name != null && theForm.bd_name.value.length <= 0)
		{
			alert("Please enter your name.");
			theForm.bd_name.focus();
			return false;
		}
		
		if(theForm.bd_pass != null && theForm.bd_pass.value.length <= 0)
		{
			alert("Please enter the password.");
			theForm.bd_pass.focus();
			return false;
		}
		
		if(theForm.bd_email != null && theForm.bd_email.value.length <= 0)
		{
			alert("Please enter your e-mail address.");
			theForm.bd_email.focus();
			return false;
		}
		
		if(theForm.bd_subject != null && theForm.bd_subject.value.length <= 0)
		{
			if(bbs_code == "bulletin")
			{
				alert("Please enter the subject address.");
			}
			else if(bbs_code == "staffs")
			{
				alert("Please enter the staff name address.");
			}
			theForm.bd_subject.focus();
			return false;
		}
		
		if(theForm.bd_content != null && theForm.bd_content.value.length <= 0)
		{
			alert("Please enter the content.");
			theForm.bd_content.focus();
			return false;
		}
		
		return true;
	}
	
	function checkAllFormFields(theForm)
	{
		for(var i=0; i<theForm.length; i++)
		{
			if(theForm[i].name.length && theForm[i].value.length <= 0)
			{
				alert("Please enter the "+theForm[i].name+".");
				theForm[i].focus();
				return false;
			}
		}
		
		return true;
	}
