//
// JAVASCRIPT.js
//
// Written by:		Daryl Stark
//					daryl@innonet.nl
//

var XMLHttpObject = null;
var LastMenuID = null;
var LastPageID = null;

function LoadPage (PageID, MenuID, ExtraVars)
{
	if (ExtraVars == undefined)
	{
		ExtraVars = '';
	}
	XMLHttpObject = CreateXMLHTTP ();
	if (XMLHttpObject)
	{
		var URL = 'ajax.php?ajax_action=Page&id=' + PageID + "&menu=" + MenuID + ExtraVars;
		LastMenuID = MenuID;
		LastPageID = PageID;
		XMLHttpObject.onreadystatechange = ShowSiteContent
		XMLHttpObject.open ("GET", URL, true);
		XMLHttpObject.send (null);
		return;
	}
	else
	{
		location.href = 'index.php?page=' + PageID + '&menu=' + MenuID + ExtraVars;
	}
}

function ShowSiteContent ()
{
	if (XMLHttpObject.readyState == 4 || XMLHttpObject.readyState == 'Complete')
	{
		document.getElementById('DivContentInner').innerHTML = XMLHttpObject.responseText;
		if (LastMenuID)
		{
			RequestMenuContent (LastPageID);
		}		
	}
}

function RequestPageTitle (PageID)
{
	var URL = 'ajax.php?ajax_action=PageTitle&id=' + PageID;
	XMLHttpObject = null;
	XMLHttpObject = CreateXMLHTTP ();
	if (XMLHttpObject)
	{
		XMLHttpObject.onreadystatechange = ChangePageTitle
		XMLHttpObject.open ("GET", URL, true);
		XMLHttpObject.send (null);
	}
}

function RequestMenuContent (PageID)
{
	var URL = 'ajax.php?ajax_action=SubMenu&id=' + LastMenuID + "&page_id=" + PageID;
	XMLHttpObject = null;
	XMLHttpObject = CreateXMLHTTP ();
	if (XMLHttpObject)
	{
		XMLHttpObject.onreadystatechange = ShowMenuContent
		XMLHttpObject.open ("GET", URL, true);
		XMLHttpObject.send (null);
	}
}

function RequestSearchContent (Redirect)
{
	var URL = 'ajax.php?ajax_action=Search&q=' + document.getElementById('SearchQ').value;
	XMLHttpObject = null;
	XMLHttpObject = CreateXMLHTTP ();
	if (XMLHttpObject)
	{
		XMLHttpObject.onreadystatechange = ShowSiteContent
		XMLHttpObject.open ("GET", URL, true);
		XMLHttpObject.send (null);
	}
	else
	{
		if (Redirect)
		{
			location.href = 'index.php?search=Search&q=' + document.getElementById('SearchQ').value;
		}
	}
}

function ChangePageTitle ()
{
	if (XMLHttpObject.readyState == 4 || XMLHttpObject.readyState == 'Complete')
	{
		document.title = XMLHttpObject.responseText;
	}
}

function ShowMenuContent ()
{
	if (XMLHttpObject.readyState == 4 || XMLHttpObject.readyState == 'Complete')
	{
		document.getElementById('DivSideBarText').innerHTML = XMLHttpObject.responseText;
		RequestPageTitle (LastPageID);
	}
}

