﻿// JScript File
//Date Format Validation

function stripBlanks(fld) 
{
 var result = "";
 var c=0;
 for (i=0; i<fld.length; i++)
  {
   if (fld.charAt(i) != " " || c > 0) 
    {
     result += fld.charAt(i);
     if (fld.charAt(i) != " ") c = result.length;
    }
  }
 return result.substr(0,c);
}

var numb = '0123456789';
function isValid(parm,val)
{
 if (parm=="") return true;
 for (i=0;i<parm.length;i++)
  {
   if (val.indexOf(parm.charAt(i),0) == -1)
      return false;
  }
 return true;
}

function isNum(parm){return isValid(parm,numb);}


var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function validateDate(fld)
{
 var dd, mm, yy;
 var today = new Date;
 var t = new Date;
 fld = stripBlanks(fld);
 if (fld == '') return false;
 if(fld.length < 10) return false;
 var d1 = fld.split('/');
 if (d1.length != 3) d1 = fld.split('-');
 if (d1.length != 3) d1=fld.split('.');
 if (d1.length != 3) return false;
 dd = d1[0]; mm = d1[1]; yy = d1[2];
 if (!isNum(dd)) return false;
 if (!isNum(yy)) return false;
 if (!isNum(mm)) return false;
 if (dd.length>2) return false;
 if (mm.length>2) return false;
 if (yy.length>4) return false;
 dd = parseFloat(dd);
 mm = parseFloat(mm);
 yy = parseFloat(yy);
 if (yy < 100) yy += 2000;
 if (yy < 1582 || yy > 2099) return false;
 if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
 if (mm < 1 || mm > 12) return false;
 if (dd < 1 || dd > day[mm-1]) return false;
 t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
 //if (t > today) return false;
 return true;
}

function Check_For_Enter(e)
    {
     var key;
     if(window.event)
        key=window.event.keyCode;
     else
        key=e.which;   
     if(key==13)
      return false;
     else
      return true; 
    }


//new
function Allow_Numeric(e)
{
    var whichCode = (window.Event) ? e.which : e.keyCode;
   //alert(Code);
    if((whichCode>=48 && whichCode<=57) || whichCode==46 || whichCode==8 )
        return true;
    else
        return false;
}


function Allow_MonthNumeric(e)
{
    var whichCode = (window.Event) ? e.which : e.keyCode;
   //alert(Code);
    if((whichCode>=48 && whichCode<=57) || whichCode==127 || whichCode==8)
        return true;
    else
        return false;
}



function Allow_Character(e)
{
   var whichCode = (window.Event) ? e.which : e.keyCode;
    //alert(whichCode);
    if((whichCode >=97 && whichCode<=122) || (whichCode>=65 && whichCode<=90) || whichCode==32 || whichCode==46|| whichCode==8 || whichCode==127)
        return true;
    else
        return false;    
}

function Allow_Date(e)
    {
       var whichCode = (window.Event) ? e.which : e.keyCode;
        //alert(Code);
        if((whichCode>=45 && whichCode<=57) || whichCode==127 || whichCode==8)
            return true;
        else
            return false;
    }
    
function Allow_PhoneNo(e)
    {
       var whichCode = (window.Event) ? e.which : e.keyCode;
        if(whichCode==32 || (whichCode>=43 && whichCode<=57) || whichCode==127 || whichCode==8)
            return true;
        else
            return false;            
    }    
    

function validateMoney(Amount)
{
 var varDecimalCount=0;
 for (i=0; i<Amount.length; i++)
   if (Amount.charAt(i) == '.')
     varDecimalCount=varDecimalCount+1;
 if(varDecimalCount>1) return false;
 else if(varDecimalCount==1)
 {
  var strArray=Amount.split('.');
  if(strArray[1]=='')
   return false;
 }
 return true;
}

function validateEmail(Email)
{
var varAtArray=Email.split('@');
if(varAtArray.length!=2) return false;
else
 {
  var varDotArray=varAtArray[1].split('.');
  if(varDotArray.length==0) return false;
  else return true;
 }
}

function Restrict_FeeNo(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==95 || varKey==46 || varKey>=38 && varKey<=43 || varKey>=45 && varKey<=57 || varKey==8 || varKey==127 || varKey==32 || varKey==9)
      return true;
     else
      return false; 
}

