

// Function to show a menu -- sets the layer variable by the getElementById method
function showLayer(layerid) {
	var layer = document.getElementById(layerid);
	layer.style.visibility = "visible";
}
// Function to hide a menu -- turns "off" the layer
function hideLayer(layerid) {
	var layer = document.getElementById(layerid);
	layer.style.visibility = "hidden";
}

// trim whitespaces
String.prototype.trim = function(){
	return LTrim(RTrim(this));
};

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Pad string
String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
};

// check for valid email
String.prototype.isEmail = function() {
	var emailReg = /^[a-zA-Z_0-9\.\-]+\@([a-zA-Z_0-9\-]+\.)+[a-zA-Z_0-9\-]+$/;
	var emailReg = /^[a-zA-Z_0-9\.\-]+\@([a-zA-Z_0-9\-\.]+)$/;
	return emailReg.test(this.trim());
};

function clearSearch(el){
	if(el.value == "<breeder search>")
		el.value = "";
}

/**
 *
 */
function validDate(date){

	date = date.trim();
	re = /^\d{1,2}[-\/]\d{1,2}[-\/]\d{4}$/; 

	if (date == '' || !date.match(re))
		return false;

	var pos1=date.indexOf('-');
	var pos2=date.indexOf('-',pos1+1);

	if (pos1==-1 || pos2==-1){
		pos1=date.indexOf('/');
		pos2=date.indexOf('/',pos1+1);
		
		if (pos1==-1 || pos2==-1)
			return false;
	}
	
	var month=date.substring(0,pos1);
	var day=date.substring(pos1+1,pos2);
	var year=date.substring(pos2+1)

	if (month <= 0 || day <= 0 || day <= 0)
		return false;

	var today = new Date();
	var thismonth = today.getMonth() + 1;
	var thisday = today.getDate();
	var thisyear = today.getFullYear();

	if(year > thisyear)
		return false;
	else if(year == thisyear && month > thismonth)
		return false;
	else if(year == thisyear && month == thismonth && day > thisday)
		return false;

	return true;
}

