var notifShowTime = 10000;
var notifShowTimeError = 10000;

function showOverlay(){
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {notificationClose(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	objOverlay.style.height = arrayPageSize[1] + 'px';
	objOverlay.style.display = 'block';
}

function hideOverlay(){
	var objOverlay = document.getElementById('overlay');
	if(objOverlay!=null){
		objOverlay.style.display = 'none';
	}
}

var myTime = 0;
var myNotificationEnabled = false;

function notificationShowNoTimeNoButtons(text){
	notificationShow(0,text);
}

function notificationShowNoTime(type,text){
	notificationShow(type,text,0);
}

function notificationShow(type,text,milisec){	

    notificationClose();
	showOverlay();
	
	var objOverlay = document.getElementById('overlay');
	var objMessage = document.getElementById("message_status");
	var objMessageContent = document.getElementById("message_status_content");
	var objMessageButtons = document.getElementById("message_status_button");
	
	if(type==0){
		/* only the "weiter" button */
		var button = createContinueButton();
		objMessageButtons.appendChild(button);
	}else if(type==1){
		/* wait text = no button */
	}else if(type==10){
		/* "continue shopping" and "to basket" buttons*/
		var button1 = createContinueShoppingButton();
		objMessageButtons.appendChild(button1);
		var button2 = createBasketButton();
		objMessageButtons.appendChild(button2);
	}else if(type==20){
		/* musiclist buttons for popup */
		var button1 = createContinueShoppingButton();
		objMessageButtons.appendChild(button1);
	}else if(type==21){
		/* musiclist buttons for popup / success */
		var button1 = createContinueShoppingButton();
		objMessageButtons.appendChild(button1);
		var button2 = createMusiclistButton();
		objMessageButtons.appendChild(button2);
	}else if(type==30){
		/* widget buttons for popup */
		var button1 = createContinueShoppingButton();
		objMessageButtons.appendChild(button1);
	}else if(type==31){
		/* widget buttons for popup / success */
		var button1 = createContinueShoppingButton();
		objMessageButtons.appendChild(button1);
		var button2 = createWidgetButton();
		objMessageButtons.appendChild(button2);
	}
		
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	if (objMessage) {
		messageHeight = 70;
		messageWidth = 370;
		objMessage.style.position = 'absolute';
		objMessage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - messageHeight) / 2) + 'px');		
		objMessage.style.left = (((arrayPageSize[0] - 20 - messageWidth) / 2) + 'px');
		objMessage.style.display = 'block';
		objMessageContent.innerHTML = text;
	}
   
    myNotificationEnabled = true;
   
    if(milisec!=0){
		notificationCloseInSeconds(milisec);   
	}
}
function createWidgetButton(){
	var button = document.createElement('a');
	button.setAttribute('href', 'customerWidgetStart.do');
	button.setAttribute('class', 'submitBtnBig');
	var buttonImage = document.createElement('img')
	buttonImage.setAttribute('width','129');
	buttonImage.setAttribute('height','25');
	buttonImage.setAttribute('alt','weiter');
	buttonImage.setAttribute('src','themes/musicbox/img/redesign/btn_big_zum_widget.png');
	button.appendChild(buttonImage);
	return button;	
}
function createMusiclistButton(){
	var button = document.createElement('a');
	button.setAttribute('href', 'dispatch.do?def=cwPlaylist');
	button.setAttribute('class', 'submitBtnBig');
	var buttonImage = document.createElement('img')
	buttonImage.setAttribute('width','129');
	buttonImage.setAttribute('height','25');
	buttonImage.setAttribute('alt','weiter');
	buttonImage.setAttribute('src','themes/musicbox/img/redesign/btn_big_zur_musikliste.png');
	button.appendChild(buttonImage);
	return button;	
}
function createBasketButton(){
	var button = document.createElement('a');
	button.setAttribute('href', 'shoppingBasket.do');
	button.setAttribute('class', 'submitBtnBig');
	var buttonImage = document.createElement('img')
	buttonImage.setAttribute('width','129');
	buttonImage.setAttribute('height','25');
	buttonImage.setAttribute('alt','weiter');
	buttonImage.setAttribute('src','themes/musicbox/img/redesign/btn_big_zum_warenkorb.png');
	button.appendChild(buttonImage);
	return button;	
}
function createContinueShoppingButton(){
	var button = document.createElement('a');
	button.setAttribute('href', 'javascript:void(0);');
	button.setAttribute('onclick', 'javascript:notificationClose();');
	button.setAttribute('class', 'submitBtnBig');
	var buttonImage = document.createElement('img')
	buttonImage.setAttribute('width','129');
	buttonImage.setAttribute('height','25');
	buttonImage.setAttribute('alt','zur&uuml;ck');
	buttonImage.setAttribute('src','themes/musicbox/img/redesign/btn_big_weiter_einkaufen.png');
	button.appendChild(buttonImage);
	return button;	
}
function createContinueButton(){
	var button = document.createElement('a');
	button.setAttribute('href', 'javascript:void(0);');
	button.setAttribute('onclick', 'javascript:notificationClose();');
	button.setAttribute('class', 'submitBtnBig');
	var buttonImage = document.createElement('img')
	buttonImage.setAttribute('width','80');
	buttonImage.setAttribute('height','19');
	buttonImage.setAttribute('alt','weiter');
	buttonImage.setAttribute('src','themes/musicbox/img/redesign/btn_small_80w_weiter.png');
	button.appendChild(buttonImage);
	return button;	
}


function notificationCloseInSeconds(myTime){
	if(myNotificationEnabled){
		if(myTime>0){
			myTime-=1000;
	   		window.setTimeout('notificationCloseInSeconds('+myTime+')', 1000);
		}else{
			notificationClose();
		}
	}
}

function notificationClose(){
	myTime = 0;
	myNotificationEnabled = false;
	
	hideOverlay();

	var objMessage = document.getElementById("message_status");
	var objMessageContent = document.getElementById("message_status_content");
	if(objMessage!=null){
		objMessage.style.display = 'none';
	}
	if(objMessageContent!=null){
		objMessageContent.innerHTML = '';
	}
	var objMessageButtons = document.getElementById("message_status_button");
	if(objMessageButtons!=null){
		objMessageButtons.innerHTML = '';
	}
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
