// JScript File

    function pageScroll() {
    
       var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop; 
       if (scrolly == 0) 
            window.scrollBy(0,265);       
    
    }

    function findObjectPosition(obj)
    {
      var curleft = curtop = 0;
      if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
          curleft += obj.offsetLeft
          curtop += obj.offsetTop
        }
      }
      return [curleft,curtop];
    }
    
    
    document.getElementPositionById = function(id) 
    //function getElementPositionById(id)
    {
        return findObjectPosition(document.getElementById(id));
    }
    
    
    function handleRefineDropdown(currenturl, variable, value)
    {
        window.location = currenturl + '&' + variable + '=' + value
    }
    
    function handleAdvancedDropdown(currenturl, variable, value)
    {
        window.location = currenturl + '?' + variable + '=' + value
    }
    
    function displayDiv(id)
    {
        if (document.getElementById(id)) {
            document.getElementById(id).style.display = "block";
        }
    }
    function hideDiv(id)
    {
        if (document.getElementById(id)) {
            document.getElementById(id).style.display = "none";
        }
    }
    
    function toggleDiv(id)
    {
        if (document.getElementById(id)) {
            if (document.getElementById(id).style.display == "none" || document.getElementById(id).style.display == "") {
                document.getElementById(id).style.display = "block";
            }
            else {
                document.getElementById(id).style.display = "none";
            }
        }
    }
    
	function executeCompare(contenttype,formelementname)
	{
	    var checkbox;
	    var checkedcount = 0;
	    var compareids = '';
	    checkbox = eval('document.aspnetForm.' + formelementname);


        if (typeof checkbox.length == 'undefined') {
    	    if (checkbox.checked) {
    	        checkedcount = 1
    	        compareids = checkbox.value;
    	    }
    	}
    	else {
	        for(var i=0; i < checkbox.length; i++){
		        if (checkbox[i].checked) {
		        compareids += checkbox[i].value + ',';	
		        checkedcount++
		        }
	        }
	        compareids = compareids.substr(0,compareids.length-1)
    	}
    	
    	
	    if (checkedcount > 0 && checkedcount <= 3) {
	        document.location = 'CompareResult.aspx?contenttype=' + contenttype + '&compareids=' + compareids
	    }
	    else {
	        if (checkedcount == 0) {
	            alert('Selecteer minimaal 1 onderdeel en probeer het nog een keer.');
	        }
	        else{
	            alert('Selecteer maximaal 3 onderdelen en probeer het nog een keer.');
	        }
	    }
	}
	
    function executeBlockedBrochures(goToROCConfirm)
    {
        
        var targetUrl;
        
        if(goToROCConfirm == '0')
        {
            targetUrl = 'UserRegister.aspx?mode=brochuresConfirmed&departmentstudyids=';
        }
        else
        {
            targetUrl = 'ConfirmROC.aspx' 
        }   
        document.location = targetUrl;
    }
	
    function executeConfirmROC(formelementname)
    {
        var checkbox;
        var checkedcount = 0;
        var compareids = '';
        checkbox = eval('document.aspnetForm.' + formelementname);

        if(checkbox.length > 0) 
        { 
            for(var i=0; i < checkbox.length; i++) 
            {
                if (checkbox[i].checked) 
                {
                    compareids += checkbox[i].value + ',';	
                    checkedcount++
                }
            }
        } 
        else 
        {
            if (checkbox.checked)
            {
                compareids = checkbox.value + ',';	
                checkedcount++;
            }
        }

        if (compareids.length > 0)
        {
            compareids = compareids.substr(0,compareids.length-1)
        }
        
        var targetUrl = 'UserRegister.aspx?mode=brochuresConfirmed&departmentstudyids=' + compareids;
        document.location = targetUrl;
    }
	
    function executeBrochure(formelementname, registerFirst)
    {
        var checkbox;
        var checkedcount = 0;
        var compareids = '';
        checkbox = eval('document.aspnetForm.' + formelementname);

        if(checkbox.length > 0) 
        { 
            for(var i=0; i < checkbox.length; i++) 
            {
                if (checkbox[i].checked) 
                {
                    compareids += checkbox[i].value + ',';	
                    checkedcount++
                }
            }
        } 
        else 
        {
            if (checkbox.checked)
            {
                compareids = checkbox.value + ',';	
                checkedcount++;
            }
        }

        if (compareids.length > 0)
        {
            compareids = compareids.substr(0,compareids.length-1)
        }
        
        if (checkedcount > 0) {
            var targetUrl = registerFirst ? 'UserRegister.aspx?mode=brochures&departmentstudyids=' + compareids : 'Brochure.aspx?departmentstudyids=' + compareids;
            document.location = targetUrl;
        } else if (checkedcount == 0) {
            alert('Selecteer minimaal 1 brochure en probeer het nog een keer.');
        }
    }
    
   var counter = 1;
   
	function ListHandler(list, item, obj, image, imageselected, imageload) {

           var posX = 0;
           var posY = 0;

         if(image != null) {
             // Get the element.
             img = obj.getElementsByTagName("img")[0];
                     
             // Set load image.
             img.src = imageload;
         }
         else {
            // If there is no image, do it the js way.
            var img = new Image();
         }

           

        //Set the image on the load image
        img.src = imageload;

        try {
         posX = findObjectPosition(img)[0];
         posY = findObjectPosition(img)[1];
        }
        catch(e) {

        }
           
        //get the listhandler via ajax
        try {
            AjaxRequest = new ActiveXObject("Microsoft.XMLHTTP");    // Trying Internet Explorer 
        }
        catch(e) {
            AjaxRequest = new XMLHttpRequest()
        }
        
        AjaxRequest.onreadystatechange  = function()
        { 
             if(AjaxRequest.readyState  == 4)
             {
                  if(AjaxRequest.status  == 200)  {
                     img.src = AjaxRequest.responseText; 
                     
                    // Release the focus, to ensure the selected line is gone.
                     obj.blur();
                    
                             
                     var ShowComparePopup = false;
                     
                     var BaseElement = document.getElementById("theBody");
                      
                      //(un)check the correct (hidden) checkbox
                      var CurrentCheckbox;
                      var CompareCounter;
                      var CompareCounterElement;
                    
                      switch (list) 
                      {
                          case "skp.compares.cities": {
                            if (document.getElementById("City_" + item))
                                CurrentCheckbox = document.getElementById("City_" + item) 
                            CompareCounterElement = document.getElementById("CompareCount")
                            ShowComparePopup = true;
                            
                            break;
                          }
                            
                          case "skp.compares.departments": {
                            if (document.getElementById("Department_" + item))
                                CurrentCheckbox = document.getElementById("Department_" + item) 
                            CompareCounterElement = document.getElementById("CompareCount")
                            ShowComparePopup = true;
                            break;
                          }
                          case "skp.compares.studies": {
                            if (document.getElementById("Study_" + item))
                                CurrentCheckbox = document.getElementById("Study_" + item) 
                            CompareCounterElement = document.getElementById("CompareCount")
                            ShowComparePopup = true;
                            break;
                          }
                          case "skp.compares.departmentstudies": {
                            if (document.getElementById("DepartmentStudy_" + item)) 
                                CurrentCheckbox = document.getElementById("DepartmentStudy_" + item) 
                            CompareCounterElement = document.getElementById("CompareCount")
                            ShowComparePopup = true;
                            break;
                          }
                          case "skp.brochures": {
                            if (document.getElementById("DepartmentStudy_" + item)) 
                                CurrentCheckbox = document.getElementById("DepartmentStudy_" + item) 
                            CompareCounterElement = document.getElementById("BrochureCount")
                            ShowComparePopup = false;
                            break;
                          }
                          case "skp.opendays": {
                            if (document.getElementById("Event_" + item)) 
                                CurrentCheckbox = document.getElementById("Event_" + item) 
                            CompareCounterElement = document.getElementById("OpenDayCount")
                            ShowComparePopup = false;
                            break;
                          }
                      }
                      
                      if(ShowComparePopup) {
                         //First remove all the other blocks, before showing the new block;
                         var OtherBlocks = getElementsByClassName(document,'div','ComparePopup');
                           for(var i=0; i < OtherBlocks.length; i++){
                               hideDiv(OtherBlocks[i].id);
                           }
                           
                         
                         var ConfirmBlock = document.createElement('div');
                         //ConfirmBlock.id = 'ComparePopup' + item;
                         //alert(posY)
                         ConfirmBlock.style.top = posY;
                         ConfirmBlock.style.left = posX + 30;
                         ConfirmBlock.setAttribute('class','ComparePopup');
                         ConfirmBlock.setAttribute('className','ComparePopup');
                         ConfirmBlock.setAttribute('id','ComparePopup' + item + '_' + counter);
                         ConfirmBlock.setAttribute('style','top:' + posY + 'px;left:' + (posX + 30) + 'px;');
                         ConfirmBlock.innerHTML = '<a class=\"CloseLink\" href="javascript:void(0);" onclick="hideDiv(\'ComparePopup' + item + '_' + counter + '\')" >X</a><b>Toegevoegd<br/>aan de vergelijkingslijst</b><br/><br/>&raquo; <a href="Compare.aspx">naar vergelijken</a>';
                     }
                      
                      
                    if (CurrentCheckbox) {
                        if (!CurrentCheckbox.checked) {
                            if(ShowComparePopup) {
                              BaseElement.appendChild(ConfirmBlock); 
                            }
                            CompareCounter = 1
                        }
                        else {
                            CompareCounter = -1 
                        }
                        if (CompareCounterElement) {
                            //alert(CompareCounterElement.innerHTML);
                            CompareCounterElement.innerHTML = (CompareCounterElement.innerHTML * 1) + CompareCounter;
                        }
                        
                        CurrentCheckbox.checked = !CurrentCheckbox.checked;
                    }
                    counter++;    
                     
                  }  
                  else {
                     alert("Error: " + AjaxRequest.status);
                  }
                     
             }
        }; 
           
       AjaxRequest.open("GET", "ListHandler.ashx?list=" + list + "&action=toggle&value=" + item + "&image=" + image + "&imageselected=" + imageselected + "&rnd=" + Math.random(),  true); 
       AjaxRequest.send(null); 

         // Retrieve the actual image.
         //img.src = "ListHandler.ashx?list=" + list + "&action=toggle&value=" + item + "&image=" + image + "&imageselected=" + imageselected + "&rnd=" + Math.random();
         
                               
      
    }
      
    
    function getElementsByClassName(oElm, strTagName, strClassName){
	    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
		    oElement = arrElements[i];
		    if(oRegExp.test(oElement.className)){
			    arrReturnElements.push(oElement);
		    }
	    }
	    return (arrReturnElements)
    }
