﻿function doSubmit(){
	var username=document.frmcsr.txtname.value;
	var company=document.frmcsr.txtCompany.value;
	//var addr1=document.frmcsr.txtAddress.value;
	//var city=document.frmcsr.txtCity.value;
	var pin=document.frmcsr.txtpin.value;
	//var state=document.frmcsr.ddstate.options[document.frmcsr.ddstate.selectedIndex].value;
	var phone=document.frmcsr.txtPhone.value;
	var email=document.frmcsr.txtEmail.value;
	var model=document.frmcsr.ddmodel.options[document.frmcsr.ddmodel.selectedIndex].value;
	var unit=document.frmcsr.txtunit.value;
	var problemdesc=document.frmcsr.txtproblem.value;
	
	if(username.length==0 || username.length=='null')
	{
	alert("Name Field should not be Empty");
	document.frmcsr.txtname.focus();
	document.frmcsr.txtname.select();
	return false;
	}

	ch1=username.substring(0,1);
	if((ch1<"a" || ch1>"z") && (ch1<"A" || ch1>"Z") && ch1==" ")
		{
			alert("The Name Field should begin with an Alphabetic Character.");
			document.frmcsr.txtname.focus();
			document.frmcsr.txtname.select();
			return false;
		}

	for (var i=0; i<username.length; i++) 
		{
			var ch =username.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch != ' ')) 
			{
				alert("The Name Field  accepts Letters Only.\n\nPlease Re-enter");
				document.frmcsr.txtname.focus();
				document.frmcsr.txtname.select();
				return false;
			}
		}
		
	if(company.length==0 || company.length=='null')
	{
	alert("company Field should not be Empty.");
	document.frmcsr.txtCompany.focus();
	return false;
	}

	if(pin.length==0 || pin.length=='null')
	{
	alert("Pincode Field should not be Empty.");
	document.frmcsr.txtpin.focus();
	return false;
	}
	if(phone.length==0 || phone.length=='null')
	{
	alert("Phone Field should not be Empty, Please Enter");
	document.frmcsr.txtPhone.focus();
	return false;
	}
	if(phone.substring(0,1)==" ")
	{
	alert("Phone Field Should Begin With a Number.")
	document.frmcsr.txtPhone.focus();
	document.frmcsr.txtPhone.select();
	return false;
	}
	for (var i=0;i<phone.length;i++)
	{
	var ch=phone.substring(i,i+1)
	if ( isNaN(ch) && (ch !="-") && (ch !="/") && (ch !=" "))
	{
	alert("Phone field accepts Numbers, - and / only.");
	document.frmcsr.txtPhone.focus();
	document.frmcsr.txtPhone.select();
	return false;
	}
	}
	if(phone.length<5)
	{
	alert("Phone Field accepts more than 5 numbers only.");
	document.frmcsr.txtPhone.focus();
	return false;
	}

	elen= email.length;
		efirstchar = email.substring(0, 1);
		elastchar  = email.substring(elen-1, elen);

		atPos = email.indexOf("@",1)	
		if (atPos == -1) 
		{
			alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
		if (email.indexOf("@",atPos+1) != -1) 
		{
		alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select(); 
			return false;
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) 
		{	
		alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
		if (periodPos+3 > elen)	
		{ alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
		if (email.indexOf("..",1) != -1)
		 {
		alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
		if (email.indexOf("@.",1) != -1) {
		alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
		if (email.indexOf(".@",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
	if (email.indexOf("-@",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
	if (email.indexOf("@-",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
	if (email.indexOf("-.",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
	if (email.indexOf(".-",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}
	if (email.indexOf("--",1) != -1)
		 {
		 alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}        
	if((efirstchar<"a" || efirstchar>"z") && (efirstchar<"A" || efirstchar>"Z"))
		{
		alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
			return false;
		}

		if((elastchar<"a" || elastchar>"z") && (elastchar<"A" || elastchar>"Z"))
		{
			alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();	
			return false;
		}

	    	for (var i = 1; i < elen; i++)
			{
			var ch = email.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && (ch != "@") && (ch != ".") && (ch !="-"))
			{	
				alert("Please Enter Valid Email Id");
			document.frmcsr.txtEmail.focus();
			document.frmcsr.txtEmail.select();
				return false;
			}
			}
			
	if (model==0)
	{
		alert("Select Model")
		document.frmcsr.ddmodel.focus();
		return false;
	}		
	
	if(unit.length==0 || unit.length=='null')
	{
	alert("Unit Serial Number Field should not be Empty.");
	document.frmcsr.txtunit.focus();
	return false;
	}
	
	if(problemdesc.length==0 || problemdesc.length=='null')
	{
	alert("Problem Description Field should not be Empty.");
	document.frmcsr.txtproblem.focus();
	return false;
	}
	
	document.frmcsr.action="cus-support-reg-handler.asp"
	document.frmcsr.submit();
}


