﻿
// JScript File

function addFuncToOnload(mFunc) {
    var ool = window.onload;
    if (ool) {
        window.onload = function() { 
            /*if (ool) ool();*/
            ool();
            mFunc();
        }
    } else {
        window.onload = mFunc;
    }
}

function dunlopDoSearch() {
    //window.dunlopSearchPageUrl
    if(window.dunlopSearchPageUrl) {
        $("div.search input.searchfld").each(function(obj){
            var url = window.dunlopSearchPageUrl + "?q=" + escape(this.value);
            document.location.href = url;
        });
    }
}
function dunlopDoSearchKeyEvent(obj,e) {
    if (obj && obj.value == '') return true;
    
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {//enter pressed
       dunlopDoSearch();
       return false;
    } else
       return true;
}

//addFuncToOnload(function() {
window.submenuRestoreDelay= 500;
window.submenuHideDelay = 500;
$(function() {
    $("div.subMenuHolder > div").hide();
    $("div.subMenuHolder > div").each(function() {        
           this.onmouseover = function() {
               window.freezeTopMenu  = true;                    
            }
            this.onmouseout = function() {
                window.freezeTopMenu  = false;
                doTopMenuRestoreImpl(window.submenuRestoreDelay);
            }
        });            
});
function doTopMenuMOver(nr, showSubmenu) {
    if(window.dunlopTopMenuImageLocation && window.dunlopTopMenuImageID) {
        var obj = document.getElementById(window.dunlopTopMenuImageID);
        if(obj) {
            var imgUrl = window.dunlopTopMenuImageLocation + 'menu-' + nr + '.gif';
            if(obj.src != imgUrl) {
                obj.src = imgUrl;                
           }
        }
        if(showSubmenu) {
            if(window.__restoreMenuTimeout) window.clearTimeout(window.__restoreMenuTimeout);
            $("div.subMenuHolder > div").hide();
            $("div.subMenu"+nr).show();
            
            
        }
        /*$("div.subMenu"+nr).each(function() {
            
        });*/
    }
    //doTopMenuMOver(5)" onmouseout="doTopMenuRestore()
}
function doTopMenuRestore() {
    if(window.freezeTopMenu) return;
    
    doTopMenuRestoreImpl(window.submenuHideDelay);
    /*
    $("div.subMenuHolder > div").hide();
    
    if(window.dunlopSelectedTopMenu) {
        doTopMenuMOver(window.dunlopSelectedTopMenu);
    }*/
}

function doTopMenuRestoreImpl(delay) {
    if(window.__restoreMenuTimeout) window.clearTimeout(window.__restoreMenuTimeout);
    if(delay < 1) {    
            if(window.freezeTopMenu) return;
            $("div.subMenuHolder > div").hide();
            
            if(window.dunlopSelectedTopMenu) {
                doTopMenuMOver(window.dunlopSelectedTopMenu);
            }
    } else {
        window.__restoreMenuTimeout = window.setTimeout(function() {
            if(window.freezeTopMenu) return;
            $("div.subMenuHolder > div").hide();
            
            if(window.dunlopSelectedTopMenu) {
                doTopMenuMOver(window.dunlopSelectedTopMenu);
            }
        }, delay);
    }
}

function doTopMenuClicked(selectedNr) {
    //find href in hidden links
    var found = false;
    window.freezeTopMenu = true;
    var selIdxNr = selectedNr - 1;
    $("div.masterTopMenu div.mainMenuTextLinks a").each(function(nr,obj) {
        if (selIdxNr == nr) {           
            found = true;
            document.location.href = this.href;
        }
    });
    if(!found) window.freezeTopMenu = false;
}



function doTopMenuPreload() {
    //preload the images after the page is loaded to prevent delays
    //$(
    //select the correct topmenu image
    $(function() {doTopMenuRestore()});
    
    addFuncToOnload(function() {
        if (window.dunlopTopMenuImageLocation) {
            //preload topmenu
            window.dunlopTopMenuImages = new Array();
            for(var i=1; i < 7;i++) {
                var img = new Image();
                img.src = window.dunlopTopMenuImageLocation + 'menu-' + i + '.gif';
                window.dunlopTopMenuImages[i] = img;
            }    
        }
    });
}


