function convertIt(_a) {
  var _c = _a;
  var _x = _a.indexOf("$");
  if (_x == -1 ) _x = _a.indexOf(",");
  if (_x != -1) {
    var _p1 = _a.substr(0,_x);
	var _p2 = _a.substr(_x+1,_a.length);
    _c = convertIt(_p1+_p2);
  }
  return (_c);
}


$(document).ready(function(){

   /* $.preloadimages('');*/

    $('.changemo').swapit('_over');
    
    if ($('form.contact-form').length) {
    	$('form.contact-form input#submitcontact').click(function() {
    	
    		var _errors = new Array();
    		if ($('form.contact-form input[name="First_Name"]').val().length == 0) {
    			$('form.contact-form input[name="First_Name"]').addClass('formerror');
    			_errors.push("You must provide your first name.");
    		}
    		if ($('form.contact-form input[name="Last_Name"]').val().length == 0) {
    			$('form.contact-form input[name="Last_Name"]').addClass('formerror');
    			_errors.push("You must provide your last name.");
    		}
    		if ($('form.contact-form input[name="Email_Address"]').val().length == 0) {
    			$('form.contact-form input[name="Email_Address"]').addClass('formerror');
    			_errors.push("You must enter a valid email address.");
    		} else {
    			var regMail = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
				if (regMail.test($('form.contact-form input[name="Email_Address"]').val()) == false) {
					$('form.contact-form input[name="Email_Address"]').addClass('formerror');
					_errors.push("You must enter a valid email address.");
				}
    		}
    		if ($('form.contact-form input[name="Subject"]').val().length == 0) {
    			$('form.contact-form input[name="Subject"]').addClass('formerror');
    			_errors.push("You must enter a subject.");
    		}
    				
    		if ($('form.contact-form textarea#Comments').val().length == 0) {
    			$('form.contact-form textarea#Comments').addClass('formerror');
    			_errors.push("Please enter your questions or comments in the box provided.");
    		}
    		
    		if (_errors.length) {
    			alert("Error\n"+_errors.join("\n"))
    			return false;
    		}
    		
    		return true;
    	});
    }
    
    /**
     *	Cubic Feet Calculator
     */
    if ($('form.calc-form').length) {
    	
    	$('form.calc-form span.calc-display').text('');
    	
    	$('form.calc-form input#calc-submit').click(function() {
    	
    		var _calcdepth = parseFloat($('input[name="calc-depth"]').val());
    		var _calcwidth = parseFloat($('input[name="calc-width"]').val());
    		var _calcheight = parseFloat($('input[name="calc-height"]').val());
    		
    		var _errors = new Array();
    		
    		if (isNaN(_calcdepth) || isNaN(_calcwidth) || isNaN(_calcheight)) {
    			
    			if (isNaN(_calcdepth)) {
    				_errors.push('You forgot to enter the depth of your cargo space.');
    			}
    			if (isNaN(_calcwidth)) {
    				_errors.push('You forgot to enter the width of your cargo space.');
    			}
    			if (isNaN(_calcheight)) {
    				_errors.push('You forgot to enter the height of your cargo space.');
    			}
    			
    			$('form.calc-form span.calc-display').html('<h1 id="mainhead">Oops!</h1><p>'+_errors.join('<br />')+'</p>');
    			
    		} else {
    			
    			_calcvolume = parseInt(((_calcwidth) * (_calcheight) * (_calcdepth)) / 27);
    			
    			$('form.calc-form span.calc-display').html('<h1>Wow!</h1><p>You have '+_calcvolume+' cubic yard(s) of stuff!</p>');
    			
    		}
    		
    		return false;
    		
    	});
    
    }
    
});
