var counter=200;
function restrict_chars(obj,maxchar,limit_char_display)
{
	var val=obj.value;

	try
	{
	if(val.length>maxchar)
	{
		alert("You have reached maximum characters limit.");
		obj.value=obj.value.substring(0,maxchar);
		return false;
	}
	counter=maxchar-(val.length);
	var str=counter+" Characters Remaining." 
	}
	catch(e)
	{
		alert(e);
	}
	document.getElementById(limit_char_display).innerHTML=str; 
}

function checkemail_reg(contact_email)
{
	
	
	var str=contact_email;
	var regis=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;

	if (regis.test(str)) { 	return true;
	} else {	
	 	return false;	}
		}
		
function checkphone_reg(contact_phone)
{

	var str1=contact_phone;
	//var regist=/^([\w-]+(?:\.[\w-]+)*)-((?:[\w-]+\.)*\w[\w-]{0,66})\-([0-9](?:\.[0-9])?)$/;
	var regist=/^([0-9][0-9][0-9]\D?[0-9][0-9][0-9]\D?[0-9][0-9][0-9][0-9])$/;
	//str.match(regexp)
	if(contact_phone.match(regist)) 
	{ 
		return true;
	} 
	else 
	{	
		return false;	
	}
}

function check_contform()
{
	var obj=document.form1;
	var msg="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
 	var error=false;
	var x,y,z;
	if(obj.contact_name.value=='') 
	{ 
	msg+="- Please enter your name.\n";  error=true; 
	x=1;
	//obj.contact_name.focus();
	
	}
	// if neither a valid email nor a valid phone number was entered:
	if(!checkphone_reg(obj.contact_phone.value) && !checkemail_reg(obj.contact_email.value) ) 
	{ 
		msg+="- Please enter either a valid phone number or a valid email address.\n"; 
		y=1;
		//obj.contact_phone.focus();
		error=true; 
	} 	
	// if the user wants to subscribe, he should enter a valid address
	//if(!error && obj.contact_subscribe.value!='' && !checkemail_reg(obj.contact_email.value)) {
	//	msg+="- Please enter either a valid email address to subscribe to our e-zine.\n"; 
	//	z=1;
	//	//obj.contact_email.focus();
	//	error=true; 
	//} 
	// if the user entered an email, it should be a valid one
	if(!error && obj.contact_email.value!='' && !checkemail_reg(obj.contact_email.value)) {
		msg+="- Please enter a valid email address.\n"; 
		z=1;
		//obj.contact_phone.focus();
		error=true; 
	} 

	if(!error && obj.contact_phone.value!='' && !checkphone_reg(obj.contact_phone.value)) {
		msg+="- Please enter a valid phone number.\n"; 
		y=1;
		//obj.contact_phone.focus();
		error=true; 
	} 

	if(error==true) 
	{
		alert(msg); 

		if(x==1)
		{
			obj.contact_name.focus();
		}		
		else if(y==1)
		{
			obj.contact_phone.focus();
		}
		else if(z==1)
		{
			obj.contact_email.focus();
		}
		return false;
	} 
	else 
	{
		return true;
	}
	 
}

