﻿//The validation for an Integer
//oMsg is the message you wants to be displayed.
//args is the object name ie pass (this) to the function

function validateInteger(Msg, args)
{
	var test = isNaN(args.value);
	if (test)
	{

	    
		alert(Msg);
		//Set the value to nothing
		args.value = "";
	}
	//if the value is a number, then check that it is a whole number
	else
	{
		if ((parseInt(args.value) / args.value) == 1 || args.value == 0)
		{	
			//if the number is a whole number then set the value to the integer part to eliminate any .00 decimals
			args.value = parseInt(args.value, 10);
		}
		else
		{
			alert(Msg);
			//Set the value to nothing
			args.value = "";
		}
		//check if the number is still valid or not
		if (isNaN(args.value))
		{
			args.value="";
		}
    }
}
//End Function

//ZOOM TO COORDINATE
function ZoomToCoord()
{

   // ('divlat','txtlat','35','21');" />
   
   //('divlong','txtlong','34','14');"
   
   if (document.getElementById('txtlat').value =="")
   {
     alert("Please enter a value for Latitutde");
     return;
   }
   
   var latvalue = document.getElementById('txtlat').value
   if (latvalue < 21 || latvalue > 35)
   {
     
     alert("Latitude value are between 21 and 35 for South Africa");
     return;
   }
   
   if (document.getElementById('txtlong').value =="")
   {
     alert("Please enter a value for Longitude");
     return;
   }
   
   var longvalue = document.getElementById('txtlong').value
   if (longvalue < 21 || longvalue > 35)
   {
        
     alert("Longitude values are between 14 and 34 for South Africa");
     return;
   
   }
   
    document.getElementById('zoomtohidden').value="1";
    document.getElementById('processing').style.display='block';
    document.getElementById("EMVodamap_Command2").value=document.getElementById("EMVodamap_Command").value;
    document.getElementById("EMVodamap_Command").value="TEMP";
    var formToSend = document.getElementById("Form1");	        
    formToSend.submit();

}

//Clears the point(Star symbol) for Surburb and Point Search
function ClearPoint()
{
    var obj = parent.frames["Map"];
    document.getElementById('btnClearPoint').value = "1";
    document.getElementById('processing').style.display = 'block';
    document.getElementById("EMVodamap_Command2").value = document.getElementById("EMVodamap_Command").value;
    document.getElementById("EMVodamap_Command").value = "TEMP";
    var formToSend = document.getElementById("Form1");
    formToSend.submit();
    
}



function onZoomBox(left, top, right, bottom)
{
	document.getElementById("EMVodamap_map_x").value = left;
	document.getElementById("EMVodamap_map_y").value = top;
	document.getElementById("EMVodamap_map_x2").value = right;
	document.getElementById("EMVodamap_map_y2").value = bottom;
	var formToSend = document.getElementById("Form1");	        
    formToSend.submit();
	
}

function ToggleDisplay(oButton, oItems, oHidden)
{
 
    if ((oItems.style.display == "") || (oItems.style.display == "none"))
        {
            oItems.style.display = "block";
            oButton.src = "Images/arrowdn.gif";
            oHidden.value="block";
        } 
    else
        {
            oItems.style.display = "none";
            oButton.src = "Images/arrow.gif";
            oHidden.value="none";
        }
     return false;
}

function ToggleLoad(oButton, oItems, oHidden){
    if ((oHidden.value == "") || (oHidden.value == "none"))
        {
            oItems.style.display = "none";
            oButton.src = "Images/arrow.gif";
        } 
    else
        {
            oItems.style.display = "block";
            oButton.src = "Images/arrowdn.gif";
        }
     return false;
}

function MapResize(id){ 
    var w,h;
    w=screen.width;
    h=screen.height;
    try{
        document.getElementById("ResizeMapHidden").value=id;
        } 
    catch(e){
        document.getElementById("ResizeMapHidden").value="1";
            }
    document.getElementById("EMVodamap_Command2").value=document.getElementById("EMVodamap_Command").value;
	document.getElementById("EMVodamap_Command").value="TEMP";
	document.getElementById("processing").style.display="block";//shows processing window
	document.getElementById("ScreeResHidden").value=id;
	document.Form1.submit();
}
		

//**********************************************************************************************************************************
// FUNCTIONS FOR LOADING LAYERS ON/OFF
//**********************************************************************************************************************************

function LayersLoad()
{

	var lyrlist,items,objI,itemlist;
	lyrlist= document.getElementById("EMVodamap_LayerController").value;
	itemlist = lyrlist.split("#");
	items = itemlist.length;
	var i=0;
	var j=0;
		while (i < parseFloat(items))
		{
			try 
			{
				//TURN Images on or off
				
				objI = document.getElementById("I" + i);
				if ((itemlist[i]=="T")||(itemlist[i]=="Y"))
				{
					objI.src="Images/tick_on.gif";
				}
			}
			catch(e){}	
			i=i+1;
		}
}


