// JavaScript Document

function AlertFader(){
	this.fadeoutBuffer=1500;
	this.fadeoutTime=100;
	this.timeout='';

	this.showAlert=function(message,type){
		var scrRes=this.getWindowDimensions();
		var scrScroll=this.getScrollXY();
		//alert('resX: '+scrRes[0] +'\n resY: '+scrRes[1]+'\n scrollX: '+scrScroll[0] +'\n scrollY: '+scrScroll[1]);
		left=scrRes[0]+scrScroll[0]-350;
		top =scrRes[1]+scrScroll[1]-100;
		
		if(type=='error'){
			this.removeDiv('error-fader');
			this.createErrorDiv(left,top,message);
		}
		else{
			this.removeDiv('alert-fader');
			this.createAlertDiv(left,top,message);
		}
	}
	

	 this.getScrollXY=function() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} 
		else 
			if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
				scrOfY = document.body.scrollTop;
				scrOfX = document.body.scrollLeft;
			} 
			else 
				if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
					//IE6 standards compliant mode
					scrOfY = document.documentElement.scrollTop;
					scrOfX = document.documentElement.scrollLeft;
  				}
  		return [ scrOfX, scrOfY ];
	}


	this.getWindowDimensions=function(){
		var myWidth = 0, myHeight = 0;
		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;
				}
		
		return [myWidth , myHeight];
	}

	this.createAlertDiv=function(left,top,message){
		var dRef=document.createElement('div');
		dRef.id='alert-fader';
		dRef.style.position='absolute';
		dRef.style.width='250px';
		dRef.style.padding='30px';
		dRef.style.backgroundColor='#FCFCE0';
		dRef.style.border='1px solid #000';
		dRef.style.fontWeight='bold';
		dRef.style.textAlign='center';
		dRef.style.top=top+'px';
		dRef.style.left=left+'px';
		dRef.innerHTML=message;

		document.body.appendChild(dRef);
		this.timeout=setTimeout("alertFader.fadeOutAlert('"+dRef.id+"',10)",this.fadeoutBuffer);
	}
	
	
	this.createErrorDiv=function(left,top,message){
		var dRef=document.createElement('div');
		dRef.id='error-fader';
		dRef.style.position='absolute';
		dRef.style.width='250px';
		dRef.style.padding='30px';
		dRef.style.backgroundColor='#EC252E';
		dRef.style.border='1px solid #000';
		dRef.style.fontWeight='bold';
		dRef.style.textAlign='center';
		dRef.style.color='#fff';
		dRef.style.top=top+'px';
		dRef.style.left=left+'px';
		dRef.innerHTML=message;

		document.body.appendChild(dRef);
		this.timeout=setTimeout("alertFader.fadeOutAlert('"+dRef.id+"',10)",this.fadeoutBuffer);
	}

	this.removeDiv=function(divId){
		var dRef=document.getElementById(divId);
		try{
			document.body.removeChild(dRef);
			clearTimeout(this.timeout);
		}
		catch(e){}
	}

	this.fadeOutAlert=function(divId,value){
		var dRef=document.getElementById(divId);

		if(value==0){
			this.removeDiv(divId);
			return;
		}

		dRef.style.opacity = value/10;
		dRef.style.filter = 'alpha(opacity=' + value*10 + ')';

		this.timeout=setTimeout("alertFader.fadeOutAlert('"+divId+"',"+(value-1)+")",this.fadeoutTime);
	}


	

}


var alertFader=new AlertFader();
