var LOADINGWAIT = 'Завантаження...';
var root=document.domain;
var loader='<br /><center><img src="http://'+root+'/ajax-loader.gif" alt="..."/><br /><span style="font-size:10px;color:#999;">'+LOADINGWAIT+'</span></center><br /><br />';
var loaderone='<img src="http://'+root+'/ajax-loader.gif" alt="'+LOADINGWAIT+'"/>';
var mainfile="http://"+document.domain+"/index.php";
var CarL = true; CarLL = true;
var CanLogoAnimate = true;
var CanAnimateSlider = true;
var Ctimer;
var StartSlider = 1;

//При ресайзе
$(window).resize(function(){});
//При загрузке страницы
$(document).ready(function(){
        $(function(){$("a[rel^='lightbox']").prettyPhoto({theme: 'dark_rounded'});});
		$("#SAI-Cars").mouseover(function(){CarLight();});
		$("#Left-Logo-Big").mouseover(function(){logoAnimate();});
		initSlider();
		$("#NewsArchive").html(loader);
		$('#NewsArchive').load(mainfile,{isajax:'true', module:'left'});
		searchInit();
		commentInit();
		optimizeImages();
       if ((navigator.appVersion.match(/MSIE\u0020([.\d]+);/)||[])[1]< 8){
	   } else{mapHIghtLight();} 
		$("#UserMail").blur(function(){ChackMail('UserMail');});
		
});

function mapHIghtLight(){
$("#HotMapIMG").fadeTo(2000,0.2,function(){$("#HotMapIMG").fadeTo(2000,1,function(){mapHIghtLight();});});
}


function optimizeImages(){
//alert('opera');
  var Elements = $(".Big-Center-Center img");
  var Images = $.makeArray(Elements);

   for(var i = 0; i <  Images.length; i++){
		var width = parseInt($(Images[i]).css("width")); 
		var height = parseInt($(Images[i]).css("height")); 
		var prop = width/height;
		if (width >485) {
		   var h = 485 / prop;
		    $(Images[i]).css("width",'485px'); $(Images[i]).css("height",h+'px');
			// $(Images[i]).removeAttr('height');
		  
		  }
		
		}
 
}

function initSlider(){
 $(".Slider-Images").fadeOut(1);
 $("#ImgSlide"+StartSlider).fadeIn(500);
 $(".Slide-Side").mouseover(function(){var c=$(this).attr('rel'); selectPart(c); CanAnimateSlider = false;});
 $(".Slide-Side").mouseout(function(){var c=$(this).attr('rel'); selectPart(c); CanAnimateSlider = true;});
 selectPart(StartSlider);
}

function selectPart(c){
if (CanAnimateSlider == true){
 if (c != StartSlider) $("#ImgSlide"+StartSlider).fadeOut(200);
 $("#SlidePart"+StartSlider).attr('class','Slide-Side');
 $("#SlidePart"+c).attr('class','Slide-Side-Sel');
 if (c != StartSlider) $("#ImgSlide"+c).fadeIn(200);
 StartSlider = c;
 x = StartSlider + 1; if (x>3) x=1;
 clearInterval(Ctimer);
 Ctimer = setInterval('selectPart('+x+');',5000);
 }
}

function logoAnimate(){
 if (CanLogoAnimate == true){
	 CanLogoAnimate = false;
	 $('#Left-Logo-Big').fadeTo(300,0.8,function(){
		$('#Left-Logo-Big').fadeTo(150,1,function(){CanLogoAnimate = true;});
	 });
 
 }
}

function CarLight(){
 if (CarL == true){CarL = false;
  if (CarLL == true) $("#SAI-Cars").append('<div id="SAI-CarsHL"></div>'); CarLL =false;
  $("#SAI-CarsHL").fadeOut(1);
  $("#SAI-CarsHL").fadeIn(1000,
		function(){$("#SAI-CarsHL").fadeOut(1000,function(){CarL=true;});});
 }}


