var aMetaTags = document.getElementsByTagName("meta");
for (var i = aMetaTags.length; --i >= 0;) {
	var sMetaTag = aMetaTags[i];
	if ((/base_url/i.test(sMetaTag.name)) || (/base_url/i.test(sMetaTag.id))) {
		BASE_URL = sMetaTag.content;
	} 
}

// replace sIFR koppen en stretch mainContainer div
function replaceAllSifrStuff() {
	if(typeof (sIFR) == "function") {
		sIFR.replaceElement(named({sSelector:"h1.sIFR-kop", sFlashSrc:BASE_URL + "sifr/h1_block.swf", sWmode: "transparent", sColor:"#165306", sLinkColor:"#165306", sBgColor:"#FFFFFF", /*sHoverColor:"#518000",*/ sStrongColor:"#000000", nPaddingTop:0, nPaddingBottom:0, sFlashVars:""}));
	};
	
	if(document.getElementById('userreview')){
		document.getElementById('userreview').style.visibility = 'visible';
		document.getElementById('userreview').style.display = 'none';
	}
}

window.onload = function(){
	replaceAllSifrStuff()
	stretchMainContainer();
	contentUp();
}

var aDivsToCenter = new Array();
var nNofDivs = 0;

function addDivToCenter(sObjID) {
	if (document.getElementById(sObjID)) {
		aDivsToCenter[nNofDivs] = sObjID;
		nNofDivs++;
	}else{
		alert("Program error: DIV with id '" + sObjID + "' not found (in addDivToCenter)");
	}
}

window.onresize = function(){
	if (nNofDivs > 0) {
		for(idx=0; idx < nNofDivs; idx++) {
			moveToCenter(aDivsToCenter[idx]);
		}
	}
	stretchMainContainer();
	contentUp();
}

// vraag browserhoogte op
function getBrowserHeight(){  
	var breedte = 0;
	var hoogte = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		breedte = window.innerWidth;
		hoogte = window.innerHeight;
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			breedte = document.documentElement.clientWidth;
			hoogte = document.documentElement.clientHeight;
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				breedte = document.body.clientWidth;
				hoogte = document.body.clientHeight;
			}
		}
	}
	return(hoogte);
}

// stretch mainContainer
function stretchMainContainer(){
	if(document.getElementById('mainContainer')){
		document.getElementById('mainContainer').style.height = getBrowserHeight();
	}
}

// getElementsByClassName
function getElementsByClassName(strClassName){
	var aElements = document.getElementsByTagName("*");
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var aReturnElements = new Array();
	var oElement;
	for(i=0;i<aElements.length;i++){
		oElement = aElements[i];
		if(oRegExp.test(oElement.className)){
			aReturnElements.push(oElement);
		}
	}
	return aReturnElements;
}

// toggle div
function toggleDiv(element){
	var aDivs = getElementsByClassName("hiddendiv");
	for(i=0;i<aDivs.length;i++){
		aDivs[i].style.display = 'none';
	}

	if(document.getElementById(element)){
		if(document.getElementById(element).style.display == 'block'){
			document.getElementById(element).style.display = 'none';
		} else {
			document.getElementById(element).style.display = 'block';
		}
	}
}

function showHideDiv(element){
	if(document.getElementById(element)){
		if(document.getElementById(element).style.display == 'block'){
			document.getElementById(element).style.display = 'none';
		} else {
			document.getElementById(element).style.display = 'block';
		}
	}
}

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
				 + ";expires="+expire.toGMTString() + ";domain=carafans.nl" + ";path=/";
}

function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
	if (dc.length > 0) {              
	begin = dc.indexOf(cname);       
		if (begin != -1) {           
		begin += cname.length;       
		end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		} 
	}
	return null;
}

function showHideHeaders(element,pxl){
	if(document.getElementById(element)){
		if(document.getElementById(element).style.display != 'none'){
			SetCookie(element,'nee',10958);
			document.getElementById(element).style.display = 'none';
			pxl.src= BASE_URL + 'Images/plus.gif';
		} else {
			SetCookie(element,'ja',10958);
			document.getElementById(element).style.display = 'block';
			pxl.src= BASE_URL + 'Images/minus.gif';
		}
	} else {
		alert('Element not found');
	}
}

function showDiv(element){
	if(document.getElementById(element)){
		if(document.getElementById(element).style.visibility == 'hidden'){
			document.getElementById(element).style.visibility = 'visible';
		}
	}
}

