function dynamicSelect(id1, id2) {
	// Feature test to see if there is enough W3C DOM support
	if (document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		// Clone the dynamic select box
		var clone = sel2.cloneNode(true);
		// Obtain references to all cloned options 
		var clonedOptions = clone.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		};
	}
}
function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {
		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

function validate(targetForm) {
	
    var EMAIL = "^[a-zA-Z0-9_-]+(\.([a-zA-Z0-9_-])+)*@[a-zA-Z0-9_-]+[.][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*$"
    var URL = "http://"
    
    for (var i = 0; i < targetForm.elements.length; i++) {
	if(targetForm.elements[i].getAttribute("strValue") != null) {
	    var message = targetForm.elements[i].getAttribute("message");
	    var strBound = targetForm.elements[i].getAttribute("strBound");	
	    var strVal = targetForm.elements[i].getAttribute("strValue");
   
	    if(eval('document.' + strBound + '.type') == 'select-one') {
		var sIndex = eval('document.' + strBound + '.selectedIndex');
		var strBoundVal = eval('document.' + strBound + '[' + sIndex + '].value'); 
	    }
	    if(strVal == strBoundVal){
		if(targetForm.elements[i].value == '') {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;
		}						
	    }
				
	}
	
	if(targetForm.elements[i].getAttribute("isReq")) {

	    var message = targetForm.elements[i].getAttribute("message");
	    
	    if(targetForm.elements[i].type == 'checkbox') {
		if(!targetForm.elements[i].checked) {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;
		}
	    }
	    else if(targetForm.elements[i].type == 'text' || 
		    targetForm.elements[i].type == 'password' || targetForm.elements[i].type == 'file') {
		if(targetForm.elements[i].value == '') {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;								
		}
		if(targetForm.elements[i].getAttribute("regex") != null) {
		    var UserRegEx = targetForm.elements[i].getAttribute("regex");
		    var InputValue = targetForm.elements[i].value;
		    if(UserRegEx == 'EMAIL') {
			var re = new RegExp(EMAIL);
			if(!InputValue.match(re)) {
			    alert(message);
			    targetForm.elements[i].focus();	
			    return false;	
			}
		    }
		    else if(UserRegEx == 'URL') {
			var re = new RegExp(URL);
			if(!InputValue.match(re)) {
			    alert(message);
			    targetForm.elements[i].focus();	
			    return false;	
			}
		    }
		    else {
			var re = new RegExp(UserRegEx);
			if(!InputValue.match(re)) {
			    alert(message);
			    targetForm.elements[i].focus();	
			    return false;	
			}
		    }
		}
	    }
	    else if(targetForm.elements[i].type == 'select-one') {
		if(targetForm.elements[i].value == '') {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;								
		}
	    }
	    else if(targetForm.elements[i].type == 'textarea') {
		if(targetForm.elements[i].value == '') {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;								
		}
	    }
	    else if(targetForm.elements[i].type == 'radio') {
		var isSelected = false;
		var j = 0;
		while(targetForm.elements[i+j].type == 'radio' && 
		      targetForm.elements[i].name == targetForm.elements[i+j].name) {
		    if(targetForm.elements[i+j].checked) {
			isSelected = true;
		    }
		    j++;
					
		}
		
		j = 0;
		
		while(targetForm.elements[i-j].type == 'radio' && 
		      targetForm.elements[i].name == targetForm.elements[i-j].name) {
		    if(targetForm.elements[i-j].checked) {
			isSelected = true;
		    }
		
		    if(i-j <= 0) {
			break;
		    }
		
		    j++;					
		}				
		
		if(!isSelected) {
		    alert(message);
		    targetForm.elements[i].focus();	
		    return false;				
		}
	    }
	    else {
		return true;
	    }
	}
    }		
}
////////////////////////////////////////////////////////////////////////////////////////////////

