var MetrixLab_OverlayType = 'entry';

var MetrixLab_PopupFolderName = 'p09646_ie';
var MetrixLab_ProjectNumber = 'p09646_ie';
var MetrixLab_CookieFolderName = 'p09646_ie';

//if true the MetrixLab_CookieFolderName name should be the same in all projects
var MetrixLab_GLOB_CookieSetup = false;

var MetrixLab_PrivacyLanguage = 'en';

var MetrixLab_DivStartLeft = '400';
var MetrixLab_DivStartTop = '180';

var MetrixLab_OverlayWidth = 350;
var MetrixLab_OverlayHeight = 300;

var MetrixLab_Coordinate_YesButton = '61,253,158,279';
var MetrixLab_Coordinate_NoButton = '192,253,289,280';
var MetrixLab_Coordinate_CloseButton = '316,5,351,24';
var MetrixLab_Coordinate_PrivacyButton = '285,285,344,300';
var MetrixLab_Coordinate_MetrixButton = '203,287,269,300';

var MetrixLab_AutoCloseInterval=0;
var MetrixLab_ForceData='0';

var MetrixLab_CookieName = "MetrixLab"+MetrixLab_CookieFolderName;
var MetrixLab_UserID='';

var MetrixLabGLOB_cookie;
var MetrixLabGLOB_Try_count = 20;



function MetrixLab_SetUserID()
{
	var Today = new Date();
	MetrixLab_UserID=''+Today.getFullYear()+'_'+(Today.getMonth()+1)+'_'+Today.getDate()+'_'+Today.getHours()+'_'+Today.getMinutes()+'_'+Today.getSeconds()+'_'+Today.getMilliseconds();	
}

function MetrixLab_isCookieEnabled()
{
    var cookieEnabled=(navigator.cookieEnabled)? true : false
    
    if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)
    { 
	    document.cookie="MetrixLabTestCookie"
	    cookieEnabled=(document.cookie.indexOf("MetrixLabTestCookie")!=-1)? true : false
    }    
    return cookieEnabled;      	
}

function MetrixLab_GetRandomNumber(MetrixLab_minValue,MetrixLab_maxValue)
{
    var MetrixLab_result = 0;

    if (MetrixLab_minValue<=MetrixLab_maxValue)
    {
	    MetrixLab_result=Math.round((Math.random()*(MetrixLab_maxValue-MetrixLab_minValue+1))+MetrixLab_minValue-0.5);
	}	
	return MetrixLab_result;
}

function MetrixLab_SetCookie()
{
    var MetrixLab_expires = new Date();
	MetrixLab_expires.setTime(MetrixLab_expires.getTime() + (180*24*60*60*1000));
	document.cookie = MetrixLab_CookieName+"=1; expires=" + MetrixLab_expires.toGMTString() + "; path=/;";

	if (MetrixLab_GLOB_CookieSetup)
	{	
		MetrixLab_GLOB_setCookie();
	}
}


function MetrixLab_ShowOverlay()
{
	MetrixLab_SetUserID();
    MetrixLab_SetCookie();
    MetrixLab_LoadOverlay();
    if (MetrixLab_AutoCloseInterval>0)
    {
            setTimeout("MetrixLab_CloseBanner();",MetrixLab_AutoCloseInterval*1000);
    }
}


function MetrixLab_GLOB_setCookie()
{
	var MetrixLabGLOB_Time = new Date();
	var MetrixLabGLOB_Script = document.createElement('script');
	MetrixLabGLOB_Script.src='http://invitation.opinionbar.com/popups/'+MetrixLab_PopupFolderName+'/cookie.asp?s='+MetrixLab_CookieName+'_GLOB&m=set&t='+MetrixLabGLOB_Time.getTime();
	MetrixLabGLOB_Script.type='text/javascript';
	var MetrixLabGLOB_Body = document.getElementsByTagName('body').item(0);
	MetrixLabGLOB_Body.appendChild(MetrixLabGLOB_Script); 
}



function MetrixLab_GLOB_getCookie()
{
	var MetrixLabGLOB_Time = new Date();
	var MetrixLabGLOB_Script = document.createElement('script');
	MetrixLabGLOB_Script.src='http://invitation.opinionbar.com/popups/'+MetrixLab_PopupFolderName+'/cookie.asp?s='+MetrixLab_CookieName+'_GLOB&m=get&t='+MetrixLabGLOB_Time.getTime();
	MetrixLabGLOB_Script.type='text/javascript';
	var MetrixLabGLOB_Body = document.getElementsByTagName('body').item(0);
	MetrixLabGLOB_Body.appendChild(MetrixLabGLOB_Script); 
}


