var myWidth = 0, myHeight = 0;

function alertDiv(strAlert,WidthAlert) {
  if (WidthAlert==null)
  	WidthAlert=250;

  if( typeof( window.innerWidth ) == 'number' ) {
	  
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	//alert(myWidth+" "+myHeight);
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  
  

  /*if(navigator.userAgent.indexOf("Firefox")!=-1){
	  
	posx = (myWidth/2) + 199;
	
	}

  if (navigator.appVersion.indexOf("MSIE")!=-1){
	posx = (myWidth/2) + 208;
	}*/
	posx = (myWidth/2) - (WidthAlert/2);
	var posy = (myHeight/2)-100;
	
	
	
	var idvelina = "alert-div-velina";	
	var velinadiv = document.createElement('div');
	velinadiv.setAttribute('id', idvelina);
	velinadiv.style.opacity = 0;
	velinadiv.style.filter = 'alpha(opacity:0)';
	/*velinadiv.style.height = screen.height+"px";
	velinadiv.style.width = screen.width+"px";*/
	if(browserUtente.indexOf("MSIE 6") > 0)
	{
		velinadiv.style.height=document.body.scrollHeight+"px";
		velinadiv.style.width=document.body.scrollWidth+"px";
	}
	else
	{
		velinadiv.style.height=document.body.offsetHeight+"px";
		velinadiv.style.width=document.body.offsetWidth+"px";
	}
	//velinadiv.style.top = document.documentElement.scrollTop+"px";
	document.body.appendChild(velinadiv);
	
	var id = "AlertDiv";	
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.style.position = "absolute";
	newdiv.style.left = posx+"px";
	if(browserUtente.indexOf("MSIE 6") > 0)
	{
		newdiv.style.top = document.body.scrollTop+posy+"px";
	}
	else
	{
		newdiv.style.top = document.documentElement.scrollTop+posy+"px";
	}
	
	newdiv.style.opacity = 0;
	newdiv.style.filter = 'alpha(opacity:0)';
	newdiv.innerHTML = getTxtAlertDiv(strAlert);
	document.body.appendChild(newdiv);
	
	//alert(document.getElementById('AlertDiv'));
	document.getElementById('alert-div').style.width=WidthAlert+"px";
	
	window.onscroll = function() {
		if(browserUtente.indexOf("MSIE 6") > 0)
		{
			document.getElementById("AlertDiv").style.top = document.body.scrollTop+posy+"px";
		}
		else
		{
			document.getElementById("AlertDiv").style.top = document.documentElement.scrollTop+posy+"px";
		}
	//window.scrollTo(0,0);
	}
	
	var freq=1;
	velinadiv.alfa=0;
	velinadiv.incremento=2;
	velinadiv.limit=10;
	velinadiv.timer_in = setInterval(function()
		{
		setOpacity(velinadiv,newdiv);
		},freq);
	
	if (document.layers) document.captureEvents(Event.KEYPRESS);
	{
		document.onkeypress = onKeyPress;
	}
	
	document.getElementById('alert-div-brnok-btn').focus();
} 

function onKeyPress (e) {
	var keycode;
	if (window.event) {keycode = window.event.keyCode}  // IE
	else if (e) {keycode = e.which};  // Netscape
	if (keycode == 13) {
		alertDivClose();
	}
}


function setOpacity(div1,div2) {

	div1.alfa=div1.alfa+div1.incremento;
	div1.style.opacity = div1.alfa/20;
	div1.style.filter = 'alpha(opacity:' + div1.alfa*5 + ')';
	div2.style.opacity = div1.alfa/10;
	div2.style.filter = 'alpha(opacity:' + div1.alfa*10 + ')';
	if (div1.alfa==div1.limit)
	{
		clearInterval(div1.timer_in);
		if(div1.incremento<0)
		{
			div1.parentNode.removeChild(div1);
			div2.parentNode.removeChild(div2);
			window.onscroll = function() {;}
		}
	}
}


function setActiveTab() {

  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  
  /*if(navigator.userAgent.indexOf("Firefox")!=-1){
	posx = (myWidth/2) + 200;
	}

  if (navigator.appVersion.indexOf("MSIE")!=-1){
	posx = (myWidth/2) + 208;
	}*/
	posx = (myWidth/2) - 100;
	posy = (myHeight/2);
	
	if(document.getElementById) {
	document.getElementById('AlertDiv').style.left = posx+"px";
	document.getElementById('AlertDiv').style.top = posy+"px";
	}
	else if(document.all) {
	document.all.Certip.style.left = posx+"px";
	document.all.Certip.style.top = posy+"px";
	}
	else if(document.layers) {
	document.Certip.left = posx+"px";
	document.Certip.top = posy+"px";
	}

}

/*window.onload = function() {
doActiveTab();
}*/
/*window.onresize = function() {
setActiveTab();
}*/

function getTxtAlertDiv(strAlert){
	strout="<div id=\"alert-div\">"
	strout=strout+"<div id=\"alert-div-close\">"
	strout=strout+"<div id=\"alert-div-close-sx\"><!-- --></div>"
	strout=strout+"<div id=\"alert-div-close-dx\"><!-- --></div>"
	strout=strout+"<div id=\"alert-div-close-cent\"><a href=\"javascript:alertDivClose();\"><img src=\"/alertDiv/img/trasparente-close.gif\" alt=\"Close\" width=\"14\" height=\"14\" /></a></div>"
	strout=strout+"</div>"
	strout=strout+"<div id=\"alert-div-content\">"
	strout=strout+"<div id=\"alert-div-txt\">"
	strout=strout+"<img src=\"/alertDiv/img/popup-alert.gif\" />"
	strout=strout+strAlert;
	strout=strout+"<div id=\"alert-div-btnok\">"
	strout=strout+"<a id=\"alert-div-brnok-btn\" href=\"javascript:alertDivClose();\"><img src=\"/alertDiv/img/trasparente.gif\" alt=\"\" /></a>"
	strout=strout+"</div>"
	strout=strout+"</div>"
	strout=strout+"</div>"
	strout=strout+"<div style=\"clear:both\"><!-- --></div>"
	strout=strout+"<div id=\"alert-div-footer\">"
	strout=strout+"<div id=\"alert-div-footer-sx\"><!-- --></div>"
	strout=strout+"<div id=\"alert-div-footer-dx\"><!-- --></div>"
	strout=strout+"<div id=\"alert-div-footer-cent\"><!-- --></div>"
	strout=strout+"</div></div>"
	strout=strout+"</div>"
	return strout;
}

function alertDivClose(){
	var newdiv = document.getElementById("AlertDiv");
	var velinadiv = document.getElementById("alert-div-velina");
	var freq=1;
	velinadiv.alfa=10;
	velinadiv.incremento=-2;
	velinadiv.limit=0;
	document.onkeypress = function() {;};
	velinadiv.timer_in = setInterval(function()
		{
		setOpacity(velinadiv,newdiv);
		},freq);
}



