/*
 * Common JS Functions (jQuery ext and other)
 */
$.fn.clearForm = function() {
 return this.each(function() {
   var type = this.type, tag = this.tagName.toLowerCase();
   if (tag == 'form')
     return $(':input',this).clearForm();
   if (type == 'text' || type == 'password' || tag == 'textarea')
     this.value = '';
   else if (type == 'checkbox' || type == 'radio')
     this.checked = false;
   else if (tag == 'select')
     this.selectedIndex = -1;
 });
};

function checkMail(str) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return Boolean(filter.test(str));
}

function checkWMZ(str) {
    var filter = /^Z\d{12}$/i;
    return Boolean(filter.test(str));
}

function checkWMR(str) {
    var filter = /^R\d{12}$/i;
    return Boolean(filter.test(str));
}

function ltrim(str) { return str.replace(/^\s+/,""); }

function left(str, n) {
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
	return String(str).substring(0,n);
}
