/**
 * @author Christophe
 * TO DO : 
 * 	- detect Pop-In type
 * 	- Communication API (Cookie Transfer, Buffer)
 * 	- Add interactive mode
 */


/* 
 * Class Helper
 */

var Cappture = {
	IE: false,
	IE6: false,
 	IE8: false,
	IsSSL: (('https:' == document.location.protocol) ? 's' : ''),
	isLoaded: false
};


Cappture.XML = function(pb_IsXSLTemplate)
{
	this._loaded = false;
	this._XML = null;
	this._Evaluate_Result = null;
	this._IsXSLTemplate = (pb_IsXSLTemplate || false);
};

Cappture.XML.prototype.load = function (ps_URL, po_Options){
	this._XML = null;
	if(document.implementation && document.implementation.createDocument){
		// *** load the XSL file
		var lo_XMLHTTPRequest = new XMLHttpRequest();
		lo_XMLHTTPRequest.open('GET', ps_URL, false);
		lo_XMLHTTPRequest.send(null);
		// *** get the XML document
		this._XML = lo_XMLHTTPRequest.responseXML;
	}else if(window.ActiveXObject){
		// *** IE
		// *** Load XML
		this._XML = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		this._XML.async = false;
		this._XML.load(ps_URL);

	}else{
		// *** Browser unknown
	}
	this._loaded = (this._XML != null);
	return this._loaded;
};
Cappture.XML.prototype.loadXML= function (ps_XML){
	this._XML = null;
	//On suppose dans un premier temps que la requÃªte est correctement formÃ©e
	try{
		if(document.implementation && document.implementation.createDocument){
			//xmlObj = document.implementation.createDocument("", "", null);
			var parser = new DOMParser();
			this._XML = parser.parseFromString(ps_XML, "text/xml");
		}else{
			if (this._IsXSLTemplate) {
				this._XML = new ActiveXObject('Msxml2.FreeThreadedDOMDocument');
			}
			else {
				this._XML = new ActiveXObject('Msxml2.DOMDocument');
			}
			this._XML.loadXML(ps_XML);
		}
		this._loaded = true;
	}catch(e){
		this._loaded = false;
		return false;
	}
	return true;
};
Cappture.XML.prototype.IsLoaded = function (){
	return this._loaded;
};

Cappture.XML.prototype.xml = function (){
	return this._XML.xml;
};

Cappture.XML.prototype.runTransform = function (px_StyleSheet){
	if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		var xsltProcessor2 = new XSLTProcessor();
		// *** load the XSL file
		xsltProcessor.importStylesheet(px_StyleSheet);
		var resultDocument = xsltProcessor.transformToFragment(this._XML, document);
		return resultDocument.firstChild.innerHTML;
	}else if(window.ActiveXObject){
		// *** IE
		// *** Transform
		return this._XML.transformNode(px_StyleSheet);
	}
	
	return '';
};

Cappture.Utils = {	
	getInternetExplorerVersion: function()
	{
	    var rv = -1; // Return value assumes failure.
	    if (navigator.appName == 'Microsoft Internet Explorer') 
		{
	        var ua = navigator.userAgent;
	        var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
	        if (re.exec(ua) != null) {rv = parseFloat(RegExp.$1);}
	    }
	    return rv;
	},
	
	initialize: function()
	{
		Cappture.IE = window.ActiveXObject ? true : false;
		//Detect IE 6
		if (Cappture.IE) 
		{
			
			if (typeof document.body.style.maxHeight == 'undefined') {Cappture.IE6 = true;}
			
			Cappture.IE8 = (parseInt(this.getInternetExplorerVersion()) > 7);
		}
		Cappture.Events.domReady.add(function(){Cappture.IsLoaded = true;});
		
	},
	Left:function (str, n){
		if (n <= 0){
			return '';
		}
		else if (n > String(str).length)
		{
			return str;
		}
		else
		{
			return String(str).substring(0, n);
		}
	},
	Right:function (str, n){
	    if (n <= 0)
		{
			return "";
		}
	    else if (n > String(str).length)
		{
			return str;
		}
	    else {
	       var iLen = String(str).length;
	       return String(str).substring(iLen, iLen - n);
	    }
	},
	getParameter: function(ps_String, ps_Parameter)
	{
		ps_Parameter = ps_Parameter.replace(/[\[]/gi,'\\\[').replace(/[\]]/gi,'\\\]');
		var ls_regexS = '[\\?&]' + ps_Parameter + '=([^&#]*)';
		var ls_regex = new RegExp( ls_regexS, 'i' );
		var ls_results = ls_regex.exec( ps_String );
		if( ls_results == null ){
			return '';
		}
		else{
			return unescape(ls_results[1]);
		}
	},
	tweetMe: function ()
	{
		if (typeof Cappture.tweet == 'undefined') {
			return;
		}
		//sendTwitter('Cappture_Popin', '', 'It Works: ' + document.location.href)
	},

	sendTweet:function ()
	{
		if (typeof Cappture.tweet == 'undefined') {
			return;
		}	
		if(typeof(gb_Cappture_Connect_Demo) != 'undefined' && gb_Cappture_Connect_Demo)
		{
			document.getElementById('Cappture_Tube').src='http' + Cappture.IsSSL + '://tracker1.cappture.com/' + gi_Cappture_Domain_Id + '/Cappture_Connect_Twitter_Send.aspx?url_source=' + escape(Cappture_Querystring_Parameter_Get('url_source'));		
		}
		else
		{
			document.getElementById('Cappture_Tube').src='http' + Cappture.IsSSL + '://tracker1.cappture.com/' + gi_Cappture_Domain_Id + '/Cappture_Connect_Twitter_Send.aspx?url_source=' + escape(document.location.href);
		}
		return;
	},
	getType: function(po_Object){
		if (typeof(po_Object) == 'undefined') {return false;}
		if (po_Object == null) {return false;}
		if (po_Object.htmlElement){return 'element';}
		var type = (typeof po_Object);
		if (type == 'object' && po_Object.nodeName){
			switch(po_Object.nodeType){
				case 1: return 'element';
				case 3: return (/\S/).test(po_Object.nodeValue) ? 'textnode' : 'whitespace';
			}
		}
		if (type == 'object' || type == 'function'){
			switch(po_Object.constructor){
				case Array: return 'array';
				case RegExp: return 'regexp';
				//case Class: return 'class';
			}
			if (typeof po_Object.length == 'number'){
				if (po_Object.item) return 'collection';
				if (po_Object.callee) return 'arguments';
			}
		}
		return type;
	},
	getPosition: function(pe_Element)
	{	
		var el = pe_Element, left = 0, top = 0;
		
		do {
			left += el.offsetLeft || 0;
			top += el.offsetTop || 0;
			el = el.offsetParent;
			
		} while (el);
		return {'x': left, 'y': top};
	},
	getCoordinates: function(pe_Element){
		var position = Cappture.Utils.getPosition(pe_Element);
		var obj = {
			'width': pe_Element.offsetWidth,
			'height': pe_Element.offsetHeight,
			'left': position.x,
			'top': position.y
		};
		obj.right = obj.left + obj.width;
		obj.bottom = obj.top + obj.height;
		return obj;
	},
	createURL: function(ps_File)
	{
		if(typeof(gs_Cappture_RootFolder) != 'undefined')
		{
			return gs_Cappture_RootFolder + ps_File;
		}
		else
		{
			//test
			//return 'http' + Cappture.IsSSL + '://192.168.0.200/' + gi_Cappture_Domain_Id + '/' + ps_File;
			 //return 'http' + Cappture.IsSSL + '://192.168.0.24/' + gi_Cappture_Domain_Id + '/' + ps_File;
			 return 'http' + Cappture.IsSSL + '://tracker1.cappture.com/' + gi_Cappture_Domain_Id + '/' + ps_File;	
		}
	},
	createDatabaseURL: function(ps_Query, ps_Database_Name, ps_Database_Type)
	{
		var ls_URL = '';
		ls_URL += 'Cappture_XQR.aspx?XQuery=' + escape(ps_Query) 
		if(typeof ps_Database_Name != 'undefined' && ps_Database_Name != '')
		{
			ls_URL += '&DatabaseName=' + escape(ps_Database_Name)
		}
		else
		{
			ls_URL += '&DatabaseName=default'
		}
		
		if(typeof ps_Database_Type != 'undefined' && ps_Database_Type != '')
		{
			ls_URL += '&DatabaseType=' + escape(ps_Database_Type);
		}
		else
		{
			ls_URL += '&DatabaseType=XML';
		}
		return Cappture.Utils.createURL(ls_URL);
	},
	toJSON: function (po_Object)
	{
		switch(Cappture.Utils.getType(po_Object)){
			case 'string':
				return '"' + po_Object.replace(/(["\\])/g, '\\$1') + '"';
			case 'array':
				var ls_Result = '';
				for(var li_Index = 0; li_Index < po_Object.length; li_Index++)
				{
					if(li_Index > 0) ls_Result += ','
					ls_Result += Cappture.Utils.toJSON(po_Object[li_Index]);
				}
				return '[' + ls_Result + ']';
			case 'object':
				var string = [];
				for (var property in po_Object) string.push(Cappture.Utils.toJSON(property) + ':' + Cappture.Utils.toJSON(po_Object[property]));
				return '{' + string.join(',') + '}';
			case 'number':
				return po_Object.toString();
			case 'function':
				return '';
			case false:
				return 'null';
		}
		return String(po_Object);
	
	}
	
};

Cappture.Utils.QueryString = {
	Parameter_Get: function(ps_Name)
	{
		ps_Name = ps_Name.replace(/[\[]/gi,'\\\[').replace(/[\]]/gi,'\\\]');
		var ls_regexS = '[\\?&]' + ps_Name + '=([^&#]*)';
		var ls_regex = new RegExp( ls_regexS, 'i' );
		var ls_results = ls_regex.exec( window.location.href );
		if( ls_results == null ){
			return '';
		}
		else{
			return unescape(ls_results[1]);
		}
	},
    Hash_Get: function()
	{
		return document.location.hash;
	}
}


Cappture.Event = 
{ 
   x:0, 
   y:0,
   evt: null,
   id:null,
   init: function(evt) 
   { 
      this.evt=(evt) ? evt : window.event; // l'objet événement 
      if (!this.evt) {return;} 
      this.elt=(this.evt.target) ? this.evt.target : this.evt.srcElement; // la source de l'événement 
    
      this.id=(this.elt) ? this.elt.id : ""; 
 
      // Calcul des coordonnées de la souris par rapport au document 
 
      if (this.evt.pageX || this.evt.pageY) 
      { 
         this.x = this.evt.pageX; 
         this.y = this.evt.pageY; 
      } 
      else if (this.evt.clientX || this.evt.clientY) 
      { 
         this.x = this.evt.clientX + document.body.scrollLeft; 
         this.y = this.evt.clientY + document.body.scrollTop; 
      } 
   },
  // Cappture.Event.prototype.init=init; 
 
   stop:function()    { 
      this.evt.cancelBubble = true; 
      if (this.evt.stopPropagation) {this.evt.stopPropagation();}    
   },
	registerEvent: function(po_Object, ps_EventName, po_Bind, ps_HandlerName, po_Arguments)
	{
		var lo_fn = po_Object['on' + ps_EventName];
		
		
		 var lo_Function = function(pe_Event){
		 	if (typeof lo_fn == 'function') {lo_fn(pe_Event);}
		 	po_Bind[ps_HandlerName].apply(po_Bind, [pe_Event].concat(po_Arguments));
//		 	Cappture_EventFunctionHelper.apply(null, [po_Bind, ps_HandlerName, po_Arguments, pe_Event])();
			return;
		};
		
		if(po_Object)
	    {
	        if (po_Object.attachEvent)
	        {
	            po_Object.attachEvent ('on' + ps_EventName, lo_Function);
	        } 
	        else if (po_Object.addEventListener) 
	        {
	            po_Object.addEventListener (ps_EventName, lo_Function, false);
	        } 
	        else
	        {
	            po_Object['on' + ps_EventName] = lo_Function;
	        }
	    }
		return;
	} 
};
Cappture.Event.Scroll = function (pi_Threshold, po_Object, po_Handle)
{
	this.ctype = 'Event.Scroll';
	if(po_Handle == null) {
		this._Handle = Cappture_FunctionHelper(po_Object, 'Display', true);	
	}
	else{
		this._Handle = po_Handle;
	}	
	if (pi_Threshold < 0)
	{
		pi_Threshold = Math.abs(pi_Threshold) % 100;
		
		this._Threshold = function(){
			return (pi_Threshold * (Cappture.Utils.Window.getPageSizeWithScroll()[1] - Cappture.Utils.Window.Get_Size().top) / 100)
		};
		
	}
	else
	{
		this._Threshold = pi_Threshold;
		this._Threshold = function(){	
			var li_MaxScrollHeight = Cappture.Utils.Window.getPageSizeWithScroll()[1] - Cappture.Utils.Window.Get_Size().top;
			var li_RealPageHeight = Cappture.Utils.Window.getPageSizeWithScroll()[1];
			var lf_TargetPercent = (100 * pi_Threshold) / li_MaxScrollHeight;
			//I search for a percent of scroll
			return (lf_TargetPercent * li_MaxScrollHeight) / 100;
		};
	}	

	this._Object = po_Object;
}

Cappture.Events = {
	
	domReady: {
	    add: function(fn) {
	        //-----------------------------------------------------------
	        // Already loaded?
	        //-----------------------------------------------------------
	        if (Cappture.Events.domReady.loaded) {return fn();}
	        //-----------------------------------------------------------
	        // Observers
	        //-----------------------------------------------------------
	        var observers = Cappture.Events.domReady.observers;
	        if (!observers) {observers = Cappture.Events.domReady.observers = [];}
	        // Array#push is not supported by Mac IE 5
	        observers[observers.length] = fn;
	        //-----------------------------------------------------------
	        // domReady function
	        //-----------------------------------------------------------
	        if ( Cappture.Events.domReady.callback) {return;}
	        Cappture.Events.domReady.callback = function() {
	            if (Cappture.Events.domReady.loaded) {return;}
	            Cappture.Events.domReady.loaded = true;
	            if (Cappture.Events.domReady.timer) {
	                clearInterval(Cappture.Events.domReady.timer);
	                Cappture.Events.domReady.timer = null;
	            }
	            var observers = Cappture.Events.domReady.observers;
	            for (var i = 0, length = observers.length; i < length; i++) {
	                var fn = observers[i];
	                observers[i] = null;
	                fn();
	                // make 'this' as window
	                
	            }
	            Cappture.Events.domReady.callback = Cappture.Events.domReady.observers = null;
	        };
	        //-----------------------------------------------------------
	        // Emulates 'onDOMContentLoaded'
	        //-----------------------------------------------------------
	        var ie = !!(window.attachEvent && !window.opera);
	        var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1;
	        if (document.readyState && webkit) {
	            // Apple WebKit (Safari, OmniWeb, ...)
	            Cappture.Events.domReady.timer = setInterval(function() {
	                var state = document.readyState;
	                if (state == 'loaded' || state == 'complete') {
	                    Cappture.Events.domReady.callback();
	                }
	            },
	            50);
	        } else if (document.readyState && ie) {
	            // Windows IE
	            var src = (window.location.protocol == 'https:') ? '://0': 'javascript:void(0)';
	            document.write('<script type="text/javascript" defer="defer" src="' + src + '" ' + 'onreadystatechange="if (this.readyState == \'complete\')  Cappture.Events.domReady.callback();"' + '><\/script>');
	        } else {
	            if (window.addEventListener) {
	                // for Mozilla browsers, Opera 9
	                document.addEventListener("DOMContentLoaded", Cappture.Events.domReady.callback, false);
	                // Fail safe
	                window.addEventListener("load", Cappture.Events.domReady.callback, false);
	            } else if (window.attachEvent) {
	                window.attachEvent('onload', Cappture.Events.domReady.callback);
	            } else {
	                // Legacy browsers (e.g. Mac IE 5)
	                var fn = window.onload;
	                window.onload = function() {
	                    Cappture.Events.domReady.callback();
	                    if(fn){fn();}
	                }
	            }
	        }
	    }
	}
}
;



Cappture.Element = function(id) 
{ 
   this.id = id; 
   this.elt =(this.id) ? document.getElementById(id) : null; 
 
   function getX() 
   { 
      return this.elt.offsetLeft; 
   } 
   Cappture.Element.prototype.getX=getX; 
 
 
   function getY() 
   { 
      return this.elt.offsetTop; 
   } 
   Cappture.Element.prototype.getY=getY; 
 
   function setX(x) 
   { 
      return this.elt.style.left=x+"px"; 
   } 
   Cappture.Element.prototype.setX=setX; 
 
   function setY(y) 
   { 
      return this.elt.style.top=y+"px" 
   } 
   Cappture.Element.prototype.setY=setY; 
 
} 


Cappture.Element.Draggable = function(id) 
{ 
   if (!id) {return;} 
   this.base=Cappture.Element; 
 
   this.base(id); 
   this.elt.obj=this 
   this.elt.onmousedown=Cappture.Event.startDrag; 
 
   function startDrag(evt) 
   { 
      this.elt.style.zIndex=1; 
      this.lastMouseX=evt.x; 
      this.lastMouseY=evt.y; 
      evt.dragObject=this; 
 
      document.onmousemove=Cappture.Event.drag; 
      document.onmouseup=Cappture.Event.stopDrag; 
 
      if (this.onStartDrag){this.onStartDrag();}
   } 
   Cappture.Element.Draggable.prototype.startDrag = startDrag;    
 
   function stopDrag(evt) 
   { 
      this.elt.style.zIndex=0; 
      evt.dragObject=null; 
      document.onmousemove=null; 
      document.onmouseup=null; 
 
      if (this.onDrop) {this.onDrop();} 
   } 
   Cappture.Element.Draggable.prototype.stopDrag=stopDrag; 
 
   function drag(evt) 
   {    
      dX=this.getX()+evt.x-this.lastMouseX; 
      dY=this.getY()+evt.y-this.lastMouseY; 
 
      this.setX(dX); 
      this.setY(dY); 
       
      this.lastMouseX=evt.x; 
      this.lastMouseY=evt.y; 
 
      if (this.onDrag) {this.onDrag();} 
 
   } 
   Cappture.Element.Draggable.prototype.drag=drag; 
};
Cappture.Element.Draggable.prototype = new Cappture.Element();

Cappture.Event.startDrag = function(evt) 
{ 
   Cappture.Event.init(evt); 
   if (this.obj && this.obj.startDrag) 
   { 
      this.obj.startDrag(Cappture.Event); 
   } 
} 
 
Cappture.Event.stopDrag = function stopDrag(evt) 
{ 
   if (Cappture.Event.dragObject) Cappture.Event.dragObject.stopDrag(Cappture.Event); 
} 
 
Cappture.Event.drag = function(evt) 
{ 
   Cappture.Event.init(evt); 
   if (Cappture.Event.dragObject) {Cappture.Event.dragObject.drag(Cappture.Event);} 
   return false; 
}

//Cappture.Element.Draggable.prototype = new Cappture.Element();



Cappture.Cookie = {
	Names: {PRGM: 'CSM_PMGR', TESTM: 'CSM_TestMode', LVSSID:'CSM_LVSSID', POPINTEST: 'CSM_GRP_TEST', GRPSEED:'CSM_GRP_SEED', GRPPART:'CSM_GRP_PART'},
	'delete': function (ps_Name)
	{
		var timestamp= new Date();
		timestamp.setTime (timestamp.getTime()-10);
		document.cookie = ps_Name + "=" + escape('') + "; path=/; expires=" + timestamp.toGMTString();
	},
	get: function(ps_Name){
		var la_Cookies = document.cookie.split(/;\s?/);
		for(var i=0; i < la_Cookies.length; i++){
			var la_Cookies_Name_Value = la_Cookies[i].split(/=/);		
			if(la_Cookies_Name_Value[0] == ps_Name){return unescape(la_Cookies_Name_Value[1])}
		}
		return '';
	},
	set:function(ps_Name, ps_Value)
	{
		//Set expiry to end of day
		var ld_Date = new Date();
		var ld_Cookie_Expiry_Date = new Date(ld_Date.getFullYear(), ld_Date.getMonth(), ld_Date.getDate(), 23, 59, 59, 999);
		//timestamp.setTime (timestamp.getTime()+ (24*60*60*1000));
		document.cookie = ps_Name + "=" + escape(ps_Value) + "; path=/; expires=" + ld_Cookie_Expiry_Date.toGMTString();
	},
	reset:function ()
	{
		var timestamp= new Date();	
		timestamp.setTime (timestamp.getTime() - 10);
		document.cookie = Cappture.Cookie.Names.PRGM + "=" + escape('') + "; path=/; expires=" + timestamp.toGMTString();
		return;
	},
	setWithExpiry: function (ps_Name, ps_Value, pi_Expiry)
	{
		//Set expiry to end of day
		var ld_Date = new Date();
		li_Time = (ld_Date.getTime() + pi_Expiry);
		var ld_Cookie_Expiry_Date = new Date(li_Time);
		//timestamp.setTime (timestamp.getTime()+ (24*60*60*1000));
		document.cookie = ps_Name + "=" + escape(ps_Value) + "; path=/; expires=" + ld_Cookie_Expiry_Date.toGMTString();
	}	
}

Cappture.Utils.Window = {
	Get_Size:function ()
	{
		if( typeof( window.innerWidth ) == 'number' )
		{
			xScroll = window.innerWidth;yScroll = window.innerHeight;
		}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			xScroll = document.documentElement.clientWidth;
			yScroll = document.documentElement.clientHeight;
		}
		else if(document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			xScroll = document.body.clientWidth;
			yScroll = document.body.clientHeight;
		}
		
		return {width: xScroll, top: yScroll};
	},
	getScrollXY: function() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	},
	getScrollerWidth:function () {
	    var scr = null;
	    var inn = null;
	    var wNoScroll = 0;
	    var wScroll = 0;
	
	    // Outer scrolling div
	    scr = document.createElement('div');
	    scr.style.position = 'absolute';
	    scr.style.top = '-1000px';
	    scr.style.left = '-1000px';
	    scr.style.width = '100px';
	    scr.style.height = '50px';
	    // Start with no scrollbar
	    scr.style.overflow = 'hidden';
	
	    // Inner content div
	    inn = document.createElement('div');
	    inn.style.width = '100%';
	    inn.style.height = '200px';
	
	    // Put the inner div in the scrolling div
	    scr.appendChild(inn);
	    // Append the scrolling div to the doc
	    document.body.appendChild(scr);
	
	    // Width of the inner div sans scrollbar
	    wNoScroll = inn.offsetWidth;
	    // Add the scrollbar
	    scr.style.overflow = 'auto';
	    // Width of the inner div width scrollbar
	    wScroll = inn.offsetWidth;
	
	    // Remove the scrolling div from the doc
	    document.body.removeChild(
	        document.body.lastChild);
	
	    // Pixel width of the scroller
	    return (wNoScroll - wScroll);
	},
	getPageSizeWithScroll: function(){
		if (window.innerHeight && window.scrollMaxY) {// Firefox
			yWithScroll = window.innerHeight + window.scrollMaxY;
			xWithScroll = window.innerWidth + window.scrollMaxX;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yWithScroll = document.body.scrollHeight;
			xWithScroll = document.body.scrollWidth;
		} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
			yWithScroll = document.body.offsetHeight;
			xWithScroll = document.body.offsetWidth;
	  	}
		arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
		return arrayPageSizeWithScroll;
	}
};


