// Print functie (voor afvalkalender zoekresultaten)
function printAfvalkalender() {

	if (/\/admin\//.test(document.location)) {
		alert('Printen is niet mogelijk binnen de PageProcessor admin omgeving');
		return false;
	}

	if (document.getElementById('afvalzoekresultaten')) {
		window.printgedeelte = '<table><tr><td class=alineatekst>'+document.getElementById('afvalzoekresultaten').innerHTML+'</td></tr></table>';

		//disable de links om bladeren via printversie te voorkomen
		window.printgedeelte = window.printgedeelte.replace(/href/gi,"hrefdisabled");
		window.printgedeelte = window.printgedeelte.replace(/onclick/gi,"onclickdisabled");
		
		//open popup en vul deze 
		var w =  window.open('/print.html');
	}
}

//benodigde functie voor foto overzichts bouwsteen
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var popupscherm=0;

function popup_afbeelding(filename, fileid, width, height, scrollbars, resizable, menubar, toolbar, status, location) {
	if (popupscherm && ! popupscherm.closed)	popupscherm.close();
	if (!filename || filename=="")				filename="http://www.pageprocessor.nl";
	if (!fileid || fileid=="")					fileid="PageProcessor";
	if (!width || width=="")					width="50";
	if (!height || height=="")					height="50";
	if (!scrollbars || scrollbars=="")			scrollbars="no";
	if (!resizable || resizable=="")			resizable="no";
	if (!menubar || menubar=="")				menubar="no";
	if (!toolbar || toolbar=="")				toolbar="no";
	if (!status || status=="")					status="no";
	if (!location || location=="")				location="no";
	popupscherm=0;
	var args = "height=" + height + ", width=" + width + ", scrollbars=" + scrollbars + ", resizable=" + resizable +  ", menubar=" + menubar + ", toolbar=" +toolbar + ", status=" + status + " ,location=" + location;
	popupscherm = open(filename, fileid, args);
	if (!InternetExplorer) 						popupscherm.focus();
}

