﻿//
var ie = !-[1,];
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var XMLHttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function ajax_request(url_string, id_text, res_in) {
	if (id_text != "") var text = document.getElementById(id_text);
	//url_string = url_string + "&x=" + rnd(65535);
	XMLHttp.open("get", url_string, true);
	XMLHttp.onreadystatechange = function() {
		if (XMLHttp.readyState == 4) {
			if (XMLHttp.status == 200) {
				if (res_in == "inh") text.innerHTML = XMLHttp.responseText;
				if (res_in == "val") text.value = XMLHttp.responseText;
				if (res_in == "alt") alert(XMLHttp.responseText);
				statload.style.visibility = "hidden";
			} else {
				if (res_in == "inh") text.innerHTML = "load error!";
				if (res_in == "val") text.value = "err";
				if (res_in == "alt") alert("error");
				statload.style.visibility = "hidden";
			}
		} else { statload.style.visibility = "visible"; }
	};
XMLHttp.send(null);
}  
// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
// x.getResponseHeader("content-type"), x.responseXML : x.responseText;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// возвращает cookie если есть или undefined
function getCookie(name) {
    var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"))
    return matches ? decodeURIComponent(matches[1]) : undefined 
}
 
// уcтанавливает cookie
function setCookie(name, value, props) {
    props = props || {}
    var exp = props.expires
    if (typeof exp == "number" && exp) {
        var d = new Date()
        d.setTime(d.getTime() + exp*1000)
        exp = props.expires = d
    }
    if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }
 
    value = encodeURIComponent(value)
    var updatedCookie = name + "=" + value
    for(var propName in props){
        updatedCookie += "; " + propName
        var propValue = props[propName]
        if(propValue !== true){ updatedCookie += "=" + propValue }
    }
    document.cookie = updatedCookie
 
}
 
// удаляет cookie
function deleteCookie(name) {
    setCookie(name, null, { expires: -1 })
}

// - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -

function rnd(m) {return Math.floor(Math.random() * m); }
function rgb2hex(r,g,b) {return Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');}
function hex2dec(hex){return(parseInt(hex,16));}
function dec2hex(dec){return (dec < 16 ? "0" : "") + dec.toString(16);} 

function mpos(e) {
  var x = 0, y = 0;
  if (!e) e = window.event;
  if (e.pageX || e.pageY) {
    x = e.pageX;
    y = e.pageY;
  } else if (e.clientX || e.clientY) {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }
  return {"x":x, "y":y};
}

function glassbox(a) {
	var mc = mpos();
	var box = document.getElementById("glassbox");
		if (a.rel.substring(0,8) == "glassbox") {
			if (a.rel.substring(9,12) == "img") {box.innerHTML = '<b>'+a.title+'</b><hr /><img src="'+a.href+'" alt="" />';} 
			if (a.rel.substring(9,12) == "txt") {box.innerHTML = '<b>'+a.title+'</b><hr />'+a.rel.substring(13);} 
		}
	box.style.display = "block";
	box.style.top = mc.y;
	box.style.left = mc.x;
	box.onclick = function() {box.style.display="none";}
	return false;
}

function upd_votec() {ajax_request("vote.php","voteball","val");};
function upd_story() {ajax_request("story.php","story","inh");};
function upd_hosti() {ajax_request("iphost.php","hostinfo","inh");};

var logos = [2,"img/jab-vs-icq_logo.png","img/icqdie_logo.png","img/jlampa_logo.png","img/nokaktus_logo.png","img/lamp-natural.png","img/noicq_logo.png","http://chart.apis.google.com/chart?cht=qr&chs=90x90&chl=ICQ%20MUST%20DIE!!!"];
function newlogo() {
	if (logos[0] > 7) {logos[0] = 1;}
	logoimg.src = logos[logos[0]];
	logos[0]++;
};

function sendm() {
	var nick = document.getElementById("nick");
	var contact = document.getElementById("contact");
	var message = document.getElementById("message");

	if (nick.value.length <= 1 || nick.value.length > 50) {
		alert("Имя должно быть от 2 до 50 символов!");
		nick.focus();
		return false;
	};

	if (contact.value.length <= 6 || contact.value.length > 100) {
		alert("Контактная информация должна быть от 7 до 100 символов!");
		contact.focus();
		return false;
	};

	if (message.value.length <= 4 || message.value.length > 1024) {
		alert("Объём сообщения должен быть от 5 до 1024 символов!");
		message.focus();
		return false;
	};
	ajax_request("mess.php?ajax=on&nick="+nick.value+"&contact="+contact.value+"&message="+message.value,"mainframe","alt");
	nick.value = contact.value = message.value = "";
	//setTimeout('ajax_request("xmpp.php?mes=New message","mainframe","nul");', 5000);
};


// © Балдуев Илья
