/*
uso: 
<a href="/models/galleryfullsize.php?modelID=citigolf&img=g.13full.jpg" onclick="winOpenNP(this.href,'gallery','width=640,height=480,scrollbars=auto'); return false;" title="Image 2"><img src="http://assets.vw.co.za/models/citigolf/g.13thumb.jpg" width="190" height="127" alt="Image 2" border="0"></a>

*/

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 == 'emosite') {
        features =
            'menubar='          +'yes'+
            ',location='        +'no'+
            ',status='          +'yes'+
            ',toolbar='         +'no'+
            ',scrollbars='      +'no'+
            ',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;
}

// CONTACT US related popups
// Legal Terms & Conditions Window
var contacusPolicyWinHandle = null;
function contacus_policy(url) {
    if (!url) { url = '/contacus/policy.php'; }
    contacusPolicyWinHandle = winOpenNP(url,'contacus_policy','width=450,height=400,scrollbars=yes,resizable=yes');
}

// DEALERS AND SERVICES related popups
// Mastercar Locator (nee AutoLocator) Window
function models_mastercars_autlocator(url) {  // wrapper
	models_mastercars_locator(url);
}
var mastercarsLocatorWinHandle = null;
function models_mastercars_locator(url) {
    if (!url) { url = '/models/mastercars/locator/'; }
    mastercarsLocatorWinHandle = winCenteredPopup(url,'models_mastercars_locator',null,740,500);
}

// ENTHUSIASTS related popups
// E-Shop window
var eshopWinHandle = null;
function enthusiasts_e_shop(url) {
    if (!url) { url = '/enthusiasts/e-shop/'; }
    eshopWinHandle = winCenteredPopup(url,'enthusiasts_e_shop',null,788,450);
}

// MODELS related popups and supporting functions
// Bus tribute
var busWinHandle = null;
function models_bus_tribute(url) {
    if (!url) { url = '/models/bus/tribute/'; }
    busWinHandle = winCenteredPopup(url,'models_bus_tribute',null,750,460);
}

// Caravelle
function models_caravelle() {
    url = '/models/caravelle/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var caravelleHome = window.open(url,'caravelleHome','');
        window.opener = caravelleHome; // trick
    }
}

// Citi Golf Experience
var citigolfWinHandle, game1WinHandle, game2WinHandle, game3WinHandle = null;
function models_citigolf_experience(url) {
    if (!url) { url = '/models/citigolf/experience/'; }
    if (document.images) self.name='citigolfHome';
    citigolfWinHandle = winCenteredPopup(url,'models_citigolf_experience',null,788,521)
}
function models_citigolf() {
    url = '/models/citigolf/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var citigolfHome = window.open(url,'citigolfHome','');
        window.opener = citigolfHome; // trick
    }
}
function citigolfSpecs() {
    url = '/models/citigolf/specs.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var citigolfHome = window.open(url,'citigolfHome','');
        window.opener = citigolfHome; // trick
    }
}
function citigolfPrices() {
    url = '/models/citigolf/prices.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var citigolfHome = window.open(url,'citigolfHome','');
        window.opener = citigolfHome; // trick
    }
}
function launchGame(gameNum) {
    if (gameNum == "game1Window") {
        game1WinHandle = winCenteredPopup('game1.php','models_citigolf_game1Window',null,387,279);
    }
    else if (gameNum == "game2Window") {
        game2WinHandle = winCenteredPopup('game2.php','models_citigolf_game2Window',null,400,300);
    }
    else if (gameNum == "game3Window") {
        game3WinHandle = winCenteredPopup('game3.php','models_citigolf_game3Window',null,440,600);
    }
}

// Citi.com Experience
var citi_comWinHandle = null;
function models_citigolf_citi_com(url) {
    if (!url) { url = '/models/citigolf/citi.com/'; }
    if (document.images) self.name='citigolfHome'; 
    citi_comWinHandle = winCenteredPopup(url,'models_citigolf_citi_com',null,700,440);
}
function citigolf360() {
    url = '/models/citigolf/360view.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var citigolfHome = window.open(url,'citigolfHome','');
        window.opener = citigolfHome; // trick
    }
}
function finance() {
    url = '/finance/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var financeHome = window.open(url,'financeHome','');
        window.opener = financeHome; // trick
    }
}

// Golf
function models_golf() {
    url = '/models/golf/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var golfHome = window.open(url,'golfHome','');
        window.opener = golfHome; // trick
    }
}

