var screenW = 800;
var screenH = 600;
var leftPos = 0;
var topPos = 0;
var genericWinHandle = null;

// display text in the browser status bar
function statusTxt(text) {
	window.setTimeout('window.status="' + text + '"', 1);
    return true;
}

// calculate the horizontal centre of the screen
function winLeft(W) {
    if (screen.availWidth) {
    	screenW = screen.availWidth;
    }
    return (screenW - W) / 2;
}

// calculate the vertical centre of the screen
function winTop(H) {
    if (screen.availHeight) {
    	screenH = screen.availHeight;
    }
   	return (screenH - H) / 2;
}

// attempt to centre the window on the screen
function winCenter(W,H) {
	leftPos = winLeft(W);
    topPos = winTop(H);
    return leftPos, topPos;
}

// position the window at a certain point on the screen
function winPosition(X,Y) {
  	leftPos = X;
    topPos = Y;
    return leftPos, topPos;
}

// set popup window position to screen centre
function winCenteredPopup(url,name,type,W,H) {
	winCenter(W,H);
    var features = winPopupType(type) + ',height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    return winGenericOpen(url,name,features);;
}

// set popup window position to a certain location
function winPositionedPopup(url,name,type,W,H,X,Y) {
	winPosition(X,Y);
    var features = winPopupType(type) + ',height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    return winGenericOpen(url,name,features);
}

// open a popup window without positioning
function winOpenNP(url,name,features) {
	genericWinHandle = window.open(url,name,features);
    setTimeout("genericWinHandle.focus();", 200);
    return genericWinHandle;
}

// open a generic popup window
function winGenericOpen(url,name,features) {
	genericWinHandle = window.open(url,name,features);
    setTimeout("genericWinHandle.focus();", 200);
    setTimeout("genericWinHandle.moveTo(leftPos,topPos);", 250);
    setTimeout("leftPos = topPos = 0;", 5000);
    return genericWinHandle;
}

// close an open browser window
function winClose(winHandle) {
	if (winHandle && !winHandle.closed) {
		winHandle.close();
        return true;
	}
    return false;
}

// the type of popup to launch
function winPopupType(type) {
    var features = '';
    if (type == 'specs') {
        features =
            'menubar='          +'no'+
            ',location='        +'no'+
            ',status='          +'yes'+
            ',toolbar='         +'no'+
            ',scrollbars='      +'yes'+
            ',resizable='       +'yes';
    }
	if (type == 'config') {
		features = 
			'menubar='          +'no'+
            ',location='        +'no'+
            ',status='          +'no'+
            ',toolbar='         +'no'+
            ',scrollbars='      +'yes'+
            ',resizable='       +'yes';
	}	
    else {
        features =
            'menubar='          +'no'+
            ',location='        +'no'+
            ',status='          +'no'+
            ',toolbar='         +'no'+
            ',scrollbars='      +'no'+
            ',resizable='       +'no';
    }
    features = features+',fullscreen=no,titlebar=no,directories=no';
    return features;
}

// Specs Comparator Opener
var specsWinHandle = null;
function specsLauncher(url) {
    if (!url) { url = '/specs/'; }
	var W = 750;
    var H = 550;
 	winCenter(W,H);
    var features = 'scrollbars=yes,status=no,resizable=yes,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    specsWinHandle = winGenericOpen(url,'specsWin',features);
}

// Nuvolari Concept-car Opener (Link to German site)
function nuvolariLauncher(url) {
    if (!url) { url = 'http://www.audi.com/satellite/nuvolari/en/html/intro.html'; }
    window.open(url,'nuvolariWin','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,left=50,top=100,width=740,height=400');
}

// Boutique Catalogue Opener
var experience_boutiqueWinHandle = null;
function experience_boutiqueLauncher(url) {
    if (!url) { url = '/experience/boutique/catalogue.php'; }
    var W = 755;
    var H = 540;
 	winCenter(W,H);
    var features = 'status=yes,resizable=yes,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    experience_boutiqueWinHandle = winGenericOpen(url,'experience_boutiqueWin',features);
}

// Audi Financial Services Application Form Opener
var services_audiFinance_applicationWinHandle = null;
function services_audiFinance_applicationLauncher(url) {
    if (!url) { url = 'https://www.wesbank.co.za/fastapp/audi/index.asp'; }
    var features = 'width=750,height=540,scrollbars=yes,resizable=yes';
    services_audiFinance_applicationWinHandle = winOpenNP(url,'services_audiFinance_applicationWin',features);
}
// All Road Microsite Opener
var allroad_WinHandle = null;
function allroad_micrositeLauncher(url) {
    if (!url) { url = 'http://www.audiconcept.com/php/flash.php?lang=false&id=false&qual=hi'; }
    var W = 790;
    var H = 560;
 		winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    allroad_WinHandle = winGenericOpen(url,'allroadWin',features);
}

// A4 Finance Banner Opener
var campaigns_a4financeWinHandle = null;
function campaigns_a4financeLauncher(url) {
    if (!url) { url = '/campaigns/a4finance/'; }
    var W = 500;
    var H = 375;
 		winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    campaigns_a4financeWinHandle = winGenericOpen(url,'campaigns_a4financeWin',features);
}

// A4 Finance Banner Opener
var campaigns_a4financeWinHandle = null;
function handleClick() {
	var url = '/a4/';
    //if (!url) { url = '/a4/a4finance/'; }
    //var W = 500;
    //var H = 375;
 		//winCenter(W,H);
    //var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    //campaigns_a4financeWinHandle = winGenericOpen(url,'campaigns_a4financeWin',features);
	window.location = url;
}

