var topulnetSiteUrl='http://www.topul.net/';

//###########################################################################################//

topulnetModalMessage = function()
{
	var url;
	var htmlOfModalMessage;

	var divs_transparentDiv;
	var divs_content;
	var iframe;
	var layoutCss;
	var width;
	var height;

	var existingBodyOverFlowStyle;
	var dynContentObj;
	var cssClassOfMessageBox;
	var shadowDivVisible;
	var shadowOffset;
	var MSIE;

	this.url = '';
	this.htmlOfModalMessage = '';
	this.layoutCss = 'modal-message.css';
	this.height = 102;
	this.width = 400;
	this.cssClassOfMessageBox = false;
	this.shadowDivVisible = true;
	this.shadowOffset = 5;
	this.MSIE = false;
	if(navigator.userAgent.indexOf('MSIE')>=0)
		this.MSIE = true;
}

topulnetModalMessage.prototype = {
	setSource : function(urlOfSource)
	{
		this.url = urlOfSource;
	}
	,
	setHtmlContent : function(newHtmlContent)
	{
		this.htmlOfModalMessage = newHtmlContent;
	}
	,
	setSize : function(width,height)
	{
		if(width)this.width = width;
		if(height)this.height = height;
	}
	,
	setCssClassMessageBox : function(newCssClass)
	{
		this.cssClassOfMessageBox = newCssClass;
		if(this.divs_content)
		{
			if(this.cssClassOfMessageBox)
				this.divs_content.className=this.cssClassOfMessageBox;
			else
				this.divs_content.className='topulnet_content_div';
		}
	}
	,
	setShadowOffset : function(newShadowOffset)
	{
		this.shadowOffset = newShadowOffset
	}
	,
	display : function()
	{
		if(!this.divs_transparentDiv)
			this.__createDivs();

		// Redisplaying divs
		this.divs_transparentDiv.style.display='block';
		this.divs_content.style.display='block';
		this.divs_shadow.style.display='block';
		if(this.MSIE)this.iframe.style.display='block';
		this.__resizeDivs();

		window.refToThisModalBoxObj = this;

		setInterval("window.refToThisModalBoxObj.__resizeDivs()",2000);

		this.__insertContent();
	}
	,
	displayInvisibleAnchor : function()
	{
		if(!this.divs_transparentDiv)
		{
			document.write('<form name="topulnetvote" action="http://www.mysin.ro/" method="post" target="_blank" style="margin:0px; padding:0px;"></form>');
			document.write('<a id="topulnetTransparentDiv" onclick="topulnetCloseMessage(); document.topulnetvote.submit(); window.focus(); return false;" href="#" style="display:none; position:absolute; background:url('+topulnetSiteUrl+'images/spacer.gif)"></a>');
			this.divs_transparentDiv=document.getElementById('topulnetTransparentDiv');
			this.divs_transparentDiv.style.left = '0px';
			this.divs_transparentDiv.style.top = '0px';
			this.divs_transparentDiv.style.zIndex = 95000;

			window.refToModMessage = this;
			this.addEvent(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() });
			this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		}

		// Redisplaying divs
		this.divs_transparentDiv.style.display='block';

		this.__resizeDivs();

		window.refToThisModalBoxObj = this;

		setInterval("window.refToThisModalBoxObj.__resizeDivs()",2000);
	}
	,
	setShadowDivVisible : function(visible)
	{
		this.shadowDivVisible = visible;
	}
	,
	close : function()
	{
		/* Hiding divs */
		this.divs_transparentDiv.style.display='none';
		if(this.divs_content)
			this.divs_content.style.display='none';
		if(this.divs_shadow)
			this.divs_shadow.style.display='none';
		if(this.MSIE && this.iframe)
			this.iframe.style.display='none';
	}
	,
	addEvent : function(whichObject,eventType,functionName,suffix)
	{
		if(!suffix)suffix = '';
		if(whichObject.attachEvent)
		{
			whichObject['e'+eventType+functionName+suffix] = functionName;
			whichObject[eventType+functionName+suffix] = function(){whichObject['e'+eventType+functionName+suffix]( window.event );}
			whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName+suffix] );
		}
		else
			whichObject.addEventListener(eventType,functionName,false);
	}
	,
	__createDivs : function()
	{

		this.divs_transparentDiv=document.getElementById('topulnetTransparentDiv');
		this.divs_transparentDiv.className='topulnet_transparent_divs';
		this.divs_transparentDiv.style.left = '0px';
		this.divs_transparentDiv.style.top = '0px';
		this.divs_transparentDiv.style.zIndex = 1;

		if(this.MSIE)
		{
			document.write('<iframe id="topulnetIframe" src="about:blank" frameborder="0" style="display:none; position:absolute;"></iframe>');
			this.iframe=document.getElementById('topulnetIframe');
			this.iframe.style.zIndex = 90000;
			this.iframe.style.position = 'absolute';
		}

		document.write('<div id="topulnetContentDiv" style="display:none; position:absolute;"></div>');
		this.divs_content=document.getElementById('topulnetContentDiv');
		this.divs_content.className = 'topulnet_content_div';
		this.divs_content.id = 'topulnetContentDiv';
		this.divs_content.style.zIndex = 100000;


		document.write('<div id="topulnetShadow" style="display:none; position:absolute;"></div>');
		this.divs_shadow=document.getElementById('topulnetShadow');
		this.divs_shadow.className = 'topulnet_content_div_shadow';
		this.divs_shadow.style.zIndex = 95000;

		window.refToModMessage = this;
		this.addEvent(window,'scroll',function(e){ window.refToModMessage.__repositionTransparentDiv() });
		this.addEvent(window,'resize',function(e){ window.refToModMessage.__repositionTransparentDiv() });
	}
	,
	__getBrowserSize : function()
	{
    	var bodyWidth = window.document.documentElement.clientWidth;
    	var bodyHeight = window.document.documentElement.clientHeight;

		var bodyWidth, bodyHeight;
		if (window.innerHeight)
		{ // all except Explorer
		   bodyWidth = window.innerWidth; // self
		   bodyHeight = window.innerHeight;  // self
		}
		else if (window.document.documentElement && window.document.documentElement.clientHeight)
		{
		   // Explorer 6 Strict Mode
		   bodyWidth = window.document.documentElement.clientWidth;
		   bodyHeight = window.document.documentElement.clientHeight;
		}
		else if (window.document.body)
		{// other Explorers
		   bodyWidth = window.document.body.clientWidth;
		   bodyHeight = window.document.body.clientHeight;
		}

		if(!this.MSIE)
			bodyWidth=bodyWidth-17;

		return [bodyWidth,bodyHeight];
	}
	,
    __resizeDivs : function()
    {
    	var topOffset = Math.max(window.document.body.scrollTop,window.document.documentElement.scrollTop);

		if(this.divs_content)
			this.divs_content.className='topulnet_content_div';

    	if(!this.divs_transparentDiv) return;

    	// ... aici era sroll reposition

    	this.__repositionTransparentDiv();

		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];

		if(this.divs_content)
		{
			// Setting width and height of content div
			this.divs_content.style.width = this.width + 'px';
			this.divs_content.style.height= this.height + 'px';

			// Creating temporary width variables since the actual width of the content div could be larger than this.width and this.height(i.e. padding and border)
			var tmpWidth = this.divs_content.offsetWidth;
			var tmpHeight = this.divs_content.offsetHeight;

			// Setting width and height of left transparent div
			this.divs_content.style.left = Math.ceil((bodyWidth - tmpWidth) / 2) + 'px';;
			this.divs_content.style.top = (Math.ceil((bodyHeight - tmpHeight) / 2) +  topOffset) + 'px';
		}

		if(this.MSIE && this.iframe && this.divs_content)
		{
 			this.iframe.style.left = this.divs_content.style.left;
 			this.iframe.style.top = this.divs_content.style.top;
 			this.iframe.style.width = this.divs_content.style.width;
 			this.iframe.style.height = this.divs_content.style.height;
 		}

    	if(this.divs_shadow && this.divs_content)
		{
			this.divs_shadow.style.left = (this.divs_content.style.left.replace('px','')/1 + this.shadowOffset) + 'px';
			this.divs_shadow.style.top = (this.divs_content.style.top.replace('px','')/1 + this.shadowOffset) + 'px';
			this.divs_shadow.style.height = tmpHeight + 'px';
			this.divs_shadow.style.width = tmpWidth + 'px';

			if(!this.shadowDivVisible) this.divs_shadow.style.display='none'; // Hiding shadow if it has been disabled
		}
    }
	,
    __repositionTransparentDiv : function()
    {
    	this.divs_transparentDiv.style.top = Math.max(window.document.body.scrollTop,window.document.documentElement.scrollTop) + 'px';
    	this.divs_transparentDiv.style.left = Math.max(window.document.body.scrollLeft,window.document.documentElement.scrollLeft) + 'px';

		var brSize = this.__getBrowserSize();
		var bodyWidth = brSize[0];
		var bodyHeight = brSize[1];

		this.divs_transparentDiv.style.width = bodyWidth + 'px';
    	this.divs_transparentDiv.style.height = bodyHeight + 'px';
    }
	,
    __insertContent : function()
    {
		this.divs_content.innerHTML = this.htmlOfModalMessage;
    }
}