function ShowMonth(month, year){
  if (parseInt(month)<1){month=12; year = parseInt(year)-1;}
  if (parseInt(month)>12){month=1; year = parseInt(year)+1;}
  $('#NewsArchive').load(mainfile,{isajax:'true', module:'left', m:month, y:year});
}

function searchInit(){
 var sT = $("#SearchItem");
 var RealText = sT.val();
  sT.focus(function(){if (RealText == sT.val()){sT.val('');  sT.css('font-style','normal');  }});
  sT.blur(function(){if ('' == sT.val()){sT.val(RealText); sT.css('font-style','italic');    }});
  
  sT.keyup(function(){
   var valu = sT.val();
   if (valu.length > 3){
    $("#Center-Column").html(loader);
    $("#Center-Column").load(mainfile,{isajax:'true', module:'search',sv:valu});
   }
    });
  }

var SelVar = 0;
function SetVote(id){$(".Check-Box-Checked").attr('class','Check-Box');$("#S"+id).attr('class','Check-Box-Checked');SelVar = id;}

function SendVoting(){var mv = $("#MyVar").val();var qid = $("#qid").val();$("#VotingBlock").html(loader);
$("#VotingBlock").load(mainfile,{isajax:'true', module:'right',sv:SelVar, mvar:mv,qd:qid});
}

var RealText; var RealText1; var RealText2;
function commentInit(){
var sT = $("#UserName");
  RealText = sT.val();
  sT.focus(function(){if (RealText == sT.val()){sT.val('');  sT.css('font-style','normal');  }});
  sT.blur(function(){if ('' == sT.val()){sT.val(RealText); sT.css('font-style','italic');    }});

var sT1 = $("#UserMail");
  RealText1 = sT1.val();
  sT1.focus(function(){if (RealText1 == sT1.val()){sT1.val('');  sT1.css('font-style','normal');  }});
  sT1.blur(function(){if ('' == sT1.val()){sT1.val(RealText1); sT1.css('font-style','italic');    }});
  
var sT2 = $("#UserText");
  RealText2 = sT2.val();
  sT2.focus(function(){if (RealText2 == sT2.val()){sT2.val('');  sT2.css('font-style','normal');  }});
  sT2.blur(function(){if ('' == sT2.val()){sT2.val(RealText2); sT2.css('font-style','italic');    }});  

}

