// Ken onclick event toe aan alle anchor elements naar externe links in homeartikel.
// e = element Id
// eigenSite = adresEigenSite
function trackExternalLinks(e, eigenSite) {
	var aList = xGetElementsByTagName("a", xGetElementById(e));
	if (aList != null) {
		for (i = 0; i < aList.length; i++) {
			if (aList[i].href.indexOf(eigenSite) < 0) {
				// alleen externe links
				//alert(aList[i]+e);
				YAHOO.util.Event.addListener(aList[i], 'click', trackExternalLinkHP);
			}
		}
	}
}

function trackExternalLinkHP(e)
{
	e = new xEvent(e);
	if (e.target.href == null) {
		var a = e.target.alt;
	} else {
		var a = e.target.href;
	}
	
	pageTracker._trackPageview('/voorpagina-'+escape(a));
}

function trackLinkID(e)
{
	e = new xEvent(e);
	if (this.id && this.id != '') {
		var a = this.id;
		if (this.target.href != null) {
			a = a + '-' + this.target.href;
		}
	} else {
		var a = e.target;
	}
	pageTracker._trackPageview('/tracklink-'+escape(a));
}

function initStdInput(idArray, valArray) {
	for (var i = 0; i < idArray.length; i++) {
		e = xGetElementById(idArray[i]);	

		if (e != null) {
			e.stdValue = valArray[i];
			e.onfocus = function() { stdFocus(this, this.stdValue, '#000'); }
			e.onblur = function() { stdLostFocus(this, this.stdValue, 'Gray'); }
		}
	}
}

function initStdSubmit(idSubmit,valArray,stdArray) {
	e = xGetElementById(idSubmit);	
	if (e != null) {
		e.valArray = valArray;
		e.stdArray = stdArray;
		e.onsubmit = function() {
			stdSubmit(this.valArray,this.stdArray);
		}
	}
}

