function isNumeric(string, ignoreWhiteSpace) 
{
	if (string.search) 
	{
		if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
	}
	return true;
}

function isAlphaNumeric(string, ignoreWhiteSpace) 
{
	if (string.search) 
	{
		if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false;
	}
	return true;
}

function isEmail(address) 
{
	if (address != '' && address.search) 
	{
		if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
		else return false;
	}
	var domain = address.substring(address.indexOf('@') + 1);
	if (domain.indexOf('.') == -1) return false;
	if (domain.indexOf('.') == 0 || domain.indexOf('.') == domain.length - 1) return false;
	return true;
}

function isValidName(string)
{
	var re = /^([a-zA-Z])+$/;
	if(!string.match(re))
		return false;
	else
		return true;
}

function strtrim(inputString) 
{
	if (typeof inputString != "string") 
	{
		return inputString; 
	}
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") 
	{
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ")
	{
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1)
	{
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; 
}

function autotab(original,destination)
{
	if(IgnoreKeys())
		return;
	
	if(document.selection.createRange().text.length != 0)
		return;

	if(original.getAttribute && original.value.length == original.getAttribute("maxlength"))
	{
		destination.focus()
	}
}

function IgnoreKeys()
{
	// Ignore Home and End keys
	if(event.keyCode == 35 || event.keyCode == 36) //home and end
		return true;

	if(event.keyCode == 9) // Shift tab
		return true;
		
	if(event.keyCode == 37 || event.keyCode == 38 || 
		event.keyCode == 39 || event.keyCode == 40) // Arrow keys
		return true;
		
	if(event.keyCode == 46) //Delete
		return true;
		
	if(event.keyCode == 16) // Shift
		return true;				
		 	
	if(event.keyCode == 8) // Back
		return true;				

	return false;			

}

function validate_forms()
{
	form1 = document.frmfeed;
	if(strtrim(form1.txt_fname.value) == "")
	{
		alert("Please Specify Your Name !!");
		form1.txt_fname.value = strtrim(form1.txt_fname.value);
		form1.txt_fname.focus();
		form1.txt_fname.select();
		return false;
	}
	if(strtrim(form1.txt_fname.value).length < 2)
	{
		alert("Your Name is too short!!");
		form1.txt_fname.value = strtrim(form1.txt_fname.value);
		form1.txt_fname.focus();
		form1.txt_fname.select();
		return false;
	}
	if(strtrim(form1.txt_org.value) == "")
	{
		alert("Please Specify Your Organization Name !!");
		form1.txt_org.value = strtrim(form1.txt_org.value);
		form1.txt_org.focus();
		form1.txt_org.select();
		return false;
	}
	if(strtrim(form1.txt_phone.value) == "")
	{
		alert("Please specify Phone Number.");
		form1.txt_phone.focus();
		form1.txt_phone.select();
		return false;
	}
	if(isNumeric(form1.txt_phone.value) == false)
	{
		alert("Phone should be numeric only.");
		form1.txt_phone.focus();
		form1.txt_phone.select();
		return false;
	}
	if(strtrim(form1.txt_phone.value).length < 6)
	{
		alert("Phone no. is too short.");
		form1.txt_phone.value = strtrim(form1.txt_phone.value);
		form1.txt_phone.focus();
		form1.txt_phone.select();
		return false;
	}
	if(strtrim(form1.Email.value) == "")
	{
		alert("Please Specify Your E-mail !!");
		form1.Email.value = strtrim(form1.Email.value);
		form1.Email.focus();
		form1.Email.select();
		return false;
	}
	if(isEmail(form1.Email.value) == false)
	{
		alert("EmailID is invalid");
		form1.Email.focus();
		form1.Email.select();
		return false;
	}

	return true;
}
