/*
	Для отмены асинхронной загрузки файлов css нужно закомментировать блок на строках 264 - 271
*/
var endopen1;
var endopen2;
var endopen3;
var Arr_tag = new Array();
var num;
var param;
var kol_cikl=0;
var next_id=0;

function getrandom(min_random, max_random) {
    var range = max_random - min_random;
    var gen_ch = Math.floor(Math.random()*range) + min_random;
	return gen_ch;
	}

function edit_text(num) {
	clearTimeout(endopen1);
	//alert("Re-Re!!");
	if(Arr_tag.length) {
		try {
			var prov_id = document.getElementById("spanid_" + num).style.visibility;
			}
		catch(e) {
			try {
			var gen_ch = getrandom(0, kol_tag); edit_text(gen_ch);
			}
		catch(e) {}
			}
		if(prov_id=='hidden') {
			var Arr_tag_new = new Array();
			document.getElementById("spanid_" + num).style.visibility='visible';
			for(j=0;j<Arr_tag.length;j++) {
				if(Arr_tag[j] != num) Arr_tag_new[Arr_tag_new.length] = Arr_tag[j];
				}
			Arr_tag=Arr_tag_new;
			}
		else {
			var pro_id = getrandom(0, Arr_tag.length);
			document.getElementById("spanid_" + Arr_tag[pro_id]).style.visibility='visible';
			var Arr_tag_new = new Array();
			for(j=0;j<Arr_tag.length;j++) if(Arr_tag[j] != Arr_tag[pro_id]) Arr_tag_new[Arr_tag_new.length] = Arr_tag[j];
			Arr_tag=Arr_tag_new;
			}
		new_kol=getrandom(0, kol_tag);
		endopen1 = setTimeout("edit_text(" + new_kol + ")", time_tag);
		}
	else if(is_cikl>0) {
		clearTimeout(endopen1);
		if(kol_cikl>0) {
			kol_cikl--;
			if(kol_cikl==1) is_cikl=0;
			}
		endopen2 = setTimeout("cikl_new()", 1000*delay_rep);
		}
	else if(next_id>0) {
		if(is_central_section < 1) {
			if(g_width <= 800 && is_viva_txt > 0) {
				manager_close_tv();
				}
			else endopen2 = setTimeout("add_slide(next_id)", 2000*delay_rep);
			}
		else {/*alert("Re-Re!!!");*/}
		}
	}
	
function cikl_new() {
	clearTimeout(endopen2);
	for(i=0;i<kol_tag;i++) document.getElementById("spanid_" + i).style.visibility="hidden";
	for(i=0;i<kol_tag;i++) Arr_tag[Arr_tag.length] = i;
	var get_rand = getrandom(0, kol_tag);
	edit_text(get_rand);
	}

