﻿// JScript File
function formReset()
{
    var x=document.forms.aspnetForm
    x.reset()
    return false;
}

//=========================Check For No ===
function chknum(s)
	     {
            if (isNaN(s.value)==true)
			    {
				    alert( "Please enter numeric value.");
				    s.value="";
				    s.focus();
				   
			    }    
	     }
	     
//======================================
var whitespace = " \t\n\r";
function isEmpty(s)
			
			{  
				if ((s == null) || (s.length == 0))
					return true;
			}
			
//===========================Check Only for blank============			
function isBlank(s)
		
			{
				if(s=="")
					return false;
		
			}
//============================Check For Requiored Field And White spaces(If Emoty Space)============			
function isWhitespace(s)
			
			{  
				var i;
				if (isEmpty(s))
					return true;
				for (i = 0; i < s.length; i++)
 					{   
 						var c = s.charAt(i);
						if (whitespace.indexOf(c) == -1)
						return false;
					}
				return true;
			}
//===========================Check for Emails==============			
function isEmail(s)
			
			{
				if (isEmpty(s))
				if (isWhitespace(s)) 
				return false;
				var i = 1;
				var sLength = s.length;
				while ((i < sLength) && (s.charAt(i) != "@"))
					{ 
						i++
					}
				if ((i >= sLength) || (s.charAt(i) != "@")) 
					return false;
				else 
					i += 2;
				while ((i < sLength) && (s.charAt(i) != "."))
					{ 
						i++
					}
				if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
					return false;
				else 
					return true;
			}
//===============================Check For Specified Charecters=============			
function isCharsInBag(s, bag)
			
			{  
				var i;
				for (i = 0; i < s.length; i++)
					{   
						var c = s.charAt(i);
 						if (bag.indexOf(c) == -1) 
						return false;
					}
				return true;
			}
			
			
//====================Check If Selected Index Is zero========
function DDIndexChk(s)
{
            if (s.selectedIndex == "0" )
						{
							s.focus();
							return true;
						}
}

//==============Mobile No Validation=========================
function ValidateMobileNo(s)
{
                 if(s == 0)        
                    {
                        //alert("Enter mobile number.");
                        return true;
                    }
                if(s.length != 10)        
                    {
                        //alert("Invalid mobile number.");
                        return true;
                    }
                var digits="0123456789";
                 var temp;
                 for (var i=0;i<s.length;i++)
                 {         temp=s.substring(i,i+1);
                           if (digits.indexOf(temp)== -1)
                           {      
                                //alert("Invalid mobile number.");
                                return true;
                           }
                 } 
}
//================================Check For Zip Code===================================
function ZipCodeValidate(s)
{ 
var checkzipcode=s;
                if(checkzipcode == 0)        
                    {
                        //alert("Enter pin code.");
                        return true;
                    }
                if(checkzipcode.length != 6)        
                    {
                        //alert("Invalid pin code.");
                        return true;
                    }
                var digits="0123456789";
                 var temp;
                 for (var i=0;i<checkzipcode.length;i++)
                 {         temp=checkzipcode.substring(i,i+1);
                           if (digits.indexOf(temp)== -1)
                           {      
                                //alert("Invalid pin code.");
                                return true;
                           }
                 }          
}

//=======================Date Validate======================================

function DateValidate(s)
{
var check1=s;
            
             if(check1.length ==0)
                {
                     alert("Enter date.");
                     return true;
                }
            
            if(check1.length !=10 || check1=="MM/DD/YYYY")
                {
                     alert("Invalid date.");
                     return true;
                }
                        
            var a1=check1.substring(3,5);
            var a2=check1.substring(0,2);
            
            
            if(a1 > 31 || a2 > 12)
                
                {
                    alert("Invalid date.");
                     return true;
                }
                
             if(a1==31 && a2==02) 
                 {
                        alert("Invalid date.");
                        return true;
                 }
              if(a1==31 && a2==04) 
                 {
                        alert("Invalid date.");
                        return true;
                 }
              if(a1==31 && a2==06) 
                 {
                        alert("Invalid date.");
                        return true;
                 }
              if(a1==31 && a2==09) 
                 {
                        alert("Invalid date.");
                        return true;
                 }
              if(a1==31 && a2==11) 
                 {
                        alert("Invalid date.");
                        return true;
                 }
                    
             var a3=check1.substring(6,10);
             var vnumeric=a1+a2+a3;
             var digits="1234567890";
                 var temp;
                 for (var i=0;i<vnumeric.length;i++)
                 {         temp=vnumeric.substring(i,i+1);
                           if (digits.indexOf(temp)== -1)
                           
                           { 
                                                           
                                alert("Invalid date.");                                  
                                return true;
                           }
                 } 
             var leapyear=a3%4;
             
             if( leapyear == 0 && a2 == 2 && a1 > 29)
                
                  {
                         alert("Invalid date.");
                         return true;
                  }
                            
             if( leapyear != 0 && a2 == 2 && a1 > 28)
                
                  {
                         alert("Invalid date.");
                         return true;
                  }  
}


