function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//=================================
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//======================================
//====Check for  valid email address====
//======================================
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}

//==============================
//=====Check for characters=====
//==============================
function validateTALength(strField, cntlName, maxChar)
{
	if(obj.elements[cntlName].value.length > maxChar)
	{
		alert(strField+" should be within "+maxChar+" characters.");
		obj.elements[cntlName].focus();
		obj.elements[cntlName].select();
		return false;
	}
	return true;
}

//============================================
//============ Checks URL against link =======
//============================================
function chkURL(tmpStr)
{
	var url_pat = /^(http|https|ftp):\/\/([\w-]+\.)+[\w-]+(\/[\w-\.\/?%&amp;,=#@\/:]*)?/;
	return(url_pat.test(tmpStr));
}

//=============================================
//======Function for opening a new window======
//=============================================
function showWindow(fName, width, height, left, top)
{
	window.open(fName, '', 'width='+width+',height='+height+',left='+left+',scrollbars=1,top='+top+',toolbar=0,menubar=0,location=0');
}

//=============================
//===Function to Search Dog====
//=============================
function Search()
{
	obj.keywords.value = obj.keywords.value.replace(/[^\w]+/g, ' ');
	trimFields();
	if(obj.keywords.value == "" || obj.keywords.value == 'Enter the Keywords')
	{
		alert("Please enter the keywords for searching.");
		obj.keywords.focus();
		return false;
	}
	//Everything fine
	self.location = "search.php?keywords="+encodeURIComponent(obj.keywords.value);
	return true;
}

//Used to call click event of button by pressing enter key on a text box
function clickButton(e)
{
	var evt = e ? e : window.event;
	if(evt.keyCode == 13)
	{
		Search();
	}
}

//===================================
//====Function to Search Pedigree====
//===================================
function searchPedigree()
{
	var dog_name = obj.search_pedigree.value;
	trimFields();
	if(dog_name == "" || dog_name == 'Enter the Dog Name')
	{
		alert("Please enter the Dog Name.");
		obj.search_pedigree.focus();
		return false;
	}
	//Everything fine
	self.location = "pedigree.php?dog_name="+encodeURIComponent(dog_name);
	return true;
}

//Used to call click event of button by pressing enter key on a text box
function clickEnterButton(e)
{
	var evt = e ? e : window.event;
	if(evt.keyCode == 13)
	{
		searchPedigree();
	}
}

//===================================
//====Function to Search ShowDog====
//===================================
function searchShowDog(genderName)
{
	var dog_name = obj.search_dogs.value;
	trimFields();
	if(dog_name == "" || dog_name == 'Enter the Dog Name')
	{
		alert("Please enter the Dog Name.");
		obj.search_dogs.focus();
		return false;
	}
	//Everything fine
	self.location = "show_dogs.php?gender="+genderName+"&dog_name="+encodeURIComponent(dog_name);
	return true;
}

//Used to call click event of button by pressing enter key on a text box
function clickEnterButtonShowDog(e ,genderName)
{
	var evt = e ? e : window.event;
	if(evt.keyCode == 13)
	{
		searchShowDog(genderName);
	}
}
