/************************************************************************************
* ERBS - Erics Room Booking System                               
*************************************************************************************
* Copyright (C) 2007  Eric Lawson (http://www.ericsworld.eu)(eric4444@gmail.com)
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*************************************************************************************
* javastuff.js
*
* This file contains the java functions used in the script.
*************************************************************************************/

function checkdepart()
{
	if (document.login.dept.value < 1 )
	{
		alert("You must choose a department.");
		document.forms[0].dept.focus();return(false)
	}
}


function confirm_delete(siteurl,a,b)
{
	answer=confirm("All associated bookings will also be deleted. Click OK to Delete");
	if (answer==true)
	{
		window.location = siteurl + "/index.php?action=rem&id=" + a + "&data=" + b
	}
}

var xmlHttp

function ajax_book_period(wek,day,per,rom,uid,div,dpt)
{ 
	var url, x = new Array();
	var obj = document.getElementById(div);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
   
  	x[0] = "wek=" + parseInt(wek);
	x[1] = "day=" + parseInt(day);
	x[2] = "per=" + parseInt(per);
	x[3] = "rom=" + parseInt(rom);
	x[4] = "uid=" + parseInt(uid);
	x[5] = "div=" + parseInt(div);
	x[6] = "dpt=" + parseInt(dpt);
	
	url=siteurl + "/index.php?action=book&" + x.join("&");
	
	xmlHttp.open("GET", url);
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{
			obj.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.send(null);
}

function ajax_del_booking(wek,day,per,rom,bid,uid,div,dpt)
{ 
	var url, x = new Array();
	var obj = document.getElementById(div);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
   
  	x[0] = "wek=" + parseInt(wek);
	x[1] = "day=" + parseInt(day);
	x[2] = "per=" + parseInt(per);
	x[3] = "rom=" + parseInt(rom);
	x[4] = "bid=" + parseInt(bid);
	x[5] = "uid=" + parseInt(uid);
	x[6] = "div=" + parseInt(div);
	x[7] = "dpt=" + parseInt(dpt);
	
	url=siteurl + "/index.php?action=delbook&" + x.join("&");
	
	xmlHttp.open("GET", url);
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{
			obj.innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.send(null);
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
