﻿// JScript File

var overfkag = 0;
var check = document.getElementsByTagName('input')
var dv = document.getElementsByTagName('div')
var tr = document.getElementsByTagName('tr')
var span = document.getElementsByTagName('span');
function allChecked(){	
	for(var i=0;i<check.length;i++){
		if(check[i].getAttribute('type') == 'checkbox'){
			check[i].checked = true;
		}
	}
}
 
// закрытие/открытие блоков
function openCategori(attr){
	for(var i=0;i<dv.length;i++){
		if(dv[i].getAttribute('categori') == attr){
			dv[i].style.display = dv[i].style.display == 'none'?'block':'none';  
			getEl(attr).style.display = dv[i].style.display == 'none'?'block':'none';
		}
	}
}
 
function onCheck(attr, p, advattr){
	for(var i=0;i<check.length;i++){
		if(check[i].getAttribute('categori') == attr){
			if(p.checked == true){
			check[i].checked = true;
			checkCat = check[i].getAttribute('onclick');
			if(checkCat){
			checkCat = checkCat.toString()
			t = checkCat.indexOf("'")
			t += 1;
			v = checkCat.indexOf("'", t)
			r = checkCat.slice(t, v)
				for(var b=0;b<check.length;b++){
					if(check[b].getAttribute('categori') == r && p.getAttribute('categori') != r){
						check[b].checked = true;
					}
				}
			}
			}else{
			checkCat = check[i].getAttribute('onclick');
			if(checkCat){
			checkCat = checkCat.toString();
			t = checkCat.indexOf("'")
			t += 1;
			v = checkCat.indexOf("'", t)
			r = checkCat.slice(t, v)
				for(var b=0;b<check.length;b++){
					if(check[b].getAttribute('categori') == r && p.getAttribute('categori') != r){
						check[b].checked = false;
					}
				}			
			}
			check[i].checked = false;
			}
		}
	}
	if(advattr){
		allChcategori = 0;
		for(var b=0;b<check.length;b++){
			if(check[b].getAttribute('categori') == advattr){
				if(check[b].checked == true)
				allChcategori += 1;
			}
		}
		for(var b=0;b<check.length;b++){
			if(check[b].getAttribute('city') == advattr){
				if(allChcategori == 0){
				check[b].checked = false;
				}else{
				check[b].checked = true;				
				}
			}
		}
	}
}
function catOver(n, stat){
	n.style.background = '#fcfcf2'
	getEl(stat).style.visibility = 'visible';
}
function catOut(n, stat){
	n.style.background = '#f1f1e7'
	getEl(stat).style.visibility = 'hidden';
}
 
 
function checkUp(city, tp){
	maxChecked = 0;
	maxCheckedCity = 0;
	for(var b=0;b<check.length;b++){
		if(check[b].getAttribute('categori') == tp.getAttribute('categori')){
			if(check[b].checked == true)
			maxChecked += 1;
		}
	}
	for(var b=0;b<check.length;b++){
		if(check[b].getAttribute('categori') == city){
		checkCat = check[b].getAttribute('onclick').toString();
			t = checkCat.indexOf("'")
			t += 1;
			v = checkCat.indexOf("'", t)
			r = checkCat.slice(t, v)
			if(r == tp.getAttribute('categori')){
				if(maxChecked > 0){
				check[b].checked = true;
				}else{
				check[b].checked = false;				
				}
			}
		}
	}
	for(var b=0;b<check.length;b++){
		if(check[b].getAttribute('categori') == city){
			if(check[b].checked == true)
			maxCheckedCity += 1;
		}
	}
	for(var b=0;b<check.length;b++){
		if(check[b].getAttribute('city') == city){
			if(maxCheckedCity > 0){
			check[b].checked = true;
			}else{
			check[b].checked = false;
			}
		}
	}
}
 
function allChecked()
{	
	$("input[type='checkbox']").attr("checked","checked");
}
 
function totalCats()
{
    $("#allCat").text($("input:checked[childcat='1']").length);
}
 
 
 
//функция выбора списка, тут же подгружается нужный код.
function init_orders_list(){	
    $("tr.cityOnclick").mouseover(function() { if($(this).attr("over") == 0) this.style.background = '#f1f1e7'; 
                                        })
                       .mouseout(function() { if($(this).attr('over') == 0) this.style.background = '#fcfcf2';	
                                        })
                       .click(function(){ 
                            
                            $("tr.cityOnclick").css({"background" : "#fcfcf2"});
                            $("tr.cityOnclick").attr("over", "0");
                            
                            $("span.countContent").html('');
                            $("span.countContent").css({'display':'none'});
                            
                            this.style.background = '#f1f1e7';
				            getTrId = $(this).attr('advid');
				            $(this).attr("over","1");
				            $("#"+getTrId).html('<div align="center"><img src="content/img/generator.gif"></div>'); //загружаем 
				            $("#"+getTrId).css({"display":"block"});
                            
                            mode = '';
                            if ($(this).attr('old') == '1')
                                mode = 'old';

                            $.get("ajax/order_info.aspx", {id: getTrId, mode: mode},
                                        function(data)
                                        {
                                            $("#"+getTrId).html(data);

                                        });

                        });

}
 