//========================Extension Check=============================
function CheckExtension(s)
{
var checkfileupload=s;
                if(checkfileupload == 0 )
                    {
                        alert("Enter Fileupload.");
                        return false;
                    } 
                    
               else
                    {  	
                       var path1_length1=checkfileupload.length;
                       var path1_length2=checkfileupload.lastIndexOf('.');
                       var path1_extension=checkfileupload.substr(path1_length2+1,path1_length1);		
                       
                       switch(path1_extension)
                           {
                               
                                case "gif":
                                    { return true;}
                                        break;
                                case "jpg":
                                    { return true;}
                                        break;
                                case "jpeg":
                                     { return true;}
                                        break;
                                case "bmp":
                                    { return true;}
                                        break;
                                 default:
                                    { alert("File extension is in wrong format.");
                                      return false; 
                                    }
                                       break;
                            }
                     }
}
function CheckExtensiondoc(s)
{
var checkfileupload=s;
                if(checkfileupload == 0 )
                    {
                        alert("Enter Fileupload.");
                        return false;
                    } 
                    
               else
                    {  	
                       var path1_length1=checkfileupload.length;
                       var path1_length2=checkfileupload.lastIndexOf('.');
                       var path1_extension=checkfileupload.substr(path1_length2+1,path1_length1);		
                       
                       switch(path1_extension)
                           {
                               
                                case "doc":
                                    { return true;}
                              
                                 default:
                                    { alert("File extension is in wrong format.");
                                      return false; 
                                    }
                                       break;
                            }
                     }
}
//========================Range Validator==================
function RangeValidate(s,MinRange,MaxRange)
{
 if(s .length ==0)
                    {                        
                        alert("Field may not be blank");
                        return true;                    
                    } 
            if((parseInt(s)< parseInt(MinRange)) || (parseInt(s)> parseInt(MaxRange)))
                    {                        
                        alert("Range Value Between "+ MinRange + " and " + MaxRange);
                        return true;                 
                    }  
}
//===========================

function chngcol(CheckBoxControl)
			{
			var i=0;
				if(CheckBoxControl.checked == true)
				{
					CheckBoxControl.style.backgroundColor='red';
					
					
				}
				else
				{
				CheckBoxControl.style.backgroundColor='white';
				}
				
			}
		
//===================Select All in Gridview==========================================================			
function checkAll(theForm, cName) 
{
    for (i=0,n=theForm.elements.length;i<n;i++)
    {   
        if (theForm.elements[i].id.indexOf(cName) !=-1)
            if (theForm.elements[i].checked == true) 
            {
                theForm.elements[i].checked = false;
            } 
            else 
            {
                theForm.elements[i].checked = true;
            }  
    }
}


 //===============================Check Confirmation For Deletion Of Records===========================
 function chkdeleteion(GridViewObject)
{
var ctr=0;
var obj = GridViewObject.all.tags("input");   
                    for (i=0;i<obj.length;++i  )
                        {
                            if(obj[i].checked)
                               {
                                    ctr=ctr+1;
                               }                           
                       }
          if(ctr<=0)
          {
          alert("Select atleast one record to delete.")
          return true;
          }
          else
          {
                  if (confirm("Are you sure to delete records?"))
                  {
                  return false;
                  }
                  else
                  {
                   for (i=0;i<obj.length;++i  )
                        {
                            if(obj[i].checked)
                               {
                                    obj[i].checked=false;
                                    ctr=ctr+1;
                               }                           
                       }
                  return true;
                  }
          }
}

function checktime(thetime) {
var a,b,c,f,err=0;
a=thetime.value;
if (a.length != 5) err=1;
b = a.substring(0, 2);
c = a.substring(2, 3); 
f = a.substring(3, 5); 
if (/\D/g.test(b)) err=1; //not a number
if (/\D/g.test(f)) err=1; 
if (b<0 || b>23) err=1;
if (f<0 || f>59) err=1;
if (c != ':') err=1;
if (err==1) {
alert ('That is not a valid time.\nPlease re-enter in format XX:XX ');
return true;
thetime.value = ""; 
thetime.focus();
}
}

//===================================================================

function formReset()
    {
           var frm_elements = aspnetForm.elements; 
            for(i=0; i<frm_elements.length; i++) 
                {
                       if (frm_elements[i].id.substring(0,2) != "Bt" && frm_elements[i].id.substring(0,2) != "bt" && frm_elements[i].id.substring(0,2) !="LB" && frm_elements[i].type.substring(0,2) != "hi" && frm_elements[i].id.substring(0,2) != "dd" && frm_elements[i].type.substring(0,4) != "te")
                       {
                       
                         
                         frm_elements[i].value="";
                       }
                                                                   
                } 

            return false;
    } 
    //====================
    
    //Convert Number to Words            
            
 //=========================Number validate=======================
 function numervalid(evt)
{
var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;



}		        
//PRINT

             
function printPartOfPage(elementId)
        {
         var printContent = document.getElementById(elementId);
         var windowUrl ='Default.aspx';
         var uniqueName = new Date();
         var windowName = 'Print' + uniqueName.getTime();
         var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

         printWindow.document.write(printContent.innerHTML);
         printWindow.document.close();
         printWindow.focus();
         printWindow.print();
         printWindow.close();
        }

function confirmmsg()
     {  				
		if(confirm("Do you want to print data?")==true)      
         
           return printPartOfPage('Print');   
            else
          return false;
                        
    						
	}                   