// a4 Microsite Opener
var a4_micrositeWinHandle = null;
function a4_micrositeLauncher(url) {
    if (!url) { url = '/a4/microsite/index.html'; }
    var W = 800;
    var H = 540;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a4_micrositeWinHandle = winGenericOpen(url,'a4_micrositeWin',features);
}


// A6 Microsite Opener
var a6_micrositeWinHandle = null;
function a6_micrositeLauncher(url) {
    if (!url) { url = '/a6/microsite/'; }
    var W = 750;
    var H = 450;
 		winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a6_micrositeWinHandle = winGenericOpen(url,'a6_micrositeWin',features);
}

// A6 TDI Microsite Opener
var a6_tdiWinHandle = null;
function a6_tdiLauncher(url) {
    if (!url) { url = '/a6/tdi/index.php'; }
    var W = 680;
    var H = 460;
 	winCenter(W,H);
    var features = 'status=no,resizable=yes,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a6_tdiWinHandle = winGenericOpen(url,'a6_tdiWin',features);
}

// S4 Microsite Opener
var a4_s4_micrositeWinHandle = null;
function a4_s4_micrositeLauncher(url) {
    if (!url) { url = '/a4/s4/microsite/index.php'; }
    var W = 750;
    var H = 470;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a4_s4_micrositeWinHandle = winGenericOpen(url,'a4_s4_micrositeWin',features);
}

// A8 Microsite Opener
var a8_micrositeWinHandle = null;
function a8_micrositeLauncher(url) {
    if (!url) { url = '/a8/microsite/index.php'; }
    var W = 750;
    var H = 450;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a8_micrositeWinHandle = winGenericOpen(url,'a8_micrositeWin',features);
}

// S4 Microsite Opener
var a4_s4micrositeWinHandle = null;
function a4_s4micrositeLauncher(url) {
    if (!url) { url = '/a4/s4/microsite/index.php'; }
    var W = 750;
    var H = 470;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a4_s4micrositeWinHandle = winGenericOpen(url,'a4_s4micrositeWin',features);
}

// S4 TV Commercial Opener
var a4_s4_tvcWinHandle = null;
function a4_s4_tvcLauncher(url) {
    if (!url) { url = '/experience/multimedia/_assets/s4_electric.mpg'; }
    var W = 320;
    var H = 255;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a4_s4tvcWinHandle = winGenericOpen(url,'a4_s4tvcWin',features);
}

// S4 Game Opener
var a4_s4_gameWinHandle = null;
function a4_s4_gameLauncher(url) {
    if (!url) { url = '/a4/s4/game/index.php'; }
    var W = 750;
    var H = 450;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a4_s4gameWinHandle = winGenericOpen(url,'a4_s4gameWin',features);
}

// A3 Microsite Opener
var a3_micrositeWinHandle = null;
function a3_micrositeLauncher(url) {
    if (!url) { url = '/a3/microsite/'; }
    var W = 750;
    var H = 470;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a3_micrositeWinHandle = winGenericOpen(url,'a3_micrositeWin',features);
}

// Virgin Active Competition Rules Opener
var a3_launch_virginPopupWinHandle = null;
function a3_launch_virginPopupLauncher(url) {
    if (!url) { url = '/a3/launch/vapopup.php'; }
    var W = 380;
    var H = 350;
 	winCenter(W,H);
    var features = 'scrollbars=yes,status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a3_launch_virginPopupWinHandle = winGenericOpen(url,'a3_launch_virginPopupWin',features);
}

// Virgin Active Competition Rules Opener
var a3_newa3_launch_virginPopupWinHandle = null;
function a3_newa3_launch_virginPopupLauncher(url) {
    if (!url) { url = '/a3/newa3/launch/vapopup.php'; }
    var W = 380;
    var H = 350;
 	winCenter(W,H);
    var features = 'scrollbars=yes,status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a3_newa3_launch_virginPopupWinHandle = winGenericOpen(url,'a3_newa3_launch_virginPopupWin',features);
}

// RS6 Microsite Opener
var a6_rs6_micrositeWinHandle = null;
function a6_rs6_micrositeLauncher(url) {
    if (!url) { url = '/a6/rs6/microsite.php'; }
    var W = 750;
    var H = 350;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    a6_rs6_micrositeWinHandle = winGenericOpen(url,'a6_rs6_micrositeWin',features);
}

// Le Mans quattro Special Opener
var vorsprung_concept_lemans_specialWinHandle = null;
function vorsprung_concept_lemans_specialLauncher() {
    url = 'http://www.audi.com/satellite/iaaspecial/en/index_lmq_en.html';
    var W = 760;
    var H = 470;
 	winCenter(W,H);
    var features = 'status=no,resizable=no,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
    vorsprung_concept_lemans_specialWinHandle = winGenericOpen(url,'vorsprung_concept_lemans_specialWin',features);
}

// A8 Configurator Opener
var configuratorWinHandle = null;
function configuratorLauncher(url) {
    if (!url) {url = '/configurator';}
    var W = 816;
    var H = 550;
 	winCenter(W,H);
    var features = 'scrollbars=yes,status=yes,resizable=yes,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
	configuratorWinHandle = winCenteredPopup(url,'configuratorWin','config',W,H);
}

// A8 Configurator Opener
var a8_configWinHandle = null;
function a8_configLauncher(url) {
    if (!url) {url = '/configurator';}
    var W = 816;
    var H = 550;
 	winCenter(W,H);
    var features = 'scrollbars=yes,status=yes,resizable=yes,height='+H+',width='+W+',left='+leftPos+',top='+topPos;
	a8_configWinHandle = winCenteredPopup(url,'a8_configWin','config',W,H);
}
