if (typeof vcc != "object")
	vcc = new Object();

vcc.userAgent = navigator.userAgent.toLowerCase();
vcc.win = (vcc.userAgent.indexOf("win") > -1);
vcc.mac = (vcc.userAgent.indexOf("mac") > -1);
vcc.ie = (vcc.userAgent.indexOf("msie") > -1);
vcc.w3c = (document.getElementById && !vcc.ie);
vcc.opera = (vcc.userAgent.indexOf("opera") > -1);
vcc.safari = (vcc.userAgent.indexOf("safari") > -1);
vcc.ns6 = (vcc.userAgent.indexOf("netscape6") > -1);
vcc.version = (vcc.ie) ? parseFloat(navigator.appVersion.match(/MSIE\s(\d+\.\d+)/)[1]) : null;

vcc.getObj = function(strLayer) {
	if(typeof(strLayer) == "object") return strLayer;
	var elmLayer = document.getElementById(strLayer);
	if (!elmLayer)
		elmLayer = document.getElementsByName(strLayer)[0];
	return elmLayer;
}

vcc.show = function() {
	for (var i=0; i<vcc.show.arguments.length; i++) {
		if ((elmLayer=vcc.getObj(vcc.show.arguments[i])))
			elmLayer.style.visibility = "visible";
	}
}

vcc.hide = function() {
	for (var i=0; i<vcc.hide.arguments.length; i++) {
		if ((elmLayer=vcc.getObj(vcc.hide.arguments[i])))
			elmLayer.style.visibility = "hidden";
	}
}

vcc.setDisplay = function(strLayer,strValue) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	elmLayer.style.display = strValue;
}

vcc.getX = function(strLayer,blnGlobal) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	var currentX = elmLayer.offsetLeft;
	if (blnGlobal) {
		while (elmLayer.offsetParent) {
			elmLayer = elmLayer.offsetParent;
			currentX += elmLayer.offsetLeft;
		}
	}
	return currentX;
}

vcc.getY = function(strLayer,blnGlobal) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	var currentY = elmLayer.offsetTop;
	if (blnGlobal) {
		while (elmLayer.offsetParent) {
			elmLayer = elmLayer.offsetParent;
			currentY += elmLayer.offsetTop;
		}
	}
	return currentY;
}

vcc.getW = function(strLayer) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	if (window.getComputedStyle) {
		var style=getComputedStyle(elmLayer, null);
		return parseInt(style.getPropertyValue('width'));
	}
	else if (elmLayer.style.pixelWidth)
		return elmLayer.style.pixelWidth;
	else if(elmLayer.offsetWidth)
		return elmLayer.offsetWidth;
}

vcc.getH = function(strLayer) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	if (window.getComputedStyle) {
		var style=getComputedStyle(elmLayer, null);
		return parseInt(style.getPropertyValue('height'));
	}
	else if (elmLayer.style.pixelHeight)
		return elmLayer.style.pixelHeight;
	else if(elmLayer.offsetHeight)
		return elmLayer.offsetHeight;
}

/*
vcc.getScrollW = function(strLayer) {
	if (!(elmLayer=vcc.getObj(strLayer))) return false;
	if (vcc.ie)
		return (vcc.mac) ? elmLayer.offsetWidth : elmLayer.scrollWidth;
	else if(vcc.w3c)
		return elmLayer.offsetWidth;
}*/

vcc.moveTo = function(strLayer, x, y, bRight) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	if (bRight) {
		if (x || x==0) elmLayer.style.right = x + "px";
	} 
	else {
		if (x || x==0) elmLayer.style.left = x + "px";
	}
	if (y || y==0) elmLayer.style.top = y + "px";
}

vcc.moveBy = function(strLayer, x, y, bRight) {
	vcc.moveTo(strLayer, vcc.getX(strLayer) + x, vcc.getY(strLayer) + y, bRight);
}

vcc.clip = function(strLayer,t,r,b,l) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	elmLayer.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}