//	link the correct classes by mouseover dropdown menu
function sfHover() {
	if (document.getElementById("nav")) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
function setIconFalse(tagname) {
	if (/\/admin\//.test(document.location))
		return false;

	var el;
	var c = $(tagname);

	for (el=0;el<c.length;el++)
		c[el].setAttribute ('icon', 'false');
}

function toggleFAQ(el) {
	if (!el || /\/admin\//.test(document.location))
		return;
	
	if (el.style.display == 'none')
		el.style.display = 'block';
	else
		el.style.display = 'none';
	
	setHeights();
}

function initLinks() {
	// plaats een klein icoontje achter een externe link en achter links die naar bestanden wijzen
	// standaard: http://, ftp://, mailto:, doc, xls, pdf
	
	// de icoontjes staan in de dir css/images/
	// en hebben de zelfde naam als de extensie
	// doc => /images/icons/doc.gif
	
	// voeg eventueel extra types (bestandsextenties toe)
	if (typeof tagAhref=='undefined')
		return;
		
	tagAhref.setType('docx');
	tagAhref.setType('xlsx');
	
	// plaats het icoontje links, ipv rechts
	tagAhref.left = true;
	
	// plaats het icoontje boven ipv onder
	tagAhref.top = 'top';
	
	// start met het toevoegen van icoontjes
	// geef eventueel een rootnode op, bijvoorbeeld tagAhref.init('maintable');
	tagAhref.init('mainsitecontent');
}


//hoogte browser
	var isNav4, isNav6
	var isBrand = navigator.appName
	var navVer = parseInt(navigator.appVersion)
	
	var isNav4 = (isBrand == "Netscape" && navVer < 5) ? true : false
	var isNav6 = (isBrand == "Netscape" && navVer >= 5) ? true : false

function getInsideWindowHeight() {
	if (isNav4 || isNav6)
		return window.innerHeight
 	else 
	    return document.body.clientHeight
}
function getInsideWindowWidth() {
	if (isNav4 || isNav6)
		return window.innerWidth
 	else 
	    return document.body.clientWidth
}

//this function will get the current/computed style in IE and Moz/FF
function getStyle(obj,Attribute) {
	if (obj) {
		if (obj.currentStyle)
			var value = eval('obj.currentStyle.'+Attribute)
		else
			var value = eval('document.defaultView.getComputedStyle(obj, null).'+Attribute)
		return parseInt(value);
	}
}

function setHeights() {
	try {
		schermhoogte 				= getInsideWindowHeight();
		schermbreedte 				= getInsideWindowWidth();
		var header					= document.getElementById('mainheader');
		var header_height			= parseInt(getStyle(header,'height'));
		var footer					= document.getElementById('mainfooter');
		var footer_height			= parseInt(getStyle(footer,'height'));
		var swirl					= document.getElementById('swirl');
		var extra = 457;
		if (swirl) {
			var linkscontent		= document.getElementById('section13');
			var linkscontent14		= document.getElementById('section14');
			
			if (linkscontent14 &&  linkscontent14.offsetHeight > linkscontent.offsetHeight) {
				linkscontent = linkscontent14;
				var extra = 20;
			}
			
		} else
			var linkscontent		= document.getElementById('section6');
		
		if (linkscontent)
			var linkscontent_height	= linkscontent.offsetHeight + extra;
		
		var links					= document.getElementById('links');
		var links_height			= links.offsetHeight;
		var midden					= document.getElementById('midden');
		var midden_height			= midden.offsetHeight;
		var rechts					= document.getElementById('rechts');
		
		if (rechts)
			var rechts_height			= rechts.offsetHeight;
			
		var mainsite				= document.getElementById('mainsite');
		var mainsitecontent			= document.getElementById('mainsitecontent');
		var bottomdrop				= document.getElementById('bottomdrop');
		var bottomdrop_height		= parseInt(getStyle(bottomdrop,'height'));
		
		if (swirl)
			max_contentheight = Math.max(Math.max(linkscontent_height,midden_height),rechts_height) + bottomdrop_height + 7;
		else
			max_contentheight = Math.max(Math.max(linkscontent_height,midden_height),rechts_height) + bottomdrop_height;
		
		if ((max_contentheight + header_height + footer_height) > schermhoogte) {
			
			footer.style.top = max_contentheight + header_height + bottomdrop_height;
			bottomdrop.style.top = max_contentheight + header_height;
		} else {
			
			var section17 = document.getElementById('section17');
			
			if (section17) {
				var section17_height = section17.offsetHeight + 457;
				max_contentheight = section17_height + bottomdrop_height;
			} else {
				max_contentheight = schermhoogte - header_height - footer_height - bottomdrop_height;
			}
			
			if (max_contentheight>0) {
				bottomdrop.style.top = max_contentheight + header_height;
				footer.style.top = max_contentheight + header_height + bottomdrop_height;
			} else {
				footer.style.top = schermhoogte - footer_height;
				bottomdrop.style.top = schermhoogte - footer_height - bottomdrop_height;
			}
		}
		
		mainsite.style.height = max_contentheight + 8;
		mainsitecontent.style.height = max_contentheight;
		links.style.height = max_contentheight - 14;
		rechts.style.height = max_contentheight - 14;
		
		if (swirl)
			swirl.style.height = max_contentheight + 8;

	} catch (e) {}

}

function initAll(resize) {
	setHeights();
	if (resize === false) {
		//Classes addon for dropdown menu
		if (window.attachEvent)
			sfHover();
		
		// link icons (only for Afvalvrij)
		if (document.body.className == 'afvalvrij') {
			setIconFalse('.alineatekst_groen A');
			setIconFalse('.nieuwsviewer A');
			setIconFalse('.kaart_gelderland A');
			initLinks();
		}
	}
}

function setActiveTab(bsid, nr) {
	var menu = document.getElementById("carrouselmenu"+bsid)
	
	var content = document.getElementById('carrousel'+bsid+'_'+nr);
	if (bsid !== '' && typeof menu == "object" && typeof content == "object") {
		var alltabs = $('.tab_carrousel_item',menu);

		for (var i = 0; i < alltabs.length; i++) {
			alltabs[i].className = 'tab_carrousel_item';

			var allcontent = document.getElementById('carrousel'+bsid+'_'+i);
			if (allcontent)
				allcontent.style.display = 'none';
				
		}
		content.style.display = 'block';
		
		
		alltabs[nr].className = 'tab_carrousel_item tcactive';
		//dom.nodes("DIV", alltabs[nr]).each(function (el) {
		
		for (var i = 0; i < alltabs[nr].childNodes.length ;i++) {
			var el =  alltabs[nr].childNodes[i];
			alert(el.nodeName)
			if (el && el.nodeName=='DIV')
				el.style.backgroundColor = "transparent";
		}
		if (nr == 1) {
			try {
				initCarousel();
			} catch (e){}
		}
		
	}
}



function initCarousel() {
    jQuery("#mycarousel").jcarousel({
        scroll: 1,
        initCallback: ccallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: false,
        buttonPrevHTML: false,
		visible:true,
        wrap: 'last',
		auto: 5,
		itemFallbackDimension:10 // fallback width and height if the jcarousel hasnt a with height for its selft ; (i.e. is hidden)
    });
}
function ccallback (carousel) {
	jQuery('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});

	jQuery('.jcarousel-scroll select').bind('change', function() {
		carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		return false;
	});

	jQuery('#mycarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});

	jQuery('#mycarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
}


/**
 * Shows the detail content of an organisation within the organisation list. The detail content is 
 * found by searching for the correct parent div. The parent div has the id 'oid[organisationId]' 
 * where [organisationId] is the parameter organisationId.
 *
 * @param	organisationId	The ID of the organisation which is used to find the correct div. 
 */
function showOrganisationDetail(organisationId) {
	var elementId = 'oid' + organisationId;
	var parentElement = document.getElementById(elementId);
	
	if (parentElement !== 'undefined') {
		var detail = getElementsByClassName(parentElement, 'div', 'organisation_detail');
		
		if (detail !== 'undefined') {
			// Get the first detail div because this is the one that is needed.
			for (var i in detail) {
				if (detail[i].style.display == 'none') {
					detail[i].style.display = 'block';
				} else {
					detail[i].style.display = 'none';
				}
			}
		}
	}
	setHeights();
	sIFR.replace(sansaconprolight, { selector: 'div.sifr_afvalaward',css:{'.sIFR-root': {'color':'#000000', 'font-size':'18px' } } } );
}

function getElementsByClassName(node, tag, searchClass, searchClass2) {
	var classElements=[];
	node = node || document;
	var pattern = new RegExp('(^|\\s)' + searchClass+ '(\\s|$)');
	if (searchClass2) var pattern2 = new RegExp('(^|\\s)' + searchClass2 + '(\\s|$)');
	var els = (!tag &&  node.all) || node.getElementsByTagName(tag|| '*');
	var elsLen = els.length;
	for (var i=0, j=0;i<els.length;i++){
		if (pattern.test(els[i].className) || (pattern2 && pattern2.test(els[i].className))) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/**
 * Sets the replyToMessageId into the hidden input field 'reageer_message_id'.
 *
 * @param	replyToMessageId	The ID of the message to which will be replied.
 */
function setReplyToMessageId(replyToMessageId) {
	var reageerMessageIdInputElement = document.getElementById('reageer_message_id');
	
	if (reageerMessageIdInputElement !== 'undefined') {
		reageerMessageIdInputElement.value = replyToMessageId;
		
		tabclick(5);
	}
}

var selectedTab = 0;
curvyCornersVerbose = false;

function tabclick(n) {
  if (n === selectedTab) return; // nothing to do.
  var li = document.getElementById('tab' + selectedTab);
  curvyCorners.adjust(li, 'className', ''); // Remove the 'select' style
  li = document.getElementById('page' + selectedTab);
  li.style.display = 'none';                // hide the currently selected sub-page
  li = document.getElementById('page' + n);
  li.style.display = 'block';               // show the new sub-page
  li = document.getElementById('tab' + n);  // get the new (clicked) tab
  curvyCorners.adjust(li, 'className', 'select'); // and update its style
  curvyCorners.redraw();        // Redraw all elements with className curvyRedraw
  selectedTab = n;              // store for future reference
  
	if (n == 1) {
		try {
			initCarousel();
		} catch (e){}
	}
}



