function showSubscription(){
	document.getElementById('newsletterssubscription').style.display = 'block';
	document.getElementById('newsletterslist').style.display = 'none';
	return false;
}

function DoSearch(f){
   document.forms[0].submit();
   return true;
}

function SearchKey(f) {
  if (window.event && window.event.keyCode == 13){
     return	DoSearch(f);
  }else{
    return true;
  }
}


/*
* Show Hide Elements Functionality
*/
function switchid(itemid) { 
   whichitem = document.getElementById(itemid); 
   if (whichitem.className=="show") 
   { 
      whichitem.className="hide"; 
   } 
   else 
   { 
      whichitem.className="show"; 
   } 
} 

function switchallids(itemid) {
	var idx = 1;
	var id = "b" + idx;
	var act = document.getElementById(id);
	while(act != null){
		if(id == itemid){
			switchid(itemid);
		}else{
			act.className="hide";
		}
		
		idx = idx + 1;
		id = "b" + idx;
		act = document.getElementById(id);
	}
	return false;
}


/*
* Font Size Increase Decrease Functionality 
*/
function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
	  //setActiveStyleSheet('A++');   optional but I do not recommend the usage of it!
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A-');
      break;
  }
  return false;
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      // Turned off on request of the customer.
      //setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A--');
      break;
  }
  return false;
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A-');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  for(i=0;i<document.links.length;i++){
    link = document.links[i];
    if(link.className.indexOf('target_blank') >=0 || link.href.indexOf('.pdf') >=0 || link.target.indexOf('_blank') >=0 ){
      link.target="_blank";
    }
  }
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);

//google search pdf agenda en verslag
//get result from page
function getResult()
{
	var querycontent = document.getElementById('qcontent').value + "%20AND%20Agenda%20AND%20verslag";
	window.location.href = '/CBG/nl/_search/pdfresult/default?cx=000434066175819866604:_tpdtn05cw8&cof=FORID:11&ie=ISO-8859-1&hq=inurl:pdf&site:www.cbg-meb.nl&as_filetype=PDF&q='+querycontent+'&sa=Search+Pdf';
    var cleanquery = querycontent.replace("%20AND%20Agenda%20AND%20verslag", " ");
    document.getElementById('qcontent').value = cleanquery;
    createCookie("qtxt", cleanquery, 1);
    return false;
}
//on enter key
 function submitenter(myfield, e) {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

        if (keycode == 13) {
            if (document.getElementById("Submit1")) document.getElementById("Submit1").click();
           return false;
        }
        else{
            return true;
		}
}

jQuery.extend({ 'QueryString': window.location.search.length <= 1 ? new Array() : function(a) { var b = new Array(); for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); b[p[0]] = unescape(p[1]); } return b; } (window.location.search.substr(1).split('&')) });

//jquery handler
$(document).ready(function() {
	//fill inputfield googlesearch after post
	var linkquery = $.QueryString["q"]; //alert(linkquery);
	var qcookie = readCookie("qtxt");
	//$("#qcontent").val(qcookie);
	if (qcookie == null)
	{
	$("#qcontent").val("");
	}
	else {
	$("#qcontent").val(qcookie);
	}			
	//show pdf on popup
	$("A[href$='.pdf']").click(function() {
		newWin = window.open(this.href, "pdf", "location=no,toolbar=no,width=800,height=600");
		if (window.focus) { newWin.focus(); }
		if (newWin) {
			// popup worked, block original event
			return false;
		} else {
			// popup failed, let original go through
			return true;
		};
	});
	
	//get url
	//nl
	var pathname = window.location.pathname;
	if(pathname == '/CBG/nl/_meta/contact/klachtenbehandeling/default.htm' || pathname == '/cbg/nl/_meta/contact/klachtenbehandeling/default.htm')
	{
		$(location).attr('href','/CBG/nl/over-ons/contact/klachtenbehandeling/default.htm');
	}
	
	//en
	if(pathname == '/CBG/en/_meta/contact/' || pathname == '/cbg/en/_meta/contact/')
	{
		$(location).attr('href','/CBG/en/about/contact/complaints%20handling/default.htm');
	}
	
	//
	//if(pathname == '/CBG/en/about/organisation/MEB/default' || pathname == '/cbg/en/about/organisation/meb/default' || pathname == '/CBG/en/about/organisation/MEB/default.htm')
	//	{
	//		$(location).attr('href','/CBG/en/about/organisation/MEB-new/default.htm');
	//}
	//hide spec li
	//$('ul.dropDownMenu li ul li:nth-child(5)').hide();
});