Cappture.Popin = function (pa_Parameters)
{
	//Initialize Popin
	this.ctype='Popin';
	this.Id = '';
	this.Message = '';
	this.Message_Type = Cappture.Popin.Type.CLASSIC;
	this.Version = 3;
	this._Pages = 0;
    this._IsActive=1;
    this.Article_Id = -1;
	this.Page_Threshold = 0;
	this.Action = null;
	this.Expiration = 'MESSAGEWEB_METHOD_REPEAT_ANYTIME';
    this.Color = 'Classic';
	this.PlaceHolder = 'Cappture_Popin';
	this.draggable = false;
	this.DisplayCloseIcon = true;
	this.IsReady = false;
	this.FollowScroll = false;
	this.DisplayPosition = Cappture.Popin.Positioning.MIDDLE;
	this.DisplayPosition_X = null;
	this.DisplayPosition_Y = null;
	this._Relative_Position_X = 0;
	this._Relative_Position_Y = 0;
	this.DisplayPosition_IsRelative = false;
	this.DisplayPosition_X_IsPercent = false;
	this.DisplayPosition_Y_IsPercent = true;
	this.DisplayPosition_X_Reference = 'LEFT';
	this.DisplayPosition_Y_Reference = 'TOP';
	this._ForceNoAction = false;
	this._MessageFetching = false;
	this._MessageReady = true;
	this._CancelDisplay = false;

	
	
	for(var ls_PropertyName in pa_Parameters)
	{
		this[ls_PropertyName] = pa_Parameters[ls_PropertyName];
	}

	

};

Cappture.Popin.Expiration_Time = {IMMEDIATE:'MESSAGEWEB_METHOD_REPEAT_ANYTIME', HOUR_12:'MESSAGEWEB_METHOD_REPEAT_HOUR_12',HOUR_6:'MESSAGEWEB_METHOD_REPEAT_HOUR_6', HOUR_4:'MESSAGEWEB_METHOD_REPEAT_HOUR_4', HOUR_2:'MESSAGEWEB_METHOD_REPEAT_HOUR_2', HOUR:'MESSAGEWEB_METHOD_REPEAT_HOUR', HOUR2:'MESSAGEWEB_METHOD_REPEAT_HOUR2', HOUR5:'MESSAGEWEB_METHOD_REPEAT_HOUR6', HOUR12:'MESSAGEWEB_METHOD_REPEAT_HOUR12', VISIT:'MESSAGEWEB_METHOD_REPEAT_VISIT', DAY:'MESSAGEWEB_METHOD_REPEAT_DAY'};
Cappture.Popin.Positioning =  {TOPLEFT: 'MESSAGEWEB_DISPLAY_TOPLEFT', TOPRIGHT:'MESSAGEWEB_DISPLAY_TOPRIGHT', MIDDLE:'MESSAGEWEB_DISPLAY_MIDDLE', BOTTOMLEFT:'MESSAGEWEB_DISPLAY_BOTTOMLEFT', BOTTOMRIGHT:'MESSAGEWEB_DISPLAY_BOTTOMRIGHT', CUSTOM:'MESSAGEWEB_DISPLAY_CUSTOM', DOCK:'MESSAGEWEB_DISPLAY_DOCK'};
Cappture.Popin.Type = {CLASSIC: 'MESSAGEWEB_TYPE_CLASSIC', SUCCESS:'MESSAGEWEB_TYPE_SUCCESS', EMPTY:'MESSAGEWEB_TYPE_EMPTY'};
Cappture.Popin.Docking = {LEFT:'MESSAGEWEB_DOCKING_POSITION_LEFT', RIGHT:'MESSAGEWEB_DOCKING_POSITION_RIGHT', TOP:'MESSAGEWEB_DOCKING_POSITION_TOP', BOTTOM:'MESSAGEWEB_DOCKING_POSITION_BOTTOM'};
Cappture.Popin.Docking.Anchor = {X:{RIGHT:'RIGHT', CENTER:'CENTER', LEFT:'LEFT', CUSTOM:'CUSTOM'},Y:{TOP:'TOP', CENTER:'CENTER', BOTTOM:'BOTTOM', CUSTOM:'CUSTOM'}};
Cappture.Popin.prototype.adapt = function ()
{
		
		
	if(CProgram_Manager.Popin_Layout == 'Classic')
	{
		if(typeof(this.BorderColor) != 'undefined' && typeof(this.BorderWidth) != 'undefined')
		{
			document.getElementById('Cappture_Popin').style.border = this.BorderWidth + ' solid ' + this.BorderColor;
		}
		else
		{
			document.getElementById('Cappture_Popin').style.border = '1px solid #d8d6c8';
		}
		
		if(typeof(this.BackgroundColor) != 'undefined')
		{
			document.getElementById('Cappture_Popin').style.backgroundColor = this.BackgroundColor;
			
			/*if(typeof document.getElementById('cc_iframeshim') != 'undefined')
			{
				document.getElementById('cc_iframeshim').style.backgroundColor = this.BackgroundColor;
				document.getElementById('cc_iframeshim').style.background = this.BackgroundColor;
			}*/
		}
		
		if(! this.DisplayCloseIcon)
		{
			document.getElementById('CappturePopin_Close').style.display = 'none';
		}
		else
		{
			document.getElementById('CappturePopin_Close').style.display = '';
		}
		
	}
	
	
	
	
	if (CProgram_Manager.Popin_Layout == 'Free' || CProgram_Manager.Popin_Layout == 'Classic')
	{
		this.computeStyle();
	}
	
	if(Cappture.IE)
	{
		try
		{
			document.getElementById('CappturePopin_Top_Spacer').style.width = '10000px';//(parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) +'px';// - 100 + 'px'; 
			document.getElementById('CappturePopin_Bottom_Spacer').style.width = '10000px';//(parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) + 'px';// - 100 + 'px'; 
			document.getElementById('CappturePopin_Top_Spacer').width = (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) +'px';// - 100 + 'px'; 
			document.getElementById('CappturePopin_Bottom_Spacer').width = (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) + 'px';// - 100 + 'px'; 
			document.getElementById('CappturePopin_Layout').style.width = (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) + 29 +'px';// - 100 + 'px'; 
			document.getElementById('CappturePopin_Layout').width 		= (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) + 29 + 'px';// - 100 + 'px';
		}
		catch(e){}
		document.getElementById('CappturePopin_Content').parentNode.style.width = (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) +'px';// - 100 + 'px'; 
		document.getElementById('CappturePopin_Content').parentNode.width 		= (parseInt(document.getElementById('CappturePopin_Content').offsetWidth)) + 'px';// - 100 + 'px'; 
	}

	var CPI_Coord = Cappture.Utils.getCoordinates(this.getPlaceHolder());
	if(CPI_Coord.top < 0){this.getPlaceHolder().style.top = '10px';}
	if(CPI_Coord.right >=  (Cappture.Utils.Window.Get_Size().width - 20))	{this.getPlaceHolder().style.left =  Cappture.Utils.Window.Get_Size().width - CPI_Coord.width - 20;}
	if(CProgram_Manager.Popin_Layout == 'Free')
	{
		try{
			var CPI_Coord = Cappture.Utils.getCoordinates(this.getPlaceHolder());
			document.getElementById('CappturePopin_Logo').style.top = CPI_Coord.height - 2;
			document.getElementById('CappturePopin_Logo').style.left = CPI_Coord.width - 215;
		}catch(e){}
	}
	
	if(this.Draggable)
	{
		if(! document.getElementById('Cappture_Popin_Drag_Anchor'))
		{
			this.getPlaceHolder().innerHTML += '<div id="Cappture_Popin_Drag_Anchor" style="width:16px;height:16px;background-color:red;position:absolute;top:-8px;left:-8px; "><a href="javascript:void(0);" style="cursor: move; text-decoration: none">&nbsp;</a></div>';
			var lo_o = new Cappture.Element.Draggable('Cappture_Popin');		
		}		
	}
	
	if(this.FollowScroll)
	{
	
			this.onScroll = function(){
				this._RefreshDisplay(); 	
			};
		
	}

	//Ensure that Close button is available
	this.getPlaceHolder().setAttribute('p_id', this.getId());	
	
	
};

