﻿/*
Все создаваемые переменные
*/
var Alert,podloghka,width_Alert,height_Alert,width_window,height_window,texton,timer,Alert_height_width;

/*
Все создаваемые функции
*/
function $(elem){return document.getElementById(elem);}
/////////Получаем Элемент по id///////////////////
function $$(elem){return document.getElementsByTagName(elem);}
/////////Получаем Элемент по TagName//////////////////////////////
function createEl(tag,id){var create=document.createElement(tag);$$("body")[0].appendChild(create);if(!id)return create;else {create.id=id;return create;}}
/////////Создаём Элемент///////////////
function setStyles(elem,prop){for(key in prop)elem.style[key]=prop[key];return this;}
///////////Придаём стили////////////////
if(navigator.appName.toLowerCase()=="microsoft internet explorer"){var ie=true;}
/////Проверяем, это Интернет Эксплорер или нет. Кстати, Пользуйтесь Opera'ой.////IE-говно////////
function func(){width_window =document.documentElement.clientWidth? document.documentElement.clientWidth : document.body.clientWidth;height_window = document.documentElement.clientHeight? document.documentElement.clientHeight : document.body.clientHeight;}
/////////////////////////////////
addEvent(window,"load",func);
/////////////////////////////
String.prototype.delayingWrite = function(obj, delay){if (this.length>0){if (typeof obj == 'string') obj = $(obj);obj.innerHTML += this.charAt(0);s = this.substr(1);if (s) setTimeout(function(){s.delayingWrite(obj, delay);},delay);}}
function addEvent(elem,evnt,func){if(elem.addEventListener) elem.addEventListener(evnt,func,false);else if(elem.attachEvent) elem.attachEvent("on"+evnt,func);else elem["on"+evnt]=func;}
///////////Эмулируем пишущую машинку////////////////////////////
String.prototype.trim_it = function(){ var t=this;while(t.indexOf(" ")==0)t=t.substring(1,t.length);while(t.lastIndexOf(" ")==(t.length-1))t=t.substring(1,t.lastIndexOf(" "));return t;}
////////////Удаляем пробелы/////////
function Alert(text)
{
texton=text;

var width_site = (document.documentElement.scrollWidth > document.documentElement.offsetWidth)? document.documentElement.scrollWidth: document.documentElement.offsetWidth;
var height_site = (document.documentElement.scrollHeight > document.documentElement.offsetHeight)? document.documentElement.scrollHeight: document.documentElement.offsetHeight;
podloghka = document.createElement("div","podloghka");
$$("body")[0].appendChild(podloghka);
setStyles(podloghka,{
width : width_site+"px",
height : height_site+"px",
backgroundColor:"#000000",
overflow:"hidden"
});
if(ie)
podloghka.style.filter = 'alpha(opacity=70';
else podloghka.style.opacity=0.4;
Alert_height_width=createEl("div");
Alert_height_width.style.visibility="hidden";
Alert_height_width.style.position="absolute";
Alert_height_width.innerHTML="<p>"+texton+"</p><br><form onBlur='return false;'><input style='padding:7px 20px 7px 20px' onClick='close_Alert()' type='button' value='Ok'></input></form>";
if(Alert_height_width.offsetWidth>900)
Alert_height_width.width=600;
else Alert_height_width.width=Alert_height_width.offsetWidth;

width_Alert=width_window;
height_Alert=height_window;
Alert = createEl("div");
setStyles(Alert,{
borderTop:"16px solid #FF6600",
borderBottom:"8px solid #FF6600",
borderLeft:"8px solid #FF6600",
borderRight:"8px solid #FF6600",
color:"#fff",
opacity:"0.7",
textAlign:"center",
position:"fixed"
});
timer = setInterval("Alert_style()",1);
}
function Alert_style(text){
if(height_Alert>Alert_height_width.offsetHeight+50 || width_Alert-100>Alert_height_width.width)
{
if(height_Alert>Alert_height_width.offsetHeight+50) height_Alert-=30;
if(width_Alert>Alert_height_width.width)width_Alert=width_Alert-(1.3333*30);
setStyles(Alert,{
width:width_Alert+"px",
height:height_Alert+"px",
backgroundColor:"#cc0000",
overflow:"hidden",
top:(height_window-Alert.offsetHeight)/2+"px",
left:(width_window-Alert.offsetWidth)/2+"px"
});

		  
}
else {
Alert.innerHTML="<p id='Alert'>"+texton+"</p><br><form onBlur='return false;'><input style='padding:7px 20px 7px 20px' onClick='close_Alert()' type='button' value='Ok'></input></form>";
clearInterval(timer);
}}
function close_Alert()
{
Alert.style.display="none";
podloghka.style.display="none";
}
var xmlHttp;
var Ajax=
{

getPage:function (element,method,page,send)
{
	if (window.XMLHttpRequest) 
	{
	xmlHttp = new XMLHttpRequest();
	// branch for IE/Windows ActiveX version
	} 
	else if (window.ActiveXObject) 
	{
	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else {
	alert ("Ошибка создания объекта XMLHttpRequest");
	return;
	}


xmlHttp.open(method, page, true);
xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) 
		{ 
			if (xmlHttp.status == 200) 
			{
			var myDiv = element;
			myDiv.innerHTML=xmlHttp.responseText;
			} 
			else
			{
			myDiv.innerHTML='Загрузка не удалась!';
			}
		}
	};
	xmlHttp.send(send);}}

