var jsAreaShowTime = 1000;
var JsAreas = new Object();
var divHangTimer = null;
var activeAreaId = null;


function GetArea(id)
{
	return JsAreas[id] ? JsAreas[id] : (JsAreas[id] = new JsArea(id));
}

// A single popup window
function JsArea(id)
{
	this.AreaId = id;
}

// Function to return the DIV Layer
JsArea.prototype.ContentArea= function()
{
	var divArea = document.getElementById(this.AreaId);
	if (divArea != null)
	{
		return divArea;
	}
	return null;
}


// Function to show the DIV Layer
JsArea.prototype.popareaup = function(x, y)
{
if (activeAreaId != null)	
	jsAreaClose(activeAreaId);
	
	var divLayer = this.ContentArea();
	divLayer.style.position = 'absolute';
	divLayer.style.display = 'block';
	divLayer.style.left = x + "px" ;
	/*divLayer.style.top = y;*/
	divLayer.style.top = "150px"
	 
	divLayer.style.filter='shadow(color=black, direction=135, strength=10)'
	divLayer.onmouseover= JsAreaMouseOver;
	divLayer.onmouseout = jsAreaMouseOut;
	activeAreaId = this.AreaId;
	
	return false;
}

// Function to hide the DIV Layer
JsArea.prototype.hide = function()
{
	var divLayer = this.ContentArea();
	if (divLayer != null)
		divLayer.style.display = 'none';
		
	return false;
}

// Function to be called
// by Web forms to show the Popup Window
function PopupArea(e, areaId)
{
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else 
	if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	var area = GetArea(areaId);
	var winHeight= document.body.clientHeight
	document.getElementById(areaId).style.display = 'block'
	
	 
	posx= (document.body.clientWidth - document.getElementById(areaId).clientWidth)/2
	posy= (winHeight - document.getElementById(areaId).clientHeight)/2
	
	
	 area.popareaup(posx, posy);
}
//Function to clear the fields when the user hides the DIv Layer
function ClearFields()
{
 if (document.getElementById('ctl00_UserLogin_Password')!= null)
    {
        document.getElementById('ctl00_UserLogin_Password').value=""
    }
    
 if (document.getElementById('ctl00_UserLogin_UserName')!= null)
    {
     document.getElementById('ctl00_UserLogin_UserName').value=""
    }   
    
     

 //Clear validation messages
 
  if (document.getElementById('ctl00_UserLogin_reqUserName')!= null)
    { 
     document.getElementById('ctl00_UserLogin_reqUserName').style.visibility='hidden';
    }   
    
    
  if (document.getElementById('ctl00_UserLogin_reqPassword')!= null)
    {
     document.getElementById('ctl00_UserLogin_reqPassword').style.visibility='hidden'
    }   
 
  if (document.getElementById('ctl00_UserLogin_reqselRegion')!= null)
    {
     document.getElementById('ctl00_UserLogin_reqselRegion').style.visibility='hidden'
    }        
 
  //Reset select box
   if (document.getElementById('ctl00_UserLogin_selRegion')!= null)
    {
      document.getElementById('ctl00_UserLogin_selRegion').options[0].selected =1
    } 
    
 //Clear failure message 
 if (document.getElementById('ctl00_UserLogin_FailureText')!= null)
    {
     document.getElementById('ctl00_UserLogin_FailureText').innerText=""
    }   

 
 
 

}

// Function to hide the DIV Layer
function jsAreaClose(areaId)
{   ClearFields();
	GetArea(areaId).hide();
	activeAreaId = divHangTimer = null;	
}



// Function to keep the Div Layer
// showing for a "period" of time
// after that period, if the mouse
// has been outside the DIV Layer, 
// it will be hidden automatically
function KeepArea(areaId)
{
	if (areaId == activeAreaId && divHangTimer != null)
	{
		clearTimeout(divHangTimer);
		divHangTimer = null;
	}
}
 
 
// Function to release the DIV Layer
function RelArea(areaId)
{
	if (areaId == activeAreaId && divHangTimer == null)
		divHangTimer = setTimeout('jsAreaClose(\'' + areaId + '\')', jsAreaShowTime);
}
 

// Function fired when mouse is over the 
// DIV Layer, used to keep the layer showing
function JsAreaMouseOver(e)
{
	if (!e) 
		var e = window.event;
	var targ = e.target ? e.target : e.srcElement;
	KeepArea(activeAreaId);
}

// Function that fires when mouse is out of
// the scope of the DIV Layer
function jsAreaMouseOut(e)
{
	if (!e) 
    var e = window.event;
	var targ = e.relatedTarget ? e.relatedTarget : e.toElement;
	var activeAreaView = document.getElementById(activeAreaId);
 
}

 

function ShowPopup()
{
 document.getElementById('ctl00_spnLoging').focus();
 document.getElementById('ctl00_spnLoging').click();
}

/*
HTMLElement.prototype.click = function() {
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}

*/