Cappture.Popin.prototype.close= function()
{
	try{
		this.getPlaceHolder().style.display = 'none';
		this.getPlaceHolder().style.visibility = 'hidden';
		this.getPlaceHolder().innerHTML = '';	
	}
	catch(e){}
	return;
};

Cappture.Popin.prototype.onResize = function()
{
	this._RefreshDisplay();
}

Cappture.Popin.prototype._RefreshDisplay = function()
{

	
	var le_Div = this.getPlaceHolder();
	var li_ScrollTop = 0;
    var li_ScrollLeft = 0;
	
	var li_Computed_X, li_Computed_Y;
	
	
	var lo_Scrolls = Cappture.Utils.Window.getScrollXY();
    li_ScrollLeft = lo_Scrolls[0];
    li_ScrollTop = lo_Scrolls[1];
    
	var lo_Coord = Cappture.Utils.getCoordinates(le_Div);
	
    var li_Width = lo_Coord.width;
    var li_Height = lo_Coord.height;
	var lo_Size = Cappture.Utils.Window.Get_Size();	
	this.calculateBounds(li_Width, li_Height);
	
	var li_Relative_Position_X, li_Relative_Position_Y;
	switch(this.DisplayPosition)
	{
		case Cappture.Popin.Positioning.MIDDLE:
			li_Relative_Position_X = ((lo_Size.width / 2) - (li_Width / 2) - 20);
			li_Relative_Position_Y = ((lo_Size.top / 2) - (li_Height / 2));
			
			li_Computed_X = ((lo_Size.width / 2) - (li_Width / 2) - 20) + li_ScrollLeft;
    		li_Computed_Y = ((lo_Size.top / 2) - (li_Height / 2)) + li_ScrollTop;
			break;
		case Cappture.Popin.Positioning.BOTTOMLEFT:
			li_Relative_Position_X = 5;
			li_Relative_Position_Y = (lo_Size.top - li_Height - 20);
			
			li_Computed_X = 5;
			li_Computed_Y = (lo_Size.top - li_Height - 20) + li_ScrollTop;
			break;
		case Cappture.Popin.Positioning.BOTTOMRIGHT:		
			li_Relative_Position_X = (lo_Size.width - li_Width - 20);
			li_Relative_Position_Y = (lo_Size.top - li_Height - 20);
			
			li_Computed_Y = (lo_Size.top - li_Height - 20) + li_ScrollTop;
			li_Computed_X = (lo_Size.width - li_Width - 20) + li_ScrollLeft;
			break;
		case Cappture.Popin.Positioning.TOPLEFT:
			li_Relative_Position_X = li_ScrollLeft;
			li_Relative_Position_Y = ((li_ScrollTop == 0) ? 5 : li_ScrollTop);
			
			li_Computed_X = li_ScrollLeft;
			li_Computed_Y = 5;
			break;
		case Cappture.Popin.Positioning.TOPRIGHT:
			li_Relative_Position_X = 5;
			li_Relative_Position_Y = (lo_Size.width - li_Width - 20);
			
			li_Computed_Y = ((li_ScrollTop == 0) ? 5 : li_ScrollTop);
			li_Computed_X = (lo_Size.width - li_Width - 20) + li_ScrollLeft;
			break;
		case Cappture.Popin.Positioning.CUSTOM:
			//Calculate Relative position
			if(this.DisplayPosition_IsRelative)
			{
				if (this.DisplayPosition_Y_IsPercent)
				{
					li_Relative_Position_Y = (lo_Size.top * (this.DisplayPosition_Y / 100)) - ((this.DisplayPosition_Y_Reference == 'CENTER')?(li_Height / 2):0);
					li_Computed_Y = (lo_Size.top * (this.DisplayPosition_Y / 100)) - ((this.DisplayPosition_Y_Reference == 'CENTER')?(li_Height / 2):0) +  li_ScrollTop;
				}
				else
				{
					li_Relative_Position_Y = this.DisplayPosition_Y;
					li_Computed_Y = this.DisplayPosition_Y + li_ScrollTop;
				}
				
				if (this.DisplayPosition_X_IsPercent)
				{	
					li_Relative_Position_X = (lo_Size.width * (this.DisplayPosition_Y / 100)) - ((this.DisplayPosition_X_Reference == 'CENTER')?(li_Width / 2):0) ;
					li_Computed_X = (lo_Size.width * (this.DisplayPosition_Y / 100)) - ((this.DisplayPosition_X_Reference == 'CENTER')?(li_Width / 2):0) +  li_ScrollLeft;
				}
				else
				{
					li_Relative_Position_X = this.DisplayPosition_X;
					li_Computed_X = this.DisplayPosition_X + li_ScrollLeft;
				}
			}
			else
			{
				li_Relative_Position_X = this.DisplayPosition_Y;
				li_Relative_Position_Y = this.DisplayPosition_X;
				
				
				li_Computed_Y = this.DisplayPosition_Y;
				li_Computed_X = this.DisplayPosition_X;
			}
			break;
		case Cappture.Popin.Positioning.DOCK:
			
			break;
	}
	
	
	//manage bounds
	//X
	if(li_Computed_X < this._Bounds.minLeft){li_Computed_X = this._Bounds.minLeft;}
	else if(li_Computed_X > this._Bounds.maxLeft){li_Computed_X = this._Bounds.maxLeft;}
	//Y
	if(li_Computed_Y < this._Bounds.minTop){li_Computed_Y = this._Bounds.minTop;}
	else if(li_Computed_Y > this._Bounds.maxTop){li_Computed_Y = this._Bounds.maxTop;}
	
	
	le_Div.style.left	= li_Computed_X + 'px';
    le_Div.style.top	= li_Computed_Y + 'px';
			
	this._Relative_Position_X = li_Relative_Position_X;
	this._Relative_Position_Y = li_Relative_Position_Y;
	return;
}

//Compute Popin Position & Content
Cappture.Popin.prototype.Display = function(pb_ByPass_Tracking)
{
	
	if(this._CancelDisplay){return;}
	if(! this._MessageReady)
	{
		this.fetchContent();
		self.setTimeout(Cappture_FunctionHelper(this, 'Display', null), 1000);
	}
	else
	{
		CapptureConnect_Initialize();
	    var le_Div = this.getPlaceHolder();
		
		
	    le_Div.style.display = 'block';
	    le_Div.innerHTML = this.getContent();
		
		Cappture_ComputeStyle(le_Div);
		
		
	    this._IsActive = 0;
	    this._RefreshDisplay();
		
	   	this.show(pb_ByPass_Tracking);
	}
	
   
};

Cappture.Popin.prototype.fetchContent = function()
{
	if(!this._MessageFetching) 
	{
		this._MessageFetching = true;
		Cappture_FunctionHelper(this, '_Fetch', null)();
	}	
	else{
		return;
	}
};

Cappture.Popin.prototype.show = function(pb_ByPass_Tracking)
{
	//Update Program Status
	if((typeof(gb_Cappture_Connect_Demo) != 'undefined' && gb_Cappture_Connect_Demo == true) || Cappture_Querystring_Parameter_Get('PopTest') == 'true' )
	{
		this._Pages = 0;
		this._IsActive = 1;
	}
	CProgram_Manager.Programs_State[this.getId()].ViewPages = this._Pages;
	CProgram_Manager.Programs_State[this.getId()].IsActive = this._IsActive;
	CProgram_Manager.Programs_State[this.getId()].LastDisplay = new Date();
	CProgram_Manager.saveState();
	//Remove header in popin
	if(typeof(this.Version) == 'undefined' || this.Version == 1)
	{
		this.getPlaceHolder().childNodes[0].removeChild(this.getPlaceHolder().childNodes[0].childNodes[0]);
	}
	//detect links in pop-in
	if(! this.IsReady)
	{
		Cappture_ReplaceLink(this.getPlaceHolder());
		this.IsReady = true;
		
		//evaluate Script
		var scripts = [];
		var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
		while ((script = regexp.exec(this.getPlaceHolder().innerHTML))) scripts.push(script[1]);
		scripts = scripts.join('\n');
		if (scripts){ (window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);}
		
		//register onclick event
	
		/*this.getPlaceHolder().onclick = null;
		
		Cappture.Event.registerEvent(this.getPlaceHolder(), 'click', CProgram_Manager, 'onClick', this);*/
	//	this.getPlaceHolder().onclick = Cappture_FunctionHelper(CProgram_Manager, 'onClick', [this, window.e]);
	}
	if(CProgram_Manager.Popin_Layout == 'Classic')
	{	
		if(typeof(this.BackgroundColor) != 'undefined')
		{
			if(this.BackgroundColor != 'transparent')
			{
				this.getPlaceHolder().innerHTML += '<IFRAME id="cc_iframeshim" name="cc_iframeshim" class="CappturePopin_HiddenFrame" frameBorder="0" scrolling="no" style="width:100%; height:100%"></IFRAME>';		
			}
		}
		
	}
	else
	{
		this.getPlaceHolder().innerHTML += '<IFRAME id="cc_iframeshim" name="cc_iframeshim" class="CappturePopin_HiddenFrame" frameBorder="0" scrolling="no" style="width:100%; height:100%"></IFRAME>';		
	}
	
	cc_LOP = this;
	if(typeof(gb_Cappture_Connect_Demo) != 'undefined' && gb_Cappture_Connect_Demo == true && typeof(Cappture_Demo_Display_Description) == 'function')
	{
		Cappture_Demo_Display_Description(this);
	}
	
	
	//document.getElementById('CappturePopin_Content').colSpan = 2;

	this.adapt();
	
	
	
	if(this.Message_Type == Cappture.Popin.Type.SUCCESS)
	{
		Cappture.Communication.sendStat(this, 4, '');
		//return;
	}
	else
	{
 		Cappture.Communication.sendStat(this, 9, '');
	}
	
	this.getPlaceHolder().style.visibility = 'visible';
	
	if(typeof this.onShow == 'function')
	{
		this.onShow();
	}
	
	if(typeof this._DisplayDelay != 'undefined' && !isNaN(parseInt(this._DisplayDelay)))
	{
		self.setTimeout(Cappture_FunctionHelper(this,'close',null), this._DisplayDelay * 1000);
	}
	
	
	return;
};
Cappture.Popin.prototype.getContent = function()
{
	if (this.Message != null) return this.Message;
	
	return '';
};

Cappture.Popin.prototype.clone = function()
{
	var lo_Result = new Cappture.Popin(this);
	return lo_Result;
	
}


Cappture.Popin.prototype.getId = function()
{
	return (typeof this.Id == 'undefined' || this.Id == '')?this.id:this.Id;
};

Cappture.Popin.prototype.setId = function(pi_Id)
{
		if(typeof this.Id == 'undefined' || this.Id == '')
		{
			this.id = pi_Id;
		}
		else
		{
			this.Id = pi_Id;
		}
		
	return (typeof this.Id == 'undefined' || this.Id == '')?this.id:this.Id;
};

Cappture.Popin.prototype.computeStyle = function ()
{
	//return;
	var p = document.getElementById(this.PlaceHolder);
	
	var c = p.getElementsByTagName("*");
	for(var i = 0; i < c.length; i++)
	{
		if(p.offsetHeight < (c[i].offsetHeight + c[i].offsetTop))
		p.style.height = (c[i].offsetHeight + c[i].offsetTop) + "px";
		if(p.offsetWidth < (c[i].offsetWidth + c[i].offsetLeft))
		p.style.width = (c[i].offsetWidth + c[i].offsetLeft) + "px";
	} 
	
	
	
};

Cappture.Popin.prototype.getPlaceHolder = function()
{
	return (document.getElementById(this.PlaceHolder))?document.getElementById(this.PlaceHolder):document.getElementById('Cappture_Popin');
}

Cappture.Popin.prototype.register = function(){
	
	if(this.Program_Manager == null) {
		CProgram_Manager.register(this);
	} 
	else
	{
		CProgram_Manager.get(this.Program_Manager).register(this);
	}
}

function CapptureConnect_Article_Display(po_Program)
{
	//get from CProgram Manager
	var lo_Program = CProgram_Manager.getProgram(po_Program.getId());
	if(lo_Program != null){
		lo_Program.show();
	}
	return;
}

