function getSelection(name)
{
	var radios = document.getElementsByName(name);
	if (radios != null)
	{
		for (var i = 0; i < radios.length; i++)
		{
			var radio = radios[i];
			if (radio.checked) 
			{
				return radio.value;
			}
		}
	}
	return null;
}

function popup(url, windowWidth, windowHeight)
{
	if (window.showModalDialog)
	{
		window.showModalDialog(url, 
			window,
			"dialogWidth:"+windowWidth+"px; dialogHeight:"+windowHeight+"px; help: no; scroll:no; resizable:yes; center:yes; status: no; unadorned: yes; title: no");
	}
	else {

		var centerWidth = (window.screen.width - windowWidth) / 2;
		var centerHeight = (window.screen.height - windowHeight) / 2;

		var newWindow = window.open(url, 'popup', 'resizable=0,width=' + windowWidth + 
		',height=' + windowHeight + 
		',left=' + centerWidth + 
		',top=' + centerHeight);

		newWindow.focus();
	}
}

function export_report_popup(url, windowWidth, windowHeight)
{
	if (window.showModalDialog)
	{
		var returnvalue = window.showModalDialog(url, 
			window,
			"dialogWidth:"+windowWidth+"px; dialogHeight:"+windowHeight+"px; help: no; scroll:no; resizable:yes; center:yes; status: no; unadorned: yes; title: no");
		if(returnvalue!=null)
		{
			window.location.href=returnvalue;
		}
	}
	else {

		var centerWidth = (window.screen.width - windowWidth) / 2;
		var centerHeight = (window.screen.height - windowHeight) / 2;

		var newWindow = window.open(url, 'popup', 'resizable=0,width=' + windowWidth + 
		',height=' + windowHeight + 
		',left=' + centerWidth + 
		',top=' + centerHeight);

		newWindow.focus();
	}
}

function doDelete()
{
	var str = "";
	
	var ids = frames["dataframe"].ids;
	var doc = frames["dataframe"].document;
	
	for (var i = 0; i < ids.length; i++)
	{
		var cb = doc.getElementById("cb"+ids[i]);
		if (cb.checked)
		{
			str += ids[i] + ",";
		}
	}
	
	if (str == "")
	{
		alert("Please select items to delete.");
		return;
	}
	
	if (confirm("Are you sure you want to delete the select items?"))
	{
		var form = document.forms[0];	
		form.dowhat.value = "delete";
		form.ids.value = str;
		form.submit();
	}
}

function openGoogleDocs()
{
	window.open("http://docs.google.com", "Google", "height=900,width=1100", "toolbar=no");
}

function doAssignAssetsToUsers()
{
	var str = "";
	
	var ids = frames["dataframe"].ids;
	var doc = frames["dataframe"].document;
	
	for (var i = 0; i < ids.length; i++)
	{
		var cb = doc.getElementById("cb"+ids[i]);
		if (cb.checked)
		{
			str += ids[i] + ",";
		}
	}
	
	if (str == "")
	{
		alert("Please select assets to assign to users.");
		return;
	}
	
	var url = "assign_assets_to_users.html?ids="+str;
	popup(url, 550, 350);
}

function doAssignAssetToUsers(assignableKey)
{
	var url = "assign_assets_to_users.html?ids="+assignableKey;
	popup(url, 550, 350);
}

function launchGmap(address)
{
	
	if (address == null || address == "")
	{
		alert("The address has not be set yet.");
		return;
	}
	
	window.open("launchGmap.html?myaddress="+address, "", "height=600,width=820", "toolbar=no");
}


function doAssignAssetsToLocation()
{
	var str = "";
	
	var ids = frames["dataframe"].ids;
	var doc = frames["dataframe"].document;
	
	for (var i = 0; i < ids.length; i++)
	{
		var cb = doc.getElementById("cb"+ids[i]);
		if (cb.checked)
		{
			str += ids[i] + ",";
		}
	}
	
	if (str == "")
	{
		alert("Please select assets to assign to location.");
		return;
	}
	
	var url = "assign_assets_to_location.html?ids="+str;
	popup(url, 450, 250);
}

function doLogin()
{
	var form = document.forms[0];
	if (form.username.value == null || form.username.value == "")
	{
		alert("USERNAME is required.");
		return;
	}
	
	if (form.password.value == null || form.password.value == "")
	{
		alert("PASSWORD is required.");
		return;
	}
	
	form.submit();
}


function launchFloorPlan(key)
{
	window.open("launch_floor_plan.html?key="+key, "", "height=700,width=900", "toolbar=no");
}

function calculatePosition(id)
{
	 var img = document.getElementById("floorimg");
	 var floorimgPos = getPosition(img);

	 var dragable1 = document.getElementById(id);
	 var dragable1Pos = getPosition(dragable1);

	 var d1X = dragable1Pos.x - floorimgPos.x;
	 var d1Y = dragable1Pos.y - floorimgPos.y;

	return {x:d1X, y:d1Y};
}

function getPosition(e){
    var left = 0;
    var top  = 0;

    while (e.offsetParent){
	    left += e.offsetLeft;
	    top  += e.offsetTop;
	    e     = e.offsetParent;
    }


    left += e.offsetLeft;
    top  += e.offsetTop;

    return {x:left, y:top};

}

function exportReport(format)
{
	var str = "";
	
	var ids = frames["dataframe"].ids;
	var doc = frames["dataframe"].document;
	
	for (var i = 0; i < ids.length; i++)
	{
		var cb = doc.getElementById("cb"+ids[i]);
		if (cb.checked)
		{
			str += ids[i] + ",";
		}
	}
	
	if (str == "")
	{
		alert("Please select assets to export.");
		return;
	}
	
	var form = document.forms[0];	
//	form.action = "export.xml?"+
//		"name=PropertyReport&format="+format+
//		"&filter="+form.filter.value + "&contains=" + form.contains.value;

	form.action = "export.xml?name=PropertyReport&format="+format+"&ids="+str;

	form.submit();
}

function exportGReport()
{
	var str = "";
	
	var ids = frames["dataframe"].ids;
	var doc = frames["dataframe"].document;
	
	for (var i = 0; i < ids.length; i++)
	{
		var cb = doc.getElementById("cb"+ids[i]);
		if (cb.checked)
		{
			str += ids[i] + ",";
		}
	}
	
	if (str == "")
	{
		alert("Please select assets to export.");
		return;
	}
	
	var form = document.forms[0];	
	
//	var url = "export_greport.html?name=PropertyReport&filter="+form.filter.value + "&contains=" + form.contains.value

	var url = "export_greport.html?name=PropertyReport&ids="+str;
	
	export_report_popup(url, 550, 330);

}










