﻿//Client-side implementation of the maintenance schedules page
//NOTE: this is unchanged legacy code

var n = navigator, d = document;
var agent = n.userAgent.toLowerCase();

//Browser sniff hash obj
var sniff = {
	bw: {
		ns:d.layers,
		ie:d.all && !d.getElementById,
		ie4:agent.indexOf("MSIE 4.") != -1,
		ie5:agent.indexOf("MSIE 5.") != -1,
		ie6:agent.indexOf("MSIE 6.") != -1,
		dom:d.getElementById,
		ns6:d.getElementById && agent.indexOf("Gecko") != -1
	},
	os: {
		win:agent.indexOf("Win") != -1,
		mac:agent.indexOf("Mac") != -1
	}
};

maint_003750_03_Replace = new Array(
//	PM   S1   S2	//
	'x', 'x', ' ',	'Replace engine oil and filter',
	' ');			// LAST LINE

maint_003750_03_Inspect = new Array(
//	PM   S1   S2	//
	'x', ' ', ' ', 	'All lights',
	'x', ' ', ' ', 	'Brake fluid level',
	'x', ' ', ' ', 	'Clutch fluid',
	'x', ' ', ' ', 	'Differential oil',
	'x', ' ', ' ', 	'Engine air filter',
	'x', ' ', ' ', 	'Engine coolant level/top-off',
	'x', ' ', ' ', 	'Engine drive belts',
	'x', ' ', ' ', 	'Power steering fluid/top-off',
	'x', ' ', ' ', 	'Radiator hoses',
	'x', ' ', ' ', 	'Tires/adjust air pressure',
	'x', ' ', ' ', 	'Transmission fluid/oil',
	'x', ' ', ' ', 	'Washer fluid level/top-off',
	'x', ' ', ' ', 	'Wiper blades',
	' ');			// LAST LINE
	
maint_003750_03_opt = ' ';

maint_007500_06_Replace = new Array(
//	PM   S1   S2	//
	'x', 'x', 'x',	'Replace engine oil and filter',
	'x', ' ', ' ', 	'Road test vehicle',
	'x', 'x', 'x', 	'Rotate tires (except G35 Coupe)',
	' ');			// LAST LINE

maint_007500_06_Inspect = new Array(
//	PM   S1   S2	//
	'x', ' ', ' ', 	'All lights',
	'x', ' ', ' ', 	'Automatic transmission fluid',
	'x', 'x', ' ', 	'Axle & suspension parts',
	'x', ' ', ' ', 	'Battery fluid level/terminals',
	' ', ' ', ' ', 	'Brake lines & cables',
	'x', ' ', ' ', 	'Brake fluid level',
	'x', 'x', ' ', 	'Brake pads, rotors',
	'x', ' ', ' ', 	'Charging/Starting system',
	'x', ' ', ' ', 	'Clutch fluid',
	'x', ' ', ' ', 	'Differential oil',
	'x', 'x', ' ', 	'Drive shaft boots',
	'x', ' ', ' ', 	'Engine air filter',
	'x', ' ', ' ', 	'Engine drive belts',
	'x', 'x', ' ', 	'Exhaust system',
	'x', 'x', ' ', 	'Front suspension ball joints',
	'x', ' ', ' ', 	'Horn operation',
	'x', ' ', ' ', 	'Manual transmission oil',
	'x', ' ', ' ', 	'Power steering fluid/top-off',
	'x', 'x', ' ', 	'Propeller shaft',
	'x', ' ', ' ', 	'Radiator hoses',
	'x', ' ', ' ', 	'Shock absorbers/struts',
	'x', 'x', ' ', 	'Steering gear and linkage',
	'x', 'x', ' ', 	'Steering linkage ball joints',
	'x', ' ', ' ', 	'Transfer case oil (4WD/AWD)',
	'x', ' ', ' ', 	'Washer fluid level/top-off',
	'x', ' ', ' ', 	'Wiper blades',
	' ');			// LAST LINE

