/**
 * @desc shortcut of document.getElementById
 */ 
function getId(id) {
    return document.getElementById(id);
}


/**
 * @desc stretch page height always till bottom of page
 * @desc called from main.tpl and iframe.js
 * @return void
*/          
function setPageHeight() {    
    if(document.getElementById && !(document.all)) {    // firefox
        
        // set midRight height to fill the whole page
        var iPageHeight = window.innerHeight;        
        document.getElementById('midRight').style.minHeight = iPageHeight + 'px';  // minHeight werkt goed in Firefox                 
        
                                        
        // set height for leftContainerDoorloop element (in case the items are too large) ONLY ON HOME PAGE
        if(getId('leftContainerDoorloop') != null) {
            var aPageSize = getPageSize();        // get aPageHeight from frame.js
            var iLeftContainerHeight = aPageSize[1];
            getId('leftContainerDoorloop').style.height = iLeftContainerHeight + 'px';
        }        
              
    }
    else if(document.all) {  // IE                
                                        
        // set midRight height to fill the whole page
        var iPageHeight = document.documentElement.clientHeight;         
        
        // voor IE8 zet height op 100%
        if(checkVersion() == 'IE8') {
            document.getElementById('midRight').style.height = '100%';     
        }
        // voor IE6 en IE7
        else {        
            document.getElementById('midRight').style.minHeight = iPageHeight + 'px';  // minHeight werkt goed voor IE7
            //document.getElementById('midRight').style.height = 'auto !important';      // deze is gezet in screen.css, als je het hier ziet geeft ie error
            document.getElementById('midRight').style.height = iPageHeight + 'px';     // voor IE6                           
        }
        
        // set height for leftContainerDoorloop element (in case the items are too large) ONLY ON HOME PAGE
        if(getId('leftContainerDoorloop') != null) {
            var aPageSize = getPageSize();        // get aPageHeight from frame.js
            var iLeftContainerHeight = aPageSize[1];
            if(getId('leftContainerDoorloop'));
            getId('leftContainerDoorloop').style.height = iLeftContainerHeight + 'px';
        }
    } 
}        
                             

                             
                             
                             
                             
                             
                             

/**
 * @desc nav onmouseover change picture 
 * @params imageId, picName, hrefId, hId, sSelected
**/  
function navChangePictureHover(imageId, picName, hrefId, hId, sSelected) { 
    
    getId(imageId).src= sRootUrl+"images/nav/navBottom/"+picName
    getId(hrefId).style.background = 'url(images/nav/navBottom/redDot.gif) repeat-x';
    getId(hrefId).style.backgroundPosition = '0px 15px';
    getId(hId).style.cursor = 'pointer';
}
function navChangePictureOut(imageId, picName, hrefId, hId, sSelected) { //alert(sSelected);
    
    if(sSelected == 'true') {
        getId(imageId).src= sRootUrl+"images/nav/navBottom/" + picName + "_on.gif";       
        getId(hrefId).style.background = 'url(images/nav/navBottom/blackDot.gif) repeat-x';                
    }
    else {
        getId(imageId).src= sRootUrl+"images/nav/navBottom/"+picName + "_off.gif"        
        getId(hrefId).style.background = 'url(images/nav/navBottom/greyDot.gif) repeat-x';        
    }

    getId(hrefId).style.backgroundPosition = '0px 15px';
}


 



// show pointer
function showPointer(id) {
    getId(id).style.cursor = 'pointer';
}
// onmouseover vergroot afbeelding
function styleOnVergrootAfb(id) {
    id.style.cursor = 'pointer';
    id.style.color = '#C31A2D'; 
    id.style.borderBottom = 'dotted #C31A2D 1px';
    /*
    id.style.background = 'url(../images/nav/enkele_rodelijn.gif) repeat-x';          
    id.style.backgroundPosition = '0px 17px';
    */                
}
// onmouseout vergroot afbeelding
function styleOutVergrootAfb(id) {
    id.style.cursor = 'pointer';
    id.style.color = '#00B6B6'; 
    id.style.borderBottom = 'dotted #00B6B6 1px';
    /*
    id.style.background = 'url(../images/nav/enkele_blauwelijn.gif) repeat-x';          
    id.style.backgroundPosition = '0px 17px';
    */                    
}


// zoekveld bovenaan de pagina
function cleanField(id) {   
    if(getId(id).value == 'Zoek...') {
        getId(id).value = '';      
    }   
}
function showText(id, text) {
    if(getId(id).value == '') {
        getId(id).value = text;    
    }
}

  