function showHideTr(elements,element){
	if(document.getElementById(element)){
		if(document.getElementById(element).style.display == 'block'){
			document.motoraanbieden.Register.value = 'Ik ben al lid';
			document.motoraanbieden.nieuwlid.value = '1';
			document.getElementById(element).style.display = 'none';
			var aTr = getElementsByClassName(elements);
			for(i=0;i<aTr.length;i++){
				aTr[i].style.display = 'block';
			}
		} else {
			document.motoraanbieden.Register.value = 'Nog geen lid?';
			document.motoraanbieden.nieuwlid.value = '0';
			document.getElementById(element).style.display = 'block';
			var aTr = getElementsByClassName(elements);
			for(i=0;i<aTr.length;i++){
				aTr[i].style.display = 'none';
			}
		}
	}
}

function getHeight(objectid) {
	var object = (document.getElementById) ? document.getElementById(objectid) : document.all[objectid];
	if (object) {
		if (object.clientHeight) {
			return parseInt(object.clientHeight);
		}else if (window.getComputedStyle(object,null).getPropertyValue('height')) {
			return parseInt(window.getComputedStyle(object,null).getPropertyValue('height'));
		}else{
			return 0;
		}
	}
}

function getWidth(objectid) {
	var object = (document.getElementById) ? document.getElementById(objectid) : document.all[objectid];
	if (object) {
		if (object.clientWidth) {
			return parseInt(object.clientWidth);
		}else if (window.getComputedStyle(object,null).getPropertyValue('width')) {
			return parseInt(window.getComputedStyle(object,null).getPropertyValue('width'));
		}else{
			return 0;
		}
	}
}

function getWindowWidth() {
	var y;
	if (self.innerWidth) { // all except Explorer
		y = self.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		y = document.documentElement.clientWidth;
	}else if (document.body) { // other Explorers
		y = document.body.clientWidth;
	}
	return y;
}

