function modelChanged(code) {   
	setModel(code);
	nextStep();
} 

function mvsChanged(code) {
	setMvs(code);
	clearPromos();
	addDefaultMvsPromos();
	setTimeout('graphic()',1)
}

function keyChanged(a) {
	Keymodel=a;
	setTimeout('graphic()',1)
}

function mvsBCChanged(code) {
	setMvsBodyColor(code);
	setMvsInnerPreparation(getFirstValidIPCode()); 
	graphic();
	if(ServerSide["useFlash"]=="true" && IsNE6()==false) setTimeout('setFlash("BC")',1);
}

function mvsIPChanged(code) {
	setMvsInnerPreparation(code);
	setTimeout('graphic()',1)
}

function mvsOptAdded(code) {
	codiceGRPEsc = code;
	listGRPEsc = getOptEsclusiveList(code);
	indexGRPEsc = -1;
	
	treeGRP = getOptInclusiveTree(code);
	codiceGRP = code;
	indexGRP = -1;

	if(listGRPEsc!=null && listGRPEsc.length>0) {
		optWindowDetailsEsc(code, listGRPEsc);
	}
	else {
		if(treeGRP!=null && treeGRP.length>0) {
			optWindowDetailsInc(code, treeGRP);
		}
		else {
			addOptional(code);
		}
	}
	setTimeout('graphic()',1)
}

function mvsOptGroupAdded() {
	if(codiceGRP != null && treeGRP != null && indexGRP != -1){
		addOptional(codiceGRP);
		for (var b = 0; b < treeGRP[indexGRP].length; b++) {
			addOptional(treeGRP[indexGRP][b].code);
		}
	}
	setTimeout('graphic()',1)
}

function mvsOptRemoved(code) {
	listGRPEsc = getOptInclusiveListRemoving(code);
	codiceGRPEsc = code;
	indexGRPEsc = -1;
	
	if(listGRPEsc!=null && listGRPEsc.length>0) {
		optWindowDetailsIncRem(code, listGRPEsc);
	}
	else {
		delOptional(code);
	}
	setTimeout('graphic()',1)
}

function mvsOptGroupRemoved(toAdd) {
	if(codiceGRPEsc != null && listGRPEsc != null && indexGRPEsc != -1){
		if(toAdd){
			addOptional(codiceGRPEsc);
		}
		else{
			delOptional(codiceGRPEsc);
		}
		for (var b = 0; b < listGRPEsc.length; b++) {
			delOptional(listGRPEsc[b].code);
		}
	}
	setTimeout('graphic()',1)
}

function mvsOptChanged(code) {
	setOptional(code);
	graphic();
	if(ServerSide["useFlash"]=="true" && IsNE6()==false) setTimeout('setFlash("OPT")',1);
}

function mvsPromoAdded(code) {
	addPromo(code);
	setTimeout('graphic()',1)
}

function mvsPromoRemoved(code) {
	delPromo(code);
	setTimeout('graphic()',1)
}

function mvsInfoRequested(code){
	var dest="";
	if(ServerSide["BVAddress"]!=null && ServerSide["BVAddress"]!=""){
		dest=ServerSide["BVAddress"] +"/" +ServerSide["scriptRoot"]+ "/"+ "/popup/p_conf_standard.php" +"?"+ServerSide["linkString"];
	}
	else{
		dest="../popup/p_conf_standard.php"+"?"+ServerSide["linkString"];
	}
	dest+="&codModello="+Vehicle.Model.code+"&codVeicolo="+code;
	window.open(dest, "Info",'width=610,height=500,scrollbars=yes');
}

function optionalInfoRequested(code){
	var dest="";
	if(ServerSide["BVAddress"]!=null && ServerSide["BVAddress"]!=""){
		dest=ServerSide["BVAddress"] +"/" +ServerSide["scriptRoot"]+ "/"+ "/popup/popupOptionalInfo.jsp" +"?"+ServerSide["linkString"];
	}
	else{
		dest="../popup/popupOptionalInfo.jsp"+"?"+ServerSide["linkString"];
	}
	dest+="&codModello="+Vehicle.Model.code+"&codVeicolo="+Vehicle.Mvs.code+"&codOptional="+code;
	window.open(dest, "Info",'width=499,height=500,scrollbars=yes');
}

