function CreateProject(map, tblDataID)
{
	var me = this;
	me._map = map;	
	me._tblData = document.getElementById(tblDataID).tBodies[0];
	
	me._colIdxNum = 0;
	me._colIdxType = 1;
	me._colIdxIConeID = 2;
	me._colIdxLat = 3;
	me._colIdxLng = 4;
	me._colIdxDel = 5;
	me._colIdxMove = 6;
	
	var icon = new GIcon();
	icon.image = 'images/reddot.png';
	icon.iconSize = new GSize(20, 20);
	icon.iconAnchor = new GPoint(10, 10);
	me._markerOpts = {
		"icon": icon,
		"clickable": false,
		"draggable": false,
		"labelText": "",
		"labelOffset": new GSize(-10,-10)
		//,"zIndexProcess": function(marker,b){return icones._numCones;}
	};
	
	if(me._map!=null){
		me._clickListener = GEvent.bind(me._map, "click", me, function(overlay, latLng, overlayLatLng){
			var iConeID;
			var lat;
			var lng;
			if(latLng!=null){
				lat = latLng.lat().toFixed(5);
				lng = latLng.lng().toFixed(5);
			} else if(overlay!=null){
				iConeID=overlay.id.substring(2);
				lat = overlay.getPoint().lat().toFixed(5);
				lng = overlay.getPoint().lng().toFixed(5);
			}
			
			me.addRow(iConeID, lat, lng);
		});
	}
	
	icones.stopClickListeners();
}


CreateProject.prototype.addRow = function(id, lat, lng)
{
	var newRowID = this._tblData.rows.length;
	var row = this._tblData.insertRow(newRowID);
	
	if(lat!=null && lat!="" && lng!=null && lng!=""){
		var opts = this._markerOpts;
		opts.labelText = newRowID+1;
		row._marker = new LabeledMarker(new GLatLng(lat,lng), opts);
		this._map.addOverlay(row._marker);
	}
	
	//Populate each cell's values for this row.
	this._buildRowNum(row,newRowID);
	this._buildRowType(row,newRowID);
	this._buildRowIConeID(row,newRowID,id);
	this._buildRowLat(row,newRowID,lat);
	this._buildRowLng(row,newRowID,lng);
	this._buildRowDelete(row,newRowID);
	this._buildRowMove(row,newRowID);
}
CreateProject.prototype.deleteRow = function(rowNum)
{
	var numRows = this._tblData.rows.length;
	//move the values for the row to delete to the last row.
	for(var i=rowNum; i<numRows; i++){
		this.swapRows(i,i+1);
	}
	
	//remove the marker from the map
	this._map.removeOverlay(this._tblData.rows[numRows-1]._marker);
	//delete the row
	this._tblData.deleteRow(numRows-1);
}
CreateProject.prototype.swapRows = function(idxRowA, idxRowB)
{
	var rowA = this._tblData.rows[idxRowA];
	var rowB = this._tblData.rows[idxRowB];
	
	//if both rows exist swap their values.
	if(rowA!=null && rowB!=null){
		var tempVal;
		var tempVal2
		
		//swap the iConeIDs
		tempVal = rowA.cells[this._colIdxIConeID].innerHTML;
		rowA.cells[this._colIdxIConeID].innerHTML = rowB.cells[this._colIdxIConeID].innerHTML;
		rowB.cells[this._colIdxIConeID].innerHTML = tempVal;
		
		//swap the Latitude
		tempVal = rowA.cells[this._colIdxLat].innerHTML;
		rowA.cells[this._colIdxLat].innerHTML = rowB.cells[this._colIdxLat].innerHTML;
		rowB.cells[this._colIdxLat].innerHTML = tempVal;
		
		//swap the Longitudes
		tempVal = rowA.cells[this._colIdxLng].innerHTML;
		rowA.cells[this._colIdxLng].innerHTML = rowB.cells[this._colIdxLng].innerHTML;
		rowB.cells[this._colIdxLng].innerHTML = tempVal;
		
		//swap the associated markers
		tempVal = rowA._marker;
		tempVal2 = rowA._marker.labelText;
		rowA._marker.changeLabel(rowB._marker.labelText);
		rowA._marker = rowB._marker;
		rowB._marker.changeLabel(tempVal2);
		rowB._marker = tempVal;
	}
}
CreateProject.prototype.submit = function()
{
	var txt="";
	var numRows = this._tblData.rows.length;
	for(var i=0; i<numRows; i++){
		//Add the Location delimiter, if needed.
		if(txt!=null && txt!=""){
			txt+="|";
		}
		
		//set the type for this Location.
		var typeRBs = this._tblData.rows[i].cells[this._colIdxType].childNodes;
		for(var j=0; j<typeRBs.length; j++){
			if(typeRBs[j].checked){
				txt+=typeRBs[j].value;
			}
		}
		txt+="|";
		
		//set the latitude for this Location.
		txt+= this._tblData.rows[i].cells[this._colIdxLat].innerHTML;
		txt+="|";
		
		//set the longitude for this Location.
		txt+= this._tblData.rows[i].cells[this._colIdxLng].innerHTML;
	}
	
	var link = "createProject.aspx?";
	link += "projName="+document.getElementById("projName").value+"&";
	link += "projDesc="+document.getElementById("projDesc").value+"&";
	link += "projSTime="+document.getElementById("projSTime").value+"&";
	link += "projETime="+document.getElementById("projETime").value+"&";
	link += "tzOffset="+((new Date()).getTimezoneOffset()/-60)+"&";
	link += "locStr="+txt;
	
	popup(link, "settings", 10, 10, "no", "false");

	setTimeout("icones.refreshCones();",500);
	
	this.kill();	
}
CreateProject.prototype.kill = function()
{
	var numRows = this._tblData.rows.length;
	for(var i=0; i<numRows; i++){
		//delete this row
		this.deleteRow(0);
	}
	
	//turn off the click listener.
	GEvent.removeListener(this._clickListener);
	
	//resize and close the left bar
	icones.loadLeftData(null,200);
	icones.startClickListeners();
	manageLeftBar.onclick();
}


