var d = document;var w = window;var ui_menu;var ui_menu_childs;
/******************************ERRORS******************************************/
function get(ID){return d.getElementById(ID)}
w.onerror=function(err,url,line)
{
 var query="err="+err+"&url="+url+"&line="+line+"&browser="+navigator.userAgent;
 var obj = d.createElement("SCRIPT");
 obj.type="text/javascript";
 obj.src="/errors/js_error.php?"+query;
 var head = d.getElementsByTagName('HEAD')[0];
 var add = head.appendChild(obj);
 head.removeChild(add);
 return true
}

d.ondragstart = d.onselectstart = d.oncopy = function(e)
{
 e = e || w.event;
 var el = e.target || e.srcElement;
 return ((el.tagName == "INPUT" && (el.type == "text" || el.type == "password")) || (el.tagName == "TEXTAREA") || (d.location.pathname.toLowerCase() == "/contacts/"))
}

/*******************************GETS*******************************************/
function getElementsByClass(searchClass,node,tag) {
 var classElements = new Array();
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
 for (var i = 0, j = 0; i < elsLen; i++) {
  if (pattern.test(els[i].className)) {
   classElements[j] = els[i];
   j++;
  }
 }
 return classElements;
}
function getElementsByRel(searchRel,node,tag){
 var relElements = new Array();
 if (node == null) node = d;
 if (tag == null) tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp('(^|\\\\s)'+searchRel+'(\\\\s|$)');
 for (var i = 0, j = 0; i < elsLen; i++) {
  if (pattern.test(els[i].rel)) {relElements[j] = els[i]; j++;}
 }
 return relElements;
}
function getChildElements(node,tag)
{
 if (node == null) node = d;
 if (tag == null) tag = '*';
 var els = node.getElementsByTagName(tag);
 return els;
}
/********************************EVENTS****************************************/
function addEvent(element,type,handler){
 if(element.addEventListener){
  element.addEventListener(type,handler,false);
 }
 else{
  if(!handler.$$guid) handler.$$guid = addEvent.guid++;
  if(!element.events) element.events = {};
  var handlers = element.events[type];
  if(!handlers){
   handlers = element.events[type] = {};
   if(element["on" + type]) {
    handlers[0] = element["on" + type];
   }
  }
  handlers[handler.$$guid] = handler;
  element["on" + type] = handleEvent;
 }
}
addEvent.guid = 1;
function removeEvent(element, type, handler) {
   if (element.removeEventListener) {
      element.removeEventListener(type, handler, false);
   } else {
      if (element.events && element.events[type]) {
         delete element.events[type][handler.$$guid];
      }
   }
}
function clearEvent(e){
 e = e || w.event;
 (e.preventDefault)?e.preventDefault():(e.returnValue=false);
 return false;
}
function handleEvent(e){
 var returnValue = true;
 e = e || fixEvent(((this.ownerDocument || this.d || this).parentWindow || w).event);
 var handlers = this.events[e.type];
 for(var i in handlers){
  this.$$handleEvent = handlers[i];
  if(this.$$handleEvent(e) === false){
   returnValue = false;
  }
 }
 return returnValue;
}
function fixEvent(e){
 e = e || w.event;
 if(e.isFixed){return e}
 eisFixed = true;
 e.preventDefault = e.preventDefault || function(){this.returnValue = false}
 e.stopPropagation = e.stopPropagaton || function(){this.cancelBubble = true}
 return e;
}
function blockEvent(e){
 e = e || w.event;
 if(e.stopPropagation) e.stopPropagation();
 else e.cancelBubble = true;
 if(e.preventDefault) e.preventDefault();
 else e.returnValue = false;
}