function Restrict_Name(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==95 || varKey==46 || varKey>=38 && varKey<=43 || varKey>=45 && varKey<=57 || varKey==127 || varKey==8 || varKey==32 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Date(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=45 && varKey<=57 || varKey==127 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Priority(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=48 && varKey<=57 || varKey==8 || varKey==127 || varKey==9)
      return true;
     else
      return false; 
}

function Restrict_Phone(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=44 && varKey<=57 || varKey==32 || varKey==127 || varKey>=40 && varKey<=41 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Address(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=32 && varKey<=93 || varKey>=97 && varKey<=122 || varKey==127 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Pincode(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=48 && varKey<=57 || varKey==127 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Money(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=48 && varKey<=57 || varKey==127 || varKey==46 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Restrict_Email(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=48 && varKey<=57 || varKey==46 || varKey>=64 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==127 || varKey==95 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}
function Allow_AlphaNumeric(e)
{
    var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=48 && varKey<=57 || varKey==46 || varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==127 || varKey==32 || varKey==38 || varKey==45 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}

function Restrict_SkillName(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey == 43 || varKey == 35 ||varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==32 || varKey==46 || varKey>=38 && varKey<=41 ||varKey>=48 && varKey<=57 || varKey==127 || varKey==8 || varKey==9)
      return true;
     else
      return false; 
}

function Restrict_NameNo(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==95 || varKey==46 || varKey>=38 && varKey<=43 || varKey>=45 && varKey<=57 || varKey==127 || varKey==8 || varKey==32 || varKey==9)
      return true;
     else
      return false; 
}

function AllowTime(e) // Santhosh
{

var whichCode = (window.Event) ? e.which : e.keyCode;
   
 if((whichCode>=48 && whichCode<=57) || whichCode == 58 || whichCode == 65 || whichCode == 77 || whichCode == 80 || whichCode == 32 || whichCode ==127 || whichCode==8)
        return true;
    else
        return false;


}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function GetBrowser()
{
    var browserName = ""; 

    var ua = navigator.userAgent.toLowerCase(); 
    if ( ua.indexOf( "opera" ) != -1 ) 
    { 
        browserName = "opera"; 
    } 
    else if ( ua.indexOf( "msie" ) != -1 ) 
    { 
        browserName = "msie"; 
    } 
    else if ( ua.indexOf( "safari" ) != -1 ) 
    { 
        browserName = "safari"; 
    }
    else if ( ua.indexOf( "mozilla" ) != -1 ) 
    { 
        if ( ua.indexOf( "firefox" ) != -1 ) 
        { 
            browserName = "firefox"; 
        } 
        else 
        { 
            browserName = "mozilla"; 
        } 
    } 

    return browserName; 
} 

function Restrict_ReceiptNo(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==32 || varKey==46 || varKey>=38 && varKey<=41 || varKey>=48 && varKey<=57 || varKey==8 || varKey== 45 || varKey==47)
      return true;
     else
      return false; 
}



function Restrict_Mark(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;
     var event=e || window.event;
     var target=event.target || event.srcElement;
     var strMark=new Array();      
     if(varKey>=48 && varKey<=57 || varKey==46 || varKey==8)
     {
      if(varKey==46)
      {
        strMark=document.getElementById(target.id).value.split('.');
        if(strMark[1]!=null)
            return false;
      }
      else if(varKey>=48 && varKey<=57)
      {
        strMark=document.getElementById(target.id).value.split('.');
        if(strMark[1]!=null)
        if(strMark[1].length>1)
            return false;
      }
      return true;
     } 
     else
      return false; 
}


function Restrict_EnrollmentNo(e)
{
 var varKey;
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
     if(varKey>=65 && varKey<=90 || varKey>=97 && varKey<=122 || varKey==95 || varKey==46 || varKey>=38 && varKey<=43 || varKey>=45 && varKey<=57 || varKey==127 || varKey==8)
      return true;
     else if(varKey==13)
     {
     
     return true;
     
     
     }
     else
      return false; 
}

function Restrict_Multiline(e,intMax)
{
    
     var varKey;
     var event=e || window.event;
     var target=event.target || event.srcElement     
     if(window.event)
        varKey=window.event.keyCode;
     else
        varKey=e.which;   
      if(varKey>=32 && varKey<=93 || varKey>=97 && varKey<=122 || varKey==127 || varKey==8)
     {       
        if(target.value.length<intMax)
             return true;
        else
            return false;
     }
     else
      return false;         
}

function FreezeGridViewHeader(gridID,Panel) 
    {
        /// <summary>
        ///   Used to create a fixed GridView header and allow scrolling
        
        fColumnResize(gridID);
        
        if(!(document.getElementById(Panel).style.height==null || document.getElementById(Panel).style.height==''))
        {
            //alert(Panel+' in');
            var wrapperDivCssClass="WrapperDiv";
            var grid = document.getElementById(gridID);
            if (grid != null && grid != 'undefined')
            {
                grid.style.visibility = 'hidden';
                var div = null;
                var div1=null;
                if (grid.parentNode != 'undefined' && grid.parentNode !=null) 
                {
    //                //Find wrapper div output by GridView
                    div1 = grid.parentNode;
                    div=document.getElementById(Panel);
                    if (div.tagName == "DIV")
                    {
                        div.className = wrapperDivCssClass;  
                        div.style.overflow = "auto";
                        //div.style.zIndex=-1;                   
                    }
                }                
                
                var tags = grid.getElementsByTagName('TBODY');
                if (tags != 'undefined' && tags !=null)
                {
                    var tbody = tags[0];
                    var trs = tbody.getElementsByTagName('TR');
                    var headerHeight = 8;
                    if (trs != 'undefined' && trs!=null) 
                    {
                        headerHeight += trs[0].offsetHeight;
                        var headTR = tbody.removeChild(trs[0]);
                        var head = document.createElement('THEAD');
                        head.appendChild(headTR);
                        
                        grid.insertBefore(head, grid.firstChild);
                    }
                    //Needed for Firefox
                   
                    tbody.style.height = (div.offsetHeight -  headerHeight) + 'px';
                    
                    tbody.style.overflowX = "hidden";
                    tbody.overflow = 'auto';
                    tbody.overflowX = 'hidden';
                    //tbody.class='MyGridViewRow';
                }
                grid.style.visibility = 'visible';
                
            }
        }
       
}
            
function CompareDate(Date1,Date2)
{
//returns 1 when Date1 is lesser
//returns 2 when Date2 is lesser
//returns 0 when Both dates are equal
 var dd1, mm1, yy1, dd2, mm2, yy2;
 Date1 = stripBlanks(Date1);
 Date2 = stripBlanks(Date2);
 
 var d1 = Date1.split('/');
 if (d1.length != 3) d1 = Date1.split('-');
 if (d1.length != 3) d1=Date1.split('.');
 var d2 = Date2.split('/');
 if (d2.length != 3) d2 = Date2.split('-');
 if (d2.length != 3) d2=Date2.split('.');

 dd1 = parseFloat(d1[0]);
 mm1 = parseFloat(d1[1]);
 yy1 = parseFloat(d1[2]);
 dd2 = parseFloat(d2[0]);
 mm2 = parseFloat(d2[1]);
 yy2 = parseFloat(d2[2]);
 
 if(yy1<yy2) return 1;
 if(yy1>yy2) return 2;
 if(mm1<mm2) return 1;
 if(mm1>mm2) return 2;
 if(dd1<dd2) return 1;
 if(dd1>dd2) return 2;
 return 0;
}

function checkEvent(e) 
   {
   //var targ;
   var event=e || window.event;
    var targ=event.target || event.srcElement
//        if (!e)
//             e = window.event;
//        if (e.target)
//            targ = e.target;
//        else if(e.srcElement)
//             targ = e.srcElement;
        if(targ.options.selectedIndex!=-1)
            showHideToolTip(targ, event, event.type)
   }
   
function showHideToolTip (theDropDown, e, eType)
    {
        var toolTipObj = new Object();
        var iframeObj = new Object();
        
        //var event=e || window.event;
        toolTipObj = document.getElementById("tooltip");
        iframeObj=document.getElementById("iframeTop");
        //toolTipObj.style.zIndex=99999;
        toolTipObj.innerHTML = theDropDown.options[theDropDown.selectedIndex].text;
        if(eType == "mouseout")
        {
            toolTipObj.style.display = "none";
            iframeObj.style.display = "none";
        }
        else
        {
            if(stripBlanks(theDropDown.options[theDropDown.selectedIndex].text)!="")
            {
                var xPosition=getPosition(e).x+15;
                var yPosition=getPosition(e).y+10;
                toolTipObj.style.display = "inline";
                
                toolTipObj.style.top = yPosition;
                toolTipObj.style.left = xPosition;
                iframeObj.style.display = "inline";
                
                iframeObj.style.top = yPosition;
                iframeObj.style.left = xPosition;
                
                iframeObj.style.width=toolTipObj.offsetWidth;
                iframeObj.style.height=toolTipObj.offsetHeight;
                
            }
        }
     }
     
function DisableLoadMsg()
{
    try{   
        var divLoadingMessage =  document.getElementById("divLoadingMsg")   
        if (divLoadingMessage != null && typeof(divLoadingMessage) != 'undefined')   
        {   
        divLoadingMessage.style.display="none";   
        divLoadingMessage.parentNode.removeChild(divLoadingMessage);   
        }   
       }
    catch(e){}
}

function getPosition(e) 
{
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) 
    {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else 
    {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}


//  true when a header is currently being resized
var _isResizing;
//  a reference to the header column that is being resized
var _element;
//  an array of all of the tables header cells
var _ths;

function fColumnResize(args)
{
    //  get all of the th elements from the gridview
    if($get(args)!=null)
    {
    _ths =$get(args).getElementsByTagName('TH');
    
    //  if the grid has at least one th element
        if(_ths.length > 1)
        {
        
            for(i = 0; i < _ths.length; i++)
            {
                //  determine the widths
                _ths[i].style.width = Sys.UI.DomElement.getBounds(_ths[i]).width + 'px';
            
                //  attach the mousemove and mousedown events
                if(i < _ths.length - 1)
                {
                    $addHandler(_ths[i], 'mousemove', _onMouseMove);
                    $addHandler(_ths[i], 'mousedown', _onMouseDown);
                }
            }

            //  add a global mouseup handler            
            $addHandler(document, 'mouseup', _onMouseUp);
            //  add a global selectstart handler
            $addHandler(document, 'selectstart', _onSelectStart);
        } 
     }     
}

function _onMouseMove(args)
{    
    if(_isResizing)
    {
        
        //  determine the new width of the header
        var bounds = Sys.UI.DomElement.getBounds(_element); 
        var width = args.clientX - bounds.x;
        
        //  we set the minimum width to 1 px, so make
        //  sure it is at least this before bothering to
        //  calculate the new width
        if(width > 1)
            {
        
            //  get the next th element so we can adjust its size as well
            var nextColumn = _element.nextSibling;
            var nextColumnWidth;
            
            if(width < ConvertToNum(_element.style.width))
            {
                //  make the next column bigger
                nextColumnWidth = ConvertToNum(nextColumn.style.width) + ConvertToNum(_element.style.width) - width;
            }
            else if(width > ConvertToNum(_element.style.width))
            {
                //  make the next column smaller
                nextColumnWidth = ConvertToNum(nextColumn.style.width) - (width - ConvertToNum(_element.style.width));
            }   
            
            //  we also don't want to shrink this width to less than one pixel,
            //  so make sure of this before resizing ...
            if(nextColumnWidth > 1)
            {
                _element.style.width = width + 'px';
                nextColumn.style.width = nextColumnWidth + 'px';
            }
        }
    }   
    else
        {
        //  get the bounds of the element.  If the mouse cursor is within
        //  2px of the border, display the e-cursor -> cursor:e-resize
        var bounds = Sys.UI.DomElement.getBounds(args.target);
        if(Math.abs((bounds.x + bounds.width) - (args.clientX)) <= 2) {
            args.target.style.cursor = 'e-resize';
        }  
        else
        {
            args.target.style.cursor = '';
        }          
    }         
}

function _onMouseDown(args)
{
    //  if the user clicks the mouse button while
    //  the cursor is in the resize position, it means
    //  they want to start resizing.  Set _isResizing to true
    //  and grab the th element that is being resized
    if(args.target.style.cursor == 'e-resize') 
    {
        _isResizing = true;
        _element = args.target;               
    }                    
} 

function _onMouseUp(args)
{
    //  the user let go of the mouse - so
    //  they are done resizing the header.  Reset
    //  everything back
    if(_isResizing)
    {
        
        //  set back to default values
        _isResizing = false;
        _element = null;
        
        //  make sure the cursor is set back to default
        for(i = 0; i < _ths.length; i++)
        {   
            _ths[i].style.cursor = '';
        }
    }
}

function _onSelectStart(args)
{
    // Don't allow selection during drag
    if(_isResizing)
    {
        args.preventDefault();
        return false;
    }
}
    
function ConvertToNum(parm)
{
 var retParm="";
 for (i=0;i<parm.length;i++)
  {
   if (numb.indexOf(parm.charAt(i),0) != -1)
      retParm=retParm+parm.charAt(i);
  }
 if (retParm=="") return 0; 
 return Number(retParm);
}

function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() 
        {
            if (oldonload) 
            {
                oldonload();
            }
            func();
        }
    }
 }  

//**************************Httprequest Start
        
var XmlHttp;
//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
    //Creating object of XMLHTTP in IE
    try
    {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
	        XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch(oc)
        {
	        XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
    {
        XmlHttp = new XMLHttpRequest();
    }
}  
