
browser = {
    'isFF' : (navigator.userAgent.indexOf("Firefox") > -1),
    'isIE' : (navigator.userAgent.indexOf("MSIE") > -1),
    'isIE6': (navigator.userAgent.indexOf("MSIE 6") > -1),
    'isIE7': (navigator.userAgent.indexOf("MSIE 7") > -1),
    'isOpera' : (navigator.userAgent.indexOf("Opera") > -1),
    'isSafari': (navigator.userAgent.indexOf("Safari") > -1)
}

function WM_setCookie (name, value, hours, path, domain, secure) {
   
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.  
}
 
function getWindowWidth() 
{
  	var myWidth = 0;
  	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;

  	} else if( document.documentElement && document.documentElement.clientWidth  ) {
    	//IE 6+ in 'standards compliant mode'
    	myWidth = document.documentElement.clientWidth;

  	} else if( document.body &&  document.body.clientWidth   ) {
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
 	}

	return  myWidth;
}

function getWindowHeight() 
{
  	var myHeight = 0;
  	if( typeof( window.innerHeight ) == 'number' ) {
    	//Non-IE
    	myHeight = window.innerHeight;
  	} else if( document.documentElement && document.documentElement.clientHeight  ) {
    	//IE 6+ in 'standards compliant mode'
    	myHeight = document.documentElement.clientHeight;
  	} else if( document.body && document.body.clientHeight  ) {
    	//IE 4 compatible
    	myHeight = document.body.clientHeight;
 	}

	return  myHeight;
}

function getY( elementId )
{
	oElement = document.getElementById(elementId);
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( elementId )
{
	oElement = document.getElementById(elementId);
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function scrollContentTo( elementId )
{	
	if(browser.isIE) { currentPos = document.body.scrollTop; } else { currentPos = window.pageYOffset; }

	var newPos = getY(elementId);
	var posDif = newPos - currentPos;	
	var scrollPos = currentPos;
	
	for(i = 0; i < 10; i++)
	{
		scrollPos = scrollPos + posDif/10;
		window.scrollTo(0,scrollPos);
	}
}


function bookmarksite(title,url)
{
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

function go(url)
{
   if (document.images)
        location.replace(url);
    else
        location.href = url;
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function isPostcode(str) {
	var r1 = new RegExp("^[0-9]{4} *[a-zA-Z]{2}$");
	return(r1.test(str));
}

function isAdres(str)
{
	var r1 = /[0-9a-zA-Z\u00C0-\u0500]+[a-zA-Z\u00C0-\u0500]{1}.*[0-9]{1}.*/
	return(r1.test(str));
}

function isNaam(str)
{
	// var r1 = new RegExp("[a-zA-Z]*[ |.]{1}[a-zA-Z]+");
	var r1 = /[a-zA-Z\u00C0-\u0500]*[ |.]{1}[a-zA-Z\u00C0-\u0500]+/
	return(r1.test(str));
}

function checkpostcode(clickedform) {

	if (!isPostcode(clickedform.postcode.value)) {
		alert('Postcode is niet juist!\nZip code not correct!');
	}	
}

function checkemail(clickedform) {

	if (!isEmail(clickedform.email.value)) {
		alert('Email-adres is niet juist!\nEmail address is not correct!');
	}
}

function cover_page(status)
{
		if(status=='on')
		{
			document.getElementById('cover').style.height = document.body.scrollHeight;
			document.getElementById('cover').style.width  = document.body.scrollWidth;		
			document.getElementById('cover').style.display='block';
		}
		
		if(status=='off')
		{
			document.getElementById('cover').style.display='none';
		}
}	

function do_popup(url)
{	
	if(url==0)
	{		
		cover_page('off');
		document.getElementById('div_popup').style.display = 'none';
		document.getElementById('div_popup').innerHTML = '<b>Een momentje...</b>';
	} else
	{
		cover_page('on');

		$('#div_popup').load(url, function() {
			center_div('#div_popup');
			
			document.getElementById('div_popup').style.display = 'block';
		} );
	}			
}

function center_div(selector)
{
		  	var top =  ($(window).height() / 2) - ($(selector).height() / 2 )  + $(window).scrollTop();
			var left = ($(window).width()  / 2) - ($(selector).width()  / 2 )  + $(window).scrollLeft();
				
			if( top < $(window).scrollTop() )    top = $(window).scrollTop()  + 10;	
			if( left < $(window).scrollLeft() ) left = $(window).scrollLeft() + 10;	
			
            $(selector).css("top",  top  + 'px' );
			$(selector).css("left", left + 'px' );	
}
//------------------- AJAX voor html ---------------------------------------------------

function loadHTMLDoc(url,containerid) 
{	

	// tegen de cache van IE
	if (url.indexOf('?') == -1)
	{
		url = url + "?ms=" + new Date().getTime();
	} else
	{
		url = url + "&ms=" + new Date().getTime();
	}
	
	var req;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function(){processHTMLReqChange(req,containerid)};
		req.open("GET", url, true);
		if(req.overrideMimeType) req.overrideMimeType("text/html; charset=ISO-8859-1");		
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function(){processHTMLReqChange(req,containerid)};
            req.open("GET", url, true);
			//req.overrideMimeType("text/html; charset=ISO-8859-1");			 // WERKT OA. NIET MET IE6.0
            req.send();
        }
    }
}

function processHTMLReqChange(req,containerid) 
{
    // only if req shows "complete"
    if (req.readyState == 4) 
	{		
        // only if "OK"
        if (req.status == 200) 
		{
            // ...processing statements go here...
			//document.getElementById(containerid).innerHTML  = '';
			document.getElementById(containerid).innerHTML = req.responseText;

			if(containerid=='div_popup')
			{
				//document.getElementById('div_popup').style.left = (document.body.clientWidth/2) -(document.getElementById('div_popup').clientWidth/2) + 'px';			
			}
			
			// voor als we willen weten of het geladen is
			if(document.getElementById('HTMLDocLoaded'))
			{
				document.getElementById('HTMLDocLoaded').value = 1;
			}
			

        } else 
		{	
			alert("Probleem met het ontvangen van de data:\n" + req.statusText);
        }
    }
}
//----------------------------------------------------------------------
// JQUERY STUFF
//----------------------------------------------------------------------
$(document).ready(function()
{	
	var timer;
				
	$(window).resize(function() { 
				
			clearTimeout(timer); // zorgt ervoor dat IE het niet tig keer doet.
			timer=setTimeout('resize_article_side_lists()',250);	
					
	} );
	
});

function resize_article_side_lists()
{	
		if( $(window).width()  < 1185)
		{
			// sidelists passen niet ernaast en gaan naar onder
			$('#div_article_side_lists_container').addClass('class_article_side_lists_container_bottom');
			$('#div_article_side_lists_container').removeClass('class_article_side_lists_container_right');
					
		} else
		{
			// sidelists passen er naast
			$('#div_article_side_lists_container').addClass('class_article_side_lists_container_right');					
			$('#div_article_side_lists_container').removeClass('class_article_side_lists_container_bottom');
		}
}
