/** Simple tip **/
function show_tip(text) {
	Tip(text, SHADOW, false, BORDERCOLOR, '#B7B7B7', BORDERWIDTH, 1, BGCOLOR, '#FAFAF8', WIDTH, -1);
}
function show_window(title, text) {
	Tip(text, CLOSEBTN, false, CLOSEBTNTEXT, 'x', SHADOW, false, BORDERCOLOR, '#98f256', BORDERWIDTH, 1, BGCOLOR, '#f3ffea', WIDTH, -300, STICKY, true, PADDING, 10, CENTERWINDOW, true, CENTERALWAYS, true);
}

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;
}

/** Ajax **/
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);
		}
	}
}

/** Check form **/
function check() {
    if (document.getElementById('u1').value == '') {
		document.getElementById('u1').setAttribute('style', 'border:1px solid red; background-color:#ffebeb');
		alert('Вы не указали Ваше имя');
	}
	else if (document.getElementById('u2').value == '') {
		document.getElementById('u2').setAttribute('style', 'border:1px solid red; background-color:#ffebeb');
		alert('Вы не указали Ваш телефон');
	}
	else document.forms.trash.submit();
}
function done(id) {
	document.getElementById('u'+id).setAttribute('style', '');
}

function wheel_price(price) {
    document.getElementById('wheel_price').innerHTML = price;
	var total_ = document.getElementById('total_summ_').innerHTML - 0;
	var total = 0;
	total = total_ + price;
    document.getElementById('total_summ').innerHTML = total;
}

/** Chat **/
function send_message() {
    var message = document.getElementById('message').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	if (message == '') {
		alert('Введите сообщение');
	}
	else {
		ajax('chat.php', 'messages', 'message::email::phone', message+'::'+email+'::'+phone, 'value');
	}
}
function chat_dump(uid) {
    if (uid > 0) ajax('chat_dump.php', 'messages', 'uid::', uid+'::', 'value');
}