var is_polsunok = 0;
function edit_text2(num, param) {
	param = param || 0;
	clearTimeout(endopen1);
	if(kol_tag > num) {
		//alert ("spanid_" + param + '_' + num);
		if(param > 0) {
			if(document.getElementById("spanid_" + param + '_' + num).tagName == 'SPAN') {
				document.getElementById("spanid_" + param + '_' + num).style.opacity = 1.0;
				document.getElementById("spanid_" + param + '_' + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + param + '_' + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (document.getElementById("is_div").offsetHeight - height_text) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + param + '_' + num).tagName == 'BR') {
				document.getElementById("spanid_" + param + '_' + num).style.opacity = 1.0;
				document.getElementById("spanid_" + param + '_' + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + param + '_' + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (document.getElementById("is_div").offsetHeight - height_text) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + param + '_' + num).tagName == 'IMG') {
				document.getElementById("spanid_" + param + '_' + num).style.opacity = 1.0;
				document.getElementById("spanid_" + param + '_' + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + param + '_' + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (document.getElementById("is_div").offsetHeight - height_text) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + param + '_' + num).tagName == 'LI') {
				document.getElementById("spanid_" + param + '_' + num).style.opacity = 1.0;
				document.getElementById("spanid_" + param + '_' + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + param + '_' + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (document.getElementById("is_div").offsetHeight - height_text) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else document.getElementById("spanid_" + param + '_' + num).style.visibility='visible';
			}
		else {
			if(document.getElementById("spanid_" + num).tagName == 'SPAN') {
				document.getElementById("spanid_" + num).style.opacity = 1.0;
				document.getElementById("spanid_" + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + num).tagName == 'BR') {
				document.getElementById("spanid_" + num).style.opacity = 1.0;
				document.getElementById("spanid_" + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + num).tagName == 'IMG') {
				document.getElementById("spanid_" + num).style.opacity = 1.0;
				document.getElementById("spanid_" + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else if(document.getElementById("spanid_" + num).tagName == 'LI') {
				document.getElementById("spanid_" + num).style.opacity = 1.0;
				document.getElementById("spanid_" + num).style.filter = 'alpha(opacity=100)';
				/*try{document.getElementById("spanid_" + num).filters.alpha.opacity = 100;} catch(e) {}*/
				if(document.getElementById("is_div").offsetHeight > height_text) {
					document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight) + "px";
					if((document.getElementById("is_div").offsetHeight - height_text) > 30 && is_polsunok < 1) {
						is_polsunok = 1;
						}
					}
				else document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";
				}
			else document.getElementById("spanid_" + num).style.visibility='visible';
			}
		new_kol=num+1;
		endopen1 = setTimeout("edit_text2(" + new_kol + ", " + param + ")", time_tag);
		}
	else if(is_cikl>0) {
		if(is_polsunok == 1) {
			document.getElementById("id_polsunok").style.top = "188px";
			document.getElementById("id_polsunok").style.visibility = 'visible';
			}
		if(kol_cikl>0) {
			kol_cikl--;
			if(kol_cikl==1) is_cikl=0;
			}
		endopen2 = setTimeout("cikl_new2()", 1000*delay_rep);
		}
	else if(next_id>0) {
		if(is_polsunok == 1) {
			document.getElementById("id_polsunok").style.top = "188px";
			document.getElementById("id_polsunok").style.visibility = 'visible';
			}
		if(is_central_section < 1) {
			if(g_width <= 800 && is_viva_txt > 0) {
				manager_close_tv();
				}
			else endopen2 = setTimeout("add_slide(next_id)", 1000*delay_rep);
			}
		else {/*alert("Re-Re!!! 2");*/}
		}
	else if(is_polsunok == 1) {
		document.getElementById("id_polsunok").style.top = "188px";
		document.getElementById("id_polsunok").style.visibility = 'visible';
		}
	}
	
function cikl_new2() {
	clearTimeout(endopen2);
	for(i=0;i<kol_tag;i++) {
		document.getElementById("spanid_" + i).style.opacity = 0.0;
		document.getElementById("spanid_" + i).style.filter = 'alpha(opacity=0)';
		/*try{document.getElementById("spanid_" + i).filters.alpha.opacity = 0;} catch(e) {}*/
		if(height_text != 1000000) document.getElementById("id_polsunok").style.visibility = 'hidden';
		is_polsunok = 0;
		}
	edit_text2(0);
	}
	
var xmlHttp_slaid;
function add_slide(id_slide){
	clearTimeout(endopen2);
	xmlHttp_slaid = createXmlHttpRequest();
	if(xmlHttp_slaid.readyState==4 || xmlHttp_slaid.readyState==0) {
		var usname="id_slide=" + id_slide + "&type_letter=" + type_letter;
		//alert(usname);
		xmlHttp_slaid.open("POST", "/phpscript/add_slide.php", true);
		xmlHttp_slaid.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp_slaid.onreadystatechange=afterAddSlide;
        xmlHttp_slaid.send(usname);
    	}
	}
	
function afterAddSlide() {
    if(xmlHttp_slaid.readyState==4) {
        if(xmlHttp_slaid.status==200) {
			//alert (xmlHttp.responseText);
			var new_data = xmlHttp_slaid.responseText.split("<razdel>");
			try {document.getElementById("id_polsunok").style.visibility = 'hidden';}
			catch(e) {}
			is_polsunok = 0;
			var test_text = new_data[0];
			time_tag = new_data[2];
			kol_tag=new_data[1];
			is_cikl=new_data[3];	
			delay_rep=new_data[4];
			change_opt=new_data[5];
			next_id=new_data[6];
			ground_image=new_data[7];
			all_box=new_data[8];
			in_box=new_data[9];
			var is_css_text=new_data[10];
			
			if(is_css_text != 'NO!'){
				var myCSS = document.createElement( "link" );
				myCSS.rel = "stylesheet";
				myCSS.href = "/css_style/id_css/style_" + is_css_text + ".css";
				// insert it at the end of the head in a legacy-friendly manner
				//document.head.insertBefore( myCSS, document.head.childNodes[ document.head.childNodes.length - 1 ].nextSibling );
				document.head.appendChild(myCSS);
				}
			
			document.getElementById("is_div").innerHTML = test_text;
			if(ground_image == 'NO!') document.getElementById("div_width").style.background = 'none';
			else {
				document.getElementById("div_width").style.filter = 'alpha(opacity=0)';
				document.getElementById("div_width").style.opacity = '0';
				document.getElementById("div_width").style.backgroundImage = 'url(' + ground_image + ')';
				if(in_box == 1) document.getElementById("div_width").style.backgroundSize = '100% 100%';
				else document.getElementById("div_width").style.backgroundSize = 'auto';
				if(all_box == 1) document.getElementById("div_width").style.backgroundRepeat = 'repeat';
				else document.getElementById("div_width").style.backgroundRepeat = 'no-repeat';
				}
			/*document.getElementById("is_div").style.left = (width_text - document.getElementById("is_div").offsetWidth)/2 + "px";
			document.getElementById("is_div").style.top = (height_text - document.getElementById("is_div").offsetHeight)/2 + "px";*/
			if(is_cikl>0) kol_cikl=3;
			else kol_cikl=0;
			if(change_opt==1) {
				for(i=0;i<kol_tag;i++) Arr_tag[Arr_tag.length] = i;
				var get_rand = getrandom(0, kol_tag);
				if(ground_image != 'NO!') add_opaciti(get_rand, change_opt, 0);
				else edit_text(get_rand);
				}
			else if(ground_image != 'NO!') add_opaciti(0, 0, 0);
			else edit_text2(0, param);
			if(id_slide>0) {
				document.getElementById("id_slide_" + id_slide).style.fontSize = "12px";
				document.getElementById("id_slide_" + id_slide).style.color = "#990000";
				id_slide++;
				document.getElementById("id_slide_" + id_slide).style.fontSize = "16px";
				document.getElementById("id_slide_" + id_slide).style.color = "#ff0000";
				}
			}
		}
	}

var change_width = 100;
var stop_change;
function downstep_width(is_change) {
	var width = document.getElementById("newpercent").value;
	if((g_width - 10) > width) {
		width++;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newpercent").value = width;
		document.getElementById("div_width").style.width = width + 'px';
		stop_change = setTimeout("downstep_width(" + is_change + ")", new_change_width);
		}
	}
function upstep_width(is_change) {
	var width = document.getElementById("newpercent").value;
	if(width >10) {
		width--;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newpercent").value = width;
		document.getElementById("div_width").style.width = width + 'px';
		stop_change = setTimeout("upstep_width(" + is_change + ")", new_change_width);
		}
	}
	
	
function downstep_height(is_change) {
	var height = document.getElementById("newheight").value;
	if(((g_height - 50) - 10) > height) {
		height++;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newheight").value = height;
		document.getElementById("is_div").style.height = height + 'px';
		stop_change = setTimeout("downstep_height(" + is_change + ")", new_change_width);
		}
	}
function upstep_height(is_change) {
	var height = document.getElementById("newheight").value;
	if(height >10) {
		height--;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newheight").value = height;
		document.getElementById("is_div").style.height = height + 'px';
		stop_change = setTimeout("upstep_height(" + is_change + ")", new_change_width);
		}
	}
	
	
function downstep_speed(is_change) {
	var speed = time_tag;
	if(1000 > speed) {
		speed++;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newspeed").value = 1000/speed;
		time_tag = speed;
		document.getElementById("is_newspeed").value = speed;
		stop_change = setTimeout("downstep_speed(" + is_change + ")", new_change_width);
		}
	}
function upstep_speed(is_change) {
	var speed = time_tag;
	if(speed > 12) {
		speed--;
		is_change++;
		if((change_width - is_change) > 12) var new_change_width = change_width - is_change;
		else new_change_width = 12;
		document.getElementById("newspeed").value = 1000/speed;
		time_tag = speed;
		document.getElementById("is_newspeed").value = speed;
		stop_change = setTimeout("upstep_speed(" + is_change + ")", new_change_width);
		}
	}
	
function add_project(){
	data_blok('Добавьте название проекта');
	
	var container = document.createElement('div');
	container.id = 'div_name_project';
	container.align = 'center';
	container.style.position = 'relative';
	opage_el('div_blok_input').appendChild(container);
	
	container = document.createElement('div');
	container.className = 's10';
	opage_el('div_name_project').appendChild(container);
	
	container = document.createElement('input');
	container.type = 'text';
	container.id = 'id_name_project';
	container.style.width = '90%';
	opage_el('div_name_project').appendChild(container);
	
	container = document.createElement('div');
	container.className = 's10';
	opage_el('div_name_project').appendChild(container);
	
	container = document.createElement('button');
	container.type = 'button';
	container.onclick = function(){if(opage_el("id_name_project").value != '') add_project_arhiv(); else alert('Введите какое-нибудь название нового проекта!');};
	container.innerHTML = 'Создать';
	opage_el('div_name_project').appendChild(container);
	
	container = document.createElement('div');
	container.className = 's10';
	opage_el('div_name_project').appendChild(container);
	
	open_div_optim();
	opage_el('shadow_div').style.visibility = 'visible';
	addEvent(window, 'resize', resize_info);
	}
	
function add_project_arhiv(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0) {
		var usname="name_project=" + encodeURIComponent(opage_el("id_name_project").value);
		//alert(usname);
		xmlHttp.open("POST", "/phpscript/add_project_arhiv.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=afterAddProjectArhiv;
        xmlHttp.send(usname);
    	}
	}
	
function afterAddProjectArhiv() {
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
			//alert(xmlHttp.responseText);
			var response = xmlHttp.responseXML.documentElement;
			var error = response.getElementsByTagName("error").item(0).firstChild.data.toString();
			
			delete_last(opage_el('div_name_project')); 
				
			if(error == 'NO!') {
				opage_el('div_name_project').innerHTML = '<p class="error">Проект не сохранен!<br>Возможно не было добавлено название.</p>';
				}
			else {
				opage_el('div_name_project').innerHTML = '<p class="success">Проект сохранен!</p>';
	
				var container = document.createElement('div');
				container.className = 's10';
				opage_el('div_name_project').appendChild(container);
				
				if(kol_file_kol < 1) {
					container = document.createTextNode("      ");
					opage_el('list_buttons').appendChild(container);

					container = document.createElement('button');
					container.type = 'button';
					container.title = 'Добавить данный сценарий в проект';
					container.innerHTML = 'Добавить в проект';
					container.onclick = function(){list_project();};
					opage_el('list_buttons').appendChild(container);
					
					container = document.createTextNode("      ");
					opage_el('list_buttons').appendChild(container);

					container = document.createElement('button');
					container.type = 'button';
					container.title = 'Работа с презентациями (проектами слайд шоу)';
					container.innerHTML = 'Все проекты';
					container.onclick = function(){list_project(1);};
					opage_el('list_buttons').appendChild(container);
					
					kol_file_kol++;
					}
				}
			}
		}
	}
	
function list_project(all_project){
	all_project = all_project || 0;
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0) {
		var usname="all_project=" + all_project;
		//alert(usname);
		xmlHttp.open("POST", "/phpscript/list_project.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=afterListProject;
        xmlHttp.send(usname);
    	}	
	}
	
function afterListProject() {
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
			//alert(xmlHttp.responseText);
			var response = xmlHttp.responseXML.documentElement;
			var error = response.getElementsByTagName("error").item(0).firstChild.data.toString();
			var all_project = response.getElementsByTagName("all_project").item(0).firstChild.data.toString();
			
			var all_id = response.getElementsByTagName("all_id").item(0).getElementsByTagName("id");
			var all_name = response.getElementsByTagName("all_name").item(0).getElementsByTagName("name");
			var all_data = response.getElementsByTagName("all_data").item(0).getElementsByTagName("data");
			var all_default = response.getElementsByTagName("all_default").item(0).getElementsByTagName("default");
			
			var all_child = response.getElementsByTagName("all_child").item(0).getElementsByTagName("child");
			
			if(all_project == 'NO!') data_blok('Добавьте слайд в нужный проект');
			else data_blok('Управление проектами презентаций');
	
			var container = document.createElement('div');
			container.id = 'div_name_project';
			container.align = 'center';
			container.style.position = 'relative';
			opage_el('div_blok_input').appendChild(container);
	
			
			if(all_project == 'NO!') {
				container = document.createElement('div');
				container.className = 's5';
				opage_el('div_name_project').appendChild(container);
	
				container = document.createTextNode('Заголовок слайда - ');
				opage_el('div_name_project').appendChild(container);
	
				container = document.createElement('input');
				container.id = 'input_name_project';
				container.type = 'text';
				container.style.width = '300px';
				opage_el('div_name_project').appendChild(container);
		
				container = document.createElement('div');
				container.className = 's5';
				opage_el('div_name_project').appendChild(container);
				}
	
			container = document.createElement('table');
			container.id = 'table_project';
			container.border = '0';
			container.cellpadding = "3";
			container.cellspacing = "3"
			container.width = "100%";
			opage_el('div_name_project').appendChild(container);
	
			container = document.createElement('tbody');
			container.id = 'tbody_project';
			opage_el('table_project').appendChild(container);
			
// Далее выводится управление и данные для КАЖДОГО ПРОЕКТА ПРЕЗЕНТАЦИИ. А также для СВОБОДНЫХ СЛАЙДОВ. То есть для тех которые созданы по умолчанию. Они определяются наличием в переменных is_default и is_general значения "Yes!".
			for(var j = 0; j < all_id.length; j++) {
				var name = all_name.item(j).firstChild.data.toString();
				var isid = all_id.item(j).firstChild.data.toString();
				var data = all_data.item(j).firstChild.data.toString();
				var is_default = all_default.item(j).firstChild.data.toString();
	
				container = document.createElement('tr');
				container.id = 'tr_project_' + isid;
				opage_el('tbody_project').appendChild(container);
	
				container = document.createElement('td');
				container.id = 'td_1_project_' + isid;
				container.align = 'center';
				if(is_default == 'Yes!') container.style.background = '#f0fff0';
				else container.style.background = '#f0f0f0';
				if(is_default == 'NO!') container.style.fontWeight = 'bold';
				container.innerHTML = (j + 1);
				opage_el('tr_project_' + isid).appendChild(container);
	
				container = document.createElement('td');
				container.id = 'td_2_project_' + isid;
				container.align = 'left';
				if(is_default == 'Yes!') container.style.background = '#f0fff0';
				else container.style.background = '#f0f0f0';
				if(is_default == 'NO!') container.style.fontWeight = 'bold';
				if(is_default == 'Yes!') container.innerHTML = 'Заготовка слайда<br><strong>' + name + '</strong>';
				else container.innerHTML = name;
				opage_el('tr_project_' + isid).appendChild(container);
	
				container = document.createElement('td');
				container.id = 'td_3_project_' + isid;
				container.align = 'center';
				if(is_default == 'Yes!') container.style.background = '#f0fff0';
				else container.style.background = '#f0f0f0';
				if(is_default == 'NO!') container.style.fontWeight = 'bold';
				container.innerHTML = data;
				opage_el('tr_project_' + isid).appendChild(container);
	
				container = document.createElement('td');
				container.id = 'td_4_project_' + isid;
				container.align = 'center';
				if(is_default == 'Yes!') container.style.background = '#f0fff0';
				else container.style.background = '#f0f0f0';
				opage_el('tr_project_' + isid).appendChild(container);
	
				if(all_project == 'NO!') {
					container = document.createElement('button');
					container.id = 'button_project_' + isid;
					container.type = 'button';
					container.onclick = function(x){return function(){insert_project(x)}}(isid);
					container.innerHTML = 'Добавить';
					opage_el('td_4_project_' + isid).appendChild(container);
					}
				else {/* Внимание!!! Функция edit_project() еще не написана. А нужна ли она? */
					container = document.createElement('button');
					container.id = 'button_edit_project_' + isid;
					container.type = 'button';
					container.className = 'small';
					container.onclick = function(x){return function(){edit_project(x)}}(isid);
					container.innerHTML = 'Редактировать';
					container.style.width = '100px';
					opage_el('td_4_project_' + isid).appendChild(container);
					
					container = document.createElement('br');
					opage_el('td_4_project_' + isid).appendChild(container);
					
					container = document.createElement('button');
					container.id = 'button_del_project_' + isid;
					container.className = 'small';
					container.type = 'button';
					container.style.width = '100px';
					if(is_default == 'Yes!') container.onclick = function(x){return function(){delete_project(x, 0, 0)}}(isid);
					else container.onclick = function(x){return function(){if(confirm('Удалить проект вместе со всеми слайдами?\n\n"ОК" - удаляем все слайды\n"Cancel" - слайды входящие в состав пректа переведутся в разряд созданных по-умолчанию')) delete_project(x, 0, 1); else delete_project(x, 0, 0)}}(isid);
					container.innerHTML = 'Удалить';
					opage_el('td_4_project_' + isid).appendChild(container);
					}
	
				if(all_project != 'NO!') {
					var all_id_child = all_child.item(j).getElementsByTagName("id");
					var all_name_child = all_child.item(j).getElementsByTagName("name");
					var all_data_child = all_child.item(j).getElementsByTagName("data");
					//alert("Re-Re!!! " + all_id_child.length);
// А далее выводится управление и данные ДЛЯ КАЖДОГО СЛАЙДА В ТЕКУЩЕМ ПРОЕТКЕ ПРЕЗЕНТАЦИИ, то есть слайды вложенные в презентации!!!
					for(var k = 0; k < all_id_child.length; k++) {
					
						var name_child = all_name_child.item(k).firstChild.data.toString();
						var isid_child = all_id_child.item(k).firstChild.data.toString();
						var data_child = all_data_child.item(k).firstChild.data.toString();
			
						container = document.createElement('tr');
						container.id = 'tr_project_' + isid + '_' + isid_child;
						opage_el('tbody_project').appendChild(container);
			
						container = document.createElement('td');
						container.id = 'td_1_project_' + isid + '_' + isid_child;
						container.align = 'center';
						container.style.background = '#fffff0';
						container.innerHTML = (j + 1) + '.' + (k + 1);
						opage_el('tr_project_' + isid + '_' + isid_child).appendChild(container);
			
						container = document.createElement('td');
						container.id = 'td_2_project_' + isid + '_' + isid_child;
						container.align = 'left';
						container.style.background = '#fffff0';
						container.innerHTML = name_child;
						opage_el('tr_project_' + isid + '_' + isid_child).appendChild(container);
			
						container = document.createElement('td');
						container.id = 'td_3_project_' + isid + '_' + isid_child;
						container.align = 'center';
						container.style.background = '#fffff0';
						container.innerHTML = data_child;
						opage_el('tr_project_' + isid + '_' + isid_child).appendChild(container);
			
						container = document.createElement('td');
						container.id = 'td_4_project_' + isid + '_' + isid_child;
						container.align = 'center';
						container.style.background = '#fffff0';
						opage_el('tr_project_' + isid + '_' + isid_child).appendChild(container);
			
						container = document.createElement('button');
						container.id = 'button_edit_project_' + isid + '_' + isid_child;
						container.type = 'button';
						container.className = 'small';
						container.onclick = function(x){return function(){/*edit_project(x)*/window.location.href = '/conclusion/help.php?id_slide=' + x;}}(isid_child);
						container.innerHTML = 'Редактировать';
						container.style.width = '100px';
						opage_el('td_4_project_' + isid + '_' + isid_child).appendChild(container);
						
						container = document.createElement('br');
						opage_el('td_4_project_' + isid + '_' + isid_child).appendChild(container);
						
						container = document.createElement('button');
						container.id = 'button_del_project_' + isid + '_' + isid_child;
						container.className = 'small';
						container.type = 'button';
						container.style.width = '100px';
						container.onclick = function(x, y){return function(){delete_project(x, y, 0)}}(isid_child, isid);
						container.innerHTML = 'Удалить';
						opage_el('td_4_project_' + isid + '_' + isid_child).appendChild(container);
					
						}
					}
				}
	
			open_div_optim();
			opage_el('shadow_div').style.visibility = 'visible';
			addEvent(window, 'resize', resize_info);
			}
		}
	}
	
