var _onClose = new Object();

_onClose.init = function() {
	this.blockerDiv = null;
	this.closeDiv = null;
	this.closeDivTop = null;
	this.closeDivBot = null;
	this.modalDiv = null;
	this.titleDiv = null;
	this.sendButton = null;
	this.errorTextEmpty = null;
	this.errorText = null;
	this.errorAnimate = false;
	
	this.randId = 0;
	this.bodyHeightEl = null;
	this.created = false;
	this.closeHeight = 60;
	this.modalWidth = 840;
	this.modalHeight = 540;
	this.modalTop = 50;
	this.userScrollTop = 0;
	this.userScrollLeft = 0;
	this.currentY = undefined;
	this.onse_shown = false;
	this.pixelCode = '<img src="http://www.gmbtrack.com/tracki.asp?a=408&o=262&c=10&l=3" width="1" height="1" border="0">';
	
	this.blockerStyles = {
		position: 'absolute',
		top: '0px',
		left: '0px',
		width: '100%',
		height: '100%',
		border: 'none',
		padding: '0px',
		margin: '0px',
		background: 'black',
		opacity: '0.6',
		filter: 'alpha(opacity=60)',
		display: 'none'
	}
	
	this.closeStyles = {
		position: 'absolute',
		top: '0px',
		left: '0px',
		width: '100%',
		height: this.closeHeight + 'px',
		zIndex: '100',
		background: 'none',
		borderBottom: '1px solid red',
		
		
		background: 'white',
		opacity: '0.0',
		filter: 'alpha(opacity=1)',
		color: '#aaaaff',
		textAlign: 'left',
		fontSize: '20px',
		fontFamily: 'georgia',
		lineHeight: ( this.closeHeight - 3 ) + 'px'
	}
	
	this.modalStyles = {
		position: 'absolute',
		width: this.modalWidth + 'px',
		height: this.modalHeight + 'px',
		top: this.modalTop + 'px',
		left: '0px',
		border: '0px solid black',
		zIndex: '3000',
		display: 'none'
	}
	
}


