$(document).ready(function () {
   
   if (document.getElementById('introimage-slider')) {
    $('#introimage-slider').nivoSlider({
          effect: 'fade',
          animSpeed: 1000,
          pauseTime: 5000,
          directionNav: false,
          controlNav: true,
          pauseOnHover:true,
          captionOpacity:1
    });
    
  }
  
 setContentHeight();
 setHomepageHeight();
  
  $("div.table tr:nth-child(odd)").addClass("tr-b");
  
  $(".ddPicker").datepicker({ dateFormat: 'dd MM yy' });
 
  $("table.zebra tr:nth-child(odd)").addClass("tr-b");
  
  
  if (document.getElementById('maparea'))
      {
          startGmap();
      }
  
  setMainMenu();
    
  $("#searchbtn").click(function(){
      GoToUrl($("#SearchVal").val());
  });
  
  if(findParam("q")){
     setUrl();
  }
 

});



function setContentHeight(){
 if($("#content-main").height() < 450) {
    $("#content-main").height(450);
  }
5
};



function setHomepageHeight(){
  var intro = $("#introtext").height();
  var upcum = $("#upcomingprogram").height();
  if(intro > upcum) {
   $("#upcomingprogram").height(intro);
  }
  if(upcum > intro) {
   $("#introtext").height(upcum);
  }

};


function setUrl(){

     var srchVal = findParam("q");
     var url = "http://www.google.com/cse?cx=014928338060536209409%3Aaq-7g1610sy&cof=FORID%3A9&q=" + srchVal;
     $("#resultFrame").attr("src", url);

  
  }

function setMainMenu(){
  
  if(pageid == '1051') 
    {
      $("#home-img").attr('src', '/images/mainmenu-first-o.gif');
    } else {
      $('ul#mainmenu li').first().mouseenter(function(){
         $("#home-img").attr('src', '/images/mainmenu-first-o.gif');
      });
      $('ul#mainmenu li').first().mouseleave(function(){
           $("#home-img").attr('src', '/images/mainmenu-first.png');
      });
    }
}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function insertCss() {

    if (jQuery.browser.msie) {
        if (jQuery.browser.version == '7.0') {
            document.write('<link rel="stylesheet" type="text/css" href="/css/iestyle7.css" />');
        }
    }
}

function GoToUrl(srchVal) {
  var url = "/search-results.aspx";
  url = url.concat('?q=', srchVal);
  window.location.href = url;
}  

function startGmap() {
    var locationLatitude =52.3635;
    var locationLongitude =4.8788; 
    var locationZoom = 15;
    var map = new google.maps.Map(document.getElementById("maparea"), {
        scaleControl: true,
        center: new google.maps.LatLng(locationLatitude, locationLongitude),
        zoom: parseInt(locationZoom),
        streetViewControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: true,
        navigationControl: true
    });

   var marker = new google.maps.Marker({
        position: new google.maps.LatLng(locationLatitude, locationLongitude),
        map: map,
        title: "Aif",
        icon: '/images/aif-marker.png'
    });

}

function findParam(paramName){
  url = window.location.search.substring(1);
  pars = url.split("&");
  for (i=0;i<pars.length;i++) {
   par = pars[i].split("=");
   if (par[0] == paramName)
   {
      return par[1];
   }
  }
  return '';
}

function setPage(value){
  
  
  var page= 0; // Default waarde 
  page = findParam("p");
  
  if (value == "next")
  {
    page = Number(page) +  Number('1');
  }
  else
  {
    page = Number(page) -  Number('1');
  }

  var c = findParam("c");
  var n = findParam("n");
  var b = findParam("b");
  searchClients(b, c, n, page);
}

function searchClients(busValue, cntValue, nameValue, page){
 // alert(cntValue)
  
  var base = '/clientresult.aspx';

  if (busValue != '' && busValue != 'Show All')
  {
    base = base.concat('?b=', busValue);
  }
  if (cntValue!= '' && cntValue!= 'Show All')
  {
    if (base != '/clientresult.aspx')
    {
      base = base.concat('&');
    }
    else
    {
      base = base.concat('?');
    }
    base = base.concat('c=', cntValue);
  }
  if (nameValue!= '')
  {
    if (base != '/clientresult.aspx')
    {
      base = base.concat('&');
    }
    else
    {
      base = base.concat('?');
    }
    base = base.concat('n=', nameValue);
  }

  if (base != '/clientresult.aspx')
  {
    base = base.concat('&');
  }
  else
  {
    base = base.concat('?');
  }
  if (!page)
  {
    page = 0;
  }
  base = base.concat('p=', page);
  
 location.href = base;

  
  
}

/*
function sortClients(type, value) {

  if(type == 'country') {
  
    location.href = '/clients.aspx?c='+value;
    
  }
  
  if(type == 'business') {
  
    location.href = '/clients.aspx?b='+value;
    
  }
}
*/


$(function () {
    
  
  $( "#accordion" ).accordion({
      autoHeight: false,
      navigation: true,
      active: 999,
      collapsible: true 
    });

  
  // execute de search op basis van een enter
 $("input#SearchVal").keypress(function (e) {
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
          GoToUrl($("#SearchVal").val());
        return false;
      } else { return true;}
  });
  
  $("form#clientform").keypress(function (e) {
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
          location.href = '/clientresult.aspx?b='+ $("#business").val() +'&c='+ $("#country").val() +'&n='+ $("#clientname").val() +'&p=1';
        return false;
      } else { return true;}
  });
  
  
  
  
    $(".onlyshowonprint").each(function(index) {
      $(".onlyshowonprint").hide();
     });
  
  $(".factabs").tabs();
  
  /* tabs BA*/
  $(".program-tabs").tabs({
      cookie: {
        // store cookie for x part of a day, without, it would be a session cookie
        expires: 0.0005
      }
    });
/* tabs Front-End*/
  var tabIndex = 0;
  var tabParamIndex = window.location.hash.indexOf('tab=');
  if (tabParamIndex > -1) {
    tabIndex = parseInt( window.location.hash.substring(tabParamIndex + 4) );
  }
  $(".program-tabs2").tabs({
  
     select: function(event, ui) { /* setContentHeight();*/ },
    selected: tabIndex
  });
  
  /* remove accreditation */
  if (document.getElementById('NoAcc')) {
    $(".program-tabs2").tabs("remove", 4);
  }


   
   $("#getdirections").click(function(){
     var adress = $("#map-adress").val();
     window.open( 'http://maps.google.com/maps?f=d&source=s_d&saddr='+adress+'&daddr=Stadhouderskade+2,+amsterdam');
   })

    
   $("#printknop").click(function() {  
   
    printMe();
  
   })

   $("#printknop2").click(function() { 
      printMe();
   })

});
  
function printMe(){
 var title = $("title").html();
   var content=""
     
     $(".printable").each(function(index) {
        content += $(this).clone().html()
     });
      
   top.consoleRef=window.open('/print.html','','width=550,height=750,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1')
   top.consoleRef.document.write(
     '<html><head>'
     +'<title>print</title>'
     +'<script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>'
     +'<script src="/Scripts/print.js" type="text/javascript"></script>'
     +'<link href="/css/print.css" rel="stylesheet" type="text/css" />'  
     +'<title>'+ title + '</title></head>'
     +'<body onLoad="self.focus()">'
     +content
     +'</body></html>'
   )
     
   top.consoleRef.document.close()

}

startList = function () {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("mainmenu");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function () {
                    this.className += " over";
                }
                node.onmouseout = function () {
                    this.className = this.className.replace(" over", "");
                }
            }
        }
    }
}
window.onload = startList;