Cappture.Popin.prototype.calculateBounds = function(pi_Width, pi_Height)
{
	if(this._Dock && this.DisplayDocking_Reference != null && this.DisplayDocking_Position != null && document.getElementById(this.DisplayDocking_Reference))
	{
		var li_Anchor_Position_X = 0, li_Anchor_Position_Y = 0;
		switch(this.DisplayDocking_X_Reference)
		{
			case Cappture.Popin.Docking.Anchor.X.RIGHT:
				li_Anchor_Position_X = pi_Width;
				break;
			case Cappture.Popin.Docking.Anchor.X.CENTER:
				li_Anchor_Position_X = pi_Width / 2;
				break;
			case Cappture.Popin.Docking.Anchor.X.LEFT:
				li_Anchor_Position_X = 0;
				break;
			case Cappture.Popin.Docking.Anchor.X.CUSTOM:
				li_Anchor_Position_X = this.DisplayDocking_X;
				break;
		}
		
		switch(this.DisplayDocking_Y_Reference)
		{
			case Cappture.Popin.Docking.Anchor.Y.BOTTOM:
				li_Anchor_Position_Y = pi_Height;
				break;
			case Cappture.Popin.Docking.Anchor.Y.CENTER:
				li_Anchor_Position_Y = pi_Height / 2;
				break;
			case Cappture.Popin.Docking.Anchor.Y.TOP:
				li_Anchor_Position_Y = 0;
				break;
			case Cappture.Popin.Docking.Anchor.Y.CUSTOM:
				li_Anchor_Position_Y = this.DisplayDocking_Y;
				break;
		}
	
		
		var le_Reference = document.getElementById(this.DisplayDocking_Reference);
		var lo_Reference_Coordinates = Cappture.Utils.getCoordinates(le_Reference);
		
		switch(this.DisplayDocking_Position)
		{
			case Cappture.Popin.Docking.TOP:
				this._Bounds = {
					minTop: lo_Reference_Coordinates.top - li_Anchor_Position_Y,
					maxTop:lo_Reference_Coordinates.top - li_Anchor_Position_Y,
					minLeft:lo_Reference_Coordinates.left - li_Anchor_Position_X,
					maxLeft:lo_Reference_Coordinates.right - li_Anchor_Position_X	
					
				};
				break;
			case Cappture.Popin.Docking.RIGHT:/*OK*/
				this._Bounds = {
					minTop: lo_Reference_Coordinates.top - li_Anchor_Position_Y,
					maxTop:lo_Reference_Coordinates.bottom - li_Anchor_Position_Y,
					minLeft:lo_Reference_Coordinates.right - li_Anchor_Position_X,
					maxLeft:lo_Reference_Coordinates.right - li_Anchor_Position_X
				};
				break;
			case Cappture.Popin.Docking.BOTTOM:
				this._Bounds = {
					minTop: lo_Reference_Coordinates.bottom - li_Anchor_Position_Y,
					maxTop:lo_Reference_Coordinates.bottom - li_Anchor_Position_Y,
					minLeft:lo_Reference_Coordinates.left - li_Anchor_Position_X,
					maxLeft:lo_Reference_Coordinates.right - li_Anchor_Position_X	
				};
				break;
			case Cappture.Popin.Docking.LEFT: /*OK*/
				this._Bounds = {
					minTop: lo_Reference_Coordinates.top - li_Anchor_Position_Y,
					maxTop:lo_Reference_Coordinates.bottom - li_Anchor_Position_Y,
					minLeft:lo_Reference_Coordinates.left - li_Anchor_Position_X,
					maxLeft:lo_Reference_Coordinates.left - li_Anchor_Position_X	
				};
				break;
		}
		
	}
	else
	{
		var lo_WindowBounds = Cappture.Utils.Window.getPageSizeWithScroll();
		
		this._Bounds = {
			minLeft:0,
			maxLeft: (lo_WindowBounds[0] - pi_Width),
			minTop:0,
			maxTop:(lo_WindowBounds[1] - pi_Height)
		}
	}
	
}

	
Cappture.Popin.prototype.hideFlash = function (pe_Element)
{
	return;
	for(var li_Index = 0; li_Index < pe_Element.childNodes.length; li_Index++) 
	 {
	 	le_Element = pe_Element.childNodes[li_Index];
		
		if(le_Element.nodeName.toLowerCase() == 'object')
		{
			if(le_Element.parentNode.tagName.toLowerCase() != 'div')
			{
				/*wrap flash in div*/
				var newdiv = document.createElement('param');
			}
			else
			{
				le_Element.parentNode.style.zIndex = 0;	
			}
			le_Element.style.zIndex = 0;
			var lb_Param = false;
			for(var li_Index2 = 0; li_Index2 < le_Element.childNodes.length; li_Index2++)
			{
				if(le_Element.childNodes[li_Index2].getAttribute && le_Element.childNodes[li_Index2].getAttribute('name') == 'wmode')
				{
					le_Element.childNodes[li_Index2].setAttribute('value', 'transparent');
					lb_Param = true;
				}	
				if(le_Element.childNodes[li_Index2].nodeName.toLowerCase() == 'embed')
				{
					le_Element.childNodes[li_Index2].setAttribute('wmode', 'transparent');
				}
			}
			if(!lb_Param)
			{
				var newdiv = document.createElement('param');
				newdiv.setAttribute('name', 'wmode');
				newdiv.setAttribute('value', 'transparent');
				le_Element.appendChild(newdiv);
			}
			
		}
		else if(le_Element.nodeName.toLowerCase() == 'embed')
		{
			le_Element.setAttribute('wmode', 'transparent');
		}
		else if(le_Element.childNodes.length > 0)
		{
			Cappture.Utils.hideFlash(le_Element);
		}
	 }
		
};

Cappture.Communication = {
	
	
	load: function(ps_URL, po_onLoadFunction, po_Bind)
	{
		if(Cappture.IsLoaded){
			return this.loadRemote(ps_URL, po_onLoadFunction, po_Bind);
		}
		else{
			return this.loadInline(ps_URL, po_onLoadFunction, po_Bind);
		}
	},
	loadInline: function(ps_URL, po_onLoadFunction, po_Bind)
	{
		var ls_OnloadHandler = '';
		var ls_ResponseBank = 'CallbackResponse' + (new Date().getTime());
		
		window[ls_ResponseBank] = {Result:null, isReady:false};
		
		/*if(typeof po_onLoadFunction == 'string')
			ls_OnloadHandler = 'onload="' + po_onLoadFunction + '"';
		else*/ 
		if(typeof po_onLoadFunction == 'function')
		{
			var ls_FunctionName = 'loadEvent_' + (new Date().getTime());
			window[ls_FunctionName] = po_onLoadFunction;
			ls_OnloadHandler = 'onload="' + ls_FunctionName + '()"';
			
			if(po_Bind != null)
			{
				window[ls_ResponseBank] = function() {
					po_onLoadFunction.apply(po_Bind, arguments);
				};
			}
			else
				window[ls_ResponseBank] = po_onLoadFunction;
			
		}
		document.write('<' + 'script src="' +((ps_URL.indexOf('?') == -1)?ps_URL + '?CallbackId=' + escape(ls_ResponseBank):ps_URL + '&CallbackId=' + escape(ls_ResponseBank)) + '" >' + '</' + 'script' + '>');
		return ls_ResponseBank;
	},
	loadRemote: function (ps_URL, po_onLoadFunction, po_Bind) /*Load remote script(outside initial domain or load script after window complete load */
	{
		var ls_ResponseBank = 'CallbackResponse' + (new Date().getTime());
		
		window[ls_ResponseBank] = {Result:null, isReady:false};
		
		if(typeof po_onLoadFunction == 'function')
		{
			var ls_FunctionName = 'loadEvent_' + (new Date().getTime());
			window[ls_FunctionName] = po_onLoadFunction;
			ls_OnloadHandler = 'onload="' + ls_FunctionName + '()"';
			
			if(po_Bind != null)
			{
				window[ls_ResponseBank] = function() {
					po_onLoadFunction.apply(po_Bind, arguments);
				};
			}
			else
			{
				window[ls_ResponseBank] = po_onLoadFunction;
			}
		}
		
		script      = document.createElement("script"); 
	    script.type = "text/javascript"; 
	    script.src  = (ps_URL.indexOf('?') == -1)?ps_URL + '?CallbackId=' + escape(ls_ResponseBank):ps_URL + '&CallbackId=' + escape(ls_ResponseBank);
		/*if(typeof po_onLoadFunction == 'string')
		{
			script.onload = new Function(po_onLoadFunction);
		}
		else if(typeof po_onLoadFunction == 'function')
		{
			script.onload = po_onLoadFunction;
		}*/
	    document.getElementsByTagName("head")[0].appendChild(script); 
		return ls_ResponseBank;
	},
	sendStat: function(po_Program, pi_Type, ps_ExtraPArams)
	{
		var ls_QueryString = '';// 'Domain_Id=' + escape(gi_Cappture_Domain_Id);		
		/*ls_QueryString += 'Program_Id=' + escape(po_Program.getId());
		ls_QueryString += '&Article_Id=' + escape(po_Program.Article_Id);
		ls_QueryString += '&keywords=' + escape(document.location.href);
		ls_QueryString += '&cc_url=' + escape(document.location.href);
		ls_QueryString += '&cc_type=' + pi_Type;
		*/
		//document.getElementById('Cappture_Tube').src='http' + Cappture.IsSSL + '://tracker1.cappture.com/' + gi_Cappture_Domain_Id + '/Cappture_Connect_Track.aspx?' + ls_QueryString;
		
		/*Change Method to Direct Script Access*/
		/*
		ls_QueryString = 'http' + Cappture.IsSSL + '://ws.cappture.com/Service.asmx/Cappture_Track_Query_String_JSON?';
		ls_QueryString += 'ps_QueryString=' +escape(document.location.href);
		ls_QueryString += '&ps_Domain=' + escape(gi_Cappture_Domain_Id);
		ls_QueryString += '&pi_Tracking_Type=' + escape(pi_Type);
		ls_QueryString += '&ps_URL=' + escape(document.location.href);
		ls_QueryString += '&ps_Keywords=' + escape(document.location.href);
		ls_QueryString += '&pi_Program_Id=' + escape(po_Program.getId());
		ls_QueryString += '&pi_Article_Id=' + escape(po_Program.Article_Id);
		
		if(ps_ExtraPArams != '')ls_QueryString +=  '&' + ps_ExtraPArams;
		Cappture.Communication.loadRemote(ls_QueryString);
		*/
		
		ls_QueryString = 'http' +  Cappture.IsSSL  + '://ws3.cappture.com/Service.asmx/Cappture_Track_Query_String_JSON_Global?';
		ls_QueryString += 'ps_QueryString=' +escape(document.location.href);
		ls_QueryString += '&ps_Domain=' + escape(gi_Cappture_Domain_Id);
		ls_QueryString += '&pi_Tracking_Type=' + escape(pi_Type);
		ls_QueryString += '&ps_URL=' + escape(document.location.href);
		ls_QueryString += '&ps_Keywords=' + escape(document.location.href);
		ls_QueryString += '&pi_Program_Id=' + escape(po_Program.getId());
		ls_QueryString += '&pi_Article_Id=' + escape(po_Program.Article_Id);
	

		if(ps_ExtraPArams != ''){ls_QueryString +=  '&' + ps_ExtraPArams;}
		document.getElementById('Cappture_Tube').src=ls_QueryString;
		return;
	},
	
	sendData: function(ps_URL, ps_Method, pa_Arguments)
	{
		var lb_IsFirstParameter = (ps_URL.indexOf('?')==-1);
		var ls_Params = ''; 
		if(ps_Method == 'get')
		{
			for(var ls_Property in pa_Arguments)
			{
				if(! lb_IsFirstParameter) {ls_Params +='&';}
				lb_IsFirstParameter = false;
				
				ls_Params += ls_Property + '=' + escape(pa_Arguments[ls_Property]);
				
			}
			document.getElementById('Cappture_Tube').src = ps_URL + ls_Params;
		}
		return true;		
	}
};


Cappture.PluginManager = function() {
	this._Plugins_Count = 0;
	this._Plugins = [];
};

Cappture.PluginManager.prototype.registerPlugin = function(ps_Name, ps_Version, po_Plugin){
	return;
};

Cappture.Plugin = function(po_Option)
{
	for(var ls_Prop in po_Option)
	{
		this[ls_Prop] = po_Option[ls_Prop];
	}
}
Cappture.HistoryManager = {};

Cappture.HistoryManager.StateManager = function()
{
	this._MemoryHistory = new Cappture.HistoryManager.MemoryHistory();
	//getCurrent State
	//Cappture.Communication.load(Cappture.Utils.createURL('Cappture_Connect_GetData.aspx'));
	
}

Cappture.HistoryManager.StateManager.prototype.store = function(ps_Link, ps_ImageLink, ps_Name)
{
	var ls_URL = 'Cappture_Connect_StoreData.aspx?Link=' + escape(ps_Link) + '&ImageLink=' + escape(ps_ImageLink) + '&Name=' + escape(ps_Name);
	Cappture.Communication.load(Cappture.Utils.createURL(ls_URL));
}

Cappture.HistoryManager.StateManager.prototype.get = function(pi_HistoryIndex)
{
	var lb_Result = false;
	
	return {
		Items: this._MemoryHistory.getData()
	};
	
	
}

Cappture.HistoryManager.StateManager.prototype.getHistory = function()
{
	var lo_Navigation = this.get();
	var ls_Content = '<ul class="CapptureHistory_List">';
	 
	for(var li_Index = 0; li_Index < lo_Navigation.Items.length; li_Index++)
	{
		ls_Content += '<li class="CapptureHistory_Item"><a class="CapptureHistory_Link" href="' + lo_Navigation.Items[li_Index].Link + '">' + lo_Navigation.Items[li_Index].Link + '</a><img class="CapptureHistory_Thumb" border="0" src="' + lo_Navigation.Items[li_Index].ImageLink + '" /></li>';
	}
	ls_Content += '</ul>';

	return ls_Content;
}



Cappture.HistoryManager.StateManager.prototype.initialize = function(po_History)
{
	this._MemoryHistory.initialize(po_History);
}


Cappture.HistoryManager.IFrameManager = function() 
{
	this._MemoryHistory = new Cappture.HistoryManager.MemoryHistory();
	if(document.getElementById('CapptureHistoryIFrame')) {return;}
	if (Cappture.IsLoaded)
	{
		document.write('<iframe name="CapptureHistoryIFrame" id="CapptureHistoryIFrame" src="' + Cappture.Utils.createURL('Blank.html') + '" style="display:none" onload="CProgram_Manager.InitializeHistoryManager()"></iframe>')
	}
	else
	{
		var iframe  = document.createElement('iframe');
		iframe.name = 'CapptureHistoryIFrame';
		iframe.id	= 'CapptureHistoryIFrame';
		iframe.src  = Cappture.Utils.createURL('Blank.html');
	    //iframe.src  = 'Blank.html'; 
		iframe.style.display = 'none';
	    document.getElementsByTagName('body')[0].appendChild(iframe);
	}
};

Cappture.HistoryManager.IFrameManager.prototype.getHistory = function()
{
	var lo_Navigation = this.get();
	 
	var ls_Content = '<ul class="CapptureHistory_List">';
	 
	for(var li_Index = 0; li_Index < lo_Navigation.Items.length; li_Index++)
	{
		ls_Content += '<li class="CapptureHistory_Item"><a class="CapptureHistory_Link" href="' + lo_Navigation.Items[li_Index].Link + '">' + lo_Navigation.Items[li_Index].Link + '</a><img class="CapptureHistory_Thumb" border="0" src="' + lo_Navigation.Items[li_Index].ImageLink + '" /></li>';
	}
	ls_Content += '</ul>';

	return ls_Content;
}

Cappture.HistoryManager.MemoryHistory = function(){
	this._History = [];
	
	
}

Cappture.HistoryManager.MemoryHistory.prototype.serialize = function()
{	
	var lo_Temp = {Item_Count: this._History.length, Items:this._History};
	return Cappture.Utils.toJSON(lo_Temp);	
}

Cappture.HistoryManager.MemoryHistory.prototype.getData = function()
{
	return this._History;
}

Cappture.HistoryManager.MemoryHistory.prototype.add = function (po_MemoryItem)
{
	this._History.push(po_MemoryItem);
}

Cappture.HistoryManager.MemoryHistory.prototype.initialize = function(po_History){
	this._History = po_History.Items;
}

Cappture.HistoryManager.HistoryItem = function(ps_Name, ps_Link, ps_ImageLink){
	this._Name = ps_Name;
	this._Link = ps_Link;
	this._ImageLink = ps_ImageLink;
}

Cappture.HistoryManager.IFrameManager.prototype.store = function(ps_Link, ps_ImageLink, ps_Name)
{
		
		this._MemoryHistory.add(new Cappture.HistoryManager.HistoryItem(ps_Name, ps_Link, ps_ImageLink));
		var testFrame = document.getElementById('CapptureHistoryIFrame');
		
		testFrame.src = Cappture.Utils.createURL('Blank.html#' + new Date().getTime());
        // now write out the new contents
       // var doc = testFrame.contentDocument;
        //if (doc == undefined || doc == null) doc = testFrame.contentWindow.document;
		//document.getElementById('CapptureHistoryIFrame').setAttribute('totot', 'tiit');
        //doc.open();
        //doc.write('<script type="text/javascript"><![CDATA[CProgram_Manager.Cappture_LoadHistory(' + this._MemoryHistory.serialize() + ');]]>');
        //doc.close();       
	
}