_onClose.init.prototype = {
	applyCss : function( element, cssArray ) {
		var s = '';
		for ( var i in cssArray ) {
			try{
				element.style[i] = cssArray[i];
			} catch (err) {}
		}
	},
	
	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;
		}
	},
	
	/*isCorrectEmail : function( email ) {
		var mailRE = new RegExp( );
		mailRE.compile( '^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi' );
		return mailRE.test( email );
	},*/
	
	AddEvent : function ( element, event, codeToAdd ) {
		var EventCode;
		var NewEvent;
		
		try {
			EventCode = eval ( 'element.'+event+'.toString();' );
			EventCode = EventCode.substring( EventCode.indexOf( "{" ) + 1, EventCode.lastIndexOf("}") );
			
			NewEvent = new Function( codeToAdd + " " + EventCode );
			eval( 'element.'+event+' = NewEvent;' );
		} catch ( err ) {
			eval( 'element.'+event+' = function(){' + codeToAdd + '}' );
		}
	},
	
	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 ;
	},
	
	setCookie : function( name, value ) {
		document.cookie = name + "=" + value + "; path=/; expires=Mon, 01-Jan-2100 00:00:00 GMT";
	},
	
	ChangePrt : function(){
		try{
			if ( prt_change_off === true )
				return;
		} catch(err){}
		
		if (GetCookie('prtold')=='')this.setCookie('prtold', GetCookie('prt'));
		if (GetCookie('subold')=='')this.setCookie('subold', GetCookie('sub'));
		this.setCookie('prt', 'p1_'+GetCookie('subold')+'_'+GetCookie('prtold'));
		//this.setCookie('prt', 'p1');
		this.setCookie('sub', '6');
	},

	
	createDiv : function( styles ) {
		var element = document.createElement( 'div' );
		this.applyCss( element, styles );
		document.body.appendChild( element );
		return element;
	},
	
	createHtml : function() {
	
		this.blockerDiv = this.createDiv( this.blockerStyles );
		this.closeDiv = this.createDiv( this.closeStyles );
		this.modalDiv = this.createDiv( this.modalStyles );

		this.blockerDiv.id = 'blocker_' + this.randId;
		this.modalDiv.id = 'modal_' + this.randId;
		
		this.modalDiv.innerHTML += '<div onclick="this.parentNode.close('+this.randId+');">&nbsp;</div>';
		var modalChilds = this.modalDiv.childNodes;
		var count = modalChilds.length;
		for ( var i = 0; i < count; i++ ) {
			if ( modalChilds[i].nodeName.toLowerCase() == 'div' ) {
				this.titleDiv = modalChilds[i]; 
				this.applyCss ( this.titleDiv, this.titleStyles );
				break;
			}
		}		
		
		this.modalDiv.close = function( randId ) {
			this.style.display = 'none';
			document.getElementById('blocker_' + randId).style.display = 'none';
			onClose.showScroll();
			onClose.ChangePrt();
		}
		
		_THIS_ = this;
		$.get(
			'onclose_v0/onclose_content.asp',
			{ rand: _THIS_.intRand( 1000, 9999 ) },
			function( response ) {
				_THIS_.modalDiv.innerHTML += response;
				$(_THIS_.modalDiv).find('a').hover(
					function(){try{blnShowPP = 0;}catch(err){}},
					function(){try{blnShowPP = 1;}catch(err){}}
				);
				/*_THIS_.assignSubmitData();*/
				$('.CloseButton').click(function() {
					try{
						_THIS_.modalDiv.style.display = 'none';
						document.getElementById('blocker_' + _THIS_.randId).style.display = 'none';
						onClose.showScroll();
						_THIS_.ChangePrt();
						return false;
					}catch(err){alert(err)}
				})
				
				var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
				var next_day_date = new Date(Date.parse(new Date().toString())/* + (1000*60*60*24)*/);
				var string_date = months[next_day_date.getMonth()] + '&nbsp;' + next_day_date.getDate() + ',&nbsp;' + next_day_date.getFullYear();
				$('.next_day_date').html(string_date);
			}
		);
	},
	
	
	hideScroll : function() {
		if ( !window.XMLHttpRequest || window.opera ) { // ie, opera
			this.userScrollTop = this.realBody.scrollTop;
			this.userScrollLeft = this.realBody.scrollLeft;
			
			window.scrollTo( 0, 0 );
		} else { // ff
			this.realBody.style.overflow = 'hidden';
		}
	},

	
	showOnClose : function() {
		$(this.blockerDiv).animate( {opacity: 'show'}, 100 );
		$(this.modalDiv)
			.animate( {opacity: 'show'}, 100 )
			.find( 'div:eq(1)' ).append( this.pixelCode );
		this.hideScroll();
	},
	
	
	showScroll : function () {
	
		if ( !window.XMLHttpRequest || window.opera ) { // ie, opera
			window.scrollTo( this.userScrollLeft, this.userScrollTop );
			this.userScrollTop = this.userScrollLeft = 0;
		} else { // ff
			this.realBody.style.overflow = 'auto';
		}
	},

	assignEvents : function() {
		this.closeDiv.onmousemove = function() {
			var event = ( arguments[0] ) ? arguments[0] : window.event;
			var y = event.clientY;
			
			if ( _THIS_.currentY == undefined )
				_THIS_.currentY = y;
			else
				if ( y < _THIS_.currentY-1 )
					if ( !_THIS_.onse_shown ) {
						_THIS_.showOnClose();
						_THIS_.onse_shown = true;
					}
				else
					_THIS_.currentY = y;
		}
		
		this.closeDiv.onmouseout = function() {
			_THIS_.currentY = undefined;
		}
		
		this.created = true;
	},
	
	reposition : function() {
		if ( !this.created ) return false;

		var docwidth = (document.all && !window.opera) ? this.realBody.clientWidth : window.innerWidth;
		var docheight = (document.all && !window.opera) ? this.realBody.clientHeight : window.innerHeight;
		
		var docheightcomplete = this.realBody.offsetHeight;
		if ( docheightcomplete < this.realBody.scrollHeight )
			docheightcomplete = this.realBody.scrollHeight;
		if ( this.bodyHeightEl && ( docheightcomplete < this.bodyHeightEl.offsetHeight ) )
			docheightcomplete = this.bodyHeightEl.offsetHeight;
			

		this.closeDiv.style.top = this.realBody.scrollTop + 'px';
		this.blockerDiv.style.height = ( docheightcomplete - 2 ) + 'px';
		this.blockerDiv.style.width = ( document.body.clientWidth ) + 'px';
		
		
		this.modalDiv.style.top = 
			( ( this.modalTop + this.modalHeight ) > docheight )
				? this.closeHeight + ( ( docheight - this.modalHeight - this.closeHeight ) > 0 ? docheight - this.modalHeight - this.closeHeight : 0  ) + 'px' 
				: this.modalTop+'px';
				
		this.modalDiv.style.left = Math.round( ( docwidth - this.modalWidth ) / 2 ) + 'px';
	},
	
	start : function() {
		this.randId = this.intRand( 1000, 9999 );
		
		this.realBody = ( document.compatMode == "CSS1Compat") ? document.documentElement : document.body;

		this.createHtml();
		this.assignEvents();
		this.reposition();
	}
}


onClose = new _onClose.init();

var cookie_show = onClose.ReadCookie('show');
var cookie_onmouse = onClose.ReadCookie('onmouse');

if ( (onClose.ReadCookie('show') == false) && (onClose.ReadCookie('onmouse') == false) ) {
	onClose.AddEvent( 
		window, 'onload', 
		"onClose.bodyHeightEl = document.getElementById('MainTable'); onClose.start();" 
	);
}

//------------------

function TrimStr(s) {
  s = s.replace( /^\s+/g, '');
  return s.replace( /\s+$/g, '');
}

function GetCookie(aName){
  var Result='';
  var arrCookies = new Array();
  var arrCookie = new Array();
  arrCookies = document.cookie.split(';');
  for(key in arrCookies){
    arrCookie = arrCookies[key].split('=');
    if(TrimStr(arrCookie[0])==aName) Result = arrCookie[1];
  };
  return Result;
};
