N = (document.all) ? 0 : 1;
var over = false;
var mDown = false;
var ob,ob1;
var va = 0;
var load = 0;
var h,w,tool;
function emtyCoordValues(){
		document.Form1.txtX1.value = '';
		document.Form1.txtX2.value = '';
		document.Form1.txtY1.value = '';
		document.Form1.txtY2.value = '';
}
function setVar(intH,intW){
 h = intH;
 w = intW;
 //status=h + "," + w
 //alert(h + "," + w);
 
}
function MD(e) {

	if (over){
		ob = document.getElementById("imgbtnMap");
		ob = ob.style;

		X=returnX(e);
		Y=returnY(e);
		
		document.Form1.txtX1.value = returnX(e);
		document.Form1.txtX2.value = returnX(e);
		document.Form1.txtY1.value = returnY(e);
		document.Form1.txtY2.value = returnY(e);
		mDown = true;
		
		return false;
	}




}



function MM(e) {

	
	if (mDown){

			X2=returnX(e);
			Y2=returnY(e);
		
		
		
		
		document.Form1.txtX2.value = X2;
		document.Form1.txtY2.value = Y2;
		
		
		
		switch (document.Form1.txtTool.value) 
		{ 
		case "zoomIn" : 
			zoomIn(e);
			break; 
		case "zoomOut" : 
			zoomUt();
			break; 
		default : 
			zoomPan(e);
		} 
			
	return false;
		
	}
	
}



function MU(e) {

	
	if (mDown){
		//if(N){
			mDown = false;
			showLoading()
			document.Form1.submit();
		//}else{
			
		//	mDown = false;
		
		 //if (returnX(e) > w || returnX(e) < 0){
		//		showLoading()
		//		document.Form1.submit();
				
			
			
		//}
		//if (returnY(e) > h || returnY(e) < 0){
			
		//		showLoading()
		//		document.Form1.submit();
			
		//}
		//}
		
		
	}
	
	ob = null;
	va = 0;
	
}