//**********************************************************************************************************************************
// FUNCTIONS FOR TURNING LAYERS ON/OFF
//**********************************************************************************************************************************
function LayersF(id){
	
	var objI,lstr,strb,stra,lpos;			
	
	var ControllerInput = document.getElementById("EMVodamap_LayerController")
	lstr= ControllerInput.value;
		
	var ControllerArray = lstr.split("#");	
	
	//image modification and string mod
	objI=document.getElementById("I" + id);
	var Itmp;
	Itmp = objI.src.split("/");
	if(Itmp[Itmp.length-1]=="tick_on.gif")
	{
		objI.src="Images/tick.gif";
		ControllerArray[id] = "F"; 
	}
	else{
		objI.src="Images/tick_on.gif"
		ControllerArray[id] = "T"; 
	}
	
	 for(var i=0; i<ControllerArray.length; i++)
      {
      
          if (i == 0)
          {
           ControllerInput.value = ControllerArray[i];
          }
          else
          {
           ControllerInput.value = ControllerInput.value + "#" + ControllerArray[i];
          }
      
     }
	
	
	RefreshMapLayers(); // Added to auto-refresh map. AKA 20080521
}

//FUNCTION TO HANDLE BUTTON CLICK ON LAYERS ON/OFF
function RefreshMapLayers(){
;
	document.getElementById("EMVodamap_Command2").value=document.getElementById("EMVodamap_Command").value;
	document.getElementById("EMVodamap_Command").value="TEMP";
	document.getElementById("processing").style.display="block";//shows processing window
	var formToSend = document.getElementById("Form1");	        
    formToSend.submit();
}

//SPECIAL CLICK FUNCTION FOR TURNING EXCEPTION REPORT LAYERS ON OR OFF - i.e Community Services Exception
function SpecialClick(LyrID1,LyrID2,SpecialImageID){

    var objI,objI1,objI2,lstr,strb,stra,lpos;
    
    //image stuff
    objI=document.getElementById(SpecialImageID);
	objI1=document.getElementById("I" + LyrID1);
	objI2=document.getElementById("I" + LyrID2);
	var Itmp;
	Itmp = objI.src.split("/");
	
    //string positions FOR 1
	lstr= document.getElementById("EMVodaMap_LayerController").value;
	lpos = parseInt(LyrID1-1,10) + parseInt(LyrID1-1,10); //use i -1 cause the numbering we are using is related to the xml file, but the array is zero based and the xml is not

	//String before 1
	if (lpos==0){
		strb="";
	}
	else{
		strb=lstr.substring(0,lpos);
	}
	//string after
	if (lpos+1==lstr.length){
		stra="";
	}
	else{
		stra=lstr.substring(lpos+1,lstr.length);
	}

	if(Itmp[Itmp.length-1]=="tick_on.gif"){
		document.getElementById("EMVodaMap_LayerController").value = strb + "F" + stra;
	}
	else{
		document.getElementById("EMVodaMap_LayerController").value = strb + "T" + stra;
	}
	
	  //string positions FOR 2
	lstr= document.getElementById("EMVodaMap_LayerController").value;
	lpos = parseInt(LyrID2-1,10) + parseInt(LyrID2-1,10); //use i -1 cause the numbering we are using is related to the xml file, but the array is zero based and the xml is not

	//String before 1
	if (lpos==0){
		strb="";
	}
	else{
		strb=lstr.substring(0,lpos);
	}
	//string after
	if (lpos+1==lstr.length){
		stra="";
	}
	else{
		stra=lstr.substring(lpos+1,lstr.length);
	}

	if(Itmp[Itmp.length-1]=="tick_on.gif"){
		document.getElementById("EMVodaMap_LayerController").value = strb + "F" + stra;
	}
	else{
		document.getElementById("EMVodaMap_LayerController").value = strb + "T" + stra;
	}
	
	if(Itmp[Itmp.length-1]=="tick_on.gif"){
		objI.src="Images/tick.gif";
		objI1.src="Images/tick.gif";
		objI2.src="Images/tick.gif";
		document.getElementById("SOSHidden").value="false"
	}
	else{
		objI.src="Images/tick_on.gif"
		objI1.src="Images/tick_on.gif";
		objI2.src="Images/tick_on.gif";
		document.getElementById("SOSHidden").value="true"
	}
}
//Layers click function for custom data
function LayersCD(CDID){

    var iobj,itmp;
    iobj=document.getElementById("CD" + CDID);
    itmp = iobj.src.split("/");

    if(itmp[itmp.length-1]=="tick_on.gif"){
    //i.e. it is on, so switch off
		document.getElementById("hidMyData").value = document.getElementById("hidMyData").value.replace(CDID + ",","");
        iobj.src="Images/tick.gif";
	}
	else{
		document.getElementById("hidMyData").value = document.getElementById("hidMyData").value + CDID + ",";
        iobj.src="Images/tick_on.gif";
    }
    document.getElementById("EMVodaMap_Command2").value=document.getElementById("EMVodaMap_Command").value;
	document.getElementById("EMVodaMap_Command").value="TEMP";
	document.getElementById("processing").style.display="block";//shows processing window
	document.Form1.submit();
}

