/****************************************************************************************
	Location: MMCShared/Script
	Library: MMCLinks.js
	Conventions: Functions in this javascript library should be prefixed with 'mmclinks_'

*****************************************************************************************/

var baseCorpUrl = 'www.mitsubishi-motors.ca';
var baseConfigUrl = 'configurator.mitsubishi-motors.ca';
var baseComparUrl = 'comparator.mitsubishi-motors.ca';

/*********************************************
Corporate Site Links
*********************************************/
function mmclinks_DealerInformation(provid, compid, langid) {
	var strURL;
	var strOptions;
	if ((provid.length==0) || (compid.length==0)) {
		return false;
	}
	strURL = '/DealerLocator/DealerInfo.aspx?lng=' + langid + '&popup=true&provid=' + provid + '&compid=' + compid;
	strOptions='width=730,height=570,scrollbars=yes,resizable=yes,left=200,top=100,screenx=200,screeny=100'; 
	mmclinks_OpenNewWindow(strURL, 'dealerinfo', strOptions);
}

function mmclinks_DealerLocator(LangID){
	var strurl, strname;
	strname='corporate';
	strurl=mmclinks_GetBaseCorporateURL() + 'DealerLocator/DealerMap.aspx?lng=' + LangID;
	mmclinks_OpenNewWindow(strurl, strname, '');
}

function mmclinks_PeaceOfMind(LangID) {
	var strurl, strname;
	strname='corporate';
	strurl=mmclinks_GetBaseCorporateURL() + 'PeaceOfMind/RoadsideAssistance.aspx?lng=' + LangID;
	mmclinks_OpenNewWindow(strurl, strname, '');
}

function mmclinks_ModelPhotoGallery(LangID, ModelYear, ModelName) {
	var strurl, strname;
	strname='corporate';
	strurl=mmclinks_GetBaseCorporateURL() + ModelYear + '/' + ModelName + '/PhotoGallery.aspx?lng=' + LangID+'&gallery=int01';
	mmclinks_OpenNewWindow(strurl, strname, '');
}

