// S GIRVIN 10/2005

// get the layer object called "name"
function getLayer(name) {
	var theObj = document.getElementById(name);
	if (theObj!=null) {
		return theObj.style
	 }  else {
	    return(null);
	 }
}

// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "hidden";
}

// toggle layer to visible
function showLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "visible";
}

function startDigitising() {
	hideLayer('helpDiv');
	hideLayer('reportSearch');
	showLayer('digDiv');
	toggle(true);
	runScript('mapIF','init');
	var myDIV = getObject("mapIF","helpDiv");
	myDIV.innerHTML = "LEFT CLICK TO START DRAWING SITE AND RIGHT CLICK TO COMPLETE SITE BOUNDARY.";
}

function stopDigitising() {
	hideLayer('digDiv');
	hideLayer('reportSearch');
	showLayer('helpDiv');
	toggle(false);
	runScript('mapIF','deinit');
	var myDIV = getObject("mapIF","helpDiv");
	myDIV.innerHTML = "";
}

function startSearch() {
	stopDigitising();
	hideLayer('digDiv');
	hideLayer('helpDiv');
    showLayer('reportSearch');
}

function toggle(blDig){

	var myImg = getObject("mapIF","mapIMG");
	var myDIV = getObject("mapIF","placeHolder");

	if (blDig){
		myImg.style.zIndex  = 200;
		myImg.style.display  = "none";
		myDIV.style.zIndex  = 500;
		myDIV.style.display  = "inline";
	  }
	else {
		myImg.style.zIndex  = 500;
		myImg.style.display  = "inline";
		myDIV.style.zIndex  = 200;
		// myDIV.style.display  = "none";		
	  }
}

function setValues(){

	// sets the value of the hidden text boxes to the user
	// entered text, so the values are submitted by the map form
		
	var txtReportNo = getObject('sspsFormIF','reportNo');
	var txtReportPass = getObject('sspsFormIF','reportPass');

	var txtReportNoHidden = getObject('mapIF','reportNo');
	var txtReportPassHidden = getObject('mapIF','reportPass');
	
	txtReportNoHidden.value = txtReportNo.value;
	txtReportPassHidden.value = txtReportPass.value;
}

function submitForm(){
	var frmID = "mapIF";
	var id = "mapForm";
		
	var theForm = getObject(frmID, id);

	theForm.action = "genMap.aspx"; // this strips out the querystring
	if (confirm("Do you wish to create this Report ?")) {
		parent.Progress(true);
		setValues();
		theForm.submit(); 
		return true
    }
    else{
		return false
    }
}

function submitSearch(){
	var frmID = "mapIF";
	var id = "mapForm";
		
	var theForm = getObject(frmID, id);
	setValues();
	theForm.action = "genMap.aspx"; // this strips out the querystring
	theForm.submit(); 

}


function clearRoutine(){
	clearBoxes();
	runScript('mapIF','clearAll');
	runScript('legIF','setDisplay');
}

function clearBoxes(){
	document.getElementById("theMeasTotal").value = "";
	document.getElementById("theMeasSegment").value = "";
	document.getElementById("theCurrSegment").value = "";
	
	var lstBox = getObject("mapIF","lstCoords");
	lstBox.clear;
	var strCoords = getObject("mapIF","strCoords");
	strCoords.value = "";
}

function getHelpText(){
try {
	var txtArea = getObject('sspsFormIF','txtHelp');
	var txtHidden = getObject('mapIF','txtUserHelp');
	txtArea.value = txtHidden.value;
	}
	catch(ex){}
}

function enableDig(){
// enable / disable digitising based on hidden value in genmap.aspx
// also run when ssps loads, or option is null

try {
	var optDig = getObject('sspsFormIF','digitise');
	var optZoom = getObject('sspsFormIF','zoom');
	var optSearch = getObject('sspsFormIF','search');
	
	var optDigHidden = getObject('mapIF','digitise');
	optDig.disabled = optDigHidden.disabled;

	// ensure at least one option is selected
	
	if (optDig.checked == false && optSearch.checked == false) {
		optZoom.checked == true;
      }

	}	
	catch(ex){}
}