﻿// JScript File
 
    function buildCal(m, y, cM, cD,cE, brdr)
    {
        var dat_val;
        var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
        var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

        var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

        var todaydate=new Date() //DD added
        var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
        var spac="&nbsp;";
        dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
        var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0" ><tr align="center">';
        //t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr bordercolor="#FF6600">';
        //for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SUNMONTUEWEDTHUFRISAT".substr(s,3)+'</td>';
        t+='</tr><tr align="center" bordercolor="#FF6600">';
        for(i=1;i<=42;i++)
        {
            var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
            dat_val=x;
            
            if (x==scanfortoday) //DD added
                x='<span id="today">'+x+'</span>' //DD added
            if(x==spac)
            {
                x='<span id="empty">'+ x +'</span>'
                t+='<td class="'+ cE +'">'+x+'</td>';
             
            }
            else
            {
                t+='<td class="'+cD+'" align="right" valign="top"><a href=# class="'+ cD +'" id="date_no" style="text-decoration:none;" onclick="makeRequest('+ dat_val +')">'+x+'</a></td>';
            }
            if(((i)%7==0)&&(i<32))
            {
            t+='</tr><tr bordercolor="#FF6600">';
            }
            else if(((i)%7==0)&&(i<42))
            {
             t+='</tr><tr bordercolor="#FF6600">';
             }
        }
        return t+='</tr></table></div>';
    }   
    function sub1()
    {
       // alert("IT");
        var today=new Date();
        var curr_mth=today.getMonth() 
           
        document.getElementById("month").selectedIndex=curr_mth;   
        var curr_yr=today.getFullYear();
        document.getElementById("years").value=curr_yr;
        var mth_names=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
        var mth_val=document.getElementById("month").selectedIndex;
        var bfr_name=mth_names[mth_val-1];
        var aft_name=mth_names[mth_val+2];
        var MyCalen=buildCal(4,2007,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML=MyCalen;   
    }
    
    function get_mthname()
    {
        var mth_names=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
        var mth_val=document.getElementById("month").selectedIndex;
        //alert(mth_val);
        var yr_val=document.getElementById("years").value;
        var bfr_name=mth_names[mth_val-1];
        var aft_name=mth_names[mth_val+1];
        var mth_name=mth_names[mth_val];
        
        
         var bfr_val=bfr_name;
        if(document.getElementById("month").selectedIndex == 0)
        {
        //alert(document.getElementById("month").selectedIndex);
        document.getElementById("before_mth").innerHTML="DEC"+"<<";
        document.getElementById("after_mth").innerHTML="FEB"+">>";
        document.getElementById("month").selectedIndex=0;
        document.getElementById("years").value=yr_val;
        var tot_mth=mth_val+1;
        //alert(yr_val);
        var MyCalen=buildCal(tot_mth,yr_val,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML= MyCalen ;
        }
        else if(document.getElementById("month").selectedIndex == 11)
        {
        document.getElementById("before_mth").innerHTML="NOV"+"<<";
        document.getElementById("after_mth").innerHTML="JAN"+">>";
        document.getElementById("month").selectedIndex=11;
        document.getElementById("years").value=yr_val;
        var tot_mth=mth_val+1;
       
        var MyCalen=buildCal(tot_mth,yr_val,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML= MyCalen ;
        }
        else
        { 
        document.getElementById("before_mth").innerHTML=bfr_val+"<<";
        document.getElementById("after_mth").innerHTML=aft_name+">>";
        document.getElementById("month").selectedIndex=mth_val;
        document.getElementById("years").value=yr_val;
        var tot_mth=mth_val+1;
       
        var MyCalen=buildCal(tot_mth,yr_val,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML= MyCalen ;
        //alert(tot_mth);
        //alert(yr_val);
        }
          //buildCal(5,2007,"main","days",1);
        //document.form1.action="team.team_schedule.html?mth_name="+ tot_mth +"&yr_no="+ yr_val +"&Qry_bfr="+ bfr_name +"&Qry_aft="+ aft_name +"";
        //document.form1.submit();
    }
    
    function disp_befcal()
    {
        var mth_val;
        
        var sel_val=document.getElementById("before_mth").innerHTML;
        var substr_val=sel_val.substring(0,3);
        //alert(substr_val)
        var mth_names=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
        for(i=0;i<mth_names.length;i++)
        {
            if(mth_names[i]==substr_val)
            {
                mth_val=i+1;
            }
        } 
        if(substr_val=="DEC")
        {
        for(i=0;i<mth_names.length;i++)
        {
            if(mth_names[i]==substr_val)
            {
                mth_val=i+1;
            }
        } 
      
        
            var yr_val=document.getElementById("years").value;   
            var tot_yr= yr_val-1     
        var MyCalen=buildCal(mth_val,tot_yr,"main","days","emptycel",1); 
        
        document.getElementById("dates").innerHTML= MyCalen ; 
        document.getElementById("month").selectedIndex=mth_val-1; 
        document.getElementById("years").value=yr_val-1;
        document.getElementById("before_mth").innerHTML=mth_names[mth_val-2]+"<<";
        document.getElementById("after_mth").innerHTML=mth_names[mth_val-12]+">>";
        } 
        else
        {  
        var yr_val=document.getElementById("years").value;      
        var MyCalen=buildCal(mth_val,yr_val,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML= MyCalen ;
        document.getElementById("month").selectedIndex=mth_val-1; 
        document.getElementById("before_mth").innerHTML=mth_names[mth_val-2]+"<<";
        document.getElementById("after_mth").innerHTML=mth_names[mth_val]+">>";
        }
         //anchorRequest(mth_names[mth_val-2]);     
    }
    function disp_aftcal()
    {
        var sel_val=document.getElementById("after_mth").innerHTML;
        var substr_val=sel_val.substring(0,3);
        
        var mth_names=new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
        for(i=0;i<mth_names.length;i++)
        {
            if(mth_names[i]==substr_val)
            {
                var mth_val=i+1;
            }
        } 
        if(substr_val=="JAN")
        {
        for(i=0;i<mth_names.length;i++)
        {
            if(mth_names[i]==substr_val)
            {
                mth_val=i+1;
            }
        } 
        alert(mth_val);
        
            var yr_val=document.getElementById("years").value; 
              
            var tot_yr= parseInt(yr_val)+1; 
            alert(tot_yr);    
        var MyCalen=buildCal(mth_val,tot_yr,"main","days","emptycel",1); 
        
        document.getElementById("dates").innerHTML= MyCalen ; 
        document.getElementById("month").selectedIndex=mth_val-1; 
        document.getElementById("years").value=tot_yr;
        document.getElementById("before_mth").innerHTML=mth_names[mth_val+10]+"<<";
        document.getElementById("after_mth").innerHTML=mth_names[mth_val]+">>";
        } 
        else
        {
               
        var yr_val=document.getElementById("years").value;         
        var MyCalen=buildCal(mth_val,yr_val,"main","days","emptycel",1);
        document.getElementById("dates").innerHTML= MyCalen ; 
        document.getElementById("month").selectedIndex=mth_val-1; 
        document.getElementById("before_mth").innerHTML=mth_names[mth_val-2]+"<<";
        document.getElementById("after_mth").innerHTML=mth_names[mth_val]+">>";
        }
    }
    
    function makeRequest(dat_val)
    {
    var http_request=false;
        try
        {
            http_request=new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                http_request=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    http_request=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e)
                {
                     alert("ur browser broken");
                    return false;
                }
            }
        }
        http_request.onreadystatechange=function()
        {
            if(http_request.readyState==4)
            {
                if(http_request.status==200)
                {
                    var EvtArr=http_request.responseText;
                    var SplitArr=EvtArr.split("&");
                    document.getElementById("evt_det").innerHTML=SplitArr[0];
                    document.getElementById("evt_schd").innerHTML=SplitArr[1];
                    
                }
            }
        }
        
        var mth_val=(document.getElementById("month").selectedIndex)+1;
        
        var yr_val=document.getElementById("years").value;
        
        http_request.open("GET","Viewrating.aspx?qryDate="+ dat_val +"&qryMth="+ mth_val +"&qryYr="+ yr_val,true);
        http_request.send(null);
    }
    function cal_ajaxbeffunc()
    {
        var http_request=false;
  
        try
        {
            http_request=new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                http_request=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    http_request=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e)
                {
                     alert("ur browser broken");
                    return false;
                }
            }
        }
        http_request.onreadystatechange=function()
        {
            if(http_request.readyState==4)
            {
                if(http_request.status==200)
                {
                    var EvtArr=http_request.responseText;
                    var SplitArr=EvtArr.split("&");
                    document.getElementById("evt_det").innerHTML=SplitArr[0];
                    document.getElementById("evt_schd").innerHTML=SplitArr[1];
                    
                }
            }
        }
        
            var mth_val=(document.getElementById("month").selectedIndex)+1;
        
            var yr_val=document.getElementById("years").value;
        
            http_request.open("GET","Viewrating.aspx?qryMth="+ mth_val +"&qryYr="+ yr_val,true);
            http_request.send(null);
        
        
       
    }
    function cal_ajaxaftfunc()
    {
        var http_request=false;
  
        try
        {
            http_request=new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                http_request=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    http_request=new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e)
                {
                     alert("ur browser broken");
                    return false;
                }
            }
        }
        http_request.onreadystatechange=function()
        {
            if(http_request.readyState==4)
            {
                if(http_request.status==200)
                {
                    var EvtArr=http_request.responseText;
                    var SplitArr=EvtArr.split("&");
                    document.getElementById("evt_det").innerHTML=SplitArr[0];
                    document.getElementById("evt_schd").innerHTML=SplitArr[1];
                    
                }
            }
        }
        
            //var mth_val=(document.getElementById("month").selectedIndex)+1;
        
            var yr_val=document.getElementById("years").value;
        
            http_request.open("GET","Viewrating.aspx?qryYr="+ yr_val,true);
            http_request.send(null);       
       
    }
    