function mouse_button(e)
{
 e = e || w.event;
 var button;
 if (e.which == null) button = (e.button < 2) ? "LEFT":((e.button == 4) ? "MIDDLE" : "RIGHT");
 else button= (e.which < 2) ? "LEFT" :((e.which == 2) ? "MIDDLE" : "RIGHT")
 return button
}
/**********************************POSITIONING*********************************/
function getClientWidth()
{
 var myWidth = 0;
 if(typeof( w.innerWidth ) == 'number') myWidth = w.innerWidth;
 else if(d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight)) myWidth = d.documentElement.clientWidth;
 else if(d.body && (d.body.clientWidth || d.body.clientHeight)) myWidth = d.body.clientWidth;
 return myWidth;
}
function getClientHeight()
{
 var myHeight = 0;
 if(typeof(w.innerWidth) == 'number') myHeight = w.innerHeight;
 else if(d.documentElement && (d.documentElement.clientWidth || d.documentElement.clientHeight)) myHeight = d.documentElement.clientHeight;
 else if(d.body && (d.body.clientWidth || d.body.clientHeight)) myHeight = document.body.clientHeight;
 return myHeight;
}

function scrollPos(){
 var x = 0,y = 0;
 if (d.attachEvent != null){
  x = (d.documentElement.scrollLeft ? d.documentElement.scrollLeft : d.body.scrollLeft);
  y = (d.documentElement.scrollTop ? d.documentElement.scrollTop : d.body.scrollTop);
 }
 else if (!d.attachEvent && d.addEventListener){
  x = w.scrollX; y = w.scrollY;
 }
 return {x:x, y:y};
}

function defPosition(e)
{
 e = e || w.event;
 var x = 0, y = 0;
 if (d.attachEvent != null)
 { // Internet Explorer & Opera
  x = e.clientX +
   (d.documentElement.scrollLeft ? d.documentElement.scrollLeft : d.body.scrollLeft);
  y = e.clientY +
   (d.documentElement.scrollTop ? d.documentElement.scrollTop : d.body.scrollTop);
 }
 else if (!d.attachEvent && d.addEventListener)
 { // Gecko
  x = e.clientX + w.scrollX;
  y = e.clientY + w.scrollY;
 }
 else { /* Do nothing*/ }
 return {x:x, y:y};
}

function absPosition(obj)
{
 var x = 0;
 var y = 0;
 if(!obj.getBoundingClientRect)
 {
  while(obj)
  {
   x += obj.offsetLeft;
   y += obj.offsetTop;
   obj = obj.offsetParent;
  }
 }
 else if (obj.getBoundingClientRect)
 {
  x = obj.getBoundingClientRect().left;
  y = obj.getBoundingClientRect().top;
 }
 return {x:x, y:y};
}

function inArray(value,arr){
 var i;
 for(var i = 0; i < arr.length; i++) {
  if(arr[i] === value) return (i);
 }
 return false;
}
/*************************************UI_MENU**********************************/
d.oncontextmenu = function(e)
{
 
 e = e || w.event;
 var el = e.target || e.srcElement;
 if(!get("ui_menu"))
 {
  var obj = d.createElement("div");
  obj.id = "ui_menu";
  var Body = d.getElementsByTagName('BODY')[0];
  if(Body.appendChild(obj)) ui_menu = get("ui_menu");
  ui_menu.innerHTML ="<ul>";
  var ui_hr = 0;
  if(get("tz"))
   {
    ui_menu.innerHTML +='<li><a class="calc" href="'+get("tz").href+'">Направить заявку</a></li>';
	ui_hr = 1;
   }
  if(get("ask"))
  {
   ui_menu.innerHTML +='<li><a class="ask" href="'+get("ask").href+'">Задать вопрос</a></li>';
   ui_hr = 1;
  }
  if(ui_hr) ui_menu.innerHTML += '<b></b>';
  if (parseInt(navigator.appVersion) > 3)
   ui_menu.innerHTML +='<li><a id="print_lnk" class="print" href="#Печать" >Печать</a></li>';
  ui_menu.innerHTML +='<li><a id="bookmark_lnk" class="favorites" href="#Добавить в избранное">Добавить в избранное</a></li>';
  ui_menu.innerHTML +="</ul>";
  ui_menu_childs = getChildElements(ui_menu);
  addEvent(get("print_lnk"),"click",printPage);
  addEvent(get("bookmark_lnk"),"click",addBookmark);
 }

 var ret = ((el.tagName == "INPUT" && (el.type == "text" || el.type == "password")) || (el.tagName == "TEXTAREA"));
 if (!ret && (el.id != "ui_menu" && !inArray(el,ui_menu_childs))) display_ui_menu(e)
 if(ret) ui_menu.style.display = "none";
 return ret
}
function display_ui_menu(e)
{
 e = e || w.event;
 var el = e.target || e.srcElement;
 if(!inArray(el,ui_menu_childs))
 {
  var mouseX = defPosition(e).x;
  var mouseY = defPosition(e).y;
  var bodyW = getClientWidth();
  var bodyH = getClientHeight();
  var menuW = ui_menu.offsetWidth;
  var menuH = ui_menu.offsetHeight;
  ui_menu.style.left = ((bodyW - mouseX) > menuW)?mouseX+"px":(mouseX - menuW)+"px";
  ui_menu.style.top = ((bodyH - mouseY) > menuH)?mouseY+"px":(mouseY - menuH)+"px";
  addEvent(d,"click",hide_ui_menu);
  ui_menu.style.display = "block";
 }
}
function hide_ui_menu(e)
{
 e = e || w.event;
 var el = e.target || e.srcElement;
 if (el.id == "ui_menu" || inArray(el,ui_menu_childs) > 0 && el.tagName != "A")
 {
  (e.preventDefault)?e.preventDefault():(e.returnValue=false);
 }
 else
 {
  ui_menu.style.display = "none";
  removeEvent(d,"click",hide_ui_menu)
 }
}