function insert_project(is_id){
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0) {
		var usname="is_id=" + is_id + '&title=' + encodeURIComponent(opage_el('input_name_project').value);
		//alert(usname);
		xmlHttp.open("POST", "/phpscript/insert_project.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=afterInsertProject;
        xmlHttp.send(usname);
    	}	
	}
	
function afterInsertProject(){
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
			//alert(xmlHttp.responseText);
			var response = xmlHttp.responseXML.documentElement;
			var error = response.getElementsByTagName("error").item(0).firstChild.data.toString();
			var name = response.getElementsByTagName("name").item(0).firstChild.data.toString();
			
			close_input_block();
			data_blok('Добавление слайда к презентации');
	
			var container = document.createElement('div');
			container.id = 'div_name_project';
			container.align = 'center';
			container.style.position = 'relative';
			opage_el('div_blok_input').appendChild(container);
	
			container = document.createElement('div');
			container.className = 's10';
			opage_el('div_name_project').appendChild(container);
				
			if(error == 'NO!') {
				opage_el('div_name_project').innerHTML = '<p class="error">Слайд не сохранен!<br>Возможно не был определен идентификатор проекта в который добавлялся слайд.</p>';
				}
			else {
				opage_el('div_name_project').innerHTML = '<p class="success">Слайд сохранен и добавлен в проект "' + name + '"!</p>';
				}
	
			container = document.createElement('div');
			container.className = 's10';
			opage_el('div_name_project').appendChild(container);
			
			open_div_optim();
			opage_el('shadow_div').style.visibility = 'visible';
			addEvent(window, 'resize', resize_info);
			}
		}
	}

