﻿String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
function openWindow(url)
{
    //openPopUp('/Proxel.mFirst.eDocs.UI/Secure/ViewDocuments.aspx?CompanyID=' + querystring,'AlertWindow');
    openPopUpDocumentView(url);
}
function openCompareDocs(URL)
{
    window.open(URL,'CompareDocuments','scrollbars=yes,menubar=no,resizable=yes,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}
function openAlertWindow(url)
{
    var popUp = window.open(url,'','left=20,top=20,width=1200,height=800,toolbar=1,menubar=1,location=0,resizable=1');
    //popUp.focus();
}
function openPopUp(URL,WindowName,WinProp)
{
    window.open(URL,WindowName,WinProp);
    return false;
} 
function openCompanyChartPopUp(URL)
{
   var options;
   if(navigator.appName=='Microsoft Internet Explorer')
    {
        var width = screen.width - 10;
        var height = screen.height - 95;
        options = 'scrollbars=yes,resizable=no,menubar=no,width=' + width + ',height=' + height+ ',toolbar=no,statusbar=yes,addressbar=no';
    }
    else
        options = 'scrollbars=yes,resizable=no,menubar=no,width=' + screen.width + ',height=' + screen.height + ',toolbar=no,statusbar=yes,addressbar=no';
        
    var win = window.open(URL,'ChartView',options);
    win.moveTo(0,0);
   //window.open(URL,'ChartView','scrollbars=yes,resizable=no,menubar=no,width=850,height=680,toolbar=no,statusbar=yes,addressbar=no');
   return false;
}
function openSensexChartPopUp(URL)
{
   window.open(URL,'ChartView','scrollbars=no,resizable=no,menubar=no,width=650,height=380,toolbar=no,statusbar=yes,addressbar=no');
   return false;
}
function openPopUpDocumentView(URL)
{
    var options;
    if(navigator.appName=='Microsoft Internet Explorer')
    {
        var width = screen.width - 10;
        var height = screen.height - 95;
        options = 'scrollbars=yes,resizable=no,menubar=no,width=' + width + ',height=' + height+ ',toolbar=no,statusbar=yes,addressbar=no';
    }
    else
        options = 'scrollbars=yes,resizable=no,menubar=no,width=' + screen.width + ',height=' + screen.height + ',toolbar=no,statusbar=yes,addressbar=no';
        
    var win = window.open(URL,'DocView',options);
    win.width = screen.width;
    win.height = screen.height-50;
//    alert(screen.width)
//    alert(screen.height)
    win.moveTo(0,0);
    return false;
}
function openPopUp_UploadDocument(URL)
{
    window.open(URL,'UploadDocument','scrollbars=yes,resizable=yes,menubar=no,width=500,height=700,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}

function openPopUp_AddAnnouncement(URL)
{
    window.open(URL,'AdAnnouncement','scrollbars=yes,resizable=yes,menubar=no,width=500,height=700,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}

//To Manage All Favourate Controls
function OpenPopupManageFavourite(URL)
{
    window.open(URL,'ManageFavourites','scrollbars=yes,resizable=no,menubar=no,width=580,height=500,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}

function OpenPopupAddFavourite(URL)
{
    window.open(URL,'ManageFavourites','scrollbars=yes,resizable=no,menubar=no,width=500,height=500,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}
                
function OpenPopupInviteFriends(URL)
{
    window.open(URL,'InviteFriends','scrollbars=yes,resizable=no,menubar=no,width=400,height=300,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}   
function OpenPopupSubmitArticle(URL)
{
    window.open(URL,'InviteFriends','scrollbars=yes,resizable=no,menubar=no,width=450,height=270,toolbar=no,statusbar=yes,addressbar=no');
    return false;
}                          
//View Companies for Events

function SelectCompanyToUnSubscribe( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) 
    {
        alert ('Please select the company to be unsubscribed.'); 
        return false;
    } 
    else {return true;}
}
//View Companies for Events

// Subscribe to events.

function SelectCompanyToSubscribe( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) {alert ('Please select the company to be subscribed for this event.'); return false;} else {return true;}

}


function SelectEventToSubscribe( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) {alert ('Please select events to be subscribed for this company.'); return false;} else {return true;}

}
// Subscribe to events.    
function SelectEventToUnSubscribe( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');

    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) {alert ('Please select events to be unsubscribed for this company.'); return false;} else {return true;}

}

//
//Function to get Query string value
function getQueryStringValue(queryName)
{
    var value="";
    if(queryName=="visitedurl")
    {
        queryName="VisitedURL";
        hu = window.location.search.substring(1);
    }
    else
        hu = window.location.search.toLowerCase().substring(1);
        
    if(window.location.search!="")
    {
        queryStr = hu.split("&");
        for (i=0;i<queryStr.length;i++)
        {
            ft = queryStr[i].split("=");
            if (ft[0] == queryName)
            {
                value=ft[1];
                break;
            }
        }
    }
    return value;
}             
//          
                
//Favourite Document
function toggleCheckBoxes( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) 
    {
        alert ('Please select the document(s) to be deleted from favourite list.'); 
        return false;
    } 
    else 
    {
        return confirm('Are you sure you want to delete the selected document(s) ?');
    }
}

//Favourite Company
function checkCheckBoxes( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) 
    {
        alert ('Please select the company(s) to be deleted from favourite list.'); 
        return false;
    } 
    else 
    {
        return confirm('Are you sure you want to delete the selected company(s)?');
    }
}

//Favourite Company
function checkFavFundsCheckBoxes( )
{
    var isClicked = 0;
    var allElements=document.getElementsByTagName('*');
    for(i = 0; i < allElements.length; i++)
    {
        elm = allElements[i];
        if (elm.type=='checkbox') 
        {
            if(elm.checked){isClicked = 1;}
        }
    }
    if (isClicked == 0) 
    {
        alert ('Please select the fund(s) to be deleted from favourite list.'); 
        return false;
    } 
    else 
    {
        return confirm('Are you sure you want to delete the selected fund(s) ?');
    }
}

//Favourite Add Company
function CheckBoxesforAdd( )
{

var isClicked = 0;
var allElements=document.getElementsByTagName('*');
for(i = 0; i < allElements.length; i++)
   {
   elm = allElements[i];
   if (elm.type=='checkbox') 
      {
         if(elm.checked){isClicked = 1;}
      }
   }
if (isClicked == 0) {alert ('Please select company to add.'); return false;} else {return true;}

}

//Start Event Subscription
function SelectAll(checkedVal)
    {
        for (var i = 1; i < CheckBoxIDs.length; i++)
           document.getElementById(CheckBoxIDs[i]).checked = checkedVal;
    }
   
 function ChangecheckBoxState()
    {      
        if (CheckBoxIDs != null)
        {
            // check to see if all other checkboxes are checked
            for (var i = 1; i < CheckBoxIDs.length; i++)
            {
                var cb = document.getElementById(CheckBoxIDs[i]);
                if (!cb.checked)
                {
                    document.getElementById(CheckBoxIDs[0]).checked= false;
                     return ;
                }
            }
            // ALL GridView checkboxes are checked so Check the header CheckBox
            document.getElementById(CheckBoxIDs[0]).checked= true;
       }
    }
//End Event Subscription


// Start Event details
function showDocument(url)
{
    window.open(url);
}
// End Event Details

// for paging

    function setPageNo(pagenumber,control)
    {
     var hdnPagenumber=document.getElementById(control);
     if (hdnPagenumber != null) 
      {
     hdnPagenumber.value =  pagenumber;
      }
    
    }
    
     function setFirstpage(control)
    {
     var hdnPagenumber=document.getElementById(control);
     hdnPagenumber.value=1;
    }
    
   function setTotalpages(totalpages,control)
   {
    var hdnTotalpages=document.getElementById(control);
    hdnTotalpages.value=totalpages;
   }
    function setCustomPageNo(pagenoctrl,goctrl,totalpagectrl,lblgoctrl)
    {
        var hdnPagenumber=document.getElementById(pagenoctrl);
        var hdntxtGo=document.getElementById(goctrl);
        var hdnTotalpages=document.getElementById(totalpagectrl);
        var hdnlinkGo=document.getElementById(lblgoctrl);

        if(hdntxtGo !=null)
        {
            hdnlinkGo.focus();
        }
        if (hdnPagenumber != null) 
        {
            if(parseInt(hdntxtGo.value) ==0 )
            {
                alert("Page number can't be 0.");
                hdntxtGo.value="";
                return false;
            }
            if(hdntxtGo.value <1 )
            {
                //hdnPagenumber.value = 1;
                alert("Page number can't be blank.");
                return false;
            }
            else if (parseInt(hdntxtGo.value) > hdnTotalpages.value )
            {
                alert("Page number is not valid.");
                hdntxtGo.value="";
                return false;
            }
            else
            {
                hdnPagenumber.value = hdntxtGo.value;
                hdntxtGo.value="";
            }
        }
    }

/// To Check and Uncheck Header and child elements of a repeater
///

function CheckAll(checkBoxName,IsChecked)
{ 
    var i=0;
    
    chkRegExp = new RegExp(checkBoxName);
    
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox')
        {
            if (chkRegExp.test(elm.name))
            {
                elm.checked = IsChecked;                
            }                
        }
        
    }
}

function CheckHeaderCBoxAccordingly(checkBoxName,IsChecked,headerCheckBoxName)
{
   if(IsChecked)
   {
       var i,count=0;
       var flag=true;    
       chkRegExp = new RegExp(checkBoxName);
       
       for(i = 0; i < document.forms[0].elements.length; i++) 
       {
         elm = document.forms[0].elements[i];
         if (elm.type == 'checkbox')
         {
            if (chkRegExp.test(elm.name))
            {
              if(elm.checked!=true)
              {
                 flag=false;
              }
            }
         }
       }
       if(flag)
       {
         CheckHeader(headerCheckBoxName,flag);
       }
   }
   else
   {        
      CheckHeader(headerCheckBoxName,false);
   }
}

function CheckHeader(checkBoxName,value)
{
    var i;

    chkRegExp = new RegExp(checkBoxName);
    
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if(elm.type == 'checkbox')
        {
            if(chkRegExp.test(elm.name))
            {
                elm.checked=value;
            }
        }
    }
}
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

var Fromhit=0;
var Tohit=0;
 function isNumberFromKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         
         if( (event.keyCode == 47 || event.keyCode == 109) || (event.keyCode >= 48 && event.keyCode <= 57)) 
         {
           if(event.keyCode == 47)
           {
             Fromhit=Fromhit+1;
             if(Fromhit>3)
             {
              return false;
             }
           }
         return true; 
         }
         else 
         {
         return false;
         }
         
      }
      function isNumberToKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         
         if( (event.keyCode == 47 || event.keyCode == 109) || (event.keyCode >= 48 && event.keyCode <= 57)) 
         {
           if(event.keyCode == 47)
           {
             Tohit=Tohit+1;
             if(Tohit>3)
             {
              return false;
             }
           }
         return true; 
         }
         else 
         {
         return false;
         }
         
      }
      
        function isInteger(s)
        {
         var i;
            for (i = 0; i < s.length; i++){   
                // Check that current character is number.
                var c = s.charAt(i);
                if (((c < "0") || (c > "9"))) return false;
            }
            // All characters are numbers.
            return true;
        }
 
        function stripCharsInBag(s, bag)
        {
         var i;
            var returnString = "";
            // Search through string's characters one by one.
            // If character is not in bag, append to returnString.
            for (i = 0; i < s.length; i++){   
                var c = s.charAt(i);
                if (bag.indexOf(c) == -1) returnString += c;
            }
            return returnString;
        }
 
        function daysInFebruary (year)
        {
         // February has 29 days in any year evenly divisible by four,
            // EXCEPT for centurial years which are not also divisible by 400.
            return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
        }
        
        function DaysArray(n)
        {
        for (var i = 1; i <= n; i++) 
        {
             this[i] = 31
             if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
             if (i==2) {this[i] = 29}
           } 
           return this
        }

function getWindowHeight() { 
var windowHeight = 0; 
if (typeof(window.innerHeight) == 'number') { 
windowHeight = window.innerHeight; 
} 
else { 
if (document.documentElement && document.documentElement.clientHeight) { 
windowHeight = document.documentElement.clientHeight; 
} 
else { 
if (document.body && document.body.clientHeight) { 
windowHeight = document.body.clientHeight; 
} 
} 
} 
return windowHeight; 
}

