function check_ident() {
	var ident_code=document.getElementById('ident_code').value;

//	var ajax_url= 'http://replicart.ru/data/info.php?ident_code='+ ident_code;
//	var ajax_url= 'http://85.21.32.18/recart/requestClient.php?contract=' + ident_code;
	var ajax_url= 'http://pacheco.ru/bases/recart/requestClient.php?contract=' + ident_code;
	var user_i= reqb(ajax_url, 'GET', null);

	var adress=document.getElementById('adress');
	var dop=document.getElementById('features');
	var bot= document.getElementById('bot');

	var lines= new Array;
	if (user_i=='error1') {
	    adress.value='';
	    dop.value='';
	    bot.disabled=true;
	}
	else {
	    lines=user_i.split("~");

        if (lines.length >1) {
				adress.value=lines[1];
				dop.value=lines[0]+', '+lines[2]+', '+lines[3];
				bot.disabled=false;
	    }
	}

	/*	var user_info_div= document.getElementById('user_info');
		user_info_div.innerHTML= user_i;
		var ajax_url= 'exec.php?do=check_ident_bot&ident_code='+ ident_code +'&ajax=true';
		var dbot= reqb(ajax_url, 'GET', null);

		dbot=parseInt(dbot);
		var bot= document.getElementById('bot');
		if (dbot!='0') bot.disabled=false;
		else */
}

function getStatusAct()
{
    var act_id=document.getElementById('status_act').value;
    var status_div=document.getElementById('status_check');
//  	var ajax_url='http://replicart.ru/data/stat.php?act='+act_id+'&rand='+Math.random();
//    var ajax_url='http://85.21.32.18/recart/statusRequest.php?act='+act_id;
    var ajax_url='http://pacheco.ru/bases/recart/statusRequest.php?act='+act_id;
    var answer= reqb(ajax_url, 'GET', null);

    /*
	var lines=new Array();
    var i=0;

    lines=answer.split("|||");
    answer='';
    for (i=0;i<lines.length;i++){
	var line=new Array();
	line=lines[i].split("~");
	if (line.length >1) {

    	    answer+='Модель картриджа: '+line[0]+'<br/>';
    	    answer+='Серийный номер: '+line[1]+'<br/>';
	    	answer+='Результат диагностики: '+line[2]+'<br/>';
    	    answer+='Подтверждено клиентом: '+line[3]+'<br/>';
		    answer+='Дата работы: '+line[4]+'<br/>';
    	    answer+='Комментарии: '+line[5]+'<br/><br/>';
	}
    }
	*/

    status_div.innerHTML=answer;

}

function recount() {
	var tPrice= document.getElementById('get_car');
	if (!tPrice) return;

	var totalprice= 0; var totalquantity= 0;
	for (var j= 2; j < tPrice.rows.length; j++) {
	var sWork1=tPrice.rows[j].cells[3].lastChild.checked;
	var 	sWork2=tPrice.rows[j].cells[4].lastChild.checked;
		var quantity=0;
		if (sWork1) {
			var price = tPrice.rows[j].cells[3].textContent;
			var oInput = tPrice.rows[j].cells[2].getElementsByTagName("input")[0];
			quantity = parseInt(oInput.value);
		}
		if(sWork2) {
			var price = tPrice.rows[j].cells[4].textContent;
			var oInput = tPrice.rows[j].cells[2].getElementsByTagName("input")[0];
			quantity = parseInt(oInput.value);
		}

		if (!quantity) {
			quantity= 0;
			//oInput.value= 0;
		}

		totalquantity+= quantity;
		totalprice+= quantity*price;
	}

	var oTotalPrice= document.getElementById('total_cost');
	//var oTotalQuantity= document.getElementById('quantity');

	oTotalPrice.innerHTML= 'Итого: '+totalquantity+' картриджей на сумму '+totalprice+' руб.';
	//oTotalQuantity.innerHTML= +' шт.';
}

