/*
 * common psuedo constants for configuration javascripts.
 */
var BUTTON_ACTION = "buttonAction";
/* buttonAction values
 */
var NEXT_BTN = "continue";
var CONTINUE_BTN = "continue";
var PREVIOUS_BTN = "previous";
var FINISH_BTN = "finish";
var SAVE_NEW_BTN = "save new";
var SAVE_BTN = "save";
/*
 * Vehicle codes to use
 */
var MAZDA_MIATA = 'MIA';
var MAZDA_PROTEGE = 'PRO';
var MAZDA_PROTEGE5 = 'PR5';
var MAZDA_MPV = 'MP2';
var MAZDA_TRIBUTE = 'TRB';
var MAZDA_TRUCK = 'TRK';
var MAZDA_MAZDA6 = 'MZ6';
var MAZDA_MAZDA6_5DOOR = 'M6H';
var MAZDA_MAZDA6_WAGON = 'M6W';
var MAZDA_RX8 = 'RX8';
var MAZDA_MAZDA3 = 'MZ3';
var MAZDA_MAZDA3_4DOOR = 'M3S';
var MAZDA_MAZDA3_5DOOR = 'M3H';
var MIATA_SPEED_05 = 'MSM';
var MAZDA_SPEED_6 = 'MS6';
var MAZDA_5 = 'MZ5';
var MAZDA_CX7 = 'CX7';
/*
 * Miscellaneous
 */
var FEATURE = 'feature';
var EXTERIOR_360 = 'ext360';
var INTERIOR_360 = 'int360';
var BROCHURE = 'brochure';
var CREDIT = 'CA';
var PAYMENTS = 'PE';

function setVal( field, value ) {
	eval('document.configForm.'+field).value = value;
	return true;
}

function LinkObj( idcode, feature, int360, ext360, brochure, learn ) {
	this.idcode = idcode;
	this.feature = feature;
	this.int360 = int360;
	this.ext360 = ext360;
	this.brochure = brochure;
    this.learn = learn;
}