function removeSIFR() {
		if(typeof sIFR == "function"){
			sIFR.rollback();
			/*var lnkObj=document.getElementById('debugSifrRemoveLnk');
			if (lnkObj) {
				lnkObj.href="javascript:doSIFR();";
				lnkObj.innerHTML = "enable sIFR";
			}*/
		}
}

function doSIFR() {
    //2009023: geen sifr meer gebruiken
    if (typeof sIFR == "function") {

        /*
        //var colr = "#ee3a32";
        //var bgColr = "#FFFFFF";
        var colr = "#FFFFFF";
        var bgColr = "#D73834";
        var bgColr2 = "#932725";
        sIFR.replaceElement(".pageTitle",
        named({sFlashSrc: window.dunlopSifrFontLocation + "sifrTitle.swf?textSize=20", 
        sColor: colr, 
        sLinkColor: colr, 
        sBgColor: bgColr, 
        sHoverColor: colr,
        sWmode: "transparent"}));
        sIFR.replaceElement(".pageSubTitle",
        named({sFlashSrc: window.dunlopSifrFontLocation+ "sifr.swf?textSize=16", 
        sColor: colr, 
        sLinkColor: colr, 
        sBgColor: bgColr, 
        sHoverColor: colr,
        sWmode: "transparent"}));
        sIFR.replaceElement("h1.leftMenuTitle",
        named({sFlashSrc: window.dunlopSifrFontLocation + "sifr.swf?textSize=16", 
        sColor: colr, 
        sLinkColor: colr, 
        sBgColor: bgColr2, 
        sHoverColor: colr,
        sWmode: "transparent"
        }));
		      
		      
		
        
        /*
        var lnkObj=document.getElementById('debugSifrRemoveLnk');
        if (lnkObj) {
        lnkObj.href="javascript:removeSIFR();";
        lnkObj.innerHTML = "remove sIFR";
        }*/
		//sIFR.rollback();
		
	}
}
function correctHeight() {
    //masterContent
    /*
    addFuncToOnload(function() {    
        correctHeightImpl();
    });
    correctHeightImpl();
    */
}
function correctHeightImpl() {
    if(true) return;
    //correct page height if needed
    var normalH = 0;
    var fixed = false;
    
   $("div.pageRightImages:first").each(function(){ 
        normalH = parseInt(''+this.clientHeight,10);
   });
   if (normalH < 600) 
        normalH= 600;
    $("div.masterContent:first").each(function(){ 
        phH = parseInt(''+this.clientHeight,10);
        if (phH < normalH) {
            normalH+=50;
            this.style.height = normalH + 'px'; 
            fixed = true;
        }
        //alert('phH='+ phH + ' imgh: '+ normalH);
    });
    if(fixed) {
        $("div.pageRightImages:first").each(function(){ 
            //hack for IE 6:
            this.style.display = 'none';
            this.style.display = 'block';
       });
       $(".pageContentInner:first").each(function(){ 
            //hack for IE 6:
            this.style.display = 'none';
            this.style.display = 'block';
            
       });
       
    }
}

function membersValidateOrderShipmentWeekKU(obj) {
    //onkeyup
    

    var v2, v = new String('' + obj.value);
    v2 = v = v.toUpperCase();
    if (v.length > 1)
        v = v.substr(0, 2);
    if (v == 'AS') {
        obj.maxLength = 4;
        // obj.value = "ASAP";
        if (v2.length > 3) {
            if (v2 != "ASAP") obj.value = "ASAP";
        } else if (v2.length > 2) {
            if (v2 != "ASA") obj.value = "ASA";
        }
    } else {
        //check for numeric values?
        obj.maxLength = 2;
    }

    //return false;
}

function membersValidateOrderShipmentWeekKD(e) {//,obj) {
    var obj = this;
    //onkeydown
    if (!e) e = window.event;
    if (!e) return true;
    
    //input mag zijn: weeknummer(getal) of ASAP
    
    //txtOrderReference
    var v = new String('' + this.value);
    v = v.toUpperCase();
    var code = e.keyCode;
    
    if (v.length == 0) {
        //'A'
        if(code == 65) return true;
        if(code >= 48 && code <= 57) return true;
    }
    if (code == 8 || code == 9 || code == 46 || code == 37 || code == 39 ||code == 65 || code == 80 || code == 83 || code == 65) return true;
    if (code >= 48 && code <= 57) return true;
    
    
    return false; 
}