// JavaScript Document
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function ltrim1(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
	
function checktelmobile(frm)
{
	with(frm)
	{
	//alert(trim(telcode.value)+"===");
		if(trim(telcode.value)!="" && trim(tel.value)!="")
		{
			telephone.value=trim(telcode.value)+'-'+trim(tel.value);
			telmobile.value=trim(telcode.value)+'-'+trim(tel.value);
		//	telmobilelength=trim(ltrim1(telcode.value,'0'))+'-'+trim(tel.value);
			telmobile.focus();
			telmobile.blur();
			
		}
		else if(trim(mobile.value)!="")
		{
			telmobile.value=trim(mobile.value);
		//	telmobilelength.value=trim(ltrim1(mobile.value,'0'));
			telmobile.focus();
			telmobile.blur();
		}
		else
		{
			//alert("please Either Enter Telephone or Mobile");
			telephone.value='';
			telmobile.value='';
		//	telmobilelength=='';
			telmobile.focus();
			telmobile.blur();
		}
	}
}
$().ready(function() {
	// validate signup form on keyup and submit
	$("#frmtrial").validate({
		rules: {
			name: {
				required: true,
				minlength: 4
			},
			organization: {
				required: true,
				minlength: 4
			},			
			/*tel: {
				required: true,
				minlength: 5
			},*/	
			telmobile:{
				required:true,/*,
				remote:"checktelmobile.php"*/
				minlength:11
			},
			/*telmobilelength: {
				minlength:10
			},*/
			email: {
				required: true,
				email: true
				/*remote: "checkemail.php"*/
			},
			state : {
				required: true
			},
			product: {
				required: true,
				minlength: 5
			}
		},
		messages: {
			name: "<br />Please Enter Your Name",
			organization: "<br />Please enter your Organisation Name",
			/*tel: "<BR>Please Enter Your Telephone No.",*/
			telmobile: {
				required: "<BR>Please Either Enter Your Telephone No. with Code or Mobile No.",
				minlength: "<BR>Telephone or Mobile No. Min Length should be 11(with prefix 0)"/*,
				remote: jQuery.format("<BR>{0}Telephone or Mobile No. Min Length should be 11(with prefix 0)")*/
			},
			/*telmobilelength: "<BR>Telephone or Mobile No. Min Length should be 10",*/
			email: {
				required:"<br />Please Enter Email Address",
				email: "<br />Please Enter a Valid Email Address"
				/*remote: jQuery.format("<BR>{0} is already in use")		*/
			},
			state :"<BR> Please Select Any State",
			product: "<br />Please Enter Product/Services"			
		}
	});

});

function validatefrm(frm)
{
	with(frm)
	{
		//alert(document.getElementById('paymentopt').value);
		//return false;
		//radCheque, radCreditcard  
		if(required(name,"Name")==false)
			return false;
		else if(required(organization,"Organization")==false)
			return false;
		
		else if(required(tel,"Telephone")==false)
			return false;
		else if(PhoneValidate(tel)==false)
			return false;
		else if(required(email,"E-mail")==false)
			return false;
		else if(EmailValidate(email)==false)
			return false;
		else if(state.value==0)
		{
			document.getElementById('errMsg').innerHTML="Please Select Any State";
			state.focus();
			return false;
		}
		
		else if(required(product,"Products/Services")==false)
			return false;
				
	}
	frm.action="free.php";
	frm.submit();
}