function printPage(e)
{
 e = e || w.event;
 hide_ui_menu(e);
 if (w.print) w.print();
 else
 {
  var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
  d.body.insertAdjacentHTML('beforeEnd', WebBrowser);
  WebBrowser1.ExecWB(6, 2);
 }
 (e.preventDefault)?e.preventDefault():(e.returnValue=false);
}

function addBookmark(e)
{
 e = e || w.event;
 hide_ui_menu(e);
 var title=d.title;
 var url=d.location;
 try{w.external.AddFavorite(url, title)}
 catch(e)
 {
  try{w.sidebar.addPanel(title,url,"")}
  catch(e)
  {
   if(typeof(opera)=="object")
   {
    a.rel="sidebar";
    a.title=title;
    a.url=url;
    return true
   }
   else alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
  }
 }
 (e.preventDefault)?e.preventDefault():(e.returnValue=false);
}

/*************************************FLASH************************************/
function insertFlash(strSrc,intWidth,intHeight,strWMode,strScale,strPlayMode,strCLSID,strCODEBASE,strBGcolor,strPosition,strFlashVars){
 if(strScale == null || strScale == "") strScale = "noscale";
 if(strPlayMode == null || strPlayMode == "") strPlayMode = "true";
 var strFlash =  '<object classid="' + strCLSID + '" codebase="' + strCODEBASE + '" ';
 strFlash += ' width="' + intWidth + '" height="' + intHeight + '">';
 strFlash += '<param name="movie" value="' + ((strSrc != "")?strSrc:strFlashVars) + '">';
 strFlash += '<param name="quality" value="high">';
 strFlash += '<param name="play" value="' + strPlayMode + '">';
 if(strWMode != null || strWMode != "") strFlash += '<param name="wmode" value="' + strWMode + '">';
 strFlash += '<param name="scale" value="' + strScale + '">';
 strFlash += '<param name="menu" value="false">';
 if(strFlashVars != null && strFlashVars != "") strFlash += '<param name="FlashVars" value="' + strFlashVars + '">';
 if(strPosition != null && strPosition != "") strFlash += '<param name="align" value="' + strPosition + '">';
 if(strBGcolor != null && strBGcolor != "") strFlash += '<param name="bgcolor" value="' + strBGcolor + '">';
 strFlash += '<embed src="' + ((strSrc != "")?strSrc:strFlashVars) + '" width="' + intWidth + '" height="' + intHeight;
 if(strWMode != null || strWMode != "") strFlash += '" wmode="' + strWMode;
 strFlash += '" play="' + strPlayMode + '" scale="' + strScale  + '" menu="false"';
 if(strBGcolor != null && strBGcolor != "") strFlash += ' bgcolor="' + strBGcolor + '"';
 if(strFlashVars != null && strFlashVars != "") strFlash += ' FlashVars="' + strFlashVars + '"';
 if(strPosition != null && strPosition != "") strFlash += ' align="' + strPosition + '"';
 strFlash += ' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"/>';
 strFlash += '</object>';
 d.write(strFlash);
 d.close();
}
/*************************************REGEXP**********************************/
function isTime(sTime){
 oReTime = /^(2[0-3][:\-][0-5][0-9]$)|^([0-1]{0,1}[0-9][:\-][0-5][0-9])$/;
 return oReTime.test(sTime);
}