function mmclinks_CopyrightWindow(LangID){
	var strurl, strname, stroptions;
	stroptions = 'scrollbars=yes,resizable=no,width=630,height=400,left=200,top=100,screenx=200,screeny=100,toolbar=0,menubar=0';
	strname = 'copyright';
	strurl = mmclinks_GetBaseCorporateURL() + 'Copyright/Copyright.aspx?lng=' + LangID + '&popup=True';
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_PrivacyWindow(LangID){
	var strurl, strname, stroptions;
	stroptions = 'scrollbars=yes,resizable=no,width=630,height=600,left=200,top=100,screenx=200,screeny=100,toolbar=0,menubar=0';
	strname = 'privacy';
	strurl = mmclinks_GetBaseCorporateURL() + 'Privacy/Privacy.aspx?lng=' + LangID + '&popup=True';
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_ProspectWindow(LangID, sourceid){
	var strurl, strname, stroptions, width, height;

	switch(sourceid) {
		case 16://2007 Outlander Sitelet
			width = 680;
			height = 711;
			break;
		default:
			width = 660;
			height = 700;
			break;
	}
	var x_offset = (screen.width - width)/2.0;
	var y_offset = (screen.height - height)/2.0;
	if(x_offset < 0.0) x_offset=0;
	if(y_offset < 0.0) y_offset=0;
	stroptions = 'scrollbars=yes,resizable=no,width='+width+',height='+height+',left='+ x_offset +',top='+ y_offset +',screenx='+ x_offset +',screeny='+ y_offset +',toolbar=0,menubar=0';
	strname = 'prospect';
	strurl = mmclinks_GetBaseCorporateURL() + 'Prospect/ProspectPopup.aspx?lng=' + LangID + '&popup=True' + '&sourceid=' + sourceid;
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_SendToAFriendWindow(LangID, Model){
	var strurl, strname, stroptions;
	stroptions = 'scrollbars=yes,resizable=no,width=640,height=450,left=200,top=100,screenx=200,screeny=100,toolbar=0,menubar=0';
	strname = 'sendtoafriend';
	strurl ='http://alphademo2.dmt.ca/SendToAFriend/SendToAFriendPopup.aspx?lng=' + LangID + '&popup=True' + '&model=' + Model;
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_WhereYouCanSeeThe2008LancerWindow(LangID){
	var strurl, strname, stroptions;
	if (LangID==2){
	stroptions = 'scrollbars=no,resizable=no,width=623,height=447,left=200,top=100,screenx=200,screeny=100,toolbar=0,menubar=0';
	}
	else {
	stroptions = 'scrollbars=no,resizable=no,width=623,height=490,left=200,top=100,screenx=200,screeny=100,toolbar=0,menubar=0';
	}
	strname = 'whereyoucanseethe2008lancer';
	strurl = mmclinks_GetBaseCorporateURL() + '/WhereYouCanSeeThe2008Lancer.aspx?lng=' + LangID + '&popup=True';
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_2007OutlanderSiteletPopup(LangID){
	var strbaseurl, strurl, strname, stroptions, width, height;
	//hard code the offset so that it looks good in Windows.
	width = screen.width - 10;
	height= screen.height - 60;
	stroptions = 'scrollbars=no,resizable=yes,width='+width+',height='+height+',left=0,top=0,screenx=0,screeny=0,toolbar=0,menubar=0';
	strname = '2007outlandersitelet';
	if(LangID==3) {
		strbaseurl = mmclinks_GetBaseURL('www.allnewoutlander.ca', '20016', '20016', '30016');
		strurl = strbaseurl + 'FR/Default.aspx';
	}
	else {
		strbaseurl = mmclinks_GetBaseURL('www.allnewoutlander.ca', '20016', '20016', '30016');
		strurl = strbaseurl + 'EN/Default.aspx';
	}
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

function mmclinks_GetBaseCorporateURL(){
	return mmclinks_GetBaseURL(baseCorpUrl, '20471', '20471', '30471');
}

/*********************************************
Configurator Links
*********************************************/

//There should be one function only for Build and Price which accepts many optional
//parameters for things like Model ID or Retailer ID.  Depending on parameters passed,
//it builds the query string accordingly.

function mmclinks_BuildAndPrice(){
	//calls mmclinks_GetBaseConfiguratorURL() and appends the query string to the end
}

function mmclinks_GetBaseConfiguratorURL(Year, ModelID, TrimID, LangID){
	//return mmclinks_GetBaseURL('configurator.mitsubishicars.ca', '20475', '20475') + '/BuildYourMitsubishi.aspx?TimePeriodID='+ Year + '&ModelID=' + ModelID + '&TrimID=' + TrimID;
	return mmclinks_GetBaseURL(baseConfigUrl, '20475', '20475','30475') + '/BuildYourMitsubishi.aspx?TimePeriodID='+ Year + '&ModelID=' + ModelID + '&TrimID=' + TrimID + '&lng=' + LangID;
}
function mmclinks_NewConfiguratorWindow(Year, ModelID, TrimID, LangID)
{
	var window_width = 910;
	var window_height = 700;
	
	if (typeof(Year) == "undefined"){ Year=""; }
	if (typeof(ModelID) == "undefined"){ ModelID=""; }
	if (typeof(TrimID) == "undefined"){ TrimID=""; }
	var x_offset = (screen.width - window_width)/2.0;
	var y_offset = (screen.height - window_height)/2.0;
	if(x_offset < 0.0) x_offset=0;
	if(y_offset < 0.0) y_offset=0;
	var window_params = 'width=' + window_width + ',height=' + window_height + ',left=' + x_offset + ',top=' + y_offset + ',scrollbars=yes,location=no,toolbar=no,resizable=no,menubar=no,status=yes';
	var win = window.open(mmclinks_GetBaseConfiguratorURL(Year, ModelID, TrimID, LangID), 'MitsubishiConfigurator', window_params);
	if(win)
		win.focus();
}

function mmclinks_NewConfiguratorWindowWithSplash(Year, ModelID, TrimID, LangID)
{

	mmclinks_NewConfiguratorWindow(Year, ModelID, TrimID, LangID);
	return;
	
	var window_width = 910;
	var window_height = 700;
	
	if (typeof(Year) == "undefined"){ Year=""; }
	if (typeof(ModelID) == "undefined"){ ModelID=""; }
	if (typeof(TrimID) == "undefined"){ TrimID=""; }
	var x_offset = (screen.width - window_width)/2.0;
	var y_offset = (screen.height - window_height)/2.0;
	if(x_offset < 0.0) x_offset=0;
	if(y_offset < 0.0) y_offset=0;
	var window_params = 'width=' + window_width + ',height=' + window_height + ',left=' + x_offset + ',top=' + y_offset + ',scrollbars=yes,location=no,toolbar=no,resizable=no,menubar=no,status=yes';
	var base_configurator_url = mmclinks_GetBaseURL(baseConfigUrl, '20475', '20475','30475');
	var configurator_params = '?BaseConfiguratorURL=' + base_configurator_url + '&TimePeriodID='+ Year + '&ModelID=' + ModelID + '&TrimID=' + TrimID + '&lng=' + LangID;
	var splash_page_url = mmclinks_GetBaseCorporateURL() + 'ConfiguratorSplash.aspx' + configurator_params;
	var win = window.open(splash_page_url, 'MitsubishiConfigurator', window_params);
	if(win)
		win.focus();
}


/*********************************************
Shared Functions
*********************************************/


function mmclinks_GetBaseURL(strExternalDomain, strTestingPort, strStagingPort, strExternalDemoPort){
	var strDomain;

	//the line below has not been tested
	strDomain = document.domain;
	switch(strDomain) {		
		case 'localhost':
			return 'http://localhost:' + strTestingPort + '/';
		case 'windshield.dmtgroup.dmt.ca':
			return 'http://windshield.dmtgroup.dmt.ca:' + strTestingPort + '/';
		case 'windshield':
			return 'http://windshield:' + strTestingPort + '/';
		case 'build.dmtgroup.dmt.ca':
			return 'http://build.dmtgroup.dmt.ca:' + strTestingPort + '/';
		case 'build':
			return 'http://build:' + strTestingPort + '/';
		case 'staging.dmtgroup.dmt.ca':
			return 'http://staging.dmtgroup.dmt.ca:' + strStagingPort + '/';
		case 'staging':
			return 'http://staging:' + strStagingPort + '/';
		case 'studio.dmt.ca':
			return 'http://studio.dmt.ca:' + strStagingPort + '/';
		case 'demo1.dmt.ca':
			return 'http://demo1.dmt.ca:' + strExternalDemoPort + '/';
		case 'alphademo1.dmt.ca':
			return 'http://alphademo1.dmt.ca/';
		case 'alphademo2.dmt.ca':
			return 'http://alphademo2.dmt.ca/';
		default:
			return 'http://' + strExternalDomain + '/';
	}	
}

function mmclinks_OpenNewWindow(strWinURL, strWinName, strOptions){
	var win;	
	if(strOptions == ''){
		strOptions = 'scrollbars=yes,location=yes,toolbar=yes,width=900,height=700,resizable=yes,menubar=yes,status=yes'
	}
	win = window.open(strWinURL, strWinName, strOptions);
	win.focus();
}

//MFGTrimID -- Optional
function mmclinks_TestDrive(LangID, MFGModelID, ModelYear, MFGTrimID){

	if (typeof(MFGTrimID) == "undefined") { MFGTrimID=""; }
	
	var strurl, strname, stroptions, width, height;
	width=200;
	height=750;
	
	var x_offset = (screen.width - width)/2.0;
	var y_offset = (screen.height - height)/2.0;
	if(x_offset < 0.0) x_offset=0;
	if(y_offset < 0.0) y_offset=0;
	stroptions = 'scrollbars=yes,resizable=yes,width=550,width='+width+',height='+height+',left='+ x_offset +',top='+ y_offset +',screenx='+ x_offset +',screeny='+ y_offset +',toolbar=0,menubar=0';
	strname = 'testdrive';
	strurl = mmclinks_GetBaseCorporateURL() + 'Showroom/TestDrive.aspx?lng=' + LangID + '&popup=True' + '&mfgmodelid='+ MFGModelID + '&myear=' + ModelYear + '&mfgtrimid='+ MFGTrimID;
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}


/*********************************************
Comparator Functions
*********************************************/
function mmclinks_ComparatorWindow(LangID, ModelName, ModelYear){
	var language_id = 22;//Default English
	if(LangID==3)
		language_id = 26;//French
		
	if(ModelName=='Lancer_Sportback')
		ModelName = 'Lancer+Sportback';
	if(ModelName=='Eclipse_Spyder')
		ModelName = 'Eclipse+Spyder';
	
	var strurl, strname, stroptions;
	stroptions = 'scrollbars=yes,resizable=no,location=no,toolbar=no,menubar=no,status=yes,width=900,height=630,left=0,top=0,screenx=200,screeny=100';
	strname = 'comparator';
	
	strurl = mmclinks_GetBaseURL(baseComparUrl, 20004, 20004, 30004);
	strurl += '/browser.asp?language_id=' + language_id + '&compareclicked=true&guid=&screen=select&category=select_version&country=&translated_country=&translated_make=Mitsubishi&localmake=Mitsubishi&make=MITSUBISHI&model=' + '&localmodel='+ ModelName + '&translated_model=' + ModelName;
	mmclinks_OpenNewWindow(strurl,strname,stroptions);
}

/*********************************************
DCT Functions
*********************************************/
function mmclinks_RequestInfo(BaseURL, PID, LangID, SkinID, DealerID, SourceID){
	var strurl, strname, stroptions;
	
	stroptions = 'scrollbars=yes,resizable=no,location=no,toolbar=no,menubar=no,status=yes,width=686,height=700,left=0,top=0,screenx=200,screeny=100';
	strname = 'dctwindow';
	
	strurl = BaseURL + '?pid=' + PID + '&sourceid=' + SourceID + '&dealerid=' + DealerID + '&lng=' + LangID + '&skinid=' + SkinID;
	mmclinks_OpenNewWindow(strurl, strname, stroptions);
}


function popUp(strURL, strType, strWidth, strHeight, winName, leftPos, topPos) {
var newWin;
    var strOptions="";
    if (strType=="nocontrols") {
        strOptions="scrollbars,resizable,height="+ strHeight+",width="+strWidth+",left="+leftPos+",top="+topPos;
    }
    if (strType=="controls") {
        strOptions="toolbar,menubar,location,scrollbars,resizable,height="+strHeight+",width="+strWidth+",left="+leftPos+",top="+topPos;
    }
    newWin = window.open("", winName, strOptions);
    newWin.close();
    newWin = window.open(strURL, winName, strOptions);
    if (window.focus)
    {
    newWin.focus()
    }
}