/** OnClose **/
/** Content\Scripts\1\onclose.js **/
var _LastVision = new Object();

_LastVision.init = function(){
	this.enabled = true;
	this.mainText = 'In order to see it - click "Cancel"';
	this.prealertText = 'There are two business owners, who want to contact you with all the necessary information on how to start your business.\nClick "Cancel" on the next window.';
	this.pixel = '<img src="http://www.gmbtrack.com/tracki.asp?a=408&o=46&c=0&l=7" width="1" height="1" border="0">';
	this.stat_new_id = '1';
	this.cookieShow = '';
	this.cookieAlert = '';
	this.links_count = 1;
	this.link_to_redir = 'http://www.last-vision.com:80/tracking/go/workathomequiz-1';
	this.service_pixel = '<img src="#" width="1" height="1" alt="" border="0" />';
}


_LastVision.init.prototype = {
	ReadCookie : function ( name ) {
		var cookie = document.cookie;
		var search = name + "=";
		var setStr = null;
		var offset = 0;
		var end = 0;
		if ( cookie.length > 0 ) {
			offset = cookie.indexOf( search );
			if ( offset != -1 ) {
				offset += search.length;
				end = cookie.indexOf( ";", offset )
				if ( end == -1 )
					end = cookie.length;
				setStr = unescape( cookie.substring( offset, end ) );
			}
		}
		if ( setStr == '' || setStr == null )
			return false
		else
			return setStr ;
	},
	
	
	intRand : function( startInt, stopInt ) {
		var start = parseInt( startInt, 10 );
		var stop = parseInt( stopInt, 10 );
		var rand;
		
		while ( true ) {
			rand = Math.round( Math.random() * ( stop + 1 ) );
			if ( ( rand >= start ) && ( rand <= stop ) ) return rand;
		}
	},

	
	LV_Main : function() {
		if ( once_closed === true || !this.enabled )	return;
		
		try {
			if ( this.prealertText.length > 21 ) 
			{
				$(document.body).append(this.pixel);
				$(document.body).append(this.service_pixel);
				alert( this.prealertText );
			}
			var i = this.intRand(1, this.links_count);
			document.location.href = this.link_to_redir;
			once_closed = true;
			this.enabled = false;
			return this.mainText;
		} catch (err) {}
	},

	
	create: function(){
		this.cookieAlert = this.ReadCookie('alert');
		this.cookieShow = this.ReadCookie('show');
		
		if ( (this.cookieShow === false) && (this.cookieAlert === false) ) {
			
			jQuery(document).ready(
				function() {
					
					document.body.onkeydown = window.onkeydown = function() {
						var KeyCode = false;
						var CtrlKey = false;
						
						var mozEvent = arguments[0];
						
						try 			{ KeyCode = mozEvent.which; }
						catch ( err )	{ KeyCode = event.keyCode; }
						
						try				{ CtrlKey = mozEvent.ctrlKey; }
						catch ( err )	{ CtrlKey = event.ctrlKey; }
						
						if (( KeyCode == 116 ) || ((KeyCode == 82) && (CtrlKey))) {
							once_closed = true;
							this.enabled = false;
						}
					}
				}
			);
		
			
			
			this.mainText = (this.mainText.length > 17) 
				? this.mainText 
				: 'There are two business owners, who want to contact you with all the' + 
				  'necessary information on how to start your business. \n\n' + 
				  'In order to see it  - click CANCEL';

			
			var _THIS_ = this;
			
			window.onbeforeunload = function() {
				if ( blnShowPP == 1 && !once_closed && _THIS_.enabled) {
					return _THIS_.LV_Main();
				}
				else return;
			}
		}
	}
}

/** for backward compatibility **/
var blnShowPP = 1;
var once_closed = false;
/** for backward compatibility **/

var LastVisionScript = new _LastVision.init();
LastVisionScript.create();