function SubmitContactForm ()
{
	var TextName = document.getElementById('TextName').value;
	var TextCompanyName = document.getElementById('TextCompanyName').value;
	var TextAddress = document.getElementById('TextAddress').value;
	var TextZipCode = document.getElementById('TextZipCode').value;
	var TextCity = document.getElementById('TextCity').value;
	var TextPhoneNumber = document.getElementById('TextPhoneNumber').value;
	var TextFaxNumber = document.getElementById('TextFaxNumber').value;
	var TextEMail = document.getElementById('TextEMail').value;
	var CheckBoxWebdesign = document.getElementById('CheckBoxWebdesign').checked;
	var CheckBoxWebapplicaties = document.getElementById('CheckBoxWebapplicaties').checked;
	var CheckBoxWebhosting = document.getElementById('CheckBoxWebhosting').checked;
	var CheckBoxPromotie = document.getElementById('CheckBoxPromotie').checked;
	var CheckBoxBeheer = document.getElementById('CheckBoxBeheer').checked;
	var CheckBoxOverigen = document.getElementById('CheckBoxOverigen').checked;
	var TextMessage = document.getElementById('TextMessage').value;

	if (TextName && TextEMail && TextMessage)
	{
		var URL = 'ajax.php?real=1&amp;ajax_action=SubmitForm';
		XMLHttpObject = null;
		XMLHttpObject = CreateXMLHTTP ();
		if (XMLHttpObject)
		{
			var POSTVars = 'TextName=' + TextName + '&';
			POSTVars = POSTVars + 'TextCompanyName=' + TextCompanyName + '&';
			POSTVars = POSTVars + 'TextAddress=' + TextAddress + '&';
			POSTVars = POSTVars + 'TextZipCode=' + TextZipCode + '&';
			POSTVars = POSTVars + 'TextCity=' + TextCity + '&';
			POSTVars = POSTVars + 'TextPhoneNumber=' + TextPhoneNumber + '&';
			POSTVars = POSTVars + 'TextFaxNumber=' + TextFaxNumber + '&';
			POSTVars = POSTVars + 'TextEMail=' + TextEMail + '&';
			POSTVars = POSTVars + 'CheckBoxWebdesign=' + CheckBoxWebdesign + '&';
			POSTVars = POSTVars + 'CheckBoxWebapplicaties=' + CheckBoxWebapplicaties + '&';
			POSTVars = POSTVars + 'CheckBoxWebhosting=' + CheckBoxWebhosting + '&';
			POSTVars = POSTVars + 'CheckBoxPromotie=' + CheckBoxPromotie + '&';
			POSTVars = POSTVars + 'CheckBoxBeheer=' + CheckBoxBeheer + '&';
			POSTVars = POSTVars + 'CheckBoxOverigen=' + CheckBoxOverigen + '&';
			POSTVars = POSTVars + 'TextMessage=' + TextMessage;

			XMLHttpObject.onreadystatechange = ShowSiteContent
			XMLHttpObject.open ("POST", URL, true);
			XMLHttpObject.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			XMLHttpObject.send (POSTVars);
		}
		else
		{
			document.forms.FormContactForm.submit ();
		}
	}
	else
	{
		alert ('U heeft niet alle velden ingevuld. Probeer het opnieuw AUB');
	}
}

function SubmitSmallForm ()
{
	var TextName = document.getElementById('SmallName').value;
	var TextEMail = document.getElementById('SmallEMail').value;
	var TextMessage = document.getElementById('SmallMessage').value;
	var TextCode = document.getElementById('SmallCode').value;
	var ID = document.getElementById('SmallID').value;

	if (TextName && TextMessage)
	{
		var URL = 'ajax.php?real=1&amp;ajax_action=SubmitSmallForm';
		XMLHttpObject = null;
		XMLHttpObject = CreateXMLHTTP ();
		if (XMLHttpObject)
		{
			var POSTVars = 'Name=' + TextName + '&';
			POSTVars = POSTVars + 'EMail=' + TextEMail + '&';
			POSTVars = POSTVars + 'Message=' + TextMessage + '&';
			POSTVars = POSTVars + 'id=' + ID + '&';
			POSTVars = POSTVars + 'Code=' + TextCode;

			XMLHttpObject.onreadystatechange = ShowSiteContent
			XMLHttpObject.open ("POST", URL, true);
			XMLHttpObject.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			XMLHttpObject.send (POSTVars);
		}
		else
		{
			document.forms.SmallForm.submit ();
		}
	}
	else
	{
		alert ('U heeft niet alle velden ingevuld. Probeer het opnieuw AUB');
	}
}
