$(function(){
  
  
/*  	var hoogte = $(document).height();
	if(document.getElementById('lijn')) 	{ document.getElementById('lijn').style.height = hoogte + 'px'; }
  
	var maxHeight = 0;
	$(".contentkols").each(function(){
		if (maxHeight < $(this).height()) {maxHeight = $(this).height()}
	});
	
	$(".contentkols").each(function(){	$(this).height(maxHeight);	});*/
	
	
/*	$(".homepage a img").hover(
		function(){  },
		function(){  }
	);
*/
	

	// Functie aanroepen via id in div, daarna doormiddel van hide sluiten //
	// this is de functie (knop) die je op dat moment aanroept //
	
	$('#closeaward').click(function(){
		$.get(url+"includes/displayaward.php",
			  function(data){ //alert(data);
			  });
		$('#award').hide();
		$(this).hide();
		
	});

	
	$('#search').click(function(e){
		if($("#search").val() == "_SEARCH") {
			$("#search").attr("value"," ");
		}
    });
	
	function dosearch() {
	
		if($('#search').val().length > 2) {
			$.get("includes/search.php", { search: $('#search').val() },
			function(data){
			 alert("Data Loaded: " + data);
			});
		}
	}
	
	$('#password').keydown(function(e){
        if (e.keyCode == 13) {
	
			$.get(url+"includes/checklogin.php", { gebruikersnaam: $('#gebruiker').val(), wachtwoord: $('#password').val() },
			function(data){
				if(data == "wel") { window.location=url+"rubitech/extranet/"; } 
				if(data == "niet" || data == "") { alert('Incorrect login!'); } 
			});
            return false;
        }
    });
	
	$('#logout').click(function(e){
      
			$.get(url+"includes/loguit.php",
			function(data){
				if(data == "wel") { window.location=url+"rubitech/"; } 
				if(data == "niet" || data == "") { alert('Logout failed!'); } 
			});
            return false;
       
    });
	
	
	$('#search').keydown(function(e){
        if (e.keyCode == 13) {
			//dosearch();
			$('#searchform').submit();
			return false;
        }
    });

	
	$('#forgetpasswordbtn').click(function(e){
		$.get(url+"includes/forgetpassword.php", { gebruikersnaam: $('#fggebruikersnaam').val() },
		function(data){
			if(data == "wel") { alert('A link to change your password has been sent to your emailaddress.'); forgetpasswordhide(); } 
			if(data == "niet" || data == "") { alert('An user with this username doesn\'t exist!'); } 
		});
	});

	
	$('#forgetpasswordbtn2').click(function(e){
		if($('#fgwachtwoord').val() == $('#fgwachtwoordconfirm').val() || $('#fgwachtwoord').val() == '' || $('#fgwachtwoordconfirm').val() == '') {
			$.get(url+"includes/forgetpassword.php", { keystring: $('#fgkeystring').val(), wachtwoord: $('#fgwachtwoord').val() },
			function(data){
				if(data == "wel") { alert('Your password has been changed. You can login with your new password now'); forgetpasswordhide2(); } 
				if(data == "niet" || data == "") { alert('Your new password don\'t fit the requirements'); } 
			});
		} else {
			alert('The passwords don\'t match.');
		}
	});

	
	$('#loginbutton').click(function(e){
		$.get(url+"includes/checklogin.php", { gebruikersnaam: $('#gebruiker').val(), wachtwoord: $('#password').val() },
		function(data){
			if(data == "wel") { window.location=url+"rubitech/extranet/"; } 
			if(data == "niet" || data == "") { alert('Incorrect login!'); } 
		});
	});
	

	$('#logoutbutton').click(function(e){
	
		var check = confirm("Weet u zeker dat u wilt uitloggen?");
		if(check == true) {	
			
			$.get(url+"includes/loguit.php", function(data){
				if(data == "wel") { window.location=url+"rubitech/"+p+"/"; } 
				if(data == "niet" || data == "") { alert('Logout failed!'); } 
			});
		
	
		}
	});

	
		//alert(hoogte);
		//alert(document.getElementById('lijn').style.height);
		
		//var hoogte = $(document).height();
//		alert(hoogte);
		
		//var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
		//alert(hoogte);
		//alert(viewportHeight);
	//	var hoogte2 = $(window).height();
	//	if(hoogte < hoogte2) { hoogte = hoogte2; }
	//	else { hoogte = hoogte; }
		//$.getDocHeight = function(){
			//var hoogte = Math.max(
			//	$(document).height(),
			//	$(window).height(),
				/* For opera: */
			//	document.documentElement.clientHeight
			//);
			//if($("#lijn")) { 
		//$("#lijn").html("&nbsp;");
		//$("#lijn").height(hoogte);
		//document.getElementById('lijn').style.height = hoogte + 'px'; 
		//}
		//	alert(hoogte);
		//};
			
		
		
});


function showsub(id) {
	if(document.getElementById(id)) { document.getElementById(id).style.display = 'block'; }	
}

function hidesub(id) {
	if(document.getElementById(id)) { document.getElementById(id).style.display = 'none'; }	
}

function swap(id) {
	var href = "a"+id+"";
	//if(document.getElementById(id)) { document.getElementById(id).style.backgroundImage = 'url(images/menu_sub_back_over2.jpg)'; }
	if(document.getElementById(href)) { document.getElementById(href).style.fontWeight = 'bold'; }
}

function swapback(id) {
	var href = "a"+id+"";
	//if(document.getElementById(id)) { document.getElementById(id).style.backgroundImage = 'url(images/menu_sub_back2.jpg)'; }	
	if(document.getElementById(href)) { document.getElementById(href).style.fontWeight = 'normal'; }
}