function MetrixLabGLOB_checkCookie()
{                
    if (typeof MetrixLabGLOB_cookie != "undefined")
    {     
		if (MetrixLabGLOB_cookie==false)     
		{                         
			//cookie not set
			MetrixLab_ShowOverlay();
		}
		else
		{
			//cookie set
		}
		
    }
	else
	{ 
		MetrixLabGLOB_Try_count--;
		if (MetrixLabGLOB_Try_count>0)
		{
			setTimeout('MetrixLabGLOB_checkCookie();',500);
		}
	}
}

function MetrixLab_CheckCookie()
{
	if (document.cookie.indexOf(MetrixLab_CookieName)==-1)
	{
		if (MetrixLab_GLOB_CookieSetup)
		{
			MetrixLab_GLOB_getCookie();
			MetrixLabGLOB_checkCookie();
		}
		else
			MetrixLab_ShowOverlay();
	}
	 
}

function MetrixLab_CheckIntercept()
{
	
    MetrixLab_RandomNumber = MetrixLab_GetRandomNumber(1,MetrixLab_Intercept);
    if (MetrixLab_RandomNumber==1)
    {
        MetrixLab_CheckCookie();
    }
}

function MetrixLab_GoToPrivacy()
{
	PopupPrivacy = window.open('http://www.opinionbar.com/privacy.aspx?lang='+MetrixLab_PrivacyLanguage+'&coun='+MetrixLab_PrivacyLanguage,'PopupPrivacy','resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,width=750,height=450');
}

