function fit(scaleOn,cusSize) {
	if(cusSize == '*') {
		var cusSize = 1
		var scaleOn = 1
	} else if(!cusSize) var cusSize = 1
	else if(cusSize.length > 1) {
		cusSize = ((cusSize*10) / Math.pow(10,cusSize.length))
	}
	cltWidth = document.body.clientWidth
	if (window.navigator.appName != 'Microsoft Internet Explorer') {
		cltWidth -= 19
	} else {
		document.getElementById('bckdiv').style.visibility = 'visible'
	}
	if (cltWidth < 608) cltWidth = 608
	userTextSize = (document.bckimgtop.width / (bgwidth * 16))
	userRes = cltWidth / bgwidth / 16
	if (scaleOn) {
		newFontSize = (Math.floor(userRes / userTextSize / 0.0625) * 0.0625)*cusSize
	} else {
		newFontSize = (1/userTextSize)*cusSize
	}
	document.body.style.fontSize=newFontSize+'em'
}

function reFit() {
	if (window.navigator.appName == 'Microsoft Internet Explorer') {
		fitWidth = document.body.clientWidth
		if (fitWidth < 608) fitWidth = 608
		userRes = fitWidth / bgwidth / 16
		fitFontSize = Math.floor(userRes / userTextSize / 0.0625) * 0.0625
		document.body.style.fontSize=fitFontSize+'em'
		fitHeight()
    }
}

function fitMidImg() {
	if (document.images['bckimgmid'].complete == false) {
		setTimeout("fitMidImg();",100);
	} else {
	    div = document.getElementById('bckimgmid');
	    img = document.getElementById('bckimggrow');
	    i = div.style.height.replace('px','');
	    j = img.style.height.replace('em','');
	    j = j * 16;
	    t = Math.round(i / (j+0.5)) * 1.1;
	    for(i=0; i<t; i++) {
	        plusimg = img.cloneNode(true);
	        if(i==0) div.innerHTML = '';
	        plusimg.id = plusimg.id + (i>0?i:'');
	        div.appendChild(plusimg);
	    }
	}
}

function fitHeight(center) {
	 if (document.getElementById('frtdiv').scrollHeight > 0) {
	 	document.getElementById('bckdiv').style.height = (document.getElementById('frtdiv').scrollHeight)  + 'px'
	 	newImgHeight = (document.getElementById('frtdiv').scrollHeight - document.getElementById('bckimgtop').height - document.getElementById('bckimgbot').height) 
	 } else {
	 	if (document.getElementById('frtdiv').offsetHeight) {
		 	document.getElementById('bckdiv').style.height = (document.getElementById('frtdiv').offsetHeight)  + 'px'
		 	newImgHeight = (document.getElementById('frtdiv').offsetHeight - document.getElementById('bckimgtop').height - document.getElementById('bckimgbot').height) 
	 	} else {
		 	document.getElementById('bckdiv').style.height = '100em'
			newImgHeight = 1600
	 	}
	 }
	 if (newImgHeight < 1) newImgHeight = 1
	 document.getElementById('bckimgmid').style.height = newImgHeight+'px'
	 document.getElementById('bckdiv').style.visibility = 'visible'
	 document.getElementById('poweredby').style.visibility = 'visible'
	 document.getElementById('bckimgbot').style.visibility = 'visible'
	 if((' '+document.getElementById('bckdiv').className+' ').indexOf(' bck2 ') != -1) {
	     eval('fitMidImg()');
	 }
}

function init() {		
	window.onresize=reFit
}

function getFile(n) {
  var file;
  if (n==''||n==self.location) return //[];
  switch(typeof ActiveXObject){ 
    case 'function':
      file = new ActiveXObject('Microsoft.XMLHTTP'); 
      break;

    default:  
      file = new XMLHttpRequest;  
      file.overrideMimeType("text/xml");
  }
  try{ 
    file.open('GET',n,false); 
    file.send('') 
  } catch(e) { 
    return '' 
  }
  return file.responseText;
}

function getAbsPos(elt,which) {
 iPos = 0
 while (elt != null) {
  iPos += elt["offset" + which]
  elt = elt.offsetParent
 }
 return iPos
}
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }

function zoomImage(link, width, height) {
    if(width && height) {
        window.open(link,"zoom"+Math.floor(Math.random()*11),'width='+width+',height='+height+',toolbar=no,scrollbars=no');
    } else {
        window.open(link,"zoom"+Math.floor(Math.random()*11),'toolbar=no,scrollbars=yes,resizable=yes');
    }
}

