// Common library for scripts

// Variables
var theHeight = 1;
var maxHeight = 48;
var blockSub = false;
var oneTimeWinName = "oneTimePop"

// Reloader : reloads page with header and main menu if not present

//    if (top.location.href == window.location.href) {
//        // content loader
//        var rl = window.location.href;
//        var rlc = rl.substring(8, rl.length)
//        var fstsl = rlc.indexOf('/');
//        var lstsl = rlc.lastIndexOf('/');
//        var section = rlc.substring(fstsl + 1, lstsl);
//
//        fstsl = rlc.indexOf('?');
//
//        if (fstsl <0) {
//            fstsl = rlc.length;
//        }
//
//        var page    =  rlc.substring(lstsl + 1, fstsl);
//        if (page == "") page = "index.jsp";
//        var params  = "&" + rlc.substring(fstsl+ 1, rlc.length);
//        var reppar = params.replace(/#/g, "~");
//        var newPage = "page=" + page + "&sh=" + section  + reppar;
//        top.location.href = "/index.jsp?" + newPage;
//        if (top.header != null) {
//                top.header.setHeader(section);
//        }
//        if (top.navigater != null) {
//            top.navigater.setActivemenu(section);
//        }
//     }

function openPopWinOnce(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
    var d_winLeft = 20  // default, pixels from screen left to window left
    var d_winTop = 20   // default, pixels from screen top to window top
    var popcookies = document.cookie
    if (openPopWinOnce.arguments.length >= 4)  // any additional features? 
        winFeatures = "," + winFeatures
    else 
        winFeatures = "" 
    if (openPopWinOnce.arguments.length == 6)  // location specified
        winFeatures += getLocationOne(winWidth, winHeight, winLeft, winTop)
    else
        winFeatures += getLocationOne(winWidth, winHeight, d_winLeft, d_winTop)
    if (popcookies.indexOf(oneTimeWinName) == -1){ // cookie not found 
       window.open(winURL, oneTimeWinName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
       document.cookie=oneTimeWinName+"=used"
    }
}

function getLocationOne(winWidth, winHeight, winLeft, winTop){
  return ""
}

function getLocationOne(winWidth, winHeight, winLeft, winTop){
    var winLocation = ""
    if (winLeft < 0) winLeft = screen.width - winWidth + winLeft
    if (winTop < 0) winTop = screen.height - winHeight + winTop
    if (winTop == "cen") winTop = (screen.height - winHeight)/2 - 20
    if (winLeft == "cen") winLeft = (screen.width - winWidth)/2
    if (winLeft>0 & winTop>0) winLocation =  ",screenX=" + winLeft + ",left=" + winLeft	+ ",screenY=" + winTop + ",top=" + winTop
        else winLocation = ""
    return winLocation
}

function pull() {
	if (window.drawMenu) clearInterval(drawMenu);
	if (browserName == "Firefox") slideMenu.style.border = "1px solid #000000;";
        if (browserName == "Firefox") slideMenu.style.background = "#8e8e8e;";
	pullMenu = setInterval("pullEngine()", 20);
}

function draw() {
	if (!blockSub) {
		clearInterval(pullMenu);
		drawMenu = setInterval("drawEngine()", 20);
	}
}

function pullEngine(theheight) {
	if (theHeight < maxHeight) {
		theHeight += 3;
		slideMenu.style.height = theHeight;
	} else {
		if (window.pullMenu) clearInterval(pullMenu);
	}
}

function drawEngine() {
	if (theHeight > 1) {
		theHeight -= 3;
		slideMenu.style.height = theHeight;
	} else {
		theHeight = 1;
		if (browserName == "Firefox") slideMenu.style.border = "0px solid #000000;";
                if (browserName == "Firefox") slideMenu.style.background = "#000000;";
		if (window.drawMenu) clearInterval(drawMenu);
	}
}

function whichBrs() {
	// Browser check
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
			return navigator.userAgent.substr(0,agt.indexOf('\/'));}
		else return 'Netscape';
	} else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0,agt.indexOf(' '));
		else return navigator.userAgent;
}

function movepic(img_name,img) {
	// image mouseover
	var theimg = document.getElementById(img_name).src;
	if ( theimg.substring(theimg.length - 6, theimg.length - 4) != "on") document.getElementById(img_name).src = images[img];
}
			
function openSubhome(thesub, img, thelang) {
	// opens the submenu
	
	// handle images
	for(x=1 ; x<=5 ; x++)document.getElementById('m' + x).src = images[(x-1)*3];
	document.getElementById('m' + thesub).src = images[img];
	
        // determin language
        switch(thelang) {
            case 'fr#' :
                var tl = "/FR";
                break;
            case 'uk#' :
                var tl = "/UK";
                break;
            default :
                var tl = "";
        }

	//open submenu 
	switch(thesub) {
		case 1	: 
                    var cleanurl = window.location.href.substring(8, window.location.href.length);
                    if (cleanurl.lastIndexOf("/") == cleanurl.indexOf("/")) {
                        blockSub = true;
                    // Removed on IGMA's request
                    //} else {
                    //    window.location.href = "/index.jsp?expanded"
                    }
                    window.location.href = tl + "/index.jsp"
                    break;
		case 2	: 
                    window.location.href= tl + "/contact/index.jsp";
                    break;
		case 3	: 
                    window.location.href= tl + "/werken/index.jsp";
                    break;				
		case 4	: 
                    window.location.href= tl + "/franchise/index.jsp";
                    break;
		case 5	: 
                    window.location.href= tl + "/voorwaarden/index.jsp";
                    break;
		default	: 
                    window.location.href= tl + "/index.jsp";
	}
}

function searchSite(theLang) {
    // Searches the site

        // determin language
        switch(theLang) {
            case 'fr#' :
                var tl = "/FR";
                break;
            case 'uk#' :
                var tl = "/UK";
                break;
            default :
                var tl = "";
        }

    var sstr = document.getElementById("search").value;
    window.location.href= tl + "/search/index.jsp?query=" + sstr;
}

function printPage(thePage, theLang) {
    // prints the requested page

        // determine language
        switch(theLang) {
            case 'fr#' :
                var tl = "/FR";
                break;
            case 'uk#' :
                var tl = "/UK";
                break;
            default :
                var tl = "";
        }

    var pagetype = thePage.substr(0, thePage.indexOf('?'));
    var QS = thePage.substr(thePage.indexOf('?'), thePage.length);
    switch(pagetype) {
        case "vacature" :
            window.open(tl + '/werken/vacaturePrint.jsp' + QS, 600, 600, '', 0,0);
            break;
        case "route1" :
            window.open(tl + '/contact/route1Print.jsp', 600, 600, '', 0,0);
            break;
        case "route2" :
            window.open(tl + '/contact/route2Print.jsp', 600, 600, '', 0,0);
            break;
        default	: 
            // nothing.
    }
}

function resizePanes(corrf1, corrf2){  
	var frame1 = document.getElementById("infopane");  
	var frame2 = document.getElementById("scroll0Container");  
	var htmlheight = document.body.parentNode.scrollHeight;  
	var windowheight = window.innerHeight;  
	if ( htmlheight < windowheight ) { 
		frame1.style.height = eval(windowheight - corrf1) + "px"; 
		frame2.style.height = eval(windowheight - corrf2) + "px"; 
	}  else { 
		frame1.style.height = eval(htmlheight - corrf1) + "px"; 
		frame2.style.height = eval(htmlheight - corrf2) + "px"; 
	}  
} 

/* include writecms.js */
document.write('<script src="/scripts/writecms.js" type="text/javascript" language="JavaScript"></script>');

