function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

function TestimonialformValidator()
{
	var Name    = document.getElementById('txtCoupleName');
	var remarks = document.getElementById('txtRemarks');
	var image   = document.getElementById('flePic');

	if(isEmpty(Name, "Name can not be empty"))
	{
		if(isEmpty(remarks,"Remarks can not be empty"))
		{
			if (isEmpty(image,"Please Specify an Image"))
			{	
				return true;

			}
		}
	}
	
	return false; 
}
function ContactformValidator()
{
	var BFName   = document.getElementById('txtBFName');
	var BLName   = document.getElementById('txtBLName');
	var GFName   = document.getElementById('txtGFName');
	var GLName   = document.getElementById('txtGLName');
	var Location = document.getElementById('txtLocation');
	var Phone    = document.getElementById('txtPhone');
	var Mail     = document.getElementById('txtMail');
	
		if(isAlphabet(BFName, "Please enter only letters for your name")) 
		{
			if (!(isAlphabet(BLName, "Please enter only letters for your name")))
			{
				if (!(isAlphabet(GFName, "Please enter only letters for your name")))
				{
					if(isAlphabet(GLName, "Please enter only letters for your name"))
					{
						if(isEmpty(Location, "Please specify a Location"))
						{
							if(isEmpty(Phone,"Please specify Phone No"))
							{
								if (emailValidator(Mail,"Please Enter a valid Email Address"))
								{
									return true;

								}
							}
						}
					}
				}
			}
		}
	
	return false; 
}



function isEmpty(elem, helperMsg){
	elem.value = trim(elem.value);
	
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus(); 
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}


