var lang_cookie_name_php = 'autoaz_language_php';
var lang_cookie_name_js  = 'autoaz_language_js';
var map_icons='';

function Set_Cookie(name,value,expires,path,domain,secure){	var today = new Date(); today.setTime( today.getTime() );if ( expires ) expires = expires * 1000 * 60 * 60 * 24;var expires_date = new Date( today.getTime() + (expires) );document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) +( ( domain ) ? ";domain=" + domain : CDOMAIN ) +( ( secure ) ? ";secure" : "" );	}
function Get_Cookie(check_name) {var a_all_cookies = document.cookie.split( ';' );var a_temp_cookie = '';var cookie_name = '';var cookie_value = '';var b_cookie_found = false; for ( i = 0; i < a_all_cookies.length; i++ ){a_temp_cookie = a_all_cookies[i].split( '=' );cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');if ( cookie_name == check_name ){b_cookie_found = true;if (a_temp_cookie.length > 1){ cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') ); }return cookie_value;break;}a_temp_cookie = null;cookie_name = '';}if(!b_cookie_found){ return null; }}
function addLoadEvent( func ) { var oldonload = window.onload; if (typeof window.onload != 'function') {window.onload = func;} else {window.onload = function() {if (oldonload) {oldonload();}func();}}}
function getPosX(obj) {var curleft = 0;if (obj.offsetParent) {while (obj.offsetParent) {curleft += obj.offsetLeft;obj = obj.offsetParent;}}return curleft;}
function getPosY(obj) {var curtop = 0;if (obj.offsetParent) {while (obj.offsetParent) {curtop += obj.offsetTop;obj = obj.offsetParent;}}return curtop;}
document.getElementsByClassName = function(cl) {var retnode = [];var myclass = new RegExp('\\b'+cl+'\\b');var elem = this.getElementsByTagName('*');for (var i = 0; i < elem.length; i++) {var classes = elem[i].className;if (myclass.test(classes)) retnode.push(elem[i]);}return retnode;};
function gotopage(p){ document.pages.page.value = p; document.pages.submit(); return false; }
function gobase(p){document.location.href=document.getElementsByTagName('base')[0].href+p;}
function onlydigits(o){o.value = o.value.replace(/[^0-9]/g,'');}
function onlyaz09(o){
	o.value = o.value.replace('A','a');
	o.value = (o.value+'').toLowerCase();
	o.value = o.value.replace(/[^0-9a-z]/g,'');
}

function display_this (t) {t.style.display='block';return false;}
function hide_this (t) {if(!t)return;t.style.display='none';return false;}
function toggle_this (t) {if(!t)return;if(t.style.display=='block')hide_this(t);else display_this(t); return false;}
function display_id (t) {return display_this(document.getElementById(t));}
function hide_id (t) {return hide_this(document.getElementById(t));}
function toggle_id (t) {return toggle_this(document.getElementById(t));}
function toggle_features (t) {ta = document.getElementById('darr');ta.innerHTML=document.getElementById(t).style.display=='none'?'&uarr;':'&darr;';return toggle_this(document.getElementById(t));}
function toggle_do_fast(t){t.className=t.className=='r_link1'?'r_link':'r_link1';do_fast_toggle();if(document.getElementById('map_legend')){if(t.className=='r_link') document.getElementById('map_legend').style.top = (parseInt(document.getElementById('map_legend').style.top) - 219) + "px";else document.getElementById('map_legend').style.top = (parseInt(document.getElementById('map_legend').style.top) + 219) + "px";}}
function check_login() {validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;var l=document.getElementById('signin').value;var p=document.getElementById('signpass').value;if (!l){alert(err_home_enter_login); return false;}if (!p){alert(err_home_enter_password); return false;}ajax_loginform(l,p);return false;}
function check_remember() {validRegExp = /^[^@]+@[^@]+[.][a-z]{2,}$/i;if (document.getElementById('email').value == '') { alert(err_home_enter_email); return false; }if ((document.getElementById('email').value)&(!document.getElementById('email').value.match(validRegExp))) { alert(err_home_email_wrong); return false; }ajax_forgot_form(document.getElementById('email').value);}
function value(id){if(document.getElementById(id))return document.getElementById(id).value;return '';}
function checked(id){return document.getElementById(id).checked}
function ifv(id){if(document.getElementById(id))return document.getElementById(id).value=='';return false;}
function aerr(e){alert(e);return false}
function check_fields(c){var i;var f=true;for(i=0;i<c.length;i+=2)if(document.getElementById(c[i])&&ifv(c[i])){f=false;break;}if(!f)alert(c[i+1]);return f;}
function lang_popup(){var l=Get_Cookie(lang_cookie_name_php);if(!l)l='ru';var t = document.getElementById('lang_'+l); hide_this(t);display_id("lang_"+l+"_up")}
function lang_hide(e){
	var l=Get_Cookie(lang_cookie_name_php);
	if(!l)l='ru';
	hide_id("lang_"+l+"_up");
	display_id("lang_"+l);
}
function change_lang(l){
	Set_Cookie(lang_cookie_name_js, l, 300, '/', CDOMAIN, '' );
	var base = document.getElementsByTagName('base')[0].href,mod = window.location.href;mod = mod.replace(base,"");mod = mod.replace(/\/$/, "");mod = mod.split("/");mod = mod[0];
	if(mod=='news') { document.location.href=base+"news/"; return false; }
	if(mod=='articles') { document.location.href=base+"articles/"; return false; }
	document.location.reload(); return false;
}

