﻿
// JScript File
var global=0;
var imageGallery2 = new Array(0);
imageGallery2[0]= new Array(10);

function getNewsQuickSearch(selID)
{  
    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='t2EventListHead5'>";
    stroutput +="<h3>";
    stroutput +="News</h3>";
    stroutput +="</div>";
    stroutput +="<div class='clear'>"
    stroutput +="</div>";
    
    
    //for start
    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>";
        
   }
   // for end
   
        //  stroutput +="<div class='clear'>";
       //   stroutput +="</div>";
          document.getElementById("newsContainer").innerHTML=stroutput 
          document.getElementById("prevNext").innerHTML="";  
          //strPreNext +='<div class="t2EventListNo">'; 
          strPreNext="";
  
          if(pageID == 0)
           { 
            strPreNext +='<img alt="First" src="/files/images/btn-prev.gif" />';
             
           }
           else 
           {
   	         prevpageid=pageID-1;
	         strPreNext +='<input type="image" onclick="getNewsQuickSearch('+0+')" alt="First" src="/files/images/btn-prev.gif" />';	 
        	 
           }  
          //for start 
          
            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='getNewsQuickSearch("+i+")' >"+ ( i + 1 )  +"</a>";	     
    	          }
                  if(i < endlimit -1 )
                  {
                 
                    strPreNext +='<span>|</span>';
                   
                  }          
            }	
	        // for end

         if(pageID == count -1 )
         {
           strPreNext +=' <img src="/files/images/btn-next.gif" alt="Last" />';
           
         }
         else
         {  
          nextpageid=count -1;
           
          strPreNext +='<input type="image" onclick="getNewsQuickSearch('+nextpageid+')" alt="Last" src="/files/images/btn-next.gif" />';      
         }
      
         
        strPreNext +='<div class="clear"/>';
//        strPreNext +="<div class='clear'>";
//        strPreNext +="</div>";      
       
         document.getElementById("prevNext").innerHTML =strPreNext; 
//end of function	
}