function delete_project(is_id, is_pid, all_delete){
	all_delete = all_delete || 0;
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0) {
		var usname="is_id=" + is_id + '&is_pid=' + is_pid + '&all_delete=' + all_delete;
		alert(usname);
		xmlHttp.open("POST", "/phpscript/delete_project.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange=afterDeleteProject;
        xmlHttp.send(usname);
    	}	
	}
	
function afterDeleteProject(){
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
			//alert(xmlHttp.responseText);
			var response = xmlHttp.responseXML.documentElement;
			var error = response.getElementsByTagName("error").item(0).firstChild.data.toString();
			var id_project = response.getElementsByTagName("id_project").item(0).firstChild.data.toString();
			var pid_project = response.getElementsByTagName("pid_project").item(0).firstChild.data.toString();
			var all_delete = response.getElementsByTagName("all_delete").item(0).firstChild.data.toString();
			
			if(pid_project=='NO!') {
				delete_last(opage_el('tr_project_' + id_project)); 
				opage_el('tbody_project').removeChild(opage_el('tr_project_' + id_project));
				}
			else {
				delete_last(opage_el('tr_project_' + pid_project + '_' + id_project)); 
				opage_el('tbody_project').removeChild(opage_el('tr_project_' + pid_project + '_' + id_project));
				}
			
			var all_pid = response.getElementsByTagName("all_pid").item(0).getElementsByTagName("id");
			var all_rock = response.getElementsByTagName("all_rock").item(0).getElementsByTagName("rock");
			var all_name = response.getElementsByTagName("all_name").item(0).getElementsByTagName("name");
			var all_data = response.getElementsByTagName("all_data").item(0).getElementsByTagName("data");
			
			for(var j = 0; j < all_pid.length; j++) {
				var pid = all_pid.item(j).firstChild.data.toString();
				var rock = all_rock.item(j).firstChild.data.toString();
				var name = all_name.item(j).firstChild.data.toString();
				var data = all_data.item(j).firstChild.data.toString();
				
				delete_last(opage_el('tr_project_' + id_project + '_' + pid)); 
				opage_el('tbody_project').removeChild(opage_el('tr_project_' + id_project + '_' + pid));
				
				if(rock!='NO!') {
					container = document.createElement('tr');
					container.id = 'tr_project_' + pid;
					opage_el('tbody_project').appendChild(container);
		
					container = document.createElement('td');
					container.id = 'td_1_project_' + pid;
					container.align = 'center';
					container.style.background = '#fffff0';
					container.innerHTML = 'd.' + (j + 1);
					opage_el('tr_project_' + pid).appendChild(container);
		
					container = document.createElement('td');
					container.id = 'td_2_project_' + pid;
					container.align = 'left';
					container.style.background = '#fffff0';
					container.innerHTML = name;
					opage_el('tr_project_' + pid).appendChild(container);
		
					container = document.createElement('td');
					container.id = 'td_3_project_' + pid;
					container.align = 'center';
					container.style.background = '#fffff0';
					container.innerHTML = data;
					opage_el('tr_project_' + pid).appendChild(container);
		
					container = document.createElement('td');
					container.id = 'td_4_project_' + pid;
					container.align = 'center';
					container.style.background = '#fffff0';
					opage_el('tr_project_' + pid).appendChild(container);
		
					container = document.createElement('button');
					container.id = 'button_edit_project_' + pid;
					container.type = 'button';
					container.className = 'small';
					container.onclick = function(x){return function(){edit_project(x)}}(pid);
					container.innerHTML = 'Редактировать';
					container.style.width = '100px';
					opage_el('td_4_project_' + pid).appendChild(container);
					
					container = document.createElement('br');
					opage_el('td_4_project_' + pid).appendChild(container);
					
					container = document.createElement('button');
					container.id = 'button_del_project_' + pid;
					container.className = 'small';
					container.type = 'button';
					container.style.width = '100px';
					container.onclick = function(x){return function(){delete_project(x)}}(pid, 0, 0);
					container.innerHTML = 'Удалить';
					opage_el('td_4_project_' + pid).appendChild(container);
					}
				}
			
			}
		}
	}
	
