var xmlHttp = createXmlHttpRequestObject();
var allowedTitles = ["Welkom", "De uitvaart", "Verzekeringen", "Over ons", "Veel gestelde vragen", "Links", "Contact", "BUDGETuitvaart", "BUDGETbegrafenis", "BUDGETcrematie", "Depositofonds", "Documentatie", "Gedenktekens", "Nabestaandenzorg", "Tarieven", "Uitvaartcentrum", "Uitvaartfotografie", "Uitvaartkisten", "Wilsbeschikking", "Nieuwsarchief", "Sitemap", "Disclaimer", "Crematie in Maastricht", "De mogelijkheden", "De Cellebroederskapel", "Koffietafelmogelijkheden Cellebroederskapel", "Kasteel de Hoogenweerth", "Koffietafelmogelijkheden Hoogenweerth", "Kerkelijke Uitvaartdienst", "Thanatopraxie", "Dragen met stijl"];
var title = "";
var lightboxW = 0;

function loadPage(id) {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    window.location.hash = title = id;
    xmlHttp.open("GET", "includes/getcontent.php?title=" + id, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("loadPage('" + id + "')", 100);
  }
}
function handleServerResponse() {
  if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {
      newContent(xmlHttp.responseText);
    } else {
      alert("There was a problem accessing the server: "+xmlHttp.statusText);
    }
  }
}
function fixHeight() {
  var cH = $('content')["offsetHeight"];
  $('headlines')["style"]["height"] = (cH - 30) + "px";
  $('content-sidebar')["style"]["height"] = (cH - 115) + "px";
}
function newContent(content) {
  window.location.hash = title;
  document["title"] = "Sassen Uitvaartverzorging - " + title;
  $('content')["innerHTML"] = content;
  fixHeight();
  var i = $('content-image');
  if(title.indexOf("Zoek:") != -1) {
    i["src"] = "images/content-images/welkom.jpg";
    i["alt"] = i["title"] = "Zoek";
  } else if(title.indexOf("Nieuws:") != -1) {
    i["src"] = "images/content-images/welkom.jpg";
    i["alt"] = i["title"] = "Nieuws";
  } else if(title == "Nieuwsarchief") {
    i["src"] = "images/content-images/welkom.jpg";
    i["alt"] = i["title"] = "Nieuwsarchief";
  } else if(title == "Sitemap") {
    i["src"] = "images/content-images/welkom.jpg";
    i["alt"] = i["title"] = "Sitemap";
  } else if(title == "Disclaimer") {
    i["src"] = "images/content-images/welkom.jpg";
    i["alt"] = i["title"] = "Disclaimer";
  } else {
    i["src"] = "images/content-images/" + title.toLowerCase() + ".jpg";
    i["alt"] = i["title"] = title;
    
    if(title == 'De Cellebroederskapel' || title == 'Kasteel de Hoogenweerth') {
      /* Image 2 */
      $('content-image2').src = "images/content-images/" + title.toLowerCase() + "2.jpg";
      $('content-image2').alt = $('content-image2').title = title;
      $('content-image2').style.display = 'block';
      
      /* Image 3 */
      $('content-image3').src = "images/content-images/" + title.toLowerCase() + "3.jpg";
      $('content-image3').alt = $('content-image3').title = title;
      $('content-image3').style.display = 'block';
    } else {
      $('content-image2').style.display = 'none';
      $('content-image3').style.display = 'none';
    }
  }
}
function checkHash() {
  var hash = unescape(window.location.hash.replace("#", ""));
  $('flashmenu').SetVariable("menuItem", hash);
  if(hash == "") {
    window.location.hash = "Welkom";
  } else if(hash != title) {
    if(inArray(hash, allowedTitles)) {
      loadPage(hash);
    } else if(hash.indexOf("Zoek: ") != -1) {
      var search = hash.replace("Zoek: ", "");
      $('search')["value"] = search;
      title = "Zoek: " + search;
      getSearchResults(search);
    } else if(hash.indexOf("Nieuws: ") != -1) {
      var id = hash.replace("Nieuws: ", "");
      title = "Nieuws: " + id;
      getNews(id);
    }
  }
}

