$current_page = '';

function CreateHTTPRequest()
{
	var xmlHttp;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	return xmlHttp;
}

function ShowCalendar(strObj)
{
	var cal = new calendar1(document.getElementById(strObj));
	cal.year_scroll = true;
	cal.time_comp = false;
	
	cal.popup();
}

function ShowLoadingBox()
{
	document.getElementById("loading_area").style.visibility = "visible";
	document.body.style.cursor = "wait";
}

function HideLoadingBox()
{
	document.getElementById("loading_area").style.visibility = "hidden";
	document.body.style.cursor = "default";
}

function loadContent(filename, arg, target)
{
	if(arg == null)
	{
		arg = "a=a";
	}
	
	ShowLoadingBox();
	
	var xmlHttp = CreateHTTPRequest();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var response_str = xmlHttp.responseText;
			
			if(xmlHttp.status == 200)
			{
				document.getElementById(target).innerHTML = response_str;
				
				HideLoadingBox();
			}
			else if(xmlHttp.status == 500)
			{
				alert("server side script error");
			}
		}
	}
	
	var parameters = arg;
	
	$current_page = filename;
	
	xmlHttp.open('POST', filename, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function SubmitBegin()
{
	ShowLoadingBox();
	return true;
}

function SubmitComplete(response)
{
	HideLoadingBox();
	
	document.getElementById("form_area").innerHTML = response;
}

function DisplayMenu()
{
	d = new dTree('d');
    
    

	d.add(0,-1,'Administration Panel');
	
	d.add(2,0,'Venue');
	d.add(3,2,'Add Venue',"javascript:loadContent('forms/clients_add_makes.php', null, 'form_area');");
    
    
	d.add(4,2,'View/Edit Venues',"javascript:loadContent('forms/clients_makes_list.php', null, 'form_area');");
	
	
	
	document.getElementById("menu_area").innerHTML = d;
}

function LoginBegin()
{
	ShowLoadingBox();
	return true;
}

function LoginComplete(response)
{
	HideLoadingBox();
	
	var response_arr = response.split("|");
	
	if(response_arr[0] == "1")
	{
		location.reload(true);
	}
	else
	{
		loadContent("forms/login.htm.php", 'msg=' + URLEncode(response_arr[1]), "form_area");
		document.getElementById("user_name").value = '';
		document.getElementById("password").value = '';
	}
}

function LogOut()
{
	var agree=confirm("Do you wish to Log Out?");
	if (agree)
	{
		var xmlHttp = CreateHTTPRequest();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var response_str = xmlHttp.responseText;
				
				if(xmlHttp.status == 200)
				{
					location.reload(true);
				}
				else if(xmlHttp.status == 500)
				{
					alert("server side script error");
				}
			}
		}
		
		var parameters = 'a=a';
		
		xmlHttp.open('POST', "actions/logout.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	}	
}

function DeleteMakes(makes_id)
{
	var agree=confirm("Do you wish to continue?");
	if (agree)
	{
		var xmlHttp = CreateHTTPRequest();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var response_str = xmlHttp.responseText;
				
				if(xmlHttp.status == 200)
				{
					document.getElementById('form_area').innerHTML = response_str;
				}
				else if(xmlHttp.status == 500)
				{
					alert("server side script error");
				}
			}
		}
		
		var parameters = 'makes_id=' + makes_id;
		
		xmlHttp.open('POST', "forms/delete_makes.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	}
}

function DeleteModel(model_id)
{
	var agree=confirm("Do you wish to continue?");
	if (agree)
	{
		var xmlHttp = CreateHTTPRequest();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var response_str = xmlHttp.responseText;
				
				if(xmlHttp.status == 200)
				{
					document.getElementById('form_area').innerHTML = response_str;
				}
				else if(xmlHttp.status == 500)
				{
					alert("server side script error");
				}
			}
		}
		
		var parameters = 'model_id=' + model_id;
		
		xmlHttp.open('POST', "forms/delete_models.php", true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	}
}


