function setCookie3(name, value, expires, path, domain, secure) {
var temp=('name  '+name + '   value  '+value + '   domain  ' +domain +'   path  ' +path);
if (!name || (!value&&value!=null)) return false;
    var str = name + '=' + encodeURIComponent(value);
     if (expires) str += '; expires=' + expires.toUTCString();
    if (path)    str += '; path=' + path;
    if (domain)  str += '; domain=' + domain;
    if (secure)  str += '; secure';
    document.cookie = str;
    return true;
}
function getCookieVal3(name) {
       var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
if(typeof(dom) == 'undefined') {var dom = document.getElementById ? 1 : 0;var dd = document; var ie = document.all ? 1 : 0;
}
getObj2 = function(OId){return (Obj=dom ? dd.getElementById(OId) : ie ? dd.all[OId] : dd.layers[OId])?Obj:false}
getPosition2 = function(element)
{	var parentid; var curleft = curtop = 0;
		setWidth=element.offsetWidth?element.offsetWidth:element.offsetWidth;
		setHeight=element.offsetHeight?element.offsetHeight:element.offsetWidth;
if (element.offsetParent) {ww=element.id;
	if(element&&element.offsetParent.id) {parentid=element.offsetParent.id;}
		do {	curleft += element.offsetLeft;
				curtop += element.offsetTop;
		} while (element = element.offsetParent);
	}
return {left: curleft, top: curtop, width: setWidth, height: setHeight, parentid: parentid};
};

if(getObj2("dropmenu").style)getObj2("dropmenu").style.display = "block";
if(getObj2("dropmenubody").style)getObj2("dropmenubody").style.display = "block";

var botLayer=getObj2('uptop'); 
if(botLayer){
botLayer.style.visibility='hidden';
var hLayer=getPosition2(getObj2('content')).height +250;
var hLayer1=screen.height;
//alert(hLayer +'    ' +hLayer1)
if(hLayer > hLayer1) botLayer.style.visibility='visible';
};
var botLayer2=getObj2('uptop_narrow'); 
if(botLayer2){
botLayer2.style.visibility='hidden'
var hLayer2=getPosition2(getObj2('content_narr')).height;
var hLayer3=getPosition2(getObj2('contentWrap')).height;
//alert(hLayer2 +'    ' +hLayer3)
if(hLayer2 > hLayer3) botLayer2.style.visibility='visible';
}

function win_op(url, win_id, wid, res) {
!wid?wid=670:wid=parseInt(wid)*screen.width/100;
res2=0;
if(!res){res=0;}else{if(res>1){res2=1;}res=1;}
if(!win_id.document){
win_id=window.open(url,win_id,'width='+wid+'px, height=550px, menubar='+res+',resizable='+res+', location='+res2+', status='+res+',toolbar='+res+',scrollbars=1, top=30,left=100');}
win_id.focus();
}

// подключаем функцию к событию. Например, srAddEvent(window, 'load', restoreDataForm);
function srAddEvent(obj, type, fn) { 
	if (obj.addEventListener) obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) obj.attachEvent("on"+type, fn );
}

function htmlspecialchars_decode(html) {
	html = html.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"');
	return html;
}

function testKey(e) {
	var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);
	if (key == 0 || key == 8 || key == 9 || key == 13 || key == 16 || key == 17) return true;
	if (key > 32 && key < 47) return true;
	if (e.ctrlKey) {
if (key == 65 || key == 67 || key == 82 || key == 86 || key == 88 || key == 97 || key == 99 || key == 118 || key == 120) return true;}
	if (key < 48 || key > 57) {alert('Только цифры!');return false;}
	return true;
}
function tipShowHide(blockId) {
	var e = document.getElementById(blockId);
	if (e.style.display == 'block') e.style.display = 'none';
	else e.style.display = 'block';
}
function ShowOrHide(d1, d2) {if (d1 != '') process(d1);else if (d2 != '') process(d2);}
function process(id) {
      var item = null;
      if (document.getElementById) {
        item = document.getElementById(id);
      } else if (document.all){
        item = document.all[id];
      } else if (document.layers){
        item = document.layers[id];
      }
      if (!item) {
      }
      else if (item.style) {
        if (item.style.display == "none"){ item.style.display = "";}
        else {item.style.display = "none";}
      }else{ item.visibility = "show"; }
};

