//Browserhandling (needed)
function cm_bwcheck(){
this.ver=navigator.appVersion
this.agent=navigator.userAgent.toLowerCase()
this.dom=document.getElementById?1:0
this.ns4=(!this.dom && document.layers)?1:0;
this.op=window.opera
this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
this.ie=this.agent.indexOf("msie")>-1 && !this.op
if(this.op)
{
	this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
	this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
	this.op7=this.dom&&!this.op5&&!this.op6
}
else if(this.moz) this.ns6 = 1
else if(this.ie)
{
	this.ie4 = !this.dom && document.all
	this.ie5 = (this.agent.indexOf("msie 5")>-1)
	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
}
this.mac=(this.agent.indexOf("mac")>-1)
this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
this.usedom= this.ns6||this.op7
this.reuse = this.ie||this.op7||this.usedom
this.px=this.dom&&!this.op5?"px":""
return this
}

var bw=new cm_bwcheck()

//Message (needed)
function cm_message(txt){alert(txt); return false}

//Pagesize (needed)
function cm_page(frame){
if(!frame) frame = self
this.x=0; this.x2 =(!bw.ie)?frame.innerWidth:frame.document.body.offsetWidth-20;
this.y=0; this.orgy=this.y2= (!bw.ie)?frame.innerHeight:frame.document.body.offsetHeight-6;
this.x50=this.x2/2; this.y50=this.y2/2; return this
}
/*-iklein1 20.01.2006-----------------------------------------------------------------------*/
/*-new flash detection----------------------------------------------------------------------*/
// Globals
// Major version of Flash required
var requiredMajorVersion = 7; 
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// Detect Client Browser type
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;

var browser = navigator.userAgent.toLowerCase();
if ( browser.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && browser.indexOf("win")!= -1 && browser.indexOf("16bit")== -1 ) {
	document.write('<scr' + 'ipt language="VBScript"\> \n');
	document.write('Function VBGetSwfVer(i) \n');
	document.write('	on error resume next \n');
	document.write('	Dim swControl, swVersion \n');
	document.write('	swVersion = 0 \n');
	document.write('	set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i)) \n');
	document.write('	if (IsObject(swControl)) then \n');
	document.write('		swVersion = swControl.GetVariable("$version") \n');
	document.write('	end if \n');
	document.write('	VBGetSwfVer = swVersion \n');
	document.write('End Function \n');
	document.write('</scr' + 'ipt\> \n');
}

// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ){
				tempArrayMinor = descArray[3].split("r");
			} else{
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else{
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		flashVer = -1;
	}
	return flashVer;
} 
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i = 25; i > 0; i--){	
		if (isIE && isWin && !isOpera){
			versionStr = VBGetSwfVer(i);
		}
		else{
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ){ 
			return false;
		}
		else if (versionStr != 0){
			if(isIE && isWin && !isOpera){
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			}
			else{
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ((versionMajor > reqMajorVer) && (versionNum >= reqVer)){
				return true;
			}
			else{
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
}
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if (lib_getcookie('X40UI') == 1 && location.href.indexOf("accessibility") == -1 && location.href.indexOf("noFlash") == -1 ){
	if (!hasReqestedVersion){
//		arrTemp = location.pathname.split("/");
//		window.location.href = '/' + arrTemp[1] + '/' + arrTemp[2] + '/_misc' + '/noFlash_adv.asp?page=' + location.pathname;
		window.location.href = '/noFlash.asp?page=' + location.pathname;
	}
}
//------------------------------------------------------------------------------------------

//Cookiehandling (needed)
function lib_getcookieval (offset){
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}


//Get Cookie (needed)
function lib_getcookie (name){
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return lib_getcookieval (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0)
	break;
}
return null;
}

//Set Cookie (needed)
function lib_setcookie (name, value){
var argv = lib_setcookie.arguments;
var argc = lib_setcookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// Set expiration date to a year from now.
var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365));

//Create a Pop-Up (Improved version for NS4.7)
function open_function(url,width,height,options){
var open_function_page = new cm_page();
var sreferrer_url = url;
var sreferrer_cookie = lib_getcookie('sReferrer');
var separator = '';

// replace by cookie or default value if sreferrer={$} is found in url
// flag in Redirect template controls whether this is written to url 
if(url.indexOf("sreferrer")>-1)
{
	if (sreferrer_cookie == '' || sreferrer_cookie == null){
		if(document.location.href.indexOf("jaguar")>-1 || document.location.href.indexOf("nib00104")>-1)
			sreferrer_cookie = 'I_JAGUARGSR_REDIRECT_2004';
		else
			sreferrer_cookie = 'I_LANDROVERGWS_REDIRECT_2004';
	}
	
	sreferrer_url = sreferrer_url.replace(/sreferrer%3D/gi,"sReferrer=");
	sreferrer_url = sreferrer_url.replace(/sreferrer=/gi,"sReferrer=");
	sreferrer_url = sreferrer_url.replace(/%7B%24%7D/gi,sreferrer_cookie);
	sreferrer_url = sreferrer_url.replace(/\{\$\}/gi,sreferrer_cookie);
}

if(options.substring(0,1) != ',') separator = ',';
self.msgWindow = open(sreferrer_url,"blank","width=" + width + ",height=" + height
+ ",dependent=yes"
+ ",left=" + (open_function_page.x2-width)/2
+ ",top=" + (open_function_page.y2-height)/2
+ separator + options
);
self.msgWindow.focus();
if (self.msgWindow.opener == null) self.msgWindow.opener = self;
}

//Change to a new Window
function open_site(x){
	var sreferrer_cookie = lib_getcookie('sReferrer');
	if(x == ""){
		return;
	}else{
		// replace by cookie or default value if sreferrer={$} is found in url
		// flag in Redirect template controls whether this is written to url 
		if(x.indexOf("sreferrer")>-1)
		{
			if (sreferrer_cookie == '' || sreferrer_cookie == null){
				if(document.location.href.indexOf("jaguar")>-1 || document.location.href.indexOf("nib00104")>-1)
					sreferrer_cookie = 'I_JAGUARGSR_REDIRECT_2004';
				else
					sreferrer_cookie = 'I_LANDROVERGWS_REDIRECT_2004';
			}
			
			x = x.replace(/sreferrer%3D/gi,"sReferrer=");
			x = x.replace(/sreferrer=/gi,"sReferrer=");
			x = x.replace(/%7B%24%7D/gi,sreferrer_cookie);
			x = x.replace(/\{\$\}/gi,sreferrer_cookie);
		}
		window.location.href = x;
	}
}

var popEnlarge
function OpenEnlargeImagePopup(popupurl,imagesrc,windowwidth,windowheight,imagealt)
{
	// split image URL into main part without dimension appendix and extension
	var imageURLmain
	if(imagesrc.lastIndexOf("_") == imagesrc.indexOf("_"))
	{imageURLmain = imagesrc.substring(0,imagesrc.length-4);}
	else
	{imageURLmain = imagesrc.substring(0,imagesrc.lastIndexOf("_"));}
	var imageURLext  = imagesrc.substring(imagesrc.length-4,imagesrc.length);
	
	// always set width to 670 for LR and 669 for JAG, SB, 26.10.2004, CR 189
	var popWidth = 0;
	var popHeight= 0;
	if(document.location.href.indexOf("jaguar")>-1 || document.location.href.indexOf("nib00104")>-1)
		{popWidth = 669;}
	else
		{popWidth = 670;}

	// parameters are empty for CMS Authoring
	if(windowwidth  == "") windowwidth = 670;
	if(windowheight == "") windowheight = 502;

	// add 0.01 to windowwidth as X40 ASP rounding slightly differs from Javascript rounding
	popHeight=Math.round((popWidth*windowheight)/(parseFloat(windowwidth)+0.01));

	if(windowwidth > popWidth || windowheight > popHeight){
		windowwidth  = popWidth;
		windowheight = popHeight;
	}	

	// manipulate image URL
	imagesrc=imageURLmain + "_" + "large" + imageURLext;

	if(popEnlarge!=null && !popEnlarge.closed){ 
	popEnlarge.close(); 
	}
	var source;
	var alttext;
	source = imagesrc.replace(/\//gi,"%2F");
	source = source.replace(/\./gi,"@");
	alttext = imagealt.replace(/\./gi,"@");
	alttext = encodeURIComponent(alttext);
	var URL = popupurl + "?src=" + source;
	URL = URL + "&width=" + windowwidth;		
	URL = URL + "&height=" + windowheight;
	URL = URL + "&alt=" + alttext;				
  var windowName = "EnlargedImage";
	
	if(document.location.href.indexOf("jaguar")>-1 || document.location.href.indexOf("nib00104")>-1)
		{if(windowheight != "0") windowheight = parseInt(windowheight) + 124;}
	else
		{if(windowheight != "0") windowheight = parseInt(windowheight) + 80;}
  var features = "top=10,left=10,width=" + windowwidth + ",height=" + windowheight + ",menubar=no,location=no,resizable=no,scrollbars=no,toolbar=no,status=yes";

  popEnlarge = window.open (URL, windowName, features);
  popEnlarge.focus();
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}


var popWallpaper
function OpenDownloadWallpaperPopup(popupurl,imagesrc,width,height,screensize)
{

	if(popWallpaper!=null && !popWallpaper.closed){ 
	popWallpaper.close(); 
	}

	var source
	source = imagesrc.replace(/\//gi,"%2F");
	source = source.replace(/\./gi,"@");
	var URL = popupurl + "?src=" + source + "&width=" + width + "&height=" + height + "&screensize=" + screensize;
  var windowName = "DownloadWallpaper";
  var features = "width=" + width + ",height=" + height + ",menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,status=yes";
  //alert("features: " + features);
  //alert("url: " + URL);

  popWallpaper = window.open (URL, windowName, features);
  popWallpaper.focus();
}

function openwindow(windowurl, windowid, windowparm) {
	self.msgWindow = window.open(windowurl, windowid, windowparm);
	self.msgWindow.focus();
	if (self.msgWindow.opener == null) self.msgWindow.opener = self;
}

var EntryWindowHandle;
var ExitWindowHandle;
function OpenSurvey(surveyname, surveystartpath, surveyendpath, windowparms, frequency)
{
	var sValue = 1;
	var sName = surveyname;
	var rndNum;
	rndNum = Math.floor(Math.random()*10);	//Create a random integer between 0 and 10
	if (document.cookie) //If accepts cookies
	{
		if (rndNum < frequency && document.cookie.indexOf(sName) == -1) //If cookie has not been set
		{
			lib_setcookie(sName, sValue, expdate, "/");

			if(surveyendpath != "")
			{
				ExitWindowHandle=window.open(surveyendpath,'surveyend',windowparms);
	    	ExitWindowHandle.oldWindow=top;
	   		top.focus();
   		}

			EntryWindowHandle = window.open(surveystartpath, 'survey', windowparms);
			EntryWindowHandle.focus();
			if (EntryWindowHandle.opener == null) EntryWindowHandle.opener = self;
		}
	}
}
function DeclineSurvey()
{
	if(opener.EntryWindowHandle)
	{
		opener.EntryWindowHandle.close();
	}
	if(opener.ExitWindowHandle)
	{
		opener.ExitWindowHandle.close();
	}
}
/*-iklein1 04.05.2006-----------------------------------------------------------------------*/
/*-writeFlash function for MS-Patch blocking controls---------------------------------------*/
function writeFlash(movie, id, width, height, play, loop, quality, Scale, WMode, Menu, SAlign, Align, bgcolor, base, FlashVars, DivID){
	var strFlash = "";
	strFlash = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="Z-INDEX:0" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" ';
	strFlash += 'Width="' + width + '" ';
	strFlash += 'Height="' + height + '" ';
	strFlash += 'ID="' + id + '" >';
	strFlash += '<PARAM NAME="Movie" value="' + movie + '" />';
	strFlash += '<PARAM NAME="Width" value="' + width + '" />';
	strFlash += '<PARAM NAME="Height" value="' + height + '" />';
	strFlash += '<PARAM NAME="Play" value="' + play + '" />';
	strFlash += '<PARAM NAME="Loop" value="' + loop + '" />';
	strFlash += '<PARAM NAME="Quality" value="' + quality + '" />';
	strFlash += '<PARAM NAME="Scale" value="' + Scale + '" />';
	strFlash += '<PARAM NAME="WMode" value="' + WMode + '" />';
	strFlash += '<PARAM NAME="Menu" value="' + Menu + '" />';
	strFlash += '<PARAM NAME="SAlign" value="' + SAlign + '" />';
	strFlash += '<PARAM NAME="Align" value="' + Align + '" />';
	strFlash += '<PARAM NAME="BGColor" value="' + bgcolor + '" />';
	strFlash += '<PARAM NAME="Base" value="' + base + '" />';
	strFlash += '<PARAM NAME="flashvars" value="' + FlashVars + '" />';
	strFlash += '<EMBED ';
	strFlash += 'NAME="' + id + '" ';
	strFlash += 'TYPE="application/x-shockwave-flash" ';
	strFlash += 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ';
	strFlash += 'src="' + movie + '" ';
	strFlash += 'width="' + width + '" ';
	strFlash += 'height="' + height + '" ';
	strFlash += 'Play="' + play + '" ';
	strFlash += 'loop="' + loop + '" ';
	strFlash += 'Quality="' + quality + '" ';
	strFlash += 'Scale="' + Scale + '" ';
	strFlash += 'WMode="' + WMode + '" ';
	strFlash += 'Menu="' + Menu + '" ';
	strFlash += 'SAlign="' + SAlign + '" ';
	strFlash += 'Align="' + Align + '" ';
	strFlash += 'bgcolor="' + bgcolor + '" ';
	strFlash += 'base="' + base + '" ';
	strFlash += 'flashvars="' + FlashVars + '">';
	strFlash += '</EMBED>';
	strFlash += '</OBJECT>';
	if (arguments[15]){
		if (document.getElementById){
			document.getElementById(arguments[15]).innerHTML = strFlash;
		}
	}
	else{
		document.write(strFlash);
	}
} 
function writeDiv(DivID, strContent){
	if (document.getElementById){
		document.getElementById(DivID).innerHTML = strContent;
	}
} 
function ThumbnailOver(obj,intItem){
				obj.className = 'thumb_' + intItem + 'hover';
				showImage(intItem);
				if (intItem != intCurrentImg){
					if (document.getElementById){
						document.getElementById("thumb_" + intCurrentImg).className = "thumb_" + intCurrentImg;
						document.getElementById(intCurrentImg + '_links').style.display = 'none';
					}
				}
				if (document.getElementById){
					document.getElementById(intItem + '_links').style.display = 'block';
				}
				intCurrentImg = intItem;
				objCurrentThumb = obj;
			}
function RestoreDefault(){
				return true;
				ThumbnailOver(document.getElementById('thumb_2'),2);
}			
/*------------------------------------------------------------------------------------------*/