Cappture.HistoryManager.IFrameManager.prototype.get = function()
{
	return '';
	/*
		var testFrame = document.getElementById('CapptureHistoryIFrame');
        // now write out the new contents
        var doc = testFrame.contentDocument;
        if (doc == undefined || doc == null) doc = testFrame.contentWindow.document;
        doc.open();
        doc.write(this._MemoryHistory.serialize());
        doc.close();       
	*/
}

Cappture.HistoryManager.IFrameManager.prototype.initialize = function(po_History)
{
	this._MemoryHistory = po_History.Items;
}

Cappture.Utils.initialize();

var CC_LayoutInitialized = false;
var cc_LOP = null;
var cc_Initial_Height;
var cc_Initial_Width;
 
var gs_Cappture_Page_Keywords = '';

function Cappture_FunctionHelper(po_Object, ps_Function_Name, pa_Arguments) {

	return function() {po_Object[ps_Function_Name].apply(po_Object, (Cappture.Utils.getType(pa_Arguments) == 'array')?pa_Arguments:[pa_Arguments]);};

}

function Cappture_EventFunctionHelper(po_Object, ps_Function_Name, pa_Arguments, pe_Event) {

	var la_Params = [pe_Event].concat(pa_Arguments);
	return function(){po_Object[ps_Function_Name].apply(po_Object, la_Params);};

}

