﻿function fontAdjust(doThis)
{	if(document.getElementById('contentBody'))
	{ 	contentPart = document.getElementById('contentBody');

//		actualSize = parseFloat(contentPart.style.fontSize);
//		
//		if(!actualSize) 	{ actualSize  = 1.2; }
//		if(doThis=='plus' && actualSize<1.7) 	{ newSize = actualSize + 0.2;}
//		if(doThis=='min' && actualSize>0.9) 	{ newSize = actualSize - 0.2;}
//		debugger;
//		contentPart.style.fontSize = newSize + 'em' ; 
		//debugger;
		if((fontResizeCount > 1 || doThis=='plus')&&(fontResizeCount < 15 || doThis=='min'))
		{
		    fontAdjustForChild(doThis, contentPart);
		    if(doThis=='plus' ) { fontResizeCount++; }
    		if(doThis=='min' ) 	{ fontResizeCount--; }
		}
		
	}
}

var fontResizeCount = 5;

function fontAdjustForChild(doThis, innerContent)
{	
    if(innerContent && innerContent.id != 'tools')
	{ 	
        var actualSize;
        if(BrowserDetect.browser == 'Explorer')
        {
            if(innerContent.children)
            {
                var i=0;
                for (i=0; i<innerContent.children.length; i++) 
		       {
		            fontAdjustForChild(doThis, innerContent.children[i]);
		       }
            }
        
		    actualSize = parseInt(innerContent.currentStyle.fontSize);
		    if(doThis=='plus' ) 	
		    { 
		        newSize = actualSize + 1;
		        
		    }
		    if(doThis=='min' && actualSize>1) 	
		    { 
		        newSize = actualSize - 1;
		        
		    }
    		
		    innerContent.style.fontSize = newSize + 'px' ; 
		}
		else	
		{ 
//	        if(innerContent.childNodes)
//            {
//                var i=0;
//                for (i=0; i<innerContent.childNodes.length; i++) 
//		       {
//		            fontAdjustForChild(doThis, innerContent.childNodes[i]);
//		       }
//            }
            var currentRule;
            var actualHeight;
            var currentSelectorText = '.' + innerContent.className;
	        for(j=0; j<this.document.styleSheets[0].cssRules.length; j++)
            {
                
//                if(this.document.styleSheets[0].cssRules[j].selectorText == currentSelectorText)
//                {
                    currentRule = this.document.styleSheets[0].cssRules[j];
                    actualSize = parseInt(currentRule.style.fontSize);
                    actualHeight = parseInt(currentRule.style.height);
//                }
                    
                    if(actualSize)
		            {
		                if(doThis=='plus' ) 	
		                { 
		                    newSize = actualSize + 1;
		                    
		                }
		                if(doThis=='min' && actualSize>1) 	
		                { 
		                    newSize = actualSize - 1;
		                   
		                }
                		
		                currentRule.style.fontSize = newSize + 'px' ; 
		            }
		            if(actualHeight)
		            {
		                if(doThis=='plus' ) 	
		                { 
		                    newHeight = actualHeight + 1;
		                }
		                if(doThis=='min' && actualHeight>1) 	
		                { 
		                    newHeight = actualHeight - 1;
		                }
                		
		                currentRule.style.height = newHeight + 'px' ;
		            }
            }
//		    if(actualSize)
//		    {
//		        if(doThis=='plus' ) 	{ newSize = actualSize + 1;}
//		        if(doThis=='min' && actualSize>1) 	{ newSize = actualSize - 1;}
//        		
//		        currentRule.style.fontSize = newSize + 'px' ; 
//		    }
		}
		
		
	}
}