function zoomIn(e){

	
		document.Form1.txtX2.value = returnX(e);
		document.Form1.txtY2.value = returnY(e);
	

	ob1 = document.getElementById("zoomRec");
	ob1 = ob1.style;
	var width, height, width1,height1;

	width = parseInt(document.Form1.txtX1.value);
	width1 =parseInt(document.Form1.txtX2.value);
	height =parseInt(document.Form1.txtY1.value);
	height1=parseInt(document.Form1.txtY2.value);
	if(va == 0){ 
		showId('zoomRec');
	}
	if((width >= width1)&&(height <= height1)){
		
				if(va == 0){ 
					
					ob1.top = returnY(e);
					
					
					va = 1;
				}
				
				ob1.left=returnX(e);
			
				ob1.width =  document.Form1.txtX1.value - document.Form1.txtX2.value;
				ob1.height = document.Form1.txtY2.value - document.Form1.txtY1.value;
			}
		
			else if((width <= width1)&&(height <= height1)) {
				
				if(va == 0){ 
					
						
						
					ob1.top=returnY(e);
					ob1.left=returnX(e);
					va = 1;
				}
				
				ob1.width = document.Form1.txtX2.value - document.Form1.txtX1.value;
				ob1.height = document.Form1.txtY2.value - document.Form1.txtY1.value;
			}
			else if((width <= width1)&&(height >= height1)){
				
				if(va == 0){ 
					
					ob1.left=returnX(e);
				
					va = 1;
				}
				
				ob1.top=returnY(e);
				
				ob1.width = document.Form1.txtX2.value - document.Form1.txtX1.value;
				ob1.height = document.Form1.txtY1.value - document.Form1.txtY2.value;
			}
			else if((width >= width1)&&(height >= height1)){
				
				ob1.left=returnX(e);
				ob1.top=returnY(e);
				ob1.width =  document.Form1.txtX1.value - document.Form1.txtX2.value;
				ob1.height = document.Form1.txtY1.value - document.Form1.txtY2.value;
			}
		
}
function zoomUt(){

}
function zoomPan(e){

	
		ob.left = returnX(e)-X ;
		ob.top = returnY(e)-Y;

	// Om kartan dras utanför definierat område skicka sidan och visa laddaruta   
    if (returnX(e) > w || returnX(e) < 5){
		if (load == 0) {
			showLoading()
			document.Form1.submit();
			
			load = 1;
		}
    }
    if (returnY(e) > h || returnY(e) < 5){
		if (load == 0) {
			showLoading()
			document.Form1.submit();
			
			load = 1;
		}
    }
	
}
function returnX(e){

	var retX
	if (N){
		retX = e.clientX + document.body.scrollLeft;
		
	}else{
		retX = event.clientX + document.body.scrollLeft;
		
	}
	return retX;
}
function returnY(e){

	var retY
	if (N){
		retY = e.clientY+ document.body.scrollTop;
		
	}else{
		retY = event.clientY+ document.body.scrollTop;
		
	}
	return retY;
}
function showId(id){
	document.getElementById(id).style.visibility = "visible";
}
function hideId(id){
	document.getElementById(id).style.visibility = "hidden";
}
function showLoading(){
	showId('divLoad');
	showId('divLoadImg');
}
function hideLoading(){
	hideId('divLoad');
	hideId('divLoadImg');
}
function swap(tool){

	switch (tool) 
	{ 
	case "zoomIn" : 
		document.Form1.zoomIn.src = 'images/toolbar/ZoomIn_Active.gif';
		document.Form1.zoomOut.src = 'images/toolbar/ZoomOut.gif';
		document.Form1.zoomPan.src = 'images/toolbar/pan.gif';
		document.Form1.txtTool.value = 'zoomIn';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebzoomin.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		break; 
	case "zoomOut" : 

		document.Form1.zoomIn.src = 'images/toolbar/ZoomIn.gif';
		document.Form1.zoomOut.src = 'images/toolbar/ZoomOut_Active.gif';
		document.Form1.zoomPan.src = 'images/toolbar/pan.gif';
		document.Form1.txtTool.value = 'zoomOut';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebzoomout.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		  
		break; 
	default : 
		document.Form1.zoomIn.src = 'images/toolbar/ZoomIn.gif';
		document.Form1.zoomOut.src = 'images/toolbar/ZoomOut.gif';
		document.Form1.zoomPan.src = 'images/toolbar/pan_Active.gif';
		document.Form1.txtTool.value = 'zoomPan';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebpan.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		
	} 

}

function swapBlack(tool){

	switch (tool) 
	{ 
	case "zoomIn" : 
		document.Form1.zoomIn.src = 'images/stadium/ZoomIn_Active.gif';
		document.Form1.zoomOut.src = 'images/stadium/ZoomOut.gif';
		document.Form1.zoomPan.src = 'images/stadium/pan.gif';
		document.Form1.txtTool.value = 'zoomIn';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebzoomin.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		break; 
	case "zoomOut" : 
		document.Form1.zoomIn.src = 'images/stadium/ZoomIn.gif';
		document.Form1.zoomOut.src = 'images/stadium/ZoomOut_Active.gif';
		document.Form1.zoomPan.src = 'images/stadium/pan.gif';
		document.Form1.txtTool.value = 'zoomOut';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebzoomout.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		  
		break; 
	default : 
		document.Form1.zoomIn.src = 'images/stadium/ZoomIn.gif';
		document.Form1.zoomOut.src = 'images/stadium/ZoomOut.gif';
		document.Form1.zoomPan.src = 'images/stadium/pan_Active.gif';
		document.Form1.txtTool.value = 'zoomPan';
		var Some_Uniform_Resource_Identifier = 'images/toolbar/mapinfowebpan.cur';
		document.getElementById('imgbtnMap').style.cursor = "url(" + Some_Uniform_Resource_Identifier + "),crosshair";
		
	} 

}

document.onmousedown = MD;

document.onmousemove = MM;

document.onmouseup = MU;

