// Script: tg2_std.js
// Version: 1.1
// Dokumentation: tg2_std.htm
// Letzte Aenderung:
// Datum: 03.03.2004
// Name: Frank Merl (onpact AG)

function checkBrowser(){
	this.agt = navigator.userAgent.toLowerCase();
	this.ver = navigator.appVersion;
	this.dom = document.getElementById?1:0;
	this.linux = (this.agt.indexOf("linux")!=-1) ? 1:0;
	this.mac = (this.agt.indexOf("mac")!=-1) ? 1:0;
	this.win = (this.agt.indexOf("win")!=-1) ? 1:0;
	this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55 = (this.ver.indexOf("MSIE 5.5")>-1 && this.dom)?1:0;
	this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.ie55)?1:0;
	this.ie4 = (document.all && !this.dom) ? 1:0;
	this.ns6 = (this.dom && parseInt(this.ver) >= 5 && this.ver.indexOf("Gecko")>-1) ? 1:0;
	this.ns5 = (this.dom && parseInt(this.ver) >= 5 && !this.ns6 && !this.linux && (this.agt.indexOf('opera')==-1)) ? 1:0;
	this.ns4 = (document.layers) ? 1:0;
	this.nn = ((document.captureEvents) && (!this.dom)) ? 1:0;
	this.mz = (((this.dom) && (!document.all) && (document.documentElement)) && (this.agt.indexOf("safari")==-1)) ? 1:0;
	this.op = ((this.dom) && (this.agt.indexOf('opera')!=-1)) ? 1:0;
	this.kon = ((this.agt.indexOf("konqueror")!=-1) || (this.agt.indexOf("safari")!=-1)) ? 1:0;
	this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5 || this.ie55 || this.ie6);
	this.os = (this.ver.indexOf("Macintosh")>-1)? "mac":"pc";
	this.ie = (this.ie5 || this.ie4 || this.ie55 || this.ie6);
	this.ns = (this.ns4 || this.ns5 || this.ns6);
	this.client = (!this.ns4) ? "ie" : "ns";
    this.iemac = (this.mac && this.ie) ? 1:0;
	return this;
}

checkBrowser.prototype.toString = function() {
    return (this.client + "_" + this.os);
}

checkBrowser.prototype.CSSstring = function(country, os) {
    if (!os) os = this.os;
    if (!country) country = 'de';
    return ("style_" + this.client + "_" + os + "_" + country);
}

var is = new checkBrowser();

function isBlockedByCookie(name){
	if (document.cookie) {
		if (document.cookie.lastIndexOf("bmp_" + name) >= 0) {
			return true;
		}
	}
	return false;
}

var popupHandle;

