var type_gl = "";
var type_flag = [0 , 0];

var c_id = 0;
var r_id = 0;
var n_id = 0;
var show_id = 0;

function td_select(elemID, mark){
	if ( (c_id != elemID) && (r_id != elemID) && (n_id != elemID)) {
		if (mark == 1) {
			document.getElementById(elemID).bgColor = '4d9de6';
		}
		else {
			document.getElementById(elemID).bgColor = '';
		}
	}
}
function td_select_c(elemID){
	if (c_id != 0) {
		document.getElementById(c_id).bgColor='';
	}
	c_id = elemID;
	document.getElementById(elemID).bgColor='0060b5';
	if (r_id != 0) {
		tr_show();
	}
}
function td_select_r(elemID){
	if (r_id != 0) {
		document.getElementById(r_id).bgColor='';
	}
	r_id = elemID;
	document.getElementById(elemID).bgColor='0060b5';
	if (r_id != 0) {
	tr_show();
	}
}
function td_select_c2(elemID){
	if (c_id != 0) {
		document.getElementById(c_id).bgColor='';
	}
	c_id = elemID;
	document.getElementById(elemID).bgColor='0060b5';
	if ((r_id != 0) && (n_id != 0)) {
		tr_show2();
	}
}
function td_select_r2(elemID){
	if (r_id != 0) {
		document.getElementById(r_id).bgColor='';
	}
	r_id = elemID;
	document.getElementById(elemID).bgColor='0060b5';
	if ((c_id != 0) && (n_id != 0)) {
		tr_show2();
	}
}
function td_select_n2(elemID){
	if (n_id != 0) {
		document.getElementById(n_id).bgColor='';
	}
	n_id = elemID;
	document.getElementById(elemID).bgColor='0060b5';
	if ((c_id != 0) && (r_id != 0)) {
	tr_show2();
	}
}
function tr_show() {
	if ((show_id != 0) && (document.getElementById(show_id) != null)) {
		document.getElementById(show_id).bgColor='';
	}
	show_id = c_id + "_" + r_id;
	if (document.getElementById(show_id) != null) {
		document.getElementById(show_id).bgColor='0060b5';
		hide('mark');
		show('mark2');
	}
	else {show('mark'); hide('mark2');}
}
function tr_show2() {
	if ((show_id != 0) && (document.getElementById(show_id) != null)) {
		document.getElementById(show_id).bgColor='';
	}
	show_id = c_id + "_" + r_id + "_" + n_id;
	if (document.getElementById(show_id) != null) {
		document.getElementById(show_id).bgColor='0060b5';
		hide('mark');
		show('mark2');
	}
	else {show('mark'); hide('mark2');}
}

function hide(elemID){
 var elem = document.getElementById(elemID);
 elem.style.display = "none";
}
function show(elemID){
 var elem = document.getElementById(elemID);
 elem.style.display = "block";
}

function set_type(num){
 if(num == 0) {
   var elem1 = document.getElementById('natur');
   var elem1_im = document.getElementById('natur_im');
   var elem2 = document.getElementById('synth');
   var elem2_im = document.getElementById('synth_im');
   type_gl = "natur";
   num2 = 1;
   im = 4;
 }
 if(num == 1){
   var elem1 = document.getElementById('synth');
   var elem1_im = document.getElementById('synth_im');
   var elem2 = document.getElementById('natur');
   var elem2_im = document.getElementById('natur_im');
   type_gl = "synth";
   num2 = 0;
   im = 3;
 }
 if(type_flag[num] == 0){
   elem1.style.textDecoration = "none";
   elem2.style.textDecoration = "underline";
   elem1_im.src = "images/circle_5.gif";
   elem2_im.src = "images/circle_"+im+".gif";
   type_flag[num] = 1;
   type_flag[num2] = 0;
 }
 show('menu');
 hide('submenu');
 hide('subsubmenu');
 hide('item');
}
 
function change_menu(elemID){
 var elem = document.getElementById(elemID);

 if(elem.style.display == "none") elem.style.display = "block";
 else 
 if(elem.style.display == "block") elem.style.display = "none";
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
    ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action) {
    http.open('get', 'upload.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function sndReq2(action) {
    http.open('get', 'upload.php?action='+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
    }
}