function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript Firefox, Opera 8.0+, Safari
alert("XMLHttpRequest not supported");
return null;
};

function dochange(valx, valy) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
 if (req.readyState==4) {
      if (req.status==200) {
          document.getElementById('image').innerHTML=req.responseText; //retuen value
    }
 }
};

req.open("GET", "/map2/sqr.php?tox="+valx+"&toy="+valy); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=Windows-1251"); // set Header
req.send(null); //send value
	
	point(document.move.left.value, document.move.up.value);
	if (document.getElementById('right') != null){
	repo(document.move.left.value, document.move.up.value);
	}
	return false;
	}

//--------------------------------------------------------------------------------------------------

var m = 0;
var n = 0;

function goin_move(x,y){ 
		document.getElementById('map').style.cursor='move';
		if (x!==''){
		n = parseInt(document.move.left.value) + parseInt(x);
		if (n<0) {n=0;}
		if (n>2500) {n=2500;}
		document.move.left.value = n;
		}
		if (y!==''){
		m = parseInt(document.move.up.value) + parseInt(y);
		if (m<0) {m=0;}
		if (m>2634) {m = 2634;}
		document.move.up.value = m;
		}
		
		dochange(document.move.left.value, document.move.up.value);
	}

function point(valx, valy) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
 if (req.readyState==4) {
      if (req.status==200) {
          //document.getElementById(src).innerHTML=req.responseText; //retuen value
          document.getElementById('pont').innerHTML=req.responseText; //retuen value
    }
 }
};

req.open("GET", "/map2/points.php?tox="+valx+"&toy="+valy); //make connection
//req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=Windows-1251"); // set Header
req.send(null); //send value
return false;
}


var ua = 'msie';
var W=navigator.userAgent.toLowerCase();
if(W.indexOf("opera")!=-1){ua='opera';}else if(W.indexOf("msie")!=-1){ua='msie';} else if(W.indexOf("mozilla")!=-1){ua='gecko';}

function $(v) { return(document.getElementById(v)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }

  
 function dragOBJ(d,e) {
	document.getElementById('map').style.cursor='move';

	function drag(e) {
	var e = e? e: window.event;
	if(!stop) {
	d.style.top=(tX=xy(e,1)+oY-eY+'px'); 
	d.style.left=(tY=xy(e)+oX-eX+'px');	
		}
	}
	var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;
	
	document.onmousemove=drag;	
	document.onmouseup=function(e){ 
	getXY(e);
	document.getElementById('map').style.cursor='default';
	stop=1; 
	document.onmousemove=''; 
	document.onmouseup=''; 
	};
	
}


function getXY(e) {
e = e? e: window.event;
  
  x = (document.getElementById('image').e) ? e.pageX : e.clientX-document.getElementById('image').offsetLeft;
  y = (document.getElementById('image').e) ? e.pageY : e.clientY-document.getElementById('image').offsetTop;
 
	var	x1= document.getElementById('map').style.left+document.move.left.value;
	var	y1= document.getElementById('map').style.top+document.move.up.value;
  
  document.move.left.value=document.move.left.value-parseInt(x1);
  document.move.up.value=document.move.up.value-parseInt(y1);
  
  
  n=document.move.left.value;
  m=document.move.up.value;
  if (n<0) n = 0;
	if (n>2500) n=2500;
	document.move.left.value = n;
		
	if (m<0) m = 0;
	if (m>2634) m = 2634;
	document.move.up.value = m;
  
  var a =  Math.round(n/100)*100+x;
  var b =  Math.round(m/100)*100+y;
  
  
  var a1 =  Math.round(n/100)*100;
  var b1 =  Math.round(m/100)*100;
  
  //document.move.sd.value = x+":"+y;
  //document.move.sd.value = a+":"+b;
  
  document.move.left.value=a1;
  document.move.up.value=b1;
  
  
if (parseInt(x1)!=0 || parseInt(y1)!=0){
  dochange(document.move.left.value, document.move.up.value);
  }
  }

//--------------------------------------------------------------------------------------------------

function direct(c){
var left = 0;
var up = 0;
if (c=='Buiucani') {
	left = 400;
	up = 800;
 }
else if (c=='Riscani') {
	left = 1300;
	up = 400;
 }
else if (c=='Centru') {
	left = 700;
	up = 1300;
 }
else if (c=='Ciocana') {
	left = 1700;
	up = 1100;
 }
else if (c=='Botanica') {
	left = 1300;
	up = 1700;
 }
  document.move.left.value = left;
  document.move.up.value = up;
  var go = new dochange(left, up);
  return false;
}

function change_bg(id,state)
{
if (state==1) 
{
document.getElementById(id).style.color='#000000';
document.getElementById(id).style.background='#cccccc';

}
else
{
document.getElementById(id).style.color='#189DDE';
document.getElementById(id).style.background='';
}
}

function cross()
{
document.getElementById('map').style.cursor='move';
}
