﻿var CustomerValue = "13";
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;


function ShowBox(eventid, isEventType) {
    SetPosition();
    popdiv = document.createElement("div");
    popdiv.id = "popupBox";
    //popdiv.style.padding = "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 = "images/stop.png";
    //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 = "1em";
    //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.id = "popupIFrameWrapper";
    
    //framewrapper.style.float = "left";
    //framewrapper.style.margin = "0px";
    //framewrapper.style.height = "100%";
    //framewrapper.style.overflow = "hidden";
    
    var frame = document.createElement("iframe");
    frame.id="popupIFrame"
    frame.frameBorder="0";
    //frame.style.width = "100%";
    //frame.style.height = "100%";
    //frame.style.margin = "auto";
    //frame.style.borderStyle = "none";
    frame.src = eventid;

    var frameSrc = "eventid=";
    if(isEventType)  {
        frameSrc = "eventtypeid=";
    }

    popdiv.appendChild(framewrapper);
    framewrapper.appendChild(frame);
    
    document.body.appendChild(popdiv);
    ShowBlur();
}

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 ShowBlur() {
    blurdiv = document.createElement("div");
    blurdiv.id = "blurbox";
    blurdiv.style.display = "block";
    blurdiv.style.position = "absolute";
    blurdiv.style.left = "0";
    blurdiv.style.top = "0";
    blurdiv.style.zIndex = "10001";
    blurdiv.style.backgroundColor = "black";
    blurdiv.style.width = "100%";
    blurdiv.style.height = "100%";
    blurdiv.style.opacity = "0.4"; 
    blurdiv.style.filter = "alpha(opacity=40)";
	
    if(isIE()) {
            blurdiv.style.width = GetDocWidth() + "px";
            blurdiv.style.height = GetDocHeight() + "px"; 
 
       if(ieVersion < 7) { //If ie 6 or lower
            blurdiv.style.position = "absolute";
            blurframe = document.createElement("iframe");
            blurframe.style.display = "none";
            blurframe.style.top = "0";
            blurframe.style.left = "0";
            blurframe.style.zIndez = "-1";
            blurframe.style.filter = "mask()";
            blurframe.style.width = "3000px";
            blurframe.style.height = "3000px";
            blurdiv.appendChild(blurframe);
       }
	}

	document.body.appendChild(blurdiv);
}

function GetDocHeight(){
	return (window.innerHeight !== undefined) ? window.innerHeight: document.body.offsetHeight;
}

function GetDocWidth(){
	return (window.innerWidth !== undefined) ? window.innerWidth : document.body.offsetWidth;
}

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 RemoveById(id){
    var element = document.getElementById(id);
    if (element){
        document.body.removeChild(element);
    }
}

function RemoveModal(){
    RemoveById("blurbox");
    RemoveById("popupBox");
}

function CloseOnESC(evt){
		var typedKey = null;
		if(evt && evt.which)
		{ 
			typedKey = evt.which //character code is contained in NN4's which property
		}
		else
		{		
			typedKey = event.keyCode; //character code is contained in IE's keyCode property
		}
		if (typedKey == 27) {	    
			if(document.all) {
				window.event.cancelBubble='true';
				window.event.returnValue = false;
			} else {
				evt.stopPropagation();
				evt.preventDefault();
				
			}
			    RemoveModal();
		 }
}



//open menu with given ID
function openMenu(menuID, linkObj) {
    //if the menu code is ready
   
    if (um.ready) {
        //find co-ordinates of link object
        var coords = {
            'x': um.getRealPosition(linkObj, 'x'),
            'y': um.getRealPosition(linkObj, 'y')
        };

        //increase y-position to place it below the link
        coords.y += (linkObj.offsetHeight + 4);

        //activate menu at returned co-ordinates
        um.activateMenu(menuID, coords.x + 'px', coords.y + 'px');
    }
}

//close menu with given ID
function closeMenu(menuID) {
    //if the menu code is ready
    if (um.ready) {
        //deactive menu
        um.deactivateMenu(menuID);
    }
}