function move_polsunok(e) {
	//alert("Re-Re!!!");
	var coords = getCoords(opage_el('id_polsunok'));
	var shiftX = e.pageX - coords.left;
	var shiftY = e.pageY - coords.top;
	
	opage_el('id_polsunok').style.position = 'absolute';
	document.body.appendChild(opage_el('id_polsunok'));
	moveAt(e);
	
	opage_el('id_polsunok').style.zIndex = 1000; // над другими элементами
	
	function moveAt(e) {
		opage_el('id_polsunok').style.left = coords.left + 'px';
		opage_el('id_polsunok').style.top = e.pageY - shiftY + 'px';
		var delta_height = getCoords(opage_el('id_polsunok')).top;
		document.getElementById("is_div").style.top = "-" + ((201*201 + (delta_height - (upper_height - 3))*document.getElementById("is_div").offsetHeight - 201*(delta_height - (upper_height - 3)))/201 - 201) + "px";
		}
	
	document.onmousemove = function(e) {
		if(getCoords(opage_el('id_polsunok')).top >= (-3 + upper_height) && getCoords(opage_el('id_polsunok')).top <= (198 + upper_height)) moveAt(e);
		else if(getCoords(opage_el('id_polsunok')).top < (-3 + upper_height)) {
			document.onmousemove = null;
			opage_el('id_polsunok').onmouseup = null;
			opage_el('id_polsunok').style.top = (-3 + upper_height) + 'px';
			}
		else if(getCoords(opage_el('id_polsunok')).top > (198 + upper_height)) {
			document.onmousemove = null;
			opage_el('id_polsunok').onmouseup = null;
			opage_el('id_polsunok').style.top = (198 + upper_height) + 'px';
			}
		}
	
	opage_el('id_polsunok').onmouseup = function() {
		document.onmousemove = null;
		opage_el('id_polsunok').onmouseup = null;
		//opage_el('id_polsunok').onmouseout = null;
		}
	
	/*opage_el('id_polsunok').onmouseout = function() {
		document.onmousemove = null;
		opage_el('id_polsunok').onmouseup = null;
		opage_el('id_polsunok').onmouseout = null;
		}*/

	}
	
