function isPlanOfferedForProvince(provinceValue, planTypeValue){
	var provinceIndex = 0;
	var planIndex = 0;
	
	for (var i=0;i<provinceValueList.length;i++){
		if (provinceValue == provinceValueList[i]){
			provinceIndex = i;
		}
	}
	
	for (var i=0;i<planTypeValueList.length;i++){
		if (planTypeValue == planTypeValueList[i]){
			planIndex = i;
		}
	}
	
	var mapValue = provinceToPlanTypeMapping[provinceIndex];
	return mapValue>=(planIndex+1);
}

function updateProvinceOptionList(planTypeElementID, provinceElementID){

	var planOptions = document.getElementById(planTypeElementID).options;
	var planIndex = planOptions.selectedIndex;	
	var planValue = planOptions[planIndex].value;
	
	var provinceOptions = document.getElementById(provinceElementID).options;
	var provinceIndex = provinceOptions.selectedIndex;	
	var provinceValue = provinceOptions[provinceIndex].value;

	for (var i=provinceOptions.length-1;i>=0;i--){
			provinceOptions.remove(i);
	}
	
	var selIndex = 0;
	for (var i=0;i<provinceTextList.length;i++){
		if (isPlanOfferedForProvince(provinceValueList[i], planValue)){
			op=document.createElement("OPTION");
			op.value=provinceValueList[i];
			op.text=provinceTextList[i];
			if (provinceValueList[i] == provinceValue) 
				selIndex = provinceOptions.length;
			provinceOptions.add(op);
		}
	}
	provinceOptions.selectedIndex = selIndex;
}

function updatePlanTypeOptionList(planTypeElementID, provinceElementID){

	var planOptions = document.getElementById(planTypeElementID).options;
	var planIndex = planOptions.selectedIndex;	
	var planValue = planOptions[planIndex].value;
	
	var provinceOptions = document.getElementById(provinceElementID).options;
	var provinceIndex = provinceOptions.selectedIndex;	
	var provinceValue = provinceOptions[provinceIndex].value;

	for (var i=planOptions.length-1;i>=0;i--){
			planOptions.remove(i);
	}

	var selIndex = 0;
	for (var i=0;i<planTypeTextList.length;i++){
		if (isPlanOfferedForProvince(provinceValue, planTypeValueList[i])){
			op=document.createElement("OPTION");
			op.value=planTypeValueList[i];
			op.text=planTypeTextList[i];
			if (planTypeValueList[i]==planValue) 
				selIndex = planOptions.length;
			planOptions.add(op);
		}
	}
	planOptions.selectedIndex = selIndex;
}

function updatePlanTypeOptionList2(planTypeElementID, provinceValue){

	var planOptions = document.getElementById(planTypeElementID).options;
	var planIndex = planOptions.selectedIndex;	
	var planValue = planOptions[planIndex].value;
	
	for (var i=planOptions.length-1;i>=0;i--){
			planOptions.remove(i);
	}

	var selIndex = 0;
	for (var i=0;i<planTypeTextList.length;i++){
		if (isPlanOfferedForProvince(provinceValue, planTypeValueList[i])){
			op=document.createElement("OPTION");
			op.value=planTypeValueList[i];
			op.text=planTypeTextList[i];
			if (planTypeValueList[i]==planValue) 
				selIndex = planOptions.length;

			planOptions.add(op);
		}
	}
	
	planOptions.selectedIndex = selIndex;
}

