//Общаемся с серваком по ajax
function ServerMessage(keyword,table,name_div)
{
	var req;
	var sss;
	if (window.XMLHttpRequest)
	{
		req=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try	{req=new ActiveXObject('MSXML2.XMLHTTP.3.0');}
		catch(e){}
	}
	if(req)
	{
		req.open("post","/ajax.php",true);
		req.setRequestHeader("Content-Type"," application/x-www-form-urlencoded;");
		req.onreadystatechange=function()
		{
	   	 if (req.readyState==4 && req.status==200)
	    	{
	    		sss=req.responseText;
	    		document.getElementById(name_div).style.display='block';
	    		document.getElementById(name_div).innerHTML=sss;
	    	}
		}
		req.send('keyword='+table+'|'+encodeURIComponent(keyword));
	}
}
function ShowDivCenter(div)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var obj=document.getElementById(div);
	if (obj) {
		obj.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 400) / 2) + 'px');
		obj.style.left = (((arrayPageSize[0] - 20 - 300) / 2) + 'px');
		obj.style.display = 'block';		
	}
	else alert('no');
}

function ShowDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.display="block";
}

function ShowHideDiv(div)
{
	if(document.getElementById(div)!=null)
	if(document.getElementById(div).style.display=='none')
	document.getElementById(div).style.display="block";
	else
	document.getElementById(div).style.display="none";
}
function HideDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.display="none";
}
function VisibleDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.visibility="visible";
}

function unVisibleDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.visibility="hidden";
}

//Проверка textarea на количестов символов
function isNotMax(e,div){
	e = e || window.event;
	var target = e.target || e.srcElement;
	var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)
	if(target.value.length > target.getAttribute('maxlength')) target.value=target.value.substr(0,target.getAttribute('maxlength'))
	if(div!="empty")
	document.getElementById(div).innerHTML=target.value.length;
	return target.value.length <= target.getAttribute('maxlength');
}

function setScroll()
{
document.body.style.overflowX='auto';
}
function SetScroll()
{
document.body.style.overflowX='auto';
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (window.sidebar) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a){
// var id_connection=document.getElementById('code_connection_user').value;
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE') window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
// SM1(id_connection,'addfav');
 return false;
}

function ShowWin1()
{
		var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 65) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 50) / 2);
	if(window.screen.width>1000)document.body.style.overflowX="hidden";
	document.getElementById('win1').style.display="block";	
	document.getElementById('win1').style.width=516+'px';	
	document.getElementById('win1').style.height=265+'px';	
	document.getElementById('win1').style.left=(lightboxLeft-258)+'px';	
	document.getElementById('win1').style.top=(lightboxTop-140)+'px';	
	document.getElementById('backplanbox').style.height=arrayPageSize[1]+'px';
	document.getElementById('backplanbox').style.width=arrayPageSize[0]+'px';
	document.getElementById('backplanbox').style.display='block';		
}
function ShowWin2()
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 65) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 50) / 2);
	if(window.screen.width>1000)document.body.style.overflowX="hidden";
	document.getElementById('win2').style.display="block";	
	document.getElementById('textwin2').innerHTML="<input type=text id=emailwin2>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' onclick=SendLetter('emailwin2')>OK</a>";
	document.getElementById('backplanbox').style.height=arrayPageSize[1]+'px';
	document.getElementById('backplanbox').style.width=arrayPageSize[0]+'px';
	document.getElementById('backplanbox').style.display='block';		
}

