 /**
 * 
 * File		:		other_functions.js  
 * Author	:		Peter Cotton 
 * Date		:		Friday 2nd June 2006
 * Purpose	:		Functions that do not fit into any other category.
 * 
 * History	:		Version 1.0 Original
 * 
 *  */
 
 
 
 
/**
 * Function to set the appropriate number of days for the selected month
 * @param none
 * @return none
 * */
 function setDaysInMonth(){
 
 	// capture selected day in an effort to reload it after changes
 	var day_selected = data.day.value;
 	var month_selected = data.month.value;
 	var year_selected = data.year.value;

	// iterate data.day removing all values
	while(data.day.length != 0){
		data.day.remove(0);
	}
 
 	// default
 	var days_of_month = 31;
 	
 	// months 4,6,9,11 have 30 days
 	if (month_selected == 4 || month_selected == 6 || month_selected == 9 || month_selected == 11){
 		days_of_month = 30;	
 	}
 	
 	// month 2 has 28 (or sometimes 29) days
 	if (month_selected == 2){
 		days_of_month = 28;
 		// if difference between selected year and 2004 is a multiple of 4
 		// then the selected year was a leap year
 		if (((year_selected-2004)/4) == Math.round((year_selected-2004)/4) && year_selected !=''){
 			days_of_month = 29;
 		}
 	}
 	
 	// loop number of days, adding them to the list of options
 	for (var i=1; i<=days_of_month; i++){
 		var new_option = document.createElement('option');
 		new_option.value = i;
 		new_option.text = i;
 		data.day.add(new_option);
 	}
 	
 	// re-establish the selected index
 	if (data.day.length >= day_selected){
 		if (day_selected != ''){
 			data.day.selectedIndex = day_selected-1;
 		}
 	}
 }
 
 
 
 
 
 /**
 * Function to make sure a textarea entry does not exceed a given limit
 * @param none
 * @return none
 * */
 function textCounter(field, maxlimit) {
 
 	// if the field is longer than the specified max, trim it
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
 }
 
 
 
 
 
 /**
 * Function to enable/disable controls on admin stock control, dispatch licenses page
 * @return void
 */
 function setActiveControls(){
 	
 	// if the 'load' option is selected
 	if (data.addressradio[0].checked){
 	
 		// enable address select box
 		data.address.disabled = false;
 		
 		// disable new address controls
 		data.addresstype.disabled = true;
 		data.name.disabled = true;
 		data.number.disabled = true;
 		data.line1.disabled = true;
 		data.line2.disabled = true;
 		data.line3.disabled = true;
 		data.town.disabled = true;
 		data.city.disabled = true;
 		data.county.disabled = true;
 		data.postcode.disabled = true;
 		data.country.disabled = true;
 		document.getElementById("typeCell").color = "gray";
 		document.getElementById("nameCell").color = "gray";
 		document.getElementById("numberCell").color = "gray";
 		document.getElementById("line1Cell").color = "gray";
 		document.getElementById("line2Cell").color = "gray";
 		document.getElementById("line3Cell").color = "gray";
 		document.getElementById("townCell").color = "gray";
 		document.getElementById("cityCell").color = "gray";
 		document.getElementById("countyCell").color = "gray";
 		document.getElementById("postcodeCell").color = "gray";
 		document.getElementById("countryCell").color = "gray";
 	
 	// if the 'new' option is selected
 	} else {
 		// disable address select box
 		data.address.disabled = true;
 		
 		// enable new address controls
 		data.addresstype.disabled = false;
 		data.name.disabled = false;
 		data.number.disabled = false;
 		data.line1.disabled = false;
 		data.line2.disabled = false;
 		data.line3.disabled = false;
 		data.town.disabled = false;
 		data.city.disabled = false;
 		data.county.disabled = false;
 		data.postcode.disabled = false;
 		data.country.disabled = false;
 		document.getElementById("typeCell").color = "black";
 		document.getElementById("nameCell").color = "black";
 		document.getElementById("numberCell").color = "black";
 		document.getElementById("line1Cell").color = "black";
 		document.getElementById("line2Cell").color = "black";
 		document.getElementById("line3Cell").color = "black";
 		document.getElementById("townCell").color = "black";
 		document.getElementById("cityCell").color = "black";
 		document.getElementById("countyCell").color = "black";
 		document.getElementById("postcodeCell").color = "black";
 		document.getElementById("countryCell").color = "black";
 	}
 }
 
 
 
 
 /**
 * Function to enable/disable controls on purchase delivery address form
 * @return void
 */
 function setActiveControls_OrderForm(){
 	
 	// if the 'load' option is selected
 	if (data.addressradio[0].checked){
 	
 		// enable address select box
 		data.address.disabled = false;
 		
 		// disable new address controls
 		data.name.disabled = true;
 		data.number.disabled = true;
 		data.line1.disabled = true;
 		data.line2.disabled = true;
 		data.line3.disabled = true;
 		data.town.disabled = true;
 		data.city.disabled = true;
 		data.county.disabled = true;
 		data.postcode.disabled = true;
 		data.country.disabled = true;
 		document.getElementById("nameCell").color = "gray";
 		document.getElementById("numberCell").color = "gray";
 		document.getElementById("line1Cell").color = "gray";
 		document.getElementById("line2Cell").color = "gray";
 		document.getElementById("line3Cell").color = "gray";
 		document.getElementById("townCell").color = "gray";
 		document.getElementById("cityCell").color = "gray";
 		document.getElementById("countyCell").color = "gray";
 		document.getElementById("postcodeCell").color = "gray";
 		document.getElementById("countryCell").color = "gray";
 	
 	// if the 'new' option is selected
 	} else {
 		// disable address select box
 		data.address.disabled = true;
 		
 		// enable new address controls
 		data.name.disabled = false;
 		data.number.disabled = false;
 		data.line1.disabled = false;
 		data.line2.disabled = false;
 		data.line3.disabled = false;
 		data.town.disabled = false;
 		data.city.disabled = false;
 		data.county.disabled = false;
 		data.postcode.disabled = false;
 		data.country.disabled = false;
 		document.getElementById("nameCell").color = "black";
 		document.getElementById("numberCell").color = "black";
 		document.getElementById("line1Cell").color = "black";
 		document.getElementById("line2Cell").color = "black";
 		document.getElementById("line3Cell").color = "black";
 		document.getElementById("townCell").color = "black";
 		document.getElementById("cityCell").color = "black";
 		document.getElementById("countyCell").color = "black";
 		document.getElementById("postcodeCell").color = "black";
 		document.getElementById("countryCell").color = "black";
 	}
 }
 
 