function setDate(prefix){
	Y = document.getElementById(prefix+"_Y").value;
	M = document.getElementById(prefix+"_M").value;
	D = document.getElementById(prefix+"_D").value;
	if(Y != '' && M != '' && D != '')
		document.getElementById(prefix).value = Y+"-"+M+"-"+D;
}

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)
{
	//addElement("command", "viewVacancyPictures");
	//addElement("id", id);
	
	//var form = document.getElementById('mainForm');
	//form.action = "viewPictures.php";
	//form.submit();
	
	
	newwindow=window.open("viewPictures.php?vacancyId="+id,'pictureWindow' ,'height=400, width=700, resizable=1, scrollbars=1');
	if (window.focus) {newwindow.focus()}
	//return false;
}


function viewFloorplan(id)
{
	//addElement("command", "viewVacancyPictures");
	//addElement("id", id);
	
	//var form = document.getElementById('mainForm');
	//form.action = "viewPictures.php";
	//form.submit();
	
	
	newwindow=window.open("viewFloorplan.php?vacancyId="+id,'pictureWindow' ,'height=400, width=700, resizable=1, scrollbars=1');
	if (window.focus) {newwindow.focus()}
	//return false;
}


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 deleteWaitlisting(id)
{
	addElement("command", "deleteWaitlisting");
	addElement("id", id);
	
	var form = document.getElementById('mainForm');
	form.submit();
}


function sendEmail()
{
	addElement("command", "sendemail");
	
	var form = document.getElementById('mainForm');
	var sender_email = document.getElementById('sender');
	var message = document.getElementById('mainForm');
	var subject = document.getElementById('mainForm');
	
	
	form.action = "send_email_complete.php";
	form.submit();
}


function addToWaitingList()
{
	addElement("command", "add");
	
	var form = document.getElementById('mainForm');
	var phone = document.getElementById('phone');
	var email = document.getElementById('email');

	//alert(phone.value);
	//alert(email.value);

	form.submit();
}


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


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



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



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