/*
vcc.clipBy = function(strLayer,dt,dr,db,dl){
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	var c=elmLayer.currentStyle.clip.substr(5);
	c=c.substr(0,c.length-3).split("p");
	c[1] = c[1].substr(2);
	c[2] = c[2].substr(2);
	c[3] = c[3].substr(2);
	var t=dt+(c[0]*1);
	var r=dr+(c[1]*1)+dl;
	var b=db+(c[2]*1)+dt;
	var l=dl+(c[3]*1);
	elmLayer.style.clip="rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}*/

vcc.preload = function(strName, strSrc, blnDoNotPreload) {
	if(blnDoNotPreload) eval(strName + " = new Object();");
	else eval(strName + " = new Image();");
	eval(strName+".src = '"+strSrc+"';");
}

/*
vcc.swapImage = function(strTarget, strNewPic, urlNewPic){
	var objImage=vcc.getObj(strTarget);
	if(objImage){
		if(strNewPic && eval("typeof(" + strNewPic +  ")") == "object")
			objImage.src=eval(strNewPic+".src");
		else if (urlNewPic)
			objImage.src = urlNewPic;
	}
}*/

vcc.setOpacity = function(strLayer, intValue) {
	if (!(objLayer=vcc.getObj(strLayer)))
		return false;
	if (vcc.ie)
		objLayer.style.filter = "alpha(opacity=" + intValue + ")";
	else if (vcc.w3c) {
		objLayer.style.MozOpacity = intValue/100;
	}
}

vcc.getDocumentWidth = function(blnContent) {
	var w;
	if (window.innerWidth) // Mozilla
		w = (blnContent) ? document.documentElement.offsetWidth : window.innerWidth
	else { // IE
		if (document.compatMode && document.compatMode != "BackCompat")
			w = (blnContent) ? document.documentElement.scrollWidth : document.documentElement.clientWidth;
		else
			w = (blnContent) ? document.body.scrollWidth : document.body.clientWidth;
	}
	return w;
}

vcc.getDocumentHeight = function(blnContent) {
	var h;
	if (window.innerHeight) // Mozilla
		h = (blnContent) ? document.documentElement.offsetHeight : window.innerHeight;
	else { // IE
		if (document.compatMode && document.compatMode != "BackCompat")
			h = (blnContent) ? document.documentElement.scrollHeight : document.documentElement.clientHeight;
		else
			h = (blnContent) ? document.body.scrollHeight : document.body.clientHeight;
	}
	return h;
}

vcc.addEvent = function(strLayer, strEvent, strFunction, bRemove) {
	if (!(elmLayer=vcc.getObj(strLayer)))
		return false;
	if (bRemove) {
		if (elmLayer.removeEventListener) {
			elmLayer.removeEventListener(strEvent, eval(strFunction), false);
		} else if (elmLayer.detachEvent) {
			elmLayer.detachEvent("on" + strEvent, eval(strFunction));
		}
	}
	else {
		if (elmLayer.addEventListener) {
			elmLayer.addEventListener(strEvent, eval(strFunction), false);
		} else if (elmLayer.attachEvent) {
			elmLayer.attachEvent("on" + strEvent, eval(strFunction));
		} else { // For browsers that don't have any of the addEventListener or attachEvent methods, we create a attachEvent method (NN4.x and IE 5.x on Mac)
			if (!eval("elmLayer.addedEventFunctions_" + strEvent))
				eval("elmLayer.addedEventFunctions_" + strEvent + " = ''");
			eval("elmLayer.addedEventFunctions_" + strEvent + " += '" + strFunction + "(); '");
			eval("elmLayer.on" + strEvent + " = new Function('" + eval("elmLayer.addedEventFunctions_" + strEvent) + "')");
		}
	}
}

