var gCountry=null;
var gMake=null;
var gModel=null;
var gModelYear=null;
var sCountry=null;
function addMake(icountry)
{   
	gCountry = assignCountry(icountry);
	sCountry = icountry;
      
    document.getElementById("sltMakeInd").style.display="block";
    funDis("sltMake");
    MCBean.getMake(gCountry, 
    { 	
    	callback:function(str) { 
    		loadDropdown(str, "sltMake"); 
    	}
    });
}

function addModel(imake)
{
	gMake=imake;
    document.getElementById("sltModelInd").style.display="block";
    funDis("sltModel");
    MCBean.getModel(gCountry,gMake, 
    { 	
    	callback:function(str) { 
    		loadDropdown(str, "sltModel"); 
    	}
    });
}

function addsltModel(imodel)
{
    if((gCountry=="Germany")|| (gCountry=="Netherlands")||(gCountry=="Spain")||(sCountry=="Germany")|| (sCountry=="Netherlands")||(sCountry=="Spain")) {
		addTyreType(imodel);
	}
	else{
		addModelYear(imodel);
	}
}

function addModelYear(imodel)
{
	gModel=imodel;
	funDis("sltModelYear");
    MCBean.getModelYear(gCountry, gMake, gModel, 
    { 	
    	callback:function(str) 
		{ 
    		if(str.length==1 || str.length==0)
			{
    			document.getElementById("sltModelYear").value=str[0];
    			modelyear_submitform();
    		}
			else
			{
    			document.getElementById("ModelYearlabel").style.display="block";
				document.getElementById("ModelYearselect").style.display="block";
		        document.getElementById("ModelYearlabel1").style.display="block";
		        document.getElementById("sltModelYearInd").style.display="block";
    			loadDropdown(str, "sltModelYear"); 
    		}
    	}
    });
}

function addTyreType(imodel)
{
	gModel=imodel;
    funDis("sltTyreType");
    MCBean.getType(gCountry, gMake, gModel,
    { 	
    	callback:function(str) 
		{
    		if(str.length==1 || str.length==0)
			{
    			document.getElementById("sltTyreType").value=str[0];
    	    	type_submitform();
    		}
			else
			{ 
				document.getElementById("TyreTypelabel").style.display="block";
				document.getElementById("TyreTypeselect").style.display="block";
				document.getElementById("TyreTypelabel1").style.display="block";
				document.getElementById("sltTyreTypeInd").style.display="block";
    			loadDropdown(str, "sltTyreType"); 
    		}
    	}
    });
}

function type_submitform()
{
	var sCountry=document.getElementById("sltCountry").value;
    var sType=document.getElementById("sltTyreType").value;
	var paramStep="4";
	var siteName=document.motorCycle.hiddenSite.value;
	var slocale=document.motorCycle.localeval.value;

    MCBean.getEncodedModel(gModel, 
    { 	
    	callback:function(str) 
		{ 
			document.motorCycle.action="/bfe/tyreSelectorController?page=motorCycle&dataToDisplay=resultpage&step="+
			paramStep+"&country="+gCountry+"&hiddenCountry="+sCountry+"&hiddenMake="+gMake+"&hiddenModel="+str+"&hiddenType="+sType+"&hiddenSite="+siteName+"&locale="+slocale+" ";
    		document.motorCycle.submit();
    	}
    });
}

function modelyear_submitform()
{
    var sCountry=document.getElementById("sltCountry").value;
    var sModelYear=document.getElementById("sltModelYear").value;
	var paramStep="4";
	var siteName=document.motorCycle.hiddenSite.value;
	var slocale=document.motorCycle.localeval.value;      
     
    MCBean.getEncodedModel(gModel, 
    { 	
    	callback:function(str) { 
    		document.motorCycle.action="/bfe/tyreSelectorController?page=motorCycle&dataToDisplay=resultpage&step="+
      		paramStep+"&country="+gCountry+"&hiddenCountry="+sCountry+"&hiddenMake="+gMake+"&hiddenModel="+str+"&hiddenModelYear="+sModelYear+"&hiddenSite="+siteName+"&locale="+slocale+" ";
    		document.motorCycle.submit();
    	}
    });
}

function loadDropdown(data, sltName)
{
    DWRUtil.addOptions(sltName, data);
    document.getElementById(sltName).disabled = false;
    document.getElementById(sltName+"Ind").style.display="none";
}

function funDis(sltDrop)
{
	switch (sltDrop)
	{
		case "sltCountry":
    		document.getElementById("sltCountry").options.length = 1; 
    		document.getElementById("sltCountry").disabled = true;
		case "sltMake":
    		document.getElementById("sltMake").options.length = 1; 
    		document.getElementById("sltMake").disabled = true;
		case "sltModel":
    		document.getElementById("sltModel").options.length = 1; 
    		document.getElementById("sltModel").disabled = true;
   		case "sltModelYear":
    		document.getElementById("sltModelYear").options.length = 1; 
    		document.getElementById("sltModelYear").disabled = true;
    	case "sltTyreType":
    		document.getElementById("sltTyreType").options.length = 1; 
    		document.getElementById("sltTyreType").disabled = true;
	}
}

function assignCountry(selectedCountry)
{
	var sCountry;
	switch(selectedCountry){
		case "Austria" :
			sCountry = "Germany"
			break;
		case "Finland" :
			sCountry = "Germany"
			break;
		case "Italy":
			sCountry = "Spain";
			break;
		case "Portugal":
			sCountry = "Germany";
			break;
		case "Switzerland":
			sCountry = "Germany";
			break;
		case "Greece":
			sCountry = "Germany";
			break;
		case "Ireland":
			sCountry = "Great Britain";
			break;
		case "Netherlands":
			//sCountry = "Benelux";
			sCountry = "Netherlands";
			break;
		case "Belgium":
			sCountry = "Netherlands";
			break;
		case "Czech Republic":
			sCountry = "Germany";
			break;
		case "Denmark":
			sCountry = "Germany";
			break;
		case "Sweden":
			sCountry = "Germany";
			break;
		case "Hungary":
			sCountry = "Germany";
			break;
		case "Poland":
			sCountry = "Germany";
			break;
		case "France":
			sCountry = "France";
			break;
		case "Norway":
			sCountry = "Germany";
			break;				
		default:
			sCountry = selectedCountry;
	}
	return sCountry;
}