function isPhone(sPhone){
 sPhone = sPhone.replace( /[\s\-\(\)\.\]\[]/g,'');
 oRePhone = /^\+*\d{7,11}(\+\d{2,4})?$/;
 return oRePhone.test(sPhone);
}

function isEmail(sEmail){
 sEmail = sEmail.replace( new RegExp('/\(.*?\)/'),'');
 oRegExp = /^[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*@[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*\.[a-zA-Z]{2,4}$/;
 return oRegExp.test(sEmail);
}

/*******************************************************************************/
function number_format(number,decimals,dec_point,thousands_sep)
{
 var i,j,kw,kd,km,minus;
 if(number < 0){number *= (-1); minus = true}
 else minus = false;
 // input sanitation & defaults
 (isNaN(decimals = Math.abs(decimals)))?decimals = 2:"";
 (dec_point == undefined)?dec_point = ",":"";
 (thousands_sep == undefined)?thousands_sep = ".":"";
 i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
 ((j = i.length) > 3)?j = j % 3:j = 0;
 km = (j ? i.substr(0,j) + thousands_sep : "");
 kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
 kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
 if(minus) km = "-" + km;
 return km + kw + kd;
}

function is_numeric(mixed_var){return !isNaN(mixed_var)}

function preventSelection(el)
{
 var preventSelection = false;
 function removeSelection(){w.getSelection().removeAllRanges()}
 function killCtrlA(e)
 {
  var e = e || w.event;
  var el = e.target || e.srcElement;
  var key = e.keyCode || e.which;
  if (el.tagName.match(/INPUT|TEXTAREA/i) && (e.ctrlKey && (key != 'U'.charCodeAt(0) && key != 'S'.charCodeAt(0)))) return;
  if(e.ctrlKey && (key == 'A'.charCodeAt(0) || key == 'C'.charCodeAt(0) || key == 'U'.charCodeAt(0) || key == 'S'.charCodeAt(0) || key == 114))
  {
   removeSelection();
   (e.preventDefault)?e.preventDefault():e.returnValue = false;
  }
 }
  addEvent(d,'mousemove',function(e)
  {
   var e = e || w.event;
   if((e.which == 1 || e.button == 1) && preventSelection) removeSelection()
  });
  addEvent(d,'mousedown',function(e)
  {
   var e = e || w.event;
   var el = e.target || e.srcElement;
   preventSelection = !el.tagName.match(/INPUT|TEXTAREA/i);
  });
  addEvent(d,'dblclick',function(){(preventSelection)?removeSelection():preventSelection = false});
  addEvent(d,'mouseup',function(){(preventSelection)?removeSelection():preventSelection = false});
  addEvent(d,'keydown',killCtrlA);
  addEvent(d,'keyup',killCtrlA);
  addEvent(d,'keypress',killCtrlA);
}
if(w.getSelection && (d.location.pathname.toLowerCase() != "/contacts/")) preventSelection(d);

function get_pos(e)
{
 e = e || w.event;
 var el = e.target || e.srcElement;
 d.title = (defPosition(e).x - absPosition(el).x - 5) + " " + (defPosition(e).y - absPosition(el).y - 5); 

}