/* функция создает новый экземпляр класса XMLHTTP   */
function get_http1(){
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return http_request;
}

/* функция получает экземпляр класса XMLHTTP,
ответ сервера и если все нормально возвращает ответ*/
function alertContents_txt(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			return http_request.responseText;
		} else {
			alert('С запросом возникла проблема.');
			return false;
		}}}


function PutInner(text,elements_id) {
	//alert(text);
	//alert(elements_id);
	document.getElementById(elements_id).innerHTML = text;
};


/* функция получает:
- url скрипта,
- параметры который нужно передать скрипту в виде ?имя_переменной=значение&...
- id элемента страницы в который нужно загрузить ответ скрипта*/
function makeRequest(url,parameters,elements_id,id,fild1) {
	var http_request = false;
	//alert(url,elements_id);
	//alert(elements_id);
	http_request=get_http1()
	if (!http_request) {
		alert('Не вышло :( Невозможно создать экземпляр класса XMLHTTP ');
		return false;  }
	http_request.onreadystatechange = function() {
		document.getElementById(elements_id).innerHTML = alertContents_txt(http_request); };
	url=url+parameters+'&id='+id+'&fild1='+fild1;
	//alert(url);
	http_request.open('GET', url, true);
	//alert(url);
	http_request.send(null);
}

function setCookie(name, value, flag)
// using example:
// setCookie("counter", 4, true);
{
	var COOKIE;
	COOKIE = name + "=" + value +";expires=" + "Wednesday, 12-Nov-2010 15:18:27 GMT;" + location.protocol + "//" + location.hostname;
	//  alert(COOKIE);
	document.cookie = COOKIE;
}

function getCookie(name)
// using example:
// var name = getCookie("name");
{
	var RESULT;
	if (document.cookie) {
	if (document.cookie.search(name)!=-1)
        {
		var startPos, endPos;
		startPos = document.cookie.search(name) + name.length + 1;
		if(document.cookie.indexOf(";", startPos) != -1)
		endPos = document.cookie.indexOf(";", startPos);
		else
		endPos = document.cookie.length;
		RESULT = document.cookie.substring(startPos, endPos);
	} else { RESULT=' '; return RESULT;};
	}
	return RESULT;
}

function getAllCookies()
// using example:
// var cookies = new Array(), name;
// cookies = getAllCookies();
// name = cookies["name"];
{
	var RESULT = new Array();

	if (document.cookie) {
		var strings = new Array();
		var temp = new Array();

		strings = document.cookie.split(";");

		for (var i=0; i<strings.length; i++) {
			temp = strings[i].split("=");
			RESULT[temp[0]] = temp[1];
		}

	} else {
		return false;
	}

	return RESULT;
}

// функции создают всплывающие окна
function openWin(url,name) {
	msgWindow= open(url,name,"width=500,height=400,status=no,toolbar=no,menubar=no,scrollbars=yes")  }

function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	win_video=window.open(url, name);
	win_video.close();
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	win_video=window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);	win_video.focus();
}

function disableField(com)
{
	document.admin_edit.nick.disabled=com;
	document.admin_edit.email.disabled=com;
	document.admin_edit.subject.disabled=com;
	document.admin_edit.text.disabled=com;
}



// функция закрывает окно
function closeIt(){
	close();   }

/* функция получает:
- url скрипта,
- параметры который нужно передать скрипту в виде ?имя_переменной=значение&...
- id элемента страницы в который нужно загрузить ответ скрипта*/
function makeRequestMove(url,str_id,elements_id,hall,mount,year,mid) {
	var http_request = false;
	//alert(url,elements_id);
	//alert(elements_id);
	http_request=get_http1()
	if (!http_request) {
		alert('Не вышло :( Невозможно создать экземпляр класса XMLHTTP ');
		return false;  }
	http_request.onreadystatechange = function() {
		document.getElementById(elements_id).innerHTML = alertContents_txt(http_request); };
	//alert(elements_id);
	if (hall>=0) {type_hall=0;} else {type_hall=1;};
	sourse_num=4+(str_id)*(5+type_hall);
	date_fr=document.list_reper.elements[sourse_num].value;
	date_to=document.list_reper.elements[sourse_num+1].value;
	fiml_id=document.list_reper.elements[sourse_num+2].value;
	if (hall<0) {$is_hall='&hall='+document.list_reper.elements[sourse_num+3].value;}
	else {$is_hall='&hall='+hall;}
	url=url+'?df='+date_fr+'&dt='+date_to+'&mnt='+mount+'&yr='+year+'&fid='+fiml_id+$is_hall+'&mid='+mid;
	http_request.open('GET', url, true);
	//alert(url);
	http_request.send(null);
}

function gopopup(type,id1,id2)
{
	p='width=171,height=190,resizable=yes,toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no';
	if(type==1)
	{
		xxx=open('http://www.kinoafisha.ru/votes_film.php3?id='+id1,'votes',p);xxx.focus();
	}
	if(type==2)
	{
		xxx=open('http://www.kinoafisha.ru/votes_cinemahall.php3?id='+id1,'votes',p);xxx.focus();
	}
	if(type==3)
	{
		p='width=400,height=400,resizable=yes,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no';
		xxx=open('http://www.kinoafisha.ru/cinemahall_sessions.php3?id1='+id1+'&id2='+id2,'sessions',p);xxx.focus();
	}
}