function check_check(pos,id){
var tPrice= document.getElementById('get_car');

	id++;
	if (pos == '1') {
		var sWork1 = tPrice.rows[id].cells[3].lastChild.checked;
	}
	else {
		var sWork2 = tPrice.rows[id].cells[4].lastChild.checked;
	}
	if (sWork1) {
		tPrice.rows[id].cells[3].lastChild.checked=true;
			//
		//if (sWork2)
		tPrice.rows[id].cells[4].lastChild.checked=false;
		}
	if (sWork2) {
		tPrice.rows[id].cells[4].lastChild.checked=true;
		tPrice.rows[id].cells[3].lastChild.checked=false;
		}
recount();
}

function addNewDev(){

	carTable= document.getElementById('get_car');
	var newLine=new Array(4);
	var id=carTable.rows.length-1;
	var carTable= document.getElementById('get_car');


	var ajax_url= 'exec.php?do=order_get&newline=1&row='+id+'&mass=0&ajax=true';
	newLine[0]= reqb(ajax_url, 'GET', null);
	var ajax_url= 'exec.php?do=order_get&newline=1&row='+id+'&mass=1&ajax=true';
	newLine[1]= reqb(ajax_url, 'GET', null);
	var ajax_url= 'exec.php?do=order_get&newline=1&row='+id+'&mass=2&ajax=true';
	newLine[2]= reqb(ajax_url, 'GET', null);
	var ajax_url= 'exec.php?do=order_get&newline=1&row='+id+'&mass=3&ajax=true';
	newLine[3]= reqb(ajax_url, 'GET', null);
	var ajax_url= 'exec.php?do=order_get&newline=1&row='+id+'&mass=4&ajax=true';
	newLine[4]= reqb(ajax_url, 'GET', null);




	var newRow=carTable.insertRow(-1);//добавляем строку в созданной таблице
		var newCell = newRow.insertCell(-1);//в созданной строке добавляем столбец
		newCell.innerHTML=newLine[0];

		var newCell = newRow.insertCell(-1);//добавляем ещё один столбец
		newCell.innerHTML=newLine[1];
	var newCell = newRow.insertCell(-1);//добавляем ещё один столбец
		newCell.innerHTML=newLine[2];
	var newCell = newRow.insertCell(-1);//добавляем ещё один столбец
		newCell.innerHTML=newLine[3];
	var newCell = newRow.insertCell(-1);//добавляем ещё один столбец
		newCell.innerHTML=newLine[4];

}


function selectDevce(selId){
	var id=selId.value;
	var id_s=selId.id;
	var row_id=document.getElementById('get_car').rows.length-2;
	var ajax_url= 'exec.php?do=order_get&dev='+id+'&row='+row_id+'&ajax=true';

	if (car_for_device= reqb(ajax_url, 'GET', null)) {
		car_select= document.getElementById('car_select_'+id_s);
		if (car_select) car_select.innerHTML= car_for_device;

		return false;
	}
	else return true;
}

function selectCar(selId) {
	var id=selId.value;
	var nameDiv=selId.parentNode.id
	var myN1=nameDiv.split("_");
	var id_s=myN1[2];
	var ajax_url= 'exec.php?do=order_get&car='+id+'&cost=1&ajax=true';

	if (cost1= reqb(ajax_url, 'GET', null)) {
		cost1_html= document.getElementById('cost1_'+id_s);
		if (cost1) cost1_html.innerHTML= cost1;


	}
	var ajax_url= 'exec.php?do=order_get&car='+id+'&cost=2&ajax=true';
	if (cost2= reqb(ajax_url, 'GET', null)) {
		cost2_html= document.getElementById('cost2_'+id_s);
		if (cost2) cost2_html.innerHTML= cost2;


	}
	var car_id=document.getElementById('carh_'+id_s);
	car_id.value=id;





}