function SendComment(){
 var Name = $("#UserName").val(); if (Name == RealText) Name = '';
 var Mail = $("#UserMail").val(); if (Mail == RealText1) Mail = '';
 var Text = $("#UserText").val(); if (Text == RealText2) Text = '';
 var Captha = $("#UserCaptcha").val();
 var itemid = $("#itemid").val();
 var itemchapter = $("#itemchapter").val();
 var itemneed = $("#itemneed").val();
 var realcaptha = itemneed.substr(4,itemneed.length - 3); realcaptha = realcaptha / 99;
$("#Notice").fadeIn(1);
 if (!Name || !Text || !Captha){
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'comments',err:'true'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else if (Captha != realcaptha) {
   $("#UserCaptcha").val('');
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'comments',err:'captha'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else {
  $("#Comment-Form").html(loaderone);
  $("#Comment-Form").load(mainfile,{isajax:'true', module:'comments',name:Name, mail:Mail, text:Text, captha:Captha, id:itemid, chapter:itemchapter, need:itemneed},function(){ShowComments(0,itemid, itemchapter);});
 }
}

function ShowComments(start,itemid, itemchapter){
  $("#CommentsYet"+start).html(loaderone);
  $("#CommentsYet"+start).load(mainfile,{isajax:'true', module:'comments',showcomments:'true', startshow:start, id:itemid, chapter:itemchapter});
}

function setmark(mark, itemchapter, itemid){
$("#Marks").html(loaderone);
if (itemchapter == 'news')
$("#Marks").load(mainfile,{isajax:'true', module:'news',marks:mark, id:itemid, chapter:itemchapter}); 
else
 $("#Marks").load(mainfile,{isajax:'true', module:'law',marks:mark, id:itemid, chapter:itemchapter}); 
}


function OpenDoc(nreg) {
var i=Math.round((Math.random() * (10000000 - 1)));
window.open("http://zakon.rada.gov.ua/cgi-bin/laws/main.cgi?nreg="+nreg,"D"+i,"width=800,height=550,status=no,toolbar=no,resizable=yes,scrollbars=yes,menubar=yes");
}


function GoNews(id,cid,lng){
location.href = "http://"+document.domain+"/"+lng+"/news/"+cid+"/"+id+".htm";
}
function wrtlat(lng){
location.href = "http://"+document.domain+"/"+lng+"/wright.htm";
}


function SendLetter(){
 var Name = $("#UserName").val(); if (Name == RealText) Name = '';
 var Mail = $("#UserMail").val(); if (Mail == RealText1) Mail = '';
 var Text = $("#UserText").val(); if (Text == RealText2) Text = '';
 var Captha = $("#UserCaptcha").val();
 var itemneed = $("#itemneed").val();
 var realcaptha = itemneed.substr(4,itemneed.length - 3); realcaptha = realcaptha / 99;
$("#Notice").fadeIn(1);
 if (!Name || !Text || !Captha){
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'wright',err:'true'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else if (Captha != realcaptha) {
   $("#UserCaptcha").val('');
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'wright',err:'captha'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else {
  $("#Comment-Form").html(loaderone);
  $("#Comment-Form").load(mainfile,{isajax:'true', module:'wright',name:Name, mail:Mail, text:Text, captha:Captha, need:itemneed});
 }
}


function MapAjax(id){
 $("#RegionShow").html(loader);
  $("#RegionShow").load(mainfile,{isajax:'true', module:'regions',showid:id});
}

function GoSubscribe(what){
var Name = $("#UserName").val(); if (Name == RealText) Name = '';
 var Mail = $("#UserMail").val(); if (Mail == RealText1) Mail = '';
  var Captha = $("#UserCaptcha").val();
 var itemneed = $("#itemneed").val();
 var realcaptha = itemneed.substr(4,itemneed.length - 3); realcaptha = realcaptha / 99;
$("#Notice").fadeIn(1);
 if (!Name || !Mail || !Captha){
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'mailer',err:'true'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else if (Captha != realcaptha) {
   $("#UserCaptcha").val('');
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'mailer',err:'captha'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else {
  $("#Comment-Form").html(loaderone);
  $("#Comment-Form").load(mainfile,{isajax:'true', module:'mailer',name:Name, mail:Mail, wdo:what, captha:Captha});
 }
}



function isValidEmail(email){email=email.replace(/^\s+|\s+$/g,'');return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);}
function ChackMail(id){
   	val=$("#"+id).val();
	if (val && val != RealText1){
if (!isValidEmail(val)){
 $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'mailer',err:'mail'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
$("#"+id).val(RealText1);}else{$("#Notice").html('');}
   }
   }
   
   
   
   
   //Mistake
  var mis;nN = navigator.appName; 
function getText(e) {
	if (!e) e= window.event; 
	if((e.ctrlKey) && ((e.keyCode==10)||(e.keyCode==13))){
		if(nN == 'Microsoft Internet Explorer'){if(document.selection.createRange()){var range = document.selection.createRange();
        mis = range.text; winop();}} 
	else {if (window.getSelection()) {mis = window.getSelection();
		winop();} 
	else if(document.getSelection()){mis = document.getSelection();
		winop();}}
    return true;
	} 
    return true;}
	
document.onkeypress = getText;  

function winop(){
 var FrameWidth = 530;
 var FrameHeight = 300;
 
 $("#AbsoluteFrame").css("width",FrameWidth+"px");
 $("#AbsoluteFrame").css("height",FrameHeight+"px");
 var FromTop =  $(document).scrollTop();
 var DocWidth =  $(window).width();
 var DocHeight =  $(window).height();
 var MarginLeft = (DocWidth - FrameWidth) / 2;
 var MarginTop = ((DocHeight - FrameHeight) / 2) + FromTop;
 $("#AbsoluteFrame").css("margin-top",MarginTop+"px");
 $("#AbsoluteFrame").css("margin-left",MarginLeft+"px");
 $("#AbsoluteFrame").fadeOut(2);
 $("#AbsoluteFrame").fadeIn(1000);
  var loc = unescape(window.location.href );
  $("#AbsoluteFrame").html(loader);
  var MissText = ' '; MissText = MissText+mis;
  $("#AbsoluteFrame").load(mainfile,{isajax:'true', module:'main',act:'error',ur:loc, textS:MissText});
}
 
function SendMistake(){
  var Text = $("#UserTextMistake").val(); 
 var Captha = $("#UserCaptcha").val();
 var itemneed = $("#itemneed").val();
 var realcaptha = itemneed.substr(4,itemneed.length - 3); realcaptha = realcaptha / 99;
 
 
 if (!Text){
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'mailer',err:'true'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else if (Captha != realcaptha) {
   $("#UserCaptcha").val('');
   $("#Notice").html(loaderone);
   $("#Notice").load(mainfile,{isajax:'true', module:'mailer',err:'captha'}, function(){$("#Notice").fadeOut(5000,function(){$("#Notice").html('');});});
 } else {
  $("#AbsoluteFrame").html(loaderone);
  $("#AbsoluteFrame").load(mainfile,{isajax:'true', module:'main',txt:Text},function(){
  
  

 $("#AbsoluteFrame").fadeOut(8000,function(){ $("#AbsoluteFrame").css("margin-left","0px");$("#AbsoluteFrame").css("margin-top","0px");});
  
  });
 }
 

}

function PrintThis(){ 
 var Info = $('#PrinterArea').html();
 var URL = unescape(window.location.href );
    Info = '<html><head>'
	       +'<style>'
		   +'body{color: #313131; margin: 0px; padding-left: 10px;padding-right: 10px; font-family: Arial,  Helvetica, Tahoma; font-size: 12px; line-height:130%;}'
		   +'h1{font-size: 15px; color: #000; margin-top: 2px; margin-bottom: 10px; font-weight:none;  font-family: Arial;}'
		   +'img.Main-News-Full-Picture{width: 240px; border: 0px;}'
			+'div.Main-Full-News-Overflow{width: 240px; float: left; margin: 0px 10px 10px 0px;}'
			+'div.Main-News-Title-Bar{padding: 4px; color: #FFF; text-align: center; background-color: #225ba9; margin-top: -5px;}'
		   +'</style>'
		   +'</head><body>'
		   +'<div style="width: 100%; height: 90px;">'
		   +'<img src="http://www.sai.gov.ua/templates/mvd/design/logo.png" style="margin-top: -3px; margin-left: 30px; float: left;">'
		   +'<p style="font-size: 24px; color: #000; font-weight: bold; padding-top: 20px; margin-left: 30px;">Управління ДАІ МВС України</p>'
		   +'<p style="font-size: 13px; color: #333; font-weight: bold; margin-left: 30px;">'+URL+'</p>'
		   +'</div><hr>'
	       +Info
		   + '</boby></dtml>';
 
 
 var XX = window.open("","Print","width=800,height=550,status=no,toolbar=no,resizable=yes,scrollbars=yes,menubar=yes");
     XX.document.write(Info);
	 
	 
	 XX.focus();
try
{
   XX.document.execCommand('print', false, null);
}
catch(e)
{
   XX.print();
}
 
} 