// Jetta Experience
var jettaWinHandle = null;
function models_jetta_experience(url) {
    if (!url) { url = '/models/jetta/experience/'; }
    jettaWinHandle = winCenteredPopup(url,'models_jetta_experience',null,680,420);
}
function models_jetta() {
    url = '/models/jetta/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var jettaHome = window.open(url,'jettaHome','');
        window.opener = jettaHome; // trick
    }
}

// GTI Experience
var gtiWinHandle = null;
function models_gti_experience(url) {
    if (!url) { url = '/models/gti/experience/'; }
    gtiWinHandle = winCenteredPopup(url,'models_gti_experience',null,760,520);
}

function models_gti() {
    url = '/models/gti/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var gtiHome = window.open(url,'gtiHome','');
        window.opener = gtiHome; // trick
    }
}

// New Beetle Experience
var newbeetleWinHandle = null;
function models_newbeetle_experience(url) {
    if (!url) { url = '/models/newbeetle/experience/'; }
    newbeetleWinHandle = winCenteredPopup(url,'models_newbeetle_experience',null,640,535);
}
function models_newbeetle() {
    url = '/models/newbeetle/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var newbeetleHome = window.open(url,'newbeetleHome','');
        window.opener = newbeetleHome; // trick
    }
}

// Passat Experience
var passatWinHandle = null;
function models_passat_experience(url) {
    if (!url) { url = '/models/passat/experience/'; }
    passatWinHandle = winCenteredPopup(url,'models_passat_experience',null,788,444);
}
function models_passat() {
    url = '/models/passat/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var passatHome = window.open(url,'passatHome','');
        window.opener = passatHome; // trick
    }
}

// Polo
function models_polo() {
    url = '/models/polo/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var poloHome = window.open(url,'poloHome','');
        window.opener = poloHome; // trick
    }
}

// Polo Classic Experience
var poloclassicWinHandle = null;
function models_poloclassic_experience(url) {
    if (!url) { url = '/models/poloclassic/experience/'; }
    poloclassicWinHandle = winCenteredPopup(url,'models_poloclassic_experience',null,788,444);
}

// Polo Playa soundboards
var soundboardWinHandle = null;
function models_poloplaya_soundboards(url) {
    soundboardWinHandle = winCenteredPopup('popup.php?which='+url,'models_poloplaya_soundboards',null,640,460);
}

// Sharan Experience
var sharanWinHandle = null;
function models_sharan_experience(url) {
    if (!url) { url = '/models/sharan/experience/'; }
    if (document.images) self.name='sharanHome';
    sharanWinHandle = winCenteredPopup(url,'models_sharan_experience',null,640,542);
}
function models_sharan() {
    url = '/models/sharan/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var sharanHome = window.open(url,'sharanHome','');
        window.opener = sharanHome; // trick
    }
}
function sharanSpecs() {
    url = '/models/sharan/specs.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var sharanHome = window.open(url,'sharanHome','');
        window.opener = sharanHome; // trick
    }
}
function sharanPrices() {
    url = '/models/sharan/prices.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var sharanHome = window.open(url,'sharanHome','');
        window.opener = sharanHome; // trick
    }
}
function sharan360() {
    url = '/models/sharan/360view.php';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var sharanHome = window.open(url,'sharanHome','');
        window.opener = sharanHome; // trick
    }
}

// Touareg Experience
var touaregWinHandle = null;
function models_touareg_experience(url) {
    if (!url) { url = '/models/touareg/experience/'; }
    touaregWinHandle = winCenteredPopup(url,'models_touareg_experience',null,785,488);
}
function models_touareg() {
    url = '/models/touareg/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var touaregHome = window.open(url,'touaregHome','');
        window.opener = touaregHome; // trick
    }
}

// Touareg (concept car used within AutoAfrica 2002 microsite)
function models_concepts_touareg() {
    url = '/models/concepts/touareg.php';  // perhaps alter this to link to Touareg within the models section
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var touaregHome = window.open(url,'touaregHome','');
        window.opener = touaregHome; // trick
    }
}

// Touran Experience
var touranWinHandle = null;
function models_touran_experience(url) {
    if (!url) { url = '/models/touran/experience/'; }
    touranWinHandle = winCenteredPopup(url,'models_touran_experience',null,788,444);
}

//Golf Experience
var golfWinHandle = null;
function models_golf_experience(url) {
    if (!url) { url = '/models/golf/experience/'; }
    golfWinHandle = winCenteredPopup(url,'models_golf_experience',null,788,444);
}


// Satellite Navigation
function models_satnav() {
    url = '/models/satnav/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var satnavHome = window.open(url,'satnavHome','');
        window.opener = satnavHome; // trick
    }
}