function get_diller(selID){
	var id=selID.value;
	var ajax_url= 'exec.php?do=order_get&metro='+id+'&ajax=true';
	diller_div= document.getElementById('diller_info');
	diller_div.innerHTML= '';
	if (dillers= reqb(ajax_url, 'GET', null)) {
		diller_div= document.getElementById('diller_select');
		if (dillers) diller_div.innerHTML= dillers;

		return false;
	}
	else return true;
}

function upd_content(div_id, url) {
	oDiv= document.getElementById(div_id);
	if (!oDiv) return true;

	oDiv.innerHTML= reqb(url, 'GET', null);
	return false;
}
function dillerInfo(selID){
	var id=selID.value;
	/*var iDiller=document.getElementById('diller_id_hidden');
	iDiller.value=id;*/

	var ajax_url= 'exec.php?do=order_get&diller='+id+'&ajax=true';
	if (diller= reqb(ajax_url, 'GET', null)) {
		diller_div= document.getElementById('diller_info');
		if (diller) diller_div.innerHTML= diller;


	}
	/*var ajax_url= 'exec.php?do=order_get&diller_name='+id+'&ajax=true';
	if (diller= reqb(ajax_url, 'GET', null)) {
		diller_div= document.getElementById('your_choose');
		if (diller) diller_div.innerHTML= diller;

		return false;
	}*/

	else return true;

}
function dillerInfoOne(selID){
	var id=selID.value;
	if (id) {
	var ajax_url= 'exec.php?do=order_get&diller='+id+'&ajax=true';
	if (diller= reqb(ajax_url, 'GET', null)) {
		diller_div= document.getElementById('diller_info');
		if (diller) diller_div.innerHTML= diller;
		return false;

	}
	else return true;
	}
}

function metro_search_word(text){
	//var =text.value;
	var startWord = text.value;
	//var startWord=text.value;
	if (!startWord) startWord='all';
		var ajax_url = 'exec.php?do=order_get&search_station=' + startWord + '&ajax=true';
		if (search = reqb(ajax_url, 'GET', null)) {
			station_div = document.getElementById('metro_all');
			if (search)
				station_div.innerHTML = search;

			return false;


	}
}

function save_user() {
	var ident_code=document.getElementById('ident_code').value;
	var user_name=document.getElementById('user_name').value;
	var user_post=document.getElementById('user_post').value;
	var user_email=document.getElementById('user_email').value;
	var user_organization=document.getElementById('user_organization').value;
	var user_phone=document.getElementById('user_phone').value;
	var error_msg;
	if (user_name) {
		if (user_post) {
			if (user_email) {
				if (user_organization) {
					if (user_phone) {
						var ajax_url= 'exec.php?do=save_user&ident_code='+ ident_code +'&name='+ user_name +'&post='+ user_post +'&email='+ user_email +'&organization='+ user_organization +'&phone='+ user_phone +'&ajax=true';
						var user_info= reqb(ajax_url, 'GET', null);
						var	user_info_div= document.getElementById('user_info');
							user_info_div.innerHTML= user_info;
						return false;

					} else {save_user_error('Не введен Телефон');}
				} else {save_user_error('Не введена Организация');}
			} else {save_user_error('Не введен E-mail');}
		} else {save_user_error('Не введена Должность');}
	} else {save_user_error('Не введено имя');}

}

function save_user_error(msg){
user_error= document.getElementById('user_error');
var html_error;
html_error='<div style="background:#FFFFFF left top no-repeat;padding-top:15px;padding-left:15px;padding-bottom:10px;>';
html_error=html_error + '<font color="red">'+ msg +'</font></div>';
user_error.innerHTML=html_error;
}

/**
 * Переключение режима для слепых
 */
