var prevcred = new Array("", "", "", "", "", "");
var pcid = 1;

function switchBlock(id){
	var block = document.getElementById(id);
	if (block.style.display != 'none') {
		block.style.display = 'none';
		//setCookie('block_'+id, 'hidden');
	} else {
		block.style.display = 'block';
		//setCookie('block_'+id, 'visible');
	}
	return false;
}
function switchSearch(a){
	var s = document.getElementById('search');
	if (s.style.display == 'block'){
		s.style.display = 'none';
		a.className = 'search';
	} else {
		s.style.display = 'block';
		a.className = 'search search_on';
	}
	return false;
}
function showSub(id){
	did = "d"+id;
	d = document.getElementById(cid);
	d.style.display = 'none';
	d = document.getElementById(did);
	d.style.display = 'block';
	cid = did;
}
function adv_manuf1() {
	ajx.query(
	'load.php?file=manuf',
	{ 'form': dId('sform') },
	function(responseJS,responseText) {
		//alert(responseJS.m);
		if(responseJS.m == "1") dId('model').disabled = true; else  dId('model').disabled = false;
		dId('div_manuf').innerHTML = responseJS.q;
	},
	true
	);
}
function adv_model1() {
	ajx.query(
	'load.php?file=model',
	{ 'form': dId('sform') },
	function(responseJS,responseText) {
		dId('div_model').innerHTML = responseJS.q;
		if(responseJS.m == "1") dId('model').disabled = true; else  dId('model').disabled = false;
	},
	true
	);
}
function year(){
	window.open('native.php','','copyhistory=0,directories=0,height=355,width=640,left=190,top=130,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function rates(){
	window.open('http://www.exchangerate.com/past_rates.html?cid=118&year=&month=&last30=yes&currency=239&action=Submit&cont=All','','copyhistory=0,directories=0,height=505,width=640,left=190,top=130,location=0,menubar=1,resizable=1,scrollbars=1,status=0,toolbar=1').focus();
}
function calc(){
	window.open('calc.php','calcs','copyhistory=0,directories=0,height=555,width=640,left=190,top=130,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function calcr(){
	window.open('calcr.php','calcy','copyhistory=0,directories=0,height=555,width=640,left=190,top=130,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function printv(text){
	pw = window.open('','print','copyhistory=0,directories=0,height=555,width=640,left=190,top=130,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
	pw.document.write(text);
	pw.document.close();
}
function reg(){
	window.open('http://sumotori.ru/reg_form.php','register','copyhistory=0,directories=0,height=430,width=560,left=200,top=250,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function delivery(){
	window.open('delivery.php','delivery','copyhistory=0,directories=0,height=430,width=560,left=200,top=250,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function agree(clink,price,year,mark_s,mark_e,srok){
	window.open('show_agree.php?clink='+clink+'&price='+price+'&year='+year+'&mark_s='+mark_s+'&mark_e='+mark_e+'&srok='+srok,'agree','copyhistory=0,directories=0,height=550,width=680,left=200,top=250,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function agree2(clink,price,year,mark_s,mark_e,srok){
	window.open('show_da.php?clink='+clink+'&price='+price+'&year='+year+'&mark_s='+mark_s+'&mark_e='+mark_e+'&srok='+srok,'agree','copyhistory=0,directories=0,height=550,width=680,left=200,top=250,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0').focus();
}
function dId(ob) {return document.getElementById(ob);}
function adv_year() {
	ajx.query(
	'load.php?file=year',
	{ 'form': dId('sauto') },
	function(responseJS,responseText) {
		dId('div_year').innerHTML = responseJS.q;
		if(responseJS.m == "0") dId('year').disabled = true; else dId('year').disabled = false;
		var t_out=dId('table_out');
		t_out.innerHTML = "";
		check_all();
	},
	true
	);
}
function adv_model() {
	ajx.query(
	'load.php?file=model',
	{ 'form': dId('sauto') },
	function(responseJS,responseText) {
		//alert(responseJS.q);
		dId('div_model').innerHTML = responseJS.q;
		dId('year').disabled = true;
		if(responseJS.m == "0") dId('model').disabled = true; else  dId('model').disabled = false;
		var t_out=dId('table_out');
		t_out.innerHTML = "";
		check_all();
	},
	true
	);
}
function adv_var() {
	ajx.query(
	'load.php?file=loader',
	{ 'form': dId('sauto') },
	function(responseJS,responseText) {
		eval(responseJS.q);
		var t_out=dId('table_out');
		if(typeof(data)!='undefined')  {t_out.innerHTML = ajtpl.go('ajtpl',data);}
		if(typeof(data2)!='undefined') {t_out.innerHTML = ajtpl.go('ajtpl2',data2);}
	},
	true
	);
}
function clang(item){
	type="cid"; i=0;
	chb = dId(type + "[" + item +"]");
	while (blah = dId(type + "[" + i +"]")) {
		blah.checked = 0;
		//eval("document.sauto.cid["+i+"].checked=0");
		i++;
	}
	chb.checked = true;
	check_all();
}
function a_check(){
	type="cid"; i=0; chk = 0;
	while (blah = dId(type + "[" + i +"]")) {
		if(blah.checked == true){ chk = 1; clink=blah.value; break;} 
		i++;
	}
	return chk;
}
function csrok(val){
	var srok = dId("srok");
	if(val){
		srok.value = "0";
		srok.disabled = true;
	}
	else{
		srok.disabled = false;
	}
}
function credit1(id){
	var lcont, lid;
	dId('lcred').style.display = 'none';
	dId('cred').style.display = 'block';

	ccont = prevcred[id]; 
	cid = 'cl'+pcid; dId(cid).style.background = '#ffffff'; 
	cid = 'cl'+id; dId(cid).style.background = '#cccccc';
	pcid = id; 
	if(ccont.length > 0){ dId('c1').innerHTML=ccont; eval('r'+id+'calculate()'); }
	else {
		ajx.query(
		'ajx_credit.php?file='+id,
		{ 'form': dId('cform') },
		function(responseJS,responseText) {
			ccont = responseJS.q;
			prevcred[id] = ccont;
			dId('c1').innerHTML=ccont;
			eval('r'+id+'calculate()');
		},
		true
		);
	}
}
function credit(id){
	var lcont, lid;
	dId('lcred').style.display = 'none';
	dId('cred').style.display = 'block';
	for(i=1;i<=4;i++){
		dId('c'+i).style.display='none';
		dId('cl'+i).style.background = '#ffffff';
	}
	dId('c'+id).style.display='block';
	dId('cl'+id).style.background = '#cccccc';
	if(id == 5){
		r5calculate();
	}
	if(id == 4){
		r4calculate();
	}
	if(id == 3){
	}
	if(id == 2){
		dId('srok2').value = 12;
		r2calculate();
	}
	if(id == 1){
		dId('srok1').value = 12;
		r1calculate();
	}
	if(id == 0){
		rcalculate();
	}

}
function ccred(){
	dId('cred').style.display = 'none';
	dId('lcred').style.display = 'block';
}
function map(map){
	window.open('http://sumotori.ru/images/place/'+map,'map','copyhistory=0,directories=0,width=430,height=430,left=200,top=250,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0').focus();
}
