
var browser=navigator.userAgent.toLowerCase();
var isIE=((browser.indexOf("msie")!=-1) && (browser.indexOf("opera")==-1));

function changepage(page)
        {
        var form='form1';
        var elem = document.getElementById("page");
        elem.value = page;
        document[form].submit();
        }

function showhide(id)
	{
        var elem = document.getElementById(id);
        if(elem.style.display=='')
        	elem.style.display = 'none';
        else
        	elem.style.display = '';
	}

function loadNewList(level, Selected)
	{
        for(var i=level+1; i<5; i++)
        	{
        	var Links = document.getElementById('Links'+i);
        	if(Links!=null)
        		{
        		$(Links).hide('fast');
        		Links.parentNode.removeChild(Links);
			}
		}

	if(Selected==null || Selected=='')
		return 0;

	var selected = new Array();
	var j = 0;
	var Elems = document.getElementsByTagName('input');
	for(var i=0; i<Elems.length; i++)
		if(Elems[i].type=='radio' && Elems[i].name=='Link[]' && Elems[i].checked)
			{
                        selected[j] = Elems[i].value;
                        j++;
			}
        Elems = document.getElementsByTagName('select');
	for(var i=0; i<Elems.length; i++)
		if(Elems[i].name=='Link[]')
			{
                        selected[j] = Elems[i].value;
                        j++;
			}

        var req = new JSHttpRequest();
        req.onreadystatechange = function()
                {
                if (req.readyState == 4)
                        {
                        //alert(req.responseJS);
                        for(var i=level+1; i<5; i++)
        			{
        			var Links = document.getElementById('Links'+i);
        			if(Links==null)
        				{
        				Links = document.getElementById('Links'+(i-1));
        				break;
					}
				}
                        if(req.responseJS.lastlevel==true)
                        	{
                                newLinks.className = '';
                                Links.innerHTML = req.responseJS.html;
                        	}
                        else
                        	{
				Links.innerHTML = req.responseJS.html;
				}
                        //alert(req.responseText);
                        //window.scrollTo(0, 1000);
                        $.scrollTo( {top:'1000px'}, 800 );
                        }
                }
        req.caching = false;
        req.open("GET", "ajax_getlevels.php", true);
        req.send({selected: selected, level: level+1});

        var submitbutton = document.getElementById('submitbutton');
        var newLinks = document.createElement('div');
        newLinks.id = 'Links'+(level+1);
        newLinks.className = 'LinksBlock';
        newLinks.innerHTML = "<img src='/images/ajax-loader.gif' />";        
        //window.ScrollTop = window.ScrollHeight;
	//Links.parentNode.appendChild(newLinks);
	
	submitbutton.parentNode.insertBefore(newLinks, submitbutton)
	}

function ToggleVisibilityLastLevels(Chekcer, id)
	{
        var Elem = document.getElementById('sublastlevels'+id);
        if(Chekcer.checked)
        	{
        	$(Elem).parent().show();
        	$(Elem).show('normal');
        	//Elem.parentNode.className = 'LinksBlock';
        	//do {Elem = Elem.parentNode;} while (Elem && Elem.tagName!='TABLE');
        	//Elem.style.margin = '20px 0px 0px 0px';
		}
        else
        	{        	
                $(Elem).hide('fast');
                var isShown = false;
                $(Elem).parent().children().each(function (num)
                	{
                	if(this.id!='sublastlevels'+id && this.style.display!='none')
                		isShown = true;	
			});
		if(!isShown)
			$(Elem).parent().hide('fast');	
                //Elem.parentNode.className = '';
                //do {Elem = Elem.parentNode;} while (Elem && Elem.tagName!='TABLE');
                //Elem.style.margin = '0px';
		}
	}
	

function ShowOffice(ID)
	{
	if(showed==0)
		{
		showed = 1;
		$("#OfficeAddress_"+ID).fadeIn("slow", function() {showed = 0});
		}
	}
	
function HideOffice(ID)
	{
	$("#OfficeAddress_"+ID).fadeOut("slow");
	}


var showed = 0;
var OnLogo = 0;
var OnOffice = 0;
function OnLogoOver()
	{
        if(showed==0)
		{
		showed = 1;
		$("#OfficeAddress_1").fadeIn("normal", function() {showed = 0});
		}
	else
		showed = 0;
	OnLogo = 1;
	}