vcc.getElementsByAttribute = function (strAttribute, strSearchValue, elmLayer, strTagName, bParentAxis, bPartialMatch) {
	strTagName = strTagName || "*";
	elmLayer = vcc.getObj(elmLayer) || document;
	var arElements = [];	
	if (bParentAxis) {
		// Look for parents
		while ((elmLayer = elmLayer.parentNode)) {
			var sAttrValue = elmLayer.getAttribute(strAttribute);
			if ((!strTagName || elmLayer.nodeName == strTagName) && 
				((strAttribute == "class" && (elmLayer.className == strSearchValue || (bPartialMatch && elmLayer.className.indexOf(strSearchValue) > -1))) ||
				(strSearchValue && (elmLayer.getAttribute(strAttribute) == strSearchValue || (bPartialMatch && sAttrValue && sAttrValue.indexOf(strSearchValue) > -1))) || 
				(!strSearchValue && sAttrValue))) {
					arElements.push(elmLayer);
			}
		}
	}
	else {
		// Look for children
		var arAllElements = elmLayer.getElementsByTagName(strTagName);
		var arElements = [];
		for (var i=0; i<arAllElements.length; i++) {
			var sAttrValue = arAllElements[i].getAttribute(strAttribute);
			if ((strAttribute == "class" && (arAllElements[i].className == strSearchValue || (bPartialMatch && arAllElements[i].className.indexOf(strSearchValue) > -1))) || 
				(strSearchValue && (sAttrValue == strSearchValue || (sAttrValue && sAttrValue.indexOf(strSearchValue) > -1))) ||
				(!strSearchValue && sAttrValue)) {
					arElements.push(arAllElements[i]);
			}
		}
	}
	return arElements.slice(0);
}

vcc.elementGetElementsByName = function (strName, strTagName, elmLayer) {
	strTagName = strTagName || "*";
	elmLayer = elmLayer || document;
	var arAllElements = elmLayer.getElementsByTagName(strTagName);
	var arElements = [];
	for (var i=0; i<arAllElements.length; i++) {
		if (arAllElements[i].name == strName)
			arElements[arElements.length] = arAllElements[i];
	}
	return arElements.slice(0);
}

vcc.openWindow = function(strURL,strName,strOptions,bDoNotReturnWindow) {
	if (!strOptions) strOptions = "location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,";
	else {
		//parse the strOptions variable to get width and height
		var arWidth = strOptions.match(/width=[0-9]+/i);
		var arHeight = strOptions.match(/height=[0-9]+/i);
		if (arWidth != null) {
			//Center window horizontally
			var intWidth = arWidth[0].substring(arWidth[0].lastIndexOf("=") + 1);
			var x = (screen.width - intWidth) / 2;
			x = (x<0) ? 0 : x
			strOptions += ",left=" + x;
		}
		if (arHeight != null) {
			//Center window vertically
			var intHeight = arHeight[0].substring(arHeight[0].lastIndexOf("=") + 1);
			var y = (screen.height - intHeight) / 2;
			y = (y<0) ? 0 : y
			strOptions += ",top=" + y;
		}
	}
	var popup = window.open(strURL,strName,strOptions);
	if (!bDoNotReturnWindow)
		return popup;
}

vcc.getQS = function(strWhich){
	var re = new RegExp( "[&\?]"+strWhich+"=([^&]*)&?", "i" );
	re.exec(window.location.href);
	return RegExp.$1;
}

vcc.setCookie = function(strName, strValue, objExpires, strPath) {
	var strCookie = strName + "=" + escape(strValue)
	if(objExpires) strCookie += ";expires=" + objExpires.toGMTString()
	if(strPath) strCookie += ";path=" + strPath
	document.cookie = strCookie
}

vcc.getCookie = function(strName) {
	var t=document.cookie.match(new RegExp(strName + "=([^;]*)"))
	return (t)?unescape(t[1]):t
}

vcc.delCookie = function(strName) {
	if (vcc.getCookie(strName)) document.cookie = strName + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
}

if(!Array.prototype.push || [0].push(true)==true) {
	Array.prototype.push = function() {
		for(var i=0;i<arguments.length;i++){
			this[this.length]=arguments[i]
		};
		return this.length;
	}
}

String.prototype.trim = function(blnLeft, blnRight) {
	if(blnLeft) return this.replace(/^\s*/,'')
	else if(blnRight) return this.replace(/\s*$/,'')
	else return this.match(/^\s*([^\s]*)\s*$/)[1]
}

