/* 
WMS Lucrasoft Javascript Standaard functies
*/
var CurrentItem = 0;
var CurrentItemLoaded = 0;
var OrderNr = 0;
var Title = 1;
var Image = 2;
var Ranking = 3;
var RankingText = 4;
var Text = 5;
var Kijkwijzer = 6;
var Link = 7;
var lstTopRentals = new Array();
var CurrentSlideItem = 0;
var SlideItems = 0;
var intCurrentPosition = 0;
var IsScrolling = false;
var IsFading = false;
var intOpacity = 0;
var intDirection = 1;

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 SetIf(p_objThis, p_strIf, p_strThen) {
    if (p_objThis.value == p_strIf) {
        p_objThis.value = p_strThen;
    }
}

function SetSourceImage(p_This, p_strImage) {
    p_This.src = p_strImage;
}

function CloseAudioVideoLoader() {
    document.getElementById('divOverLay').style.display = 'none';
    document.getElementById('divPlayer').innerHTML = '';
    document.body.className = "htmlscroll";
}

function AudioVideoLoader(Url) {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }

    document.body.className = "html";
    document.getElementById('divOverLay').style.display = 'block';
    //document.getElementById('divOverLay').style.marginTop = scrOfY + 'px';

    var so = new SWFObject('FlashPlayer/player.swf', 'player', '640', '370', '9');
    so.addParam('allowfullscreen', 'true');
    so.addParam('allowscriptaccess', 'always');
    so.addParam('wmode', 'opaque');
    so.addParam('flashvars', '&file=' + Url + '.flv&autostart=true&skin=FlashPlayer/modieus.swf');
    so.write("divPlayer");
}

function showNoTrailer() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }

    document.body.className = "html";
    document.getElementById('divOverLay').style.display = 'block';
    document.getElementById('divOverLay').style.marginTop = scrOfY + 'px';


    document.getElementById('divPlayer').innerHTML = '<img src="./design/No_trailer.jpg" alt="">';
}


function GetOrderNrItem(p_intAdd) {
    CurrentItem = CurrentItem + p_intAdd;
    intGoToPosition = CurrentItem;
    
    if (CurrentItem > lstTopRentals.length - 1) {
        CurrentItem = lstTopRentals.length - 1;
    }
    if (CurrentItem < 0) {
        CurrentItem = 0;
    }

    if (intGoToPosition > lstTopRentals.length - 4) {
        intGoToPosition = lstTopRentals.length - 4;
    }
    if (intGoToPosition < 0) {
        intGoToPosition = 0;
    }

    intDirection = -1;
    if (CurrentItemLoaded != CurrentItem) {
        CurrentItemLoaded = CurrentItem;
        if (IsScrolling == false) {
            MoveTo();
        }
        if (IsFading == false) {
            HomeFade();
        }
    }
    
}

function GetClickedItem(p_intItem) {
    CurrentItem = p_intItem;
    intGoToPosition = p_intItem;

    if (intGoToPosition > lstTopRentals.length - 4) {
        intGoToPosition = lstTopRentals.length - 4;
    }
    intDirection = -1;
    if (CurrentItemLoaded != CurrentItem) {
        CurrentItemLoaded = CurrentItem;
        if (IsScrolling == false) {
            MoveTo();
        }
        if (IsFading == false) {
            HomeFade();
        }
    }
}

function SetHomeTopRental() {
    //document.getElementById('pnlSelectedImg').style.backgroundImage = 'url(' + lstTopRentals[CurrentItem][Image] + ')';
    document.getElementById('pnlHeader').innerHTML = lstTopRentals[CurrentItem][Title];
    //document.getElementById('pnlHeader').style.backgroundImage = 'url(./design/bg_top_' + lstTopRentals[CurrentItem][OrderNr] + '.png)';
    //document.getElementById('pnlHeader').style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='./design/bg_top_" + lstTopRentals[CurrentItem][OrderNr] + "')";
    document.getElementById('pnlRanking').style.width = 79 / 50 * lstTopRentals[CurrentItem][Ranking] + 'px';
    document.getElementById('lblRankingText').innerHTML = lstTopRentals[CurrentItem][RankingText];
    document.getElementById('divHomeText').innerHTML = lstTopRentals[CurrentItem][Text];
    document.getElementById('divHomeKijkwijzer').innerHTML = lstTopRentals[CurrentItem][Kijkwijzer];
    document.getElementById('hlMoreInfo').href = lstTopRentals[CurrentItem][Link];
    var imgLoad = document.getElementById('imgSeleceted');
    imgLoad.src = '';
    imgLoad.onload = function () {
        intDirection = 1;
        setTimeout("HomeFade(" + intOpacity + ")", 100);
    }
    imgLoad.src = lstTopRentals[CurrentItem][Image];
    imgLoad.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='" + lstTopRentals[CurrentItem][Image] + "')";
}

function HomeFade() {
    document.getElementById('divHomeToFade').style.opacity = intOpacity / 100;
    document.getElementById('divHomeToFade').style.filter = 'alpha(opacity=' + intOpacity + ')';
   
    if (intDirection == 1) {
        if (intOpacity >= 100) {
            IsFading = false;
            intOpacity = 100;
            document.getElementById('divHomeToFade').style.filter = 'none)';
        } else {
            IsFading = true;
            intOpacity = intOpacity + 10;
            setTimeout("HomeFade(" + intOpacity + ")", 40);
        }
    } else {
        if (intOpacity <= 0) {
            IsFading = false;
            intOpacity = 0;
            SetHomeTopRental();
        } else {
            IsFading = true;
            intOpacity = intOpacity - 10;
            
            setTimeout("HomeFade(" + intOpacity + ")", 40);
        }
    }
}

function MoveTo() {
    var objSlide = document.getElementById('pnlHomeSlide');
    var intGoTo = intGoToPosition * 106;
    if (intGoTo > intCurrentPosition) {
        intCurrentPosition += Math.ceil((intGoTo - intCurrentPosition) / 3);
    } else {
        intCurrentPosition -= Math.ceil((intCurrentPosition - intGoTo) / 3)
    }

    objSlide.style.marginLeft = '-' + intCurrentPosition + 'px';
    if (intGoTo != intCurrentPosition) {
        //alert(intCurrent + ' # ' + intGoTo + ' # ' + intToGo + ' # ' + intGo);
        IsScrolling = true;
        setTimeout("MoveTo()", 40);
    } else {
        IsScrolling = false;
    }
}

function SetOverlay() {
    var arrayPageSize = getPageSize();
    var divOverlay = document.getElementById('Overlay')
    divOverlay.style.width = arrayPageSize[0] + 'px'
    divOverlay.style.height = arrayPageSize[1] + 'px'
    divOverlay.style.display = 'block'
}

function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    return [pageWidth, pageHeight];
}