function openPopUp(url) {
    screenw = window.screen.width;
    screenh = window.screen.height;
    var sp = new Object();
	sp.name = 'audi';
	sp.location = 0;
	sp.top = 'center';
	sp.left = 'center';
	sp.width = 700;
	sp.height = 543;
	sp.width_iemac = -1;
	sp.height_iemac = -1;
	sp.width_nnmac = -1;
	sp.height_nnmac = -1;
	sp.width_ie = -1;
	sp.height_ie = -1;
	sp.width_kon = -1;
	sp.height_kon = -1;
	sp.width_nn = -1;
	sp.height_nn = -1;
	sp.width_mz = -1;
	sp.height_mz = -1;
	sp.menubar = 0;
	sp.status = 0;
	sp.directories 	= 0;
	sp.scrollbars = 0;
	sp.resizable = 0;
	sp.fullscreen = -1;

    for (i = 1; i < window.openPopUp.arguments.length; i++) {
        var a = window.openPopUp.arguments[i];
        split = a.indexOf("=");
        if (split != -1) {
            v = a.substring(split + 1, a.length);
            k = a.substring(0, split);
            eval("sp." + k.replace(/ /g,"") + "='" + v.replace(/ /g,"") + "'");
        }
    }
	if (is.nn && sp.width_nn != -1) sp.width = sp.width_nn;
	if (is.nn && sp.height_nn != -1) sp.height = sp.height_nn;
	if (is.mz && sp.width_mz != -1) sp.width = sp.width_mz;
	if (is.mz && sp.height_mz != -1) sp.height = sp.height_mz;
	if (is.ie && sp.width_ie != -1) sp.width = sp.width_ie;
	if (is.ie && sp.height_ie != -1) sp.height = sp.height_ie;
	if (is.kon && sp.width_kon != -1) sp.width = sp.width_kon;
	if (is.kon && sp.height_kon != -1) sp.height = sp.height_kon;
	if (is.iemac && sp.width_iemac != -1) sp.width = sp.width_iemac;
	if (is.iemac && sp.height_iemac != -1) sp.height = sp.height_iemac;
	if (is.mac && is.nn && sp.width_nnmac != -1) sp.width = sp.width_nnmac;
	if (is.mac && is.nn && sp.height_nnmac != -1) sp.height = sp.height_nnmac;
	if (sp.top=="center") sp.top = Math.round((screenh-sp.height) / 2);
	if (sp.left=="center") sp.left = Math.round((screenw-sp.width) / 2);
	n = sp.name;
	sp.name = -1;
	sp.width_nn = -1;
	sp.height_nn = -1;
	sp.width_mz = -1;
	sp.height_mz = -1;
	sp.width_ie = -1;
	sp.height_ie = -1;
	sp.width_kon = -1;
	sp.height_kon = -1;
	sp.width_iemac = -1;
	sp.height_iemac = -1;
	a = "";

    if (isBlockedByCookie(n)) {
    	// geh nur einmal pro session auf.
        return;
    }

    if(sp.fullscreen=='yes'){
	sp.width = window.screen.availWidth - 10;
	sp.height = window.screen.availHeight -30;
	sp.top=0;
	sp.left=0;
	sp.fullscreen = -1;
    }

    for (p in sp) if (sp[p] != -1) a += p + "=" + sp[p] + ",";
    a = a.substring(0, a.length - 1);
    top[n] = window.open(url, n, a);
    top[n].focus();
    if (!top[n].opener) top[n].opener = window;

    popupHandle = top[n];

    if (typeof(sp.bmp) != "undefined" ) { // block multiple opening by setting a cookie
        document.cookie = "bmp_" + n + "=1;Path=/";
    }
}

function indicateModell(m) {
	switch(m) {
		case "audi": 	m = '1'; 		return m; break;
		case "a2":		m = '1;9';		return m; break;
		case "a3":		m = '1;10';		return m; break;
		case "a4":		m = '1;13';		return m; break;
		case "a4avant":	m = '1;16';		return m; break;
		case "a6":		m = '1;14';		return m; break;
		case "a6avant":	m = '1;17';		return m; break;
		case "a8":		m = '1;15';		return m; break;
		case "cabrio":	m = '1;28';		return m; break;
		case "tt":		m = '1;31';		return m; break;
		case "vw":		m = '40';		return m; break;
		case "bmw":		m = '3';		return m; break;
		case "fiat":	m = '8';		return m; break;
		case "ford":	m = '9';		return m; break;
		case "mercedes":m = '19';		return m; break;
		case "opel":	m = '22';		return m; break;
		default:		m = '1';		return m; break;
    }
}

function indicatePreis(p) {
	switch(p) {
	 	case "alle":	p = '-1;-1';	return p; break;
	 	case "klasse1":	p = '0;1';		return p; break;
	 	case "klasse2":	p = '1;2';		return p; break;
	 	case "klasse3":	p = '2;3';		return p; break;
	 	case "klasse4":	p = '3;4';		return p; break;
	 	case "klasse5":	p = '4;5';		return p; break;
	 	case "klasse6":	p = '5;6';		return p; break;
	 	case "klasse7":	p = '6;7';		return p; break;
	 	case "klasse8":	p = '7;8';		return p; break;
	 	case "klasse9":	p = '8;1';		return p; break;
	 	default:		p = '-1;-1';	return p; break;
	}
}