var gi_Cappture_MaxSlot = 1;
var CProgram_Manager = {
	FileBank_Max:2,
	_Context:[],
	Slots:[{}],
	Programs_State : {},
	Programs: [],
	Program_Count: 0,
	Program_Loaded: 0,
	Popin_Layout: 'Classic',
	Keyword_Method:[{type: 'URL'}],
	Groups:[],
	EventStack: {},
	_Plugins: new Cappture.PluginManager(),
	
	_History: new Cappture.HistoryManager.StateManager(),
	initialize: function()
	{		
	
	
		Cappture.Events.domReady.add(Cappture_FunctionHelper(this,'Compute', null));
		
		var ld_LastDisplayDate = null;
		var ls_LastTimeDisplay_Serialized = '';
		var ls_Cookie = Cappture.Cookie.get(Cappture.Cookie.Names.PRGM);
		var ls_Decoded = ls_Cookie;
		if(ls_Decoded == '') {return;}

		var la_Programs = ls_Decoded.split(',');

		for(var li_Index_PRG = 0; li_Index_PRG < la_Programs.length; li_Index_PRG++)
		{
			var ls_ProgramState = la_Programs[li_Index_PRG];
			var la_ProgramState_Items = ls_ProgramState.split('_');
			
			if(la_ProgramState_Items.length > 3)
			{
				ls_LastTimeDisplay_Serialized = la_ProgramState_Items[3];
				ld_LastDisplayDate = new Date();
				ld_LastDisplayDate.setHours(parseInt(ls_LastTimeDisplay_Serialized.substr(0, 2)),parseInt(ls_LastTimeDisplay_Serialized.substr(2, 2)),0,0);
				
			}
			else
			{
				ld_LastDisplayDate = null;
			}
			
			this.Programs_State[la_ProgramState_Items[0]] = {IsProgram: true, IsActive: la_ProgramState_Items[1], ViewPages:((!isNaN(la_ProgramState_Items[2]))?la_ProgramState_Items[2]:0), LastDisplay: ld_LastDisplayDate};
		}	
		
		
		if(typeof(Cappture_Group_Load) != 'undefined')
		{
			
			//user have requested specific group(s)
			if(Cappture.Utils.getType(Cappture_Group_Load) == 'string')
			{
				
			}
		}
		
	},
	Program_Load: function ()
	{
		if(arguments.length > 0)
		{
			this.Program_Count = arguments.length;
			for( var li_Index = 0; li_Index < arguments.length; li_Index++)
			{
				document.write('<' + 'script src="' + Cappture.Utils.createURL(arguments[li_Index] + '.js') + '" ' + '>' + '</' + 'script' + '>');
			}
		}
		
	},
	Program_Delete: function ()
	{
		if(arguments.length > 0)
		{
			this.Program_Count = arguments.length;
			for( var li_Index = 0; li_Index < arguments.length; li_Index++)
			{
				try 
				{
					this.Programs_State[arguments[li_Index]].IsProgram = false;
				}catch(e){}
			}
		}
		
	},
	register: function (po_Program)
	{
		
		if (po_Program.Version == 2) 
		{
			po_Program = new Cappture.Popin(po_Program); /*po_Program.getId(), 'Cappture_Popin', po_Program);*/
		}
	 
		var ls_Cookie = Cappture.Cookie.get(Cappture.Cookie.Names.PRGM);
		var ls_Decoded = ls_Cookie;
			
		if (!this.Programs_State[po_Program.getId()]) 
			{
				this.Programs_State[po_Program.getId()] = {
					IsProgram: true,
					IsActive: 1,
					ViewPages: 0,
					LastDisplay: null
				};
				po_Program._Pages = 0;
				po_Program._IsActive = 1;
				po_Program.LastDisplay = null;
			}
			else 
			{
				po_Program._Pages = this.Programs_State[po_Program.getId()].ViewPages;
				po_Program._IsActive = this.Programs_State[po_Program.getId()].IsActive;
				po_Program.LastDisplay = this.Programs_State[po_Program.getId()].LastDisplay;
			}
			
		if (typeof(po_Program.Page_Threshold) == 'undefined') {po_Program.Page_Threshold = 0;}
		
		Cappture_Add_Layout(po_Program);
			//Calculate from date
		var ld_Today = new Date();
		
		if (Cappture.Cookie.get(Cappture.Cookie.Names.TESTM) != 'on') 
		{	
			if (this.Decode_Date(po_Program.Date_End, 'end') < ld_Today || this.Decode_Date(po_Program.Date_Start, 'start') > ld_Today) {
				po_Program._IsActive = 0;
				po_Program._ForceNoAction = true;
			}
		}
		//Check Hours
		if(typeof(po_Program.Hour_Start) != 'undefined')
		{
			ld_Today = new Date();
			if (this.Decode_Hour(po_Program.Hour_End, 'end') < ld_Today || this.Decode_Hour(po_Program.Hour_Start, 'start') > ld_Today) 
			{
				po_Program._IsActive = 0;
				po_Program._ForceNoAction = true;
			}
			
		}//default hours 00:00 - 23:59
		
		
		//Override KW & KW_Store when loading a group
		
		if(this._Context.length > 0)
		{
			var lo_Context = this._Context.shift();
			
			if(lo_Context.Override_Popin_Method)
			{
				po_Program.Keyword_Method = lo_Context.Keyword_Method;
				po_Program.Keywords = lo_Context.Keywords;
			}
			
			if(lo_Context.grouptype == Cappture.Group.Group_Type.TEST)
			{
				po_Program.onShow = function (){
					Cappture.Cookie.setWithExpiry(Cappture.Cookie.Names.POPINTEST, this._Group.Id + '_' + this.getId(), 3600000);
				}
			}
			
			po_Program._Group = lo_Context;
		}
		
		this.Program_Loaded++;
		this.Programs.push(po_Program);
		
		//Handle Events
		if (! po_Program._ForceNoAction){CProgram_Manager.registerEvents(po_Program.Events, po_Program);}
		
	},
	Compute: function()
	{

		if (Cappture.IE)
		{
			if(this.Program_Count > 0 && this.Programs.length == 0)
			{
				window.setTimeout('CProgram_Manager.Compute()', 1000);
				return;
			}
		}
		for(var li_Index = 0; li_Index < this.Programs.length; li_Index++)
		{
			
			var lo_Program = this.Programs[li_Index];

			//if((typeof(gb_Cappture_Connect_Demo) == 'undefined' || gb_Cappture_Connect_Demo == true) && 
			
			//Get Expiry :
			
			if(lo_Program._IsActive == 0 && !lo_Program._ForceNoAction)
			{
				if(lo_Program.Expiration != null && typeof(lo_Program.Expiration) != 'undefined' && lo_Program.Expiration != Cappture.Popin.Expiration_Time.DAY)
				{
					if(lo_Program.LastDisplay != null)
					{
						switch(lo_Program.Expiration)
						{
							case Cappture.Popin.Expiration_Time.IMMEDIATE:
								lo_Program._IsActive = 1;
								lo_Program._Pages = 0;
								break;
							case Cappture.Popin.Expiration_Time.HOUR_12:
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*5) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR_6:
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*10) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR_4:
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*15) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR_2:					
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*30) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR:	
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*60) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}			
								break;
							case Cappture.Popin.Expiration_Time.HOUR2:					
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*120) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR6:					
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*60*6) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.HOUR12:
								if((new Date().getTime() - lo_Program.LastDisplay.getTime()) > (1000*60*60*12) )
								{
									lo_Program._IsActive = 1;
									lo_Program._Pages = 0;
								}
								break;
							case Cappture.Popin.Expiration_Time.VISIT:
								//Not Implemented
								break;
							default:
								break;
						}	
					}
				}
				
				if(lo_Program._IsActive == 0){continue;}
			}
			

			if(lo_Program._IsActive == 1)
			{
				if( this.evaluate(lo_Program.Keyword_Method, lo_Program.Keywords, lo_Program.Keyword_Store_Relation))
				{
					if(lo_Program.Message_Type == Cappture.Popin.Type.SUCCESS)
					{	
						if(Cappture.Cookie.get(Cappture.Cookie.Names.POPINTEST) != '')
						{
							//a Pop-In in test group have been raised
							lo_Program.setId(Cappture.Cookie.get(Cappture.Cookie.Names.POPINTEST).split('_')[1]) ;
							this.updateProgram(lo_Program);
						}
					}
					else
					{
						this.updateProgram(lo_Program);
					}
					
				}
				
			}
			
			
			this.Programs[li_Index] = lo_Program;
		}
		this.saveState();
	},
	updateProgram: function (po_Program)
	{
		if(typeof(po_Program._AlreadyDisplay) == 'undefined')
		{
			po_Program._Pages++;
			if (po_Program._Pages >= po_Program.Page_Threshold) 
			{
				if(typeof(po_Program.Action) == 'function') 
				{
					po_Program.Action();		
				}
				else
				{
					po_Program.Display();
					//CapptureConnect_Article_Display(po_Program);
				}
			}
			else
			{
				CProgram_Manager.Programs_State[po_Program.getId()].ViewPages = po_Program._Pages;
				CProgram_Manager.Programs_State[po_Program.getId()].IsActive = po_Program._IsActive;
				CProgram_Manager.Programs_State[po_Program.getId()].LastDisplay = new Date();
				CProgram_Manager.saveState();
	
			}
			po_Program._AlreadyDisplay = true;
		}
		return;
	},
	saveState: function ()
	{
		var ls_Cookies = '';
		var ls_LastDisplay_Time = '';
		for(var li_Program in this.Programs_State)
		{
			if (this.Programs_State[li_Program].IsProgram)
			{
				if (ls_Cookies != '') {ls_Cookies += ',';}
				//compute Last Display Hour
				if(this.Programs_State[li_Program].LastDisplay != null)
				{
					ls_LastDisplay_Time = '_' + Cappture.Utils.Right('0' + this.Programs_State[li_Program].LastDisplay.getHours(), 2);
					ls_LastDisplay_Time+= Cappture.Utils.Right('0' + this.Programs_State[li_Program].LastDisplay.getMinutes(), 2);
					
				}	
				ls_Cookies += li_Program + '_' + this.Programs_State[li_Program].IsActive + '_' + this.Programs_State[li_Program].ViewPages + ls_LastDisplay_Time;	
			}
		}
		
		Cappture.Cookie.set(Cappture.Cookie.Names.PRGM, ls_Cookies);
		return;
	},
	Decode_Date: function (ps_Date_Serial, ps_StartEnd)
	{
		if (ps_Date_Serial == null || typeof(ps_Date_Serial)=='undefined'){
			return new Date();
		}
		return new Date(ps_Date_Serial.substr(0,4), ps_Date_Serial.substr(4,2)-1, ps_Date_Serial.substr(6,2),  (ps_StartEnd == 'start')?0:23,  (ps_StartEnd == 'start')?0:59,
                (ps_StartEnd == 'start')?0:59, 0);
	},
	Decode_Hour: function (ps_Hour_Serial, ps_StartEnd)
	{
		var ld_Result = new Date();
		var la_DatePart = ps_Hour_Serial.split(':');
		ld_Result.setHours(parseInt(la_DatePart[0]), parseInt(la_DatePart[1]), (ps_StartEnd == 'start')?0:59, (ps_StartEnd == 'start')?0:999);
		return ld_Result;
	},
	setLayout: function(ps_Layout)
	{
		
		if (!CC_LayoutInitialized)
		{
			this.Popin_Layout = ps_Layout;		
			switch(ps_Layout)
			{
				
				case 'Demo':
					document.write('<link href="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Styles/Demo/CappturePopin.css" rel="STYLESHEET" />');
					break;
				case 'RedCSolutions':
					document.write('<link href="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Styles/RedCSolutions/CappturePopin.css" rel="STYLESHEET" />');
					break;
				case 'Classic':	
					document.write('<link href="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Styles/Classic/CappturePopin.css" rel="STYLESHEET" />');
					break;
				case 'Free':
				default:
					document.write('<link href="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Styles/Free/CappturePopin.css" rel="STYLESHEET" />');
					break;
			}	
			CC_LayoutInitialized = true;
		}
		
	},
	getLayout_Start: function()
	{
		switch(this.Popin_Layout)
		{
			case 'Demo':
				return '<table id="CappturePopin_Layout" class="CappturePopin_Layout" border="0" cellpadding="0" cellspacing="0"><tr><td class="CappturePopin_Top_Left"><img height="25" width="12" border="0" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" /></td><td class="CappturePopin_Top_Spacer" id="CappturePopin_Top_Spacer">&nbsp;</td><td class="CappturePopin_Top_Close" width="221" style="position:relative;"><a href="javascript:Cappture_Popin_Close();"><img width="220" height="25" border="0" class="CappturePopin_Close" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" align="right" /></a></td><td class="CappturePopin_Top_Right">&nbsp;</td></tr><tr><td class="CappturePopin_Left_Spacer">&nbsp;</td><td colspan="2" class="CappturePopin_Content"><div id="CappturePopin_Content" class="CC_ResetSiteStylediv">';
				break;
			case 'RedCSolutions':
				return '<table id="CappturePopin_Layout" class="CappturePopin_Layout" border="0" cellpadding="0" cellspacing="0"><tr><td class="CappturePopin_Top_Left"><img height="30" width="17" border="0" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" /></td><td class="CappturePopin_Top_Spacer" id="CappturePopin_Top_Spacer">&nbsp;</td><td class="CappturePopin_Top_Close" width="221" style="position:relative;"><a href="javascript:Cappture_Popin_Close();"><img width="220" height="30" border="0" class="CappturePopin_Close" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" align="right" /></a></td><td class="CappturePopin_Top_Right">&nbsp;</td></tr><tr><td class="CappturePopin_Left_Spacer">&nbsp;</td><td colspan="2" class="CappturePopin_Content"><div id="CappturePopin_Content" class="CC_ResetSiteStylediv">';
				break;
			case 'Classic':
				return '<div id="CappturePopin_Layout" class="CappturePopin_Layout"><a href="javascript:Cappture_Popin_Close();" id="CappturePopin_Close" class="Cappture_Popin_Close"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Popins/Classic/Cappture_Classic_Layout_Popin_Close.gif" width="16" height="16" border="0" /></a><div id="CappturePopin_Content">';
				break;
			case 'Free':
			default:
				return '<div id="CappturePopin_Layout" class="CappturePopin_Layout"><a href="javascript:Cappture_Popin_Close();" id="CappturePopin_Close" class="Cappture_Popin_Close"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Popins/Classic/Cappture_Classic_Layout_Popin_Close.gif" width="16" height="16" border="0" /></a><div id="CappturePopin_Content">';
				break;
		}
	},
	getLayout_End:function()
	{
		switch(this.Popin_Layout)
		{
			case 'Demo':
				return '</div></td><td class="CappturePopin_Right_Spacer">&nbsp;</td></tr><tr><td class="CappturePopin_Bottom_Left">&nbsp;</td><td class="CappturePopin_Bottom_Spacer" id="CappturePopin_Bottom_Spacer"><img id="CappturePopin_Bottom_Spacer_img" height="49" width="1" border="0" src="http://tracker1.cappture.com/_Images/Transparent.gif" /></td><td width="104" class="CappturePopin_Logo"><img height="49" width="221" border="0" usemap="#BottomButtonArea" src="http://tracker1.cappture.com/_Images/Transparent.gif" /><map id="BottomButtonArea" name="BottomButtonArea"><area shape="rect" href="http://www.cappture.com" coords="101,15,142,36" /><area shape="rect" href="https://www.cappture.com/Register/enroll.html" coords="143,17,183,36" /><area shape="rect" href="javascript:Cappture_SendTweet();" coords="188,17,201,33" /></map></td><td width="17" height="49" class="CappturePopin_Bottom_Right"><img height="49" width="17" border="0" src="http://tracker1.cappture.com/_Images/Transparent.gif" /></td></tr></table>';
				break;
			case 'RedCSolutions':
				return '</div></td><td class="CappturePopin_Right_Spacer">&nbsp;</td></tr><tr><td class="CappturePopin_Bottom_Left">&nbsp;</td><td class="CappturePopin_Bottom_Spacer" id="CappturePopin_Bottom_Spacer"><img id="CappturePopin_Bottom_Spacer_img" height="48" width="1" border="0" src="http://tracker1.cappture.com/_Images/Transparent.gif" /></td><td width="104" class="CappturePopin_Logo"><img height="48" width="221" border="0" usemap="#BottomButtonArea" src="http://tracker1.cappture.com/_Images/Transparent.gif" /><map id="BottomButtonArea" name="BottomButtonArea"><area shape="rect" href="https://www.cappture.com/Register/enroll.html" coords="101,15,142,36" target="_blank"/><area shape="rect" href="javascript:Cappture_RedC_Next();" coords="143,17,183,36" /><area shape="rect" href="javascript:Cappture_SendTweet();" coords="188,17,201,33" /></map></td><td width="17" height="49" class="CappturePopin_Bottom_Right"><img height="48" width="17" border="0" src="http://tracker1.cappture.com/_Images/Transparent.gif" /></td></tr></table>';
				break;
			case 'Classic':
				return '</div></div>';
				break;
			case 'Free':
			default:
				return '</div></div><div id="CappturePopin_Logo" class="CappturePopin_Logo"><img height="29" width="213" border="0" usemap="#BottomButtonArea" src="http://tracker1.cappture.com/_Images/Transparent.gif" /><map id="BottomButtonArea" name="BottomButtonArea"><area shape="rect" href="http://www.cappture.com" coords="115,17,155,36" /><area shape="rect" href="https://www.cappture.com/Register/enroll.html" coords="158,17,199,36" /></map></div>';
				break;
		}
	},
	getLayout_Configuration: function(){},
	Keyword_Method_Set: function (ps_Keyword_Method)
	{
		this.Keyword_Method = ps_Keyword_Method;
		return;
		//format:
     //	[{'type':'URL'}, {'type':'META', 'name':'<elt>'}, {'type':'INPUT', 'name':'(#?)<elt>'},{'type':'ELEMENT', 'name':'#<elt>'} ]
	},
	Keyword_Method_Get: function ()
	{	
		return this.Keyword_Method;		
	},
	Keyword_Get: function(po_Config)
	{
		var lo_Config = (po_Config)?po_Config:this.Keyword_Method;
		
		
		gs_Cappture_Page_Keywords = '';
		if(Cappture.Utils.getType(lo_Config) == 'array')
		{
			
			for(var li_Index = 0; li_Index < lo_Config.length; li_Index++)
			{
				var lo_Item = lo_Config[li_Index];
				switch(lo_Item.type)
				{
					case 'META':
						var la_Metas = document.getElementsByTagName("META");
						for(var li_Index_Meta = 0; li_Index_Meta < la_Metas.length; li_Index_Meta++){
							if(la_Metas[li_Index_Meta].getAttribute('name') == lo_Item.name)
							{
								gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + la_Metas[li_Index_Meta].getAttribute('content');
							}
						}
						
						break;
					case 'URL':
						gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + document.location.href;
						break;
					case 'INPUT':
						if(lo_Item.name.charAt(0) == '#')
						{
							if(typeof(document.getElementById(lo_Item.name.substr(1))) != 'undefined' )
							{
								gs_Cappture_Page_Keywords +=  ((gs_Cappture_Page_Keywords.length > 0)?',':'') + document.getElementById(lo_Item.name.substr(1)).value;		
							}
							//Easy, just get the value
							
							
						}
						else
						{
							//we just have its name
							//maybe we have hierarchy <form_name>.<field_name>
							
							if(lo_Item.name.indexOf('.') != -1)
							{
								
								
								if(typeof(document.forms[lo_Item.name.split('.')[0]]) != 'undefined')
								{
									
									if(typeof(document.forms[lo_Item.name.split('.')[0]][lo_Item.name.split('.')[1]]) != 'undefined')
									{
										
										gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + document.forms[lo_Item.name.split('.')[0]][lo_Item.name.split('.')[1]].value;
									}
								}
								
							}
							else
							{
								//Brute Force
								
								for(var li_Form_Index = 0; li_Form_Index < document.forms.length; li_Form_Index++)
								{
									if(typeof(document.forms[li_Form_Index][lo_Item.name]) != 'undefined')
									{
										gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + document.forms[li_Form_Index][lo_Item.name].value;
									}
								}
							}	
						}
						break;
					case 'ELEMENT':
						//We need an ID
						if(lo_Item.name.charAt(0) == '#')
						{
							var le_Element = document.getElementById(lo_Item.name.substr(1));
							//detect
							if(typeof(le_Element) != 'undefined')
							{
								if(typeof(le_Element.value) != 'undefined')
								{
									gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + le_Element.value;
								}
								else if(typeof(le_Element.innerText) != 'undefined')
								{
									gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + le_Element.innerText;
								}
								else if(typeof(le_Element.textContent) != 'undefined')
								{
									gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0)?',':'') + le_Element.textContent;
								}	
							}
							
						}
						break;
				}
			}
		}

		return gs_Cappture_Page_Keywords;

	},
	Program_ForceDisplay: function(ps_Program_Id)
	{
		var lb_Program_IsFound = false;
		var li_Index_Program = 0;
		var lo_Program = null;
		while(! lb_Program_IsFound && li_Index_Program < this.Programs.length)	
		{
			if(this.Program_Compare_Id(this.Programs[li_Index_Program].getId(), ps_Program_Id))
			{
				lb_Program_IsFound = true;
				lo_Program = this.Programs[li_Index_Program];
			}
			li_Index_Program++;
		}
		
		if(lb_Program_IsFound)
		{
			lo_Program.Display();
			CapptureConnect_Article_Display(lo_Program);
		}
		//if(typeof(this.Pro))
	},
	Program_Compare_Id: function (ps_Id_1, ps_Id_2)
	{
		var ls_Id_1 = ps_Id_1.replace('{', '').replace('}', '').toLowerCase();
		var ls_Id_2 = ps_Id_2.replace('{', '').replace('}', '').toLowerCase();
		
		
		if(ls_Id_1 == ls_Id_2)
		{
			return true;
		}
		else
		{
			return false;
		}
	},
	getProgram: function(ps_Program_Id)
	{
		var lb_Program_IsFound = false;
		var li_Index_Program = 0;
		var lo_Program = null;
		while(! lb_Program_IsFound && li_Index_Program < this.Programs.length)	
		{
			if(this.Program_Compare_Id(this.Programs[li_Index_Program].getId(), ps_Program_Id))
			{
				lb_Program_IsFound = true;
				lo_Program = this.Programs[li_Index_Program];
			}
			li_Index_Program++;
		}
		
		//if(lb_Program_IsFound)
		//{
		return lo_Program;
//			CapptureConnect_Article_Display(lo_Program);
		//}
	},
	declareGroups: function()
	{
		var lb_LoadGroup = false;
		this.Groups = arguments;
		var la_Popins_Selector = null;
		var lo_Popin_Selected = null;
		
		this.Program_Count = 0;
		
		if(this.Groups == null || this.Groups.length == 0){return;} 
		for(var li_Index_Group = 0; li_Index_Group < this.Groups.length; li_Index_Group++)
		{
			
			lo_Group = new Cappture.Group(this.Groups[li_Index_Group]);
			lb_LoadGroup = false;
			if( this.evaluate(lo_Group.Keyword_Method, lo_Group.Keywords, lo_Group.Keyword_Store_Relation))
			{
					lb_LoadGroup = true;				
			}
			if(lb_LoadGroup)
			{
				switch(lo_Group.grouptype)
				{
					case Cappture.Group.Group_Type.TEST:
					
						//Get Group Part_Repository
						var ls_Grp_Repository = Cappture.Cookie.get(Cappture.Cookie.Names.GRPPART);
						
						//Get This group informations
						
						var toHash = function(ps_Value)
						{
							var lo_Result = {};
							var la_Groups = ps_Value.split(/,/g);
							for(var li_Group_Index = 0; li_Group_Index < la_Groups.length; li_Group_Index++)
							{
								if(la_Groups[li_Group_Index] != '')
								{
									var la_Temp = la_Groups[li_Group_Index].split('_');
									lo_Result[la_Temp[0]] = parseInt(la_Temp[1]);	
								}
								
							}
							return lo_Result;
						}
						
						var serializeHash = function(po_Hash){
							
							var la_Temp = [];
							for(var lo_Prop in lo_Hash)
							{
								la_Temp.push(lo_Prop + '_' + lo_Hash[lo_Prop]);	
							}
							return la_Temp.join(',');
						}
						
						var lo_Hash = toHash(ls_Grp_Repository);
						la_Popins_Selector = new Array();
						if(!(lo_Group.Id in lo_Hash))
						{
							/*Select Group*/
							for(var li_Index_Popin = 0; li_Index_Popin < lo_Group.Popin_List.length; li_Index_Popin++)
							{
								lo_Popin = lo_Group.Popin_List[li_Index_Popin];
								
								if(!lo_Group.Allow_Empty && lo_Popin.IsEmptyPopin) continue; 
								for(var li_Index_Popin_Temp = 0; li_Index_Popin_Temp < lo_Popin.weight; li_Index_Popin_Temp++)
								{
									la_Popins_Selector.push(lo_Popin);
								}
							}
							lo_Popin_Selected = la_Popins_Selector[Math.floor(Math.random() * (la_Popins_Selector.length - 1))];
							if(lo_Popin_Selected != null)
							{
								lo_Hash[lo_Group.Id]  = lo_Popin_Selected.group;
							}
						}
						else
						{
							var li_Group = parseInt(lo_Hash[lo_Group.Id]);
							for(var li_Index_Popin = 0; li_Index_Popin < lo_Group.Popin_List.length; li_Index_Popin++)
							{
								lo_Popin = lo_Group.Popin_List[li_Index_Popin];
								
								//if(!lo_Group.Allow_Empty && lo_Popin.IsEmptyPopin) continue; 
								if (li_Group == lo_Popin.group) {
									lo_Popin_Selected = lo_Popin;
									break;
								}
							}
						}
						
						if(lo_Popin_Selected != null)
						{
							
							this.Program_Count++;
							var ls_URL = Cappture.Utils.createURL(lo_Popin_Selected.name + '.js?k=' + CProgram_Manager.getFileBank());
							lo_Group._Condition = lo_Popin_Selected.condition;
												
							this._Context.push(lo_Group);
							Cappture.Communication.load(ls_URL);	
						}
						else
						{
							//Cappture.Cookie.set(Cappture.Cookie.Names.POPINTEST, '');
							//Blind Pop-In
						}	
						Cappture.Cookie.set(Cappture.Cookie.Names.GRPPART, serializeHash(lo_Hash));
						
						break;
					case Cappture.Group.Group_Type.LOAD:
						for(var li_Index_Popin = 0; li_Index_Popin < lo_Group.Popin_List.length; li_Index_Popin++)
						{
							lo_Popin = lo_Group.Popin_List[li_Index_Popin];
							
							var ls_URL = Cappture.Utils.createURL(lo_Popin.name + '.js?k=' + CProgram_Manager.getFileBank());						
							this.Program_Count++;
							this._Context.push(lo_Group);
							Cappture.Communication.load(ls_URL);
							
						}	
						break;
					case Cappture.Group.Group_Type.CHAIN:
						for(var li_Index_Popin = 0; li_Index_Popin < lo_Group.Popin_List.length; li_Index_Popin++)
						{
							lo_Popin = lo_Group.Popin_List[li_Index_Popin];
							var ls_URL = Cappture.Utils.createURL(lo_Popin.name + '.js?k=' + CProgram_Manager.getFileBank());						
							this.Program_Count++;
							this._Context.push(lo_Group);
							Cappture.Communication.load(ls_URL);
						}	
						break;	
					
				}
			}
			
			
		}
	},
	getFileBank: function()
	{
		
		var ls_FileBank_Id = Cappture.Cookie.get('CSM_FILEBANK');
		
		if ((ls_FileBank_Id) == '')
		{
			ls_FileBank_Id = Math.floor(Math.random() * (this.FileBank_Max - 1)) + 1
			Cappture.Cookie.set('CSM_FILEBANK', ls_FileBank_Id);
		}
		
		return ls_FileBank_Id;
	},
	onScroll: function(pe_Event)
	{
		
		
		if(cc_LOP != null)
		{
			if(typeof(cc_LOP.onScroll) == 'function' )
			{
				cc_LOP.onScroll();
			}
		}

		if(typeof CProgram_Manager.EventStack['Event.Scroll'] == 'undefined'){return;}

		var lo_First_Element = CProgram_Manager.EventStack['Event.Scroll'][0];
		if(lo_First_Element == null) {return;}
		var la_Sroll = Cappture.Utils.Window.getScrollXY();
		var li_Threshold = la_Sroll[1] + 50;
		
		if(typeof lo_First_Element._Threshold == 'function'){
			li_Threshold  = lo_First_Element._Threshold();
		}
		else{
			li_Threshold = lo_First_Element._Threshold;
		}
		
		if (la_Sroll[1] >= li_Threshold)
		{
			lo_First_Element._Handle();
			CProgram_Manager.EventStack['Event.Scroll'].pop();	
			pe_Event.cancelBubble = true;
			if (pe_Event.stopPropagation) {pe_Event.stopPropagation();}
		}
		return;
	},
	onResize: function(pe_Event)
	{
		
		
		if(cc_LOP != null)
		{
			if(typeof(cc_LOP.onResize) == 'function' )
			{
				cc_LOP.onResize();
			}
		}
		return;
	},
	onClick: function (pe_Event, po_Object)
	{
		
		if(Cappture.Utils.getType(po_Object.beforeClick) == 'function' )
		{
			Cappture_FunctionHelper(po_Object, 'beforeClick', pe_Event);
		}
		//do Click Event
		/////////////////
		
		var tgt = pe_Event.target || pe_Event.srcElement;
		
		var ls_Link  = '';
		var cc_InitialAction = null;
		var la_Properties = [];
		
		var cc_InitialAction = Cappture_GetParentLink(tgt, la_Properties);
		if (cc_InitialAction != null)
		{
			if(la_Properties[0] == 'form')
			{
				ls_Link = 'linktarget=' + escape(cc_InitialAction);	
			}
			else
			{
				ls_Link = 'linktarget=' + escape(la_Properties[1]);	
			}
		}
		
		
		//return false;
		// Get top lef co-ords of div
		var divX = Cappture.Utils.getPosition(tgt).x;
		var divY = Cappture.Utils.getPosition(tgt).y;
		
		// Workout if page has been scrolled
		var pXo = Cappture.Utils.Window.getScrollXY()[0];
		var pYo = Cappture.Utils.Window.getScrollXY()[1];
		
		// Subtract div co-ords from event co-ords
		var clickX = pe_Event.clientX - divX + pXo;
		var clickY = pe_Event.clientY - divY + pYo;
		
		if(ls_Link != '') {ls_Link += '&';}
		ls_Link += 'cc_posx=' +  escape(clickX);
		ls_Link += '&cc_posy=' +  escape(clickY);
		
			
		
		if(cc_InitialAction != null)
		{
		   	if(cc_InitialAction.indexOf('javascript:') != -1)
			{
				//call javascript
				window.Cappture_OCH = new Function(cc_InitialAction.replace('javascript:', ''));
				window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', null), 500);
				//eval(cc_InitialAction.replace('javascript:', ''));
			}
			else
			{
				//call 
				if(cc_InitialAction.indexOf('|') != -1)
				{
					document.getElementById('Cappture_Popin').innerHTML += '<form action="' + cc_InitialAction.split('|')[0] + '" target="' + cc_InitialAction.split('|')[0] + '" id="CC_Link" method="GET"></form>';
					window.Cappture_OCH = new Function('document.getElementById(\'CC_Link\').submit();');
					window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', null), 500);
				}
				else
				{
					window.Cappture_OCH = function(ps_URL){document.location.href = ps_URL};
					window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', cc_InitialAction), 500);
				}
			}
			Cappture.Communication.sendStat(cc_LOP, 1, ls_Link);
		}
			
		
		if(Cappture.Utils.getType(po_Object.onclick) == 'function' )
		{
			Cappture_FunctionHelper(po_Object, 'onclick', [pe_Event]);
		}
		
		pe_Event.cancelBubble = true; 
		if(pe_Event.stopPropagation){pe_Event.stopPropagation();}   
	},
	registerEvents: function(pa_Events, po_Object)
	{
		if(typeof pa_Events != 'undefined')
		{
			for(var li_Index_Event = 0; li_Index_Event < pa_Events.length; li_Index_Event++)
			{
				if (Cappture.Utils.getType(CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype]) != 'array')
				{
					CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype] = new Array();
				}
				switch(pa_Events[li_Index_Event].ctype)
				{
					case 'Event.Scroll':
						CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype].push(new Cappture.Event.Scroll(pa_Events[li_Index_Event].Threshold, po_Object,pa_Events[li_Index_Event].handle))
						CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype].sort(function(po_Element_1, po_Element_2){return po_Element_1._Threshold - po_Element_2._Threshold;})
						break;
					case 'Event.Click':
						CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype].push(new Cappture.Event.Click(po_Object,pa_Events[li_Index_Event].handle))
						break;
					case 'Event.Move':
						CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype].push(new Cappture.Event.Move(po_Object,pa_Events[li_Index_Event].handle))
						break;
					case 'Event.Show':
						CProgram_Manager.EventStack[pa_Events[li_Index_Event].ctype].push(new Cappture.Event.Show(po_Object,pa_Events[li_Index_Event].handle))
						break;
				}
				
			}
		}
	},
	evaluate: function(po_Config, ps_Keyword, ps_Keyword_Method_Relation)
	{
		var ls_CurrentItem_Keywords;
		var lo_Config = null;
		var ls_Keyword_Method_Relation = 'OR';
		var li_While_Exit_Condition = 1;
		var ls_Program_Keywords_RAW = '';
		var la_Program_Keywords= [];
		gs_Cappture_Page_Keywords = '';
		try {
			lo_Config = (po_Config) ? po_Config : this.Keyword_Method;
			ls_Keyword_Method_Relation = (ps_Keyword_Method_Relation && ps_Keyword_Method_Relation != '') ? ps_Keyword_Method_Relation : 'OR';
			ls_Program_Keywords_RAW = ps_Keyword.toLowerCase();
			la_Program_Keywords = ls_Program_Keywords_RAW.split(/,\s?/);	
		}
		catch(e){}
		
		if(Cappture.Utils.getType(lo_Config) != 'array')
		{
			lo_Config = [lo_Config];
		}
		
		try {
			if (Cappture.Utils.getType(lo_Config) == 'array') {
			
				var li_Index = 0;
				
				
				if (ls_Keyword_Method_Relation == 'AND') {
					li_While_Exit_Condition = lo_Config.length;
				}
				while (li_Index < lo_Config.length && li_While_Exit_Condition > 0) {
					var lo_Item = lo_Config[li_Index];
					ls_CurrentItem_Keywords = '';
					
					if (typeof(lo_Item.value) != 'undefined' && lo_Item.value != null) {
						ls_Program_Keywords_RAW = lo_Item.value.toLowerCase();
						la_Program_Keywords = ls_Program_Keywords_RAW.split(/,\s?/);
					}
					
					switch (lo_Item.type) {
						case 'COOKIE':
							
							if (lo_Item.name.charAt(0) == '%') {
								if (Cappture.Cookie.get(lo_Item.name.substr(1)) != '') {
									ls_CurrentItem_Keywords = la_Program_Keywords[0];
								}
							}
							else 
								if (lo_Item.name.charAt(0) == '!') {
									if (Cappture.Cookie.get(lo_Item.name) == '') {
										ls_CurrentItem_Keywords = la_Program_Keywords[0];
									}
								}
								else {
									ls_CurrentItem_Keywords = Cappture.Cookie.get(lo_Item.name);
								}
							
							
							break;
						case 'META':
							var la_Metas = document.getElementsByTagName("META");
							for (var li_Index_Meta = 0; li_Index_Meta < la_Metas.length; li_Index_Meta++) {
								if (la_Metas[li_Index_Meta].getAttribute('name') == lo_Item.name) {
									ls_CurrentItem_Keywords = la_Metas[li_Index_Meta].getAttribute('content');
								}
							}
							
							break;
						case 'URL':
							ls_CurrentItem_Keywords = document.location.href;
							break;
						case 'INPUT':
							if (lo_Item.name.charAt(0) == '#') {
								if (typeof(document.getElementById(lo_Item.name.substr(1))) != 'undefined') {
									ls_CurrentItem_Keywords = document.getElementById(lo_Item.name.substr(1)).value;
								}
							//Easy, just get the value
							
							
							}
							else {
								//we just have its name
								//maybe we have hierarchy <form_name>.<field_name>
								
								if (lo_Item.name.indexOf('.') != -1) {
								
								
									if (typeof(document.forms[lo_Item.name.split('.')[0]]) != 'undefined') {
									
										if (typeof(document.forms[lo_Item.name.split('.')[0]][lo_Item.name.split('.')[1]]) != 'undefined') {
										
											ls_CurrentItem_Keywords = document.forms[lo_Item.name.split('.')[0]][lo_Item.name.split('.')[1]].value;
										}
									}
									
								}
								else {
									//Brute Force
									
									for (var li_Form_Index = 0; li_Form_Index < document.forms.length; li_Form_Index++) {
										if (typeof(document.forms[li_Form_Index][lo_Item.name]) != 'undefined') {
											ls_CurrentItem_Keywords = document.forms[li_Form_Index][lo_Item.name].value;
										}
									}
								}
							}
							break;
						case 'ELEMENT':
							//We need an ID
							if (lo_Item.name.charAt(0) == '#') {
								var le_Element = document.getElementById(lo_Item.name.substr(1));
								//detect
								if (typeof(le_Element) != 'undefined') {
									if (typeof(le_Element.value) != 'undefined') {
										ls_CurrentItem_Keywords = le_Element.value;
									}
									else {
										if (typeof(le_Element.innerText) != 'undefined') {
											ls_CurrentItem_Keywords = le_Element.innerText;
										}
										else {
											if (typeof(le_Element.textContent) != 'undefined') {
												ls_CurrentItem_Keywords = le_Element.textContent;
											}
										}
									}
								}
							}
							break;
					}
					ls_CurrentItem_Keywords = ls_CurrentItem_Keywords.toLowerCase();
					
					for (var li_Index_KW = 0; li_Index_KW < la_Program_Keywords.length; li_Index_KW++) {
						if (ls_CurrentItem_Keywords.indexOf(la_Program_Keywords[li_Index_KW].toLowerCase()) != -1) {
							li_While_Exit_Condition--;
							break;
						}
					}
					
					gs_Cappture_Page_Keywords += ((gs_Cappture_Page_Keywords.length > 0) ? ',' : '') + ls_CurrentItem_Keywords;
					li_Index++;
				}
			}
		}catch(e)
		{
			
		}
		
		return (li_While_Exit_Condition == 0);
	},
	onUnload: function(pe_Event)
	{
		
		//pe_Event.cancelBubble = true; 
      	//if (pe_Event.stopPropagation) pe_Event.stopPropagation();
		//check if we really quit the site, or its just navigation Stuff
		if(CProgram_Manager._isClickEvent)
		{
			return;	
		}	
		else
		{
			return "";
		}	
		CProgram_Manager._isUnloadReady = true;
		
		
	},
	InitializeHistoryManager: function()
	{
		
	},
	getHistoryManager: function(){
		return this._History;
	},
	Cappture_Load_Callback: function(po_Result, ps_Callback_Id)
	{
		if(window[ps_Callback_Id] == null){return {Result:null, isReady:true};}
		
		
		window[ps_Callback_Id].Result = po_Result;
		window[ps_Callback_Id].isReady = true;
		return;
	},
	
	Cappture_LoadHistory: function(po_History)
	{
		this.getHistoryManager().initialize(po_History);
	},
	
	RefreshPopin: function()
	{
		if(cc_LOP != null)
		{
			CapptureConnect_Initialize();
			cc_LOP.getPlaceHolder().style.display = 'block';
		    cc_LOP._RefreshDisplay();
			cc_LOP.getPlaceHolder().style.visibility = 'visible';
			
		}
	},
	
	Extend: function (po_Properties)
	{
		for(var ls_Property in po_Properties)
		{
			if (CProgram_Manager[ls_Property] == null)
			{
				CProgram_Manager[ls_Property] = po_Properties[ls_Property];
			}
		}
		return true;
	}
	
};