/// <summary>
/// Returns the first parent element with the specified nodeName
/// </summary>
/// <param name="strLayer">Id of the element whose parent you want to find.</param>
/// <param name="strParentNodeName">Name of the parent node.</param>
/// <param name="iDepth">Integer specifying number of levels to iterate before "giving up". Optional, default:15</param>
/// <returns>A HTML element</returns>
vcc.getParentNode = function(strLayer, strParentNodeName, iDepth) {
	var elmLayer = vcc.getObj(strLayer);
	if (!elmLayer)
		return;
	iDepth = iDepth || 15;
	elmTmpParent = elmLayer.parentNode;
	if (!elmTmpParent)
		return;
	for (var i=0; i<iDepth; i++) {
		if (elmTmpParent.nodeName == strParentNodeName.toUpperCase())
			return elmTmpParent;
		else
			elmTmpParent = elmTmpParent.parentNode;
	}
	return false;
}

/// <summary>
/// Searches through the document for an element with an id that contains a certian string. If there is a hit, the element is returned.
/// </summary>
/// <param name="strId">The partial id that should be used for the search</param>
/// <param name="strNodeName">If specified, only elements with this nodename is searched. (optional)</param>
/// <returns>An element.</returns>
vcc.getElementByIdFragment = function (strId, strNodeName) {
	strNodeName = strNodeName || "*";
	var arElements = document.getElementsByTagName(strNodeName);
	for (var i=0; i<arElements.length; i++) {
		if (arElements[i].id && arElements[i].id.indexOf(strId) > -1)
			return(arElements[i]);
	}
	return null;
}

vcc.printPage = function(objTargetFrame){
	if(window.print || (vcc.ie && vcc.win)){
		if(!objTargetFrame){
			if(window.print) window.print()
			else if(vcc.ie && !vcc.mac) vbPrintPage()
		}
		else{
			if(window.print && vcc.ie){
				objTargetFrame.focus()
				window.print()
			} 
			else if(window.print) objTargetFrame.print()
			else if(vcc.ie && !vcc.mac){
				objTargetFrame.focus()
				setTimeout("vbPrintPage()", 100)
			} 
		}
	}
}

if(vcc.ie && !window.print && !vcc.mac){
	with(document){
		writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>')
		writeln('<' + 'SCRIPT LANGUAGE="VBScript">')
		writeln('Sub window_onunload')
		writeln('  On Error Resume Next')
		writeln('  Set WB = nothing')
		writeln('End Sub')
		writeln('Sub vbPrintPage')
		writeln('  On Error Resume Next')
		writeln('  WB.ExecWB 6, 1')
		writeln('End Sub')
		writeln('<' + '/SCRIPT>')
	}
}

vcc.fixIePng = function() {
	if (vcc.ie && vcc.win && vcc.version > 5 && vcc.version < 7) {
		//Images
		for(var i=0; i<document.images.length; i++) {
			var oImg = document.images[i];
			var sUrl = oImg.src.toLowerCase();
			if (sUrl.substring(sUrl.length-3, sUrl.length) == "png") {
				var w = oImg.width;
				var h = oImg.height;
				oImg.src = "/Volvocars.web.sites/Images/1x1.gif";
				oImg.style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sUrl + "', sizingMethod='scale')";
			}
		}
		// Background-images
		if (vcc.pngBgsToFix) {
			var arAll = document.getElementsByTagName("*");
			for (var i=0; i<arAll.length; i++) {
				if (arAll[i] && arAll[i].currentStyle && arAll[i].currentStyle.backgroundImage && arAll[i].currentStyle.backgroundImage.indexOf("url(") > -1) {
					var sUrl = arAll[i].currentStyle.backgroundImage.substring(5, arAll[i].currentStyle.backgroundImage.length - 2);
					if (sUrl.substring(sUrl.length-3, sUrl.length) == "png") {
						for (var j=0; j<vcc.pngBgsToFix.length; j++) {
							if (sUrl.indexOf(vcc.pngBgsToFix[j]) > -1) {
								arAll[i].style.backgroundImage = "none";
								arAll[i].style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sUrl + "', sizingMethod='scale')";
							}
						}
					}
				}
			}
		}
	}
}

