function checkvalid()
{
	if(validate() == true)
	{
		document.hregistrationnew.submit();		
	}
}

function validate()
{
	
	var practice_name = document.hregistrationnew.practice_name.value;
	if(ltrim(practice_name).length < 1)
	{
		alert("Please enter Practice Name");
		document.hregistrationnew.practice_name.focus();
		return false;
	}

	var address1 = document.hregistrationnew.address1.value;
	if(ltrim(address1).length < 1)
	{
		alert("Please enter Address Line 1");
		document.hregistrationnew.address1.focus();
		return false;
	}

	var county = document.hregistrationnew.county.value;
	if(county == "0")
	{
		alert("Please select your County");
		document.hregistrationnew.county.focus();
		return false;
	}

	var postcode = document.hregistrationnew.postcode.value;
	if(ltrim(postcode).length < 1)
	{
		alert("Please enter Postal Code");
		document.hregistrationnew.postcode.focus();
		return false;
	}
	
	var telno = document.hregistrationnew.txttelno.value;
	if(ltrim(telno).length < 1)
	{
		alert("Please enter your telephone number");
		document.hregistrationnew.txttelno.focus();
		return false;
	}

	var faxno = document.hregistrationnew.txtfaxno.value;
	if(ltrim(faxno).length > 1)
	{
		if(isvalid_telno(faxno) == false)
		{
			alert("Please check your fax number");
			document.hregistrationnew.txtfaxno.focus();
			return false;		
		}
	}

	var mobileno = document.hregistrationnew.txtmobileno.value;
	if(ltrim(mobileno).length > 1)
	{
		if(isvalid_telno(mobileno) == false)
		{
			alert("Please check your mobile number");
			document.hregistrationnew.txtmobileno.focus();
			return false;		
		}
	}

	var region = document.hregistrationnew.region.value;
	if(region == "0")
	{
		alert("Please select your Region");
		document.hregistrationnew.region.focus();
		return false;
	}

	var emailid = document.hregistrationnew.txtemailid.value;
	if(isvalid_email(emailid) == false)
	{
		alert("Please check your Email Id");
		document.hregistrationnew.txtemailid.focus();
		return false;
	}

	var conperson = document.hregistrationnew.txtconperson.value;
	if(ltrim(conperson).length < 1)
	{
		alert("Please enter Contact Person");
		document.hregistrationnew.txtconperson.focus();
		return false;
	}
	
	var conposition = document.hregistrationnew.txtconposition.value;
	if(ltrim(conposition).length < 1)
	{
		alert("Please enter Contact Person's Position");
		document.hregistrationnew.txtconposition.focus();
		return false;
	}


	return true;
}

function intval(str)
{
	return parseInt(str,10);
}

function isvalid_hour(hour)
{
	var inthour = intval(hour);
	if(isNaN(inthour) == true)
	{
		return false;
	}
	if(inthour < 0 || inthour >= 12)
	{
		return false;
	}
	return true;
}

function isvalid_min(minute)
{
	var intminute = intval(minute);
	if(isNaN(intminute) == true)
	{
		return false;
	}
	if(intminute < 0 || intminute >= 60)
	{
		return false;
	}
	return true;
}

function ltrim(str)
{
	var i;
	var newstr = "";
	var char;
	var flag = 0;

	for(i=0;i<str.length;i++)
	{
		char = str.charAt(i);
		if(char >= 'a' && char <= 'z')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}
		if(char >= 'A' && char <= 'Z')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}
		if(char >= '0' && char <= '9')
		{
			newstr = newstr.concat(char);
			flag = 1;
		}	
		if(flag == 1)
		{
			if(char == ' ' || char == "-" || char == '-')
			{
				newstr = newstr.concat(char);
			}
		}
	}
	return newstr;
}

function isvalid_cardno(str)
{
	if(isNaN(Number(str)) == true)
	{
		return false;
	}
	if(ltrim(str).length < 10)
	{
		return false;
	}
	return true;
}

function isvalid_telno(str)
{
	if(isNaN(Number(str)) == true)
	{
		return false;
	}
	else
	{
		return true;
	}
}

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;

function isvalid_email(str)
{
	return emailfilter.test(str);
}