function goUrl(url) {
    var att = new Object();
    att.language  = 'de';
    for (i = 1; i < window.goUrl.arguments.length; i++) {
        var a = window.goUrl.arguments[i];
        split = a.indexOf("=");
        if (split != -1) {
            v = a.substring(split + 1, a.length);
            k = a.substring(0, split);
            eval("att." + k.replace(/ /g,"") + "='" + v.replace(/ /g,"") + "'");
        }
    }
    document.location.href = url;
}

function PopUpManager(name) {
    var att = new Object();
    att.language  = 'de';
    for (i = 1; i < window.PopUpManager.arguments.length; i++) {
        var a = window.PopUpManager.arguments[i];
        split = a.indexOf("=");
        if (split != -1) {
            v = a.substring(split + 1, a.length);
            k = a.substring(0, split);
            eval("att." + k.replace(/ /g,"") + "='" + v.replace(/ /g,"") + "'");
        }
    }
    name = name.toLowerCase(); // name in Kleinbuchstaben wandeln!

    if (name == "ak4") {
        var url = 'http://ak4-de.audi.de/entry.do?';
        if (typeof(att.carline) != 'undefined') {
            url = url + 'carline=' + att.carline + '&';
        }
        openPopUp(url, 'name=AK4SATELLIT', 'scrollbars=0','width=955','height=700','resizable=0','status=1');
    }

    if (name == "journalisten") {
        openPopUp("https://journalisten.audi.de/journalisten/DCO", 'name=journalisten', 'status=yes', 'width=782', 'height=585');
    }

    if (name == "openextlink") {
        openPopUp(att.url, 'width=800', 'height=600','scrollbars=1','menubar=1','status=1','resizable=1','toolbar=1','location=1');
    }

    if (name == "open_foren_startsite") {
        if (typeof(att.desturl) != 'undefined') var url = att.desturl;
        else var url = "http://www.museummobile.de/sprache.php";
        openPopUp(url, 'name=foren_startsite' ,'width=790', 'height=550','height_iemac=566','height_nnmac=551','width_nnmac=791');
    }

    if (name == "open_nwb" || name == "open_neuwagen") {
        var params="";
        if (typeof(att.params) == "undefined") {
            if (typeof(att.op) != "undefined") {
                params += 'op=' + att.op + '&';
            }
            if (typeof(att.model) != "undefined") {
                params = 'op=directFilterEntry&model=' + att.model;
            }
            if (typeof(att.partner) != "undefined") {
                params += '&partner=' + att.partner;
            } else {
                params += '&partner=';
            }
        } else {
            params = att.params;
        }

        var url = "http://neuwagenboerse.audi.de/neuwagenboerse/controller?" + params;
        openPopUp(url, 'name=NWBSATELLIT', 'width=792', 'height=600','scrollbars=1', 'resizable=1');
    }

    if (name == "open_dwb" || name == "open_dienstwagen") {
    	var mod = "wdwb";
    	var app_kind = "default";
    	var partner = "";
    	var str = "";

		if (typeof(att.mod) != "undefined") {
			mod = att.mod;
		}
		if (typeof(att.app_kind) != "undefined") {
			app_kind = att.app_kind;
		}
		if (typeof(att.partner) != "undefined") {
			partner = att.partner;
		}
		str = "mod="+mod+"&app_kind="+app_kind+"&partner="+partner;
		
		if (typeof(att.op) != "undefined") {
			str += '&op=' + att.op;
        }
		if (typeof(att.mId) != "undefined") {
			str += '&model=' + att.mId;
        }
		if (typeof(att.fId) != "undefined") {
			str += '&fuel=' + att.fId;
        }
		if (typeof(att.pId) != "undefined") {
			str += '&price=' + att.pId;
        }
        var url = "http://dienstwagen.audi.de/dienstwagenboerse/controller?" + str;
        openPopUp(url, 'name=DWBSATELLIT', 'width=792', 'height=600','scrollbars=1', 'resizable=1');
    }

    if (name == "open_gwb" || name == "open_gebrauchtwagen") {
        var url = 'http://gebrauchtwagen.audi.de/agwb/agwb.dll/?act=10';
        var pwidth = 779;
        var pheight = 590;

        if (typeof(att.typ) != "undefined") {
            if (att.typ == "profisuche") {
                var url = 'http://gebrauchtwagen.audi.de/agwb/agwb.dll/?';
            }
            if (att.typ == "aegwb") {
                var url = 'http://gebrauchtwagen.audi.de/aegwb/aegwb.dll/?';
                pwidth = 648;
                pheight = 642;
            }
        }
        if (typeof(att.model) != "undefined") {
            var url = 'http://gebrauchtwagen.audi.de/agwb/agwb.dll/?t_model='+att.model;
        }
        openPopUp(url, 'name=AUDI_GWB', 'width='+pwidth, 'height='+pheight, 'resizable=1','left=0','top=0');
    }

    if (name == "open_vers_finanz" || name == "open_finanz") {
        var url = "http://services.audibank.de/CalculatorFE/audi/ConfiguratorNewCars.aspx";
        openPopUp(url, 'name=calculate', 'width=760', 'height=590','left=0','top=0', 'resizable=1', 'scrollbars=1');
    }

    if (name == "calc_vw") {
        var url = "http://services.audibank.de/CalculatorFE/audi/NewCars.aspx" +
			        "?VehicleKey=" + att.MID +
			        "&VehicleYear=" + att.MY +
			        "&VehiclePrice=" + att.P +
			        "&VehicleText=" + att.MTXT +
			        "&PresetProductId=" + att.CM +
			        "&PresetMileage=" + att.KMJ +
			        "&PresetDuration=" + att.LZ +
			        "&PresetDownPayment=" + att.ANZ +
			        "&PresetRSV=" + att.R;

        openPopUp(url, 'name=calculate', 'width=760', 'height=590','left=0','top=0', 'resizable=1', 'scrollbars=1');
    }

    if (name == "open_mmi") {
        var optionen = 'toolbar=no,width=400,height=500,directories=no,status=no,scrollbars=no,resize=no,menubar=no,top=20,left=80';
        var url = 'http://www.audi.com/satellite/mmi/emulation.html';
        openPopUp(url, 'name=MMI', 'width=400', 'height=500', 'top=20', 'left=80');
    }

    if (name == "open_exclusive") {
        var url = "http://microsites.audi.com/campaigns/exclusive/start.htm";
        openPopUp(url, 'name=exclusive', 'width=750', 'height=450');
    }
    if (name == "open_gwbplus") {
        var url = "http://dealersearch.audi.com/dealersearch/gwbplus/gwb-plus-frameset.html";
        openPopUp(url, 'name=gwbplus', 'width=720', 'height=765', 'resizable=1');
    }
    if (name == "open_mofi") {
        var url = "http://www.audi.com/audi/de/de1/modellfinder.html";
        openPopUp(url, 'name=mofi', 'width=640', 'height=603', 'resizable=0');
    }


  if (name == "open_ttadvance"){
  
      var popx = 330;
      var screenW = window.screen.width;
  
       if (screenW < 1024){
           popx = screenW - 535;
       }
  
      openPopUp('http://microsites.audi.com/campaigns/ttadvance/','name=TTADVANCE','left=' + popx,'top=40','width=528','height=344','scrollbars=0');
      if(typeof(att.openttmain) != 'undefined') {
          window.document.location = "/de/de/neuwagen/tt/tt.jsp";
      }
      if(typeof(att.openttcoupe) != 'undefined') {
          window.document.location = "/de/de/neuwagen/tt/tt_coupe/ttcoupe.jsp";
      }
      if(typeof(att.openttroadster) != 'undefined') {
          window.document.location = "/de/de/neuwagen/tt/tt_roadster/tt_roadster.jsp";
      }
  }
  if (name == "open_ttquattrosport"){
  
      var popx = 330;
      var screenW = window.screen.width;
  
       if (screenW < 1024){
           popx = screenW - 535;
       }
      openPopUp('http://microsites.audi.com/campaigns/ttquattrosport/de_DE/index.html','left=' + popx,'top=40','width=530','height=344','scrollbars=0');
  }
  if (name == "open_a4dtm"){
  
      var popx = 330;
      var screenW = window.screen.width;
  
       if (screenW < 1024){
           popx = screenW - 535;
       }
      openPopUp('http://microsites.audi.com/campaigns/a4_dtm_edition/index.html','left=' + popx,'top=40','width=530','height=344','scrollbars=0');
  }
  
  if (name == "open_ttspecial"){
  
      var popx = 330;
      var screenW = window.screen.width;
  
       if (screenW < 1024){
           popx = screenW - 535;
       }
      openPopUp('http://www.audi.com/satellite/tt/start.htm','left=' + popx,'top=40','height=360','width=600','scrollbars=0','menubar=0','resizable=0');
  }
  
}

