$(document).ready(function() {
    $("#contactForm").validationEngine();
});
function verify(){
    if(!$("#contactForm").validationEngine('validate'))
	return false;
    $(".request_button").fadeOut('slow');
    $.ajax({
	    type: "POST",
	    data: $("#contactForm").serialize() ,
	    url: "/contacts.php",
	    success: function(msg){
	    //alert(msg);
	    msg = "<span style='display: block; text-align: center; font-weight: bold; color: #000; font-size: 14px;'><br />Ваше сообщение отправлено!</span>";
	    divCont=$('.contULBox');
	    divCont.width(divCont.width()).height(divCont.height());
	    divCont.fadeOut('slow', function(){
		divCont.animate({'height': '50px'}, 'slow',function(){
		    divCont.html( msg ).fadeOut(0).fadeIn('slow');
		});
	    });

	    },
	    beforeSend : function(){}  
	    });
}

function preload(image)
{var d=document; if(!d.wb_pre) d.wb_pre=new Array();
var l=d.wb_pre.length; d.wb_pre[l]=new Image; d.wb_pre[l].src=image;
}

function over_on(n,ovr)
{var d=document,x; x=d[n];if (!(x) && d.all) x=d.all[n];
if (x){        document.wb_image=x; document.wb_normal=x.src; x.src=ovr; }}

function over_off()
{var x=document.wb_image; if (document.wb_normal) x.src=document.wb_normal;}

function CheckCatalogPosition(t, val, txt){
//alert('t='+t+' val='+val+' txt='+txt);
var myArray = val.split('='); 
 if(myArray[0]=="categ"){
  alert(txt); 
  t.selectedIndex = 0;
  return false;
 }
 return true;
}




function MM_findObj(n, d) { //v4.01
 var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
 }
 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
 if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_swapImage() { //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
 var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
 if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function popup_window(img, title, x, y, classcss) {
newwindow=window.open('','imagepopup','left='+((screen.width-x)/2)+',top='+((screen.height-y)/2)+',height='+y+',width='+x+',');
var tmp = newwindow.document;
tmp.write('<html><head><title>'+title+'</title><link rel="stylesheet" href="/rud.css"></head><body class="'+classcss+'" leftmargin="0" topmargin="0"><a href="javascript:self.close()"><img src="'+img+'" width="'+x+'" height="'+y+'" border="0"></a></body></html>');
tmp.close();
if (window.focus) {newwindow.focus()}
return false;
}

function popup_window_url(url, x, y) {
newwindow=window.open(url,'','left='+((screen.width-x)/2)+',top='+((screen.height-y)/2)+',height='+y+',width='+x+',resizable=1,scrollbars=1');
if (window.focus) {newwindow.focus()}
return false;
}

function mapclick(n,d)
{ 
  selected=n;
  distribution=d;
  mapover(n);
  document.getElementById("tlayout").style.height = Math.round(Math.random() * 99); // Fix FF behavior - it do not want recalculate height of document
  document.getElementById("transp").style.display = "none";// Hide and then show transparent layer, to clear ugly border over selected region in IE
  document.getElementById("transp").style.display = "block";
  
  if (d==1) // If selected first item...
  { 
	document.getElementById("d1").className="active"; // Set "active" style for selected distribution type
	document.getElementById("d2").className=""; // Remove style from unselected distribution type
	document.getElementById("d1").innerHTML=d1name; // Set pre-defined name for selected item
	document.getElementById("d2").innerHTML='<a href="javascript:mapclick(selected, 2);">'+d2name+'</a>'; // Set pre-defined name for selected item and add appropriate link
  }
  else 
  { 
	document.getElementById("d1").className="";
	document.getElementById("d2").className="active";
	document.getElementById("d1").innerHTML='<a href="javascript:mapclick(selected, 1);">'+d1name+'</a>';
	document.getElementById("d2").innerHTML=d2name;
  }
} 

function hideexcept(n,o,d)
{
  var i, j;
  for (i=1; i<26; i++)
  {
    if ((i==n)|(i==o))
    {
      document.getElementById("m"+i).style.visibility = "hidden"; // Hide image of region to make it selected
	  if (i==n) 
	  {
	    document.getElementById("n"+i).className = "selected-region-name"; // Apply selected style to region name
	  }
	  else
	  {
	    document.getElementById("n"+i).className = "selected-region-name"; // Apply non-selected style to region name
	  }
	}
	else
	{
      document.getElementById("m"+i).style.visibility = "visible"; // Show image of region to make it unselected
      document.getElementById("n"+i).className = "region-name"; // Apply non-selected style to region name
	}
    for (j=1; j<3; j++)
	{
      if ((j==d)&(i==n))
	  {
	    document.getElementById("t"+i+"d"+j).style.height = "auto"; // Show text for selected region and distribution type
        document.getElementById("t"+i+"d"+j).style.display = "block";
	  }
	  else
	  {
	    document.getElementById("t"+i+"d"+j).style.height = "0"; // Hide all other texts
        document.getElementById("t"+i+"d"+j).style.display = "none";
	  }
	}
  }
}
  
function mapover(n) 
{ 
  var i;
  over=n;
  hideexcept(selected,over,distribution);
}

