////////////////////////////////////////////////////////////////
// Set form input values by James - 19/06/09
// Ensure that the button used to submit the forms 'type=button' not 'type=submit'
////////////////////////////////////////////////////////////////

// Enter your forms name here

var formName = 'quick_fix';

inputValues = {name : 'your name', email : 'email address', phone : 'phone number', search_field : 'please enter a search term'}; // Add the inital values for your form input fields here, using their ID as the key
inputRequired = {name : true, email : true, phone : true};

// Get number of true inputs in inputRequired

inputRequiredLength = 0;
for (key in inputRequired) {
		if(inputRequired[key] == true) inputRequiredLength++;
 }


// Detect browser

var browserName=navigator.appName; 


function setFormValues() {
	
	for (key in inputValues) {
		
		var inputPath = document.getElementById(key); // Get the path the the input
		inputPath.value = inputValues[key];  // Give it the value specified above

		inputPath.onclick = function(){ 
		
		// If the intial value is present on click remove it so the user can enter their value
		
			var thisID = this.id;
			
			if(inputValues[this.id] == this.value){
				this.value="";
			}
		}
		
		// Replace initial value if nothing is entered
		
		inputPath.onblur = function(){ 
		
			if(this.value == ""){
				this.value=inputValues[this.id];
			}
		}
	}
}

function checkRequired(){
	
	var counter = 0;
	
	for (key in inputRequired) {
		
		var inputPath = document.getElementById(key);
		
		if(inputPath.value == "" || inputPath.value == inputValues[key] && inputRequired[key] == true){
			
			if(browserName == "Microsoft Internet Explorer"){
			
				var previousBGColor = inputPath.currentStyle.backgroundColor
				var previousFontColor = inputPath.currentStyle.color
			
			}else{
				
				var previousBGColor = getComputedStyle(inputPath, '').getPropertyValue("background-color");
				var previousFontColor = getComputedStyle(inputPath, '').getPropertyValue("color");
				
			}
			
			// Change the input bg color and font color to highlight
			
			inputPath.style.background = '#ff0000';
			inputPath.style.color ='#ffffff';
			
			// On focus change the input bg color and font color back
			
			inputPath.onfocus = function(){
				inputPath.style.background = previousBGColor;
				inputPath.style.color = previousFontColor;
			}
			
			//alert("please enter a value for " + key);
			break;
			
		}else{
			
			// If the input field is validated then increase counter
			counter++; 
			
		}
	}
	
	// If everything is ok counter will equal the length of the inputRequired array so submit the form
		if(counter == inputRequiredLength){
			document[formName].submit();
		}
}
