﻿function trim(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    return value;
}

function switchFotos(fotoOff, fotoOn)
{
    document.getElementById(fotoOff + "_seAfb").style.display = 'none';
    document.getElementById(fotoOn + "_seAfb").style.display = 'block';
}

function mnsL(click)
{
    var curMargin = $("#" + mnsID).css("marginLeft");
    if (curMargin != "0px" && curMargin != "auto") $("#" + mnsID).animate({"marginLeft" : "+=75px"}, "fast");
    
    if (click == true)
    {
        clearInterval(mnsInterval);
        mnsInterval =  null;
    }
}

function mnsR(click)
{
    var checkVal = "-" + ((mnsCount - 8) * 75) + "px";
    var curMargin = $("#" + mnsID).css("marginLeft");
    if (curMargin != checkVal) $("#" + mnsID).animate({"marginLeft" : "-=75px"}, "fast");
    
    if (click == true)
    {
        clearInterval(mnsInterval);
        mnsInterval =  null;
    }
}

function setHeightRightColumns()
{
    var h2 = $("#pnlR2inner").height();
    var h3 = $("#pnlR3inner").height();
    
    var b2 = Math.ceil((h2 + 15 + 5) / 75);
    var b3 = Math.ceil((h3 + 15 + 5) / 75);
    
    var n2 = Math.max(125, b2 * 75 - 15 - 5);
    var n3 = Math.max(125, b3 * 75 - 15 - 5);
    
    $("#pnlR2inner").height(n2);
    $("#pnlR3inner").height(n3);
}

/*********************************************************************
 * No onMouseOut event if the mouse pointer hovers a child element 
 * *** Please do not remove this header. ***
 * This code is working on my IE7, IE6, FireFox, Opera and Safari
 * 
 * Usage: 
 * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
 *		So many childs 
 *	</div>
 *
 * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
**/
function is_child_of(parent, child) {
	if (child != null) {
		while (child.parentNode) {
			if ((child = child.parentNode) == parent) {
				return true;
			}
		}
	}
	return false;
}

function fixOnMouseOut(element, event, pvFunction) {
	var current_mouse_target = null;
	if (event.toElement ) {
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target) {
		pvFunction();
	}
}
/*********************************************************************/

//start van ajax request vanuit duurzaamheids tool
function ToolAjaxStart(){
    $(".NoResultsText").hide(); 
    $(".ResultCell").stop().fadeOut(500, 
        function(){ 
            $(".ResultCell").css("borderBottom", "1px solid white")
        }
    );
}
var toolFirstTime=true; //geeft aan of het de eerste keer is dat er resultaten getoond (gaan) worden
var openTool=-1; //var met het id van huidige gekozen tool
var allCategoriesSelected = false;
//einde van ajax request vanuit duurzaamheids tool
function ToolAjaxEnd(){
    //het "AllCategoriesSelected" element bestaat in html als alle categorieen op zn minst 1 keer zijn geselecteerd
    if ($(".AllCategoriesSelected").length){
        allCategoriesSelected = true;
    }
    
    
     //als het de eerste keer is en alle categorien zijn geselecteerd EN er zijn resultaten
    if (toolFirstTime && allCategoriesSelected){
        toolFirstTime = false;
        $(".ResultHeaderInitial").hide();
        
        $(".ResultContainer").stop().animate({backgroundColor:'#199FA2', color:'white'},500);
        $(".ResultHeader").show(100);
        if ($(".ResultCell").length > 0){
            //wel resultaten
            $(".ResultInner").fadeIn(800, 
                function(){
                    SetResultBorders();
                }
            );
            
          
            $(".ResultHeaderText").show();
            
          }
          else{
            //geen resultaten
            $(".NoResultsText").show();   
            $(".ResultHeaderText").hide();
          }
    }
    else if(!toolFirstTime && allCategoriesSelected && $(".ResultCell").length == 0){
        //geen resultaten
        $(".NoResultsText").show();   
        $(".ResultHeaderText").hide();
        $(".ResultInner").fadeOut(700);
    }
    else if (!toolFirstTime && allCategoriesSelected && $(".ResultCell").length > 0){
        //niet de eerste keer en WEL resultaten
        $(".ResultInner").fadeIn(800,
            function(){
                  SetResultBorders();
            }
        );
        $(".ResultCell").fadeIn(800, 
            function(){
                 SetResultBorders();
            }
        );
    }
    
}

//schuif hele venster naar links en maakt tool selectie ongedaan
function ToolSlideLeft(){

    $(".ToolContainer").stop().animate({marginLeft:22},700,
        function(){
            $(".ToolDetail").hide();
            $("#pnlRF").fadeIn(300); //duurzaam presteren tekst terug zetten
            $(".SlideLeftArrow").hide();
        }
    
    ); 
}
//schuif hele venster naar rechts met de geselecteerde tool
function ToolSlideRight(toolId){
    //als al naar rechts geschoven is, hoeft alleen nog de juiste tool zichtbaar te worden gemaakt
    if ($(".ToolContainer").css("marginLeft") != "22px" && openTool != toolId){
           $(".ToolDetail").hide();
           $(".ToolPanel" + toolId.toString()).fadeIn(400);
           openTool = toolId;
    }
    else{
        //anders naar rechts schuiven EN de juiste tool zichtbaar maken
        $(".ToolContainer").stop().animate({marginLeft:-370},700,
                function(){
                        $(".ToolDetail").hide();
                        //alert("ToolPanel "+ toolId.toString());
                        $(".ToolPanel" + toolId.toString()).fadeIn(400);
                        openTool = toolId;
                        
                        //'duurzaam presteren' rechtsonder laten verwijnen
                        $("#pnlRF").fadeOut(300);
                        $(".SlideLeftArrow").show();
                }
        
        );   
    }
}

function SetResultBorders(){
    $(".ResultCell").css("borderBottom", "1px solid #199FA1");
}

function InitThemeRadiobuttons(){
    $("[value='nee']").attr('checked', 'checked');
}