function changePre(crmid, parid, imgid, newid) {
    // i = preview image to replace
    i = parent.document.getElementById('c'+crmid+'p'+parid+'m'+imgid+'p');
    if(!i.orgSize) {
        i.orgSize = newSize = i.src.substr((i.src.lastIndexOf('/')+1+i.src.substr(i.src.lastIndexOf('/')+1,i.src.length).indexOf('.')) , 
             i.src.substr((i.src.lastIndexOf('/')+1+i.src.substr(i.src.lastIndexOf('/')+1,i.src.length).indexOf('.'))+1 , i.src.length).indexOf('.')+1);
    } else newSize = i.src.substr((i.src.lastIndexOf('/')+1+i.src.substr(i.src.lastIndexOf('/')+1,i.src.length).indexOf('.')) , 
             i.src.substr((i.src.lastIndexOf('/')+1+i.src.substr(i.src.lastIndexOf('/')+1,i.src.length).indexOf('.'))+1 , i.src.length).indexOf('.')+1);
    oldimg = i.src.substr(i.src.lastIndexOf('/')+1 , i.src.substr(i.src.lastIndexOf('/')+1,i.src.length).indexOf('.'));
    if(oldimg != newid) {
        // n = thumb image to place
	    n = parent.document.getElementById('c'+crmid+'p'+parid+'m'+newid);
	    // j = preview parent a or div
	    j = i.parentNode;
	    // 
	    if(j.nodeName.toLowerCase()=='a') {
	        a = j;
	        d = j.parentNode;
	    } else if(j.nodeName.toLowerCase()=='div') {
	        a = 0;
	        d = j;
	    } else if(j.nodeName.toLowerCase()=='strong') {
	        if(j.parentNode.nodeName.toLowerCase()=='a') {
	            a = j.parentNode;
	            d = j.parentNode.parentNode;
	        } else if(j.parentNode.nodeName.toLowerCase()=='div') {
	        	a = 0;
	        	d = j.parentNode;
	        }
	    } else {
	    	return;
	    }
	    //alert(j.nodeName)
	    // get proportions of thumb image
	    if(n.style.height && n.style.width) {
	        var thHeight = n.style.height.replace('em','');
	        var thWidth = n.style.width.replace('em','');
	        var newProportion = thWidth/thHeight;
	    }
	    if(i.style.height && i.style.width) {
	        var prHeight = i.style.height.replace('em','');
	        var prWidth = i.style.width.replace('em','');
	        var oldProportion = prWidth/prHeight;
	    }
	    
	    // to reduce the rounding differences between thumbs and originals here the difference is checked
	    // when a difference below 0.1 is measured, the original scale will be preserved.
	    if( ((newProportion > oldProportion) && (newProportion - oldProportion) < 0.1 ) 
	      || ((oldProportion > newProportion) && (oldProportion - newProportion) < 0.1 ) ) {
	        newProportion = oldProportion;
	    }
	
	    newHeight = prHeight;
	    newWidth = newHeight*newProportion;
	    // change
	    testSize = i.orgSize;
	    imgSrc = i.src.replace('/'+oldimg+newSize+'.','/'+newid+testSize+'.');
	    if(a) a.href = a.href.replace('/'+oldimg+'.','/'+newid+'.');
	    i.src = '/images/default/pix.gif';
	    i.style.width=newWidth+'em';
	    i.style.height=newHeight+'em';
	    i.src = imgSrc;
	    testImage(imgSrc, i);
    }
}

function testImage(URL, i) {
    tester=new Image();
    tester.src = URL;
    tester.onLoad = checkWidth(i, tester.width);
}

function checkWidth(i, width) {
    if(width < 80) { // should be 0 but IE7 gives strange width back
        i.src = i.src.replace(i.orgSize+'.','.');
    }
}

function getTopMargin(height) {
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") { 
            winH = window.innerHeight - height;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) { 
            if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight )) {
                winH = document.documentElement.clientHeight - height;
            } else if (document.body && ( document.body.clientWidth || document.body.clientHeight )) {
                winH = document.body.clientHeight - height;
            }
        }
    }
    topSpace =(winH / 2);
    if(topSpace > 20) {
        return topSpace;
    } else {
        return 0;
    }
}

function removeDefaultValue(id, defaultValue) {
    i = document.getElementById(id);
    if(i && i.value && i.value == defaultValue) {
        i.value = '';
        return 1;
    }
    return 0;
}

function anim(id)
{
    document.getElementById(id).src = eval('img' + id + '[counter'+id+'].src');
    eval('counter'+id+'++');    
    if(eval('counter'+id) == eval('img'+id+'.length')) {
       eval('counter'+id+' = 0'); //sets the counter value to 0
    }
}

function slide(id, delay)
{
    if(delay!=4000) {
        var temp = parseInt(delay);
        if(temp != NaN)
        delayTime = temp;
        else
        delayTime = 4000;
    } else {
        delayTime = delay;
    }
    eval('start'+id+' = setInterval("anim(\'"+id+"\')", delayTime);');
}

function changeStyleDisplay(id, to)
{
    el = document.getElementById(id);
	if(el && el.style.display) {
		el.style.display = to;
		return true;
	} else if(el) { // ook als een veld nog geen display element heeft in stijl
		el.style.display = to;
		return true;
	} else {
		return false;
	}
}