var WidthAlert=250;
window.onresize = function() {
    if (document.getElementById("alert-div-velina") != null) {
        document.getElementById("alert-div-velina").style.height = 0 + 'px';
        document.getElementById("alert-div-velina").style.width = 0 + 'px';
        var size = dimensioniPagina();
        document.getElementById("alert-div-velina").style.height = size[1] + 'px';
        document.getElementById("alert-div-velina").style.width = size[0] + 'px';
        posx = (size[2] / 2) - (WidthAlert / 2);
        posy = (size[3] / 2) - 100;
        document.getElementById("AlertDiv").style.left = posx + "px";
        
        if (browserUtente.indexOf("MSIE 6") > 0) {
            document.getElementById("AlertDiv").style.top = document.body.scrollTop + posy + "px";
        }
        else if (browserUtente.indexOf("CHROME") > 0 || browserUtente.indexOf("SAFARI") > 0)
            ;
        else {
            document.getElementById("AlertDiv").style.top = document.documentElement.scrollTop + posy + "px";
        }

    }
}

function dimensioniPagina() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		//alert("innerWidth "+window.innerWidth);
	    //alert("scrollMaxX "+window.scrollMaxX);
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	//} else if (document.body.scrollHeight > document.body.offsetHeight){ 
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;	
	}
	//alert("yScroll "+yScroll);
	//alert("xScroll "+xScroll);
	var windowWidth, windowHeight;
	//alert("pageXOffset "+window.pageXOffset);
	//alert("scrollLeft "+document.body.scrollLeft);
	//alert("scrollWidth "+document.body.scrollWidth);
	//alert("innerWidth "+window.innerWidth);
	//alert("scrollMaxX "+window.scrollMaxX);
	//alert("client width"+ document.documentElement.clientWidth);
	//alert("client heigth"+ document.documentElement.clientHeight);
	//alert("self.innerwidth"+ self.innerWidth);
	if (self.innerHeight) {	
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
		yScroll=yScroll;
		
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}


	if(xScroll > windowWidth && xScroll-windowWidth!=16){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	
	//alert("pagew "+pageWidth);
	//alert("pageh "+pageHeight);
	//alert("windoww "+windowWidth);
	//alert("windowh "+windowHeight);
	return arrayPageSize;
}

function alertDiv(strAlert,WidthAlert) {
  if (WidthAlert==null)
  	WidthAlert=250;
    var size = dimensioniPagina();
    myWidth = size[0];
	myHeight = size[1];
	posx = (size[2]/2) - (WidthAlert/2);
	posy = (size[3]/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";*/
		velinadiv.style.height=myHeight+"px";
		velinadiv.style.width=myWidth+"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";
	browserUtente = navigator.userAgent.toUpperCase();
	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 if(browserUtente.indexOf("CHROME") > 0 || browserUtente.indexOf("SAFARI") > 0)
        ;
		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 confirmDiv(strAlert, confirmDivTrue,confirmDivFalse) {
    if (WidthAlert == null)
        WidthAlert = 250;
    var size = dimensioniPagina();
    myWidth = size[0];
    myHeight = size[1];
    posx = (size[2] / 2) - (WidthAlert / 2);
    posy = (size[3] / 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";*/
    velinadiv.style.height = myHeight + "px";
    velinadiv.style.width = myWidth + "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";
    browserUtente = navigator.userAgent.toUpperCase();
    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, confirmDivTrue, confirmDivFalse);
    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 if (browserUtente.indexOf("CHROME") > 0 || browserUtente.indexOf("SAFARI") > 0)
            ;
        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;
    }

    if (confirmDivTrue == "" || confirmDivTrue==null)
        document.getElementById('alert-div-brnok-btn').focus();
    else
        document.getElementById('alert-div-brnsi-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 getTxtAlertDiv(strAlert, confirmDivTrue, confirmDivFalse) {
    
	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=\"/JsComponents/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=\"/JsComponents/alertDiv/img/popup-alert.gif\" />"
	strout=strout+strAlert;
	strout=strout+"<div id=\"alert-div-btnok\">"

	if (confirmDivTrue == "" || confirmDivTrue == null)
	    strout = strout + "<a id=\"alert-div-brnok-btn\" href=\"javascript:alertDivClose();\"><img src=\"/JsComponents/alertDiv/img/trasparente.gif\" alt=\"\" /></a>"
	else {
	    if (confirmDivFalse == "")
	        confirmDivFalse = "alertDivClose()";
	    
	    strout = strout + "<div id=\"con-btn\">"
	    strout = strout + "<a id=\"alert-div-brnsi-btn\" href=\"javascript:" + confirmDivTrue + ";\"><img src=\"/JsComponents/alertDiv/img/trasparente.gif\" alt=\"\" /></a>"
	    strout = strout + "<a id=\"alert-div-brnno-btn\" href=\"javascript:" + confirmDivFalse + ";\"><img src=\"/JsComponents/alertDiv/img/trasparente.gif\" alt=\"\" /></a>"
	    strout = strout + "</div>"
	}
	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);
}



