/*
*@author: Prabhakar Manikonda (C) 2006
*email: email2prabhakar@gmail.com
*
*/

function hai()
{
  alert("hai");
}
 

 function changePaperPrice(te)
{
  
  ptype = te.value;
  price="11.00";
  
  switch(ptype)
  {
  case "PG180":
              price="5.75"
              break;
  case "PG220":
              price="6.25"
              break;
  case "PHG180":
              price="8.25"
              break;
  case "PHG240":
              price="9.25"
              break;
  case "UPG180":
              price="10.00"
              break;
  case "UPG180":
              price="11.00"
              break;
  case "SA120.80":
              price="11.25"
              break;
   default:  
              price="11.00"
              break;
   }
   f1.paperBundleCost.value= (parseFloat(price)*20);
   f1.paperCost.value=price;
   setValues();
  }


   function round()
  {
  i=0;j=0;k=0,ck=0;
   str =  f1.tmp.value;
   l = str.length;
   ck = str.indexOf(".");
   
     if(ck==-1)
     {
      f1.tmp.value=str+".00";
      return;
      }
      else if(ck==l-2)
      {
      f1.tmp.value=str+"0";
      return;
      }
      
      i=0;
      str1="",str2="";
      while(i<ck)
      {
       ch=str.charAt(i);
       str1+=ch;
       i++;
      }
       i++;
      while(i<l)
      {
       ch=str.charAt(i);
       str2+= ch;
       i++;
      }
       if(str2.length>2)
        {
		   if(str2.charAt(2)>=6)
			str2=str2.charAt(0)+ (parseInt(str2.charAt(1))+1);	  
			else
			str2=str2.charAt(0)+str2.charAt(1);
          }
          
       f1.tmp.value=str1+"."+str2;
      
   }
 function setValues()
 {
    i = 0,j=0,k=0;
    
      
     i= parseFloat(f1.paperCostT.value);
     j= i+parseFloat(f1.chemicalsCostT.value);
     f1.tmp.value=j;
     round()
     j = f1.tmp.value;
     f1.rawCostT.value=j;

     i= parseFloat(f1.ink600mlCost.value);
     j= parseFloat(f1.copiesPM.value);
     k = (i / j)*10;
	 f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.inkPerCopyCost.value=k;

     i= parseFloat(f1.paperBundleCost.value);
     j = i / 20;
     f1.tmp.value=j;
     round()
     j = f1.tmp.value;
     f1.paperCost.value=j;

     i= parseFloat(f1.equipmentCostT.value);
     j= parseFloat(f1.interestRateT.value);
     k = (i * j)/12;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.iCapitalPMT.value=k;

     i= parseFloat(f1.equipmentCost.value);
     j= parseFloat(f1.interestRate.value);
     k = (i * j)/12;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.iCapitalPM.value=k;

     i= parseFloat(f1.iCapitalPMT.value);
     j= parseFloat(f1.copiesPMT.value);
     k = (i / j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.interestOnEachCopyT.value=k;

     i= parseFloat(f1.iCapitalPM.value);
     j= parseFloat(f1.copiesPM.value);
     k = (i / j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.interestOnEachCopy.value=k;        


    i= parseFloat(f1.iCapitalPMT.value);
    j= parseFloat(f1.totalSalaryExpenseT.value);
    k= parseFloat(f1.shopRentPMT.value);
    k = i+j+k;
    f1.tmp.value=k;
     round()
     k = f1.tmp.value;
    f1.totalMonthlyCostsT.value=k;        

    i= parseFloat(f1.iCapitalPM.value);
    j= parseFloat(f1.totalSalaryExpense.value);
    k= parseFloat(f1.shopRentPM.value);
    k = i+j+k;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
    f1.totalMonthlyCosts.value=k;        



     i= parseFloat(f1.totalMonthlyCostsT.value);
     j= parseFloat(f1.copiesPMT.value);
     k = (i / j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.fixedExpencesPerCopyT.value=k;        

     i= parseFloat(f1.totalMonthlyCosts.value);
     j= parseFloat(f1.copiesPM.value);
     k = (i / j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.fixedExpencesPerCopy.value=k;        



     i= parseFloat(f1.rawCostT.value);
     j= parseFloat(f1.filmCostT.value);
     k =parseFloat(f1.fixedExpencesPerCopyT.value);
     k = i+j+k;
     i= parseFloat(f1.interestOnEachCopyT.value);
     k = k+i;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.totalExpencesPerCopyT.value=k;        


     i= parseFloat(f1.inkPerCopyCost.value);
     j= parseFloat(f1.paperCost.value);
     k =parseFloat(f1.fixedExpencesPerCopy.value);
     k = i+j+k;
     i= parseFloat(f1.interestOnEachCopy.value);
     k = k+i;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.totalExpencesPerCopy.value=k;        


     i= parseFloat(f1.salePriceForA4T.value);
     j= parseFloat(f1.totalExpencesPerCopyT.value);
     k = (i - j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.netProfitT.value=k;        

     i= parseFloat(f1.salePriceForA4.value);
     j= parseFloat(f1.totalExpencesPerCopy.value);
     k = (i - j);
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.netProfit.value=k;        

     i= parseFloat(f1.netProfitT.value);
     j= parseFloat(f1.totalExpencesPerCopyT.value);
     k = (i / j)*100;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.percentageT.value=k;

     bcolor="MediumSeaGreen"
     fcolor="black";
     
      
      if(k>=5)    
      {
     bcolor="MediumSeaGreen"
     fcolor="gold";
             }
      else if(k>=1)
       {
     bcolor="MediumSeaGreen"
     fcolor="black";
         }
      else if(k>=0.6)
       {
     fcolor="red";
         }
      else 
       {
     bcolor="red"
     fcolor="white";
         }

      
       f1.percentageT.style.background=bcolor;
       f1.percentageT.style.color=fcolor;



     i= parseFloat(f1.netProfit.value);
     j= parseFloat(f1.totalExpencesPerCopy.value);
     k = (i / j)*100;
     f1.tmp.value=k;
     round()
     k = f1.tmp.value;
     f1.percentage.value=k;
     bcolor="MediumSeaGreen"
     fcolor="black";
     
      
      if(k>=5)    
      {
      bcolor="MediumSeaGreen";
      fcolor="gold";
       }
     else if(k>=1)    
      {
       bcolor="MediumSeaGreen";
       fcolor="black";
       }
     else if(k>=0.5)    
       {
         fcolor="red";
        }
       else
         {
	   bcolor="red";
	   fcolor="snow";
           }

       f1.percentage.style.background=bcolor;
       f1.percentage.style.color=fcolor;
      
 }





 function check32f1()
{


       error = true;

 inc = 0
 len = document.f1.elements.length;
 
	    for(inc=0;inc<len;inc++)
	   {
			typ = document.f1.elements[inc].type;

		      if( (typ=="text")||(typ=="password")||(typ=="textarea")) 
		            {
                          	               text = (document.f1.elements[inc].value);
	                          error =checkSt(text);
                                             if( error ==false)
                          	                     { break; }

		            }
            
		  }

			     if(error==false)
		      alert("error: No Input Given or Spaces Entered !");
                   else
                   {
                   	 document.f1.submit();
                   }
     }



 function check32()
{


       error = true;

 inc = 0
 len = document.forms[0].elements.length;
 
	    for(inc=0;inc<len;inc++)
	   {
			typ = document.forms[0].elements[inc].type;

		      if( (typ=="text")||(typ=="password")||(typ=="textarea")) 
		            {
                          	               text = (document.forms[0].elements[inc].value);
	                          error =checkSt(text);
                                             if( error ==false)
                          	                     { break; }

		            }
            
		  }

			     if(error==false)
		          {
                           alert("error: No Input Given or Spaces Entered !");
                             return;
                         }
                   else
                   {
                   	 document.forms[0].submit();
                   }
     }

  
  function checkSt(text)
{

      if(text==null)
		  return false;
  l=text.length;
  i=0;j=0;
while(i<l)
{
  if( text.charAt(i) == ' ')
        j++;
    i++;
  }
  if((j==l)||(text.value==''))
   {
     return false;
       
     }
     else {return true;}

}

 


function checkid(ta)
{
 text=ta.value;
l=text.length;
i=0;j=0;
s=text.indexOf(' ');
while(i<l)
{
 ch=text.charAt(i);
 if((((ch>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z'))||((ch>=0)&&(ch<=9)))&&(ch!=' '))
{
 j++;
}
i++;
}
if(j!=l)
 {
  alert("ID have invalid charcters please check");
	ta.focus();
 }
} 


function checktext(ta)
{
	 text=ta.value;
	l=text.length;
	i=0;j=0;k=0;
	k=text.indexOf(' ');
	do
	{
	ch=text.charAt(i);
		if(((ch>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z'))||(ch==' '))
		{
		j++;
		}
    	i++;
	 }while(i<l);
 
	if((j!=l))
	{
	   alert("INVALID CHARCTERS PLEASE CHECK IT");
    	ta.focus();
       } 
} 



 function checknumber(te)
{

text=te.value;
l=text.length;
i=0;j=0;k=0;
 while(i<l)
 {
 ch=text.charAt(i);
  if(((ch>=0)&&(ch<=9))&&(ch!=' '))
{
 j++;
}
i++;
}
idx=0;
idx = text.indexOf(".");
if(idx!=-1)
if(idx>0&&idx<l-1)
  j++;
if(text.charAt(0)=='-'&&l>1)  
   j++;
   
if((j!=l))
 {
  alert("SHOULD NOT CONTAIN CHARCTERS");
  te.focus();
  te.value=0.00;
  return
 }
 else
  {
  if(idx==-1)
 te.value=text;
  // te.value=text+".00";
 else if (idx==l-2)
     te.value=text+"0";
     
     setValues ();
    }
} 




 function checkmobile(te)
{

text=te.value;
l=text.length;
i=0;j=0;k=0;
 while(i<l)
 {
 ch=text.charAt(i);
  if(((ch>=0)&&(ch<=9))&&(ch!=' '))
{
 j++;
}
i++;
}
idx=0;
idx = text.indexOf(".");
if(idx!=-1)
if(idx>0&&idx<l-1)
  j++;
if(text.charAt(0)=='-'&&l>1)  
   j++;
   
if((j!=l))
 {
  alert("SHOULD NOT CONTAIN CHARCTERS");
  te.focus();
  te.value="";
  return
 }
 else
  {
  if(idx==-1)
   te.value=text;
 else if (idx==l-2)
     te.value=text;
     
     setValues ();
    }
} 


function checkemail(ta)
{
 text=ta.value;
l=text.length;
k=0;i=0;j=0;s=0;
i=text.indexOf("@");
j=text.indexOf(".");
k=text.lastIndexOf(".");
s=text.indexOf(' ');
if((i!=-1)&&(((l-j)==7)||((l-k)==3))&&(s==-1));
else
 if((i!=-1)&&((l-k)==4)&&(s==-1));
else
 {
  alert("Given E-Mail ID is wrong please check");
	ta.focus();
	}
} 

function checkpass(ta)
{
 text=ta.value;
// alert(pass1);
} 

  function checkSelect()
{
       error = false;

 inc = 0
 len = document.forms[0].elements.length;
 
	    for(inc=0;inc<len;inc++)
	   {
			typ = document.forms[0].elements[inc].type;

		        if(typ=='select-one')
		             {
                          	                 n = (document.forms[0].elements[inc].selectedIndex);
 			    if(n==0)
			       {   error=true;  }	
                                          }
		       
                       }
  if(error==true)
 {
    alert('Wizard can not be proceeded until\n you select question types for all questions')                                            
  }
  else
   {
      check()    
    }
 }

 function readOptions(se)
 {
	   var k    
	  k = new Array(4) 
	 var i 
	 i=0  
	 var items,t; 
	var bflag
	bflag =false
	  items =' ' 
	  t = ' '
              if(se.selectedIndex==1) 
             { 
	               while(bflag==false)
		 {
		           t = prompt("Enter The Answer true or false ","t/f")
			 b=checkSt(t) 
			  if(b==false)
			{ 
				  i = i-1; 
				 alert('Spaces Entered Enter Again '); 
			       }
                                          else
			{
		                 if( (t.toUpperCase()=='T')||(t.toUpperCase()=='TRUE'))
			                 {
					  items='true'
					  bflag=true;
					  break;
				        }	
			                     else if( (t.toUpperCase()=='F')||(t.toUpperCase()=='FALSE'))
				                 {
						  items='false'
						  bflag=true;
						  break;
				        	}
		                          }           
		       }
	  }
                else  if(se.selectedIndex==2) 
	 { 
		   for(i=1;i<=4;i++) 
		 { 
	  
			  st = 'Please Enter Multiple Choice Item Name '+i; 
			 k[i] = prompt(st,'');  
			 b=checkSt(k[i]) 
			  if(b==false)
			{ 
				  i = i-1; 
				 alert('Spaces Entered Enter Again '); 
			       }
			      else
			             { 
		                                for(mi=1;mi<i;mi++)
				 {
			                   if(k[mi]==k[i])             
				       {
					 alert('Duplicate Value Entered\n     Enter Again ! ');
					i = i -1
					bflag =false;
					          }	
				     }/*end of dup checking loop */
		                                       if(bflag==true)
				           {	   t =t +'  '+k[i];
					   items = items+k[i]+ '``````'  
		        		                }

	                                                         }/*end of else block */ 
                                    } /* End of for loop reading */

		var st,txt
		bflag = true
		txt = 'Please Enter The Answer'
		 while(bflag==true)
		{ 
		     st =  prompt(txt,t);
	
			    for(i=1;i<=4;i++)
			    {
			          if(st==k[i])
				{
			                      bflag=false; 
				        break;
				    }
			              else
		                                 {
			                     txt =txt + '\nBad Value Enter By Seeing the options given ';
			                        }
           
				   } /* End of the for loop */
   			    } /* End of bflag-While loop  */
             }/*end of seledted index-1 if */

     return items;
   }

