checkLocation();
 
var contentId = 40;
var currentGBookItem = 0;

/*---------------------------------------------
	Check url for correction. AJAX
---------------------------------------------*/ 
function checkLocation(){
	s = location.href;
      if (s.indexOf("http://www.rijschoolvandenwildenberg.nl") == -1) {
		location.href = "http://www.rijschoolvandenwildenberg.nl/";
	}
 }
 
 /*---------------------------------------------
	Test
---------------------------------------------*/ 
function showNextPage() {
	contentId++;
	alert(contentId);
	getContent();
 }

/*---------------------------------------------
	Create AJAX object
---------------------------------------------*/ 
function newXmlHttpObject() {
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();  }
	catch (e)
	{
		// Internet Explorer 
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			//This may still throw an exception (browser not supported).
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

/*---------------------------------------------
	Get content (main display)
---------------------------------------------*/
function getContent(contentId)
{

		var xmlHttp;
		try
		{
			xmlHttp = newXmlHttpObject();
		}
		catch (e)
		{
			alert("The browser is not supported!");
			return;
		}
		
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				//var data = ;
				//alert(xmlHttp.responseText);
				//s = xmlHttp.responseText;
				//s = "<h2>" + title + "</h2>" + xmlHttp.responseText;
				document.getElementById('text').innerHTML = xmlHttp.responseText + "<br><br>";
			}
		}


		if (contentId == 99 ) {
			xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/gbook.asp?action=showall&showlink=true&reactPage=reactie_toevoegen.asp&rpp=10&showNext=true", true);
			
		} else { 
			xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/content.asp?id=" + contentId + "&plain=true", true);
		}
		
		xmlHttp.send(null);
	
}

/*---------------------------------------------
	Increase statistics counter for subject 
---------------------------------------------*/
function addStatistics(subject)
{

		var xmlHttp;
		try
		{
			xmlHttp = newXmlHttpObject();
		}
		catch (e)
		{
			alert("The browser is not supported!");
			return;
		}
		
		xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/statistics.asp?action=add&name=" + subject, true);		
		xmlHttp.send(null);
}

/*---------------------------------------------
	Get random guestbook item (right display)
---------------------------------------------*/
function loadGBookItems(from) {

		currentGBookItem = from;
		var xmlHttp;
		try
		{
			xmlHttp = newXmlHttpObject();
		}
		catch (e)
		{
			alert("The browser is not supported!");
			return;
		}
		
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				document.getElementById('text').innerHTML = xmlHttp.responseText + "<br><br>";
			}
		}
			xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/gbook.asp?action=showall&showlink=true&reactPage=reactie_toevoegen.asp&rpp=10&showNext=true&from=" + from, true);
		xmlHttp.send(null);
	
}

/*---------------------------------------------
	Get picture item (left display)
---------------------------------------------*/
function getPictureContent(contentId) {
		var xmlHttp;
		try
		{
			xmlHttp = newXmlHttpObject();
		}
		catch (e)
		{
			alert("The browser is not supported!");
			return;
		}
		
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				//alert(xmlHttp.responseText);
				if (xmlHttp.responseText !="") {
					//44=index
					if (getContentId(id) != 44) {
						document.getElementById('text').style.width='500';
					} 
					//alert(xmlHttp.responseText);
					document.getElementById('imageHolder').style.visibility='visible';
					document.getElementById('imageHolder').innerHTML = "<div id=foto style='display:none;'><img src=http://www.rijschoolvandenwildenberg.nl/pictures/" + xmlHttp.responseText + " ></div>";					
					$('#foto').fadeIn(2800);
				} else {
					document.getElementById('imageHolder').style.visibility= 'hidden';
					document.getElementById('text').style.width='747';
				}
	
			}
		}
		
		xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/content.asp?id=" + contentId + "&plain=true&picture=true", true);
		xmlHttp.send(null);
	
}

/*---------------------------------------------
	Get random guestbook item (right display)
---------------------------------------------*/
function getGBookContent() {
		var xmlHttp;
		try
		{
			xmlHttp = newXmlHttpObject();
		}
		catch (e)
		{
			alert("The browser is not supported!");
			return;
		}
		
		xmlHttp.onreadystatechange = function()
		{
			if(xmlHttp.readyState == 4)
			{
				//document.getElementById('gbook').innerHTML = decodeURI(xmlHttp.responseText) + "<br><br>";
				document.getElementById('gbook').innerHTML = xmlHttp.responseText + "<br><br>";
				setTimeout("getGBookContent()",15000);
	
			}
		}
		
		xmlHttp.open("GET", "http://www.rijschoolvandenwildenberg.nl/db/gbook.asp?action=random", true);
		xmlHttp.send(null);
	
}

/**********************************************
	SITE FUNCTIONS
***********************************************/

function replaceAll(text, strA, strB) {
    return text.replace( new RegExp(strA,"g"), strB );    
}
  

/*---------------------------------------------
	Info form check
---------------------------------------------*/
function checkForm(frm) {
	
	if ((frm.name.value != "") 
		&& (frm.address.value != "")
		&& (frm.city.value != "")
		&& (frm.zip.value != "")
		&& (frm.phone.value != "")
		&& (frm.email.value != "")) {
	
		frm.submit();
	
	} else {
		
		document.getElementById('message').innerHTML = "<font color=red><small><b>Vul alle verplichte velden in.</b></small></font>";
		return false;
	}
}

/*---------------------------------------------
	Guestbook form check
---------------------------------------------*/
function checkGBookForm(frm) {
	
	if ((frm.name.value != "") 		
		&& (frm.description.value != "")
		&& (frm.email.value != "")) {
	
		frm.submit();
	
	} else {
		
		document.getElementById('message').innerHTML = "<font color=red><small><b>Vul alle verplichte velden in.</b></small></font>";
		return false;
	}
}
	
/*---------------------------------------------
	Info form Anders selection
---------------------------------------------*/	
function checkSelect(sel) {
	//alert(sel.options[sel.selectedIndex].value);
	if (sel.selectedIndex == 6) {
		document.getElementById('anders').style.visibility = "visible";
	} else {
		document.getElementById('anders').style.visibility = "hidden";
	}
}