// Integrate the popups into link onclick attribute to work around popup blockers
MODE_EQUALS = 0;
MODE_CONTAINS = 1;
MODE_STARTS_ENDS_WITH = 2;

popups = new Array();

popups[0] = new PopupItem(
                                "/de/de/neuwagen/a6/limousine/limousine.jsp",
                                "",
                                MODE_STARTS_ENDS_WITH,
                                function() { openPopUp('http://microsites.audi.com/satellite/a6_microsite/index.html','name=a6_micro','height=383','width=693','bmp=1'); return true; }
                            );
popups[1] = new PopupItem(
                                "/com/en/new_cars/new_cars.jsp",
                                "",
                                MODE_EQUALS,
                                function() { open_makingofa8_en(); return true; }
                            );
popups[2] = new PopupItem(
                                "/de/de/neuwagen/",
                                "/audi_exclusive/audi_exclusive.jsp",
                                MODE_STARTS_ENDS_WITH,
                                function() { PopUpManager('open_exclusive'); return true; }
                            );
popups[3] = new PopupItem(
                                "/de/de/neuwagen/a6/avant/avant.jsp",
                                "",
                                MODE_EQUALS,
                                function() { openPopUp('http://microsites.audi.com/campaigns/a6_avant/de_DE/','name=a6_avant','height=600','width=800'); return true; }
                            );

