function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function removespaces(val){
	pos = val.indexOf(" ");
	while (pos>-1){
		val = val.replace(" ", "");
		pos = val.indexOf(" ");
	}
	return val;
	
}

//validate('form1-f:username-e:passcode-l3:fname-e:sname-e:email-m:email-i:passcode-t:selectlist-s:qty-n:terms-c');
function validate(n) {
	//alert(n);
	ln=n.length-1;
	n=n.substr(0,ln);
	fldsx = n.split(":");
	fieldcol = "#fed03d";
	fieldcol2 = "#ffff00";
	chk="";
	formval="forms[0]";
	for (x in fldsx)	{
		val = fldsx[x].split("-");
	//	chk=chk+val[0]+">"+val[1]+"||||";
		if(val[1]=="f"){
			formval=val[0];
		}
		if(val[1]=="e"){
			objf = eval("document."+formval+"."+val[0]);
			remval=removespaces(objf.value);
			if (remval==''){
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			}
		}
		if(val[1]=="n"){
			objf = eval("document."+formval+"."+val[0]);
			remval=removespaces(objf.value);
			if (remval==''){
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			}
			if (isNaN(objf.value)){
					alert("Please enter a number value only.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			}
		}
		if(val[1]=="s"){
			objf = eval("document."+formval+"."+val[0]+".options[document."+formval+"."+val[0]+".selectedIndex]");
			if (objf.value==''){
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.focus();
					return false;
			}
		}
		if(val[1].substr(0,1)=="l"){
			objf = eval("document."+formval+"."+val[0]);
			ln = val[1].substr(1,1);
			vl=objf.value;
			remval=removespaces(vl);
			if (remval==""){
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			} else if (ln>vl.length){
					alert("Your entry must be at least "+ln+" characters long.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			}
		}
		if(val[1]=="m"){
			//email exists and validation
			objf = eval("document."+formval+"."+val[0]);
			remval=removespaces(objf.value);
			if (remval==""){
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.value="";
					objf.focus();
					return false;
			}
			if (remval!=""){
				if (objf.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
					alert("Please enter a valid e-mail address.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.focus();
					return false;
				}
			}
		}
		if(val[1]=="i"){
			//email validation only
			objf = eval("document."+formval+"."+val[0]);
			remval=removespaces(objf.value);
			if (remval!=""){
				if (objf.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
					alert("Please enter a valid e-mail address.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.focus();
					return false;
				}
			}
		}
		if(val[1]=="t"){
			//match 2 fields
			objf  = eval("document."+formval+"."+val[0]);
			objf2 = eval("document."+formval+"."+val[0]+"2");
			remval=removespaces(objf.value);
			if (remval!=""){
				if (objf.value!=objf2.value){
					alert("Your entries do not match.");
					objf.style.background=fieldcol2;
					objf2.style.background=fieldcol2;
					objf.className="rgbold_k1";
					objf2.className="rgbold_k1";
					objf.focus();
					return false;
				}
			} else {
					alert("Please complete the appropriate field.");
					objf.style.background=fieldcol;
					objf.className="rgbold_k1";
					objf.focus();
					return false;
			}
		}
		if(val[1]=="c"){
			objf = eval("document."+formval+"."+val[0]);
			if (objf.checked==false){
					alert("Please tick the appropriate box to continue.");
					objf.style.background=fieldcol2;
					objf.focus();
					return false;
			}
		}
	}
   objf = eval("document."+formval);
   objf.submit();
 
}

