function makeCurrency(field){
	num=field.value;
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) {
		num = "0";
		alert ("You must enter a number in \"" + field.getAttribute('vname') + "\"");
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	//num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	var newnum = (((sign)?'':'-') + num + '.' + cents);
	field.value=newnum;
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}


function validateField(thisfield) {
        var valid=true;
                if (thisfield.getAttribute('vdt') != undefined) {
                        switch(thisfield.getAttribute('vdt')) {
                                case "text":
								thisfield.value=ltrim(thisfield.value);
                                if (thisfield.value == "") {
                                        if (!thisfield.getAttribute('vname')) {
                                                fieldName = thisfield.name;
                                                fieldName = fieldName.replace (/_/g, " ");
                                        }
                                        else
                                        {
                                                fieldName = thisfield.getAttribute('vname');
                                        }
                                        alert("\"" + fieldName + "\" must be filled out.");
                                        valid=false;
                                        }
                                break
                                case "number":
                                if (thisfield.value == "") {
                                        if (!thisfield.getAttribute('vname')) {
                                                fieldName = thisfield.name;
                                                fieldName = fieldName.replace (/_/g, " ");
                                        }
                                        else
                                        {
                                                fieldName = thisfield.getAttribute('vname');
                                        }
                                        alert("\"" + fieldName + "\" must contain a number.");
                                        valid=false;
                                        }
                                break
                                case "e-mail":
                                apos=thisfield.value.indexOf("@")
                                dotpos=thisfield.value.lastIndexOf(".")
                                if (apos<1||dotpos-apos<2) {
                                        if (!thisfield.getAttribute('vname')) {
                                                fieldName = thisfield.name;
                                                fieldName = fieldName.replace (/_/g, " ");
                                        }
                                        else
                                        {
                                                fieldName = thisfield.getAttribute('vname');
                                        }
                                        alert("\"" + fieldName + "\" must contain a valid e-mail address.");
                                        valid=false;
                                        }
                                break
								case "cost":
                                 if (isNaN(thisfield.value)) {
                                        if (!thisfield.getAttribute('vname')) {
                                                fieldName = thisfield.name;
                                                fieldName = fieldName.replace (/_/g, " ");
                                        }
                                        else
                                        {
                                                fieldName = thisfield.getAttribute('vname');
                                        }
                                        alert("\"" + fieldName + "\" must contain a valid cost.");
                                        valid=false;
                                        }
                                break
                        }
                }
 if (!valid) {return false} else {return true};
}

function validateFields(thisform) {
	 var valid=true;
	 var validRet=true;
	 for (i=0; i<thisform.elements.length; i++) {
		if (thisform.elements[i].getAttribute('vdt') != undefined) {
				validRet=validateField(thisform.elements[i]);
				if (!validRet) valid=false;
			}
		}
	if (!valid) {return false} else {return true};
}
