var scrX=1280, scrY=1024, spd=10;

if(document.documentElement && document.documentElement.clientWidth) {
  scrX = document.documentElement.clientWidth;
  scrY = document.documentElement.clientHeight;
} else if(document.body) {
  scrX = document.body.clientWidth;
  scrY = document.body.clientHeight;
}

if(navigator.userAgent.indexOf("MSIE")>=0) { scrX -=4; spd *= 3; }


 function showmap() {
    document.getElementById("super").style.display = "block";
    document.getElementById("super").style.width="100%";
    slide(0,scrY-1,spd*0.3);
    return false;
 }

 function slide(h_on,h_end,h_step) {
    if(h_on<=0) h_on=scrY;
    if(h_on==h_end) return;
    h_on+=h_step;
    document.getElementById("super").style.height=h_on+'px'; //alert(document.getElementById("super").offsetHeight);
    if(Math.abs(h_end-h_on)>100) setTimeout("slide("+h_on+","+h_end+","+h_step+")",1);
    else document.getElementById("super").style.height=h_end+'px';
    //alert("h_on,h_end,h_step = "+h_on+","+h_end+","+h_step);
 }

 function change_town(town)  {
    var lnk = "<strong>Мы работаем в городах:</strong><br/> <div>";
    for (i=0; i < towns.length; i++) {
        lnk += "<a href='#' onclick=\"return choose_town('"+towns[i]+"','"+nms[i]+"')\" class='butt'>"+nms[i]+"</a> &#xa0;";
    }
    showDm("Выбрать город",lnk+"<a href='#' onclick=\"return choose_town('other','Указать')\" class='butt'>Другой</a></div>");
    return false;
 }

 function choose_town(town,name) {
    document.getElementById("tlnk").innerHTML= name + "<input type='hidden' name='town' value='"+town+"'/>";
    hideDm();
    if(town!="other" && lt!=name) {
        if(lt.length>0) document.sform.msg.value = document.sform.msg.value.toString().substr(0,document.sform.msg.value.length-lt.length-1);
        document.sform.msg.value +=  " " + name;
        lt = name;
    } else if(town=="other") {
       if(lt.length>0) document.sform.msg.value = document.sform.msg.value.toString().substr(0,document.sform.msg.value.length-lt.length-1);
        lt="";
    }
    return false;
 }

 function add_geo() {
  var r=0;
  if(!document.getElementById("super")) setTimeout("add_geo()",1111);
  else {
    for(i=0; i < towns.length; i++) {
        document.getElementById("super").innerHTML += "<a href='http://"+towns[i]+".avtochip.ru' onclick=\"return showDm('"+nms[i]+"',"+i+")\" class='butt' title='Точка чип-тюнинга г. "+nms[i]+"'><img src='res/spot.gif' id='loc"+i+"' alt='Точка чип-тюнинга г. "+nms[i]+"'/>"+nms[i]+"</a> &#xa0;";
        if(++r>7 && towns[i+1]) {
            document.getElementById("super").innerHTML += '<br/>';
            r=0;
        }
    }
    document.getElementById("super").innerHTML +='<br/><br/><img src="res/rumap.gif" id="map" width="640" height="350" alt="Точки чип-тюнинга AvtoChip.ru"/><br/><br/><a href="#" onclick="slide(0,0,-'+(spd*2)+')" class="butt" id="town_close">&#xa0; - Закрыть - &#xa0;</a> &#xa0; <a href="/contacts.php" class="butt" id="town_close">&#xa0; - Все контакты - &#xa0;</a> ';
    var mapX = scrX/2-333;
    var mapY = 145; var xy = new Array();

    for(i=0; i < towns.length; i++) {
        xy=maps[i].split(",");
        document.getElementById("loc"+i).style.left = mapX + parseInt(xy[0],10) + 'px';
        document.getElementById("loc"+i).style.top = mapY + parseInt(xy[1],10) + 'px';
    }
  }
 }