// Volkswagen Virtual Dealership
var virtualDealershipWinHandle = null;
function models_virtual(url) {
    if (!url) { url = '/models/virtual/'; }
    virtualDealershipWinHandle = winCenteredPopup(url,'models_virtual',null,700,500);
}
function pricesAndOptions() {
    url = '/finance/prices/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var pricesAndOptionsHome = window.open(url,'pricesAndOptionsHome','');
        window.opener = pricesAndOptionsHome; // trick
    }
}
function brochures() {
    url = '/enthusiasts/downloads/brochures/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var brochuresHome = window.open(url,'brochuresHome','');
        window.opener = brochuresHome; // trick
    }
}
function aftersales() {
    url = '/dealersandservices/aftersales/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var aftersalesHome = window.open(url,'aftersalesHome','');
        window.opener = aftersalesHome; // trick
    }
}
function carcare() {
    url = '/dealersandservices/carcare/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var carcareHome = window.open(url,'carcareHome','');
        window.opener = carcareHome; // trick
    }
}
function abr() {
    url = '/dealersandservices/abr/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var abrHome = window.open(url,'abrHome','');
        window.opener = abrHome; // trick
    }
}
function dealerLocator() {
    url = '/dealersandservices/dealerlocator/';
    if (window.opener && !window.opener.closed) {
        window.opener.location = url;
        window.opener.focus();
    }
    else {
        var dealerlocatorHome = window.open(url,'dealerlocatorHome','');
        window.opener = dealerlocatorHome; // trick
    }
}

// FINANCE related popups
// Finance Calculator
var financeCalculatorWinHandle = null;
function finance_calculator(url) {
    if (!url) { url = '/finance/calculator/'; }
    financeCalculatorWinHandle = winCenteredPopup(url,'finance_calculator',null,750,540);
}

// Volkswagensure Vehicle Insurance
var vwSureWinHandle = null;
function finance_vwsure(url) {
    if (!url) { url = '/finance/vwsure/'; }
    vwSureWinHandle = winCenteredPopup(url,'finance_vwsure',null,750,540);
}

// Volkswagen Instant Finance
var vwinstantFinanceWinHandle = null;
function finance_vwinstantfinance(url) {
    if (!url) { url = 'https://www.wesbank.co.za/fastapp/volkswagen/index.asp'; }
    vwinstantFinanceWinHandle = winOpenNP(url,'finance_vwinstantfinance','width=750,height=540,scrollbars=yes,resizable=yes');
}

// Auto Africa 2002
var autoafrica2002WinHandle = null;
function ourworld_autoshows_autoafrica2002(url) {
    if (!url) { url = '/ourworld/autoshows/autoafrica2002/'; }
    autoafrica2002WinHandle = winCenteredPopup(url,'ourworld_autoshows_autoafrica2002',null,750,542);
}

var autoafrica2002MapWinHandle = null;
function ourworld_autoshows_autoafrica2002Map(url) {
    if (!url) { url = '/ourworld/autoshows/autoafrica2002/map.php'; }
    autoafrica2002MapWinHandle = winCenteredPopup(url,'ourworld_autoshows_autoafrica2002Map',null,450,450);
}

// --------- promos --------

// Volkswagen Financial Services Golf and Jetta promotion
var golfjettapromoWinHandle = null;
function promos_golfjetta(url) {
    if (!url) { url = '/promos/golfjetta/?s=hpbanner'; }
	winCenter(700,444);
    var features = 'menubar=no,location=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no,titlebar=no,directories=no,height=444,width=520,left='+leftPos+',top='+topPos;
    golfjettapromoWinHandle = winGenericOpen(url,'promos_golfjetta',features);
}

// Volkswagen Financial Services Passat and Sharan promotion
var passatsharanWinHandle = null;
function promos_passatsharan(url) {
    if (!url) { url = '/promos/passatsharan/?s=hpbanner'; }
	winCenter(700,444);
    var features = 'menubar=no,location=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no,titlebar=no,directories=no,height=444,width=700,left='+leftPos+',top='+topPos;
    passatsharanpromoWinHandle = winGenericOpen(url,'promos_passatsharan',features);
}

// Volkswagen Financial Services general promotion
var financeplanWinHandle = null;
function promos_financeplan(url) {
	winCenter(700,444);
	var features = 'menubar=no,location=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no,titlebar=no,directories=no,height=444,width=520,left='+leftPos+',top='+topPos;
	financeplanWinHandle = winGenericOpen(url,'promos_financeplan',features);
}