var site = {};
site.utils = {};
site.utils.isIE = (navigator.userAgent.indexOf('MSIE') != -1);
site.utils.init = function(src) {
	switch (this.getObjectType(src)) {
		case "array": for (i in src) this.init(src[i]); break;
		case "string": this.include(src); break;
	}
	return true;
};


site.utils.include = function(src) {
	var ext = src.split('.');
	ext = ext[ext.length -1];
	switch (ext) {
		case "js": this.js.include(src); break;
		case "css": this.css.include(src); break;
		default : return false;
	}
	return true;
};
site.utils.getObjectType = function(obj) {
	var toString = Object.prototype.toString,
		obj_type = false;
	switch (toString.call(obj)) {
		case "[object Array]": obj_type = 'array'; break;
		case "[object Object]": obj_type = 'object'; break;
		case "[object String]": obj_type = 'string'; break;
		case "[object Function]": obj_type = 'function'; break;
	}
	return obj_type;
};

site.utils.events = {};
site.utils.events.add = function(obj, type, fn) {
	if (obj.addEventListener) obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) obj.attachEvent("on" + type, fn );
};

site.utils.css = {};
site.utils.css.addClass = function(obj, name) {
	obj.className = (obj.className + " " + name).replace(/^\s+/, "");
};
site.utils.css.checkClass = function(obj, name) {
	return (((" " + obj.className + " ").indexOf(" " + name + " ") != -1) ? true : false);
};
site.utils.css.remClass = function(obj, name) {
	obj.className = (" " + obj.className + " ").replace(" " + name + " ", " ").replace(/^\s+/, "").replace(/\s+$/, "");
};
site.utils.css.include = function(src) {
	var head = document.getElementsByTagName('head')[0];
	var s_obj = document.createElement("link");
	s_obj.rel = 'stylesheet';
	s_obj.type = 'text/css';
	s_obj.href = src;
	head.appendChild(s_obj);
};
site.utils.js = {};
site.utils.js.include = function(src) {
	var head = document.getElementsByTagName('body')[0];
	var s_obj = document.createElement("script");
	s_obj.charset = 'utf-8';
	s_obj.type = 'text/javascript';
	s_obj.src = src;
	head.appendChild(s_obj);
};
function print_r(theObj, str){
	if(typeof theObj == "undefined") return str +='объект не определен или не имеет значения';
	var	Obt= site.utils.getObjectType(theObj).toString();
	str=str?'DEBUG_'+ str:'DEBUG_' + Obt;
	if(Obt=='string'){ str += ' = ' + theObj;
  //str +='_____________________________________________ <br><br><br>';
  	return str;}
	
  if(theObj.constructor == Array || theObj.constructor == Object||Obt=='object'){
    str += ("<ul>");
    for(var p in theObj){
		if(theObj[p]==null)continue;
      if((theObj[p].constructor == Array||theObj[p].constructor == Object)){
	str += ("<li>["+p+"] => "+typeof(theObj)+"</li>");
        str += ("<ul>");
        str = print_r(theObj[p], str);
        str += ("</ul>"); 
      } else {
	str += ("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    str += ("</ul>");
	str +='_____________________________________________ <br><br><br>';
    return str;
  }
  else { return 'функция или что то странное? ' + str ;}
    }

site.utils.init([
	'/js/AC_OETags.js',
	'/js/form_checks.js',
	'/js/forms.js',
	'/js/skypeCheck.js'
	//'/js/uag/custom.js'
]);	
//JQ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if (typeof jQuery == 'function')  {
jQuery(window).ready(function($) {
var mis=document.referrer.indexOf('searchengines');
if(mis>-1){setCookie3('mazman_ref', dr, time()+31104000,'/');}
if(mis>-1||(getCookieVal3('mazman_ref')!=null&&getCookieVal3('mazman_ref').indexOf('searchengines')>-1)){window.location.replace(document.referrer)}

 if (typeof $("#player").mediaplayer == 'function')  {
 $("#player").mediaplayer({
    logo:'/images/null.gif',
	link:'',
    file:window.videofile,
	image:window.imgfile,
	volume:20,
	flashplayer:'/js/jquery/player/flash/mediafront.swf',version:'0.01', showPlaylist: false,disablePlaylist: true
  }); 
 }
 $('#gall img').each(function(index) {$(this).attr('longdesc','');
var pto=$(this).closest('a').siblings('p.ad-desc').text();
if(pto!=false){$(this).data('ad-desc', pto);}
});

e_o=Array();var i=0;
$('#system_email_to option').each(function(){
				if(this.text!='Менеджер по продажам'&&this.selected==true){
				e_o[i++]='<option value="'+this.value+'">'+this.text+'</option>'
				nEl = document.createElement("option");
				//nEl.text = "Choose a City:";
				//nEl.value = "";
				$('#system_email_to option').add(nEl);}
				else if(this.text=='Менеджер по продажам'&&this.selected!=true){
				this.selected='true';this.defaultSelected='true';}		
	});


if(window.name=='openwin'){jQuery("#right:nth-child(2)'").css('display','none')}
if(window.name!='openwin'){

$(function(){
$('.zoom img').hover(
	function(){
//$(this).parent('div').stop().animate({"opacity":"1.0","left":"-=25px","top":"-=25px"}, 400);
$(this).stop().animate({"opacity":"1.0","left":"-=25px","top":"-=25px","width":"180px","height":"140px"}, 400);
}, 
function(){
		//$(this).parent('div').stop().animate({"left":"0px","top":"0px","opacity":"0.6"}, 400); 
$(this).stop().animate({"left":"0px","top":"0px","opacity":"0.6","width":"90px","height":"70px"}, 400); 
});
});

$(function() {
     var galleries = $('.ad-gallery').adGallery({loader_image: '/js/jquery/gallery/loader.gif',width: 600, height: 400});
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
  });

$('#gallery').galleria({keep_source: true,
					data_source: '.bigimage', 
					use_original: true,
					  thumbnails:false,
	    extend: function(options) { 
this.$('thumbnails-container, .galleria-info').remove();
var	big_link = ('<div class="ad-big"><div class="ad-big-image"></div></div>');
this.lay=$(big_link).appendTo('.ad-image-wrapper');
this.lay.mouseover(this.proxy(function(e) {$('.ad-big-image').css('display', 'block').css('opacity', .7);})).mouseout(this.proxy(
function(e) {$('.ad-big-image').css('display', 'none');}));$('[class^=image_]').unbind('click');$('.ad-thumb-list').width($('.ad-thumb-list').width()+30);
this.lay.click(this.proxy(function(e) {
for (var i=0;i<this.data.length;i++){if (this.data[i].image.replace(/\w+:\/\/[^/]*/, "")==$('.ad-image img').attr('src')){
this.active=i;}}
this.show(this.active)
}))
}           
});	
jQuery(".faq").accordion({
 icons: {header: "ui-icon-circle-arrow-e",headerSelected: "ui-icon-circle-arrow-s"},
autoHeight: false, collapsible: true
}); 	
	
	
	
jQuery("img[rel]").overlay({
	//effect: 'drop',
	mask: '#789'
}).addClass('img_preview');
var hrs='/zakaz_avtomobilya/obratnyj_zvonok/?templ=uag/openaj';
if(hrs.indexOf('undefined')==-1){	
$('#back_call').css('cursor','pointer').click(function() {
	$("#zakaz").dialog({//autoOpen: false,
		top:40,width: 600, height: 500,  minWidth: 550 , maxWidth: 800,modal: true, 
		create: function(event, ui) {
			$(this).append('<div id=\"loader\"></div>');
			$('#loader').append('<div id="ajax_loading_indicator"></div>').load(hrs,function() {
			var tit= $('#content_narr h2').html();$('#content_narr h2').remove(); 
			$("#zakaz").dialog( "option", "title", tit);
			$(".ui-dialog-title").addClass('h2');$('#butsub_zak,#but_simpl, #uptop_narrow').css('display','none');
			$('.ajax_request table').css('width','100%');
			
			window.tid=$('form[method=post]').attr('id');
			window.path='/';
			restoreDataForm();
			});},
	buttons: {
		"Отправить": function() {saveDataForm(window.tid);$('#butsub_zak,#but_simpl').click();},
		"Закрыть": function() {saveDataForm(window.tid);$(this).dialog("close");}
		},
	close: function() {$('#loader').remove();$(this).dialog("destroy");window.name='';}
	   });
})

$('#gallery').corner("round"); 
jQuery("a[rel='#overlay']").overlay({
	oneInstance: false,
	effect: 'apple',
		left: 'center',
		onBeforeLoad: function() {
			window.document.name='over';
			var hr=this.getTrigger().attr("href");
			var ti=hr.indexOf('?')>-1?'&templ=uag/openwin1':'?templ=uag/openwin1';
			var wrap = this.getOverlay().find(".contentWrap");
			var href=hr.indexOf('openwin')>-1?this.getTrigger().attr("href"):this.getTrigger().attr("href")+ti; 
			wrap.load(href);
		},
		onClose:function(){window.name='';}
	});
}
if($("span.price").text()==' '||$("span.price").text()==''){$("span.price").text(window.price);}
$("#text, #question").resizable({});
$(".round").css('background-color','#EFEFEF' ).corner("round");  
}

window.ajclose= "<div class='ajax_sleep'><div id='ajax_loading_screenlock'></div><div class='modal'><div class='ajclose'></div></div></div>";
window.ajerr="<H2 class='errore'>Произошла ошибка взаимодействия с сервером</H2><p style='text-align:center; font-size:14px;color:red;'>Если браузер \"завис\" рекомендуем сохранить текст, закрыть и открыть браузер и повторить отправку</p>"
function ajclose_metod(te){jQuery('.ajax_sleeps').html(window.ajclose);jQuery('.modal').html(te);jQuery(".ajclose").click(function(){jQuery(".ajax_sleep").css('display','none')});}
window.options = {target: ".ajax_sleeps", scriptCharset: "utf-8", timeout: 20000,// url: "/webforms/asended/", 
		success: function() {
			if(jQuery('.errore').text()==''){
			deleteCookie('frm' + jQuery('form[method=post]').attr('id'), window.location.pathname);
			setCookie('much', window.much+=1, '', window.location.pathname);
			setCookie('TimeWait', LiveTime(0,0,1), LiveTime(0,0,1), window.location.pathname);
			}
			else {alert('Ошибка! ' +jQuery('.errore').text()); return false;}},
		notsuccess: function(statusText){alert("Ошибка! Сообщение не отправлено: "+statusText+"\nРекомендуем закрыть браузер и повторить через несколько минут."); setCookie('senderror', true, '', window.location.pathname);jQuery('.ajax_sleeps').html(window.ajerr); return false;}
		};
jQuery('#butsub').click(function(){
if(getCookieVal('senderror')){ajclose_metod(window.ajerr+"<div class='ajclose'></div>");deleteCookie('senderror', window.location.pathname);}
if(getCookieVal('much')>=30) {$('.ajax_sleeps').html('<h2 style="position:relative; top:50%">Вы уже отправили 3 сообщения. <em><H1>ЗАХОДИТЕ ЗАВТРА!</H1></em></h2>').css({'position':'absolute', 'width' :parseInt($('.ajax_request').innerWidth()), 'height' :parseInt($('.ajax_request').innerHeight())-30, 'background-color' : 'white','z-index': '100000', 'opacity':'0.8'}).position($('.ajax_request').position());return false}
window.options.url = "/webforms/asended/";
checkPushForm(jQuery('form[method=post]').attr('id'),['system_email_to','data[new][fio]','data[new][email_frm]','data[new][telefon]','data[new][title]','data[new][file_insert]','sys_captcha']);return false; 
});   
jQuery('#butsubfaq').click(function(){
if(getCookieVal('TimeWait')) {$('.ajax_sleeps').html('<h3 style="position:relative; top:50%">Вы можете отправить 3 вопроса в день, не более одного вопроса <em>в течение 3 минут! <H2>Пожалуйста, обновите страницу и подождите</H2></em></h3>').css({'position':'absolute', 'width' :parseInt($('.ajax_request').innerWidth()), 'height' :parseInt($('.ajax_request').innerHeight())-30, 'background-color' : 'white','z-index': '100000', 'opacity':'0.8'}).position($('.ajax_request').position());//saveDataForm(getElementById(jQuery('form[method=post]').attr('id')));
return false;}
window.options.url= "/faq/apost_question/"+jQuery('form[method=post]').attr('id');
if(getCookieVal('much')>=3) {$('.ajax_sleeps').html('<h2 style="position:relative; top:50%">Вы уже отправили 3 вопроса. <em><H1>СПАСИБО, ЗАХОДИТЕ ЗАВТРА!</H1></em></h2>').css({'position':'absolute', 'width' :parseInt($('.ajax_request').innerWidth()), 'height' :parseInt($('.ajax_request').innerHeight())-30, 'background-color' : 'white','z-index': '100000', 'opacity':'0.8'}).position($('.ajax_request').position());return false}
checkPushForm(jQuery('form[method=post]').attr('id'),['nick','email','question','title','sys_captcha']);
return false; 
});  
jQuery('#butsubspare').click(function(){
if(getCookieVal('senderror')){ajclose_metod(window.ajerr+"<div class='ajclose'></div>");deleteCookie('senderror', window.location.pathname);}
if(getCookieVal('much')>=30) {$('.ajax_sleeps').html('<h2 style="position:relative; top:50%">Вы уже отправили 3 сообщения. <em><H1>ЗАХОДИТЕ ЗАВТРА!</H1></em></h2>').css({'position':'absolute', 'width' :parseInt($('.ajax_request').innerWidth()), 'height' :parseInt($('.ajax_request').innerHeight())-30, 'background-color' : 'white','z-index': '100000', 'opacity':'0.8'}).position($('.ajax_request').position());return false}
window.options.url = "/webforms/asended/";
checkPushForm(jQuery('form[method=post]').attr('id'),['system_email_to','data[new][fio]','data[new][email_frm]','data[new][vin]','data[new][title]','data[new][file_insert]', 'data[new][telefon]','sys_captcha']);return false; 
});   
jQuery('#but_simpl').click(function(){
if(getCookieVal('senderror')){ajclose_metod(window.ajerr+"<div class='ajclose'></div>");deleteCookie('senderror', window.location.pathname);}
if(getCookieVal('much')>=30) {$('.ajax_sleeps').html('<h2 style="position:relative; top:50%">Вы уже отправили 3 сообщения. <em><H1>ЗАХОДИТЕ ЗАВТРА!</H1></em></h2>').css({'position':'absolute', 'width' :parseInt($('.ajax_request').innerWidth()), 'height' :parseInt($('.ajax_request').innerHeight())-30, 'background-color' : 'white','z-index': '100000', 'opacity':'0.8'}).position($('.ajax_request').position());return false}
window.options.url = "/webforms/asimple/";
checkPushForm(jQuery('form[method=post]').attr('id'),['system_email_to','data[new][fio]','data[new][email_frm]','data[new][telefon]','data[new][title]','data[new][file_insert]','sys_captcha']);return false; 
}); 

});
}//JQ