Cappture.Group = function(po_Option)
{
	this.Id = -1;
	this.ctype = 'group';
	this.Keyword_Method = [{type:'URL', name:'', value:''}];
	this.Popin_List= null; //[{name, weight}]
	this.Override_Popin_Method = true;
	
	if (po_Option != null)
	{
		for(var ls_Option in po_Option)
		{
			this[ls_Option] = po_Option[ls_Option];
		}
	}
}
Cappture.Group.Group_Type = {TEST:'MESSAGEWEBGROUP_TYPE_TEST', LOAD:'MESSAGEWEBGROUP_TYPE_LOAD', CHAIN:'MESSAGEWEBGROUP_TYPE_CHAIN'};
Cappture.Group.Group_Test_Condition = {CLICK:'MESSAGEWEBGROUP_SUCCESS_CLICK', FORM:'MESSAGEWEBGROUP_SUCCESS_FORM', BUY:'MESSAGEWEBGROUP_SUCCESS_BUY', DISPLAY:'MESSAGEWEBGROUP_SUCCESS_DISPLAY'};

if(typeof(gs_Cappture_Page_Keywords)== 'undefined'){ gs_Cappture_Page_Keywords = '';}

function Cappture_GetWidth(pe_Element)
{
	var li_Width = parseInt(pe_Element.style.width);if(isNaN(li_Width))li_Width=pe_Element.offsetWidth;
	return li_Width;
}

function Cappture_ComputeStyle(pe_Element)
{
	//return;
	var p = pe_Element;
	
	var c = p.getElementsByTagName("*");
	for(var i = 0; i < c.length; i++)
	{
		if(p.offsetHeight < (c[i].offsetHeight + c[i].offsetTop))
		p.style.height = (c[i].offsetHeight + c[i].offsetTop) + "px";
		if(p.offsetWidth < (c[i].offsetWidth + c[i].offsetLeft))
		p.style.width = (c[i].offsetWidth + c[i].offsetLeft) + "px";
	} 
	
	
	
}
function Cappture_GetHeight(pe_Element)
{
	var li_Height = parseInt(pe_Element.style.height);
	
	if(isNaN(li_Height)) {li_Height = pe_Element.offsetHeight;}
	return li_Height;
}

function CapptureConnect_Initialize()
{
	document.getElementById('Cappture_Popin').innerHTML = '';
	document.getElementById('Cappture_Popin').style.top = null;
	document.getElementById('Cappture_Popin').style.left = null;
	document.getElementById('Cappture_Popin').style.bottom = null;
	document.getElementById('Cappture_Popin').style.right = null;
	document.getElementById('Cappture_Popin').style.width = 'auto';
	document.getElementById('Cappture_Popin').style.height = 'auto';
	document.getElementById('Cappture_Popin').style.position = 'absolute';
}


function Cappture_Popin_Close()
{
	document.getElementById('Cappture_Popin').style.display = 'none';
	document.getElementById('Cappture_Popin').style.visibility = 'hidden';
	document.getElementById('Cappture_Popin').innerHTML = '';
	
	Cappture.Communication.sendStat(cc_LOP, 10);
	return;
	
}