function swaph(id) {
	var href = "a"+id+"";
	if(document.getElementById(href)) { document.getElementById(href).style.color = '#ffbd2e'; }
}

function swaphback(id) {
	var href = "a"+id+"";
	if(document.getElementById(href)) { document.getElementById(href).style.color = '#3e3d8b'; }
}



function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
 
function getPageSize(){

	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth;
		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;
	}
	
	var windowWidth, windowHeight;
 
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.scrollHeight;
	} 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 = windowWidth; } 
	else { pageWidth = xScroll; }
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




function showinlog() { 
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	if(document.getElementById('inlog')) {	
		document.getElementById('inlog').style.display = "block"; 
	}
	if(document.getElementById('inlogback')) {	
		document.getElementById('inlogback').style.height = (arrayPageSize[1] + 'px');
		document.getElementById('inlogback').style.display = "block"; 
	}
}
function hideinlog() { 
	if(document.getElementById('inlog')) {	document.getElementById('inlog').style.display = "none"; }
	if(document.getElementById('inlogback')) {	document.getElementById('inlogback').style.display = "none"; }
}
function forgetpassword() {
	if(document.getElementById('inlog')) {	document.getElementById('inlog').style.display = "none"; }
	if(document.getElementById('forgetpassword')) {	document.getElementById('forgetpassword').style.display = "block"; }
}
function forgetpasswordhide() {
	if(document.getElementById('inlog')) {	document.getElementById('inlog').style.display = "block"; }
	if(document.getElementById('forgetpassword')) {	document.getElementById('forgetpassword').style.display = "none"; }
}
function forgetpasswordhide2() {
	if(document.getElementById('inlog')) {	document.getElementById('inlog').style.display = "block"; }
	if(document.getElementById('forgetpassword2')) {	document.getElementById('forgetpassword2').style.display = "none"; }
}


function gethoogte() {
	
	var hoogte = document.getElementById('maincontent').offsetHeight;
	

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
//	alert(maxhoogte);
//	var hoogtev = myHeight - maxhoogte;
		
//	if(hoogte < hoogtev) { 
		document.getElementById('lijn').style.height = ""+myHeight+"px";
//	}
}


function verleng() {
	
	var hoogte = document.getElementById('maincontent').offsetHeight;
	

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
//	alert(maxhoogte);
	var hoogtev = myHeight - maxhoogte;
		
	if(hoogte < hoogtev) { 
		document.getElementById('maincontent').style.height = ""+hoogtev+"px";
		}
}


function showback(waarde) { 
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	
	if(document.getElementById('back')) {	
		document.getElementById('back').style.height = (arrayPageSize[1] + 'px');
		document.getElementById('back').style.display = "block"; 
		document.getElementById('back').style.overflowY = "hidden";
	}
	if(document.getElementById('movie')) { 
	
		document.getElementById('movie').style.display = "block"; 
		myRand=parseInt(Math.random()*99999999);
		myRanda=parseInt(Math.random()*999999999);
		http.open("GET", "player.php?random="+myRand+myRanda+"&flvid="+waarde+"", true); 
		http.onreadystatechange = handleRefResponse; 
		http.send(null);
		
		
	}
	
}

function hideback() { 

	if(document.getElementById('back')) {	document.getElementById('back').style.display = "none"; }
	if(document.getElementById('movie')) {	document.getElementById('movie').style.visibility = "hidden"; }
}





function handleRefResponse() { 
    if (http.readyState == 4) { 
		document.getElementById('movieflv').innerHTML = http.responseText; 
		document.getElementById('movie').style.visibility = "visible"; 
	}						
}



function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/
    
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try { xmlhttp = new XMLHttpRequest(); } 
        catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}


var http = getHTTPObject(); // We create the HTTP Object


function toongegevens(veld) {

	// alle velden uitzetten
	if(document.getElementById('introductie')) { document.getElementById('introductie').style.display = "none"; }
	if(document.getElementById('afbeeldingen')) { document.getElementById('afbeeldingen').style.display = "none"; }
	if(document.getElementById('videos')) { document.getElementById('videos').style.display = "none"; }
	if(document.getElementById('publicaties')) { document.getElementById('publicaties').style.display = "none"; }
	if(document.getElementById('brochures')) { document.getElementById('brochures').style.display = "none"; }
	if(document.getElementById('presentaties')) { document.getElementById('presentaties').style.display = "none"; }
	if(document.getElementById('ontwerpbestanden')) { document.getElementById('ontwerpbestanden').style.display = "none"; }
	if(document.getElementById('projectdocumenten')) { document.getElementById('projectdocumenten').style.display = "none"; }
	if(document.getElementById('ontwerpen')) { document.getElementById('ontwerpen').style.display = "none"; }
	if(document.getElementById('offertes')) { document.getElementById('offertes').style.display = "none"; }
	if(document.getElementById('orderbevestigingen')) { document.getElementById('orderbevestigingen').style.display = "none"; }
	if(document.getElementById('facturen')) { document.getElementById('facturen').style.display = "none"; }
	if(document.getElementById('logboeken')) { document.getElementById('logboeken').style.display = "none"; }
	if(document.getElementById('certificaten')) { document.getElementById('certificaten').style.display = "none"; }
	if(document.getElementById('montagehandleidingen')) { document.getElementById('montagehandleidingen').style.display = "none"; }
	if(document.getElementById('onderhoudscontracten')) { document.getElementById('onderhoudscontracten').style.display = "none"; }
	if(document.getElementById('overige_documenten')) { document.getElementById('overige_documenten').style.display = "none"; }
	
	if(document.getElementById(veld)) { document.getElementById(veld).style.display = "block"; }
}