/*
 * Private Helper Functions for the Create Project Object.
 */
CreateProject.prototype._buildRowNum = function(row, rowNum)
{
	if(row.cells.length < this._colIdxNum+1) row.insertCell(this._colIdxNum);
	row.cells[this._colIdxNum].innerHTML = rowNum+1;
}

CreateProject.prototype._buildRowType = function(row, rowNum)
{
	if(row.cells.length < this._colIdxType+1) row.insertCell(this._colIdxType);
	
	var rbQ = document.createElement("input");
	rbQ.setAttribute("type", "radio");
	rbQ.setAttribute("id", "typeQ"+rowNum);
	rbQ.setAttribute("name", "type"+rowNum);
	rbQ.setAttribute("value", "queue");
	
	var rbT = document.createElement("input");
	rbT.setAttribute("type", "radio");
	rbT.setAttribute("id", "typeT"+rowNum);
	rbT.setAttribute("name", "type"+rowNum);
	rbT.setAttribute("value", "taper");
	
	var rbW = document.createElement("input");
	rbW.setAttribute("type", "radio");
	rbW.setAttribute("id", "typeW"+rowNum);
	rbW.setAttribute("name", "type"+rowNum);
	rbW.setAttribute("value", "");
	rbW.setAttribute("checked", "checked");
	
	row.cells[this._colIdxType].appendChild(rbQ);
	row.cells[this._colIdxType].appendChild(rbT);
	row.cells[this._colIdxType].appendChild(rbW);
}

CreateProject.prototype._buildRowIConeID = function(row,rowNum,iConeID)
{
	if(row.cells.length < this._colIdxIConeID+1) row.insertCell(this._colIdxIConeID);
	
	if(iConeID!=null)
		row.cells[this._colIdxIConeID].innerHTML = iConeID;
}

CreateProject.prototype._buildRowLat = function(row,rowNum,lat)
{
	if(row.cells.length < this._colIdxLat+1) row.insertCell(this._colIdxLat);
	
	if(lat!=null)
		row.cells[this._colIdxLat].innerHTML = lat;
}

CreateProject.prototype._buildRowLng = function(row,rowNum,lng)
{
	if(row.cells.length < this._colIdxLng+1) row.insertCell(this._colIdxLng);
	
	if(lng!=null)
		row.cells[this._colIdxLng].innerHTML = lng;
}

CreateProject.prototype._buildRowDelete = function(row,rowNum)
{
	var me = this;
	if(row.cells.length < me._colIdxDel+1) row.insertCell(me._colIdxDel);
	
	var delBtn = document.createElement("input");
	delBtn.setAttribute("type", "button");
	delBtn.setAttribute("id", "del"+rowNum);
	delBtn.setAttribute("name", "del"+rowNum);
	delBtn.setAttribute("value", "X");
	delBtn.onclick = function() {me.deleteRow(rowNum);};
	
	row.cells[me._colIdxDel].appendChild(delBtn);
}

CreateProject.prototype._buildRowMove = function(row,rowNum)
{
	var me = this;
	if(row.cells.length < me._colIdxMove+1) row.insertCell(me._colIdxMove);
	
	var upBtn = document.createElement("input");
	upBtn.setAttribute("type", "button");
	upBtn.setAttribute("id", "up"+rowNum);
	upBtn.setAttribute("name", "up"+rowNum);
	upBtn.setAttribute("value", "^");
	upBtn.onclick = function() {me.swapRows(rowNum-1,rowNum);};
	
	var dnBtn = document.createElement("input");
	dnBtn.setAttribute("type", "button");
	dnBtn.setAttribute("id", "dn"+rowNum);
	dnBtn.setAttribute("name", "dn"+rowNum);
	dnBtn.setAttribute("value", "v");
	dnBtn.onclick = function() {me.swapRows(rowNum,rowNum+1);};
	
	row.cells[me._colIdxMove].appendChild(upBtn);
	row.cells[me._colIdxMove].appendChild(dnBtn);
}