var linkObjs =  new Array();
linkObjs[0] = new LinkObj( 'PRO', 'veh_specs_PRO.pdf', 'PRO_Interior.mov', 'PRO_Exterior.mov', '2003_protege_brochure.pdf', 'pro' );
linkObjs[1] = new LinkObj( 'PR5', 'veh_specs_PR5.pdf', 'PR5_Interior.mov', 'PR5_Exterior.mov', '2003_protege5_brochure.pdf', 'pr5' );
linkObjs[2] = new LinkObj( 'PRZ', 'veh_specs_PRZ.pdf', 'MZSP_Interior.mov', 'MZSP_Exterior.mov', '2003_mzsp_brochure.pdf', 'mzsp' );
linkObjs[3] = new LinkObj( 'MZ6', 'veh_specs_MZ6.pdf', 'MZ6_Interior.mov', 'MZ6_Exterior.mov', '2005_mazda6_brochure.pdf', 'mz6' );
linkObjs[4] = new LinkObj( 'MIA', 'veh_specs_MIA.pdf', 'MIA_Interior.mov', 'MIA_Exterior.mov', '2005_miata_brochure.pdf', 'mia' );
linkObjs[5] = new LinkObj( 'TRB', 'veh_specs_TRB.pdf', 'TRI_Interior.mov', 'TRI_Exterior.mov', '2005_tribute_brochure.pdf', 'tri' );
linkObjs[6] = new LinkObj( 'MP2', 'veh_specs_MP2.pdf', 'MPV_Interior.mov', 'MPV_Exterior.mov', '2005_mpv_brochure.pdf', 'mpv' );
linkObjs[7] = new LinkObj( 'TRK', 'veh_specs_TRK.pdf', 'TRU_Interior.mov', 'TRU_Exterior.mov', '2005_truck_brochure.pdf', 'tru' );
linkObjs[8] = new LinkObj( 'B23', 'veh_specs_TRK.pdf', 'TRU_Interior.mov', 'TRU_Exterior.mov', '2005_truck_brochure.pdf', 'tru' );
linkObjs[9] = new LinkObj( 'B30', 'veh_specs_TRK.pdf', 'TRU_Interior.mov', 'TRU_Exterior.mov', '2005_truck_brochure.pdf', 'tru' );
linkObjs[10] = new LinkObj( 'B40', 'veh_specs_TRK.pdf', 'TRU_Interior.mov', 'TRU_Exterior.mov', '2005_truck_brochure.pdf', 'tru' );
linkObjs[11] = new LinkObj( 'RX8', 'veh_specs_RX8.pdf', 'RX8_Interior.mov', 'RX8_Exterior.mov', '2005_rx8_brochure.pdf', 'rx8' );
linkObjs[12] = new LinkObj( 'M3S', 'veh_specs_M3S.pdf', 'M3S_Interior.mov', 'M3S_Exterior.mov', '2005_mazda3_brochure.pdf', 'm3s' ); /* scr1967 */
linkObjs[13] = new LinkObj( 'M3H', 'veh_specs_M3H.pdf', 'M3H_Interior.mov', 'M3H_Exterior.mov', '2005_mazda3_brochure.pdf', 'm3h' ); /* scr1967 */
linkObjs[14] = new LinkObj( 'M6H', 'veh_specs_M6H.pdf', 'M6H_Interior.mov', 'M6H_Exterior.mov', '2005_mazda6_brochure.pdf', 'm6h' ); /* scr2176 */
linkObjs[15] = new LinkObj( 'M6W', 'veh_specs_M6W.pdf', 'M6W_Interior.mov', 'M6W_Exterior.mov', '2005_mazda6_brochure.pdf', 'm6w' ); /* scr2176 */
linkObjs[16] = new LinkObj( 'MSM', 'veh_specs_MSM.pdf', 'MSM_Interior.mov', 'MSM_Exterior.mov', '2004_miz_brochure.pdf', 'msm' );
linkObjs[17] = new LinkObj( 'MZ5', 'veh_specs_MZ5.pdf', 'MZ5_Interior.mov', 'MZ5_Exterior.mov', '2006_mz5_brochure.pdf', 'mz5' ); /* scr3318 */
linkObjs[18] = new LinkObj( 'MS6', 'veh_specs_MS6.pdf', 'MS6_Interior.mov', 'MS6_Exterior.mov', '2006_ms6_brochure.pdf', 'ms6' ); /* scr3318 */
linkObjs[19] = new LinkObj( 'MX5', 'veh_specs_MX5.pdf', 'MX5_Interior.mov', 'MX5_Exterior.mov', '2006_mx5_brochure.pdf', 'mx5' ); /* scr3318 */
linkObjs[20] = new LinkObj( 'CX7', 'veh_specs_CX7.pdf', 'CX7_Interior.mov', 'CX7_Exterior.mov', '2007_cx7_brochure.pdf', 'cx7' ); /* scr3943 */
linkObjs[21] = new LinkObj( 'TRH', 'veh_specs_TRH.pdf', 'TRI_Interior.mov', 'TRB_Exterior.mov', '2005_tribute_brochure.pdf', 'tri' );
linkObjs[22] = new LinkObj( 'CX9', 'veh_specs_CX9.pdf', 'CX9_Interior.mov', 'CX9_Exterior.mov', '2008_cx9_brochure.pdf', 'cx9' ); /* scr5900 */
linkObjs[23] = new LinkObj( 'MS3', 'veh_specs_MS3.pdf', 'MS3_Interior.mov', 'MS3_Exterior.mov', '2008_mazda3_brochure.pdf', 'ms3' ); /* scr5900 */

