var focusedElement = null;

function firstinputfocus(form_id) {
	
	var userAgent = navigator.appVersion;
	
	var pattern = /MSIE 6\.0/;
	
	var ie = userAgent.match(pattern);
			
	if(!ie || true){		
		forms = document.getElementsByTagName("form"); // retives all forms
		for(i = 0; i < forms.length; i++){			
			if (form_id != undefined ) {
				if (forms[i].id == form_id) {
					input = forms[i].elements;
				} else {
					continue;
				}
			} else {
				input = forms[i].elements
			}
	
			for(i = 0; i < input.length; i++){
				r = input[i].getAttribute("readonly");				
				if(r!=null && r!=false) continue; // also excludes inputs with readonly attribute
				
				if(input[i].tagName.match(/input/i)){ // checks if it is a input 
						if (input[i].type == 'button' || // excludes the following input types
							input[i].type == 'checkbox' ||
							input[i].type == 'file' ||
							input[i].type == 'hidden' || // reason for exluding is that some inputs may not have an associated type!
							input[i].type == 'image' ||
							input[i].type == 'radio' ||
							input[i].type == 'reset' ||
							input[i].type == 'submit')continue;
	
						if(input[i].value.length == 0){
							input[i].focus();
							focusedElement = input[i];
							break;
						}
				}
				if(input[i].tagName.match(/textarea/i)){
					if(input[i].value.length == 0) {
						input[i].focus();
						focusedElement = input[i];
					}
					break;
				}	
			}			
		}
	}	
		
}