/*--------------------------------------------------------------*/

function notebook_num () {var n = Get_Cookie('auto_az_notebook'); if(n === null || n=='') return 0; n = n.split(","); return n.length; }
function notebook_add (x) {var n = Get_Cookie('auto_az_notebook'); if(n === null || n=='') { Set_Cookie( 'auto_az_notebook', x, '', '/', CDOMAIN, '' ); notebook_ticker();return false; }	n = n.split(",");	var i; for(i=0;i<n.length;i++) if(n[i]==x) return false;	n.push(x); n = n.join(",");	Set_Cookie( 'auto_az_notebook', n, '', '/', CDOMAIN, '' ); notebook_ticker();return false;}
function notebook_delete (x) {var n = Get_Cookie('auto_az_notebook');	if(n === null || n=='') return false; n = n.split(","); var i; for(i=0;i<n.length;i++) if(n[i]==x) { n.splice(i,1); break; } n = n.join(","); Set_Cookie( 'auto_az_notebook', n, '', '/', CDOMAIN, '' ); notebook_ticker(); document.location.reload(); return false;}
function notebook_ticker() {if(!document.getElementById("floating_notepad"))return;var n = notebook_num();if(n>0) display_id("floating_notepad");else hide_id("floating_notepad");document.getElementById("notepad_num").innerHTML = n;set_baskets_position();}

function SetBasketPosition() {
	var myHeight = 0;
	if (typeof (window.innerWidth) == 'number')	myHeight = window.innerHeight;
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) myHeight = document.documentElement.clientHeight;
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) myHeight = document.body.clientHeight;
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {	scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;} 
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;} 
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;	}
	var width = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
	var notepad = document.getElementById('floating_notepad');
	if(notepad) { 
		notepad.style.top = (myHeight - (notepad.offsetHeight + 8)) + scrOfY - 8 + 'px';
		notepad.style.position = 'absolute';
		width = Math.round(width/2)-500;
		notepad.style.left=width+"px";
	}
}
function notepad_clear(){Set_Cookie( 'auto_az_notebook', '', '', '/', CDOMAIN, '' );hide_id("floating_notepad");document.getElementById("notepad_num").innerHTML = 0;set_baskets_position();}
addLoadEvent(notebook_ticker);

/*--------------------------------------------------------------*/
function compare_num () {var n = Get_Cookie('auto_az_compare'); if(n === null || n=='') return 0; n = n.split(","); return n.length; }
function compare_add (x) {var n = Get_Cookie('auto_az_compare'); if(n === null || n=='') { Set_Cookie( 'auto_az_compare', x, '', '/', CDOMAIN, '' ); compare_ticker();return false; }	n = n.split(",");	var i; for(i=0;i<n.length;i++) if(n[i]==x) return false;	n.push(x); n = n.join(",");	Set_Cookie( 'auto_az_compare', n, '', '/', CDOMAIN, '' ); compare_ticker();return false;}
function compare_delete (x) {var n = Get_Cookie('auto_az_compare');	if(n === null || n=='') return false; n = n.split(","); var i; for(i=0;i<n.length;i++) if(n[i]==x) { n.splice(i,1); break; } n = n.join(","); Set_Cookie( 'auto_az_compare', n, '', '/', CDOMAIN, '' ); compare_ticker(); document.location.reload(); return false;}
function compare_ticker() {if(!document.getElementById("floating_compare"))return;var n = compare_num();if(n>0) display_id("floating_compare");else hide_id("floating_compare");if(document.getElementById("compare_num"))document.getElementById("compare_num").innerHTML = n;set_baskets_position();}
function compare_backet_go(){if(compare_num()<2){ gobase('compare/'); return false;}var url = Get_Cookie('auto_az_compare');url = url.replace(/,/g,'.',url);gobase('compare/'+url+'/');return false;}

