var OP   = (navigator.userAgent.indexOf("Opera") != -1);
var IE   = (navigator.userAgent.indexOf("MSIE") != -1) && !OP;

var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
    xmlhttp = false;
  }
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
  xmlhttp = new XMLHttpRequest();
}

function pageHit(){
  p = escape(document.location.href);
  rfr = escape(document.referrer);
  if (rfr == "undefined"){ rfr = "";}
  sx = screen.width;
  sy = screen.height;
  sc = (navigator.appName.indexOf("Microsoft") > -1) ? screen.colorDepth : screen.pixelDepth;
  src = 'stats.php?p=' + p + '&rfr=' + rfr + '&sx=' + sx + '&sy=' + sy + '&sc=' + sc;
  src = '<img style="position:absolute;left:-10px;top:-10px;" src="' + src + '" width="1" height="1" border="0" alt="" />';
  document.getElementById('counter').innerHTML = src;
}

function browserWidth(){
	if (document.all){
		return document.body.clientWidth;
	} else {
		return window.innerWidth;
	}
}

function docResize(){
	if (browserWidth() < 925){	
		document.getElementById('btmnav').style.padding = 0;
		document.getElementById('zoekform').style.left = '463px';
		document.getElementById('zoekform').style.width = '308px';
		document.getElementById('content').style.margin = '12px 0 0 0';
		document.getElementById('header').style.width = '770px';	
	} else {
		document.getElementById('btmnav').style.padding = '0 0 0 109px';
		document.getElementById('zoekform').style.left = '573px';
		document.getElementById('zoekform').style.width = '350px';
		document.getElementById('content').style.margin = '12px 0 0 110px';
		document.getElementById('header').style.width = '100%';
	}
}

function EmbedFlash(movie, id, flashvars, width, height) {

  html  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
  html += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
  html += ' id="' + id + '" width="' + width + '" height="' + height + '">';
  html += '<param name="movie" value="' + movie + '">';
  html += '<param name="bgcolor" value="#FFFFFF">';
  html += '<param name="quality" value="high">';
  html += '<param name="loop" value="false">';
  html += '<param name="flashvars" value="'+ flashvars + '">';
  html += '<param name="menu" value="false">';
  html += '<param name="wmode" value="transparent">';
  html += '<param name="allowscriptaccess" value="samedomain">';
  if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) {
    html += '<embed name="' + id + '" src="' + movie + '"';
    html += ' quality="high" bgcolor="#FFFFFF" menu="false" swLiveConnect="true" allowScriptAccess="sameDomain"';
    html += ' width="' + width + '" height="' + height + '" wmode="transparent"';
    html += ' type="application/x-shockwave-flash"';
    html += ' flashvars="' + flashvars + '"';
    html += ' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
  }
  html += '</object>';
  return html;
}

function setHeading1Size(id, lines, titel){
	var heading = document.getElementById(id);
	var i = id.replace('heading1', '');
	heading.innerHTML = EmbedFlash('flash/heading1.swf', 'flash' + i, 'id=heading1' + i + '&text=' + titel, 280, (22*lines));
}

function setHeading2Size(id, lines, titel){
	var heading = document.getElementById(id);
	var i = id.replace('heading2', '');
	heading.innerHTML = EmbedFlash('flash/heading2.swf', 'flash' + i, 'id=heading2' + i + '&text=' + titel, 390, (22*lines));
}


function set_bg_image(pageclass){

	var div = document.getElementById('bg_bg_image');
	
	if (pageclass == 'nieuws'){
		div.style.backgroundImage = "url('images/nieuws_bg_image.jpg')";
	}
	
	


}



function replaceHeadings(){



	var h1 = document.getElementsByTagName('h1');
	for (var i=0; i < h1.length; i++){
		h1[i].id = 'heading1' + i;
		h1[i].innerHTML = EmbedFlash('flash/heading1.swf', 'flash' + i, 'setHeight=true&id=heading1' + i + '&text=' + h1[i].innerHTML, 280, 22);
	}
	var h2 = document.getElementsByTagName('h2');
	for (var i=0; i < h2.length; i++){
		h2[i].id = 'heading2' + i;
		h2[i].innerHTML = EmbedFlash('flash/heading2.swf', 'flash' + i, 'setHeight=true&id=heading2' + i + '&text=' + h2[i].innerHTML, 390, 22);
	}
}

function nieuwsbriefSubmit(){
	if (document.getElementById('nieuwsbrief')){
		var nieuwsbrief = document.getElementById('nieuwsbrief');
		nieuwsbrief.onsubmit = function(){
			var naam  = document.getElementById('naam');
			var email = document.getElementById('email');
			var error = 0;
			if (naam.value == ''){
				document.getElementById('error_naam').innerHTML = '(verplicht)';
				naam.style.border = '1px solid #fe9003';
				naam.focus();
				error++;
			}
			if ((email.value.indexOf(".") < 2) || (email.value.indexOf("@") <= 0)){
				document.getElementById('error_email').innerHTML = '(verplicht)';				
				email.style.border = '1px solid #fe9003';
				if (error == 0){
					email.focus();
				}
				error++;
			}
 
 			if (error == 0){
 				document.getElementById('homenieuwsbrief').innerHTML = '<img src="images/loading.gif" />';
 				setTimeout("inschrijving('"+ naam.value +"', '"+ email.value +"')",600);
 			}		
		return false;
		}
	}
}

function inschrijving(naam, email){
	document.getElementById('homenieuwsbrief').innerHTML = '<p style="margin:20px">U bent ingeschreven op de nieuwsbrief!</p>';	
	var args  = '?naam=' + naam;
		args += '&email=' + email;
	
	xmlhttp.open("GET", 'nieuwsbrief' + args, true); //method, target, async (true)
  	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4){	    		
			var answerTxt = xmlhttp.responseText;
	    	if (answerTxt != ""){
	    		document.getElementById('homenieuwsbrief').innerHTML = '<p style="margin:20px">' + answerTxt + '</p>';	
			}
		}
	}
	xmlhttp.send(null);	
}


onload = function(){
	docResize();
	pageHit();
	nieuwsbriefSubmit();
}
onresize = docResize;

