/* popup counter */

//this will give you javascript.samplesite.com 
var fullDomain = window.location.host; 

//this splits your domain in pieces using the "." 
var domainArray = fullDomain.split('.'); 

//this will gi ve you the subdomain portion ie vader 
var subDomain =domainArray[0]; 

//get and print the domain name only ie samplesite 
var domainName = domainArray[1]; 

//get and print the domain extension ie com
var domainExt = domainArray[2]; 

//var domain = "mobilebusiness.de";
var domain = domainName+"."+domainExt;

var t; document.onmousemove = to; document.onkeypress = to;

function to(){
	clearTimeout(t);
	t = setTimeout(startPopupTimer, 2000);
} 


// Cookie-Funktionen

function setCookie(name, value, expdays) {   // gültig expdays Tage
  var now = new Date();
  var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
  document.cookie = name + "=" + escape(value) + ";" +
                    "expires=" + exp.toGMTString() + ";" +
                    "path=/";
}

function delCookie(name) {   // expires ist abgelaufen
  var now = new Date();
  var exp = new Date(now.getTime() - 1);
  document.cookie = name + "=;" +
                    "expires=" + exp.toGMTString() + ";" + 
                    "path=/";
}

function getCookie(name) {
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    var start = dc.indexOf(cname);
    if (start != -1) {
      start += cname.length;
      var stop = dc.indexOf(";", start);
      if (stop == -1) stop = dc.length;
      return unescape(dc.substring(start,stop));
    }
  }
  return null;
}

function setStyleCookie() {
  setCookie(Keks, Stil, Tage);
}

function getStyleCookie() {
  return getCookie(Keks);
}

function delStyleCookie() {
  delCookie(Keks);
}

function startPopupTimer() {
	cookieValue = getCookie(domain+"newsletterwindow");
	if (document.getElementById('mailpopup-bg')) {
		if((cookieValue == "0") || !(document.getElementById('mailpopup-bg').style.display == "none")) {
			return;
		} else {
			startPopupCounter(0, 1250, 500);
		}
	}
}

function createFadeArray(fromValue, toValue, time, steps, ease) {
	var fadeArray = new Array();
	var timesteps = time/steps;
	var directfadesteps = (toValue-fromValue)/steps;
		
	for(i=0; i<steps; i++) {
		fadeArray[i] = new Object();
		fadeArray[i]["value"] = fromValue + directfadesteps * (i+1);
		fadeArray[i]["time"] = timesteps * (i+1);
	}
	return fadeArray;
}

function fadeElement(elementId, cssAttribute, fromValue, toValue, time, steps, ease) {
	var fadeElementArray = new Array();
	fadeElementArray = createFadeArray(fromValue, toValue, time, steps, ease);
	
	for(i=0; i<steps; i++) {
		setTimeout("document.getElementById('"+elementId+"').style."+cssAttribute+" = "+fadeElementArray[i]['value']+"", fadeElementArray[i]['time']);
	}
}

function startPopupCounter(timeToWait, timeToShow, timeToShowButtons) {
	setTimeout(popupNewsletterWindowBG, timeToWait);
	setTimeout(popupNewsletterWindow, timeToWait+timeToShow);
	setTimeout(popupNewsletterWindowClosebutton, timeToWait+timeToShow+timeToShowButtons);
}

function popupNewsletterWindowBG() {
	document.getElementById('mailpopup-bg').style.display = "block";
	document.getElementById('mailpopup-bg').style.opacity = "0.0";
	
	fadeElement("mailpopup-bg", "opacity", 0.000, 0.700, 900, 18, 0);
}

function popupNewsletterWindow() {
	document.getElementById('mailpopup').style.display = "block";
	document.getElementById('mailpopup').style.opacity = "0.0";
	
	fadeElement("mailpopup", "opacity", 0.000, 1.000, 500, 10, 0);
}

function popupNewsletterWindowClosebutton() {
	document.getElementById('mailpopup-closetext').style.visibility = "visible";
}

function closeNewsletterWindow() {
	fadeElement("mailpopup", "opacity", 1.000, 0.000, 250, 2, 0);
	fadeElement("mailpopup-bg", "opacity", 0.700, 0.000, 700, 14, 0);

	setTimeout("document.getElementById('mailpopup-bg').style.display = 'none'", 750);
	setTimeout("document.getElementById('mailpopup').style.display = 'none'", 250);
	setCookie(domain+"newsletterwindow", 0, 1);
}

function closeNewsletterWindowAndNeverShowAgain() {
	fadeElement("mailpopup", "opacity", 1.000, 0.000, 250, 2, 0);
	fadeElement("mailpopup-bg", "opacity", 0.700, 0.000, 700, 14, 0);

	setTimeout("document.getElementById('mailpopup-bg').style.display = 'none'", 750);
	setTimeout("document.getElementById('mailpopup').style.display = 'none'", 250);
	setCookie(domain+"newsletterwindow", 0, 3650);
}

