var curPopupWindow = null;
var simplePopupWindow = null;

/*
 openPopupWithFeatures: open a popup window and enforce windows features and width and height
 */
function openPopupWithFeatures(url, name, features, closeOnFocus){
    closePopup();

    if (closeOnFocus) {
        curPopupWindow = window.open(url, name, features, false);
        curPopupWindow.focus();
    } else {
		/* assign the open window to a dummy var so when closePopup() is called it won't be assigned to curPopupWindow */
        win = window.open(url, name, features, false);
        win.focus();
    }
}

/*
  openSimplePopup: Opens a simple popup with no width/height restrictions or features.  Equivalent to opening a new browser window.
 */
function openSimplePopup(url, name)
{
	simplePopupWindow = window.open(url,name);
	simplePopupWindow.focus();
}

function openImagePopup(url, name) {
    features = "width=400,height=550,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no";
	openPopupWithFeatures(url, name, features, true);
}

/* 
   closePopup: Closes current popup, usually called before opening a popup to clean up last popup which prevent many popups up at once.
*/
function closePopup() {
    if (curPopupWindow != null) {

        if (!curPopupWindow.closed) 
        {
            curPopupWindow.close();
        }
        curPopupWindow = null;
    }
}

/*TBT page popup*/
function openPopupWithTBTFeatures(url2, name, features, closeOnFocus){
    closePopup();

    if (closeOnFocus) {
		
        curPopupWindow = window.open(url2, name, features, false);
		curPopupWindow.focus();
        
    } else {
		/* assign the open window to a dummy var so when closePopup() is called it won't be assigned to curPopupWindow */
        win = window.open(url2, name, features, false);
        win.focus();
    }
}

function openTBTPopup(url, name, tab)
{
	url2 = url + "?tab=" + tab;
    features = "width=400,height=600,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=no";
	openPopupWithTBTFeatures(url2, name, features, true);
}

/* ONSTAR TREATMENT SPECIFIC FUNCTIONS. These functions are being referenced inside of the flash to override a tracking issue. -DR  */


//TOP LEFT SIDE LINK for the US_EN and CA_EN treatment pages. For the divisional pages it is the "DRIVING CONFIDENCE" tile. -- DR.

function openServicesTreatment() { 
	
	if (window.location.href.indexOf("canada_english")>=0) {
	//alert ("CA_EN TEST Services Popup");
	
	url = "/us_english/jsp/services/index.jsp?make=onstar&model=homepage&deepLink=overview&custom=treatment";
	features = "width=675,height=461,location=no,menubar=no,status=no,toolbar=no,scrollbars=no,resizable=no";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | SERVICES EXPERIENCE'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | SERVICES EXPERIENCE';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | SERVICES EXPERIENCE';s_prop6='ONSTAR TREATMENT | SERVICES EXPERIENCE';s_prop25='ONSTAR';}

	
sendAnalyticsEvent();
	
}


//TOP RIGHT SIDE LINK TREATMENT PAGES

function openLearnMore() { 
	
	
	if (window.location.href.indexOf("canada_english")>=0) {
	//alert ("CA_EN TEST Learn More Popup");
	url = "/canada_english/jsp/index.jsp";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | HOME'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | HOME';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | HOME';s_prop6='ONSTAR TREATMENT | HOME';s_prop25='ONSTAR';}

sendAnalyticsEvent();
	
}


// Function that calls a brand and a make where applicable. -- DR.
function openBrands(brand,makeID) { 

if (brand=="bu" && makeID==null) {
	//alert ("CA_EN TEST BU ");
	url = "http://www.gmcanada.com/gm/english/vehicles/buick/?adv=72346";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | BUICK'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | BUICK';s_prop25='ONSTAR';
	
} else if (brand=="ca" && makeID==null) {
	//alert ("CA_EN TEST CA");
	url = "http://www.gmcanada.com/gm/english/vehicles/cadillac/?adv=72349";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | CADILLAC'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | CADILLAC';s_prop25='ONSTAR'; 

} else if (brand=="ch" && makeID==null) {
	//alert ("CA_EN TEST CH");
	url = "http://www.gmcanada.com/gm/english/vehicles/chevrolet/?adv=72348";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | CHEVROLET'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | CHEVROLET';s_prop25='ONSTAR';
		
			
			
} else if (brand=="gc" && makeID==null) {
	//alert ("CA_EN TEST GC");
	url = "http://www.gmcanada.com/gm/english/vehicles/gmc/?adv=72347";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | GMC'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | GMC';s_prop25='ONSTAR';
		
		
} else if (brand=="hu" && makeID==null) {
	//alert ("CA_EN TEST HU");
	url = "http://www.gmcanada.com/gm/english/vehicles/hummer/?adv=72350";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | HUMMER'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | HUMMER';s_prop25='ONSTAR';

} else if (brand=="pg" && makeID==null) {
	//alert ("CA_EN TEST PG");
	url = "http://www.gmcanada.com/gm/english/vehicles/pontiac/?adv=72345";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | PONTIAC'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | PONTIAC';s_prop25='ONSTAR';

} else if (brand=="sb" && makeID==null) {
	//alert ("CA_EN TEST PG");
	url = "http://gmcanada.com/ss/gm/homepage.do?lang=en_CA&brand=saab&adv=72480";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | SAAB'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | SAAB';s_prop25='ONSTAR';

}else if (brand=="sa" && makeID==null) {
	//alert ("CA_EN TEST PG");
	url = "http://gmcanada.com/ss/gm/homepage.do?lang=en_CA&brand=saturn&adv=72479";
	features = "width=1024,height=768,location=yes,menubar=yes,status=yes,toolbar=yes,scrollbars=yes,resizable=yes";
	openPopupWithFeatures(url, name, features, true);
	
	s_pageName='ONSTAR | TREATMENT | ONSTAR | GM VEHICLES | SATURN'; s_prop1='ONSTAR TREATMENT | ONSTAR';s_prop2='ONSTAR TREATMENT | GM VEHICLES';s_prop3='ONSTAR TREATMENT';s_prop4='ca_en';s_prop5='ONSTAR TREATMENT | ONSTAR | GM VEHICLES';s_prop6='ONSTAR TREATMENT | GM VEHICLES | SATURN';s_prop25='ONSTAR';

}
sendAnalyticsEvent();
}






