
var bIS_IE;
if (window.Event){
	bIS_IE = false
}else{
	bIS_IE = true
}

function ShowMessage (bMode,sMsg,sID){
    var oWaitDIV;
    var nPosX,nPosY,nMessageB,nMessageH;
    
    if (bMode == true){
        
        if(!document.getElementById(sID)) CreateWaitDIV(sMsg,sID);
        oWaitDIV = document.getElementById(sID);
        oWaitDIV.style.display = "";

        // Hoehe/Breite der Messagebox
        nMessageB = oWaitDIV.clientWidth;
        nMessageH = oWaitDIV.clientHeight;

        //Berechnung X/Y-Pos
        nPosX = (document.body.clientWidth/2 - nMessageB/2) + document.body.scrollLeft; 
        nPosY = (document.body.clientHeight/2 - nMessageH/2) + document.body.scrollTop;
        
        // DIV platzieren
        oWaitDIV.style.left = nPosX + "px";
        oWaitDIV.style.top = nPosY + "px";        
        
    }else{
        if(document.getElementById(sID)){
            oWaitDIV = document.getElementById(sID);
            oWaitDIV.style.display = "none";
            document.body.style.cursor = "arrow";
        }
    }
}

function openPopupWin (sUrl,sName,sScrollbars,nWidth,nHeight) {
    //M.G. 21.11.08
	var sResize="no";
	
	if(window.Event) {
    //IE
        nPosX = (screen.width - nWidth) / 2
        nPosY = (screen.height - nHeight) / 2
    } else {
        nPosX = (screen.availWidth - nWidth) / 2
        nPosY = (screen.availHeight - nHeight) / 2
    }
	//M.G. 21.11.08
	if(sScrollbars=="resyes"){sScrollbars=="no";sResize="yes";}
	
	//M.G. 21.11.08
    sProp = "width=" + nWidth + ",height=" + nHeight + ",left=" + nPosX + ", top=" + nPosY + ",resizable=" + sResize + ",scrollbars=" + sScrollbars + ",dependent=yes";
    var WinHandle = open(sUrl, sName, sProp);
    WinHandle.focus();
}

function GenPopup (sArtNr,sKontext,e){
    var sIframeName;
    var H,B,X,Y;
    var oDate = new Date();
    
    // Defaultwerte
    sIframeName = "IFramePopupobj";
    H = 60;
    B = 350;
    X = 100;
    Y = 100;

    if (document.all) {
        X = e.clientX + document.body.scrollLeft;
        Y = e.clientY + document.body.scrollTop;
    }else{
        X = e.pageX;
        Y = e.pageY;
    }
    
    X += 20
    Y -= 20

    // IFrame erzeugen/holen
    if(!document.getElementById(sIframeName)) {
        iframeOBJ = createIframe (sIframeName,X,Y,H,B);
    }else{
        iframeOBJ = document.getElementById(sIframeName)
        iframeOBJ.style.heigth = H + "px";
        iframeOBJ.style.left = Math.round(X) + "px";
        iframeOBJ.style.top = Math.round(Y) + "px";
    }

    // URL ->  HTML im IFrame macht ShowPopup()
    iframeOBJ.src = "/iprosvc/ArtikelInfo.aspx?i=" + oDate.getTime() + "&artnr="+ sArtNr + "&Kontext=" + sKontext;
    iframeOBJ.style.display = "block";
}


function ShowPopup(){
	if (iframeOBJ) {
		iframeOBJ.style.display = "";
		SetMouseEvents();
	}
}

function SetMouseEvents(){
  if (bIS_IE){
    document.onmousedown = CaptureMouseClick;
  }else{
    window.captureEvents(Event.MOUSEDOWN);
    window.onmousedown = CaptureMouseClick;
  }
}

function CaptureMouseClick(e) {
	HidePopup();
}

function HidePopup(){
	if (iframeOBJ) {
		iframeOBJ.style.display = "none";
		ChangeURL("about:blank",iframeOBJ)
		DeleteMouseEvents();
	}
}

function DeleteMouseEvents(){
  if (bIS_IE){
    document.onmousedown = null;
  }else{
	window.releaseEvents(Event.MOUSEDOWN)
  }
}