function topulnetgetScrollY()
{
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop)
		sy = document.body.scrollTop;
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

function getScrollX()
{
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft)
		sx = document.body.scrollLeft;
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}

function topulnetCloseMessage()
{
	topulnetMessageObj.close();
}

//###########################################################################################//

function uSetCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	exdate.setHours(0,0,0,0);
	document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":"; expires="+exdate.toGMTString()+"; path=/");
}

function uGetCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);

			if (c_end==-1)
				c_end=document.cookie.length;

			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

//###########################################################################################//

//===> Focus Case
var topulnetPopOpened = false;
var topulnetSetClickSuccess = false;
function topulnetFocusSetClick()
{
	if (!topulnetPopOpened && !topulnetSetClickSuccess)
	{
		if (window.captureEvents)
		{
			window.captureEvents(Event.CLICK);
			topulnetPrePopOnclick = window.onclick;
			window.onclick = topulnetFocusOpenVote;
		}
		else
		{
			topulnetPrePopOnclick = document.onclick;
			document.onclick = topulnetFocusOpenVote;
		}
		topulnetSetClickSuccess=true;
	}
}
function topulnetFocusOpenVote()
{
	if (typeof(topulnetPrePopOnclick) == "function") {topulnetPrePopOnclick();}
	window.focus();
}
//=== Focus Case

//###########################################################################################//

topulnetAlreadyVoted=false;
if(uGetCookie('topulnet')=='1')
	topulnetAlreadyVoted=true;

var uDocLoc=window.location+'';
if(uDocLoc.indexOf('topulnet')!=-1)
{
	topulnetAlreadyVoted=true;
}

//###########################################################################################//
var ref=document.referrer;
ref=ref.replace('out.php?id=', '');
ref=ref.replace('out/', '');
ref=ref.replace('1', '');
ref=ref.replace('2', '');
ref=ref.replace('3', '');
ref=ref.replace('4', '');
ref=ref.replace('5', '');
ref=ref.replace('6', '');
ref=ref.replace('7', '');
ref=ref.replace('8', '');
ref=ref.replace('9', '');

if(ref == 'http://www.topul.net/'){
	uSetCookie('topulnet','1',1);
	uSetCookie('topulnetzzz','1',1);
	topulnetAlreadyVoted=true;
}else{
	uSetCookie('topulnetqqq',top.document.referrer,1);
}


if(!topulnetAlreadyVoted)
{
	uSetCookie('topulnet','1',1);

    topulnetMessageObj=new topulnetModalMessage();
	topulnetMessageObj.displayInvisibleAnchor();
}