maint_007500_06_opt = ' ';

maint_011250_09_Replace = maint_003750_03_Replace;
maint_011250_09_Inspect = maint_003750_03_Inspect;
maint_011250_09_opt = maint_003750_03_opt;


maint_015000_12_Replace = new Array(
//	PM   S1   S2	//
	'x', 'x', 'x',	'Replace engine oil and filter',
	'x', 'x', 'x', 	'Replace in-cabin microfilter (if equipped)',
	'x', ' ', ' ',	'Lubricate all locks/hinges',
	'x', ' ', ' ', 	'Replace engine air filter',
	'x', ' ', ' ', 	'Replace wiper blades',
	'x', 'x', 'x', 	'Rotate tires (except G35 Coupe, Sport)',
	' ');			// LAST LINE

maint_015000_12_Inspect = new Array(
//	PM   S1   S2	//
	'x', ' ', ' ', 	'Air conditioning system',
	'x', ' ', ' ', 	'All lights',
	'x', 'x', 'x', 	'Automatic transmission fluid',
	'x', 'x', ' ', 	'Axle & suspension parts',
	'x', 'x', 'x', 	'Brake lines & cables',
	'x', 'x', 'x', 	'Brake pads, rotors',
	'x', 'x', 'x', 	'Brake light & cruise control switches<sup>1</sup>',
	'x', 'x', 'x', 	'Cruise control vacuum hoses',
	'x', 'x', 'x', 	'Differential oil',
	'x', 'x', 'x', 	'Drive shaft boots (4WD/AWD)',
	'x', ' ', ' ', 	'Engine drive belts',
	'x', 'x', ' ', 	'Exhaust system',
	'x', 'x', ' ', 	'Front suspension ball joints',
	'x', 'x', 'x', 	'Manual transmission oil',
	'x', 'x', 'x', 	'Propeller shaft',
	'x', 'x', ' ', 	'Steering gear and linkage',
	'x', 'x', ' ', 	'Steering linkage ball joints',
	'x', 'x', 'x', 	'Transfer case oil (4WD/AWD)',
	' ');			// LAST LINE

maint_015000_12_opt = '<table border="0"><tr valign="top"><td class="charttext"><i>1</i></td><td class="charttext"><i>G35 sedan, Sport only: Inspect the clearance between the brake pedal and the switches.</i></td></tr></table>';

maint_018750_15_Replace = maint_003750_03_Replace;
maint_018750_15_Inspect = maint_003750_03_Inspect;
maint_018750_15_opt = maint_011250_09_opt;

maint_022500_18_Replace = maint_007500_06_Replace;
maint_022500_18_Inspect = maint_007500_06_Inspect;
maint_022500_18_opt = maint_007500_06_opt;

maint_026250_21_Replace = maint_003750_03_Replace;
maint_026250_21_Inspect = maint_003750_03_Inspect;
maint_026250_21_opt = maint_011250_09_opt;

maint_030000_24_Replace = new Array(
//	PM   S1   S2	//
	'x', 'x', 'x',	'Replace engine oil and filter',
	'x', 'x', 'x', 	'Replace in-cabin microfilter (if equipped)',
	'x', ' ', ' ',	'Lubricate all locks/hinges',
	'x', ' ', ' ', 	'Replace automatic transmission fluid',
	'x', ' ', ' ', 	'Replace differential oil (if applied)',
	'x', 'x', 'x', 	'Replace climate-controlled seat filters (M45/M35/Q45, if so equipped)',
	'x', 'x', 'x', 	'Replace engine air filter',
	'x', ' ', ' ', 	'Replace engine coolant/flush system',
	'x', ' ', ' ', 	'Replace engine drive belts',
	'x', ' ', ' ', 	'Replace manual transmission oil',
	'x', ' ', ' ', 	'Replace radiator cap',
	'x', ' ', ' ', 	'Replace transfer case oil (4WD/AWD)',
	'x', ' ', ' ', 	'Replace wiper blades',
	'x', 'x', 'x', 	'Rotate tires (except G35 Coupe, Sport)',
	'x', ' ', ' ', 	'Optional: flush automatic transmission (flush with ATF)',
	' ');			// LAST LINE

