﻿
// JScript File

var imageGallery2 = new Array();
var selMonth="";
var selYear="";
var selDate="";

 
function getEventsQuickSearch(selID)
{  
    	
    if(imageGallery.length>0)
    {
        var pageID=selID;
        var temp = (pageID*pageLength)+pageLength;  
        if(temp>imageGallery.length)
        {
           temp=imageGallery.length;
        }
        document.getElementById("newsContainer").innerHTML="";
        	
	    count=0;
	    count=Math.ceil(imageGallery.length/pageLength);
    	
	    stroutput='';
	    strPreNext='';
        stroutput +="<div class='t2EventListHead1'>";
        stroutput +="<h3>&nbsp;</h3>";
        stroutput +="</div>";
        stroutput +="<div class='t2EventListHead2'>";
        stroutput +="<h3>";
        stroutput +="Date</h3>";
        stroutput +="</div>";
        stroutput +="<div class='t2EventListHead3'>"
        stroutput +="<h3>Event</h3></div>"
        stroutput +="<div class='t2EventListHead4'>"
        stroutput +="<h3>Location</h3></div>"
        stroutput +="<div class='clear'></div>"

        for(i=(pageID*pageLength);i<temp;i++)
        {
	        var typecheck= imageGallery[i][11];
            typecheck = fRemoveSquarebrace(typecheck); 
            
            stroutput +="<div class='t2EventListBody'>";
            if(imageGallery[i][8]!="")
            {
                stroutput +="<img height='68' alt='' src='"+imageGallery[i][8]+"' width='68'>";
            }
            else
            {
                stroutput +="<img height='68' alt='' src='/files/img_blankImage.gif' width='68'>";
            }
            stroutput +="<div>";
            stroutput +="<p class='t2EventListBodyP1'>";
            stroutput +=""+imageGallery[i][5]+"/"+imageGallery[i][4]+"/"+imageGallery[i][6]+"";
            stroutput +="</p>";
            
            stroutput +="<p class='t2EventListBodyP2'>";
            stroutput +=""+imageGallery[i][1]+"";
            stroutput +="</p>";
            stroutput +="<p class='t2EventListBodyP3'>";
            stroutput +=""+imageGallery[i][2]+"";
            
            stroutput +="</p>";
            stroutput +="</div>";
            stroutput +="<p class='t2EventListBodyP4'>";
            stroutput +=""+imageGallery[i][7]+"";
                
            stroutput +="&nbsp;";      
            if(imageGallery[i][10]!="")
            {      
                    
              stroutput +="<a target='_blank' href='"+imageGallery[i][10]+"'>Find out more</a>";
            }     
            else
            {
                if(imageGallery[i][0]!="")
                { 
                    stroutput +="<a href='/output/page"+imageGallery[i][0]+".asp'>Find out more</a>";
                }
            }
            
            stroutput +="</p>";
            
            
            stroutput +="<div class='clear'>"
            stroutput +="</div>";
            stroutput +="</div>";
            
        }
        document.getElementById("newsContainer").innerHTML=stroutput 
        document.getElementById("prevNext").innerHTML="";  
        strPreNext="";

        if(pageID == 0)
        { 
            strPreNext +='<img alt="First" src="/files/images/btn-prev.gif" />';
        }
        else 
        {
            prevpageid=pageID-1;
            strPreNext +='<input type="image" onclick="getEventsQuickSearch('+0+')" alt="First" src="/files/images/btn-prev.gif" />';	 
        }  

        startlimit=0
        endlimit=count
        if(count <= 5)
        {
            startlimit=0;
            endlimit=count;
        }
        else if(pageID < (count-2))
        {	        
            if(pageID >= 2)
            {
                startlimit=pageID-2;
                endlimit=pageID+3;
            }
            else
            {
                startlimit=0;
                endlimit=5; 
            }
        }
        else
        {
            startlimit=count-5;
            endlimit=count;
        } 
                       
        for(i=startlimit;i<endlimit;i++)
        {    	 
            if(i == pageID )
            {
                strPreNext +="<a style='text-decoration: none;' class='Pagination_a'  >"+ ( i + 1 )  +"</a>";	     
            }
            else
            {
                strPreNext +="<a style='text-decoration: underline;'  href='#' onclick='getEventsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
            }
            if(i < endlimit -1 )
            {
                strPreNext +='<span>|</span>';
            }          
        }	

        if(pageID == count -1 )
        {
            strPreNext +=' <img src="/files/images/btn-next.gif" alt="Last" />';
        }
        else
        {  
            nextpageid=count -1;
            strPreNext +='<input type="image" onclick="getEventsQuickSearch('+nextpageid+')" alt="Last" src="/files/images/btn-next.gif" />';      
        }
        strPreNext +='<div class="clear"/>';
        document.getElementById("prevNext").innerHTML =strPreNext;
    }
    else
    {
        document.getElementById("prevNext").innerHTML='' 
        stroutput = '<p>No Events Available</p>';
        document.getElementById("newsContainer").innerHTML=stroutput;
    } 

}