popups[4] = new PopupItem(
                                "/de/de/neuwagen/a4/rs4/rs4.jsp",
                                "",
                                MODE_EQUALS,
                                function() { openPopUp('http://microsites.audi.com/campaigns/rs4/de_DE/index.html','name=rs4m','height=600','width=800','bmp=1'); return true; }
                            );

function PopupItem(url0, url1, mode, popupFunction) {
    this.url0 = url0;
    this.url1 = url1;
    this.mode = mode;
    this.popupFunction = popupFunction;
}

function addPopupsToLinks() {
    thisHost = window.location.protocol + "//" + window.location.host;
    linkCount = document.links.length;

    for (i = 0; i < linkCount; i++) {
        linkOnclick = document.links[i].onclick;
        if (!linkOnclick) {
            linkUrl = String(document.links[i]);
            hostIdx = linkUrl.indexOf(thisHost);
            if (hostIdx > -1) {
                linkUrl = linkUrl.substring(hostIdx + thisHost.length);
            }

            for (q = 0; q < popups.length; q++) {
                switch (popups[q].mode) {
                    case MODE_EQUALS:
                        if (linkUrl == popups[q].url0) {
                            document.links[i].onclick = popups[q].popupFunction;
                        }
                    break;
                    case MODE_CONTAINS:
                        if (linkUrl.indexOf(popups[q].url0) > -1) {
                            document.links[i].onclick = popups[q].popupFunction;
                        }
                    break;
                    case MODE_STARTS_ENDS_WITH:
                        if (linkUrl.indexOf(popups[q].url0) == 0 && linkUrl.lastIndexOf(popups[q].url1) == (linkUrl.length - popups[q].url1.length)) {
                            document.links[i].onclick = popups[q].popupFunction;
                        }
                    break;
                }
            }
        }
    }
}