function OpenPopup (c) 
{
window.open(c,
'window',
'width=810,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
}

function openKiaShop () 
{
	window.open('http://udstyr.kiamotors.dk/','_blank','scrollbars=yes,resizable=yes,toolbar=yes,directories=yes,location=yes,menubar=yes,status=yes,left=0,top=0');
}
/* MENU - IE6 */
//startlist = function() 
//{ 
//	if (document.all&&document.getelementbyid) 
//	{ 
//		navroot = document.getelementbyid("menu");
//		for (i=0; i<navroot.childnodes.length; i++) 
//		{
//			node = navroot.childnodes[i];
//			if (node.nodename=="li" && node.classname == "a") 
//			{
//				node.onmouseover=function() 
//				{ 
//					this.classname+=" over";
//					//if(!document.getelementbyid("experience")) hideselects("hidden");
//				}
//				node.onmouseout=function() 
//				{
//					alert('out');
//					this.classname=this.classname.replace(" over", "");
//					//if(!document.getelementbyid("experience")) hideselects("visible");

//				}
//			}
//		}
//	}
//}


function hideSelects(action) { 
	//documentation for this script at http://www.shawnolson.net/a/1198/
	//possible values for action are 'hidden' and 'visible'
	if (action!='visible'){action='hidden';}
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version<7) { 
	for (var S = 0; S < document.forms.length; S++){
	for (var R = 0; R < document.forms[S].length; R++) {
	if (document.forms[S].elements[R].options) {
	document.forms[S].elements[R].style.visibility = action;
	}
	}
	}
	}
}

function activateTab(tabId)
{	
	for(i=1;i<=4;i++)
	{  
	    if(document.getElementById('tab'+i)!=null)
	    {
	        j = document.getElementById(('tab'+i));
		    j.className=j.className.replace("active", "");	
		}
    }
	document.getElementById(('tab'+tabId)).className+=" active";

	for(i=1;i<=4;i++)
	{ 	
	    if(document.getElementById('tabContent'+i)!=null)
	    {
	        j = document.getElementById(('tabContent'+i)); 
		    j.className=j.className.replace("active", "");	
		}
    }
	document.getElementById(('tabContent'+tabId)).className+="active";
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curtop;
}

function popUp(url,posY) {
	if(url) { 
		document.getElementById('carPicture').src = url;
		display = 'block' ;
		document.getElementById('popup').style.top = posY-100+'px';
	}
	else	display = 'none';
	
	document.getElementById('popupwrapper').style.display = display ;
	document.getElementById('popup').style.display = display ;

}



function showPicture(url,imgNm,thumb) {
	
	if(imgNm != 'plain') {
		var showMedium = "occasionImage";

		if(document.all) {
		    document.images[showMedium].filters.blendTrans.apply();
		}
		
		
		document.images[showMedium].src = url;
		if(document.all) {
		    document.images[showMedium].filters.blendTrans.play();
		}

		a = document.getElementById("occasionThumbs");
		for (i=0; i<a.childNodes.length; i++) {
			node = a.childNodes[i];
			if (node.nodeName=="A") {	node.style.borderColor = '#ffffff';	}
		}
	
		thumb.style.borderColor = '#B81116';
	 	
	}
}


function BPEscape(url) {
	
	return escape(url);
}

function am() 
	{
		AMRoot = document.getElementById("allmodels");
		mh=0;
		j=0;
		for (i=0; i<AMRoot.childNodes.length; i++) {
			node = AMRoot.childNodes[i];
			if (node.className=="AMpanel") {
				if(node.offsetHeight>mh) mh = node.offsetHeight;
			}
			if (node.className=="colend") {
				for (j=j; j<i; j++) {
					node = AMRoot.childNodes[j];
					
					if(node.className=="AMpanel") node.style.height = mh + 'px';;
				}
				mh=0;
			}
		}
}

function chooseModel(modelId, hfModelId)
{
	document.getElementById('allmodels').style.display = 'none';
	document.getElementById('col1').style.display = 'block';
	document.getElementById('contentBody').style.visibility = 'visible';
	document.getElementById('content').style.backgroundImage = "url('../img/bg_hoofdnavigatie.gif')";
	hideSelects('visible');
	
	//model opslaan in HiddenField
	document.getElementById(hfModelId).value = modelId;
	// site layout opnieuw opbouwen
	setupGrid();
}

function changeModelTypeImage(imageUrl, imageId)
{
	document.getElementById(imageId).setAttribute("src", imageUrl);
}

//Browser Detect
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
