//ESRI Australia Template code for Redlining Functions.....
var draw_Pts=0;
var draw_Str="";

var draw_Points=new Array();
var draw_color=new Array();
var draw_size=new Array();

var pts=new Array();
var pts_color=new Array();
var pts_size=new Array();
var pts_type=new Array();
var pts_count=0;

var drawCount=0;
var linepoints=0;

var drawfirst=true;
var firstpoint="";

var drawing=false;
var LabelX=new Array();
var LabelY=new Array();
var LabelText=new Array();
var LabelColor=new Array();
var LabelSize=new Array();
var LabelCount=0;
var labeltex="";

var dimensioning=new Array(); 

function draw(e){
    if (isIE)	{
		document.all.theImage.style.cursor = "crosshair";
		theCursor = document.all.theImage.style.cursor;
	}
    document.all['drawshape'].strokecolor=currentcolor;
    document.all['drawshape'].strokeweight=currentsize;


	if(drawfirst){
		firstpoint=mouseX+","+mouseY;
		drawfirst=false;
	}
 
	draw_Pts++;
	if(draw_Pts==1){
	   draw_Str="m "+mouseX+","+mouseY;
	}
	if(draw_Pts>=2){
	  draw_Str=draw_Str+" l "+mouseX+","+mouseY;
	}

    draw_color[drawCount]=currentcolor;
	draw_size[drawCount]=currentsize;
	var theX=mouseX;
	var theY=mouseY;
    f71(theX,theY);  //
			  var u = Math.pow(10,1);
		      var uX = Math.round(mapX * u) / u;
              var uY = Math.round(mapY * u) / u;

	if(drawCount==-1) drawCount=0;
	if(linepoints==0){
		draw_Points[drawCount]=uX+","+uY;
    }else{
		var tt=draw_Points[drawCount];
		draw_Points[drawCount]=tt+";"+uX+","+uY; 
	}
	linepoints=linepoints+1;
	if(currentshape=="shape"){
		var t_Str=draw_Str+" l "+firstpoint+" e";
		showtempDraw(t_Str);
	}else{
		show_Draw_Path();
	}
}


function drawPoint(e){

    pts_color[pts_count]=currentcolor;
	pts_size[pts_count]=currentsize;
	pts_type[pts_count]=currenttype;
	var theX=mouseX;
	var theY=mouseY;
    f71(theX,theY);  //
	pts[pts_count]=mapX+","+mapY+"!!";
	pts_count+=1;
	//var theString=writeXML();
	//alert("pts="+pts);
	sendMapXML(); 
	//showRetrieveMap();
	//sendToServer(imsURL,theString,99); 
}

function showtempDraw(nn){
  document.all['drawshape'].path=nn;
}

function show_Draw_Path(){
  document.all['drawshape'].path=draw_Str+" e";
}
function clear_Draw_Path(){
  draw_Str="";
  draw_Pts=0;
  document.all['drawshape'].path=draw_Str+"m 0,0 e";
}	

/*function addCustomToMap5(){
	var theString="";
	if(drawCount>0){
	  theString+= '<LAYER type="acetate" id="1300" name="drawing">\n';
      for(var j=0;j<drawCount;j++){
		var ff=draw_Points[j].split(";");
		var pointsinline=ff.length;
		if(pointsinline>1){
           var firstcoord=ff[0].split(",");
           theString+='<OBJECT units="database">\n<LINE coords="' + forceComma(firstcoord[0])+coordsDelimiter+forceComma(firstcoord[1]);
           for(var i=1;i<pointsinline;i++){
			   var thecoord=ff[i].split(",");
			   theString+=pairsDelimiter+forceComma(thecoord[0])+coordsDelimiter+forceComma(thecoord[1]);
           }
		   theString+='" >\n';
		   theString+='<SIMPLELINESYMBOL type="solid" color="'+convertHexToDec(draw_color[j]);
		   theString+='" width="'+draw_size[j]+'" />\n</LINE>\n</OBJECT>\n';
        }
      }
	  theString+='</LAYER>\n';
    }
	return theString;
}  */

/*function addCustomToMap6(){
	var theString="";
	if(pts_count>0){
	    theString+= '<LAYER type="acetate" id="1301" name="drawing">\n';
		for (var i=0;i<pts_count;i++) {
			var ff=pts[i].split(",");
			theString += '<OBJECT units="acetate">\n<POINT coords="' + forceComma(ff[0]) + coordsDelimiter + forceComma(ff[1]) + '">\n';
			theString += '<SIMPLEMARKERSYMBOL  type="' + pts_type[i] + '"';
			theString += ' color="' + convertHexToDec(pts_color[i]) + '" width="' + pts_size[i] + '" />\n</POINT>\n</OBJECT>\n';
		}			
		theString += '</LAYER>\n';
    }
	return theString;
}  */


function adduserlab(e){
  var theX=mouseX;
  var theY=mouseY;
  f71(theX,theY);
  LabelX[LabelCount]=mapX;
  LabelY[LabelCount]=mapY;
 
//mar06 gsmith via ppunter
  LabelText[LabelCount]=fixlab(labeltex);
  //alert(currLabelColor);
  LabelColor[LabelCount]=currLabelColor;
  LabelSize[LabelCount]=currentsize;
  LabelCount=LabelCount+1;
  XMLMode=1;
  //alert("LabelText"+LabelText); 
  sendMapXML();
}

// 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;
	
}
