

var tsEndUserPath = "http://event.timeslot.info/";
var CustomerValue = "";
var tsheight = 440;
var tswidth = 521;
var tswinwidth = 0;
var tswinheight = 0;
var tsleft = 200;
var tstop = 200;
var ieVersion;
var tsPosType;
var tsLeft;
var tsTop;
var tsBlurTop;
var tsBlurLeft;
var popdiv;
var blurdiv;
var blurframe;

window.onscroll = function() { 
    SetPosition();

    if(popdiv) {
        popdiv.style.top = tsTop;
        popdiv.style.left = tsLeft;
    }

    if(blurdiv) {
        blurdiv.style.top = tsBlurTop;
        blurdiv.style.left = tsBlurLeft;
    }
    
    if(blurframe) {
        blurframe.style.top = tsBlurTop;
        blurframe.style.left = tsBlurLeft;
    }
}

function SetPosition() {
	var isStandarts = (document.compatMode == 'CSS1Compat');
	tsPosType = "fixed";
	tsLeft = "50%";
	tsTop = "50%";
	tsBlurLeft = "0px";
	tsBlurTop = "0px";

	if(isIE()) {
		if(ieVersion < 7 || !isStandarts) {
			tsPosType = "absolute";
			var LeftScroll = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;  
			var TopScroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
			tsBlurLeft = LeftScroll + "px";
  			tsBlurTop = TopScroll + "px";
  			tsTop =  TopScroll + GetDocHeight() / 2 + "px";
			tsLeft = LeftScroll + GetDocWidth() / 2 + "px";

		}
	}
	//alert(isStandarts + " " + tsPosType + " " + tsLeft + " " + tsTop);
}

function isIE(){
    var pattern = /MSIE (\d)/;
    var b_version = navigator.appVersion;
    var regres = pattern.exec(b_version);
    ieVersion = (regres) ? regres[1] : 10; 
    return (regres && regres[1] < 8);  
}


function GetDocHeight(){
	return (window.innerHeight !== undefined) ? window.innerHeight: document.body.offsetHeight;
}

function GetDocWidth(){
	return (window.innerWidth !== undefined) ? window.innerWidth : document.body.offsetWidth;
}

function TSShowEvent(eventid) {
    TSShowEvent_internal(eventid, false);
}

function TSShowEventGroup(eventid) {
    TSShowEvent_internal(eventid, true);
}


function TSShowEvent_internal(eventid, isEventType) {
    SetPosition();
    popdiv = document.createElement("div");
    popdiv.id = "tsPopDiv";
    popdiv.style.paddingTop = "0.2em";
    popdiv.style.paddingButtom = "0.2em";
    popdiv.style.width = tswidth + "px";
    popdiv.style.height = tsheight + "px";
    popdiv.style.backgroundColor = "white";
    popdiv.style.position = tsPosType;
    popdiv.style.top = tsTop;
    popdiv.style.left = tsLeft;
    popdiv.style.marginLeft = "-" + tswidth / 2 + "px";
    popdiv.style.marginTop = "-" + tsheight / 2 + "px";
    popdiv.style.zIndex = "9999";
    popdiv.style.textAlign = "right";
    popdiv.style.overflow = "hidden";
    
    
    var close = document.createElement("a");
    var closeImg = document.createElement("img");
    closeImg.src = tsEndUserPath + "images/luklang.gif";
    closeImg.style.borderStyle = "none";
    closeImg.style.borderWidth = "0px";
    closeImg.style.marginButtom = "0px";
    close.href = "javascript:RemoveModal();";
    //close.appendChild(document.createTextNode("Luk"));
    close.appendChild(closeImg);
    close.style.paddingRight = "10px";
    close.style.fontWeight = "bold";
    
    var closeDiv = document.createElement("div");
    //closeDiv.style.height = "1em";
    closeDiv.appendChild(close);
    popdiv.appendChild(closeDiv);
    var framewrapper = document.createElement("div");
    //framewrapper.style.float = "left";
    framewrapper.style.margin = "0px";
    framewrapper.style.height = "100%";
    framewrapper.style.overflow = "hidden";
    
    var frame = document.createElement("iframe");
    frame.style.width = "100%";
    frame.style.height = "100%";
    frame.style.margin = "auto";
    frame.style.borderStyle = "none";
    //  frame.src = tsEndUserPath + "loading.htm";
    //  alert(frame.src);
    var frameSrc = "eventid=";
    if(isEventType)  {
        frameSrc = "eventtypeid=";
    }
    var newframe = tsEndUserPath + "Default.aspx?" + frameSrc + eventid;
    var customerParameter = "&" + "CustomerID=";
    if (CustomerValue != "") {
        newframe = tsEndUserPath + "Default.aspx?" + frameSrc + eventid + customerParameter + CustomerValue;
    }
    frame.src = newframe;
    frame.style.overflow = "hidden";

    popdiv.appendChild(framewrapper);
    framewrapper.appendChild(frame);
    
    document.body.appendChild(popdiv);
    ShowBlur();
}

function RemoveModal(){
    RemoveById("tsPopDiv");
    RemoveById("tsBlurDiv");
}

function ShowBlur() {
    blurdiv = document.createElement("div");
    blurdiv.id = "tsBlurDiv";
    blurdiv.style.display = "block";
    blurdiv.style.position = tsPosType;
    blurdiv.style.left = tsBlurLeft;
    blurdiv.style.top = tsBlurTop;
    blurdiv.style.zIndex = "9000";
    blurdiv.style.backgroundColor = "black";
    blurdiv.style.width = "100%";
    blurdiv.style.height = "100%";
    blurdiv.style.opacity = "0.5"; 
    blurdiv.style.filter = "alpha(opacity=50)";
	
    if(isIE()) {
            blurdiv.style.width = GetDocWidth() + "px";
            blurdiv.style.height = GetDocHeight() + "px"; 
 
       if(ieVersion < 7) { //If ie 6 or lower
            blurdiv.style.position = tsPosType;
            blurframe = document.createElement("iframe");
            blurframe.style.display = "none";
            blurframe.style.top = tsBlurTop;
            blurframe.style.left = tsBlurLeft;
            blurframe.style.zIndez = "-1";
            blurframe.style.filter = "mask()";
            blurframe.style.width = "3000px";
            blurframe.style.height = "3000px";
            blurdiv.appendChild(blurframe);
       }
	}
	document.body.appendChild(blurdiv);
}

function RemoveById(id){
    var element = document.getElementById(id);
    if (element){
        document.body.removeChild(element);
    }
}