function MetrixLab_GoToMetrixLab()
{
	PopupPrivacy = window.open('http://www.MetrixLab.com/','PopupPrivacy','resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,width=750,height=450');
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function MetrixLab_GoToWebSurvey()
{
    switch(MetrixLab_OverlayType)
    {
        case 'entry':
            MetrixLab_GoToWebSurveyEntry();
        break;
        case 'exit':
            MetrixLab_GoToWebSurveyExit();
        break;
        case 'entryexit':
            MetrixLab_GoToWebSurveyEntryExit();
        break;
    }
}

function MetrixLab_GoToWebSurveyEntry()
{
	var i,j=-1;
	var Cookie_Array = new Array();
	for(i=1;i<=4;i++)
	{
		if(getCookie('p09646_ie_tracking_'+i))
		 {
		 j++;
		 Cookie_Array[j]=i;
		 }
	}
	if(j>-1)
	{
		MetrixLab_ForceData='';
		for(i=0;i<Cookie_Array.length;i++)
		{
			MetrixLab_ForceData+="5555,"+Cookie_Array[i]+",;";
		}
	}
	else
	{
		MetrixLab_ForceData='0';
	}
    if (MetrixLab_ForceData=='0')
    {					
        PopupWebSurvey = window.open('http://websurvey2.opinionbar.com/go.asp?s='+MetrixLab_ProjectNumber+'&c=overlay&t=4','PopupWebSurvey','resizable=yes,scrollbars=yes,toolbar=no,menubar=no,width=750,height=450');					
    }
    else
    {
        PopupWebSurvey = window.open('http://websurvey2.opinionbar.com/go.asp?s='+MetrixLab_ProjectNumber+'&c=overlay&t=4&f=;'+MetrixLab_ForceData+'','PopupWebSurvey','resizable=yes,scrollbars=yes,toolbar=no,menubar=no,width=750,height=450');
    }				

    MetrixLab_CloseBanner();
}

function MetrixLab_GoToWebSurveyExit()
{
   MetrixLab_SetCookie();
   MetrixLab_ShowPopupEntryExit();
   MetrixLab_CloseBanner();
}

function GoTowebSurveyEntryExit()
{
   MetrixLab_SetCookie();
   MetrixLab_ShowPopupEntryExit();
   MetrixLab_CloseBanner();
}

function MetrixLab_CloseBanner()
{
    var MetrixLab_Div=document.getElementById('MetrixLab_Div');
    if (MetrixLab_Div)
    {
        MetrixLab_Div.parentNode.removeChild(MetrixLab_Div);
    }
}

function MetrixLab_ShowPopupEntryExit()
{
	
	MetrixLab_PopupAttributes="resizable=yes,scrollbars=yes,toolbar=no,menubar=no,width=390,height=370";
	
	MetrixLab_PopupWin=open('inv.htm', 'new_window', MetrixLab_PopupAttributes);
	MetrixLab_PopupWin.document.write('<html><head><title></title></head>');
	MetrixLab_PopupWin.document.write('<body>');
	
	
	MetrixLab_PopupWin.document.write('<scr'+'ipt>');
	MetrixLab_PopupWin.document.write("var metrixlab_userid='"+MetrixLab_UserID+"';");
	MetrixLab_PopupWin.document.write("var metrixlab_ForceData='"+MetrixLab_ForceData+"';");
	MetrixLab_PopupWin.document.write('</scr'+'ipt>');	
	MetrixLab_PopupWin.document.write("<script language='javascript' src='http://invitation.opinionbar.com/popups/"+MetrixLab_PopupFolderName+"/exit.js'>");
	MetrixLab_PopupWin.document.write('</scr'+'ipt>');
	
	
	MetrixLab_PopupWin.document.write('</body></html>');	
	MetrixLab_PopupWin.blur();
	
}

function Metrixlab_SetDivVisible()
{
	document.getElementById('MetrixLab_overlay').style.display='block';
}

function metrixlab_onready(el, func){
	this.args = new Array(el, func)
	this.doTry = function(){
			try{
					var el = eval(this.args[0])
					el.onloading = this.args[1]
					el.onloading()
					clearInterval(this.args[2])
			}
			catch(e){}
	}
	this.doTry.bind = function(object){
			var method = this;
			return function(){
					method.apply(object);
			}
	}
	this.args[2] = setInterval(this.doTry.bind(this), 250);
	return this
}

function MetrixLab_LoadOverlay()
{    
    var MetrixLab_HTMLString="";
    MetrixLab_HTMLString += "<MAP name='MetrixLab_Popup_Map'>\n";
    MetrixLab_HTMLString += " <AREA shape='rect' coords='"+MetrixLab_Coordinate_YesButton+"' href='javascript:MetrixLab_GoToWebSurvey();' target='_self'>\n";
    MetrixLab_HTMLString += " <AREA shape='rect' coords='"+MetrixLab_Coordinate_NoButton+"' href='javascript:MetrixLab_CloseBanner();' target='_self'>\n";
    MetrixLab_HTMLString += " <AREA shape='rect' coords='"+MetrixLab_Coordinate_CloseButton+"' href='javascript:MetrixLab_CloseBanner();' target='_self'>\n";
    MetrixLab_HTMLString += " <AREA shape='rect' coords='"+MetrixLab_Coordinate_PrivacyButton+"' href='javascript:MetrixLab_GoToPrivacy();' target='_self'>\n";
    MetrixLab_HTMLString += " <AREA shape='rect' coords='"+MetrixLab_Coordinate_MetrixButton+"' href='javascript:MetrixLab_GoToMetrixLab();' target='_self'>\n";    
    MetrixLab_HTMLString += "</MAP>\n";
    MetrixLab_HTMLString += "<div id='MetrixLab_overlay' style='display:none;position:absolute; z-index:9999; left: "+MetrixLab_DivStartLeft+"px; top: "+MetrixLab_DivStartTop+"px;'>";    
    MetrixLab_HTMLString += "<img onload='Metrixlab_SetDivVisible();' src='"+MetrixLab_BasePath+"overlay.gif' USEMAP='#MetrixLab_Popup_Map' alt='' border='0' width='"+MetrixLab_OverlayWidth+"' height='"+MetrixLab_OverlayHeight+"' name='MetrixLab_overlay_gif' id='MetrixLab_gif'>";    
    MetrixLab_HTMLString += "</div>";
    
    var MetrixLab_Body=document.getElementsByTagName('body').item(0);
    var MetrixLab_Div = document.createElement('div');
    MetrixLab_Div.style.display='block';
    MetrixLab_Div.id='MetrixLab_Div';
    MetrixLab_Div.innerHTML = MetrixLab_HTMLString;
    MetrixLab_Body.appendChild(MetrixLab_Div);
}
function MetrixLab_AddEvent(object, type, handler)
{
	if (object.addEventListener) 
	{
		object.addEventListener(type, handler, false);
	} 
	else if (object.attachEvent) 
	{
		object.attachEvent(['on',type].join(''),handler);
	} 
	else 
	{
		object[['on',type].join('')] = handler;
	}
} 

MetrixLab_AddEvent(window,"load",MetrixLab_CheckIntercept);