// customize YAHOO.widget.Calendar
function customizeCalendar(calId) {
	if (calId != null) {
		calId.cfg.setProperty("DATE_FIELD_DELIMITER", ".");  

		calId.cfg.setProperty("MDY_DAY_POSITION", 1);  
		calId.cfg.setProperty("MDY_MONTH_POSITION", 2);  
		calId.cfg.setProperty("MDY_YEAR_POSITION", 3);  

		calId.cfg.setProperty("MD_DAY_POSITION", 1);  
		calId.cfg.setProperty("MD_MONTH_POSITION", 2);  

		calId.cfg.setProperty("MONTHS_SHORT",   ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"]);  
		calId.cfg.setProperty("MONTHS_LONG",    ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"]);  
		calId.cfg.setProperty("WEEKDAYS_1CHAR", ["Z", "M", "D", "W", "D", "V", "Z"]);  
		calId.cfg.setProperty("WEEKDAYS_SHORT", ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"]);  
		calId.cfg.setProperty("WEEKDAYS_MEDIUM",["Zon", "Maa", "Din", "Woe", "Don", "Vri", "Zat"]);  
		calId.cfg.setProperty("WEEKDAYS_LONG",  ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag"]);  

		// enable CalendarNavigation
		//calId.cfg.setProperty("navigator", true); voor later order
	}

	return;
}

// maak een YAHOO.widget.Calendar
function maakKalender(calField, dagid, maandid, jaarid) {
	var oCal = new YAHOO.widget.Overlay("cal"+calField, { visible: false} );
	
	var oButton = new YAHOO.widget.Button({ type: "menu",
											id: "cal"+calField+"picker",
											label: "",
											menu: oCal,
											container: calField } );
	
	oButton.on("appendTo", function() {
		oCal.setBody("&#32"); // empty element to reserve space to render the Calender instance into
		oCal.body.id = "cal"+calField+"container";
		oCal.render(this.get("container")); // render Button into the container element
	});
	
	function onButtonClick() {
		var oCalendar = new YAHOO.widget.Calendar("button"+calField+"calendar", oCal.body.id);
		customizeCalendar(oCalendar);
		oCalendar.render();
	
		oCalendar.changePageEvent.subscribe(function() {
			window.setTimeout(function() {
					oCal.show();
				}, 0);
		});
	
		oCalendar.selectEvent.subscribe(function(p_sType, p_aArgs) {
			var aDate;
			if (p_aArgs) {
				aDate = p_aArgs[0][0];
				YAHOO.util.Dom.get(dagid).value = aDate[2];
				YAHOO.util.Dom.get(maandid).value = aDate[1];
				YAHOO.util.Dom.get(jaarid).value = aDate[0];
			}
			oCal.hide();
		});
	
		this.unsubscribe("click", onButtonClick); // unsubscribe, this code has to be executed once.
	}

	oButton.on("click", onButtonClick);
}

// maak tooltips reeks voor een pagina
function maakTooltips(callFields, calToolTipTexts) {
	for (var i = 0; i < callFields.length; i++) {
		e = xGetElementById(callFields[i]);
		if (e != null) {
			e.callFields = callFields;
			e.callPanel = new YAHOO.widget.Panel(callFields[i]+'Panel', {
				context: [callFields[i], 'bl', 'tr'],
				y: 10,
				underlay: "shadow",
				close: true,
				visible: false,
				draggable: true
				/*effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}*/
				} );

			e.callPanel.setHeader("Toelichting op "+callFields[i]);
			e.callPanel.setBody(calToolTipTexts[i]);

			e.callPanel.render(document.body);

			e.onfocus = function() {
				for (var i = 0; i < this.callFields.length; i++) {
					f = xGetElementById(this.callFields[i]);
					if (f != null) {
						f.callPanel.cfg.setProperty("visible", false);
					}
				}
				this.callPanel.cfg.setProperty("visible", true);
			}
		}
	}
}

function initTabUI(tabs, bgcolor1, bgcolor2, bgcolor3) {
	var tmp;
	var e;

	// init tabbladen filter
	// onmouseover werkt alleen als de gebruiker nog niet geklikt heeft in zijn sessie
	//YAHOO.util.Cookie.remove("if", { path: "/", domain: ".daysout.nl" } );

	if (bgcolor1 == null) { bgcolor1 = '#5fc35d'; }
	if (bgcolor2 == null) { bgcolor2 = '#fff'; }
	if (bgcolor3 == null) { bgcolor3 = '#000'; }

	for (var j = 0; j < tabs.length; j++) {
		e = xGetElementById(tabs[j]);	
		if (e != null) {
			e.tabs = tabs;
	
			e.onmouseover = function () {
				var initFilter = YAHOO.util.Cookie.get("if");
				if (initFilter == null) {
					for (var j = 0; j < this.tabs.length; j++) {
						e = xGetElementById(this.tabs[j]);	
						if (e != null) {
							e.style.backgroundColor = bgcolor2;
							e.style.color = bgcolor3;
							e.style.textDecoration = 'none';
							
							f = xGetElementById(e.id+'C');	
							f.style.display = 'none';
						}
					}
	
					this.style.backgroundColor = bgcolor1;
					this.style.color = bgcolor2;
					this.style.textDecoration = 'underline';
	
					e = xGetElementById(this.id+'C');	
					if (e != null) {
						YAHOO.util.Cookie.set("if", this.id, { path: "/", domain: ".daysout.nl" } );
						e.style.display = 'block';
					}
				} else {
					for (var j = 0; j < this.tabs.length; j++) {
						e = xGetElementById(this.tabs[j]);	
						if (e != null) {
							e.style.textDecoration = 'none';
						}
					}
					if (this.style.backgroundColor != bgcolor1) {
						this.style.textDecoration = 'underline';
					}
				}
			}
			
			e.onmouseout = function() {
				this.style.textDecoration = 'none';
			}
	
			e.onclick = function () {
				YAHOO.util.Cookie.set("if", this.id, { path: "/", domain: ".daysout.nl" } );
	
				for (var j = 0; j < this.tabs.length; j++) {
					e = xGetElementById(this.tabs[j]);	
					if (e != null) {
						e.style.backgroundColor = bgcolor2;
						e.style.color = bgcolor1;
						e.style.textDecoration = 'none';
	
						f = xGetElementById(e.id+'C');	
						f.style.display = 'none';
					}
				}
	
				this.style.backgroundColor = bgcolor1;
				this.style.color = bgcolor2;
				this.style.textDecoration = 'none';
	
				e = xGetElementById(this.id+'C');	
				if (e != null) {
					e.style.display = 'block';
				}
			}
		}
	}
}

function initTabContentUI(container, tabs, bgcolor1, bgcolor2, bgcolor3) {
	if (bgcolor1 == '') { bgcolor1 = '#27bdee'; }
	if (bgcolor2 == '') { bgcolor2 = '#fff'; }
	if (bgcolor3 == '') { bgcolor2 = '#000'; }

	e = xGetElementById(container);	
	if (e != null) {
		e.tabs = tabs;
	
		e.onmouseout = function() {
			var initFilter = YAHOO.util.Cookie.get("if");
			if (initFilter == null) {
				for (var j = 0; j < this.tabs.length; j++) {
					e = xGetElementById(this.tabs[j]);	
					if (e != null) {
						e.style.backgroundColor = bgcolor2;
						e.style.color = bgcolor3;
	
						f = xGetElementById(e.id+'C');	
						f.style.display = 'none';
					}
				}
			}
		}
	
		var initFilter = YAHOO.util.Cookie.get("if");
		e2 = xGetElementById(initFilter);
		if (e2 != null) {
			e2.style.backgroundColor = bgcolor1;
			e2.style.color = bgcolor2;
			e2.style.textDecoration = 'none';
	
			f = xGetElementById(e2.id+'C');	
			f.style.display = 'block';
		} else {
			YAHOO.util.Cookie.remove("if", { path: "/", domain: ".daysout.nl" } );
		}
	}
}