function doSearch() {
  var search = $('search')["value"];
  window.location.hash = title = "Zoek: " + search;
  getSearchResults(search);
}
function getSearchResults(search) {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    xmlHttp.open("GET", "includes/getcontent.php?search=" + escape(search), true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("getSearchResults('" + search + "')", 100);
  }
}
function getNews(id) {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    window.location.hash = title = "Nieuws: " + id;
    xmlHttp.open("GET", "includes/getcontent.php?newsid=" + id, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("getNews('" + id + "')", 100);
  }
}
function placeLightbox(swf, w, h) {
  lightboxW = w;
  document["body"].setAttribute("onresize", "positionLightbox();");
  document["body"].setAttribute("onscroll", "positionLightbox();");
  var overlay = document.createElement("div");
  overlay.setAttribute("id", "overlay");
  overlay.setAttribute("alt", "Klik om te sluiten");
  overlay.setAttribute("title", "Klik om te sluiten");
  overlay.setAttribute("onclick", "removeLightbox();");
  document.getElementsByTagName("body")[0].insertBefore(overlay, document.getElementsByTagName("body")[0]["firstChild"]);
  var dObj = document.createElement("div");
  dObj.setAttribute("id", "lightbox");
  dObj.setAttribute("style", "z-index:10000; width:100%; height:0; position:absolute; top:0; left:0; text-align:center; cursor:pointer; display:block;");
  dObj.setAttribute("alt", "Klik om te sluiten");
  dObj.setAttribute("title", "Klik om te sluiten");
  dObj.setAttribute("onclick", "removeLightbox();");  
  document.getElementsByTagName("body")[0].insertBefore(dObj, document.getElementsByTagName("body")[0]["firstChild"]);
  var sObj = document.createElement("img");
  sObj.setAttribute("id", "close_btn");
  sObj.setAttribute("style", "z-index:11000; width:25px; height:25px; position:absolute; top:0; left:0; cursor:pointer; display:block;");
  sObj.setAttribute("alt", "Klik om te sluiten");
  sObj.setAttribute("title", "Klik om te sluiten");
  sObj.setAttribute("onclick", "removeLightbox();");
  sObj.setAttribute("src", "images/close_btn.png");
  document.getElementsByTagName("body")[0].insertBefore(sObj, document.getElementsByTagName("body")[0]["firstChild"]);
  var so2 = new SWFObject("flash/" + swf, "flashoverlay", w, h, "8", "#000");
  so2.addParam("wmode", "transparent");
  so2.write("lightbox");
  positionLightbox();
  setTimeout("positionLightbox();", 100);
}
function positionLightbox() {
  var pSize = getPageSize();
  var obj = $('lightbox');
  if(obj) obj.setAttribute("style", "z-index:10000; width:100%; position:absolute; top:125px; left:0; text-align:center; cursor:pointer; display:block;");
  var overlay = $('overlay');
  if(overlay) {
    overlay.setAttribute("style", "z-index:9000; position:absolute; top:0; left:0; width:" + pSize[0] + "px; height:" + pSize[1] + "px; background:#000; display:block; cursor:pointer;");  
    var opacity = 70;
  	overlay["style"]["opacity"] = (opacity / 100);
    overlay["style"]["MozOpacity"] = (opacity / 100);
    overlay["style"]["KhtmlOpacity"] = (opacity / 100);
    overlay["style"]["filter"] = "alpha(opacity=" + opacity + ")";
  }
  var sObj = $('close_btn');
  var offsetLeft = ((pSize[0] / 2) + (lightboxW / 2)) - 20;
  if(sObj) sObj.setAttribute("style", "z-index:11000; width:25px; height:25px; position:absolute; top:120px; left:" + offsetLeft + "px; cursor:pointer; display:block;");
}
function removeLightbox() {
  removeObjectById('lightbox');
  removeObjectById('overlay');
  removeObjectById('close_btn');
  document["body"].removeAttribute("onresize");
  document["body"].removeAttribute("onscroll");
}
function unfold(id) {
  for(var i = 1; i <= 8; i++) {
    var obj = $('faq' + i);
    if(obj) {
      obj["style"]["display"] = "none";
    }
  }
  var obj = $('faq' + id);
  if(obj) {
    obj["style"]["display"] = "block";
  }
  fixHeight();
}
function documentatieSubmit() {
  var ok = true;
  $('naam')["className"] = "";
  if($('naam')["value"] == "") {
    $('naam')["className"] = "red";
    ok = false;
  }
  $('adres')["className"] = "";
  if($('adres')["value"] == "") {
    $('adres')["className"] = "red";
    ok = false;
  }
  $('postcode')["className"] = "";
  if($('postcode')["value"] == "") {
    $('postcode')["className"] = "red";
    ok = false;
  }
  $('plaats')["className"] = "";
  if($('plaats')["value"] == "") {
    $('plaats')["className"] = "red";
    ok = false;
  }
  $('telefoon')["className"] = "";
  if($('telefoon')["value"] == "") {
    $('telefoon')["className"] = "red";
    ok = false;
  }
  $('email')["className"] = "";
  if($('email')["value"] == "") {
    $('email')["className"] = "red";
    ok = false;
  }
  var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  if(!filter.test($("email")["value"])) {
    $('email')["className"] = "red";
    ok = false;
  }
  if(ok) {
    sendDocumentatie();
  }
}