function SetBasketPosition_Compare() {
	var myHeight = 0;
	if (typeof (window.innerWidth) == 'number')	myHeight = window.innerHeight;
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) myHeight = document.documentElement.clientHeight;
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) myHeight = document.body.clientHeight;
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {	scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;} 
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;} 
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;	}
	var width = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
	var compare = document.getElementById('floating_compare');
	if(compare) { 
		compare.style.top = (myHeight - (compare.offsetHeight + 8)) + scrOfY - 8 +  'px';
		compare.style.position = 'absolute';
		width = Math.round(width/2)-280;
		if(document.getElementById("floating_notepad")) if(document.getElementById("floating_notepad").style.display!='block') width-=220;
		compare.style.left=width+"px";
	}
}

function compare_clear(){Set_Cookie( 'auto_az_compare', '', '', '/', CDOMAIN, '' );if(document.getElementById("floating_compare")){hide_id("floating_compare");document.getElementById("compare_num").innerHTML = 0;}set_baskets_position();}
addLoadEvent(compare_ticker);
/*--------------------------------------------------------------*/

function set_baskets_position(){
	SetBasketPosition();
	SetBasketPosition_Compare();
	if(map_icons) position_legend();
}

window.onscroll = function(){set_baskets_position();};
window.onresize = function(){set_baskets_position();};


function preload_images(){var is=['op_l.jpg','h1.gif','h2.gif','o1.png','o2.png','o3.png','o4.png'];var isa=[];var i;for(i=0;i<is.length;i++){isa[i]=new Image;isa[i].src="images/"+is[i];}}
if(ADOMAIN) addLoadEvent(preload_images);
function HideShowNomenc(isFull) { document.getElementById('partialBrands').style.display = isFull ? 'none' : 'block'; document.getElementById('fullBrands').style.display = isFull ? 'block' : 'none';}
var quick_search_count = 0;
function quick_search(){
	if(!quick_search_count)return;
	var bid = document.getElementById("quick_search_brands").value;	bid = bid.split('|');bid = bid[1];
	var mid = document.getElementById("quick_search_models").value;	mid = mid.split('|'); mid = mid[1];
	var age = document.getElementById("quick_search_age").value;
	var pri = document.getElementById("quick_search_price").value;
	var filter = "cars/";
	if(bid) filter+="brand/"+bid+"/";
	if(mid) filter+="model/"+mid+"/";
	if(age!='0') filter+="age/"+age+"/";
	if(pri!='0') filter+="price/"+pri+"/";
	document.location.href=document.getElementsByTagName('base')[0].href + filter;
}
function car_open_gallery(obj,img){hs.close();hs.htmlExpand(obj, { contentId: 'img_gallery', objectWidth:670, allowMultipleInstances:false, dimmingOpacity: .001, allowSizeReduction: false, allowHeightReduction: false, align: 'center', outlineType: 'rounded-white', minHeight: 100 } );car_change_gallery(img);return false;}
function car_change_gallery(img){var is = document.getElementsByTagName('img'),i;for(i=0;i<is.length;i++){if(is[i].className=="car_gallery_big_img") is[i].src = 'uploads/ads/'+img;}}

function advancedSearch(){
	var i,v,fields,s='search/';
	fields = ['brand','model','body','kpp','fuel','color','gear','condition','credit'];
	for(i=0;i<fields.length;i++){
		v = value("search_"+fields[i]);
		if(v==""||v=="0"||v=="undefined")continue;
		if(fields[i]=="model"||fields[i]=="brand"){v=v.split("|");v=v[1];}
		s+= fields[i]+"/"+v+"/";
	}
	fields = ['price','motor','prob','year'];
	for(i=0;i<fields.length;i++){
		v1 = value("search_"+fields[i]+"1");
		v2 = value("search_"+fields[i]+"2");
		if((v1=="0"||v1=="")&&(v2==""||v2=="0"))continue;
		if((v1!="0"&&v1!="")&&(v2!=""&&v2!="0")) v= v1+"-"+v2;
		if((v1=="0"||v1=="")&&(v2!=""&&v2!="0")) v= "-"+v2;
		if((v1!="0"&&v1!="")&&(v2==""||v2=="0")) v= v1+"-";
		s+= fields[i]+"/"+v+"/";
	}
	for(v=[],i=0;i<200;i++){if(!document.getElementById("search_feature_"+i)) continue;if(document.getElementById("search_feature_"+i).checked) v.push(i);}
	if(v.length)s+="features/"+v.join(".")+"/";
	document.location.href=document.getElementsByTagName('base')[0].href+s;
	return false;
}

function goto_page(p){
	var base = document.getElementsByTagName('base')[0].href, path = window.location.href, i, s="", f=0;
	path = path.replace(base,"");
	path = path.replace(/\/$/, "");
	path = path.split("/");
	for(i=1;i<path.length;i+=2)if(path[i]=="page"){ path[i+1]=p; f=1; break; }
	if(!f) { path.push("page"); path.push(p); }
	path = path.join("/")+"/";document.location.href=base+path;return false;
}