function ChangeURL(sNewURL,oIFrame){
	var IFrameDoc = null;
	
	if (oIFrame.contentDocument) {
	    // For NS6
	    IFrameDoc = oIFrame.contentDocument; 
	} else if (oIFrame.contentWindow) {
	    // For IE5.5 and IE6
	    IFrameDoc = oIFrame.contentWindow.document;
	} else if (oIFrame.document) {
	    // For IE5
	    IFrameDoc = oIFrame.document;
	}
	
	if (IFrameDoc != null){
		// URL wird nicht in History eingetragen
		IFrameDoc.location.replace(sNewURL);
	}else{
		// URL wird inHistory eingetragen
		iframeOBJ.src = sNewURL;
	}
	
	return false;
}



function ResizePopup(sDIVElement){
	var nHoehe;

	// Popup da
	if (!iframeOBJ) return;
	
	// Objekt fuer Hoehenermittlung da?
	if(window.frames[iframeOBJ.id].document.getElementById(sDIVElement) == null) return;

	// 2 mal da sonst Hoehe falsch im IE
	for (var i=0; i < 2; i++) {
		nHoehe = window.frames[iframeOBJ.id].document.getElementById(sDIVElement).offsetHeight
		if (iframeOBJ) iframeOBJ.style.height = nHoehe + "px";
	}
}

function isEmail(s){
    var reg;
    var a = false;
    var res = false;

    if(typeof(RegExp) == 'function'){
        var b = new RegExp('abc');
        if(b.test('abc') == true) a = true;
    }

    if (a == true){
        var b = new RegExp("^[a-z0-9'+_-]+(?:\.[a-z0-9'+_-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+([a-z]{2,4})$","i");
        res = b.test(s);
    } else{
        res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5)
    }
    return (res);
}

function restoreValue (aObjE,Evalue) {

    switch (aObjE[0].type) {
    case "checkbox":
        aObjE[0].checked = true;
    break;
    case "radio":
        for(var i=0;i<aObjE.length;i++) {
            if(aObjE[i].value == Evalue)
                aObjE[i].checked = true;
            else
                aObjE[i].checked = false;
        }
    break;
    case "text":
        aObjE[0].value = Evalue;
    break;
    case "textarea":
        aObjE[0].value = Evalue;
    break;
    }
}


function CreateWaitDIV (sText,sID) {
    oDIV = document.createElement("div");
    oDIV.setAttribute("id",sID);
    document.body.appendChild(oDIV);
    
    oElement = document.getElementById(sID);
    oElement.style.display = "none";
    oElement.style.whiteSpace = "nowrap";
    oElement.innerHTML = sText;
}

function createIframe (sName,X,Y,H,B) {
    var oIF; 
    if (document.createElement && (oIF = document.createElement("iframe"))) {
        oIF.setAttribute("id",sName);
        oIF.setAttribute("name",sName);
        oIF.src = "about:blank";
        oIF.style.position = "absolute";
        oIF.style.left = Math.round(X) + "px";
        oIF.style.top = Math.round(Y) + "px";
        oIF.style.width = Math.round(B) + "px";
        oIF.style.height = Math.round(H) + "px";
        oIF.style.zIndex = 1000;
        oIF.frameBorder = 0;
        oIF.style.backgroundColor = "#959595";
        //oIF.style.border = "1px solid red";
        oIF.scrolling = "auto";
        oIF.style.display = "none";
        document.body.appendChild(oIF);
    }
    return oIF;
}

function getCsid() {
  var a = document.cookie;
  var b = a.substr(a.search('VisitorID=')+10)
  if (b.search(';') != -1)
    return b.substr(0,b.search(';'));
  else
    return b;
}

function RefreshWakoPosAnzahl(){
  var sURL = "/iprosvc/GetWakoInfo.aspx?action=posanzahl";
  sendRequest(sURL, "", MMA_REQUEST_GET, 0 , "CallbackWakoPosAnzahl");
}

function CallbackWakoPosAnzahl(sResult){
  if(document.getElementById("wako_nr")){
    document.getElementById("wako_nr").innerHTML = "(" + sResult + ")";
  }
}
