// JavaScript Document
function chkEmail(eml)
{
	var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if (!eml.match(re)) 
	return 0;
	else
	return 1;

}

function chkText(text)
{
var rexpr =/^[0-9a-zA-Z\s]+$/;
if (!text.match(rexpr))
return 0;
else
return 1;
}

function chkCharacter(charr)
{
	var expch =/^[a-zA-Z\s]+$/;
	if (!charr.match(expch))
	return 0;
	else
	return 1;
}
function chkNum(num)
{
	var rexp = /^[0-9\(\)\+\.\-\ \\]+$/;
	if (!num.match(rexp))
	return 0;
	else
	return 1;
}


function chkEmpty(txt)
{
if (txt=="")
   return 0;
else
  return 1;
}


function CheckContact()
	{
	var  errormsg = "";
	Form = document.frm_mail;
//---------------------Name-------------------------------		
	if (!chkEmpty(Form.name.value))
		errormsg = errormsg + "Error: Please Enter Name. \n";
		
		if (chkEmpty(Form.name.value))
		if(!chkCharacter(Form.name.value))
			errormsg = errormsg + "Error: Invalid Input For Name Please Enter Character Only. \n";
//--------------------------------------------------------------

//---------------------Company Name-------------------------------	
	if (chkEmpty(Form.cname.value))
		if(!chkText(Form.cname.value))
			errormsg = errormsg + "Error: Invalid input for Company Name. \n";
//--------------------------------------------------------------

//---------------------phone------------------------------------	
	if (chkEmpty(Form.phone.value))
		if(!chkNum(Form.phone.value))
			errormsg = errormsg + "Error: Phone number should be in Number. \n";
//--------------------------------------------------------------

//---------------------Email-------------------------------	
	if (!chkEmpty(Form.email.value))
		errormsg = errormsg + "Error: Please Enter Email Address. \n";

	if (chkEmpty(Form.email.value))
		if (!chkEmail(Form.email.value))
			errormsg = errormsg + "Error: Please Enter Valid Email Address. \n";
//--------------------------------------------------------------

//---------------------comments-------------------------------			
	if (!chkEmpty(Form.comments.value))
		errormsg = errormsg + "Error: Please Enter Comments. \n";
		
/*		if (chkEmpty(Form.comments.value))
		if(!chkText(Form.comments.value))
			errormsg = errormsg + "Error: Invalid input for Comments. \n";
			
			
	if (chkEmpty(Form.comments.value))
		{
		inputStr = Form.comments.value;
		strlength= inputStr.length;
			if (strlength > 600)
			{
				Form.comments.value=inputStr.substring(0,600);
				errormsg =errormsg + "Error: The character limit is 600.";
				
			}
		}*/
//--------------------------------------------------------------



	if (errormsg == "")
	{
		Form.action = "contact.php" ;
		Form.submit();
		
	}
	else
	{
		alert ( errormsg );
	}

}

//------------------Step1--------------------------

function checkstep1()
{
	
	var errmsg ="";
	Form = document.frm1;
	
	
	for(i=1; i<=10; i++)
		{
		var name = "loanType"+i;
		var box = document.getElementById(name); 
		if (box.checked == true) 
		{
			var count = true;
			break;
		}
		
	}
	if(!count)
	errmsg = "Error: Please Choose Loan Type.";
	
	if (errmsg=="")
	{
		Form.action="step2.php";
		Form.submit();
	}
	else
	{
		alert (errmsg);	
	}

}
//-----------------Step2-------------------------

function checkstep2()
{
	var errmsg ="";
	Form = document.frm2;
	var count =false;
	
	
//---------------------Name-------------------------------		
	if (!chkEmpty(Form.amount.value))
		errmsg = "Error: Please Enter Loan Amount. \n";
		
		if (chkEmpty(Form.amount.value))
		if(!chkNum(Form.amount.value))
			errmsg = errmsg + "Error: Invalid Input For Loan Amount. \n";
//--------------------------------------------------------------
	
	for(i=1; i<=7; i++)
		{
		var name = "credit"+i;
		var box = document.getElementById(name); 
		if (box.checked == true) 
		{
			count = true;
			break;
		}
		
	}
	if(!count)
	errmsg =  errmsg + "Error: Please Choose Bad Credit.\n";
	
	if(errmsg =="")
	{
		Form.action="step3.php";
		Form.submit();
	}
	else
	{
		alert (errmsg);	
	}
	
}
//---------------------Step3-------------------------
function checkstep3()
{
	var errmsg ="";
	Form = document.frm3;
	
	
	
//---------------------Name-------------------------------		
	if (!chkEmpty(Form.fname.value))
		errmsg = "Error: Please Enter First Name. \n";
		
		if (chkEmpty(Form.fname.value))
		if(!chkCharacter(Form.fname.value))
			errmsg = errmsg + "Error: Invalid Input For First Name. \n";
//--------------------------------------------------------------
//---------------------Surname-------------------------------	
	if (!chkEmpty(Form.surname.value))
		errmsg =  errmsg + "Error: Please Enter Surname. \n";
		
	if (chkEmpty(Form.surname.value))
		if(!chkCharacter(Form.surname.value))
			errmsg = errmsg + "Error: Invalid input for Surname. \n";
//--------------------------------------------------------------

//--------Date-------------
	if(!chkEmpty(Form.date1.value))
		errmsg = errmsg + "Error: Please Enter Date. \n";

//--------month-------------
	if(!chkEmpty(Form.month1.value))
		errmsg = errmsg + "Error: Please Enter Month. \n";
		
//---------year-------------------
	if(!chkEmpty(Form.year1.value))
		errmsg = errmsg + "Error: Please Enter year. \n";

//---------------------phone------------------------------------	
	if (chkEmpty(Form.phone.value))
		if(!chkNum(Form.phone.value))
			errmsg = errmsg + "Error: Phone number should be in Number. \n";
//--------------------------------------------------------------	
//---------------------Email-------------------------------	
	if (!chkEmpty(Form.email.value))
		errmsg = errmsg + "Error: Please Enter Email Address. \n";

	if (chkEmpty(Form.email.value))
		if (!chkEmail(Form.email.value))
			errmsg = errmsg + "Error: Please Enter Valid Email Address. \n";
//--------------------------------------------------------------	
	if(errmsg =="")
	{
		Form.action="step_save.php";
		Form.submit();
	}
	else
	{
		alert (errmsg);	
	}
	
}