function SendLetter(mail)
{
	var feedback=true;
	var re2=/^[0-9a-zA-Z\-_]+@[0-9a-zA-Z\-_\.]+\.[a-zA-Z]{2,3}$/;	

	var mailtext=document.getElementById(mail).value;
	if(mailtext==="" || !re2.test(mailtext)) {feedback=false;pole=mail;}
	if(feedback==true)
	{
		document.getElementById(mail).value="";
		SendToServer(mailtext,'sendletter','textwin2');
		//setTimeout('HideLetter()',2500);		
	}
	else
	{
		$("#"+pole).highlightFade({color:'#ffffff',speed:1000,iterator:'sinusoidal'});
	}
}
function SendToServer(keyword,table,div)
{
	var req;
	var sss;
	if (window.XMLHttpRequest)
	{
		req=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try	{req=new ActiveXObject('MSXML2.XMLHTTP.3.0');}
		catch(e){}
	}
	if(req)
	{
		req.open("post","/ajax.php",true);
		req.setRequestHeader("Content-Type"," application/x-www-form-urlencoded;");
		req.onreadystatechange=function()
		{
	   	 if (req.readyState==4 && req.status==200)
	    	{
	    		sss=req.responseText;
				//alert(sss);
				if(div!="empty"){
				document.getElementById(div).style.display='block';
				document.getElementById(div).innerHTML=sss;}
	    	}
		}
		req.send('keyword='+table+'|'+encodeURIComponent(keyword));
	}
}
function load() {
	var adress=document.getElementById('adressmap').value;
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 65) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 50) / 2);
	if(window.screen.width>1000)document.body.style.overflowX="hidden";
	document.getElementById('borderbox').style.left=(lightboxLeft-400)+'px';	
	document.getElementById('borderbox').style.top=(lightboxTop-250)+'px';
	document.getElementById('borderbox').style.width=800+'px';
	document.getElementById('borderbox').style.height=501+'px';	
	document.getElementById('borderbox').style.display="block";	
	document.getElementById('contentplanbox').style.display="block";	
	document.getElementById('contentplanbox').style.width=780+'px';	
	document.getElementById('contentplanbox').style.height=480+'px';	
	document.getElementById('contentplanbox').style.left=(lightboxLeft-390)+'px';	
	document.getElementById('contentplanbox').style.top=(lightboxTop-239)+'px';	
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("planbox"));
		var geocoder = new GClientGeocoder();
		var customUI = new GMapUIOptions();
customUI.maptypes = {};
customUI.zoom = {};
customUI.controls = {};
customUI.maptypes.normal = true;
customUI.maptypes.hybrid = false;
customUI.zoom.doubleclick = true;
customUI.zoom.scrollwheel = false;
customUI.controls.largemapcontrol3d = true;
customUI.controls.menumaptypecontrol = false;
map.setUI(customUI);		
        function showAddress(address) {
          geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              //alert(address + " not found");
              document.getElementById("planbox").style.display = 'none';
            } else {
			        // Create our "tiny" marker icon
			 var blueIcon = new GIcon(G_DEFAULT_ICON);
			 var title = adress;
			 blueIcon.image = "/img/map_logo.png";
		     blueIcon.iconSize = new GSize(42, 42);
			  blueIcon.iconAnchor = new GPoint(15,42);			 
			 blueIcon.shadow =null;
			 // Set up our GMarkerOptions object
			  markerOptions = {icon:blueIcon,title:title};
              map.setCenter(point, 15);
			  var marker = new GMarker(point, markerOptions);
              
		    /*GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(adress);
          });*/
		  map.addOverlay(marker);
            }
          }
          );

        } 
		showAddress(adress);
      }
    }
	
	function Unloadmap(){document.getElementById('planbox').innerHTML='';HideDiv("borderbox");HideDiv("contentplanbox");}
	
	
function loadcont() {
	var adress=document.getElementById('adressmap').value;
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var customUI = new GMapUIOptions();
customUI.maptypes = {};
customUI.zoom = {};
customUI.controls = {};
customUI.maptypes.normal = true;
customUI.maptypes.hybrid = false;
customUI.zoom.doubleclick = true;
customUI.zoom.scrollwheel = false;
customUI.controls.largemapcontrol3d = true;
customUI.controls.menumaptypecontrol = false;
map.setUI(customUI);		
        function showAddress(address) {
          geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              //alert(address + " not found");
              document.getElementById("map").style.display = 'none';
            } else {
			        // Create our "tiny" marker icon
			 var blueIcon = new GIcon(G_DEFAULT_ICON);
			 var title = adress;
			 blueIcon.image = "/img/map_logo.png";
		     blueIcon.iconSize = new GSize(42, 42);
			  blueIcon.iconAnchor = new GPoint(15,42);			 
			 blueIcon.shadow =null;
			 // Set up our GMarkerOptions object
			  markerOptions = {icon:blueIcon,title:title};
              map.setCenter(point, 15);
			  var marker = new GMarker(point, markerOptions);
              
		    /*GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(adress);
          });*/
		  map.addOverlay(marker);
            }
          }
          );

        } 
		showAddress(adress);
      }
    }
	
