/* 
WMS Lucrasoft Javascript Standaard functies
*/

function makeHttpRequest(url){ 
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
        if (http_request.overrideMimeType) { 
            http_request.overrideMimeType('text/xml'); 
    } 
        } else if (window.ActiveXObject) { // IE 
            try { 
                http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
            } catch (e) { 
                try { 
                    http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
                } catch (e) {} 
            } 
        } 
    if (!http_request) { 
        alert('Helaas, jouw browser is te oud om deze pagina te kunnen laden.'); 
        return false; 
    } 
        http_request.open('GET', url, true); 
        http_request.send(null); 
}

function getField(fldName, strType) {
  var arrCheck = new Array;
  var blnFound = false;
  arrObjects = document.getElementsByTagName(strType.toUpperCase());
  for (i=0; i<arrObjects.length; i++) {
    if (arrObjects[i].id.split("_")[arrObjects[i].id.split("_").length - 1] == fldName) {
      blnFound = true;
      break;
    }
  }
  return arrObjects[i];
}

function PopUp(strPath) {
    window.open(strPath, 'WMSPOPUP', 'status=yes,resizable=yes,width=1024,height=764');
}

function MailTo(value) {
   if (value) {
		 var strTemp='';
		 for (i = value.length-1; i>=0; i--){
			 strTemp+=value.charAt(i);
		 }
		 strTemp = strTemp.split('|').join('@');
		 document.write('<a href=mailto:' + strTemp + '>' + strTemp + '</a>');
	 }
}

function ShowStockImage(p_intItem, p_strImage) {
    ResetAllStocksImages();
    document.getElementById(p_intItem.replace('divThumb_', 'hlImage_')).style.display = 'block';
    document.getElementById(p_intItem).className = 'pnlThumb_BG_Selected';
}

function ResetAllStocksImages() {
    var divItem = document.getElementById('divThumb_0');
    var intCounter = 0;
    while (divItem) {
        divItem.className = 'pnlThumb_BG';
        document.getElementById('hlImage_' + intCounter).style.display = 'none';
        intCounter += 1;
        divItem = document.getElementById('divThumb_' + intCounter);
    }
}

function FillIf(p_this, p_strIf, p_strFill) {
    if (p_this.value == p_strIf) {
        p_this.value = p_strFill;
    }
}

var imgSlideImage_1, imgSlideImage_2;
function LoadFlashPlayer(p_strFile, p_strTarget, p_intWidth, p_intHeight, p_ExtraVar) {
    var so = new SWFObject('FlashPlayer/player.swf', 'player', p_intHeight, p_intWidth, '9');
    so.addParam('allowfullscreen', 'false');
    so.addParam('allowscriptaccess', 'always');
    so.addParam('wmode', 'opaque');
    so.addParam('flashvars', '&file=' + p_strFile + '&autostart=false' + p_ExtraVar + '&skin=FlashPlayer/modieus.swf');
    so.write(p_strTarget);
    document.getElementById(p_strTarget).style.display = 'block';
}

var IsFading = true;
var CurrentImageID = 1;
var CurrentImageCount = 1;
var intDirection = 1;

function ChangeSlideImageAuto(p_intDir) {
    ChangeSlideImage(p_intDir);
    setTimeout('ChangeSlideImageAuto(' + p_intDir + ')', 10000);
}

function ChangeSlideImage(p_intDir) {
    intDirection = p_intDir;
    if (IsFading == false) {
        IsFading = true;
        imgSlideImage_1 = document.getElementById("imgSlideImage_" + CurrentImageID);
        if (document.getElementById("imgSlideImage_2")) {
            CurrentImageID = CurrentImageID + p_intDir;
            imgSlideImage_2 = document.getElementById("imgSlideImage_" + (CurrentImageID));
            if (!imgSlideImage_2) {
                intSlideCounter = 0;
                if (p_intDir == 1) {
                    CurrentImageID = 1;
                } else {
                    CurrentImageID = CurrentImageCount;
                }
                imgSlideImage_2 = document.getElementById("imgSlideImage_" + CurrentImageID);
            }
            var img = new Image();
            img.onload = function () {
                if (imgSlideImage_2 != null) {
                    SlideShow(0);
                }
            }
            img.src = imgSlideImage_2.src;
        }
    }
}

function StartSlide() {
    if (document.getElementById("imgSlideImage_1")) {
        intSlideCounter = 0;
        var img = new Image();
        img.onload = function () {
            if (imgSlideImage_2 != null) {
                SlideShow(0);
            }
        }
        imgSlideImage_2 = document.getElementById("imgSlideImage_1");
        imgSlideImage_2.style.zIndex = '20';
        imgSlideImage_1 = null;
        img.src = imgSlideImage_2.src
        setTimeout('ChangeSlideImageAuto(1)', 10000);
    }
}

function SlideShow(intOpacity) {
    if (intOpacity == 0) {
        if (imgSlideImage_1 != null) { imgSlideImage_1.style.zIndex = '20'; }
        if (imgSlideImage_2 != null) { imgSlideImage_2.style.zIndex = '10'; }
    }
    intOpacity = intOpacity + 10;

    if (imgSlideImage_1 != null) {
        imgSlideImage_1.style.zIndex = '20';
        imgSlideImage_1.style.opacity = ((100 - intOpacity) / 100);
        imgSlideImage_1.style.filter = 'alpha(opacity=' + (100 - intOpacity) + ')';
    }

    if (imgSlideImage_2 != null) {
        imgSlideImage_2.style.zIndex = '10';
        imgSlideImage_2.style.opacity = intOpacity / 100;
        imgSlideImage_2.style.filter = 'alpha(opacity=' + intOpacity + ')';
    }

    if (intOpacity >= 100) {
        IsFading = false;
    } else {
        setTimeout('SlideShow(' + intOpacity + ')', 40);
    }
}