function pure_see_main(sender)
{

	var i='1';

	for (i = 1; i <= 11; i++) {
		var pp= document.getElementById('pure_'+i);
		var text_id=document.getElementById('pure_'+i).firstChild.nodeValue;
		if ((pp.className=='')||(pp.className=='normal_font')||(pp.className=='right_r_nowidth')) pp.className='normal_font_big';
		else pp.className='normal_font';
	}
	var ss=document.getElementById('s_s');
	var image = sender.getElementsByTagName('img')[0];
	if (ss.getAttribute('on') == 1) {
		ss.innerHTML = 'Для людей со<br/>слабым зрением';
		ss.setAttribute('on', 0);
		image.src = image.src.replace(/_on\.jpg/, '.jpg');
	} else {
		ss.innerHTML = 'Нормальный<br/>режим';
		ss.setAttribute('on', 1);
		image.src = image.src.replace(/\.jpg/, '_on.jpg');
	}
	return false;
}

function pure_see(sender)
{

	var pp;

	for (var i = 1; i <= 12; i++) {
		pp = document.getElementById('pure_see_'+i);
		if (pp && pp.firstChild) {
			var text_id = pp.firstChild.nodeValue;
			if ((pp.className == '') || (pp.className == 'sh_text'))
				pp.className = 'sh_text_big';
			else
				pp.className = 'sh_text';
		}
	}
var ss=document.getElementById('s_s');
	var image = sender.getElementsByTagName('img')[0];
	if (ss.getAttribute('on') == 1) {
		ss.innerHTML = 'Для людей со<br/>слабым зрением';
		ss.setAttribute('on', 0);
		image.src = image.src.replace(/_on\.jpg/, '.jpg');
	} else {
		ss.innerHTML = 'Нормальный<br/>режим';
		ss.setAttribute('on', 1);
		image.src = image.src.replace(/\.jpg/, '_on.jpg');
	}

	return false;
}

function answers(mod) {
	var div_id=mod.parentNode.id;
	var mA=div_id.split("_");
	var mAb=document.getElementById('answer_a_' + mA[1]);

	if (mAb.style.display=='')mAb.style.display='none';
	else mAb.style.display='';
	return false;

}
function answers_check() {

	var name=document.getElementById('q_name').value;
	var question=document.getElementById('q_question').value;
	var mail=document.getElementById('q_mail').value;

	if (name) {
		if (question) {
				var ajax_url= 'exec.php?do=add&q_name='+ name +'&q_question='+ question +'&q_email='+ mail +'&ajax=true';
				var ans= reqb(ajax_url, 'GET', null);
				var ans_div= document.getElementById('div_q');
			if (ans) ans_div.innerHTML= ans;
		} 
		else { 
			alert('Введите вопрос'); 
		}
	}else { alert('Введите Имя'); }
}



function printcatalog(){
var brand=document.getElementById('brand').value;
var device=document.getElementById('device').value;
var text=document.getElementById('text').value;
var str='/print/catalog.php?brand='+brand+'&device='+device+'&text='+text
myWin= open(str, "displayWindow");
}
function printorder(id){
var str='?print=1&id='+id;
myWin= open(str, "displayWindow");
}
//******************************************************************************
function reqb(url, method, data)
{
	if (window.XMLHttpRequest) {
		HttpRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		HttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
	}
	else return false;


	HttpRequest.open(method, url, false);

	HttpRequest.send(data);
	if (HttpRequest.status == 200) return HttpRequest.responseText;
	else return false;
}

function openWin(wUri, wName, wWidth, wHeight, wScroll, wMenu, wResizable) {
	var scrollBars = (wScroll!=0) ? 1 : 0;
	var menuBars = (wMenu) ? 1 : 0;
	var resizable = (wResizable) ? 1 : 0;
	var positionLeft = (screen.width - wWidth)/2;
	var positionTop = (screen.height - wHeight)/2;
	var myW = window.open(wUri,wName,'width='+wWidth+',height='+wHeight+',top='+positionTop+',left='+positionLeft+',location=0,menubar='+menuBars+',resizable='+resizable+',scrollbars='+scrollBars+',status=0,titlebar=0,toolbar=0,directories=0,hotkeys=0')
	myW.focus();
}