function getCoords(elem) {
    // (1)
    var box = elem.getBoundingClientRect();
    
    var body = document.body;
    var docEl = document.documentElement;
    
    // (2)
    var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
    var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
    
    // (3)
    var clientTop = docEl.clientTop || body.clientTop || 0;
    var clientLeft = docEl.clientLeft || body.clientLeft || 0;
    
    // (4)
    var top  = box.top +  scrollTop - clientTop;
    var left = box.left + scrollLeft - clientLeft;
    
    // (5)
    return { top: Math.round(top), left: Math.round(left) };
	}
	
function add_opaciti(get_rand, change_opt, sgag){
	clearTimeout(endopen3);
	var norm_add = sgag + 0.1; 
	var ie_add = 100*norm_add;
	document.getElementById("div_width").style.filter = 'alpha(opacity=' + ie_add + ')';
	document.getElementById("div_width").style.opacity = norm_add;
	if(ie_add < 100) endopen3 = setTimeout("add_opaciti(" + get_rand + ", " + change_opt + ", " + norm_add + ")", 50);
	else if(change_opt == 1) edit_text(get_rand);
	else edit_text2(0, param);
	}

var static_var_1;
var static_var;
function manager_show_tv(){
	opage_el("tv_bloc_id").className = 'mini_tv_block';
	opage_el("tv_bloc_id").children[1].className = 'position_relative';
	
	var container = document.createElement("div");
	container.id = 'shine_block_id';
	container.style.top = '50%';
	container.style.left = '47.5%';
	opage_el("tv_bloc_id").children[1].appendChild(container);
	
	setTimeout("opage_el('shine_block_id').style.visibility = 'visible'", 100);
	setTimeout("opage_el('shine_block_id').style.visibility = 'hidden'", 500);
	
	opage_el("tv_bloc_id").children[1].children[0].className = 'center_cell';
	opage_el("tv_bloc_id").children[1].children[0].children[0].className = 'position_relative center_cell';
	
	opage_el("is_div").style.width = opage_el("tv_bloc_id").children[1].children[0].children[0].offsetWidth + 'px';
	
	opage_el("div_width").style.height = (opage_el("is_div").offsetHeight + 20) + 'px';
	opage_el("tv_bloc_id").children[1].children[0].children[0].style.height = opage_el("div_width").offsetHeight + 'px';
	
	static_var_1 = setTimeout("tod_hidden()", 1500);
	
	setTimeout("opage_el('div_width').style.width = '100%'", 2500);
	
	static_var = setTimeout("hat_position()", 3000);
	}