function getSearched(selID)
{

 
       var ddlMonth = document.getElementById("searchMonth");  
       var monthValue = ddlMonth.options[ddlMonth.selectedIndex].value;
       
       var ddlYear = document.getElementById("searchYear");  
       var yearValue = ddlYear.options[ddlYear.selectedIndex].value;
       
       var ddlSearchCategory= document.getElementById("searchCategory");  
       var categoryValue = ddlSearchCategory.options[ddlSearchCategory.selectedIndex].value; 
       categoryValue = fRemoveSquarebrace(categoryValue);
         
       
       var strText = document.getElementById("searchText").value;      
       
      
        strText=trim11(strText);
      
       var pageID=selID;
       var temp = (pageID*pageLength)+pageLength;  
      if(temp>imageGallery.length)
       {
         temp=imageGallery.length;
       }
        document.getElementById("newsContainer").innerHTML="";
        temp1=0;
	    
	    count=0;
	    count=Math.ceil(imageGallery.length/pageLength);
    	
	    stroutput='';
	    strPreNext='';	
        pageCount=0;
        
    
     
       var searchMonth=monthValue;
       var searchYear= Right(yearValue,2);
       var count=0;
       if(searchMonth != 10 || searchMonth != 11 || searchMonth !=12)
       {
          searchMonth = 0 + searchMonth;    
       }
      imageGallery2=new Array();
      
     
      
      if(strText == "")
      {   
         if(imageGallery.length >0)
         {
           global=0;
              for(i=0;i<imageGallery.length;i++)
              {   
        		  
                        var strCheckMonth=  imageGallery[i][4];
                        
                        var strCheckType = imageGallery[i][11];
                        strCheckType =fRemoveSquarebrace(strCheckType);
                        
                        if(strCheckMonth != 10 || strCheckMonth != 11 || strCheckMonth !=12)
                        {  
                          strCheckMonth = 0 + strCheckMonth;  
                        }         
                           if( ( strCheckMonth == searchMonth && imageGallery[i][6]== searchYear  &&  strCheckType == categoryValue))
                           {
                               //start if            
                                 
                                         
                                     imageGallery2[global]=new Array(10) ;
                                     imageGallery2[global].push(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]);                                                          
                                      //,
                                
                                  global = global+1;
                                 //end if 
                           }
                }
               if(imageGallery2.length >0)
               {
                 search2(0);
               }
                else
                {
            
                   document.getElementById("prevNext").innerHTML='' 
                   //stroutput +='<div class="t2EventsList">';
                   stroutput +='<p> No news Available</p>';
                   //stroutput +='</div>';      
                
                document.getElementById("newsContainer").innerHTML=stroutput
                }
        }
        else
        {
           document.getElementById("prevNext").innerHTML='' 
           //stroutput +='<div class="t2EventsList">';
           stroutput +='<p> No news Available</p>';
           //stroutput +='</div>';              
           document.getElementById("newsContainer").innerHTML=stroutput
        }
      
       
         
  
      }
      else
      {       
         


     global=0;
      for(i=0;i<imageGallery.length;i++)
      {   
		  
                var strCheckMonth=  imageGallery[i][4];
                if(strCheckMonth != 10 || strCheckMonth != 11 || strCheckMonth !=12)
                {  
                  strCheckMonth = 0 + strCheckMonth;  
                }            
               
                              
                var str7 = imageGallery[i][7];
                str7 = str7.toUpperCase(); 
                var str1 = imageGallery[i][1];
                str1 = str1.toUpperCase();
                var str2 =imageGallery[i][2];
                str2 = str2.toUpperCase();
                
                var str11= imageGallery[i][11]
                str11 = fRemoveSquarebrace(str11);
                
                
                if( ( strCheckMonth == searchMonth && imageGallery[i][6]== searchYear && str11 == categoryValue) && ( str7.indexOf(strText.toUpperCase() ) !=-1 || str1.indexOf(strText.toUpperCase())!=-1 || str2.indexOf(strText.toUpperCase())!=-1))
                {
                 //start if            
                 
                         
                     imageGallery2[global]=new Array(10) ;
                     imageGallery2[global].push(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]);                                                          
                      //,
                
                  global = global+1;
                 //end if   
                }
                              
            
        }
        		//	 alert(imageGallery2[0][10]);
         if(imageGallery2.length >0)
         {
        search2(0);
        }
        else
        {
           document.getElementById("prevNext").innerHTML='' 
           //stroutput +='<div class="t2EventsList">';
           stroutput +='<p> No news Available</p>';
           //stroutput +='</div>';      
        
        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 search2(selID)
{




			 //alert(imageGallery2[1][10]);
 var pageID=selID;
  var temp = (pageID*pageLength)+pageLength; 
   
 
  if(temp>imageGallery2.length)
   {
     temp=imageGallery2.length;
   }
 
    document.getElementById("newsContainer").innerHTML="";
    
	j=selID
	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='t2EventListHead5'>";
    stroutput +="<h3>";
    stroutput +="News</h3>";
    stroutput +="</div>";
    stroutput +="<div class='clear'>"
    stroutput +="</div>";
	 
	 
    for(i=(pageID*pageLength);i<temp;i++)
	{
        stroutput +="<div class='t2EventListBody'>";
        //stroutput +="<img height='68' alt='' src='"+imageGallery2[i][18]+"' width='68'>";
        if(imageGallery2[i][18]!="")
        {
            stroutput +="<img height='68' alt='' src='"+imageGallery2[i][18]+"' width='68'>";
        }
        else
        {
            stroutput +="<img height='68' alt='' src='/files/img_blankImage.gif' width='68'>";
        }
        stroutput +="<div>";
        stroutput +="<p class='t2EventListBodyP1'>";
        
         var newarray=new String(imageGallery2[0]);
         
       
         newarray.split(",");
         
        stroutput +=""+imageGallery2[i][15]+"/"+imageGallery2[i][14]+"/"+imageGallery2[i][16]+"";
        stroutput +="</p>";
        stroutput +="<p class='t2EventListBodyP2'>";
        stroutput +=""+imageGallery2[i][11]+"";
        stroutput +="</p>";
        stroutput +="<p class='t2EventListBodyP3'>";
        stroutput +=""+imageGallery2[i][12]+"";
        stroutput +="</p>";
        stroutput +="</div>";
        stroutput +="<p class='t2EventListBodyP4'>";
        stroutput +=""+imageGallery2[i][17]+"";
       
        if(imageGallery2[i][20]!="")
        {      
          stroutput +="<a target='_blank' href='"+imageGallery2[i][20]+"'>Find out more</a>";
        }     
        else
        {
            if(imageGallery2[i][10]!="")
            { 
                stroutput +="<a href='/output/page"+imageGallery2[i][10]+".asp'>Find out more</a>";
            }
        }
        
        
           
//        if(imageGallery2[i][21]!="")
//        {       
//        
//          stroutput +="<a target='_blank'href='/output/page"+imageGallery2[i][21]+".asp'>Find out more &gt;&gt;</a>";
//        }     
//        else
//        {
         // stroutput +="&nbsp;<a href='/output/page"+imageGallery2[i][10]+".asp'>Find out more &gt;&gt;</a>";
//        }
            stroutput +="</p>";
            stroutput +="<div class='clear'>"
            stroutput +="</div>";
            stroutput +="</div>";
        
   }
//  stroutput +="<div class='clear'>";
//  stroutput +="</div>";
  document.getElementById("newsContainer").innerHTML=stroutput
  
 
  document.getElementById("prevNext").innerHTML="";
  
  //strPreNext +='<div class="t2EventListNo">'; 
  strPreNext="";
  
  if(pageID == 0)
   { 
    strPreNext +='<img alt="First" src="/files/images/btn-prev.gif" />';
     
   }
   else 
   {
   	 prevpageid=pageID-1;
	 strPreNext +='<input type="image" onclick="search2('+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+2;
                }
		        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='search2("+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="search2('+nextpageid+')" alt="Last" src="/files/images/btn-next.gif" />';      
     }
      
     
     strPreNext +='<div class="clear"/>';
     
   
   
   document.getElementById("prevNext").innerHTML =strPreNext; 
}




 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;
}