function findLink( id, whichlink, env )
{

	var popwidth, popheight;
	var result = "";
	var found = false;
	var prefix = "/MusaWeb";
	if (env) prefix = env + prefix;

	if ( id != null && id.length > 3 )
    {
		id = id.substr( 0, 3 );
	}

	for( var nI = 0; nI < linkObjs.length; nI++ )
    {
		if ( linkObjs[nI].idcode == id )
        {
			found = true;
			break;
		}
	}
	if ( found == true )
    {

        if ( whichlink == "learn" ) {
            result='displayPage.action?pageParameter=modelsMain&vehicleCode=' + linkObjs[ nI ].learn;
            return result;
			}
        else
        {
    		var fileName = null;
    		var filePath = null;
    		if ( whichlink == FEATURE )
            {

    			fileName = linkObjs[ nI ].feature;
    			filePath="/pdf/specs_features/";
    			popwidth="775";
    			popheight="500";
    		}
            else if ( whichlink == EXTERIOR_360 ) {
    			fileName = linkObjs[ nI ].ext360;
    			filePath="/movies/";
    			popwidth="400";
    			popheight="400";
			}

            else if ( whichlink == INTERIOR_360 ) {
    			fileName = linkObjs[ nI ].int360;
    			filePath="/movies/";
    			popwidth="400";
    			popheight="400";
           	}

            else {
    			fileName = linkObjs[ nI ].brochure;
    			filePath="/pdf/brochures/";
    			popwidth="775";
    			popheight="500";
    			}

    		if ( fileName == '' ) {
    			result = "";
    			}
            else  {
    			result = "javascript:popup('" + prefix + filePath + fileName + "', '"
    					+ whichlink + "', '" + popwidth +"', '" + popheight + "')";
    			}
    	}

        return result;
    }
}


function goLink( id, whichlink ) {
	var popwidth, popheight;
	var result = "";
	var found = false;
	var prefix = "/MusaWeb";

	if ( id != null && id.length > 3 ) {
		id = id.substr( 0, 3 );
	}

	for( var nI = 0; nI < linkObjs.length; nI++ ) {
		if ( linkObjs[nI].idcode == id ) {
			found = true;
			break;
		}
	}
	if ( found == true ) {
		var fileName = null;
		var filePath = null;
		if ( whichlink == FEATURE ) {

			fileName = linkObjs[ nI ].feature;
			filePath="/pdf/specs_features/";
			popwidth="775";
			popheight="500";
		} else if ( whichlink == EXTERIOR_360 ) {

			fileName = linkObjs[ nI ].ext360;
			filePath="/movies/";
			popwidth="400";
			popheight="400";
		} else if ( whichlink == INTERIOR_360 ) {

			fileName = linkObjs[ nI ].int360;
			filePath="/movies/";
			popwidth="400";
			popheight="400";
		} else {

			fileName = linkObjs[ nI ].brochure;
			filePath="/pdf/brochures/";
			popwidth="775";
			popheight="500";
		}

		if ( fileName == '' ) {
			// error, do nothing
		} else {
			popup(prefix + filePath + fileName, whichlink, popwidth, popheight);
		}
	}
}

function findFinanceLink( whichlink ) {
	var popwidth, popheight;
	var result = "";
	var prefix = "/MusaWeb";
	var path = "/loadFinance.action?atdServletAction="
	var pathSuffix = whichlink;
	var title = "Mazda";

	popwidth="670";
	popheight="500";

	if ( pathSuffix == null || pathSuffix == '' ) {
		result = '';
	} else {
		result = "javascript:popup('" + prefix + path + pathSuffix + "', '"
				+ title + "', '" + popwidth +"', '" + popheight + "')";
	}
	return result;
}

function findCreditLink( whichlink ) {
	var popwidth, popheight;
	var result = "";
	var prefix = "/MusaWeb";
	var path = "/loadFinance.action?atdServletAction="
	var pathSuffix = whichlink;
	var title = "Mazda";

	popwidth="780";
	popheight="500";

	if ( pathSuffix == null || pathSuffix == '' ) {
		result = '';
	} else {
		result = "javascript:popup('" + prefix + path + pathSuffix + "', '"
				+ title + "', '" + popwidth +"', '" + popheight + "')";
	}
	return result;
}

function goFinanceLink( whichlink ) {
	var popwidth, popheight;
	var prefix = "/MusaWeb";
	var path = "/loadFinance.action?atdServletAction="
	var pathSuffix = whichlink;
	var title = "Mazda";

	popwidth="670";
	popheight="500";

	if ( pathSuffix == null || pathSuffix == '' ) {
		// error, do nothing
	} else {
		popup(prefix + path + pathSuffix, title, popwidth, popheight);
	}
}

