/*
Purpose : Admin Module's Verification
Author  : Debraj SenGupta (WDC)
Version : 1.0
*/

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function chk_feedback()
{

if(document.forms[0].mill_name_a.value=="" && document.forms[0].mill_name_b.value=="")
	{
	 alert("Please Enter mill name"); 
     document.forms[0].mill_name_a.focus();
	 return false;
	}

if(document.forms[0].mill_name_a.value !="" && document.forms[0].mill_name_b.value !="")
	{
	 alert("Only one mill name is acceptable"); 
	 return false;
	}

if(document.forms[0].annual_sale.value=="")
	{
	 alert("Please Enter annual sale");
     document.forms[0].annual_sale.focus();
	 return false;
	}

if(document.forms[0].annual_sale.value !="")
	{
      if(isNaN(document.forms[0].annual_sale.value))
	   {
		  alert("Annual Sale is numeric only"); 
          document.forms[0].annual_sale.focus();
          document.forms[0].annual_sale.select();
	      return false;
	   }
	}

var radio_choice=false;
var new_radio_choice=false;

for(var i=0;i<document.forms[0].use_paper.length;i++)
	{
if(document.forms[0].use_paper[i].checked)
	{
    radio_choice=true;
	}
	}
if(!radio_choice)
	{
	 alert("Please specify end use of your sold paper"); 
     return false;
	}
	
for(var j=0;j<document.forms[0].price_diff.length;j++)
	{
if(document.forms[0].price_diff[j].checked)
	{
    new_radio_choice=true;
	}
	}
if(!new_radio_choice)
	{
	 alert("Please specify landed price difference"); 
     return false;
	}

return true;

}

function checkuserpwd()
{
if(document.user_pwd.ppwd.value=="")
	{
	 alert("Please enter your previous password");
     document.user_pwd.ppwd.focus();
	 return false;
	}
if(document.user_pwd.npwd.value=="")
	{
	 alert("Please Enter youe new password");
     document.user_pwd.npwd.focus();
	 return false;
	}
if(document.user_pwd.cpwd.value=="")
	{
	 alert("Confirm your password");
     document.user_pwd.cpwd.focus();
	 return false;
	}
	if(document.user_pwd.cpwd.value !="" && document.user_pwd.npwd.value !="")
	{
	 if(document.user_pwd.cpwd.value != document.user_pwd.npwd.value)
		{
	 alert("Password does not match");
     document.user_pwd.cpwd.focus();
     document.user_pwd.cpwd.select();
	 return false;
		}
	}
}


function rm_calculation()
{
var gsm=document.getElementsByName("gsm[]");
var size1=document.getElementsByName("size1[]");
var size2=document.getElementsByName("size2[]");
var rm=document.getElementsByName("rm[]");
var rm_calculated=0;

for(var i=0;i<6;i++)
	{
if(size1[i].value !="" && size2[i].value !="")
		{

var s1=parseFloat(size1[i].value,10);
var s2=parseFloat(size2[i].value,10);
var g=parseFloat(gsm[i].value,10);

if(isNaN(size1[i].value))
			{
               alert("Size1 should be numeric");
               return false;
			}

else if(isNaN(size2[i].value))
			{
               alert("Size2 should be numeric");
               return false;
			}

else {
rm_calculated=(s1*s2*g)/20000;
rm[i].value=rm_calculated;
		}

		}

}
}

// Function for indent master