function SearchByMonthYear(monthtext,yeartext)
{
    
    if(monthtext!="" && yeartext!="")
    {
        selMonth=monthtext;
        selYear=yeartext;
        imageGallery2=[];
        if(imageGallery.length >0)
        {
            for(i=0;i<imageGallery.length;i++)
            {
                if( monthtext == imageGallery[i][4] && yeartext== imageGallery[i][12] )
                {
                    imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                } 
            }

            if(imageGallery2.length >0)
            {
                getSearchResults(0);
            }
            else
            {
                document.getElementById("prevNext").innerHTML='' 
                stroutput = '<p>No Events Available</p>';
                document.getElementById("newsContainer").innerHTML=stroutput;    
            }
        }
        else
        {
            document.getElementById("prevNext").innerHTML='' 
            stroutput = '<p>No Events Available</p>';
            document.getElementById("newsContainer").innerHTML=stroutput;
        }
    }
    
}

function SearchByDate(datetext,monthtext,yeartext)
{
    if(monthtext!="" && yeartext!="" && datetext!="")
    {
        selMonth=monthtext;
        selYear=yeartext;
        selDate=datetext;
        imageGallery2=[];
        if(imageGallery.length >0)
        {
            for(i=0;i<imageGallery.length;i++)
            {
                if( monthtext == imageGallery[i][4] && yeartext==imageGallery[i][12] && datetext== imageGallery[i][5])
                {
                    imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                } 
            }
            if(imageGallery2.length >0)
            {
                getSearchResults(0);
            }
            else
            {
                document.getElementById("prevNext").innerHTML='' 
                stroutput = '<p> No Events Available</p>';
                document.getElementById("newsContainer").innerHTML=stroutput    
            }
        }
        else
        {
            document.getElementById("prevNext").innerHTML='' 
            stroutput = '<p> No Events Available</p>';
            document.getElementById("newsContainer").innerHTML=stroutput
        }
    }
    
}
function SearchByCategory()
{
    Catgeory_count=document.getElementById("HdnCount").value;
    var allflag="false";
    var categoryid=new Array();
    var catid="";
    if(document.getElementById("all").checked==true)
    {
        allflag="true";
    }
    else
    {
        for (i=1,j=0;i<Catgeory_count;i++,j++)
        {
            if(document.getElementById(i).checked==true)
            {
                catid=document.getElementById(i).value;
                catid=RemoveBraces(catid);
                
                categoryid[j]=catid;
            }
        }
    }
    imageGallery2=[];
    if(imageGallery.length >0)
    {
        if(allflag=="true")
        {
            if(selMonth!="" && selYear!="" && selDate!="")
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    if( selMonth == imageGallery[i][4] && selYear== imageGallery[i][12] && selDate== imageGallery[i][5] )
                    {
                        imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                    }
                }
            }
            else if(selMonth!="" && selYear!="")
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    if( selMonth == imageGallery[i][4] && selYear== imageGallery[i][12] )
                    {
                        imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                    }
                }
            }
            else
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                }
            }
        }
        else
        {
            if(selMonth!="" && selYear!="" && selDate!="")
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    if( selMonth == imageGallery[i][4] && selYear== imageGallery[i][12] && selDate== imageGallery[i][5] )
                    {
                        if(categoryid.length>0)
                        {
                            for(k=0;k<categoryid.length;k++)
                            {
                                if(RemoveBraces(imageGallery[i][11])==categoryid[k])
                                {
                                    imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                                }
                            }
                        }
                        else
                        {
                            imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                        }
                    }
                }
            }
            else if(selMonth!="" && selYear!="")
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    if( selMonth == imageGallery[i][4] && selYear== imageGallery[i][12] )
                    {
                        if(categoryid.length>0)
                        {
                            for(k=0;k<categoryid.length;k++)
                            {
                                if(RemoveBraces(imageGallery[i][11])==categoryid[k])
                                {
                                    imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                                }
                            }
                        }
                        else
                        {
                            imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                        }
                    }
                }
            }
            else
            {
                for(i=0;i<imageGallery.length;i++)
                {
                    if(categoryid.length>0)
                    {
                        for(k=0;k<categoryid.length;k++)
                        {
                            if(RemoveBraces(imageGallery[i][11])==categoryid[k])
                            {
                                imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                            }
                        }
                    }
                    else
                    {
                        imageGallery2.push(new Array(imageGallery[i][0],imageGallery[i][1],imageGallery[i][2],imageGallery[i][3],imageGallery[i][4],imageGallery[i][5],imageGallery[i][6],imageGallery[i][7],imageGallery[i][8],imageGallery[i][9],imageGallery[i][10],imageGallery[i][11],imageGallery[i][12],imageGallery[i][13]));                                                          
                    }
                }
            }
        }
        if(imageGallery2.length >0)
        {
            getSearchResults(0);
        }
        else
        {
            document.getElementById("prevNext").innerHTML='' 
            stroutput = '<p>No Events Available</p>';
            document.getElementById("newsContainer").innerHTML=stroutput;    
        }
    }
    else
    {
        document.getElementById("prevNext").innerHTML='' 
        stroutput = '<p>No Events Available</p>';
        document.getElementById("newsContainer").innerHTML=stroutput;
    }
}

