﻿
// 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='news_header1'></div>"
        stroutput +="<div class='news_header2'>التاريخ</div>"
        stroutput +="<div class='news_header4'>الحدث</div>"
        stroutput +="<div class='news_header5'>الموقع</div>"
        stroutput +="<br class='clear'>"

        for(i=(pageID*pageLength);i<temp;i++)
	    {
	        var typecheck= imageGallery[i][11];
	        typecheck = fRemoveSquarebrace(typecheck); 

	        stroutput +="<div class='news_desc'>";

            stroutput +="<div class='news_img'>";
            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 +="<div class='news_desc_in'>";
            
            stroutput +="<div class='news_date'>";
            stroutput +=""+imageGallery[i][5]+"/"+imageGallery[i][4]+"/"+imageGallery[i][6]+"";        
            stroutput +="</div>";
            
            stroutput +="<div class='news_event'>";
            stroutput +=""+imageGallery[i][1]+"";        
            stroutput +="</div>";
            
            stroutput +="<div class='news_loc'>";
            stroutput +=""+imageGallery[i][2]+"";
            stroutput +="</div>";
            
            stroutput +="<div class='news_summary'>";
            stroutput +=""+imageGallery[i][7]+"";        
            
            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 +="</div>";
                    
            stroutput +="</div>";
            stroutput +="<br class='clear'>";
            stroutput +="</div>";
        }
        document.getElementById("newsContainer").innerHTML=stroutput; 
        document.getElementById("prevNext").innerHTML="";  
        strPreNext="";
        strPreNext +='<div class="clear"/>'; 

        strPreNext +='<div class="paging">';
        strPreNext +='<div class=pages>';
        if(pageID == 0)
        { 
            strPreNext +='<img height=17 alt="First" src="/files/images/btn-next.gif" width=17>'
        }
        else 
        {
         prevpageid=pageID-1;
         strPreNext +='<a class="imgs" href="#" onclick="getEventsQuickSearch('+0+')"><img alt="First" height="17" width="17" src="/files/images/btn-next.gif" /></a>';	 
         //strPreNext +='<input class="imgs" type="image" onclick="getEventsQuickSearch('+0+')" alt="First" height="17" width="17" src="/files/images/news_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 )
              {
                if(i==(endlimit-1))
                {
                    strPreNext +="<a style='text-decoration: none;' class='last'   >"+ ( i + 1 )  +"</a>";	     
                }
                else
                {
                    strPreNext +="<a style='text-decoration: none;'   >"+ ( i + 1 )  +"</a>";	     
                }
                
              }
              else
              {
                if(i==(endlimit-1))
                {
                    strPreNext +="<a style='text-decoration: underline;' class='last'  href='#' onclick='getEventsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
                }
                else
                {
                    strPreNext +="<a style='text-decoration: underline;'  href='#' onclick='getEventsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
                }
              }
        }	

        if(pageID == count -1 )
        {
            strPreNext +=' <img height="17" width="17" src="/files/news_prev.gif" alt="Last" />';
        }
        else
        {  
            nextpageid=count -1;
            strPreNext +='<a class="imgs" href="#" onclick="getEventsQuickSearch('+nextpageid+')"><img alt="Last" height="17" width="17" src="/files/news_prev.gif" /></a>';	 
        }
        strPreNext +='</div></div>';
        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 getSearchResults(selID)
{
    if(imageGallery.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='news_header1'></div>"
        stroutput +="<div class='news_header2'>التاريخ</div>"
        stroutput +="<div class='news_header4'>الحدث</div>"
        stroutput +="<div class='news_header5'>الموقع</div>"
        stroutput +="<br class='clear'>"

        for(i=(pageID*pageLength);i<temp;i++)
	    {
	        var typecheck= imageGallery2[i][11];
	        typecheck = fRemoveSquarebrace(typecheck); 

	        stroutput +="<div class='news_desc'>";

            stroutput +="<div class='news_img'>";
            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 +="<div class='news_desc_in'>";
            
            stroutput +="<div class='news_date'>";
            stroutput +=""+imageGallery2[i][5]+"/"+imageGallery2[i][4]+"/"+imageGallery2[i][6]+"";        
            stroutput +="</div>";
            
            stroutput +="<div class='news_event'>";
            stroutput +=""+imageGallery2[i][1]+"";        
            stroutput +="</div>";
            
            stroutput +="<div class='news_loc'>";
            stroutput +=""+imageGallery2[i][2]+"";
            stroutput +="</div>";
            
            stroutput +="<div class='news_summary'>";
            stroutput +=""+imageGallery2[i][7]+"";        
            
            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 +="</div>";
                    
            stroutput +="</div>";
            stroutput +="<br class='clear'>";
            stroutput +="</div>";
        }
        document.getElementById("newsContainer").innerHTML=stroutput; 
        document.getElementById("prevNext").innerHTML="";  
        strPreNext="";
        strPreNext +='<div class="clear"/>'; 

        strPreNext +='<div class="paging">';
        strPreNext +='<div class=pages>';
        if(pageID == 0)
        { 
            strPreNext +='<img height=17 alt="First" src="/files/images/btn-next.gif" width=17>'
        }
        else 
        {
         prevpageid=pageID-1;
         strPreNext +='<a class="imgs" href="#" onclick="getSearchResults('+0+')"><img alt="First" height="17" width="17" src="/files/images/btn-next.gif" /></a>';	 
        }  
        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 )
              {
                if(i==(endlimit-1))
                {
                    strPreNext +="<a style='text-decoration: none;' class='last'   >"+ ( i + 1 )  +"</a>";	     
                }
                else
                {
                    strPreNext +="<a style='text-decoration: none;'   >"+ ( i + 1 )  +"</a>";	     
                }
                
              }
              else
              {
                if(i==(endlimit-1))
                {
                    strPreNext +="<a style='text-decoration: underline;' class='last'  href='#' onclick='getEventsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
                }
                else
                {
                    strPreNext +="<a style='text-decoration: underline;'  href='#' onclick='getEventsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
                }
              }
        }	

        if(pageID == count -1 )
        {
            strPreNext +=' <img src="/files/news_prev.gif" alt="Last" />';
        }
        else
        {  
            nextpageid=count -1;
            strPreNext +='<a class="imgs" href="#" onclick="getSearchResults('+nextpageid+')"><img alt="Last" height="17" width="17" src="/files/news_prev.gif" /></a>';	 
        }
        strPreNext +='</div></div><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;
}