function chk_indent_master()
{

if(document.forms[0].order_no.value=="")
	{
	 alert("Please enter order no"); 
     document.forms[0].order_no.focus();
	 return false;
	}

var quality=document.getElementsByName("quality[]");
var gsm=document.getElementsByName("gsm[]");
var size1=document.getElementsByName("size1[]");
var size2=document.getElementsByName("size2[]");
var rm=document.getElementsByName("rm[]");
var qty_tonn=document.getElementsByName("qty_tonn[]");

var chk=0;
var total=0;
var rm_calculated=0;

for(var i=0;i<quality.length;i++)
	{
if(quality[i].value=="#" && gsm[i].value=="" && qty_tonn[i].value=="" )
		{
         chk=chk+1;        
		}
	}
if(chk==6)
	{
alert("Enter atleast one record");
return false;
	}

for(var i=0;i<6;i++)
	{
if(quality[i].value !="#")
		{
if(gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}

 }

if(gsm[i].value !="")
		{

if(isNaN(gsm[i].value))
			{
               alert("GSM should be numeric");
               return false;
			}
if(quality[i].value=="#" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}

 }

 if(size1[i].value !="")
		{
      if(isNaN(size1[i].value))
			{
               alert("Size1 should be numeric");
               return false;
			}else {
if(quality[i].value=="#" || gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}
 }

if(size2[i].value !="")
		{
      if(isNaN(size2[i].value))
			{
               alert("Size2 should be numeric");
               return false;
			}else {
if(quality[i].value=="#" || gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}
 }

if(size1[i].value !="" && size2[i].value !="")
		{

var s1=parseFloat(size1[i].value,10);
var s2=parseFloat(size2[i].value,10);
var g=parseFloat(gsm[i].value,10);

rm_calculated=(s1*s2*g)/20000;
rm[i].value=rm_calculated;
		}
/*
 if(rm[i].value !="")
		{
   if(isNaN(rm[i].value))
			{
               alert("RM WT should be numeric");
               return false;
			}else {
if(quality[i].value=="" || gsm[i].value=="" || size[i].value=="" || qty_tonn[i].value=="")
			{
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}

 }
*/

 if(qty_tonn[i].value !="")
		{
	 if(isNaN(qty_tonn[i].value))
			{
               alert("Quantity should be numeric");
               return false;
			}else if(quality[i].value=="#" || gsm[i].value=="")
			{
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			else {
              
            total=total + parseFloat(qty_tonn[i].value,10);
			
			}

 }

	}

document.forms[0].total.value=total;

document.forms[0].action="user_indent1.php";
document.forms[0].submit();
return true;

}



// Function for bulk indent 

function chk_bulk_indent()
{

if(document.forms[0].circular_dt.value=="")
	{
	 alert("Please enter circular date"); 
     document.forms[0].circular_dt.focus();
	 return false;
	}

if(document.forms[0].qty.value=="")
	{
	 alert("Please enter total quantity"); 
     document.forms[0].qty.focus();
	 return false;
	}

if(document.forms[0].qty.value !="")
	{
	if(isNaN(document.forms[0].qty.value))
		{
	 alert("Total quantity must be numeric"); 
     document.forms[0].qty.focus();
	 document.forms[0].qty.select();
	 return false;
	    }
	}

var quality=document.getElementsByName("quality[]");
var gsm=document.getElementsByName("gsm[]");
var size1=document.getElementsByName("size1[]");
var size2=document.getElementsByName("size2[]");
var rm=document.getElementsByName("rm[]");
var qty_tonn=document.getElementsByName("qty_tonn[]");

var chk=0;
var total=0;
var rm_calculated=0;

for(var i=0;i<quality.length;i++)
	{
if(quality[i].value=="#" && gsm[i].value=="" && qty_tonn[i].value=="" )
		{
         chk=chk+1;        
		}
	}
if(chk==6)
	{
alert("Select atleast one product");
return false;
	}

for(var i=0;i<6;i++)
	{
if(quality[i].value !="#")
		{
if(gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}

 }

if(gsm[i].value !="")
		{

if(isNaN(gsm[i].value))
			{
               alert("GSM should be numeric");
               return false;
			}
if(quality[i].value=="#" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}

 }

 if(size1[i].value !="")
		{
      if(isNaN(size1[i].value))
			{
               alert("Size1 should be numeric");
               return false;
			}else {
if(quality[i].value=="#" || gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}
 }

if(size2[i].value !="")
		{
      if(isNaN(size2[i].value))
			{
               alert("Size2 should be numeric");
               return false;
			}else {
if(quality[i].value=="#" || gsm[i].value=="" || qty_tonn[i].value=="")
			{
	
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}
 }

if(size1[i].value !="" && size2[i].value !="")
		{

var s1=parseFloat(size1[i].value,10);
var s2=parseFloat(size2[i].value,10);
var g=parseFloat(gsm[i].value,10);

rm_calculated=(s1*s2*g)/20000;
rm[i].value=rm_calculated;
		}
/*
 if(rm[i].value !="")
		{
   if(isNaN(rm[i].value))
			{
               alert("RM WT should be numeric");
               return false;
			}else {
if(quality[i].value=="" || gsm[i].value=="" || size[i].value=="" || qty_tonn[i].value=="")
			{
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			}

 }
*/

 if(qty_tonn[i].value !="")
		{
	 if(isNaN(qty_tonn[i].value))
			{
               alert("Quantity should be numeric");
               return false;
			}else if(quality[i].value=="#" || gsm[i].value=="")
			{
             alert("Please fill the corresponding related mandatory data");
			 return false;
			}
			else {
              
            total=total + parseFloat(qty_tonn[i].value,10);
			
			}

 }

	}

document.forms[0].total.value=total;

if(document.forms[0].qty.value != total)
	{
        alert("Total quantity does not equal to applied quantity");
        document.forms[0].total.focus();
		document.forms[0].total.select();
		return false;
	}

document.forms[0].action="bulk_indent1.php";
document.forms[0].submit();
return true;

}