maint_030000_24_Inspect = new Array(
//	PM   S1   S2	//
	'x', ' ', ' ', 	'All lights',
	' ', 'x', 'x', 	'Automatic transmission fluid <sup>1</sup>',
	'x', 'x', 'x', 	'Axle & suspension parts',
	'x', 'x', 'x', 	'Brake lines & cables',
	'x', 'x', 'x', 	'Brake pads, rotors',
	'x', 'x', 'x', 	'Brake light & cruise control switches <sup>2</sup>',
	'x', 'x', 'x', 	'Cruise control vacuum hoses',
	' ', 'x', 'x', 	'Differential oil <sup>1</sup>',
	'x', 'x', 'x', 	'Drive shaft boots (4WD/AWD)',
	'x', 'x', 'x', 	'Exhaust system',
	'x', 'x', 'x', 	'Front suspension ball joints',
	'x', 'x', 'x', 	'Fuel lines/connections',
	'x', 'x', 'x', 	'Fuel tank vapor vent system hoses',
	'x', ' ', ' ', 	'Headlights/adjust if necessary',
	' ', 'x', 'x', 	'Manual transmission oil <sup>1</sup>',
	'x', 'x', 'x', 	'Propeller shaft <sup>2</sup>',
	'x', 'x', 'x', 	'Steering gear and linkage',
	'x', 'x', 'x', 	'Steering linkage ball joints',
	' ', 'x', 'x', 	'Transfer case oil (4WD/AWD) <sup>1</sup>',
	' ');			// LAST LINE

maint_030000_24_opt = '<table border="0"><tr valign="top"><td class="charttext"><i>1</i></td><td class="charttext"><i>Replace (not just inspect) oil/fluid if towing a trailer, using a camper or a car-top carrier, or driving on rough or muddy roads.</i></td></tr><tr valign="top"><td class="charttext"><i>2</i></td><td class="charttext"><i>G35 sedan, Sport only: Inspect the clearance between the brake pedal and the switches.</i></td></tr></table>';


maint_033750_27_Replace = maint_003750_03_Replace;
maint_033750_27_Inspect = maint_003750_03_Inspect;
maint_033750_27_opt = maint_011250_09_opt;

maint_037500_30_Replace = maint_007500_06_Replace;
maint_037500_30_Inspect = maint_007500_06_Inspect;
maint_037500_30_opt = maint_007500_06_opt;

maint_041250_33_Replace = maint_003750_03_Replace;
maint_041250_33_Inspect = maint_003750_03_Inspect;
maint_041250_33_opt = maint_011250_09_opt;

maint_045000_36_Replace = maint_015000_12_Replace;
maint_045000_36_Inspect = maint_015000_12_Inspect;
maint_045000_36_opt = maint_007500_06_opt;

maint_048750_39_Replace = maint_003750_03_Replace;
maint_048750_39_Inspect = maint_003750_03_Inspect;
maint_048750_39_opt = maint_011250_09_opt;

maint_052500_42_Replace = maint_007500_06_Replace;
maint_052500_42_Inspect = maint_007500_06_Inspect;
maint_052500_42_opt = maint_007500_06_opt;

maint_056250_45_Replace = maint_003750_03_Replace;
maint_056250_45_Inspect = maint_003750_03_Inspect;
maint_056250_45_opt = maint_011250_09_opt;

maint_060000_48_Replace = maint_030000_24_Replace;
maint_060000_48_Inspect = maint_030000_24_Inspect;
maint_060000_48_opt = maint_030000_24_opt;

maint_063750_51_Replace = maint_003750_03_Replace;
maint_063750_51_Inspect = maint_003750_03_Inspect;
maint_063750_51_opt = maint_011250_09_opt;

