// aimsCommon.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsMap.js
*/

aimsCommonPresent=true;


var legendImage="";
var modeBlurb = "Zoom In";

// delimiter to be used between coordinates in strings in ArcXML request
var coordsDelimiter = " ";
// delimiter to be used between pairs of coordinates in strings in ArcXML request
var pairsDelimiter = ";";

var chkUnits=false;
var legendTemp = false;
var ovIsVisible=false;

var showBuffer = false;

var chkGeocodeLayers = false;

var isArcMapService = false;

// character used by browser in decimals - either point or comma
var decimalChar = ((("theChar is" + (10/100)).indexOf("."))==-1) ? "," : ".";
//alert("Decimal character: " + decimalChar);

/*  *****************************************************
*	Various String manipulation Functions
*	*****************************************************
*/

function swapQuotes(inText) {
	inText = inText.replace(/"/g, "'");
	return inText;
}

// convert hexidecimal rgb number to delimited decimal rgb
function convertHexToDec(hexColor) {
	var pos = hexColor.indexOf(",");
	var decString = hexColor;
	if (pos==-1) {
		pos = hexColor.indexOf("#");
		if (pos!=-1) {
			hexColor = hexColor.substring((pos + 1),(pos + 7));
		}
		//alert(hexColor);
		var redHex = hexColor.substring(0,2);
		var greenHex = hexColor.substring(2,4);
		var blueHex = hexColor.substring(4,6);
		decString = parseInt(redHex,16) + "," + parseInt(greenHex,16) + "," + parseInt(blueHex,16);
		
	} 
	//alert(decString);
	return decString;
	
}



/*  *****************************************************
*	Various utility Functions
*	*****************************************************
*/

// replace single quotes with double single quotes
//	set up interior single qoutes and apostrophes for queries
function fixSingleQuotes(inputString) {
	var outString = inputString.replace(/'/g, "''");
	return outString;
}
// replace the five problem characters for the server's XML parser
function makeXMLsafe(oldString) {
	//alert(oldString);
	oldString = oldString.replace(/&/g, "&amp;");
	oldString = oldString.replace(/'/g, "&apos;");
	oldString = oldString.replace(/>/g, "&gt;");
	oldString = oldString.replace(/</g, "&lt;");
	oldString = oldString.replace(/"/g, "&quot;");
	/*
	oldString = swapStuff(oldString,"'","&apos;");
	oldString = swapStuff(oldString,">","&gt;");
	oldString = swapStuff(oldString,"<","&lt;");
	oldString = swapStuff(oldString,'"',"&quot;");
	*/
	//alert(oldString);
	return oldString;
}

// get the substring between beforeString and afterString, starting at startpos
// 		must be found before limitpos (0 for no limit) 
// 		caseSensitive = true or false
function getInsideString(inString,beforeString,afterString,startpos,limitpos,caseSensitive) {
	var returnString = "";
	var ucInString = inString;
	var ucBefore = beforeString;
	var ucAfter = afterString;
	if (limitpos==0) limitpos = inString.length;
	if (!caseSensitive) {
		ucInString = inString.toUpperCase();
		ucBefore = beforeString.toUpperCase();;
		ucAfter = afterString.toUpperCase();;
	}
	pos = ucInString.indexOf(ucBefore,startpos);
	//alert(startpos);
	if ((pos != -1) && (pos<limitpos)) {
		pos = pos + ucBefore.length;
		var endpos = ucInString.indexOf(ucAfter,pos);
		returnString = inString.substring(pos,endpos);
	}	
	
	return returnString;
}