function getSearchResults(selID)
{   
    if(imageGallery2.length>0)
    {
        var pageID=selID;
        var temp = (pageID*pageLength)+pageLength;  
        if(temp>imageGallery2.length)
        {
           temp=imageGallery2.length;
        }
        document.getElementById("newsContainer").innerHTML="";
        	
	    count=0;
	    count=Math.ceil(imageGallery2.length/pageLength);
    	
	    stroutput='';
	    strPreNext='';	

        stroutput +="<div class='t2EventListHead1'>";
        stroutput +="<h3>&nbsp;</h3>";
        stroutput +="</div>";
        stroutput +="<div class='t2EventListHead2'>";
        stroutput +="<h3>";
        stroutput +="Date</h3>";
        stroutput +="</div>";
        stroutput +="<div class='t2EventListHead3'>"
        stroutput +="<h3>Event</h3></div>"
        stroutput +="<div class='t2EventListHead4'>"
        stroutput +="<h3>Location</h3></div>"
        stroutput +="<div class='clear'></div>"

        for(i=(pageID*pageLength);i<temp;i++)
        {
	        var typecheck= imageGallery2[i][11];
            typecheck = fRemoveSquarebrace(typecheck); 
            
            stroutput +="<div class='t2EventListBody'>";
            if(imageGallery2[i][8]!="")
            {
                stroutput +="<img height='68' alt='' src='"+imageGallery2[i][8]+"' width='68'>";
            }
            else
            {
                stroutput +="<img height='68' alt='' src='/files/img_blankImage.gif' width='68'>";
            }
            stroutput +="<div>";
            stroutput +="<p class='t2EventListBodyP1'>";
            stroutput +=""+imageGallery2[i][5]+"/"+imageGallery2[i][4]+"/"+imageGallery2[i][6]+"";
            stroutput +="</p>";
            
            stroutput +="<p class='t2EventListBodyP2'>";
            stroutput +=""+imageGallery2[i][1]+"";
            stroutput +="</p>";
            stroutput +="<p class='t2EventListBodyP3'>";
            stroutput +=""+imageGallery2[i][2]+"";
            
            stroutput +="</p>";
            stroutput +="</div>";
            stroutput +="<p class='t2EventListBodyP4'>";
            stroutput +=""+imageGallery2[i][7]+"";
                
            stroutput +="&nbsp;";      
            if(imageGallery2[i][10]!="")
            {      
                    
              stroutput +="<a target='_blank' href='"+imageGallery2[i][10]+"'>Find out more</a>";
            }     
            else
            {
                if(imageGallery2[i][0]!="")
                { 
                    stroutput +="<a href='/output/page"+imageGallery2[i][0]+".asp'>Find out more</a>";
                }
            }
            
            stroutput +="</p>";
            
            
            stroutput +="<div class='clear'>"
            stroutput +="</div>";
            stroutput +="</div>";
            
        }
        document.getElementById("newsContainer").innerHTML=stroutput 
        document.getElementById("prevNext").innerHTML="";  
        strPreNext="";

        if(pageID == 0)
        { 
            strPreNext +='<img alt="First" src="/files/images/btn-prev.gif" />';
        }
        else 
        {
            prevpageid=pageID-1;
            strPreNext +='<input type="image" onclick="getSearchResults('+0+')" alt="First" src="/files/images/btn-prev.gif" />';	 
        }  

        startlimit=0
        endlimit=count
        if(count <= 5)
        {
            startlimit=0;
            endlimit=count;
        }
        else if(pageID < (count-2))
        {	        
            if(pageID >= 2)
            {
                startlimit=pageID-2;
                endlimit=pageID+3;
            }
            else
            {
                startlimit=0;
                endlimit=5; 
            }
        }
        else
        {
            startlimit=count-5;
            endlimit=count;
        } 
                       
        for(i=startlimit;i<endlimit;i++)
        {    	 
            if(i == pageID )
            {
                strPreNext +="<a style='text-decoration: none;' class='Pagination_a'  >"+ ( i + 1 )  +"</a>";	     
            }
            else
            {
                strPreNext +="<a style='text-decoration: underline;'  href='#' onclick='getSearchResults("+i+")' >"+ ( i + 1 )  +"</a>";	     
            }
            if(i < endlimit -1 )
            {
                strPreNext +='<span>|</span>';
            }          
        }	

        if(pageID == count -1 )
        {
            strPreNext +=' <img src="/files/images/btn-next.gif" alt="Last" />';
        }
        else
        {  
            nextpageid=count -1;
            strPreNext +='<input type="image" onclick="getSearchResults('+nextpageid+')" alt="Last" src="/files/images/btn-next.gif" />';      
        }
        strPreNext +='<div class="clear"/>';
        document.getElementById("prevNext").innerHTML =strPreNext; 
    }
    else
    {
        document.getElementById("prevNext").innerHTML='' 
        stroutput = '<p>No Events Available</p>';
        document.getElementById("newsContainer").innerHTML=stroutput;
    }
}

function Right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trim11 (str) 
{
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--)
	 {
		if (/\S/.test(str.charAt(i))) 
		{
			str = str.substring(0, i + 1);
			break;
	    }
	 }
	return str;
}

function fRemoveSquarebrace(src)
{
    var dst = "";
    var c = "";
    var dst1 = "";
    var c1 = "";
    for (var i = 0; i < src.length; i++)
    {
        c = src.charAt(i);
        
        if (c != '{')
        {
            dst += c;
        }
       
    }
    for (var i = 0; i < dst.length; i++)
    {
        c1 = dst.charAt(i);
        
        if (c1 != '}')
        {
            dst1 += c1;
        }
       
    }    
    return dst1;
}

function RemoveBraces(src)
{
    src=src.replace("{","");
    src=src.replace("}","");
    return src
}