function ads_sort_by(what,asc){
	var base = document.getElementsByTagName('base')[0].href, path = window.location.href, i, s="", f=0;
	path = path.replace(base,"");
	path = path.replace(/\/$/, "");
	path = path.split("/");
	var sort = what+'_'+asc;
	for(i=1;i<path.length;i+=2)if(path[i]=="sort"){ path[i+1]=sort; f=1; break; }
	if(!f) { path.push("sort"); path.push(sort); }
	path = path.join("/")+"/";document.location.href=base+path;
	return false;
}

function runFilter(){
	var vars = ['model','price','age','motor','body','drive','fuel'];
 	for(i=0;i<vars.length;i++) eval("var "+vars[i]+"=[];");
	var e = document.filter_form.elements;
	for(i=0;i<e.length;i++) {
		if(e[i].type!='checkbox' || !e[i].checked) continue;
		eval(e[i].name + ".push(e[i].value);");
	}
	var url = [];
 	for(i=0;i<vars.length;i++) {
 		eval("var a = "+vars[i]+".join('.');");
 		if(a!='')url.push(vars[i]+"/"+a);
    }
    url = "cars/brand/"+cur_filter_brand+"/"+url.join('/');
	if(url.length) url+="/";
	document.location.href = document.getElementsByTagName('base')[0].href+url;
	return false;
}

function initFilter(){
	var e = document.filter_form.elements;
	var fi;var i;var j;
	for(fi=0;fi<cur_filter.length;fi++){
		var f = cur_filter[fi];
		var sms = 0;
		for(i=0;i<e.length;i++) {
			if(e[i].type!='checkbox' || e[i].name!=f) continue;
			var ch = false;
			var o = eval("cur_filter_"+f);
			for(j=0;j<o.length;j++) if(e[i].value==o[j]) ch = true;
			e[i].checked = ch;
			if(ch) sms = 1;
		}
		if(sms)toggle_filter(document.getElementById('fd_'+f),'f_'+f);
	}
}

function display_id_near_this(id,t,x,y) {var o = document.getElementById(id).style;o.top = getPosY(t) + (t.offsetHeight || t.style.height) + y + 'px';o.left = getPosX(t) + x + 'px';o.display = 'block';return true;}
function toggle_filter(t,id){
	t.className=t.className=="ic2"?"ic1":"ic2";
	toggle_id(id);
}