vcc.getStyle = function (strLayer, sStyle) {
	if (!(elmLayer=vcc.getObj(strLayer))) return false;
	if (elmLayer.currentStyle)
		return elmLayer.currentStyle[sStyle];
	else if (document.defaultView && document.defaultView.getComputedStyle) {
		var oCss = document.defaultView.getComputedStyle(elmLayer, "");
		if (oCss)
			return document.defaultView.getComputedStyle(elmLayer, "").getPropertyValue(sStyle);
	}
	else if (window.getComputedStyle)
		return getComputedStyle(elmLayer, "").getPropertyValue(sStyle);
	else if (elmLayer.style)
		return elmLayer.style[sStyle];
}

vcc.getDocScroll = function() {
	if (typeof window.pageXOffset != "undefined")
		return {x:window.pageXOffset, y:window.pageYOffset}
	else if (typeof window.scrollX != "undefined")
		return {x:window.scrollX, y:window.scrollY};
	else if (vcc.ie) {
		if (document.compatMode && document.compatMode == "CSS1Compat")
			return {x:document.body.parentNode.scrollLeft, y:document.body.parentNode.scrollTop};
		else
			return {x:document.body.scrollLeft, y:document.body.scrollTop};
	}
	return {x:0, y:0};
}

vcc.addCssRule = function(sSelector, sProperty) {
	if (!(vcc.ie && vcc.win)) {
		var arStyles = document.getElementsByTagName("style");
		if (arStyles && arStyles.length > 0 && document.createTextNode) {
			var oLastStyle = arStyles[arStyles.length - 1];
			var oRule = document.createTextNode(sSelector + " {" + sProperty + ";}");
			oLastStyle.appendChild(oRule);
		}
	}
	else if (document.styleSheets && document.styleSheets.length > 0) {
		var oLastStyle = document.styleSheets[document.styleSheets.length - 1];
		if (typeof oLastStyle.addRule == "object"){
			oLastStyle.addRule(sSelector, sProperty);
		}
	}
}

if (vcc.getQS("showerrors") == "true")
	vcc.setCookie("showerrors", "true", null, "/");
else if (vcc.getQS("showerrors") == "false")
	vcc.setCookie("showerrors", "false", null, "/");

vcc.showError = function(sError) {
	if (vcc.getCookie("showerrors") == "true" || vcc.getObj("controlpanel")) {
		var elmErrors = vcc.getObj("errors");
		if (!elmErrors) {
			elmErrors = document.createElement("div");
			document.body.appendChild(elmErrors);
			elmErrors.id = "errors";
			vcc.iErrors = 0;
		}
		elmErrors.innerHTML = "#" + vcc.iErrors + " " + sError + "<br/><br/>" + elmErrors.innerHTML;
		elmErrors.style.display = "block";
		vcc.setOpacity(elmErrors, 80);
		vcc.iErrors++;
	}
}

vcc.showBrowserTooOld = function(sLoadingDiv, sBrowserTooOld) {
	vcc.hide(sLoadingDiv);
	var elmOld = vcc.getObj("browserTooOld");
	elmOld.innerHTML = sBrowserTooOld;
	elmOld.style.display = "block";
}





// This function now calls a wrapper function (vcc.trackEvent) instead of the supplied statistics function directly (dcsMultiTrack). This is because there are bugs in the externalinterface class (in IE at least) when sending empty strings as parameters.
vcc.trackEvent = function(sUrl, sTitle, sGroup, sSubGroup) {
	if (typeof dcsMultiTrack == "function") {
		sUrl = (sUrl == "[null]") ? "" : sUrl;
		sTitle = (sTitle == "[null]") ? "" : sTitle;
		sGroup = (sGroup == "[null]") ? "" : sGroup;
		sSubGroup = (sSubGroup == "[null]") ? "" : sSubGroup;
		dcsMultiTrack('DCS.dcsuri', sUrl, 'WT.ti', sTitle, 'WT.cg_n', sGroup, 'WT.cg_s', sSubGroup);
	}
}

// Browsercheck
var oBrowserCookie = vcc.getCookie("browserchecked"); 
if ((!document.getElementById || vcc.ns6) && (!oBrowserCookie || oBrowserCookie.length < 1)) {
	vcc.setCookie("browserchecked", "true", null, "/");
	location.href = "/oldbrowser.htm";
}