// onmouseOVER print dit artikel link
function changeCursorOver(id) {        

    getId(id).style.cursor = 'pointer';
    getId(id).style.borderBottom = 'dotted #C31A2D 1px';
    /*
    getId(id).style.background = 'url(../images/nav/enkele_rodelijn.gif) repeat-x';
    getId(id).style.backgroundPosition = '0px 17px';
    */
    getId(id).style.color = '#C31A2D';    
}

// onmouseOUT print dit artikel link
function changeCursorOut(id) {  
      
    getId(id).style.cursor = 'pointer';
    getId(id).style.borderBottom = 'dotted #56A9AD 1px';
    /*
    getId(id).style.background = 'url(../images/nav/enkele_blauwelijn.gif) repeat-x';
    getId(id).style.backgroundPosition = '0px 17px';
    */
    getId(id).style.color = '#56A9AD';    
}

// onmouseOVER image (used on homepage images on the left)
function changeCursorOverImage(id) {                     
    getId(id).style.cursor = 'pointer';
}

// onmouseOUT image  (used on homepage images on the left)
function changeCursorOutImage(id) {      
    getId(id).style.cursor = 'pointer';
}




// onclick printPage
function printPage() {
    window.print();    
} 



// show info container
function showInfoContainer(id) {    
    getId(id).style.cursor = 'pointer';                  
    getId('iDealInfoContainer').style.display = 'block';                  
    
}
// hide info container
function hideInfoContainer() {
    getId('iDealInfoContainer').style.display = 'none';                  
}




// ZOEKEN FORMULIER
function zoek_pub_onclick(id) { 
    var searchString = getId(id).value;        
    searchString = searchString.replace(/ /g,'+');
    
    // ajax call om de searchString te filteren                       
/*    var oRequest = new cRequest();                      
    oRequest.sUrl = sRootUrl + 'libs/ajax/filterSearchString.php?call=searchString&searchstring=' + searchString;
    oRequest.sType = 'GET';       
    var trefwoord = eval(oRequest.getContent().responseText);             // set data in var data
*/    
    
    window.location.href = sRootUrl + 'zoeken/' + getId(id).name + '/' + searchString;    

}
// trefwoord en druk op ENTER
function zoek_pub_pressdown(id, event) {     
    // IE
    if(window.event) {
        keynum = event.keyCode;
    }
    // Netscape/Firefox/Opera
    else if(event.which) {
        keynum = event.which;
    }   
         
    if(keynum == 13) {   
        window.location.href=sRootUrl+'zoeken/'+getId(id).name+'/'+getId(id).value;    
    }
}




/* REGISTER VAN AUTEURS LETTERS */
function letterPicHover(id, picName) { 
               
    getId(id).src = sRootUrl+"images/register_auteurs/"+picName+"_h.gif";
}
function letterPicOut(id, picName, sSelected) {
    
    if(sSelected == 'true') {
        getId(id).src = sRootUrl+"images/register_auteurs/"+picName+"_s.gif";
    }
    else {
        getId(id).src = sRootUrl+"images/register_auteurs/"+picName+"_n.gif";        
    }
}



/**
* @desc get Auteur naam
*/
function setAuteurName(iAuteurId, sRootUrl) {
    
    // ajax call : get Auteur achter en voornaam
                    
    var oRequest = new cRequest();                          
    oRequest.sUrl = sRootUrl + 'iframe/getAuteurName.php?auteurid=' + iAuteurId;
    oRequest.sType = 'GET';       
    var sAuteur = eval(oRequest.getContent().responseText);             // set data in var data    
    
    // remove quotes
    var sAuteur = removeQuotes(sAuteur, '"', '');
    
    // set Auteurnaam in input field
    top.getId('auteur').value = sAuteur;
    
    // hide iFrame
    top.getId('autoCompleteDropDown').style.display = 'none';   
    
    // set focus on auteur input field
    top.getId('auteur').focus();
    
}    

 // Loop over the string value replacing out each matching substring
function removeQuotes(str, sSearch, sReplace) {
        
    var intIndexOfMatch = str.indexOf(sSearch);
                       
    while (intIndexOfMatch != -1){
        // Relace out the current instance.
        str = str.replace(sSearch, sReplace)
      
        // Get the index of any next matching substring.
        intIndexOfMatch = str.indexOf(sSearch);
    }
  
    return str;
}




// used for ie8 detection
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null) {
            rv = parseFloat(RegExp.$1);
        }
    }

    return rv;
}

function checkVersion() {
    msg = '';
    var ver = getInternetExplorerVersion();

    if (ver > -1) {
        if (ver >= 8.0) {
            msg = 'IE8';
        }
    }
    return msg;
}