function OnLogoOut()
	{
        OnLogo = 0;
        if(OnLogo==0 && OnOffice==0)
        	{
                setTimeout(function() {
                	if(OnLogo==0 && OnOffice==0)
                        	$("#OfficeAddress_1").fadeOut("normal", function() {OnLogo=0; OnOffice=0;});
                	}, 500);
        	}

	}
function OnOfficeOver()
	{
        OnOffice = 1;
	}
function OnOfficeOut()
	{
	OnOffice = 0;
        if(OnLogo==0 && OnOffice==0)
                setTimeout(function() {
                	if(OnLogo==0 && OnOffice==0)
                        	$("#OfficeAddress_1").fadeOut("normal", function() {OnLogo=0; OnOffice=0;});
                	}, 500);
	}

var showed2 = 0;
var OnLogo2 = 0;
var OnOffice2 = 0;
function OnLogoOver2()
	{
        if(showed2==0)
		{
		showed2 = 1;
		$("#OfficeAddress_2").fadeIn("normal", function() {showed2 = 0});
		}
	else
		showed2 = 0;
	OnLogo2 = 1;
	}
function OnLogoOut2()
	{
        OnLogo2 = 0;
        if(OnLogo2==0 && OnOffice2==0)
        	{
                setTimeout(function() {
                	if(OnLogo2==0 && OnOffice2==0)
                        	$("#OfficeAddress_2").fadeOut("normal", function() {OnLogo2=0; OnOffice2=0;});
                	}, 500);
        	}

	}
function OnOfficeOver2()
	{
        OnOffice2 = 1;
	}
function OnOfficeOut2()
	{
	OnOffice2 = 0;
        if(OnLogo2==0 && OnOffice2==0)
                setTimeout(function() {
                	if(OnLogo2==0 && OnOffice2==0)
                        	$("#OfficeAddress_2").fadeOut("normal", function() {OnLogo2=0; OnOffice2=0;});
                	}, 500);
	}


var showed3 = 0;
var OnLogo3 = 0;
var OnOffice3 = 0;
function OnLogoOver3()
	{
        if(showed3==0)
		{
		showed3 = 1;
		$("#OfficeAddress_3").fadeIn("normal", function() {showed3 = 0});
		}
	else
		showed3 = 0;
	OnLogo3 = 1;
	}
function OnLogoOut3()
	{
        OnLogo3 = 0;
        if(OnLogo3==0 && OnOffice3==0)
        	{
                setTimeout(function() {
                	if(OnLogo3==0 && OnOffice3==0)
                        	$("#OfficeAddress_3").fadeOut("normal", function() {OnLogo3=0; OnOffice3=0;});
                	}, 500);
        	}

	}
function OnOfficeOver3()
	{
        OnOffice3 = 1;
	}
function OnOfficeOut3()
	{
	OnOffice3 = 0;
        if(OnLogo3==0 && OnOffice3==0)
                setTimeout(function() {
                	if(OnLogo3==0 && OnOffice3==0)
                        	$("#OfficeAddress_3").fadeOut("normal", function() {OnLogo3=0; OnOffice3=0;});
                	}, 500);
	}



var showed4 = 0;
var OnLogo4 = 0;
var OnOffice4 = 0;
function OnLogoOver4() {
    if(showed4==0) {
		showed4 = 1;
		$("#OfficeAddress_4").fadeIn("normal", function() {showed4 = 0});
	}
	else
		showed4 = 0;
	OnLogo4 = 1;
}
function OnLogoOut4() {
    OnLogo4 = 0;
    if(OnLogo4==0 && OnOffice4==0) {
        setTimeout(function() {
            if(OnLogo4==0 && OnOffice4==0)
                    $("#OfficeAddress_4").fadeOut("normal", function() {OnLogo4=0; OnOffice4=0;});
            }, 500);
    }
}
function OnOfficeOver4() {
    OnOffice4 = 1;
}
function OnOfficeOut4() {
	OnOffice4 = 0;
    if(OnLogo4==0 && OnOffice4==0)
            setTimeout(function() {
                if(OnLogo4==0 && OnOffice4==0)
                        $("#OfficeAddress_4").fadeOut("normal", function() {OnLogo4=0; OnOffice4=0;});
                }, 500);
}



