function checkDateFormat(dateid,fieldname,required){
		var dateformat = /^\d{4}\-\d{1,2}\-\d{1,2}$/
		var emptyDateformat = /^\s*$/
		var DateObj = document.getElementById(dateid);
		
		if(required && required == true){
			if(!dateformat.test(DateObj.value))
			{
				alert("Please use date format 'yyyy-mm-dd' for " + fieldname);
				return false;
			}
		} else {
			if(emptyDateformat.test(DateObj.value))
				return true;
			else if(!dateformat.test(DateObj.value))
			{
				alert("Please use date format 'yyyy-mm-dd' for " + fieldname);
				return false;
			}
		}
		
		var dateArray = DateObj.value.split("-");
		var year = parseInt(dateArray[0]);
		var month = parseInt(dateArray[1].replace(/^0*/,""));
		var day = parseInt(dateArray[2].replace(/^0*/,""));
		
		//alert(year + "-" + dateArray[1].replace(/^0*/,"") + "-" + day);
		
		if(year < 1990 || year > 2050){
			alert("The year should be between 1990 and 2050 for " + fieldname);
			return false;
		}
		if(month < 1 || month > 12){
			alert("Invalid month for " + fieldname);
			return false;
		}
		if(month == 2 && day != (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 )){
			alert("Invalid date for " + fieldname);
			return false;
		}
		
		if(day < 1 ){
			alert("Invalid date for " + fieldname);
			return false;
		}
		
		if(day > 31 && (month == 1 || month == 3 ||month == 5 ||month == 7 ||month == 8 ||month == 10 ||month == 12)){
			alert("Invalid date for " + fieldname);
			return false;
		}
		
		if(day > 30 && (month == 2 || month == 4 ||month == 6 ||month == 9 ||month == 11 )){
			alert("Invalid date for " + fieldname);
			return false;
		}
		
		return true;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function getProductListBySubject(category, subject, divImg, start, limit){
		if(!category || !subject)
			return;
		
		var url = "/catalog/getProductListBySubject.php";
		var params = 'category=' + category + "&subject=" + subject;
		
		if (limit > 0)
			params = params + '&start=' + start + "&limit=" + limit;
		
		set_visible("process_progress", "block");

		//alert("category: " + category + " - subject: " + subject + " - url: " + url + "?" + params);
		 var ajax = new Ajax.Request(
                                    url,
                                    {method: 'get', parameters: params, onFailure: reportError,
                                        onSuccess:function(transport)
                                        {
											set_visible("process_progress", "none");
                                            var json = transport.responseText.evalJSON(true);
                                           // alert(json.image);
                                            $('productList').innerHTML = "";
                                            $('productList').innerHTML = json.product_list_html;
											$(divImg).innerHTML = json.image;
											//alert($('img').innerHTML);
                                            
                                        }
                                    }
                                );
								
}
function reportError(request) {
	set_visible("process_progress", "none");
	alert("Request failed.");
}

function set_visible(element, visible) {
  if ("string" == typeof element) {
    element = $(element);
  } 
  element.setStyle({display:visible});
}

