function get_http(){
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new
                ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    @else
        xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function ajax(fileway, select_id, data, value, fill_type) {
	this.http = get_http();
	this.working = false;
	var url = '/inc/ajax/' + fileway;
	if (!this.working && this.http) {
	   	var http = this.http;
	    url = url + '?';
	    var arr_data = data.split('::');
	    var arr_value = value.split('::');
		for(i=0; i<arr_data.length; i=i+1) {
        	url = url + arr_data[i] + '=';
        	if(arr_value[i]) url = url + encodeURIComponent(arr_value[i]);
        	url = url + '&';
    	}
		this.http.open("GET", url, true);
	    this.http.onreadystatechange = function() {
			if (http.readyState == 4) {
				if (fill_type == 'select') fill_select(select_id, http.responseText);
        	   	else fill(select_id, http.responseText, fill_type);
                this.working = false;
                document.getElementById('loadline').innerHTML = '';
	        }
	        else {
	        	document.getElementById('loadline').innerHTML = '<div class="loadline"></div>';
	        }
    	}
        this.working = true;
	    this.http.send(null);
	}
	if(!this.http) {
    	alert('Ошибка при создании XMLHTTP объекта!')
	}
}
function fill (select_id, data, fill_type) {
	var insert = document.getElementById(select_id);
	if (fill_type == 'input') insert.value = data;
    else if (fill_type == 'window') show_window('DREN', data);
    else if (fill_type == 'return') errors(data);
    else insert.innerHTML = data;
}
function fill_select (select_id, data) {
	if (data) {
		var select = document.getElementById(select_id);
    	select.options.length = 0;
    	if(data.length == 0) return;
    	var arr = data.split('--|--');
    	for(var i=0; i<arr.length; i++) {
        	val = arr[i].split('---');
        	select.options[select.options.length]=new Option(val[1], val[0], false, false);
		}
	}
}

function comments() {
	if (document.getElementById('m2').value == "") alert('Введите сообщение');
	else {
        var message = document.getElementById('m2').value;
        var user = document.getElementById('m1').value;
		var rid = document.getElementById('m3').value;
		var id = document.getElementById('m4').value;
		ajax('comment.php', 'comments_block', 'message::user::rid::id', message+'::'+user+'::'+rid+'::'+id, 'value');
        document.getElementById('m2').value = '';
		var kol = document.getElementById('kolcom').innerHTML - 0 + 1;
		document.getElementById('kolcom').innerHTML = kol;
	}
}

function select_all() {
	var text_val = eval('document.blogform.blog');
    text_val.focus();
    text_val.select();
}

function check(data_send) {
	var arr_data = data_send.split('::');
	for(i=0; i<arr_data.length; i=i+1) {
    	if (!document.getElementById('v'+arr_data[i]).value) {
			document.getElementById('v'+arr_data[i]).setAttribute('style', 'border:1px solid red; background-color:#ffebeb');
			alert('Поле должно быть заполнено');
			return false;
    	}
    }
	return true;
}
function done(id) {
	document.getElementById('v'+id).setAttribute('style', '');
}