function sendDocumentatie() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    var data = $('gedrukt')["checked"] + ";" + $('begeleiding')["checked"] + ";" + $('advies')["checked"] + ";" + $('naam')["value"] + ";" + $('adres')["value"] + ";" + $('postcode')["value"] + ";" + $('plaats')["value"] + ";" + $('telefoon')["value"] + ";" + $('fax')["value"] + ";" + $('email')["value"];
    xmlHttp.open("GET", "includes/getcontent.php?sendDocumentatie=" + unescape(data), true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("sendDocumentatie()", 100);
  }
}

function openWilsbeschikking() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    xmlHttp.open("GET", "includes/getcontent.php?wilsbeschikking=1", true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("openWilsbeschikking()", 100);
  }
}
function openWilsbeschikking2() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    var data = "";
    if($('naam') != undefined) {
      data = $('naam')["value"] + ";" + $('voornamen')["value"] + ";" + $('adres')["value"] + ";" + $('postcode')["value"] + ";" + $('woonplaats')["value"] + ";" + $('telefoon')["value"] + ";" + $('email')["value"] + ";" + $('geboorteplaats')["value"] + ";" + $('geboortedatum')["value"];
      data = "&data=" + unescape(data);
    }
    xmlHttp.open("GET", "includes/getcontent.php?wilsbeschikking=2" + data, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("openWilsbeschikking2()", 100);
  }
}
function openWilsbeschikking3() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    var data = "";
    if($('opbaren') != undefined) {
      data = $('opbaren')["value"] + ";" + $('afscheidnemen')["value"] + ";" + $('locatie')["value"] + ";" + $('asbestemming')["value"] + ";" + $('locatieasbestemming')["value"] + ";" + $('kerkdienst')["value"] + ";" + $('avonddienst')["value"] + ";" + $('uitvaart')["value"] + ";" + $('volgwagens')["value"] + ";" + $('koffietafel')["value"] + ";" + $('locatiekoffietafel')["value"] + ";" + $('aantalkoffietafel')["value"];
      data = "&data=" + unescape(data);
    }      
    xmlHttp.open("GET", "includes/getcontent.php?wilsbeschikking=3" + data, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("openWilsbeschikking3()", 100);
  }
}
function openWilsbeschikking4() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    var data = "";
    if($('rouwcirculaires') != undefined) {
      data = $('rouwcirculaires')["value"] + ";" + $('aantalrouwcirculaires')["value"] + ";" + $('gedachtenisprentjes')["value"] + ";" + $('aantalgedachtenisprentjes')["value"] + ";" + $('fotogedachtenisprentjes')["value"] + ";" + $('overlijdensannonce')["value"] + ";" + $('overlijdensannoncekrant')["value"] + ";" + $('dankbetuigingen')["value"] + ";" + $('aantaldankbetuigingen')["value"] + ";" + $('aantalaktevanoverlijden')["value"] + ";" + $('bloemen')["value"] + ";" + $('soortbloemen')["value"] + ";" + $('bloemenlint')["value"] + ";" + $('kist')["value"];
      data = "&data=" + unescape(data);
    }      
    xmlHttp.open("GET", "includes/getcontent.php?wilsbeschikking=4" + data, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("openWilsbeschikking4()", 100);
  }
}

