function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function setTitle(newTitle) {
	var currentTitle = document.getElementsByTagName("title")[0];
	if(currentTitle != null) {
		try
		{
			currentTitle.innerHTML = newTitle;	
		}
		catch (e) { }
	}
}

function initStylesheet() {
	var acceptedBrowser = true;
	var fileref = document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");

	if($.browser.mozilla) {
		fileref.setAttribute("href", "/style/browser-mozilla.css");
	} else if($.browser.msie) {
		fileref.setAttribute("href", "/style/browser-msie.css");
	} else {
		acceptedBrowser = false;
	}

	if(acceptedBrowser)
		document.getElementsByTagName("head")[0].appendChild(fileref);
}

function showLoader() {
	if($.browser.msie) {
		var loader = document.getElementById("content_loader");
		if(loader != null)
			loader.style.visibility = 'visible !important';
	}
}

function hideLoader() {
	var loader = document.getElementById("content_loader");
	var content = document.getElementById("content");
	if(loader != null) {
		loader.style.visibility = 'hidden';
		loader.style.display = 'none';
		content.style.visibility = 'visible';
	}
}

function focusSearchField() {
	var element = document.getElementById("searchfield");
	if(element != null)
		if(element.value == "vul een trefwoord in")
			element.select();
}
		
function routeBeschrijving(locatie) {
	var mapLink = "";
	var frametitle = "";
	if (locatie == "catharina") {
		mapLink = "http://maps.google.nl/maps?f=q&source=s_q&hl=nl&q=Slagveld+37,+3231+Brielle,+Zuid-Holland&sll=52.806082,4.257202&sspn=2.268059,4.938354&ie=UTF8&cd=3&geocode=FWABGAMda5k_AA&split=0&hq=&hnear=Slagveld+37,+3231+Brielle,+Zuid-Holland&ll=51.905228,4.167767&spn=0.018084,0.038581&z=15&iwloc=A&output=embed";
		frametitle = "Catharina Stichting";
	} else if (locatie == "leemgaarde") {
		mapLink = "http://maps.google.nl/maps?f=q&source=s_q&hl=nl&q=Patrijzenlaan+6,+3233+Oostvoorne,+Westvoorne,+Zuid-Holland&sll=51.875007,4.058461&sspn=0.018096,0.038581&ie=UTF8&cd=1&geocode=FfQcGAMdEX8-AA&split=0&hq=&hnear=Patrijzenlaan+6,+3233+Oostvoorne,+Westvoorne,+Zuid-Holland&ll=51.911926,4.095755&spn=0.018081,0.038581&z=15&output=embed";
		frametitle = "Leemgaarde";
	} else if (locatie == "swinshoek") {
		mapLink = "http://maps.google.nl/maps?f=q&source=s_q&hl=nl&geocode=&q=Vestalaan+1,+3235+Rockanje,+Westvoorne,+Zuid-Holland&sll=51.875007,4.056444&sspn=0.018096,0.038581&ie=UTF8&hq=&hnear=Vestalaan+1,+3235+Rockanje,+Westvoorne,+Zuid-Holland&ll=51.875007,4.058461&spn=0.018096,0.038581&z=15&output=embed";
		frametitle = "Swinshoek";
	} else if (locatie == "welzijn") {
		mapLink = "http://maps.google.nl/maps?f=q&source=s_q&hl=nl&q=Rozemarijnstraat+42,+3231+Brielle,+Zuid-Holland&sll=51.911926,4.095755&sspn=0.018081,0.038581&ie=UTF8&cd=2&geocode=FSH-FwMdGJQ_AA&split=0&hq=&hnear=Rozemarijnstraat+42,+3231+Brielle,+Zuid-Holland&ll=51.903772,4.166608&spn=0.018085,0.038581&z=15&output=embed";
		frametitle = "Welzijn Ouderen";
	}
	if(mapLink == "")
		return false;
	
	$.nyroModalManual({url: mapLink, title: frametitle, width: 650, height: 500});
}

function changeFontSize(size) {
	if(size != "small" && size != "normal" && size != "large")
		return false;
		
	// get elements
	var body = document.getElementsByTagName("body")[0];
	var fs_small = document.getElementById("fs-small");
	var fs_normal = document.getElementById("fs-normal");
	var fs_large = document.getElementById("fs-large");
	
	if(body != null && fs_small != null && fs_normal != null && fs_large != null) {
		// change active element to normal
		if(fs_small.getAttribute("rel") == "active") {
			fs_small.src = "/images/a_small.jpg";
			fs_small.removeAttribute("rel");
		}
		if(fs_normal.getAttribute("rel") == "active") {
			fs_normal.src = "/images/a_normal.jpg";
			fs_normal.removeAttribute("rel");
		}
		if(fs_large.getAttribute("rel") == "active") {
			fs_large.src = "/images/a_large.jpg";
			fs_large.removeAttribute("rel");
		}
		
		// change element of the given size to active
		eval("fs_" + size + ".src = \"/images/a_" + size + "_active.jpg\";");
		eval("fs_" + size + ".setAttribute(\"rel\", \"active\");");

		// set body class
		body.setAttribute("className", "fontsize-" + size);
		body.setAttribute("class", "fontsize-" + size);

		// set cookie
		createCookie("fontsize", size, 1);
	} else {
		return false;
	}
}

function initFontSize() {
	var cookievalue = readCookie("fontsize");
	if(cookievalue != null)
		changeFontSize(cookievalue);
	else
		changeFontSize("normal");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
} 

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
} 

function eraseCookie(name) {
	createCookie(name,"",-1);
}