function ShowListMenu(id)
{
	for(i=1;i<=document.getElementById('maxlist').value;i++)
	{
		if(document.getElementById("nlist"+i)!=null)
		document.getElementById('nlist'+i).className="namelist";
		HideDiv("menulist"+i)
	}
		document.getElementById('nlist'+id).className="namelistactiv";
		ShowDiv("menulist"+id)
}
function ActMList(id)
{
	if(document.getElementById('nlist'+id).className=="namelist")
	document.getElementById('nlist'+id).className="namelisthover";
}
function desActMList(id)
{
	if(document.getElementById('nlist'+id).className=="namelisthover")
	document.getElementById('nlist'+id).className="namelist";
}

/*Форум*/
function sestvalue(div,value)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).value=value;
	
}
function PrintMessage(item,ans,page)
{
	var feedback=true;
	item=document.getElementById('itemnow').value;
	re1=/^[А-Яа-я\ \-_0-9a-zA-Z]+$/;
	re2=/^[0-9a-zA-Z\-_]+@[0-9a-zA-Z\-_\.]+\.[a-zA-Z]{2,3}$/;
	var idmes=document.getElementById('nummessage').value;
	var author_message=document.getElementById('author_message').value;
	var mail_message=document.getElementById('mail_message').value;
	var newcod,mes;
	var cod=document.getElementById("codbuttoncomment").src;
	var len=cod.length;
	var ras=cod.substr(len-6,6);
	ras=ras.substr(0,2);
	ras=parseInt(ras);
	ras=ras*56-15;
	if(mail_message=="" || !re2.test(mail_message)) {feedback=false;mes='Проверьте адрес';}
	if(author_message=="" || !re1.test(author_message)){feedback=false;mes='Имя содержит недопустимые символы';}
	if(parseInt(document.getElementById("cod_message").value)!=ras){
	var t=document.getElementById("cod_message").value;
	feedback=false;mes='Неверный код';}
	var text_message=document.getElementById('textreviewcomment').value;
	text_message=text_message.replace(/"/g,'&quot;');	
	text_message=text_message.replace(/'/g,'`');
	GenCode();
	if(feedback!=false)
	{
		SendToServer(idmes+'|'+item+'|'+ans+'|'+page+'|'+mail_message+'|'+author_message+'|'+text_message,'printmessage','listmessage');
		HideDiv('message');
		CleanMessage();
	}
	else alert(mes);
}

function GenCode()
{
		newcod=(Math.round(Math.random()*7+2)*10 + Math.round(Math.random()*1+1));
		document.getElementById('codbuttoncomment').src="/cod/cod_"+newcod+".jpg";
		document.getElementById('codbuttoncomment').value=newcod;
}
function CleanMessage()
{
		document.getElementById('author_message').value="";
		document.getElementById('mail_message').value="";
		document.getElementById('textreviewcomment').value="";
		document.getElementById('cod_message').value="";
}
function isNotMax(e,div){
	e = e || window.event;
	var target = e.target || e.srcElement;
	var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)
	if(target.value.length > target.getAttribute('maxlength')) target.value=target.value.substr(0,target.getAttribute('maxlength'))
	document.getElementById(div).innerHTML=target.value.length;
	return target.value.length <= target.getAttribute('maxlength');
}
function SetValueList(id){
document.getElementById('listmessagenow').value=id;alert(id)
}
/*Конец Форум*/
function ShowAllPhotos(id)
{
HideDiv("p"+id);
ShowDiv("hidden"+id);
ShowDiv("hh"+id);
}

function ShowHidePhotos(id)
{
ShowDiv("p"+id);
HideDiv("hidden"+id);
HideDiv("hh"+id);

}