var showed5 = 0;
var OnLogo5 = 0;
var OnOffice5 = 0;
function OnLogoOver5() {
    if(showed5==0) {
        showed5 = 1;
        $("#OfficeAddress_5").fadeIn("normal", function() {showed5 = 0});
    }
    else
        showed5 = 0;
    OnLogo5 = 1;
}
function OnLogoOut5() {
    OnLogo5 = 0;
    if(OnLogo5==0 && OnOffice5==0) {
        setTimeout(function() {
            if(OnLogo5==0 && OnOffice5==0)
                    $("#OfficeAddress_5").fadeOut("normal", function() {OnLogo5=0; OnOffice5=0;});
            }, 500);
    }
}
function OnOfficeOver5() {
    OnOffice5 = 1;
}
function OnOfficeOut5() {
    OnOffice5 = 0;
    if(OnLogo5==0 && OnOffice5==0)
            setTimeout(function() {
                if(OnLogo5==0 && OnOffice5==0)
                        $("#OfficeAddress_5").fadeOut("normal", function() {OnLogo5=0; OnOffice5=0;});
                }, 500);
}



var showed6 = 0;
var OnLogo6 = 0;
var OnOffice6 = 0;
function OnLogoOver6() {
    if(showed6==0) {
        showed6 = 1;
        $("#OfficeAddress_6").fadeIn("normal", function() {showed6 = 0});
    }
    else
        showed6 = 0;
    OnLogo6 = 1;
}
function OnLogoOut6() {
    OnLogo6 = 0;
    if(OnLogo6==0 && OnOffice6==0) {
        setTimeout(function() {
            if(OnLogo6==0 && OnOffice6==0)
                    $("#OfficeAddress_6").fadeOut("normal", function() {OnLogo6=0; OnOffice6=0;});
            }, 500);
    }
}
function OnOfficeOver6() {
    OnOffice6 = 1;
}
function OnOfficeOut6() {
    OnOffice6 = 0;
    if(OnLogo6==0 && OnOffice6==0)
            setTimeout(function() {
                if(OnLogo6==0 && OnOffice6==0)
                        $("#OfficeAddress_6").fadeOut("normal", function() {OnLogo6=0; OnOffice6=0;});
                }, 500);
}
	
var printed = false;
function myprint()
	{
	if(printed)
		{
		myprint_back();
		printed = false;
		}
	else
		{
		$('#header').hide();
		$('#top_menu').hide();
		$('#last_car').hide();
		$('#footer').hide();
		$('.borderbottom').hide();
		$('a').hide();
		$('a.myprint').show();
		$('a.myprint').html('Назад');
		printed = true;
		setTimeout('myprint_continuation()', 1000)
		}
	}
function myprint_continuation()
	{
	window.print();
	/*$('#header').show();
	$('#top_menu').show();
	$('#last_car').show();
	$('#footer').show();*/
	}
function myprint_back()
	{
	$('#header').show();
	$('#top_menu').show();
	$('#last_car').show();
	$('#footer').show();
	$('.borderbottom').show();
	$('a').show();
	$('a.myprint').html('Версия для печати');
	}
	
function prepareForm()
		{
		/*$('input:hidden', document.form1).each(function (i)
			{
			if(this.name.indexOf('Service')!=-1 || this.name.indexOf('Count')!=-1)
				$(this).remove();
			})*/
		$("input:text", '#content').each(function (i)
			{
	                if(this.value!="")
	                	{
	                	var founded = document.getElementById(this.name+"="+this.value);
	                	if(founded!=null)
	                		founded.value = this.value;
	                	else
                			$(document.form1).append("<input type='hidden' id='"+this.name+"="+this.value+"' name='"+this.name+"' value='"+this.value+"' />");
				}
			});
	        $("select", '#content').each(function (i)
			{
	                if(this.value!="")
	                	{
	                	var founded = document.getElementById(this.name+"="+this.value);
	                	if(founded!=null)
	                		founded.value = this.value;
	                	else
                			$(document.form1).append("<input type='hidden' id='"+this.name+"="+this.value+"' name='"+this.name+"' value='"+this.value+"' />");
				}
			});
		//$(document.form1).append("<input type='hidden' name='p' />");
		}