



function submitSearch()
{
	sendCommand("search");
}


function sendCommand(command)
{
	addElement("command", command);
	
	var form = document.getElementById('mainForm');
	form.submit();
}

function deletePicture(id, picNum)
{
	addElement("command", "deletePicture");
	addElement("id", id);
	addElement("picNum", picNum);
	
	var form = document.getElementById('mainForm');
	form.action = "upload_pics.php";
	form.submit();
}



function viewVacancyPictures(id)
{
	newwindow=window.open("viewPictures.php?vacancyId="+id,'pictureWindow' ,'height=400, width=650, resizable=1, scrollbars=1');
	if (window.focus) {newwindow.focus()}
}

function uploadPictures(id)
{
	addElement("command", "uploadPictures");
	addElement("id", id);
	
	var form = document.getElementById('mainForm');
	form.action = "upload_pics.php";
	form.submit();
}


function gotoUploadPictures(id)
{
	addElement("command", "gotoUploadPictures");
	addElement("id", id);
	
	var form = document.getElementById('mainForm');
	form.action = "upload_pics.php";
	form.submit();
}



function addElement(name, value)
{
	var commandDiv = document.getElementById('commandDiv');
	var newElement = document.createElement('input');

	newElement.setAttribute('type', 'hidden');
	newElement.setAttribute('id', name);
	newElement.setAttribute('name', name);
	newElement.setAttribute('value', value);

	commandDiv.appendChild(newElement);
}




function editVacancyEntry(id)
{
	addElement("command", "editVacancyEntry");
	addElement("id", id);
	
	var form = document.getElementById('mainForm');
	form.submit();
}




function deleteVacancyEntry(id)
{
	addElement("command", "deleteVacancyEntry");
	addElement("id", id);
	
	var form = document.getElementById('mainForm');
	form.submit();
}

function getFields()
{ 
	return ["id", "property", "address", "city", "zipcode", "unit", 
				"unittype", "rent1year", "rent2year", "prefrent1year",
				"prefrent2year", "monthlycost", "costpersqft", "leasetype", "description", "contact", "captions"];
}

function addVacancy()
{
	var unittype = document.getElementById('edit_unittype');
	//alert("1:"+unittype);
	if (unittype.value=="error")
	{
		alert("Please select a unit type before submitting.");
	}
	else 
	{
		var fields = getFields();
		var i;
		var formElement;
		
		for(i = 0; i < fields.length; i++)
		{
			formElement = document.getElementById('edit_' + fields[i]);
			if(formElement!=undefined )
			{
				addElement(fields[i], formElement.value);
			}
		}
		
		addElement("command", "addVacancy");
		var form = document.getElementById('mainForm');
		form.submit();
	}
}



function submitVacancyChange(id)
{
	
	var unittype = document.getElementById('edit_unittype');

	if (unittype.value=="error")
	{
		alert("Please select a unit type before submitting.");
	}
	else 
	{
		var fields = getFields();
		var i;
		var formElement;
		
		for(i = 0; i < fields.length; i++)
		{
			formElement = document.getElementById('edit_' + fields[i]);
			if(formElement!=undefined )
			{
				addElement(fields[i], formElement.value);
				/*alert(formElement.name + " = "+formElement.value);*/
			}
		}
		
		addElement("command", "submitVacancyChange");
		addElement("id", id);
		var form = document.getElementById('mainForm');
		form.submit();
	}
}

function onTypeChange(formElement)
{
	if(formElement.value == "error")
	{
		document.getElementById('edit_monthlycost').disabled = true;
		document.getElementById('edit_costpersqft').disabled = true;	
		document.getElementById('edit_rent1year').disabled = true;
		document.getElementById('edit_rent2year').disabled = true;
		document.getElementById('edit_prefrent1year').disabled = true;
		document.getElementById('edit_prefrent2year').disabled = true;	
		
		document.getElementById('edit_monthlycost').style.borderColor = "#aaaaaa";
		document.getElementById('edit_costpersqft').style.borderColor = "#aaaaaa";
		document.getElementById('edit_rent1year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_rent2year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_prefrent1year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_prefrent2year').style.borderColor = "#aaaaaa";

		document.getElementById('edit_monthlycost').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_costpersqft').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_rent1year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_rent2year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_prefrent1year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_prefrent2year').style.backgroundColor = "#eeeeee";
	}
	else if(formElement.value != "commercial")
	{
		document.getElementById('edit_monthlycost').disabled = true;
		document.getElementById('edit_costpersqft').disabled = true;
		document.getElementById('edit_rent1year').disabled = false;
		document.getElementById('edit_rent2year').disabled = false;
		document.getElementById('edit_prefrent1year').disabled = false;
		document.getElementById('edit_prefrent2year').disabled = false;
		
		document.getElementById('edit_monthlycost').style.borderColor = "#aaaaaa";
		document.getElementById('edit_costpersqft').style.borderColor = "#aaaaaa";
		document.getElementById('edit_rent1year').style.borderColor = "#7FB5E5";
		document.getElementById('edit_rent2year').style.borderColor = "#7FB5E5";
		document.getElementById('edit_prefrent1year').style.borderColor = "#7FB5E5";
		document.getElementById('edit_prefrent2year').style.borderColor = "#7FB5E5";
		
		document.getElementById('edit_monthlycost').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_costpersqft').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_rent1year').style.backgroundColor = "#f2faff";
		document.getElementById('edit_rent2year').style.backgroundColor = "#f2faff";
		document.getElementById('edit_prefrent1year').style.backgroundColor = "#f2faff";
		document.getElementById('edit_prefrent2year').style.backgroundColor = "#f2faff";
	}
	else
	{
		document.getElementById('edit_monthlycost').disabled = false;
		document.getElementById('edit_costpersqft').disabled = false;
		document.getElementById('edit_rent1year').disabled = true;
		document.getElementById('edit_rent2year').disabled = true;
		document.getElementById('edit_prefrent1year').disabled = true;
		document.getElementById('edit_prefrent2year').disabled = true;
		
		document.getElementById('edit_monthlycost').style.borderColor = "#7FB5E5";
		document.getElementById('edit_costpersqft').style.borderColor = "#7FB5E5";
		document.getElementById('edit_rent1year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_rent2year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_prefrent1year').style.borderColor = "#aaaaaa";
		document.getElementById('edit_prefrent2year').style.borderColor = "#aaaaaa";
		
		document.getElementById('edit_monthlycost').style.backgroundColor = "#f2faff";
		document.getElementById('edit_costpersqft').style.backgroundColor = "#f2faff";
		document.getElementById('edit_rent1year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_rent2year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_prefrent1year').style.backgroundColor = "#eeeeee";
		document.getElementById('edit_prefrent2year').style.backgroundColor = "#eeeeee";
		
	}
	
	return true;
}