function nextStep() {
	document.formXML.azione.value='nextStep';
	submitXML();
}

function previousStep() {
	Vehicle.step = Vehicle.step - 1 ;
	document.formXML.azione.value='previousStep';
	submitXML();
}

function firstStep() { 
	document.formXML.azione.value='firstStep';
	submitXML();
}

/*
function loadConfig() {
	document.formXML.azione.value='loadConfig';
	if(Vehicle.step==0){
		submitXML();
	}
	else{
		document.formXML.submit(); 
	}
}
function saveConfig() {
	document.formXML.azione.value='saveConfig';
	document.formXML.submit(); 
}
*/

function externalLinkCalled(code){
	var extLink=getExternalLinkByCode(code);
	//FINANCING
	if(extLink.code=="financing"){
		var dest = "../carconfig/promoFin.jsp"+"?"+ServerSide["linkString"];
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		window.location.href=dest;
		return;
	}
	//DEALERLOCATOR
	if(extLink.code=="dealerLocator"){
		// var dest="../dealerlocator/pb_dl_home.jsp"+"?"+ServerSide["linkString"]+"&DLR_SCOPE=LEAD";
		var dest="index.php?pid=6";
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		window.location.href=dest;
		return;
	}
	//SAVE CONFIG
	if(extLink.code=="saveConfig"){
		document.formXML.azione.value='saveConfig';
		document.formXML.submit(); 
		return;
	}
	//BROCHURE
	if(extLink.code=="brochure"){
		//var dest = "../catalog/catalog.jsp"+"?"+ServerSide["linkString"]+ "&modelKey="+ Vehicle.Model.code;
		var dest = "index.php?pid=27&modelKey="+ Vehicle.Model.code;
		// modelKey=0253D
		
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		window.location.href=dest;
		return;
	}
	//PRINT LEAFLET
	if(extLink.code=="printLeaflet"){
		//document.formXML.action="popup/conf_print.php";
		//document.formXML.target="PrintLeaflet";
		var dest="popup/conf_print.php"; 
		window.open(dest, "PrintLeaflet", 'width=610, height=600, scrollbars=yes');
		//document.formXML.submit();
		//document.formXML.action="../carconfig/ccStep4.jsp";
		//document.formXML.target="_self";
	}
	//SENDTOFRIEND
	if(extLink.code=="sendToFriend"){
		//document.formXML.action="popup/send_to_friend.php";
		document.formXML.action="?pid=29";
		document.formXML.azione.value="";
		document.formXML.submit();
	}
	//LOAD CONFIG
	if(extLink.code=="loadConfig"){
		document.formXML.azione.value='loadConfig';
		if(Vehicle.step==0){
			submitXML();
			return;
		}
		else{
			document.formXML.submit(); 
			return;
		}
	}
	//TESTDRIVE
	if(extLink.code=="testDrive"){
		var dest = "../testdrive/testdrive.jsp"+"?"+ ServerSide["linkString"]+ "&modelKey="+Vehicle.Model.code;
		if(ServerSide["commercialVersionCode"]!=null && ServerSide["commercialVersionCode"]!=""){
			dest+="%7C"+ServerSide["commercialVersionCode"];
		}
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		dest+="&cartype="+Vehicle.Model.desc;
		window.location.href=dest;
		return;
	}
	//SENDLEAD
	if(extLink.code=="sendLead"){
		var dest = "../carconfig/ccleadform.jsp"+"?"+ServerSide["linkString"];
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		window.location.href=dest;
		return;
	}
	//READYDELIVERY
	if(extLink.code=="readyDelivery"){
		var dest = "../demo/stock_locator_demo.jsp"+"?"+ ServerSide["linkString"]+ "&modelKey="+Vehicle.Model.code;
		if(ServerSide["commercialVersionCode"]!=null && ServerSide["commercialVersionCode"]!=""){
			dest+="%7C"+ServerSide["commercialVersionCode"];
		}
		if(extLink.linkTo!=""){
			dest=makeLinkTo(extLink.linkTo);
		}
		window.location.href=dest;
		return;
	}
	
	
	/*
	var prevStep=Vehicle.step;
	Vehicle.step=5;
	document.formXML.summaryBoxes.value=boxDXCode();
	Vehicle.step=prevStep;
	*/
}