function getWindowHeight() {
	var y;
	if (self.innerHeight) { // all except Explorer
		y = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
	}else if (document.body) { // other Explorers
		y = document.body.clientHeight;
	}
	return y;
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function moveToCenter(sObjID) {
	oTag = document.getElementById(sObjID);
	nWindowWidth = getWindowWidth();
	if (oTag && nWindowWidth && oTag.offsetWidth) {
		oTag.style.left = Math.floor((nWindowWidth - oTag.offsetWidth) / 2) + 'px';
	}

	aScrollXY = getScrollXY();

	nWindowHeight = getWindowHeight();
	if (oTag && nWindowHeight && oTag.offsetHeight) {
		nScrollTop =  + parseInt(aScrollXY[1], 10) + Math.floor((nWindowHeight - oTag.offsetHeight) / 2);
		oTag.style.top = nScrollTop + 'px';
	}
}

function resizeWindow(objid) {
	var height = getHeight(objid);
	var width = getWidth(objid);
	var win_height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	var win_width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;

	if (window.navigator.appName == "Netscape") win_height -= 50;

	if (height < 50) height = 50;
	else if (height > 700) height = 700;
	if (width < 200) width = 200;
	else if (width > 900) width = 900;
	self.resizeBy(width - win_width, height - win_height);
	self.focus();
}

function checkToClear(element, value){
	if(element.value == value){
		element.value = '';
	} // if
} // function checkToClear

function checkToRestore(element, value){
	if(element.value == ''){
		element.value = value;
	} // if
} // function checkToRestore

function checkNieuwsbrief(){
	var oForm = document.black_nieuwsbrief;	
	if (oForm.email_nieuwsbrief.value == "") {
		alert("Voer een e-mailadres in, als u zich wilt aanmelden voor CaraFans nieuwsbrief.");
		return false ;
	}
		
	// Controleer of het e-mailadres wel geldig is (minimaal: a@b.c)
	if (oForm.email_nieuwsbrief.value.search(/^[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+@[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+\.[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+$/) == -1) {
		alert("Het ingevulde e-mail adres is niet geldig");
		return false ;
	}
	
	return true ;		
}
	

function resetform(oForm){
	oForm.Merk.selectedIndex = 0;
	oForm.Categorie.selectedIndex = 0;
	oForm.Type.value = "";
	oForm.Provincie.selectedIndex = 0;
	oForm.BouwjaarVAN.selectedIndex = 0;
	oForm.BouwjaarTOT.selectedIndex = 0;
	oForm.PrijsVAN.selectedIndex = 0;
	oForm.PrijsTOT.selectedIndex = 0;
	var iBegin = 1900;	
	var d = new Date();	
	
	// bouwjaar vanaf opnieuw vullen
	var iTeller = 1;
	document.getElementById('select4').options.length = 0;
	document.getElementById('select4').options[0] = new Option('-- Vanaf bouwjaar --','');
	for(var i = iBegin; i <= d.getFullYear(); i++){
		document.getElementById('select4').options[iTeller] = new Option(i, i);
		iTeller++;
	}
	
	// bouwjaar tot opnieuw vullen
	var iTeller = 1;
	document.getElementById('select5').options.length = 0;
	document.getElementById('select5').options[0] = new Option('-- Tot bouwjaar --','');
	for(var i = iBegin; i <= d.getFullYear(); i++){
		document.getElementById('select5').options[iTeller] = new Option(i, i);
		iTeller++;
	}
	
	// prijs vanaf opnieuw vullen
	document.getElementById('FormsComboBox3').options.length = 0;	
	var iTeller = 1;
	var iBegin = 1000;		
	document.getElementById('FormsComboBox3').options[0] = new Option('Geen voorkeur','');
	for(var i = iBegin; i <= 30000; i=i+1000){
		document.getElementById('FormsComboBox3').options[iTeller] = new Option(String.fromCharCode(0x20ac) + ' ' + i, i);
		iTeller++;
	}
	document.getElementById('FormsComboBox4').options[iTeller] = new Option(String.fromCharCode(0x20ac) + ' 100000', '100000');
	
	// prijs tot opnieuw vullen
	document.getElementById('FormsComboBox4').options.length = 0;	
	var iTeller = 1;
	var iBegin = 1000;		
	document.getElementById('FormsComboBox4').options[0] = new Option('Geen voorkeur','');
	for(var i = iBegin; i <= 30000; i=i+1000){
		document.getElementById('FormsComboBox4').options[iTeller] = new Option(String.fromCharCode(0x20ac) + ' ' + i, i);
		iTeller++;
	}
	document.getElementById('FormsComboBox4').options[iTeller] = new Option(String.fromCharCode(0x20ac) + ' 100000', '100000');
}


function Whois(ID) {
	url = BASE_URL + 'Content/CaraForum/Whois.cfm?MemID='+ID;
	ww = window.open(url, 'mw', 'toolbar=no,location=no,menubar=no,scrollbars=yes,width=650,height=660,left=100,top=5,resizeable=no,status=no');
}

function crop(widthmax){ 
	var x = document.images;
	for (var i=0;i<x.length;i++){
		if (x[i].className != "nocrop") {
			var height = parseInt(x[i].height);
			var width = parseInt(x[i].width);
	
			if (width  > widthmax){
				newwidth 	= widthmax-5;
				newheight 	= Math.round(widthmax * (height / width));
		
				x[i].width  = newwidth;
				x[i].height = newheight+2;
			}
		}
	}
}

function fCropImage(sImage, iWidthMax){ 
	if (sImage.className != "nocrop") {
		var iHeight = parseInt(sImage.height);
		var iWidth = parseInt(sImage.width);

		if (iWidth  > iWidthMax){
			iNewWidth 	= iWidthMax-5;
			iNewHeight 	= Math.round(iWidthMax * (iHeight / iWidth));
			sImage.width  = iNewWidth;
			sImage.height = iNewHeight+2;
		}
	}
}

function DeleteMessages(){
	return confirm('Weet u zeker u dit wilt verwijderen?');
}

function SetAbbo(){
	return confirm('ABONNEREN\n\nMet deze functie abonneert u zich op dit bericht.\nZodra iemand reageert ontvangt u deze reactie (geheel vrijblijvend) per email.\nZodoende kunt u de discussie over dit onderwerp goed volgen.\n\nU kunt ten alle tijden het abonnement weer stopzetten.\n\nWilt u zich abonneren op dit bericht?');
}

function ResetAbbo(){
	return confirm('ABONNEMENT STOPZETTEN\n\nMet deze functie zet u uw abonnement op dit bericht stop.\nHierna zult u geen reacties van andere bezoekers op dit bericht meer ontvangen.\n\nWilt u uw abonnement stopzetten?');
}

function toonRoute(startPostcode, eindPostcode, straat, plaats, naam) {
	window.open('toonroute.cfm?startpostcode='+startPostcode+'&eindpostcode='+eindPostcode+'&straat='+straat+'&plaats='+plaats+'&naam='+naam, 'windowlocatienet');
}

function hideTempBlock(weg){
	oWeg = document.getElementById(weg);
	if(oWeg){
		if (oWeg.style.display == 'none'){
			oWeg.style.display = 'block';
			moveToCenter(weg);
		} else {					
		// Hide de popup
			oWeg.style.display = 'none';		
		}
	} 		
}

function popupwindow(url){
	var h = 600;
	var w = 750;
	var x = (screen.width/2)  - (w/2);
	var y = (screen.height/2) - (h/2);
	window.open(url, '', 'resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no,location=no,width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + '')
}    

function motordreams(id){
	url = 'http://www.ovis.nl/partners/caravandreams.nl/fiche.php?id=' + id;
	var mdw;
	mdw = window.open(url,'motordreams', 'height=600,width=800,status=yes,toolbar=yes,menubar=yes,location=yes,top=20,left=20,resizable=yes');
	mdw.focus();
}
