function modelChanged(code) {   
	setModel(code);
	nextStep();
} 

function mvsChanged(code) {
	setMvs(code);
	clearPromos();
	addDefaultMvsPromos();
	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_tech_data.php" +"?"+ServerSide["linkString"];
	}
	else{
		dest="../popup/p_tech_data.php"+"?"+ServerSide["linkString"];
	}
	dest+="&codModello="+Vehicle.Model.code+"&codVeicolo="+code;
	window.open(dest, "Info",'width=499,height=500,scrollbars=yes');
}
function mvsOptRequested(code){
	var dest="";
	if(ServerSide["BVAddress"]!=null && ServerSide["BVAddress"]!=""){
		dest=ServerSide["BVAddress"] +"/" +ServerSide["scriptRoot"]+ "/"+ "/popup/p_tech_data.php" +"?"+ServerSide["linkString"];
	}
	else{
		dest="../popup/p_opt_data.php"+"?"+ServerSide["linkString"];
	}
	dest+="&codModello="+Vehicle.Model.code+"&codVeicolo="+code;
	window.open(dest, "Info",'width=499,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';
	var prevStep=Vehicle.step;
	Vehicle.step=5;
	document.formXML.summaryBoxes.value=boxDXCode();
	Vehicle.step=prevStep;
	document.formXML.action='../egarage/saveConfiguration.jsp';
	document.formXML.submit();
}

function externalLinkCalled(destination){
	//PRINT LEAFLET
	if(destination==null || destination=="") return;
	if(destination.indexOf('drukuj.php')!=-1){


		var dest=destination+"?"+ServerSide["linkString"]; 
		window.open(dest, "PrintLeaflet", 'width=567, height=600, scrollbars=yes');

		prepareXML();
		document.forms.PrintForm.target='PrintLeaflet';
		document.forms.PrintForm.action='drukuj.php';
		document.forms.PrintForm.XMLString.value = document.forms.formXML.XMLString.value;
		document.forms.PrintForm.submit();

		return;
	}

	if(destination.indexOf('wyslij.php')!=-1){

		var dest=destination+"?"+ServerSide["linkString"]; 
		window.open(dest, "SendFriend", 'width=400, height=400, scrollbars=yes');

		prepareXML();
		document.forms.PrintForm.target='SendFriend';
		document.forms.PrintForm.action='wyslij.php';
		document.forms.PrintForm.azione.value='wyslij';
		document.forms.PrintForm.XMLString.value = document.forms.formXML.XMLString.value;
		document.forms.PrintForm.submit();

		return;
	}

	/*
	//SEND TO DEALER 
	if(destination.indexOf('pb_dl_input.jsp')!=-1){
		var dest=destination+"?"+ServerSide["linkString"]+"&DLR_SCOPE=LEAD";
		window.location.href=dest;
		return;
	}
	*/
	//TESTDRIVE 
	if(destination.indexOf('index.php?pid=81')!=-1){
		var dest="index.php?pid=81";
		window.location.href=dest;
		return;
	}
	
	if(destination.indexOf('pb_dl_input.jsp')!=-1){
		var newpar = document.createElement("INPUT");
		newpar.type="HIDDEN";
		newpar.name="DLR_SCOPE";
		newpar.id="DLR_SCOPE";  // it is necessary to add an id!
		newpar.value="LEAD";
		document.formXML.appendChild(newpar);
		var newpar2 = document.createElement("INPUT");
		newpar2.type="HIDDEN";
		newpar2.name="mapName";
		newpar2.id="mapName";  // it is necessary to add an id!
		newpar2.value="NONE";
		document.formXML.appendChild(newpar2);
	}
	
	//OTHERS
	document.formXML.azione.value='externalLink';
	var prevStep=Vehicle.step;
	Vehicle.step=5;
	document.formXML.summaryBoxes.value=boxDXCode();
	Vehicle.step=prevStep;
	document.formXML.action=destination;
	document.formXML.submit();
}

 