function externalGoTo(code){
	//GOTO CCHOME
	if(code=="gotoModelHome"){
		var dest = "../showroom/showroomModel.jsp"+"?"+ServerSide["linkString"]+"&modelKey="+Vehicle.Model.code;
		if(ServerSide["commercialVersionCode"]!=null && ServerSide["commercialVersionCode"]!=""){
			dest+="%7C"+ServerSide["commercialVersionCode"];
		}
		window.location.href=dest;
		return;
	}
	if(code=="gotoComparison"){
		// var dest = "../confronto/confronto.jsp"+"?"+ServerSide["linkString"]+"&mvsCode="+Vehicle.Mvs.code;
		var dest = "index.php?pid=28"+"&ModelCode="+Vehicle.Model.code+"&ModelVer="+Vehicle.Mvs.code;
		window.location.href=dest;
		//alert(Vehicle.Model.code);
		return;
	}
}

function externalPopup(code){ 
	//OPEN HELP POPUP
	if(code=="popHelp"){
		var popPath="../popHelp/pophelp.jsp"+"?"+ ServerSide["linkString"]+"&cCategory=" + "SHOWROOM/STEP" +Vehicle.step;
		window.open(popPath, "pppShowroom", "width=700,height=380");
		return;
	}
	//OPEN COMPARISON POPUP
	if(code=="popComparison"){
		alert("ATTENZIONE! Path popup e parametri da confermare");
		var popPath="../confronto/confronto.jsp"+"?"+ ServerSide["linkString"]+ "&codVeicolo="+Vehicle.Mvs.code;
		window.open(popPath, "p", "width=599,height=530");
		return;
	}
	//OPEN VEHICLE INFO POPUP
	if(code=="popVehicleInfo"){
		var popPath="popup/popupVehicleInfo.php"+"?codVeicolo="+Vehicle.Mvs.code;
		window.open(popPath, "p", "width=600,height=530,scrollbars=yes");
		return;
	}
}

function makeLinkTo(linkTo){
	var dest = linkTo;
	if(dest.indexOf("?")==-1){
		dest+="?"
	}
	else{
		dest+="&"
	}
	dest+=ServerSide["linkString"];
	return dest;
}



//ESTENSIONI LCV

function filterChanged(codeType, codevalue){
	//alert("filterChanged(): "+codeType+" - "+codevalue);
	var pipeIndex=codevalue.indexOf("|");
	var code=codevalue.substring(0,pipeIndex);
	var value=codevalue.substring(pipeIndex+1,codevalue.length);
	//alert("codeType: "+codeType+" code: "+code+" - value: "+value);
	setFilter(new TDV(""+codeType,""+code,""+value));
	addToHistory();
	setTimeout('graphic()',1);
}

function lastFilterRemoved(){
	removeFromHistory();
	setTimeout('graphic()',1);
}

function allFiltersRemoved(){
	clearHistory();
	setTimeout('graphic()',1);
}

function showListCalled(){
	var mvsFilteredTDList=countMvsByFilter("", "", false, true);
	var listSize=mvsFilteredTDList.length;
	//alert("listSize: "+listSize);
	var maxSize=ServerSide["maxVehicleListSizeLCVE"];
	//alert("maxSize: "+maxSize);
	if(maxSize==null || maxSize.length==0){
		//default
		maxSize=20;
	}
	if(listSize>maxSize){
		//alert("TODO per passare allo step successivo selezionare un numero di veicoli inferiore a 20"); 
		errorAlert(convertApici(ServerSide["popopTooManyVehiclesTitleLCVE"]), convertApici(ServerSide["popopTooManyVehiclesTextLCVE"]));
	}
	else{
		document.formXML.mvsFilteredKeys.value=createMvsFilteredKeysString(mvsFilteredTDList);
		Vehicle.step = Vehicle.step - 1 ;
		nextStep();
	}
}

function setFormFiltersBox(){
	document.formXML.filtersBox.value=ServerSide["filtersBox"];
}
