/*******************************************************************************************
 File        : jscript.js
 DateTime    : 13/02/2008.
 Author      : Pankaj Padole.
 Purpose     : This file contains common function used in the application 
*******************************************************************************************/
	
	/*******************************************************************************************
		 Function    : Reset()
		 DateTime    : 13/02/2008.
		 Author      : Pankaj Padole.
		 Purpose     : This function is used to reset the form
		 Parameter   :
		                frm - object - instance of the form object
		 Change Log  :
		______________________________________________________________________________________
		   No   |      Author       |      Date/Time            |     Issue 
		______________________________________________________________________________________
		        |                   |                           |
		        |                   |                           | 
    *******************************************************************************************/
	
	function Reset(frm)
	{
		document.forms(frm).reset();		
	}
	
  
     /*******************************************************************************************
         Function    : PhoneNumber()
         DateTime    : 13/02/2008.
         Author      : Pankaj Padole.
         Purpose     : This function is used to validate phone no,fax no,extension no. 
         Returns     : 
                        Returnvalue - boolean - true if unblock key is press, otherwise false.
         Change Log  :
        ______________________________________________________________________________________
           No   |      Author       |      Date/Time            |     Issue 
        ______________________________________________________________________________________
                |                   |                           |
                |                   |                           |
    *******************************************************************************************/	
	function PhoneNumber()
	{
	    var key = window.event.keyCode;
	    if (key > 57 || key < 48 )
	    {
	        if(key!=45 && key!=40 && key!=41 && key!=43 && key!=13 && key!=32)
	        {
	            window.event.returnValue = false;
	        }
        }
	}

     /*******************************************************************************************
         Function    : Numeric()
         DateTime    : 13/02/2008.
         Author      : Pankaj Padole.
         Purpose     : This function is used to validate numeric fields.
         Returns     : 
                        Returnvalue - boolean - true if unblock key is press, otherwise false.
         Change Log  :
        ______________________________________________________________________________________
           No   |      Author       |      Date/Time            |     Issue 
        ______________________________________________________________________________________
                |                   |                           |
                |                   |                           | 
    *******************************************************************************************/		
	function Numeric()
	{
	    var key = window.event.keyCode;
	    if (key > 57 || key < 48 )
	    {
			if(key!=46 )
			{
				if(key!=13)
				{
        		    window.event.returnValue = false;
 				}
 			}
    	}
	}

    /*******************************************************************************************
     Function    : ValidateForm()
     DateTime    : 13/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to validate the textboxes in careers-apply.asp page.
     Parameter   :
                    frm - object - instance of the form object
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
	function ValidateForm(frm)
 	{
	       var r=0;
   	       if(document.frm.txtFirstName.value == "")
           {
              alert("Please enter the First Name.")
    	      document.frm.txtFirstName.focus();
	          r=1;
              return(false);
           }
	       if(document.frm.txtLastName.value == "")
	       {
        	  alert("Please enter the Last Name.")
	          document.frm.txtLastName.focus();
		      r=1;	          
	          return(false);
           }
	      if(document.frm.comboDay.value == "")
	      {
      		 alert("Please Select Day.")
		     document.frm.comboDay.focus();
	         r=1;
	         return(false);
	      }
	      if(document.frm.comboMonth.value == "")
	      {
		      alert("Please Select Month.")
		      document.frm.comboMonth.focus();
		      r=1;
	          return(false);
	      }
	      if(document.frm.comboYear.value == "")
	      {
		      alert("Please Select Year.")
		      document.frm.comboYear.focus();
		      r=1;
	          return(false);
      	  }
	      if(document.frm.txtEducation.value == "")
	      {
		      alert("Please Enter Your Education Details.")
		      document.frm.txtEducation.focus();
		      r=1;
	          return(false);
	      }
	      if(document.frm.txtPresentAddress.value == "")
	      {
		      alert("Please Enter Your Present Address.")
		      document.frm.txtPresentAddress.focus();
		      r=1;
	          return(false);
          }
          if(document.frm.txtPermanentAddress.value == "")
	      {
		      alert("Please Enter Your Permanent Address.")
		      document.frm.txtPermanentAddress.focus();
		      r=1;
	          return(false);
          }
 	      if(document.frm.txtEmail.value == "")
	      {
		      alert("Please Enter Your Email Address.")
		      document.frm.txtEmail.focus();
		      r=1;
	          return(false);
          }
          var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		  var address = document.frm.txtEmail.value;
		  if(reg.test(address) == false) 
          {
	  	      alert("Please provide valid email.");
	  	      document.frm.txtEmail.focus();
	  	      r=1;
	          return (false);
	      }
          if (document.frm.txtCurrentCTC.value == "")
	      {
		      alert("Please Enter Your Current CTC.")
		      document.frm.txtCurrentCTC.focus();
		      r=1;
	          return(false);
          }
          else if(isNaN(document.frm.txtCurrentCTC.value)==true)
	      {
	   	      alert("CTC must be Numeric Field.");
	  	      document.frm.txtCurrentCTC.focus();
	  	      r=1;
	          return (false);
	      }
	     if (document.frm.txtExpectedCTC.value == "")
	     {
	  	     alert("Please Enter Your Expected CTC.")
	         document.frm.txtExpectedCTC.focus();
		     r=1;
	         return(false);
	     }
	     else if(isNaN(document.frm.txtExpectedCTC.value)==true)
	     {
		    alert("Expected CTC must be Numeric Field.");
		    document.frm.txtExpectedCTC.focus();
		    r=1;
	        return (false);
	     }
	     if(tf.txtCaptcha.value=="")
	     {
		    alert("Please enter Verification Code.")
		    tf.txtCaptcha.focus();
		    r=1;
		    return false;
	     }	
	     if(r==1)
	     {
         	return true;
         }
    }
    
    /*******************************************************************************************
     Function    : chkvalidate()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to validate the textboxes in login page.
     Parameter   :
                    frm - object - instance of the form object
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
    function chkvalidate(tf)
    {
	    if(tf.txtUsername.value==null || tf.txtUsername.value=="")
	    {
		    alert("User Name cannot be blank.");
		    tf.txtUsername.focus();
		    return false;
	    }
	    else if(tf.txtPassword.value==null || tf.txtPassword.value=="")
	    {
		    alert("Password cannot be blank.");
		    tf.txtPassword.focus();
		    return false;
	    }
	    else
	    {
		    return true;
	    }
    }
    
    /*******************************************************************************************
     Function    : log_out()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to terminate user session.    
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
    function log_out()
	{
		location.href="logout.asp";
	}
	
	/*******************************************************************************************
     Function    : addactivity()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to redirect user to activity page.     
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
    function addactivity()
    {		
	    //location.href="portal2.asp";
	    //location.href="postActivity.asp";
	    location.href="addMHPActivity.asp";
    }    
   
	/*******************************************************************************************
     Function    : validate()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to validate the textboxes in activity page.    
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
	function validate()
    {		
		//alert(document.form1.txtdesc.value.replace(/^\s+|\s+$/g,""));
		desc=document.form1.txtdesc.value.replace(/^\s+|\s+$/g,"");    
		        
		var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
		if (obj.test(desc)) 
		{ 
			desc = desc.replace(obj, '$2'); 
		}
		var obj = /  /g;
		while (desc.match(obj)) 
		{ 
			desc = desc.replace(obj, " "); 
		}		
        		
        if(document.form1.txtpcode.value=="")
        {
          alert("Select Project");
          document.form1.txtpcode.focus();
          return false;
        }
        if(document.form1.txtacode.value=="")
        {
          alert("Select Activity");
          document.form1.txtacode.focus();
          return false;
        }
        if(document.form1.txtdesc.value=="")
        {
          alert("Enter Description");
          document.form1.txtdesc.focus();
          return false;
        }
        if(document.form1.txthr.value=="")
        {
          alert("Enter Hours");
          document.form1.txthr.focus();
          return false;
        }        
        if(desc.length<50)
        {
			alert("Description should be atleast 50 characters.");
			document.form1.txtdesc.focus();
			return false;
        }        
    }
    
    
    function checkSpaces(txt)
    {
		var key=window.event.keyCode; 
        var uid=new String(); 
        var str=document.getElementById(txt).value;    
        var uid=document.getElementById(txt).value;      
        uid=str.indexOf("  ");
        if(uid>0)
        {  
            var len=str.length;          
            document.getElementById(txt).value=str.substr(0,(len-1));
        }
    }
    /*******************************************************************************************
     Function    : check_Numbers()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to numeric validation.   
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
   *******************************************************************************************/ 
   function check_Numbers() 
   {
            var key = window.event.keyCode;        
            if (key > 57 || key < 48 )
            {
                if(key!=46)
                {
                    window.event.returnValue = false;
                }
            }            
   } 
    /*******************************************************************************************
     Function    : chkhr()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to validate minutes.    
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
   *******************************************************************************************/ 
   function chkhr() //this function will check whether user has entered minutes greater than 59
	    {
		    tempmin=0;
		    objname=document.form1.txthr.value;
		    upd=document.form1.txtupd.value;
		    updhr=document.form1.hr.value;
		    savehr=document.form1.maxhr.value; //In Minutes
	        if((objname).length!=0 && objname!="")
		    {
	            val=objname;
	            if(val==0)
			    {
				      alert("Zero not allowed");
				      form1.txthr.focus();
				      return false;
			    }    
			    test=val.indexOf(".",0)
			    if(test!="-1")
			    {
				      str=val.split(".");
				       if(str[1]>59)
					    { 
					      alert("Minutes Should not be more than 59");
					      form1.txthr.focus();
					      return false;
					    }
				        if(str[1].length==1)
					    {					   
					        tempmin=parseInt(str[1])*10;
					    }
					    else if(str[1].length==0)
					    {
						    //alert(str[1].length)
					        tempmin="00";
					    }
					    else
					    {
						    tempmin=str[1];
					    }	
					    form1.txthr.value=str[0]+"."+tempmin
			     }
			    //**************This is for Daily Hours
			    totmin=Cal_Totalmin(objname)
			    if(upd==1)
			    {
			          savehr=parseInt(savehr)-Cal_Totalmin(updhr)
			          savehr=parseInt(savehr)+parseInt(totmin)
			    }
			    else
			    {
			      savehr=parseInt(savehr)+parseInt(totmin)
			    }
			    if(savehr > 1440)
			    {
			      alert("You can not Post activity for more than 24 Hours");
			      document.form1.txthr.focus();
			      return false;
			    }
			    //**********End Daily Hour code
			    //*********This is for Bud.Hours
			    postedmin=0;
			    budmin=0;
			    actualentry=0;
			    tothr=0;
			    temp=document.getElementById("temp").value; //Bud Hour and Total posted hr seperated by comma
			    //alert(temp);
			    str=temp.split(",")
			    bhr=str[0] // Total Bud. Hr.
			    postedhr=str[1] // Total posted Hr.
			    if(postedhr!="" & (postedhr.length!=0))
			    {
				    postedmin=Cal_Totalmin(postedhr)
				    //alert(postedmin);
			    }
			    if(bhr!="" & (bhr.length!=0))
			    {
				    budmin=Cal_Totalmin(bhr)
				    //alert(budmin);
			    }
			    actualentry=Cal_Totalmin(objname)
			    if(upd==1)
			    {
			       postedmin=parseInt(postedmin)-Cal_Totalmin(updhr)
			       postedmin=parseInt(postedmin)+parseInt(actualentry)
			    }
			    else
			    {
			      postedmin=parseInt(postedmin)+parseInt(actualentry)
			    }
			    if(postedmin > budmin )
			    {
			      alert("You Cross the limit for Budgeted Hours");
			      document.form1.txthr.focus();
			      return false;
			    }
			    //**********End bud.hours code
	      } 	
      }
     /*******************************************************************************************
     Function    : Cal_Totalmin()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to convert hours into minutes.
     Parameter   :
                    txt - object - instance of the textbox to be validated.
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
     function Cal_Totalmin(txt)
     {
        stractualentry=txt.indexOf(".")
	    if(stractualentry!="-1")
	    {
	        str=txt.split(".");
	        strpostedmin=str[1];
	        if(str[1].length==1)
            {
                strpostedmin=parseInt(str[1])*10;
            }
	        if(str[1]=="")
		    {
		        strpostedmin="00";
		    }
		    strtxt=str[0]
	        stractualentrymin1=parseInt(strtxt)*60 // Converted in Minutes
	        totmin=parseInt(strpostedmin)+parseInt(stractualentrymin1)
	    }
	    else
	    {
		    totmin=parseInt(txt)*60 // Converted in Minutes
	    }
	    return totmin;
     }
     /*******************************************************************************************
     Function    : Cal_TotalHr()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to convert minutes into hours.
     Parameter   :
                     txt - object - instance of the textbox to be validated.
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
     function Cal_TotalHr(txt)
     {
        totmin="";
        tothr="0";
        totmin=(txt%60).toString();
	    tothr=parseInt(txt/60)
	        if((totmin.length)==1)
            {
              //totmin=parseInt(totmin)*10;
              totmin="0"+totmin;
            }
	        if(totmin=="")
		    {
		        totmin="00";
		    }
	    tothr=tothr+"."+totmin
	    return tothr;
     }
     /*******************************************************************************************
     Function    : show_modal()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to open a new window.
     Parameter   :
                    para1 - page to be opened.
                    txt   - object - instance of the textbox to be validated.
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
     function show_modal(para1,para2)
     {
 	    var rv = new Array(0,0);
 	    rv=window.showModalDialog(para1,'','addressbar:no;dialogHeight:650 px;dialogWidth:500 px;');
 	        if(rv!=null)
            { 
             document.getElementById(para2).value=rv[0];
               if(rv[1]!=null & (rv[1].length!=0))
                {
                 document.getElementById("temp").value=rv[1]; //Budhours,Totalposted hr for particular project
                 str=rv[1].split(",")
			     bhr=str[0] // Total Bud. Hr.
			     postedhr=str[1] // Total Used Hr.            
			     document.getElementById("txtread_bhr").value=bhr;
			        if(postedhr=="" & (postedhr.length==0))
				    {
					    postedhr="0";
			        }
			     document.getElementById("txtread_Usedhr").value=postedhr;
			     balmin=parseFloat(Cal_Totalmin(bhr))-parseFloat(Cal_Totalmin(postedhr));
			     document.getElementById("txtread_balhr").value=Cal_TotalHr(balmin);    
                }
            }
            else
            {
			    document.getElementById(para2).value=document.getElementById(para2).value;
            }
     }
     /*******************************************************************************************
     Function    : chkdata()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to open a new window.
     Parameter   :
                    frm - object - instance of the form object
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
     *******************************************************************************************/ 
     function chkdata()
     {
       pcode=document.form1.txtpcode.value;
       acode=document.form1.txtacode.value;
       upd=document.form1.txtupd.value;
	    if(pcode=="" && (pcode).length==0)
	    {
	       alert("Select Project");
	       form1.B3.focus();
	       return false;
	    }
	    if(acode=="" && (acode).length==0)
	    {
	       alert("Select Activity");
	       form1.B4.focus();
	       return false;
	    }
	    no=document.form1.TotRec.value;
        if(upd!=1)
        {
		    for(i=1;i<=no;i++)
		    {
		      acode1=document.getElementById("actcode"+i).value;
		      pcode1=document.getElementById("projcode"+i).value;
		      if(pcode==pcode1 & acode==acode1)
		      {
		         alert("You already Post this activity");
		         document.form1.B4.focus();
		         return false;
		      }
		    }   
	    }
     }
     /*******************************************************************************************
     Function    : validateCost()
     DateTime    : 15/02/2008.
     Author      : Pankaj Padole.
     Purpose     : This function is used to open a new window.
     Parameter   :
                    txt   - object - instance of the textbox to be validated.
     Change Log  :
    ______________________________________________________________________________________
       No   |      Author       |      Date/Time            |     Issue 
    ______________________________________________________________________________________
            |                   |                           |
            |                   |                           | 
    *******************************************************************************************/ 
     function validateCost(txt)
      {  
         var key=window.event.keyCode;    
         var cost=document.getElementById(txt).value; 
         var str=new String();
         str=cost.split("");    
         var len=str.length;
         if(str[len-1]==",")
         {
             if(key==46)
             {
                 window.event.returnValue=false;  
             }    
         }    
         if(cost=="" && (key==46))
         {
             window.event.returnValue=false;    
         }
         else
         {
             cost=cost.indexOf(".");
             if(cost>0 && (key==46))
             {
                 window.event.returnValue=false;    
             }
             else
             {
                 var len=str.length;
                 if(str[len-3]==".")
                 {                  
                     window.event.returnValue=false;
                 }
                 else if(key > 57 || key < 48)
                 {       
                     if(key!=46)
                     {   
                         if(key!=13)
                         {
                             window.event.returnValue = false;
                         }
                     }         
                 }   
             }
          }
      }
      
     /*******************************************************************************************
         Function    : DisplayLeaveApplication()
         DateTime    : 22/02/2008.
         Author      : Pankaj Padole.
         Purpose     : This function is used to validate the textboxes in login page.
         Parameter   :
                        frm - object - instance of the form object
         Change Log  :
        ______________________________________________________________________________________
           No   |      Author       |      Date/Time            |     Issue 
        ______________________________________________________________________________________
                |                   |                           |
                |                   |                           | 
    *******************************************************************************************/ 
    
    var testwindow;
    function DisplayLeaveApplication()
    {   
        //'window.open("leave.asp","leavewindow","left=20,top=20,height=450,width=500")'; 
        testwindow=window.open("leave.asp","leavewindow","left=20,top=20,height=450,width=500,status=yes");   
    }
    /*******************************************************************************************
         Function    : ApplicationClose()
         DateTime    : 22/02/2008.
         Author      : Pankaj Padole.
         Purpose     : This function is used to validate the textboxes in login page.
         Parameter   :
                        frm - object - instance of the form object
         Change Log  :
        ______________________________________________________________________________________
           No   |      Author       |      Date/Time            |     Issue 
        ______________________________________________________________________________________
                |                   |                           |
                |                   |                           | 
    *******************************************************************************************/ 
     function ApplicationClose()
     {    
       if(testwindow  && !testwindow.closed) 
       {
            testwindow.close();   
       }
     }


	function OpenSite()
	{
		window.open("http://www.automaticinfotech.com","_parent","");
	}
	function ValidateFRM(tf)
	{		
		if(tf.ImportFile.value=="")		
		{
			alert("Please select a file.");	
			return false;
		}
		else
		{
			//tf.temp.value=tf.ImportFile.value;			
			return true;			
		}				
	}
	
	function LockControl1()
	{
	    var key=window.event.keyCode;
	    if(key!=9)
	    {   
	        if(key!=13)
	        {
	            window.event.returnValue = false;           
	        }
	    }
	}
	
	function Default_Bold()
	{
		document.getElementById("First").style.fontWeight="bold";
	} 
    
