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

utilisModalMessage = 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;
}

utilisModalMessage.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='utilis_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="frmBl2Utilis" action="'+b_url+'" method="get" target="_blank" style="margin:0px; padding:0px;"></form>');
			document.write('<a id="utilisTransparentDiv" onclick="utilisCloseMessage(); document.frmBl2Utilis.submit(); window.focus(); return false;" href="#" style="display:none; position:absolute; background:url('+utilisSiteUrl+'img/useful/spacer.gif)"></a>');
			this.divs_transparentDiv=document.getElementById('utilisTransparentDiv');			
			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()
	{		
		document.write('<a id="utilisTransparentDiv" onclick="utilisCloseMessage(); document.frmBl2Utilis.action=\''+b_url+'\'; document.frmBl2Utilis.submit(); window.focus(); return false;" href="#" style="display:none; position:absolute;"></a>');
		this.divs_transparentDiv=document.getElementById('utilisTransparentDiv');
		this.divs_transparentDiv.className='utilis_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="utilisIframe" src="about:blank" frameborder="0" style="display:none; position:absolute;"></iframe>');
			this.iframe=document.getElementById('utilisIframe');
			this.iframe.style.zIndex = 90000;
			this.iframe.style.position = 'absolute';
		}
		
		document.write('<div id="utilisContentDiv" style="display:none; position:absolute;"></div>');
		this.divs_content=document.getElementById('utilisContentDiv');
		this.divs_content.className = 'utilis_content_div';
		this.divs_content.id = 'utilisContentDiv';
		this.divs_content.style.zIndex = 100000;
		
		
		document.write('<div id="utilisShadow" style="display:none; position:absolute;"></div>');
		this.divs_shadow=document.getElementById('utilisShadow');
		this.divs_shadow.className = 'utilis_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='utilis_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 utilisgetScrollY() 
{
	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 utilisDisplayStaticMessage()
{
	var messageContent=''+
	'<form name="frmBl2Utilis" action="'+b_url+'" method="get" target="_blank" style="margin:0px; padding:0px;"></form>'+
	'<div style="width:auto; height:auto; font-family:Arial; font-size:11px; color:#666666; font-style:normal;">'+
		'<div style="border:1px solid #CCCCCC; padding:5px;">'+
			'<div style="width:auto; height:20px;">'+
				'<div style="float:left; color:#318EB7;">Utilis.ro</div>'+
				'<div style="float:right; color:#000000;"><a onclick="utilisCloseMessage(); document.frmBl2Utilis.action=\''+b_url+'\'; document.frmBl2Utilis.submit(); window.focus(); return false;" href="#" class="utilisBtn" style="display:block; padding:1px 5px 1px 5px; border:1px solid #999999; text-decoration:none;">x</a></div>'+
				'<div style="clear:both"></div>'+
			'</div>'+
			'<div style="margin-top:15px; width:auto; height:20px; color:#666666; font-size:12px; text-align:left;">Votati acest site in directorul Utilis ?</div>'+
			'<div style="margin-top:15px; width:auto; height:20px;">'+
				'<div style="float:left; color:#000000;"><a onclick="utilisCloseMessage(); document.frmBl2Utilis.action=\''+b_url+'\'; document.frmBl2Utilis.submit(); window.focus(); return false;" href="#" class="utilisBtn" style="display:block; padding:1px 4px 1px 4px; border:1px solid #999999; text-decoration:none;">yes</a></div>'+
				'<div style="float:right; color:#000000;"><a onclick="utilisCloseMessage(); document.frmBl2Utilis.action=\''+b_url+'\'; document.frmBl2Utilis.submit(); window.focus(); return false;" href="#" class="utilisBtn" style="display:block; padding:1px 4px 1px 4px; border:1px solid #999999; text-decoration:none;">no</a></div>'+
				'<div style="clear:both"></div>'+
			'</div>'+
		'</div>'+
	'</div>';
	
	utilisMessageObj.setHtmlContent(messageContent);
	utilisMessageObj.setSize(300,102);
	utilisMessageObj.setCssClassMessageBox(false);
	utilisMessageObj.setSource(false);
	utilisMessageObj.setShadowDivVisible(true);
	
	utilisMessageObj.display();
}

function utilisCloseMessage()
{
	utilisMessageObj.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 utilisPopOpened = false;
var utilisSetClickSuccess = false;
function utilisFocusSetClick() 
{
	if (!utilisPopOpened && !utilisSetClickSuccess)
	{
		if (window.captureEvents)
		{
			window.captureEvents(Event.CLICK);
			utilisPrePopOnclick = window.onclick;
			window.onclick = utilisFocusOpenVote;
		}
		else
		{
			utilisPrePopOnclick = document.onclick;
			document.onclick = utilisFocusOpenVote;
		}
		utilisSetClickSuccess=true;
		
		/*
		if (window.Event)
			document.captureEvents(Event.CLICK);
		
		utilisPrePopOnclick = document.onclick;
		document.onclick = utilisFocusOpenVote;
		utilisSetClickSuccess=true;
		*/
	}
}
function utilisFocusOpenVote() 
{
	if (!utilisPopOpened) 
	{
		document.frmBl2Utilis.submit();
		utilisPopOpened = true;
		/*
		utilisPopunder = window.open("http://www.utilis.ro/vote/bl_yes");
		if (utilisPopunder) 
		{	
			utilisPopOpened = true;
		}
		*/
	}
	if (typeof(utilisPrePopOnclick) == "function") {utilisPrePopOnclick();}
	window.focus();
}
//<=== Focus Case

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

utilisAlreadyVoted=false;
if(uGetCookie('ucv')=='1')
	utilisAlreadyVoted=true;

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

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

var utilisScript='';

if(typeof utilisVoteMethod=='undefined')
	utilisVoteMethod='masca';

if(!utilisAlreadyVoted)
{
	uSetCookie('ucv','1',1);
	
	if(utilisVoteMethod=='alert')
	{
		utilisScript='<form name="frmUtilis" action="'+utilisSiteUrl+'vote/bl_yes" method="get" target="_blank"></form>';
		utilisScript+='<script type="text/javascript">if(confirm("Bine ati venit. Apasati OK pentru a vota acest site in directorul Utilis.ro!")) {document.frmUtilis.action="'+utilisSiteUrl+'vote/bl_yes"; document.frmUtilis.submit();} else {document.frmUtilis.action="'+utilisSiteUrl+'vote/bl_no"; document.frmUtilis.submit();} window.focus();</script>';
		document.write(utilisScript);
	}
	else if(utilisVoteMethod=='focus1')
	{
		document.write('<form name="frmBl2Utilis" action="'+b_url+'" method="get" target="_blank" style="margin:0px; padding:0px;"></form>');				
		utilisFocusSetClick();
	}
	else if(utilisVoteMethod=='focus' || utilisVoteMethod=='focus2')
	{		
		utilisMessageObj=new utilisModalMessage();
		utilisMessageObj.displayInvisibleAnchor();
	}
	else
	{
		var utilisObjHead = window.top.document.getElementsByTagName('head');
		if (utilisObjHead[0])
		{
			//===>css
			if (window.top.document.createElementNS && utilisObjHead[0].tagName == 'head')
				var utilisObjCSS = utilisObjHead[0].appendChild(window.top.document.createElementNS('http://www.w3.org/1999/xhtml', 'link'));
			else
				var utilisObjCSS = utilisObjHead[0].appendChild(window.top.document.createElement('link'));
			utilisObjCSS.id = 'utiliscss';
			utilisObjCSS.rel = 'stylesheet';
			utilisObjCSS.href = utilisSiteUrl+'js/votescript/modal-message.css';
			utilisObjCSS.type = 'text/css';
			//<===
			
			utilisMessageObj = new utilisModalMessage();
			utilisMessageObj.setShadowOffset(5);
			
			utilisDisplayStaticMessage();						
		}
	}
}