function tod_hidden(){
	clearTimeout(static_var_1);
	opage_el('tv_bloc_id').children[1].children[0].style.height = '100%';
	opage_el('tv_bloc_id').children[1].children[0].style.overflow = 'visible';
	}
function hat_position(){
	clearTimeout(static_var);
	if(opage_el('div_width').offsetHeight >= opage_el('tv_bloc_id').offsetHeight) opage_el("tv_bloc_id").style.top = (opage_el('div_width').offsetHeight - opage_el('tv_bloc_id').offsetHeight + 10) + 'px';
	opage_el("tv_bloc_id").children[0].className = 'close_tv_block';
	opage_el("tv_bloc_id").children[0].style.top = ((opage_el('tv_bloc_id').offsetHeight - opage_el('div_width').offsetHeight)/2 - 5) + 'px';
	opage_el("tv_bloc_id").children[0].style.right = ((opage_el('tv_bloc_id').offsetWidth - opage_el('div_width').offsetWidth)/2 - 5) + 'px';
	opage_el("tv_bloc_id").children[0].onclick = function(){opage_el("tv_bloc_id").children[0].className = ''; manager_close_tv();}
	}
function manager_close_tv(){
	opage_el('div_width').className = 'close_width';
	setTimeout("opage_el('div_width').style.width = '0%'", 1000);
	
	static_var_1 = setTimeout("tod_heght()", 1000);
	
	}
function tod_heght(){
	clearTimeout(static_var_1);
	/**/
	opage_el('tv_bloc_id').children[1].children[0].className = 'center_cell close_heght';
	opage_el('tv_bloc_id').children[1].children[0].style.overflow = 'hidden';
	setTimeout("opage_el('tv_bloc_id').children[1].children[0].style.height = '0%'", 1000);
	
	setTimeout("opage_el('shine_block_id').style.visibility = 'visible'", 1000);
	setTimeout("opage_el('shine_block_id').style.visibility = 'hidden'", 1500);
	
	static_var_1 = setTimeout("all_close_tv()", 1500);
	}
function all_close_tv(){
	clearTimeout(static_var_1);
	opage_el("tv_bloc_id").children[1].removeChild(opage_el('shine_block_id'));
	opage_el("tv_bloc_id").className = 'position_relative';
	is_viva_txt = 0;
	}