maint_067500_54_Replace = maint_007500_06_Replace;
maint_067500_54_Inspect = maint_007500_06_Inspect;
maint_067500_54_opt = maint_007500_06_opt;

maint_071250_57_Replace = maint_003750_03_Replace;
maint_071250_57_Inspect = maint_003750_03_Inspect;
maint_071250_57_opt = maint_011250_09_opt;

maint_075000_60_Replace = maint_015000_12_Replace;
maint_075000_60_Inspect = maint_015000_12_Inspect;
maint_075000_60_opt = maint_015000_12_opt;

maint_078750_63_Replace = maint_003750_03_Replace;
maint_078750_63_Inspect = maint_003750_03_Inspect;
maint_078750_63_opt = maint_011250_09_opt;

maint_082500_66_Replace = maint_007500_06_Replace;
maint_082500_66_Inspect = maint_007500_06_Inspect;
maint_082500_66_opt = maint_007500_06_opt;

maint_086250_69_Replace = maint_003750_03_Replace;
maint_086250_69_Inspect = maint_003750_03_Inspect;
maint_086250_69_opt = maint_011250_09_opt;

maint_090000_72_Replace = maint_030000_24_Replace;
maint_090000_72_Inspect = maint_030000_24_Inspect;
maint_090000_72_opt = maint_030000_24_opt;

maint_093750_75_Replace = maint_003750_03_Replace;
maint_093750_75_Inspect = maint_003750_03_Inspect;
maint_093750_75_opt = maint_011250_09_opt;

maint_097500_78_Replace = maint_007500_06_Replace;
maint_097500_78_Inspect = maint_007500_06_Inspect;
maint_097500_78_opt = maint_007500_06_opt;

maint_101250_81_Replace = maint_003750_03_Replace;
maint_101250_81_Inspect = maint_003750_03_Inspect;
maint_101250_81_opt = maint_011250_09_opt;


maint_105000_84_Replace = new Array(
//	PM   S1   S2	//
	'x', 'x', 'x',	'Replace engine oil and filter',
	'x', 'x', 'x', 	'Replace in-cabin microfilter',
	'x', ' ', ' ',	'Lubricate all locks/hinges',
	'x', ' ', ' ', 	'Replace engine air filter',
	'x', ' ', ' ', 	'Replace wiper blades',
	'x', 'x', 'x', 	'Rotate tires (except G35 Coupe, Sport)',
	'x', 'x', 'x',	'Replace Spark Plugs',
	' ');			// LAST LINE

maint_105000_84_Inspect = maint_015000_12_Inspect;
maint_105000_84_opt = maint_015000_12_opt;


maint_108750_87_Replace = maint_003750_03_Replace;
maint_108750_87_Inspect = maint_003750_03_Inspect;
maint_108750_87_opt = maint_011250_09_opt;

maint_112500_90_Replace = maint_007500_06_Replace;
maint_112500_90_Inspect = maint_007500_06_Inspect;
maint_112500_90_opt = maint_007500_06_opt;

maint_116250_93_Replace = maint_003750_03_Replace;
maint_116250_93_Inspect = maint_003750_03_Inspect;
maint_116250_93_opt = maint_011250_09_opt;

maint_120000_96_Replace = maint_060000_48_Replace;
maint_120000_96_Inspect = maint_060000_48_Inspect;
maint_120000_96_opt = maint_060000_48_opt;