function sendWilsbeschikking() {
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
    var data = "";
    if($('besprnaam') != undefined) {
      data = $('besprnaam')["value"] + ";" + $('bespradres')["value"] + ";" + $('besprpostcode')["value"] + ";" + $('besprtelefoon')["value"] + ";" + $('overlijdensverzekeringen')["value"] + ";" + $('polis')["value"] + ";" + $('testament')["value"] + ";" + $('notariaat')["value"] + ";" + $('extest')["value"] + ";" + $('vrijblijvendekostenopgave')["value"];
      data = "&data=" + unescape(data);
    }      
    xmlHttp.open("GET", "includes/getcontent.php?wilsbeschikking=5" + data, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  } else {
    setTimeout("sendWilsbeschikking()", 100);
  }
}
///////////////////////////////////////////////////////////

function doubleCheckDel(url) {
  var a = confirm("Weet je zeker dat je dit item wilt verwijderen?");
	if(a) {
	  document.location = url;
	}
}
function getPageSize() {
  var xScroll, yScroll, windowWidth, windowHeight, scrOfX, scrOfY = 0;
	
  if(typeof(window["pageYOffset"]) == 'number') { //Netscape compliant
    scrOfY = window["pageYOffset"];
    scrOfX = window["pageXOffset"];
  } else if(document["body"] && (document["body"]["scrollLeft"] || document["body"]["scrollTop"])) { //DOM compliant
    scrOfY = document["body"]["scrollTop"];
    scrOfX = document["body"]["scrollLeft"];
  } else if(document["documentElement"] && (document["documentElement"]["scrollLeft"] || document["documentElement"]["scrollTop"])) { //IE6 standards compliant mode
    scrOfY = document["documentElement"]["scrollTop"];
    scrOfX = document["documentElement"]["scrollLeft"];
  }

	if(window["innerHeight"] && window["scrollMaxY"]) {	
		xScroll = window["innerWidth"] + window["scrollMaxX"];
		yScroll = window["innerHeight"] + window["scrollMaxY"];
	} else if(document["body"]["scrollHeight"] > document["body"]["offsetHeight"]){ // all but Explorer Mac
		xScroll = document["body"]["scrollWidth"];
		yScroll = document["body"]["scrollHeight"];
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document["body"]["offsetWidth"];
		yScroll = document["body"]["offsetHeight"];
	}
		
	if(self["innerHeight"]) {	// all except Explorer
		if(document["documentElement"]["clientWidth"]){
			windowWidth = document["documentElement"]["clientWidth"]; 
		} else {
			windowWidth = self["innerWidth"];
		}
		windowHeight = self["innerHeight"];
	} else if(document["documentElement"] && document["documentElement"]["clientHeight"]) { // Explorer 6 Strict Mode
		windowWidth = document["documentElement"]["clientWidth"];
		windowHeight = document["documentElement"]["clientHeight"];
	} else if(document["body"]) { // other Explorers
		windowWidth = document["body"]["clientWidth"];
		windowHeight = document["body"]["clientHeight"];
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth, pageHeight, windowHeight, scrOfY];
}
function removeObjectById(id) {
  var obj = $(id);
  if(obj != undefined) obj["parentNode"].removeChild(obj);
}
function inArray(v, a) {
  for(var i in a) {
    if(a[i] == v) return true;
  }
  return false;
}
function createXmlHttpRequestObject() {
  var xmlHttp;
  if(window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      xmlHttp = false;
    }
  } else {
    try {
      xmlHttp = new XMLHttpRequest();
    } catch(e) {
      xmlHttp = false;
    }
  }
  if(!xmlHttp) {
    alert("Error creating the XMLHttpRequest object.");
  } else {
    return xmlHttp;
  }
}
function $(id) {
  return document.getElementById(id);
}