function Cappture_ReplaceLink(pe_Element,po_Popin)
{
	var lb_LinkFound = false;
	var le_Element;
	
	var lo_Result;
	
	
	for(var li_Index = 0; li_Index < pe_Element.childNodes.length; li_Index++)
	{	
		le_Element = pe_Element.childNodes[li_Index];	
		try
		{
			if (le_Element.getAttribute && le_Element.getAttribute('p_norewrite') == 'true' || le_Element.getAttribute('p_isready') == 'true')
			{
				continue;
			}
		}
		catch (excd)
		{
		}
		
		if(Cappture.IE && le_Element.nodeName == 'img' && le_Element.src.toLower().indexOf('/popins/') == -1 && le_Element.src.toLower().indexOf('transaprent.gif')==-1)
		{
			//le_Element.setAttribute('onload', 'Cappture.Popin.adapt()');

		}
		else if(le_Element.href && le_Element.nodeName.toLowerCase() != 'img')
		{
			try 
				{
					
					lb_LinkFound = true;
					lo_Result = new String(le_Element.href);
					
					if (lo_Result.indexOf('Cappture_Popin_Close') == -1) 
					{
					
						if (le_Element.getAttribute('target') != null && le_Element.getAttribute('target') != '' && typeof(le_Element.getAttribute('target')) != 'undefined')
						{
							le_Element.setAttribute('cc_link', le_Element.href + '|' + le_Element.getAttribute('target') + '|GET');
						} 
						else 
						{
							le_Element.setAttribute('cc_link', lo_Result.toString());
						}	
						try 
						{
							le_Element.setAttribute('p_isready', 'true');
							le_Element.setAttribute('href', 'javascript:void(0)');
						} 
						catch (e) 
						{
						}
					}
				}
				catch(e){}
		}
		else if (le_Element.onclick)
		{
			
		}
		else if(le_Element.type && le_Element.type == 'submit')
		{

			//change to button 
			// need to retrieve the right form
			var ls_CCLink = '';
			var le_CurrentElement = le_Element;
			var lb_FormFound = false;
			
			do		
			{
				le_CurrentElement = le_CurrentElement.parentNode;
				if(le_CurrentElement.nodeName.toLowerCase() == 'form'){lb_FormFound = true;}

			}
			while(le_CurrentElement.nodeName.toLowerCase() != 'form' && le_CurrentElement.id != 'Cappture_Popin' && !lb_FormFound);
			
			if(lb_FormFound)
			{
				if(le_CurrentElement.name != '')
				{
					ls_CCLink = 'javascript:document.' + le_CurrentElement.name + '.submit()';
				}
				else if(le_CurrentElement.id != '')
				{
					ls_CCLink = 'javascript:document.getElementById(\'' + le_CurrentElement.name + '\').submit()';

				}
				else
				{
					//give a name to this form
					le_CurrentElement.name = 'CC_FORM_TMP';
					ls_CCLink = 'javascript:document.' + le_CurrentElement.name + '.submit()';
				}
				
				if(le_CurrentElement.getAttribute('onsubmit') != null && le_CurrentElement.getAttribute('onsubmit') != '' && typeof(le_CurrentElement.getAttribute('onsubmit')) != 'undefined')
				{
					le_Element.setAttribute('cc_formsubmit', le_CurrentElement.getAttribute('onsubmit'));
				}
				//le_CurrentElement.setAttribute('onsubmit', 'return false;');
				
				
				
				
				//if (le_CurrentElement.getAttribute('target') != null && le_CurrentElement.getAttribute('target') != '' && typeof(le_CurrentElement.getAttribute('target')) != 'undefined')
				//	le_Element.setAttribute('cc_link', ls_CCLink + '|' + ((le_Element.getAttribute('method') == '' || le_Element.getAttribute('method') == null )?'POST':le_Element.getAttribute('method')) + '|' + le_CurrentElement.getAttribute('target'));
				//else
				le_Element.setAttribute('cc_link', ls_CCLink + '|' + ((le_Element.getAttribute('method') == '' || le_Element.getAttribute('method') == null )?'POST':le_Element.getAttribute('method')) + '|' +((le_Element.getAttribute('target') == '' || le_Element.getAttribute('target') == null )?'':le_Element.getAttribute('target')) );
				
				le_Element.setAttribute('cc_formaction', 	le_CurrentElement.getAttribute('action'));
				le_Element.setAttribute('cc_formname', 		le_CurrentElement.name);
				le_Element.setAttribute('cc_method', 		le_CurrentElement.getAttribute('method'));
				//le_CurrentElement.setAttribute('action', null);
				//le_Element.type = 'button';
				le_Element.setAttribute('onclick', 'void(0)');
				le_Element.setAttribute('p_isready', 'true');
			}
		}
		
		Cappture_ReplaceLink(le_Element);
	}
	return;
}

function Cappture_GetParentLink(pe_Element, pa_Properties)
{
	var lb_LinkFound = false;
	var lo_Result = null;
	while(pe_Element.nodeName.toLowerCase() != 'body' && pe_Element.id != 'Cappture_Popin' && !lb_LinkFound)
	{
		if(pe_Element.getAttribute('cc_link') != null && pe_Element.getAttribute('cc_link') != '' && typeof(pe_Element.getAttribute('cc_link')) != 'undefined')
		{
			lb_LinkFound = true;
			lo_Result = pe_Element.getAttribute('cc_link');
			if (pe_Element.getAttribute('cc_formaction') != null && pe_Element.getAttribute('cc_formaction') != '' && typeof(pe_Element.getAttribute('cc_formaction')) != 'undefined') 
			{
				pa_Properties.push('form');
				pa_Properties.push(pe_Element.getAttribute('cc_formaction'));
				pa_Properties.push((pe_Element.getAttribute('cc_formname'))?(pe_Element.getAttribute('cc_formname')):'');
			}
			else 
			{
				pa_Properties.push('link');
				pa_Properties.push(lo_Result);
				pa_Properties.push((pe_Element.getAttribute('name'))?pe_Element.getAttribute('name'):'');
			}
		}
		else if(pe_Element.onclick)
		{
			lb_LinkFound = true;
			lo_Result = pe_Element.onclick;
			pa_Properties.push('click');
			pa_Properties.push(lo_Result);
			pa_Properties.push((pe_Element.getAttribute('name'))?pe_Element.getAttribute('name'):'');
		}
		else if(pe_Element.ondblclick)
		{
			lb_LinkFound = true;
			lo_Result = pe_Element.ondblclick;
			pa_Properties.push('dblclick');
			pa_Properties.push(lo_Result);
			pa_Properties.push((pe_Element.getAttribute('name'))?pe_Element.getAttribute('name'):'');
			
		}
		pe_Element = pe_Element.parentNode;
	}
	return lo_Result;
}

function Cappture_Connect_Click(pe_Event)
{
	var li_Type = 1;
	var ls_Condition = '';
	var lb_IsForm = null;
	var lb_Check_Click = false;


	
	if(cc_LOP._Group && cc_LOP._Group.grouptype == Cappture.Group.Group_Type.TEST )
	{
		
		if(cc_LOP._Group.Test_Condition == Cappture.Group.Group_Test_Condition.FORM)
		{
			lb_IsForm = true;
			lb_Check_Click = true;
		}
		else if(cc_LOP._Group.Test_Condition == Cappture.Group.Group_Test_Condition.CLICK)
		{
			lb_IsForm = false;
			lb_Check_Click= true;
		}
		
		ls_Condition = (cc_LOP._Group._Condition || '');
	}
	var tgt = pe_Event.target || pe_Event.srcElement;
	
	
	//return false;
	// Get top lef co-ords of div
	var divX = Cappture.Utils.getPosition(tgt).x;
	var divY = Cappture.Utils.getPosition(tgt).y;
	
	// Workout if page has been scrolled
	var pXo = Cappture.Utils.Window.getScrollXY()[0];
	var pYo = Cappture.Utils.Window.getScrollXY()[1];
	
	// Subtract div co-ords from event co-ords
	var clickX = pe_Event.clientX - divX + pXo;
	var clickY = pe_Event.clientY - divY + pYo;

	var ls_Link  = '';
	var cc_InitialAction = null;
	var la_Properties = [];
	
	var cc_InitialAction = Cappture_GetParentLink(tgt, la_Properties);

	if (cc_InitialAction != null)
	{
		if(la_Properties[0] == 'form')
		{
			ls_Link = 'linktarget=' + escape(cc_InitialAction);	
			
			if(lb_Check_Click && lb_IsForm)
			{
				if (ls_Condition != '')
				{
					if (la_Properties[2].toLowerCase() == ls_Condition.toLowerCase())
					{
						li_Type = 4;
					}
				}
				else
				{
					li_Type = 4;
				}

			}
			else
			{
				li_Type = 5;
			}
		}
		else
		{
			ls_Link = 'linktarget=' + escape(la_Properties[1]);	
			if(lb_Check_Click && !lb_IsForm)
			{
				if (ls_Condition != '')
				{
					if (la_Properties[2].toLowerCase() == ls_Condition.toLowerCase())
					{
						li_Type = 4;
					}
				}
				else
				{
					li_Type = 4;
				}

			}
		}
	}
	

	
	
	if(ls_Link != '') ls_Link += '&'
	ls_Link += 'cc_posx=' +  escape(clickX);
	ls_Link += '&cc_posy=' +  escape(clickY);
   	
   
   if(cc_InitialAction != null)
   {
	   	if(cc_InitialAction.indexOf('javascript:') != -1)
		{
			//call javascript
			window.Cappture_OCH = new Function(unescape(cc_InitialAction.replace('javascript:', '')));
			window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', null), 500);
			//eval(cc_InitialAction.replace('javascript:', ''));
		}
		else
		{
			//call 
			if(cc_InitialAction.indexOf('|') != -1)
			{
				document.getElementById('Cappture_Popin').innerHTML += '<form action="' + cc_InitialAction.split('|')[0] + '" target="' + cc_InitialAction.split('|')[1] + '" id="CC_Link" method="' + cc_InitialAction.split('|')[2] +'"></form>';
				window.Cappture_OCH = new Function('document.getElementById(\'CC_Link\').submit();');
				window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', null), 500);
			}
			else
			{
				window.Cappture_OCH = function(ps_URL){document.location.href = ps_URL};
				window.setTimeout(Cappture_FunctionHelper(window,'Cappture_OCH', cc_InitialAction), 500);
			}
		}
		try 
		{
			if (cc_LOP.onclick) {
				cc_LOP.onclick(pe_Event);
			}
		} 
		catch (e) 
		{
		
		}
		Cappture.Communication.sendStat(cc_LOP, li_Type, ls_Link);
   }
  return;
}

function Cappture_Querystring_Parameter_Get(ps_Name)
{
	return Cappture.Utils.QueryString.Parameter_Get(ps_Name);
}


function Cappture_Add_Layout(po_Program)
{
	//add new Layout to message
	po_Program.Message = CProgram_Manager.getLayout_Start() + po_Program.Message + CProgram_Manager.getLayout_End();
}








if (!Cappture.IE6) 
{
	
	CProgram_Manager.initialize();
	document.write('<img id="Cappture_Tube" width="0" height="0" border="0" alt="" />');
	document.write('<style type="text/css">#Cappture_Popin{position:absolute;z-index:1500;width:auto;height:auto;visibility:hidden;display:none;}</style><div id="Cappture_Popin" class="CC_ResetSiteStylediv" onclick="Cappture_Connect_Click(event)" ></div>');	
	
	if(typeof(gs_Cappture_Bootstrap_URL) != 'undefined' && gs_Cappture_Bootstrap_URL != '')
		document.write('<script type="text/javascript" src="'  + gs_Cappture_Bootstrap_URL + '"></script>');	
	else
		document.write('<script type="text/javascript" src="' + Cappture.Utils.createURL('/Cappture_Connect_Create.aspx?ms=' + new Date().getTime()) + '"></script>');		
	///document.write('<script type="text/javascript" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Tracker/twitter.js"></script>');
	
	if(typeof(gb_Cappture_Connect_Demo) != 'undefined' && gb_Cappture_Connect_Demo == true)
	{
		var ls_DemoStyle = '';
		if(typeof(Cappture.IE) != 'undefined' && Cappture.IE && !Cappture.IE8)
			ls_DemoStyle = 'position:absolute;top:expression(eval(document.compatMode &&document.compatMode=="CSS1Compat") ? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight-10)  : document.body.scrollTop+(document.body.clientHeight-this.clientHeight -10));left:expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollLeft + 10 : document.body.scrollLeft + 10);width:269px;height:200px;z-index: 15001;background-repeat:no-repeat;background-image:url("http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Demo/Demo_ControlPanel.png");';
		else
			ls_DemoStyle = 'position:fixed;bottom:10px;left:10px;width:269px;height:200px;z-index: 15001;background-image:url("http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Demo/Demo_ControlPanel.png");background-repeat:no-repeat'
		
		document.write('<style type="text/css">#Cappture_Demo_Panel_Button_Left{float:right; margin-left: 2px;margin-right: 2px;margin-top:4px;}#Cappture_Demo_Panel_Button_Right{float:right; margin-left: 2px;margin-right: 2px;margin-top:4px;}#Cappture_Demo_Panel{' + ls_DemoStyle + '}</style><table cellpadding="0" cellspacing="0" border="0" class="CC_ResetSiteStylediv" id="Cappture_Demo_Panel" style="width:269px;height:200px;" width="269" height="200"><tbody><tr><td colspan="4" width="269"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="269" height="78" border="0" /></td></tr><tr><td width="51"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="53" height="70" border="0" /></td><td width="202" style="width:202px" colspan="2"><div id="CappturePopin_Demo_Description"></div></td><td width="17"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="17" height="70" border="0" /></td></tr><tr><td width="53"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="53" height="26" border="0" /></td><td width="132"><div id="CappturePopin_Demo_Hint"></div></td><td width="70"><a id="Cappture_Demo_Panel_Button_Right" href="javascript:Cappture_Demo_Next();"><img border="0" src="http://tracker1.cappture.com/_Images/Demo/Demo_ControlPanel_Button_Right.png" valign="middle"/></a><a id="Cappture_Demo_Panel_Button_Left" href="javascript:Cappture_Demo_Previous();" valign="middle"><img border="0" src="http://tracker1.cappture.com/_Images/Demo/Demo_ControlPanel_Button_Left.png"  valign="middle"/></a></td><td><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="17" height="23" border="0" /></td></tr><tr><td colspan="4" width="269"><img src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Images/Transparent.gif" width="269" height="23" border="0" /></td></tr></tbody></table><form id="Cappture_Demo_Form" method="get" action="http://tracker1.cappture.com/_InstantDemo/InstantDemo.aspx"><input type="hidden" name="keyword" id="Cappture_Keyword" value="" /><input type="hidden" name="url_source" id="Cappture_URL" value="" /><input type="hidden" name="AD" id="Cappture_AD" value="" /><input type="hidden" name="cd_language" id="Cappture_Language" value="" /></form>');
		document.write('<script type="text/javascript" src="http' + Cappture.IsSSL + '://tracker1.cappture.com/_Tracker/Cappture_Connect_Demo.js"></script>');
		
		
	}
	
	if(Cappture_Querystring_Parameter_Get('cc_testmode') == 'on')
	{
		Cappture.Cookie.set(Cappture.Cookie.Names.TESTM, 'on');
	}
	else if(Cappture_Querystring_Parameter_Get('cc_testmode') == 'off')
	{
		Cappture_DeleteCookie(Cappture.Cookie.Names.TESTM);
	}
	
	if(Cappture.Cookie.get(Cappture.Cookie.Names.TESTM) == 'on')
	{
		document.write('<a class="Cappture_Reset_Link" href="javascript:Cappture.Cookie.reset();">Reinit</a>');
	}
}

function Cappture_GetScrollXY() {
	return Cappture.Utils.Window.getScrollXY();
}


//Register watches
Cappture.Event.registerEvent(window, 'scroll', CProgram_Manager, 'onScroll', null);
//Cappture.Event.registerEvent(window, 'resize', CProgram_Manager, 'onResize', null);