AIM = {frame: function(c) {var n = 'f' + Math.floor(Math.random() * 99999);var d = document.createElement('DIV');d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';document.body.appendChild(d);var i = document.getElementById(n);if (c && typeof(c.onComplete) == 'function')i.onComplete = c.onComplete;return n;},form: function(f, name) {f.setAttribute('target', name);},submit: function(f, c) {AIM.form(f, AIM.frame(c));if (c && typeof(c.onStart)=='function')return c.onStart();else return true;},loaded: function(id) {var i = document.getElementById(id);if (i.contentDocument) var d = i.contentDocument;else if (i.contentWindow) var d = i.contentWindow.document; else var d = window.frames[id].document;if (d.location.href == "about:blank")return;if (typeof(i.onComplete) == 'function')i.onComplete(d.body.innerHTML);}}
function uploadphotos_onstart() {if(cars_uploaded_images>=15){alert("Limit reached!");return false;}document.getElementById('file_upload_loader').style.display="inline";return true;}
function uploadphotos_oncomplete(response) {
	tresponse = response;
	hide_id('file_upload_loader');
	if(response=='error'){alert('Bad image');return false;}
	if(response=='big'){alert('Too large file');return false;}
	response = response.split('|');
	cars_uploaded_images++;
	if(cars_uploaded_images>=15) hide_id("images_upload_form");
	var dd = document.getElementsByTagName('base')[0]?'':'../';
	document.getElementById("addcar_photo"+cars_uploaded_images).innerHTML = "<img src='"+dd+"uploads/ads/"+response[0]+"'>";
	display_id("addcar_photo"+cars_uploaded_images);
	document.getElementById("images_upload_form").reset();
	document.getElementById("uploaded_images").value+="*"+tresponse;
}
var cars_uploaded_images = 0;

var varHt = 0;var Ht = 219;var x=0;var z=20;
function do_fast_toggle() {var Hide = document.getElementById("do_fast");if (x === 0) {Hide.style.display = 'block';Hide.style.height = varHt+'px';if (((Ht-varHt) < z) && (varHt !== Ht)) varHt = Ht; else varHt = varHt+z;if (varHt <= Ht) setTimeout('do_fast_toggle()',5);if (varHt > Ht) { varHt = Ht; x = 1;Hide.style.height=varHt+'px';}} else {Hide.style.height = varHt+'px'; varHt = varHt-z;if ((Ht-varHt) <= Ht) setTimeout('do_fast_toggle()',5);if ((Ht-varHt) > Ht) {varHt=x=0;Hide.style.height=varHt+'px';Hide.style.display="none";}}}

// ======== PHONES EDITOR ===================
var board_add_phone_selected_id=board_add_phone_selected_code=board_add_phone_added=0;
function board_add_phone_open(){
	display_id('add_phone'); hide_id('add_phone_button');
	display_id('add_phone_code_select'); hide_id('add_phone_code_display');
	document.getElementById("add_phone_code_display_span").innerHTML = '';
	document.getElementById('add_phone_code_select_input').options[0].selected = true;
	document.getElementById('add_phone_submit_button').className = "add_phone_submit_button_disable";
	document.getElementById('add_phone_number_input').value = '';
	return false;
}
function board_add_phone_ontype(o){
	onlydigits(o);
	document.getElementById('add_phone_submit_button').className = value('add_phone_code_select_input')&&value('add_phone_number_input').length==7?"add_phone_submit_button_enabled":"add_phone_submit_button_disable";
}
function board_add_phone_code_select(id){
	if(!id)return false;
	var i,code;for(i=0;i<tel_prefixes_ids.length;i++)if(tel_prefixes_ids[i]==id){code=tel_prefixes_codes[i];break;}
	board_add_phone_selected_id=id;board_add_phone_selected_code=code;
	document.getElementById("add_phone_code_display_span").innerHTML = code;
	hide_id('add_phone_code_select');display_id('add_phone_code_display');
	document.getElementById('add_phone_submit_button').className = value('add_phone_code_select_input')&&value('add_phone_number_input').length==7?"add_phone_submit_button_enabled":"add_phone_submit_button_disable";
}
function board_display_phones(){
	var i,j,code_d;
	for(i=1;i<=3;i++)hide_id('board_phone_'+i);
	var codes = value('phone_codes').split('|SEPARATOR|');
	var numbers = value('phone_numbers').split('|SEPARATOR|');
	for(i=1;i<codes.length;i++){
		display_id('board_phone_'+i);
		for(j=0;j<tel_prefixes_ids.length;j++)if(tel_prefixes_ids[j]==codes[i])code_d=tel_prefixes_codes[j];
		document.getElementById('board_phone_code_'+i).innerHTML=code_d;
		document.getElementById('board_phone_number_'+i).innerHTML=numbers[i];
	}
	board_add_phone_added=i-1;
	if(board_add_phone_added<3) display_id('add_phone_button'); else hide_id('add_phone_button');
}
function board_add_phone_submit(){
	if(document.getElementById('add_phone_submit_button').className=="add_phone_submit_button_disable")return;
	hide_id('add_phone');
	document.getElementById('phone_codes').value+='|SEPARATOR|'+board_add_phone_selected_id;
	document.getElementById('phone_numbers').value+='|SEPARATOR|'+value('add_phone_number_input');
	board_display_phones();
	return false;
}
function board_delete_phone(n){
	var i,cods='',nums='';
	var codes = value('phone_codes').split('|SEPARATOR|');
	var numbers = value('phone_numbers').split('|SEPARATOR|');
	for(i=1;i<codes.length;i++){if(i==n)continue;cods+='|SEPARATOR|'+codes[i];nums+='|SEPARATOR|'+numbers[i];}
	document.getElementById('phone_codes').value = cods;document.getElementById('phone_numbers').value = nums;
	board_display_phones();
	return false;
}
function board_add_phone_close(){hide_id('add_phone');display_id('add_phone_button');return false;}
// ======== PHONES EDITOR END ===================

// ======== MAP ===================
function createMarker(x,y, type, name) {
	var image = new google.maps.MarkerImage('images/map/'+map_icons[type],new google.maps.Size(28,29),new google.maps.Point(0,0),new google.maps.Point(11,29));
	var xy = new google.maps.LatLng(x,y);
	var marker = new google.maps.Marker({map: map, position: xy, icon:image, title:map_titles[type], draggable:false});
	google.maps.event.addListener(marker, "click", function() {if(infowindow)infowindow.close();infowindow = new google.maps.InfoWindow({content: name});infowindow.open(map, marker);});
	map_markers.push(marker);
}

function position_legend(){
	try {var x = getPosX(controlDiv);}catch (err) { setTimeout("position_legend()",2000); return; }
	try {var y = getPosY(controlDiv);}catch (err) { setTimeout("position_legend()",2000); return; }
	if(x>0 && y>0) {
		var legendDiv = document.getElementById('map_legend');
		legendDiv.style.display='block';
		x+=6; y+=30;
//		x+=1000-226; y+=30;
		legendDiv.style.top=y+"px";
		legendDiv.style.left=x+"px";
	}
	else setTimeout("position_legend()",2000);
}

function map_initialize() {
	var x = map_x?map_x:40.406961;
	var y = map_y?map_y:49.887886;
	var z = map_z?map_z:12;
	var settings = {
		zoom: z, center: new google.maps.LatLng(x,y), mapTypeControl: true, 
		mapTypeControlOptions: {
			style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, 
			mapTypeIds: [google.maps.MapTypeId.ROADMAP,google.maps.MapTypeId.SATELLITE,google.maps.MapTypeId.HYBRID] }, 
		navigationControl: true, 
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("map_canvas"), settings);
	google.maps.event.addListener(map, "click", function(){if(infowindow)infowindow.close();});
	map_display_points();
	geocoder = new google.maps.Geocoder();

	controlDiv = document.createElement('DIV');
	controlDiv.index = 1;
	controlDiv.id = 'controlDiv';
	controlDiv.style.width = controlDiv.style.height = '1px';
	map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
	setTimeout("position_legend()",2000);
}
function map_display_points(){var i;for(i=0;i<map_points.length;i++){ var point = map_points[i]; createMarker(point[1], point[2], point[0], point[3]);}}
function map_legend_checkbox(type, b){var i;for(i=0;i<map_markers.length;i++){var point = map_points[i];if(type!=point[0]) continue;map_markers[i].setVisible(b);}}
function map_show_legend(){hide_id('map_legend_0');display_id('map_legend_1');document.getElementById('map_legend').style.marginBottom = "-140px";}
function map_hide_legend(){hide_id('map_legend_1');display_id('map_legend_0');document.getElementById('map_legend').style.marginBottom = "-37px";}
function map_search_form(){
	var o = document.getElementById('map_search');
	var address = o.value;
	o.focus();
	if (geocoder) {o.style.background="url('images/loading.gif')";geocoder.geocode( { 'address': address+' az', region: 'az'}, function(results, status) {o.style.background="#FFF";if (status == google.maps.GeocoderStatus.OK) {map.fitBounds(results[0].geometry.viewport);var marker = new google.maps.Marker({map: map, position: results[0].geometry.location });}});}	
	return false;
}

function map_get_link(){
	try {
		var o = document.getElementsByClassName('get_link_form');var i;
		var c = map.getCenter();
		var x = c.lat();
		var y = c.lng();
		var z = map.getZoom();
		var url = get_link_url+x+'/'+y+'/'+z+'/';
		for(i=0;i<o.length;i++)o[i].innerHTML=url;
	} catch(e){}
}
// ======== MAP END ===================
function catalog_show(body){
	body = "cbody_"+body;
	var d = document.getElementsByClassName('cbody_0');
	var i; for(i=0;i<d.length;i++)d[i].style.display='none';
	var d = document.getElementsByClassName(body);
	var i; for(i=0;i<d.length;i++)d[i].style.display='block';
}

// ============ PAGINATOR =======================

var Paginator = function(paginatorHolderId, pagesTotal, pagesSpan, pageCurrent, baseUrl){
	if(!document.getElementById(paginatorHolderId) || !pagesTotal || !pagesSpan) return false;
	this.inputData = {
		paginatorHolderId: paginatorHolderId,
		pagesTotal: pagesTotal,
		pagesSpan: pagesSpan < pagesTotal ? pagesSpan : pagesTotal,
		pageCurrent: pageCurrent,
		baseUrl: baseUrl ? baseUrl : '/pages/'
	};
	this.html = {
		holder: null,
		table: null,
		trPages: null, 
		trScrollBar: null,
		tdsPages: null,
		scrollBar: null,
		scrollThumb: null,
		pageCurrentMark: null
	};
	this.prepareHtml();
	this.initScrollThumb();
	this.initPageCurrentMark();
	this.initEvents();
	this.scrollToPageCurrent();
} 
Paginator.prototype.prepareHtml = function(){
	this.html.holder = document.getElementById(this.inputData.paginatorHolderId);
	this.html.holder.innerHTML = this.makePagesTableHtml();
	this.html.table = this.html.holder.getElementsByTagName('table')[0];
	var trPages = this.html.table.getElementsByTagName('tr')[0]; 
	this.html.tdsPages = trPages.getElementsByTagName('td');
	this.html.scrollBar = getElementsByClassName(this.html.table, 'div', 'scroll_bar')[0];
	this.html.scrollThumb = getElementsByClassName(this.html.table, 'div', 'scroll_thumb')[0];
	this.html.pageCurrentMark = getElementsByClassName(this.html.table, 'div', 'current_page_mark')[0];
	if(this.inputData.pagesSpan == this.inputData.pagesTotal){
		addClass(this.html.holder, 'fullsize');
	}
}
Paginator.prototype.makePagesTableHtml = function(){
	var tdWidth = (100 / this.inputData.pagesSpan) + '%';
	var html = '' +
	'<table width="100%">' +
		'<tr>' 
			for (var i=1; i<=this.inputData.pagesSpan; i++){html += '<td width="' + tdWidth + '"></td>';}
			html += '' + 
		'</tr><tr><td colspan="' + this.inputData.pagesSpan + '">' +
				'<div class="scroll_bar">' + 
					'<div class="scroll_trough"></div>' + 
					'<div class="scroll_thumb"><div class="scroll_knob"></div></div>' + 
					'<div class="current_page_mark"></div>' + 
				'</div>' +
			'</td>' +
		'</tr>' +
	'</table>';
	return html;
}

Paginator.prototype.initScrollThumb = function(){
	this.html.scrollThumb.widthMin = '8'; // minimum width of the scrollThumb (px)
	this.html.scrollThumb.widthPercent = this.inputData.pagesSpan/this.inputData.pagesTotal * 100;
	this.html.scrollThumb.xPosPageCurrent = (this.inputData.pageCurrent - Math.round(this.inputData.pagesSpan/2))/this.inputData.pagesTotal * this.html.table.offsetWidth;
	this.html.scrollThumb.xPos = this.html.scrollThumb.xPosPageCurrent;
	this.html.scrollThumb.xPosMin = 0;
	this.html.scrollThumb.xPosMax;
	this.html.scrollThumb.widthActual;
	this.setScrollThumbWidth();
}

Paginator.prototype.setScrollThumbWidth = function(){
	this.html.scrollThumb.style.width = this.html.scrollThumb.widthPercent + "%";
	this.html.scrollThumb.widthActual = this.html.scrollThumb.offsetWidth;
	if(this.html.scrollThumb.widthActual < this.html.scrollThumb.widthMin){
		this.html.scrollThumb.style.width = this.html.scrollThumb.widthMin + 'px';
	}
	this.html.scrollThumb.xPosMax = this.html.table.offsetWidth - this.html.scrollThumb.widthActual;
}

Paginator.prototype.moveScrollThumb = function(){
	this.html.scrollThumb.style.left = this.html.scrollThumb.xPos + "px";
}

Paginator.prototype.initPageCurrentMark = function(){
	this.html.pageCurrentMark.widthMin = '3';
	this.html.pageCurrentMark.widthPercent = 100 / this.inputData.pagesTotal;
	this.html.pageCurrentMark.widthActual;
	this.setPageCurrentPointWidth();
	this.movePageCurrentPoint();
}

Paginator.prototype.setPageCurrentPointWidth = function(){
	this.html.pageCurrentMark.style.width = this.html.pageCurrentMark.widthPercent + '%';
	this.html.pageCurrentMark.widthActual = this.html.pageCurrentMark.offsetWidth;
	if(this.html.pageCurrentMark.widthActual < this.html.pageCurrentMark.widthMin){
		this.html.pageCurrentMark.style.width = this.html.pageCurrentMark.widthMin + 'px';
	}
}

Paginator.prototype.movePageCurrentPoint = function(){
	if(this.html.pageCurrentMark.widthActual < this.html.pageCurrentMark.offsetWidth){
		this.html.pageCurrentMark.style.left = (this.inputData.pageCurrent - 1)/this.inputData.pagesTotal * this.html.table.offsetWidth - this.html.pageCurrentMark.offsetWidth/2 + "px";
	} else {
		this.html.pageCurrentMark.style.left = (this.inputData.pageCurrent - 1)/this.inputData.pagesTotal * this.html.table.offsetWidth + "px";
	}
}

Paginator.prototype.initEvents = function(){
	var _this = this;
	this.html.scrollThumb.onmousedown = function(e){
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		var dx = getMousePosition(e).x - this.xPos;
		document.onmousemove = function(e){
			if (!e) var e = window.event;
			_this.html.scrollThumb.xPos = getMousePosition(e).x - dx;
			_this.moveScrollThumb();
			_this.drawPages();
		}
		document.onmouseup = function(){
			document.onmousemove = null;
			_this.enableSelection();
		}
		_this.disableSelection();
	}
	this.html.scrollBar.onmousedown = function(e){
		if (!e) var e = window.event;
		if(matchClass(_this.paginatorBox, 'fullsize')) return;
		_this.html.scrollThumb.xPos = getMousePosition(e).x - getPageX(_this.html.scrollBar) - _this.html.scrollThumb.offsetWidth/2;
		_this.moveScrollThumb();
		_this.drawPages();
	}
	//addEvent(window, 'resize', function(){Paginator.resizePaginator(_this)});
}

Paginator.prototype.drawPages = function(){
	var percentFromLeft = this.html.scrollThumb.xPos/(this.html.table.offsetWidth);
	var cellFirstValue = Math.round(percentFromLeft * this.inputData.pagesTotal);
	var html = "";
	if(cellFirstValue < 1){
		cellFirstValue = 1;
		this.html.scrollThumb.xPos = 0;
		this.moveScrollThumb();
	} else if(cellFirstValue >= this.inputData.pagesTotal - this.inputData.pagesSpan) {
		cellFirstValue = this.inputData.pagesTotal - this.inputData.pagesSpan + 1;
		this.html.scrollThumb.xPos = this.html.table.offsetWidth - this.html.scrollThumb.offsetWidth;
		this.moveScrollThumb();
	}
	for(var i=0; i<this.html.tdsPages.length; i++){
		var cellCurrentValue = cellFirstValue + i;
		if(cellCurrentValue == this.inputData.pageCurrent){
			html = "<span>" + "<strong>" + cellCurrentValue + "</strong>" + "</span>";
		} else {
			html = "<span>" + "<a href='" + this.inputData.baseUrl + cellCurrentValue + "'>" + cellCurrentValue + "</a>" + "</span>";
		}
		this.html.tdsPages[i].innerHTML = html;
	}
}

Paginator.prototype.scrollToPageCurrent = function(){
	this.html.scrollThumb.xPosPageCurrent = (this.inputData.pageCurrent - Math.round(this.inputData.pagesSpan/2))/this.inputData.pagesTotal * this.html.table.offsetWidth;
	this.html.scrollThumb.xPos = this.html.scrollThumb.xPosPageCurrent;
	this.moveScrollThumb();
	this.drawPages();
}

Paginator.prototype.disableSelection = function(){
	document.onselectstart = function(){
		return false;
	}
	this.html.scrollThumb.focus();	
}
Paginator.prototype.enableSelection = function(){
	document.onselectstart = function(){
		return true;
	}
}

Paginator.resizePaginator = function (paginatorObj){
	paginatorObj.setPageCurrentPointWidth();
	paginatorObj.movePageCurrentPoint();
	paginatorObj.setScrollThumbWidth();
	paginatorObj.scrollToPageCurrent();
}


function getElementsByClassName(objParentNode, strNodeName, strClassName){
	var nodes = objParentNode.getElementsByTagName(strNodeName);
	if(!strClassName){
		return nodes;	
	}
	var nodesWithClassName = [];
	for(var i=0; i<nodes.length; i++){
		if(matchClass( nodes[i], strClassName )){
			nodesWithClassName[nodesWithClassName.length] = nodes[i];
		}	
	}
	return nodesWithClassName;
}


function addClass( objNode, strNewClass ) {replaceClass( objNode, strNewClass, '' );}
function removeClass( objNode, strCurrClass ) {replaceClass( objNode, '', strCurrClass );}

function replaceClass( objNode, strNewClass, strCurrClass ) {
	var strOldClass = strNewClass;
	if ( strCurrClass && strCurrClass.length ){
		strCurrClass = strCurrClass.replace( /\s+(\S)/g, '|$1' );
		if ( strOldClass.length ) strOldClass += '|';
		strOldClass += strCurrClass;
	}
	objNode.className = objNode.className.replace( new RegExp('(^|\\s+)(' + strOldClass + ')($|\\s+)', 'g'), '$1' );
	objNode.className += ( (objNode.className.length)? ' ' : '' ) + strNewClass;
}

function matchClass( objNode, strCurrClass ) {
	return ( objNode && objNode.className.length && objNode.className.match( new RegExp('(^|\\s+)(' + strCurrClass + ')($|\\s+)') ) );
}


function addEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.addEventListener)
		objElement.addEventListener(strEventType, ptrEventFunc, false);
	else if (objElement.attachEvent)
		objElement.attachEvent('on' + strEventType, ptrEventFunc);
}
function removeEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.removeEventListener) objElement.removeEventListener(strEventType, ptrEventFunc, false);
		else if (objElement.detachEvent) objElement.detachEvent('on' + strEventType, ptrEventFunc);
}

function getPageY( oElement ) {
	var iPosY = oElement.offsetTop;
	while ( oElement.offsetParent != null ) {
		oElement = oElement.offsetParent;
		iPosY += oElement.offsetTop;
		if (oElement.tagName == 'BODY') break;
	}
	return iPosY;
}

function getPageX( oElement ) {
	var iPosX = oElement.offsetLeft;
	while ( oElement.offsetParent != null ) {
		oElement = oElement.offsetParent;
		iPosX += oElement.offsetLeft;
		if (oElement.tagName == 'BODY') break;
	}
	return iPosX;
}

function getMousePosition(e) {
	if (e.pageX || e.pageY){
		var posX = e.pageX;
		var posY = e.pageY;
	}else if (e.clientX || e.clientY) 	{
		var posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		var posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	return {x:posX, y:posY}	
}
function compare_submit(){
	var a = [];
	if(value('modification_id1')) a.push(value('modification_id1'));
	if(value('modification_id2')) a.push(value('modification_id2'));
	if(value('modification_id3')) a.push(value('modification_id3'));
	document.location.href = document.getElementsByTagName('base')[0].href + 'compare/'+a.join('.')+'/';
}
