var menu_qty = 20;
var noSubMenu = new Array();

noSubMenu[0] = 1;
//noSubMenu[1] = 2;
noSubMenu[2] = 3;
noSubMenu[3] = 4;
noSubMenu[4] = 5;
noSubMenu[5] = 6;
noSubMenu[6] = 8;
noSubMenu[7] = 9;

function selectMenu (mark) {
	var noShowSubmenu = false;
	for (i in noSubMenu) if (noSubMenu[i] == mark) noShowSubmenu = true;
	
	hideAllSubmenu ();
  
	document.getElementById('td_menu_'+mark).style.backgroundImage = "url(/images/"+color_theme+"/menu_bg_sel.jpg)";
	
	if (noShowSubmenu == false) {
		document.getElementById('div_menu_'+mark).style.backgroundImage = "url(/images/"+color_theme+"/select_menu_arrow.jpg)";
		document.getElementById('div_submenu_'+mark).style.display = "block";
	}
}


function hideAllSubmenu () {
	for (i = 1; i <= menu_qty; i++) {
		try {
            
            document.getElementById('td_menu_'+i).style.backgroundImage = "";
    		document.getElementById('div_menu_'+i).style.backgroundImage = "";
    		document.getElementById('div_submenu_'+i).style.display = "none";
        }
        catch(e) {
   
        }
	}
    

}


function changeColorTheme(theme) {
	color_theme = theme;
	hideAllSubmenu();
	
	document.getElementById('css_color_theme').href = '/css/'+theme+'.css';
	
	document.getElementById('color_theme_circle_grunt').src = "/images/grunt/color_theme_grunt.jpg";
	document.getElementById('color_theme_circle_green').src = "/images/green/color_theme_green.jpg";
	document.getElementById('color_theme_circle_hard').src = "/images/hard/color_theme_hard.jpg";
	
	document.getElementById('color_theme_circle_'+theme).src = "/images/"+theme+"/color_theme_"+theme+"_sel.jpg";
	
	
	//alert(base_url);
	var url = theme_url + "?theme="+theme;
    
   // document.write(url);
 
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.getElementById('js').appendChild(jsel);

}



function showNotice() {
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "300";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('notice_div').style.left = left+"px";
	document.getElementById('notice_div').style.top = top+"px";
	
	document.getElementById('notice_div').style.display = "block";
}



function closeNotice() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('notice_div').style.display = "none";
}



function showRegistrationForm() {
	closeLogin();
	
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "205";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('registration_block_div').style.left = left+"px";
	document.getElementById('registration_block_div').style.top = top+"px";
	
	document.getElementById('registration_block_div').style.display = "block";
}



function closeRegistration() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('registration_block_div').style.display = "none";
}




function showLogin() {
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('login_block_div').style.left = left+"px";
	document.getElementById('login_block_div').style.top = top+"px";
	
	document.getElementById('login_block_div').style.display = "block";
}





function closeLogin() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('login_block_div').style.display = "none";
}



function showForgotPassword() {
	closeLogin()
	
	document.getElementById('div_trans').style.height = document.body.scrollHeight+"px";
	document.getElementById('div_trans').style.display = "block";
	//alert(2);
	var width = "330";
	var height = "200";
	var left = (screen.width  - width)  / 2;
	var top = (screen.height - height) / 3 + document.body.scrollTop;

	document.getElementById('forgot_password_block_div').style.left = left+"px";
	document.getElementById('forgot_password_block_div').style.top = top+"px";
	
	document.getElementById('forgot_password_block_div').style.display = "block";
}





function closeForgotPassword() {
	document.getElementById('div_trans').style.display = "none";
	document.getElementById('forgot_password_block_div').style.display = "none";
}


function changeHeight() {
	document.getElementById('main_tbl').style.height = (window.innerHeight - 55 - 114) + "px";
	//alert();
}


function commentToPlain(id) {
	document.getElementById('td_commet_mark_plain').className = "comment_area_sel";
	document.getElementById('td_commet_mark_editor').className = "comment_area";
	switchToPlain(id);
}


function commentToEditor(id) {
	document.getElementById('td_commet_mark_plain').className = "comment_area";
	document.getElementById('td_commet_mark_editor').className = "comment_area_sel";
	switchToEditor(id);
}


var switch_to_rte = 0;

function switchToEditor(id) {
	var textArea = id;
	
	if(document.getElementById(textArea + '___Frame'))
	var editor_frame = document.getElementById(textArea + '___Frame');
	
	if( !editor_frame ) {
		var div = document.getElementById(id);
		var height = document.getElementById(id).style.height;
		var width = document.getElementById(id).style.width;
		var oEditor = new FCKeditor(id);
		oEditor.BasePath = "/library/FCKeditor/";
		oEditor.ToolbarSet = "BasicBlock";
		oEditor.Width = width;
		oEditor.Height = height;
		oEditor.ReplaceTextarea();
	}
	else {
		if (typeof(FCKeditorAPI) == 'undefined') return;
		var oEditor = FCKeditorAPI.GetInstance(textArea);
		editor_frame.style.display = "block";
		document.getElementById(textArea).style.display = "none";
		var editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea');
		oEditor.EditorDocument.body.innerHTML = document.getElementById(textArea).value;
		oEditor.Focus();
	}
	switch_to_rte = 1;
}



function switchToPlain(id) {
	var textArea = id;
	var txtarea = document.getElementById(textArea);
	
	
	if ( typeof(FCKeditorAPI) == 'undefined' ) return;
	var oEditor = FCKeditorAPI.GetInstance(textArea);
	if (! oEditor) return;
	var editor_frame = document.getElementById(textArea + '___Frame');
	var editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea');
	var html = oEditor.GetXHTML(false);
	editor_frame.style.display = "none";
	txtarea.style.display = "block";
	txtarea.value = html;
	txtarea.focus();
	switch_to_rte = 0;
}