function populateText(maintArray) {

//	headingContent2 = '45,000 Miles or 36 Months';
//	headingContent2 = '&nbsp;<b>' + parseFloat(maintArray.substring(6,9)) + ',' + maintArray.substring(9,12) + ' Miles or ' + parseFloat(maintArray.substring(13,15)) + ' Months</b>';
	headingContent2 = '<table width="100%" cellpadding=0 cellspacing=0><tr><td class="tTableText" valign="bottom" align="center"><b>Recommended Services for your Infiniti at ' + parseFloat(maintArray.substring(6,9)) + ',' + maintArray.substring(9,12) + ' Miles or ' + parseFloat(maintArray.substring(13,15)) + ' Months</td><b>';
//	headingContent2 += '<td style="text-align:right;"><a href="#" target="_blank"><img src="/img/supp/common/btn_print.gif" alt="Print"  onload="setOverSrc(this);" /></a></td>'
	headingContent2 += '</tr></table>';
	updateContent('heading2', headingContent2);  // update heading2

  optionalText2 = eval(maintArray + '_opt');
  optionalText2 += '<br /><div class="gInformationText">Equipment varies by model. Perform only those operations that apply to your vehicle.</div>';
	updateContent('optionaltext', optionalText2);  // update optional text on bottom.

	buildChart('Replace', maintArray);
	buildChart('Inspect', maintArray);

}

function buildChart(CHART, MAINTARRAY){
	MAINTARRAY = eval(MAINTARRAY+'_'+CHART);
	content = "";
//	content += '<table border=0 cellpadding=0 cellspacing=0><tr><td width=5></td><td width=318 height=20 class="charttext"><b>'+ CHART +'</b></td><td width=1></td><td width=25 align="center"></td><td width=1></td></tr>';
//	content += '<table width="100%" cellpadding=0 cellspacing=0><tr><td width=5></td><td height=20 class="charttext"><b>'+ CHART +'</b></td><td width=1></td><td width=25 align="center" class="charttext"><b>PM</b></td><td width=1></td><td width=25 align="center" class="charttext"><b>S1</b></td><td width=1></td><td width=25 align="center" class="charttext"><b>S2</b></td><td width=1></td></tr>';
	content += '<table width="100%" cellpadding=0 cellspacing=0 class="tSuppTable"><tr><td class="tTabularHeader tTableColumnLeft">'+ CHART +'</b></td><td width="65" class="tTabularHeader tTableColumnLeft" style="text-align:center;font-weight:normal;padding-left:0;">Premium</td><td width="75" class="tTabularHeader tTableColumnLeft" style="text-align:center;font-weight:normal;padding-left:2;">Schedule 1</td><td width="75" class="tTabularHeader" style="text-align:center;font-weight:normal;padding-left:2;">Schedule 2</td></tr>';
	for (var i=0; i<MAINTARRAY.length-1; i=i+4){
		if (i%8 == 0) oddEven = "tTabularGreyRow";
		else oddEven = "tTabularWhiteRow"
		content += '<tr>';
		content += '<td class="tTableText '+oddEven+' tTableColumnLeft">'+MAINTARRAY[i+3]+'<sup>&nbsp;</sup></td>';
		content += '<td align="center" class="tTableText '+oddEven+' tTableColumnLeft" style="padding-left:0;">'+checkDot(MAINTARRAY, i);
		content += '<td align="center" class="tTableText '+oddEven+' tTableColumnLeft" style="padding-left:0;">'+checkDot(MAINTARRAY, i+1);
		content += '<td align="center" class="tTableText '+oddEven+'" style="padding-left:0;">'+checkDot(MAINTARRAY, i+2);
		content += '</tr>';
	}
	content += '</table>';
	updateContent(CHART, content);
}

function checkDot(ARRAYNAME, N) {
	maintArray = eval(ARRAYNAME);
	if (maintArray[N] == 'x' || maintArray[N] == 'X'){
		return '<b>&#149;</b>';
	} else {
		return '&nbsp;';
	}
}

function updateContent(lyrName, content){
	var lyrObj = (sniff.bw.ns)?document[lyrName].document:sniff.bw.ie?d.all[lyrName]:d.getElementById(lyrName);
	if (sniff.bw.ns) {
		lyrObj.close();
		lyrObj.write(content);
		lyrObj.close();
	} else {
		lyrObj.innerHTML = content;
	}
	SOAAdjustHeight();
}