//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
}

//Flashhandling (needed)
function lib_flashcheck(){
var browser = navigator.userAgent.toLowerCase();
flashVersion = 0;
// NS3+, Opera3+, IE5+ Mac
if ( navigator.plugins != null && navigator.plugins.length > 0 ) 
{
	var flashPlugin = navigator.plugins['Shockwave Flash'];
	if ( typeof flashPlugin == 'object' ) 
	{
		if ( flashPlugin.description.indexOf('7.') != -1 ) flashVersion = 7;
		else if ( flashPlugin.description.indexOf('6.') != -1 ) flashVersion = 6;
		else if ( flashPlugin.description.indexOf('5.') != -1 ) flashVersion = 5;
		else if ( flashPlugin.description.indexOf('4.') != -1 ) flashVersion = 4;
		else if ( flashPlugin.description.indexOf('3.') != -1 ) flashVersion = 3;
	}
} // IE4+ Win32 (VBscript)
else 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('on error resume next \n');
document.write('DIM obFlash \n');
document.write('SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
document.write('IF IsObject(obFlash) THEN \n');
document.write('flashVersion = 7 \n');
document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") END IF \n');
document.write('IF flashVersion < 7 and IsObject(obFlash) THEN \n');
document.write('flashVersion = 6 \n');
document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") END IF \n');
document.write('IF flashVersion < 6 and IsObject(obFlash) THEN \n');
document.write('flashVersion = 5 \n');
document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") END IF \n');
document.write('IF flashVersion < 5 and IsObject(obFlash) THEN \n');
document.write('flashVersion = 4 \n');
document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") END IF \n');
document.write('IF flashVersion < 4 and IsObject(obFlash) THEN \n');
document.write('flashVersion = 3 \n');
document.write('END IF');
document.write('</scr' + 'ipt\> \n');
} // no Flash
else {
flashVersion = -1;
}
return flashVersion;
}

var fv = lib_flashcheck()

//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 + "_" + windowheight + "x" + windowwidth + 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;
}