/*	-------------------------------------------------------------------
	Comment this line to disable the popup windows. [EMAKINA]
	-------------------------------------------------------------------	*/
	addEvent(window, 'load', findPopUps, false);
	
/*	-------------------------------------------------------------------
	Update this Url depending on the server you are on. [EMAKINA]
	-------------------------------------------------------------------	*/
	url_NL = emakina['url_NL']; //"http://onderzoek.goudengids.nl";
	url_BE_NL = emakina['url_BE_NL']; //"http://onderzoek.goudengids.be";
	url_BE_FR = emakina['url_BE_FR']; //"http://etude.pagesdor.be";
	
	surveyurl_NL = emakina['surveyurl_NL']; 
	surveyurl_BE_NL = emakina['surveyurl_BE_NL']; 
	surveyurl_BE_FR = emakina['surveyurl_BE_FR'];	
	
	iframeurl = emakina['iframeurl'];
	jsurl = emakina['popupjsurl'];
	
/*	-------------------------------------------------------------------
	Update this Url depending on the server you are on. [TRUVO]
	-------------------------------------------------------------------	*/	
	popupurl = emakina['popupurl'];
	
/*	-------------------------------------------------------------------
	AddEvent
	-------------------------------------------------------------------	*/
	function addEvent(elm, evType, fn, useCapture)
	{
		if(elm.addEventListener)
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent)
		{
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else
		{
			elm['on' + evType] = fn;
		}
	}

/*	-------------------------------------------------------------------
	Create the popup window
	-------------------------------------------------------------------	*/
	var newWindow = null;

	function popUpWin(url, type, strWidth, strHeight)
	{				
		type = type.toLowerCase();
		
		
		//	Depending of the type :		
		var tools="";		
		if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";		
		else if (type == "console" ) tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=100,top=100";
				
		//	Create the url of the popup + the parameter to open the survey.		
		var tempUrl = popupurl + "?url=" + url;

		
		
		//	Open the popup
				
		newWindow = window.open(tempUrl, 'newWin', tools);
					
		//	Set Cookie
		setCookie("truvo_survey_temp", "done", "", "", "", "");
	
		//	Keep focus on current windows
		//newWindow.blur();				
		window.focus();
			
	}

/*	-------------------------------------------------------------------
	Methode call on onclick
	-------------------------------------------------------------------	*/
	function doPopUp(e)
	{
		if (clearToOpenPopup())
		{		
			//	set defaults - if nothing in rev attrib, these will be used
			var t = "console";
			var w = "690";
			var h = "630";
			var url = '';
			var bl;
			var lg;
					
			//	look for parameters			
			attribs = this.rev.split(";");		
			
			for(com in attribs)
			{			
			   
				//	Remove blank 
				value = attribs[com].replace(/ /g, "");
													
			    //	Remove quote from value
			    first = value.indexOf("'");
			    last =  value.lastIndexOf("'");
				if (first < last) value = value.substring(first+1, last);				
						
				//	Collect info
				switch(com)
				{					
					case '0' :    // BusinessUnit
						url += "?BusinessUnit=" + value;
						bl = value;						
						break;
					case '1' :    // Language
						url += "%26Language=" + value;
						lg = value;
						break;
					case '2' :    //  Categoty												
						url += "%26Category=" + value;
						break;
					case '3' :    // LinkSource
						url += "%26LinkSource=" + value;
						break;					
				}
													
			}					
			//  Choose the correct survey url
			switch (bl+'_'+lg)			
			{
			    case 'NL_NL' :
			        url = url_NL + surveyurl_NL + url;
			        break;
			    case 'BE_NL' :
			        url = url_BE_NL + surveyurl_BE_NL + url;
			        break;
			    case 'BE_FR' :
			        url = url_BE_FR + surveyurl_BE_FR + url;
			        break;
			}	
			//	Call the popup script		
			popUpWin(url, t, w, h);
		}					
	}

/*	-------------------------------------------------------------------
	Add onclick event for all link with rev and popup="true"
	-------------------------------------------------------------------	*/		
	function findPopUps()
	{		
				
		var popups = document.getElementsByTagName("a");
		for (i=0; i<popups.length; i++)
		{				
			if (popups[i].rev != "")
			{
				//	Attach popup behaviour
				//popups[i].onclick = doPopUp;	Removed and replaced with friendly method to do the same thing. - Kristofer Baxter (LMI)
				//LMI.BrowserEvent.bind( popups[i], 'click', popups[i], doPopUp );
				YAHOO.util.Event.addListener( popups[i], 'click', doPopUp, popups[i] );			
			}
		}		
		
	}
	
/*	-------------------------------------------------------------------
	Check //	Create  COOKIES
	-------------------------------------------------------------------	*/	
	function clearToOpenPopup()				//	Return true if the popup can be created
	{
		var ret = false;
		if (getCookie ( "truvo_survey") != null )
		{		
			//alert("truvo_survey");
			if (getCookie ( "truvo_survey_temp") != null )
			{						
				//alert("truvo_survey_temp");
				ret = true;
			}
		}
		else
		{			
			var d = new Date();
			//	Expiration date
			if (d.getMonth() == 12)			
				d.setMonth(1);
			else
				d.setMonth(d.getMonth() +1);
				
			//	One month cookie to tell that the popup can't be open
			setCookie("truvo_survey", "done", d.toGMTString(), "", "", ""); 
			
			//	Temp cookie to tell that the popup must be open during the current session
			setCookie("truvo_survey_temp", "done", "", "", "", "");
			ret = true;
		}
		return ret;
	}

	
	function getCookie ( cookie_name )
	{
	
		//alert("getCookie : " + cookie_name);
		var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
		//alert("getCookie END");

		if ( results )
			return ( unescape ( results[2] ) );
		else
			return null;
	}
	
	function setCookie ( name, value, expire, path, domain, secure )
	{
		//alert("setCookie : " + name);
		var cookie_string = name + "=" + escape ( value );

		if ( expire )				
			cookie_string += "; expires=" + expire;
		
		if ( path )
			cookie_string += "; path=" + escape ( path );

		if ( domain )
			cookie_string += "; domain=" + escape ( domain );

		if ( secure )
			cookie_string += "; secure";
		
		document.cookie = cookie_string;
		//alert("setCookie END");
	}
	
	function deleteCookie ( cookie_name )
	{
		  var d = new Date ( );  // current date & time
		  d.setTime ( d.getTime() - 1 );
		  document.cookie = cookie_name += "=; expires=" + d.toGMTString();
	}
	
/*	------------------------------------------------------
	PopupAction
	------------------------------------------------------	*/
	function unloadIt()	
	{		
		//alert("unloadIt");
		deleteCookie("truvo_survey_temp");
	}
