var textPosition = "text_";
var imgPosition = "img_";
var tmIdPosition = "tm_id_";

function moveUp(positions)
{
	var currentPosition = positions.toString();
	var positionUp = parseInt(positions) - 1;
	
	positionUp = positionUp.toString();
	
	var tempImgDown = document.getElementById(imgPosition + positionUp).src;
	var tempTextDown = document.getElementById(textPosition + positionUp).innerHTML;
	var tempTMDown = document.getElementById(tmIdPosition + positionUp).value;
	
	var tempImgUp = document.getElementById(imgPosition + currentPosition).src;
	var tempTextUp = document.getElementById(textPosition + currentPosition).innerHTML;
	var tempTMUp = document.getElementById(tmIdPosition + currentPosition).value;
	
	//Move planner item Up 1 Level
	document.getElementById(imgPosition + positionUp).src = tempImgUp;
	document.getElementById(textPosition + positionUp).innerHTML = tempTextUp;	
	document.getElementById(tmIdPosition + positionUp).value = tempTMUp;	
	
	//Move planner item Down 1 Level
	document.getElementById(imgPosition + currentPosition).src = tempImgDown;
	document.getElementById(textPosition + currentPosition).innerHTML = tempTextDown;
	document.getElementById(tmIdPosition + currentPosition).value = tempTMDown;
	
	locationPosition(positionUp, tempTMUp, currentPosition, tempTMDown);
}

function moveDown(positions)
{
	var currentPosition = positions.toString();
	var positionDown = parseInt(positions) + 1;
	
	positionDown = positionDown.toString();
	
	var tempImgUp = document.getElementById(imgPosition + positionDown).src;
	var tempTextUp = document.getElementById(textPosition + positionDown).innerHTML;
	var tempTMUp = document.getElementById(tmIdPosition + positionDown).value;
	
	var tempImgDown = document.getElementById(imgPosition + currentPosition).src;
	var tempTextDown = document.getElementById(textPosition + currentPosition).innerHTML;
	var tempTMDown = document.getElementById(tmIdPosition + currentPosition).value;
	
	//Move planner item Down 1 Level
	document.getElementById(imgPosition + positionDown).src = tempImgDown;
	document.getElementById(textPosition + positionDown).innerHTML = tempTextDown;
	document.getElementById(tmIdPosition + positionDown).value = tempTMDown;
	
	//Move planner item Up 1 Level
	document.getElementById(imgPosition + currentPosition).src = tempImgUp;
	document.getElementById(textPosition + currentPosition).innerHTML = tempTextUp;
	document.getElementById(tmIdPosition + currentPosition).value = tempTMUp;
	
	locationPosition(positionDown, tempTMDown, currentPosition, tempTMUp);
}

function  deletePosition(position)
{
	var totalPlanner = planner_count;
	var currentPosition = position;
	currentPosition.toString();	
		
	document.getElementById(imgPosition + currentPosition).src = "";
	document.getElementById(textPosition + currentPosition).innerHTML = "";
	var tm_id = document.getElementById(tmIdPosition + currentPosition).value;
		
	deleteLocation(tm_id);
		
	for(var i = 1; i <= totalPlanner; i++)
	{
		if(i > position)
		{
			var tempImgUp = document.getElementById(imgPosition + i).src;
			var tempTextUp = document.getElementById(textPosition + i).innerHTML;
			var tempTMUp = document.getElementById(tmIdPosition + i).value;
				
			document.getElementById(imgPosition + currentPosition).src = tempImgUp;
			document.getElementById(textPosition + currentPosition).innerHTML = tempTextUp;
			document.getElementById(tmIdPosition + currentPosition).value = tempTMUp;
				
			locationPosition(currentPosition, tempTMUp, 0, 0);
				
			if(i == (totalPlanner - 1))
			{	document.getElementById("down_button_" + i).style.display = "none";		}			
			
			currentPosition++;
		}
	}
		
	if((totalPlanner - 1) == 1)
	{
		document.getElementById("down_button_1").style.display = "none";
	}
		
	document.getElementById("place_holder_" + totalPlanner).style.display = "none";
	planner_count = (totalPlanner - 1);
		
	document.getElementById("delete_confirmation_" + position).style.visibility = "hidden";
		
	if(planner_count == 0)
	{
		var displayInfo = "<table width='100%' border='0' cellspacing='1' cellpadding='12' id='trip-planner'>";
			
		/*if(clientRegistered == 0)
		{
			displayInfo += "<tr><td bgcolor='#FFFFFF' id='trip_planner_message' colspan='2'><h2>Save your Trip Planner for the next time you visit! ";
			displayInfo += "<a href='javascript:void(0);' onClick='openDropDown(\"wrapper-login\");'>Click here to login or register.</a></h2></td></tr>";
		}*/
						
		displayInfo += "<tr><td bgcolor='#FFFFFF'><h2>You currently have no locations in your Trip Planner. </h2>";
		displayInfo += "Add locations from the map by clicking an icon and choosing &quot;Add to Trip Planner.&quot;<br><br>";
       	displayInfo += "<h2><b>Use the Trip Planner to save locations that interest you. </b></h2>";
       	displayInfo += "You can then arrange them in the order you'd like to visit. Share your plan with a friend or print it out and take it on the road.</td>";
    	displayInfo += "</tr></table>";
      		
		document.getElementById("dropdown-content").innerHTML = displayInfo;
		//document.getElementById("trip_planner_message").innerHTML = "";
	}
}

function openDeletePosition(position)
{
	document.getElementById("delete_confirmation_" + position).style.visibility = "visible";
}

function closeDeletePosition(position)
{
	document.getElementById("delete_confirmation_" + position).style.visibility = "hidden";
}