﻿var searchStartCalendar=null;
var searchEndCalendar=null;
var addEntryStartCalendar=null;
var addEntryEndCalendar=null;
var addEventStartCal=null;
var addEventEndCal=null;
 var topMiddleCP,bottomMiddleCP,topRightCP,bottomRightCP,leftPanel;
 
 var PageBuffer_Next="";
 var PageBuffer_Prev="";
var CurrentPage = 0, LastPage = -1;


//for the category only paging
var _lastCatID=-1;
var _totalNumOfPages=-1;
var _lastCatName="";


var _lastCatIDArrayStr = "";
var _lastNumToTakeArrayStr = "";
var _lastOrgAffID=-1;
var _lastContinentCode="";
var _lastCountryID=-1;
var _lastStartDate="";
var _lastEndDate="";
var _lastKeywords="";

//these two are for the last "results from user/org queries"
var _lastSourceEntryID="";
var _lastSourceIsOrg="";


var entrySortType="Latest";
var groupByCatYesNo="YES";

var theLastMode = "MODEHOME";

var storyCache=null;
var storyIndex=0;
var intervalID=null;
var isPaused=false;

var searchControl=null;
var boolIncludeGoogleResult=true;
var searchResultTabsPanel = null;

function dude(){
alert("hey");
}

//-----------------------------------NEW COOLITE AJAX METHODS------------------------------------------------------------------------------------------


function GetResultsFromSourcePagingNonCategory(page,entryID,isOrg,currentMode,sortType,successFunc)
{
Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetResultsFromSourcePagingNonCategory",
                cleanRequest : true,
                params       : {
                    pageNum : page,
                    sourceEntryID : entryID,
                    isOrganization : isOrg,
                    currentMode : currentMode,
                    entrySortType : sortType
                    
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : eval(successFunc),
               // failure : onGetCategorySearchResultPageFailure,
                eventMask: {
                        showMask: false,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });
}

function onGetResultsFromSourcePagingNonCategorySuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var pageView = $get("PageView");
               pageView.innerHTML = content;
               _totalNumOfPages = parseInt(numPages);
            //   var numPageElement = $get("NumPages");
               
               $get("NumPages").innerHTML = numPages;
               
               if (PageBuffer_Prev=="") PageBuffer_Prev=content;
               
               if (_totalNumOfPages>CurrentPage)
                {
                //Get search option cookie info
                var searchOptions = readCookie("searchOptions");
                var currentSortType="";
                var currentGroupYesNo="";
                if (searchOptions !=null && searchOptions!=undefined){
                     var searchOptionsArray = searchOptions.split("|");
                     currentSortType = searchOptionsArray[0];
                     currentGroupYesNo=searchOptionsArray[1];
                     createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                     
                } else {
                    //Just use the current sort type, and the hard coded groupyesno...
                    createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                     currentSortType=entrySortType;
                     currentGroupYesNo=groupByCatYesNo;
                }
                
                
                    //Get the next one
                    GetResultsFromSourcePagingNonCategory((CurrentPage+1),_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,"onGetResultsFromSourcePagingNonCategoryNextPage");
                    
                    //Get the previous one
                    GetResultsFromSourcePagingNonCategory((CurrentPage-1),_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,"onGetResultsFromSourcePagingNonCategoryPreviousPage");
               
                } else {
                     LastPage=CurrentPage;
                    if (_totalNumOfPages==1 && CurrentPage==1){
                         $get("nextPageButton").disabled=true;
                        $get('previousPageButton').disabled = true;
                    } else {
                     $get("nextPageButton").disabled=true;
                     $get('previousPageButton').disabled = false;
                    }
                }
                
                
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function onGetResultsFromSourcePagingNonCategoryPreviousPage(result)
{
 //var strResult=Ext.DomQuery.selectValue("string", result, "");
 var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                PageBuffer_Prev = content;
                
                if (_totalNumOfPages>CurrentPage)
                {
                    $get('nextPageButton').disabled = false;
                } 
                else if (_totalNumOfPages==CurrentPage)
                {
                    $get('nextPageButton').disabled = true;
                }
                
                  if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
                
               // var pageView = $get("PageView");
              // pageView.innerHTML = content;
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   
   hidePagingProgress();
}

function onGetResultsFromSourcePagingNonCategoryNextPage(result)
{
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
             
                    if (content=="END"){
                        LastPage=CurrentPage;
                        $get('nextPageButton').disabled=true;
                    } else {
                     PageBuffer_Next = content;
                    $get('nextPageButton').disabled = false;
                    }
                    
                   
                
                   if (CurrentPage > 1)
                       $get('previousPageButton').disabled = false; 
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
                  
        }
   }
   hidePagingProgress();
}

function GetSearchResultPagingNonCategory(page,org,continentCode,country,startDate,endDate,keywords,currentMode,sortType,successFunc)
{
Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetSearchResultPagingNonCategory",
                cleanRequest : true,
                params       : {
                    pageNum : page,
                    orgAffiliation : org,
                    continentCode : continentCode,
                    country : country,
                    startDate : startDate,
                    endDate : endDate,
                    keywords : keywords,
                    currentMode : currentMode,
                    entrySortType : sortType
                    
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : eval(successFunc),
               // failure : onGetCategorySearchResultPageFailure,
                eventMask: {
                        showMask: false,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });
}

function onGetSearchResultPagingNonCategorySuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var pageView = $get("PageView");
               pageView.innerHTML = content;
               _totalNumOfPages = parseInt(numPages);
            //   var numPageElement = $get("NumPages");
               
               $get("NumPages").innerHTML = numPages;
               
               if (PageBuffer_Prev=="") PageBuffer_Prev=content;
               
               if (_totalNumOfPages>CurrentPage)
                {
                //Get search option cookie info
                var searchOptions = readCookie("searchOptions");
                var currentSortType="";
                var currentGroupYesNo="";
                if (searchOptions !=null && searchOptions!=undefined){
                     var searchOptionsArray = searchOptions.split("|");
                     currentSortType = searchOptionsArray[0];
                     currentGroupYesNo=searchOptionsArray[1];
                     createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                     
                } else {
                    //Just use the current sort type, and the hard coded groupyesno...
                    createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                     currentSortType=entrySortType;
                     currentGroupYesNo=groupByCatYesNo;
                }
                    //Get the next one
                    GetSearchResultPagingNonCategory((CurrentPage+1),_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchNonCategoryGroupNextPage");
                    //Get the next one
                    GetSearchResultPagingNonCategory((CurrentPage-1),_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchNonCategoryGroupPreviousPage");
                
                } else {
                     LastPage=CurrentPage;
                    if (_totalNumOfPages==1 && CurrentPage==1){
                         $get("nextPageButton").disabled=true;
                        $get('previousPageButton').disabled = true;
                    } else {
                     $get("nextPageButton").disabled=true;
                     $get('previousPageButton').disabled = false;
                    }
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}


function GetCategorySearchResultPage(page,catID,org,continentCode,country,startDate,endDate,keywords,currentMode,sortType,successFunc)
{
Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetCategorySearchResultPage",
                cleanRequest : true,
                params       : {
                    pageNum : page,
                    categoryID : catID,
                    orgAffiliation : org,
                    continentCode : continentCode,
                    country : country,
                    startDate : startDate,
                    endDate : endDate,
                    keywords : keywords,
                    currentMode : currentMode,
                    entrySortType : sortType
                    
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : eval(successFunc),
               // failure : onGetCategorySearchResultPageFailure,
                eventMask: {
                        showMask: false,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });
}

function onGetCategorySearchResultPageSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var pageView = $get("PageView");
               pageView.innerHTML = content;
               
               if (PageBuffer_Prev=="") PageBuffer_Prev=content;
               
               if (_totalNumOfPages>CurrentPage)
                {
                    //Get search option cookie info
                    var searchOptions = readCookie("searchOptions");
                    var currentSortType="";
                    var currentGroupYesNo="";
                    if (searchOptions !=null && searchOptions!=undefined){
                         var searchOptionsArray = searchOptions.split("|");
                         currentSortType = searchOptionsArray[0];
                         currentGroupYesNo=searchOptionsArray[1];
                         createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                         
                    } else {
                        //Just use the current sort type, and the hard coded groupyesno...
                        createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                         currentSortType=entrySortType;
                         currentGroupYesNo=groupByCatYesNo;
                    }
                        //Get the next one
                        GetCategorySearchResultPage((CurrentPage+1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchNextPage");
                       //Get the previous one
                        GetCategorySearchResultPage((CurrentPage-1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchPreviousPage");
                
                } else {
                    LastPage=CurrentPage;
                    if (_totalNumOfPages==1 && CurrentPage==1){
                         $get("nextPageButton").disabled=true;
                        $get('previousPageButton').disabled = true;
                    } else {
                     $get("nextPageButton").disabled=true;
                     $get('previousPageButton').disabled = false;
                    }
                   
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function onGetSearchNonCategoryGroupPreviousPage(result)
{
 //var strResult=Ext.DomQuery.selectValue("string", result, "");
 var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                PageBuffer_Prev = content;
                
                if (_totalNumOfPages>CurrentPage)
                {
                    $get('nextPageButton').disabled = false;
                } 
                else if (_totalNumOfPages==CurrentPage)
                {
                    $get('nextPageButton').disabled = true;
                }
                
                  if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
               // var pageView = $get("PageView");
              // pageView.innerHTML = content;
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   hidePagingProgress();
}

function onGetSearchPreviousPage(result)
{
 //var strResult=Ext.DomQuery.selectValue("string", result, "");
 var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                PageBuffer_Prev = content;
               
                if (_totalNumOfPages>CurrentPage)
                {
                    $get('nextPageButton').disabled = false;
                } 
                else if (_totalNumOfPages==CurrentPage)
                {
                    $get('nextPageButton').disabled = true;
                }
                
                if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
               // var pageView = $get("PageView");
              // pageView.innerHTML = content;
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   hidePagingProgress();
}

function onGetSearchNextPage(result)
{
 //   var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
             
                    if (content=="END"){
                        LastPage=CurrentPage;
                        $get('nextPageButton').disabled=true;
                    } else {
                     PageBuffer_Next = content;
                    $get('nextPageButton').disabled = false;
                    }
                    
                   
                
                   if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
                  
        }
   }
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function onGetSearchNonCategoryGroupNextPage(result)
{
 //   var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var numPages = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
             
                    if (content=="END"){
                        LastPage=CurrentPage;
                        $get('nextPageButton').disabled=true;
                    } else {
                     PageBuffer_Next = content;
                    $get('nextPageButton').disabled = false;
                    }
                    
                   
                    if (CurrentPage>1) {
                        $get('previousPageButton').disabled = false;
                    } else {
                        $get('previousPageButton').disabled = true;
                    }
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
                  
        }
   }
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function GetCategorySourceSearchResultPage(page,catID,entryID,isOrgBool,currentMode,sortType,successFunc)
{
Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetCategorySourceSearchResultPage",
                cleanRequest : true,
                params       : {
                    pageNum : page,
                    categoryID: catID,
                    sourceEntryID : entryID,
                    isOrg : isOrgBool,
                    currentMode : currentMode,
                    entrySortType : sortType
                    
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : eval(successFunc),
               // failure : onGetCategorySearchResultPageFailure,
                eventMask: {
                        showMask: false,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });
}

function onGetCategorySourceSearchResultPageSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase())
            {
                var pageView = $get("PageView");
               pageView.innerHTML = content;
               
               if (PageBuffer_Prev=="") PageBuffer_Prev=content;
               
               if (_totalNumOfPages>CurrentPage)
                {
                    //Get search option cookie info
                    var searchOptions = readCookie("searchOptions");
                    var currentSortType="";
                     var currentGroupYesNo="";
                    if (searchOptions !=null && searchOptions!=undefined){
                         var searchOptionsArray = searchOptions.split("|");
                         currentSortType = searchOptionsArray[0];
                        currentGroupYesNo =searchOptionsArray[1];
                         createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                         
                    } else {
                        //Just use the current sort type, and the hard coded groupyesno...
                        createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                         currentSortType=entrySortType;
                         currentGroupYesNo=groupByCatYesNo;
                    }
                    
                    
                        //Get the next
                       
                       GetCategorySourceSearchResultPage((CurrentPage+1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchNextPage");
                       
                       //Get the previous
                       GetCategorySourceSearchResultPage((CurrentPage-1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchPreviousPage");
    
                } else {
                     LastPage=CurrentPage;
                    if (_totalNumOfPages==1 && CurrentPage==1){
                         $get("nextPageButton").disabled=true;
                        $get('previousPageButton').disabled = true;
                    } else {
                     $get("nextPageButton").disabled=true;
                     $get('previousPageButton').disabled = false;
                    }
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function onGetSourceSearchPreviousPage(result)
{
 //var strResult=Ext.DomQuery.selectValue("string", result, "");
 var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                PageBuffer_Prev = content;
                
                if (_totalNumOfPages>CurrentPage)
                {
                    $get('nextPageButton').disabled = false;
                } 
                else if (_totalNumOfPages==CurrentPage)
                {
                    $get('nextPageButton').disabled = true;
                }
                
                if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
               // var pageView = $get("PageView");
              // pageView.innerHTML = content;
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   hidePagingProgress();
}

function onGetSourceSearchNextPage(result)
{
 //   var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
             
                    if (content=="END"){
                        LastPage=CurrentPage;
                        $get('nextPageButton').disabled=true;
                    } else {
                     PageBuffer_Next = content;
                    $get('nextPageButton').disabled = false;
                    }
                    
                   
                
                     if (CurrentPage>1) {
                        $get('previousPageButton').disabled = false;
                    } else {
                        $get('previousPageButton').disabled = true;
                    }
                }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
                  
        }
   }
   hidePagingProgress();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function GetResultsFromSourceGroupedByCat(entryID,isOrg,activeMode,currSortType,currGroupYesNo)
{
 Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetResultsFromSourceGroupedByCat",
                cleanRequest : true,
                params       : {
                    sourceEntryID : entryID,
                    isOrganization: isOrg,
                    currentMode : activeMode,
                    entrySortType : currSortType,
                    groupByCatYesNo : currGroupYesNo
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onGetSearchResultsFromSourceSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });
}

function onGetSearchResultsFromSourceSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
               communityPanel.getBody().update(content);
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}
function GetSearchResultsGroupedByCat(categoryIDStr,numToTakeStr,org,continentCode,country,startDate,endDate,keywords,activeMode,sortType,groupYesNo)
{
    //var catStr = categoryIDArray.join("|");
    //var numToTakeStr = numToTakeArray.join("|");
    
        Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetSearchResultsGroupedByCat",
                cleanRequest : true,
                params       : {
                    categoriesStr : categoryIDStr,
                    numToTakeFromCatsStr : numToTakeStr,
                    orgAffiliation : org,
                    continentCode : continentCode,
                    country : country,
                    startDate : startDate,
                    endDate : endDate,
                    keywords : keywords,
                    currentMode : activeMode,
                    entrySortType : sortType,
                    groupByCatYesNo : groupYesNo
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onGetSearchResultsGroupedByCatSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: "Searching Entries, one moment..."
                    }

            });

}

function onGetSearchResultsGroupedByCatSuccess(result)
{
//    var strResult=Ext.DomQuery.selectValue("string", result, "");
var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                
                //Clear the window
                var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
               // communityPanel.autoScroll=false;
               // communityPanel.doLayout();
                    communityPanel.getBody().update("");
                    
                    
//                if (boolIncludeGoogleResult)
//                {   
//                    if (!Ext.getCmp("searchResultTabPanel"))
//                    {
//                        searchResultTabsPanel = new Ext.TabPanel({
//                        renderTo: communityPanel.getBody(),
//                        activeTab: 0,
//                        deferredRender: false,
//                        enableTabScroll:true,
//                        layoutOnTabChange: true,
//                        xtype: 'tabpanel',
//                        id:'searchResultTabPanel',

//                        items: [{
//                                    title: 'Climate 1-Stop Results',
//                                    html: content,
//                                    id: 'climate1stopResultTab',
//                                    layout: 'fit',
//                                    bodyStyle:'background-color:;'
//                                   //bodyCssClass:'searchResultTabPanel-body'
//                                                //autoScroll:true,
//                                    // defaults:{ autoScroll:true } 
//                                },
//                                {
//                                       title: 'Google Results',
//                                       html: 'Google Results Processing...',
//                                       id: 'googleResultTab',
//                                       layout: 'fit',
//                                    //   bodyCssClass:'searchResultTabPanel-body',
//                                       closable:true
//                                    //   autoScroll:true,
//                                     //   defaults:{ autoScroll:true }  
//                                }
//                               ]
//                    });
//                    
//                    //Now the tab panel has been created.
//                      //add the tab panel to the community section
//                        communityPanel.add(searchResultTabsPanel);
//                        communityPanel.doLayout();
//                    }
//                   
//                   
//                    //Then do the google search which should add a tab.
//                    initGoogleSearch();
//                   

//                } else {
                     var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                   communityPanel.getBody().update(content);
               // }
               
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function getGraph()
{
 var strInitWindow = "new Ext.Window({id:'graphWinObj',renderTo: Ext.getBody(),resizable: true, collapsible:true,title:\"Preparing Graph...\",autoScroll:true,height: 500,width: 700,frame:true,x:"+startingLeft+",y:"+startingTop+"});";
             eval("graphWin = " + strInitWindow);
             eval("graphWin" + ".show();");
             getGraphContent("graphWin");
}

var graphWin;
function getGraphContent(graphWindowName)
{
var windowID = eval(graphWindowName + ".id");
Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetGraphContent",
                cleanRequest : true,
                params       : {
                    graphWindowName : graphWindowName
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onGetGraphSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:windowID,
                       // minDelay: 500,
                        msg: "Preparing Graph..."
                    }

            });
}

function onGetGraphSuccess(result)
{
 
    var strResult= getWebSvcString(result);
   // alert(strResult);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var title = resultParts[0];
            var windowName = resultParts[1];
             var content = resultParts[2];
    //title=escape(title);
    //entryWin0.setTitle("cool");
            eval(windowName +".setTitle(title)");
            eval(windowName +".body.update(content)");
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function GetEntryContent(entryID,entryWinName)
{
    var windowID= eval(entryWinName + ".id");
        Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetEntryContent",
                cleanRequest : true,
                params       : {
                    entryID : entryID,
                    containerName: entryWinName
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onGetEntryContentSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:windowID,
                       // minDelay: 500,
                        msg: "Fetching Entry..."
                    }

            });
}

function onGetEntryContentSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
   // alert(strResult);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var title = resultParts[0];
            var windowName = resultParts[1];
             var content = resultParts[2];
    //title=escape(title);
    //entryWin0.setTitle("cool");
            eval(windowName +".setTitle(title)");
            eval(windowName +".body.update(content)");
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function UpdateLatestQASection(activeMode)
{
    Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetLatestQASection",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateQASuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_LatestQA",
                       // minDelay: 500,
                        msg: "Preparing Q/A..."
                    }

            });
}

function onUpdateQASuccess(result)
{
    var strResult= getWebSvcString(result);
    
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var qaPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_LatestQA");
               qaPanel.getBody().update(content);
              // alert(strResult.length);
               //Ext.Msg.alert("Message", content);
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
}

function UpdateNewsFeedsSection(activeMode)
{
        Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetNewsFeedsSection",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateNewsFeedsSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_NewsFeedsTab",
                       // minDelay: 500,
                        msg: "Preparing News..."
                    }

            });
}
function onUpdateNewsFeedsSuccess(result)
{
    var strResult= getWebSvcString(result);
    
    //=Ext.DomQuery.selectValue("string", result, "");
    //alert(blah.length);
    //alert(result.childNodes[0].text);
    
   // alert(result.childNodes[1].text.length);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var newsFeedsPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_NewsFeedsTab");
               newsFeedsPanel.getBody().update(content);
              // alert(strResult.length);
               //Ext.Msg.alert("Message", content);
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function UpdateBookmarksSection(activeMode)
{
        Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetBookmarksSection",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateBookmarksSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_BookmarksTab",
                       // minDelay: 500,
                        msg: "Preparing Bookmarks..."
                    }

            });
}
function onUpdateBookmarksSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
   // alert(strResult);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var bookmarksPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_BookmarksTab");
               bookmarksPanel.getBody().update(content);
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
} 

function UpdateDataAndVisualizationTab(activeMode,tabID)
{
    var loadingMsg = "Preparing Data Visualization...";
    Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetDataVizTabContent",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode,
                    tabID : tabID
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateDataVizSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: loadingMsg
                    }

            });

}

function GetProjectLocations(activeMode)
{
    didNotifyProjAdded=false;
    var loadingMsg = "Fetching Project Locations...";
    Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetProjectLocations",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onGetProjectLocationsSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_projectsTab",
                       // minDelay: 500,
                        msg: loadingMsg
                    }

            });
}

function createMarker(location, url,markerOptions) { 
    var marker = new GMarker(location,markerOptions); 
    GEvent.addListener(marker, "click", function() { 
        eval(url); 
    }); 
    return marker; 
} 


function onGetProjectLocationsSuccess(result)
{
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;

        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase())
            {
                //Plot the markers on the projects map, check to make sure the projectsMap is not null.
	        
                if (projectMap!=null)
                {
                    //Remove the yellow marker then add all the markers
                     if (addProjectMarker!=null) projectMap.removeOverlay(addProjectMarker);
                            
                      var redIcon = new GIcon(G_DEFAULT_ICON);
                       redIcon.image = "Images/projectMarkerIcon.png";

                        // Set up our GMarkerOptions object
                        markerOptions = { icon:redIcon };
                        
                    var markerInfoArray = content.split("|#|");
                    
                    //Loop through and add markers to the map
                    for (var i=0;i<markerInfoArray.length;i++)
                    {
                        //Split this marker's info (lat,long,htmlBubbleContent)
                        var projectInfoArray = markerInfoArray[i].split("~$~");
                        
                        projectMap.addOverlay(createMarker(new GLatLng(parseFloat(projectInfoArray[0]), parseFloat(projectInfoArray[1])), "displayEntry("+projectInfoArray[2]+");",markerOptions)); 

                        
                     //   var point = new GLatLng(parseFloat(projectInfoArray[0]), parseFloat(projectInfoArray[1]));
                       // projectsMaps.setCenter(point, 10);
                    //    var marker = new GMarker(point);
                     //   projectMap.addOverlay(marker);
                     //   GEvent.addListener(marker, "click", function()
                     //   {marker.openInfoWindowHtml(projectInfoArray[2]);});
                    }
                    
                }
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
 //  showNewsFeedsTab();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function onUpdateDataVizSuccess(result)
{
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var tabID = resultParts[1];
            var content = resultParts[2];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
//                var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
//               communityPanel.getBody().update(content);
               
               //Use the returned tabID to update the html content of the tab
               //var tabTest = Ext.getCmp(tabID);
                 var tab = Ext.getCmp(tabID);
                 //var tab2 = Ext.getCmp("ctl00_MainContentPlaceHolder_"+tabID);
                 //alert(t
                 
                 //Update the content of the tabs
                 if (tab.rendered){
                    tab.body.update(content);
                 } else {
                    tab.html = content;
                 }
                
                 //Now that the tabs have the appropriate HTML content, initiate the maps,etc
                 if (tabID.toUpperCase()=="PROJECTSTAB")
                 {
                    //Get Project location info to display as placemarkers.
                    initializeProjectsMap();
                    tab.doLayout();
                  //   tab.doLayout();
                 } 
                 else if (tabID.toUpperCase()=="OBSERVEDDATATAB")
                 {
                    
                 }
                 else if (tabID.toUpperCase()=="PROJECTIONSDATATAB")
                 {
                 
                 }
               // tab.update(content);
               
                //elem = $find(panel);
             // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   showNewsFeedsTab();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function UpdateCommunitySection(activeMode)
{
    var loadingMsg = "Loading...";
  
    if (activeMode.toUpperCase()=="MODEHOME")
    {
        loadingMsg = "Preparing Community Section...";
    } else if (activeMode.toUpperCase()=="MODEADDENTRY")
    {
        loadingMsg = "Preparing Add Entry Form...";
    } else if (activeMode.toUpperCase()=="MODECALENDAR")
    {
        loadingMsg = "Preparing Community Calendar...";
    } else if (activeMode.toUpperCase()=="MODEDISCUSS")
    {
        loadingMsg = "Preparing Topic Discussion...";
    } else if (activeMode.toUpperCase()=="MODEABOUT")
    {
        loadingMsg = "Preparing About Information...";
    } else if (activeMode.toUpperCase()=="MODEDATAVISUALIZATION")
    {
        loadingMsg = "Preparing Data Visualization...";
    }
    
    Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetCommunitySection",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateCommunitySuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_CommunityPanel",
                       // minDelay: 500,
                        msg: loadingMsg
                    }

            });
}

function onUpdateCommunitySuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
               communityPanel.getBody().update(content);
               
               if (activeMode.toUpperCase()=="MODECLIMATEMAPPER"){
               wmsURL = resultParts[2];
               var currWMSLyrID = resultParts[3];
               
                initializeMap(currWMSLyrID);
               }
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
   showNewsFeedsTab();
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}

function UpdateLatestEntriesSection(activeMode)
{
    Ext.net.DirectMethod.request({
                url          : "Climate1StopWebService.asmx/GetLatestEntriesSection",
                cleanRequest : true,
                params       : {
                    currentMode : activeMode
                },
//                success      : function (result) {
//                    Ext.Msg.alert("Message", Ext.DomQuery.selectValue("string", result, ""));
                success      : onUpdateLatestEntriesSuccess
                ,
                eventMask: {
                        showMask: true,
                        target:"customtarget",
                        customTarget:"ctl00_MainContentPlaceHolder_LatestEntriesPanel",
                       // minDelay: 500,
                        msg: "Fetching Latest Entries..."
                    }

            });
}

function onUpdateLatestEntriesSuccess(result)
{
    //var strResult=Ext.DomQuery.selectValue("string", result, "");
    var strResult= getWebSvcString(result);
    if (strResult!=""){
         var elem;
        if (strResult.indexOf("|~|")!=-1)
        {
            var resultParts = strResult.split("|~|");
            var sentMode = resultParts[0];
            var content = resultParts[1];
            
            if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                var latestEntriesPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_LatestEntriesPanel");
               latestEntriesPanel.getBody().update(content);
                //elem = $find(panel);
               // elem._childDiv.innerHTML = result;
            }
                  
        }
        else
        {
            //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
            //during the send/receive process
            //elem = $find(context);
            //elem._childDiv.innerHTML = result;
        }
   }
    //alert(Ext.DomQuery.selectValue("string", result, ""));
}
//----------------------------------------------------------------------------------------------------------------------------------------------------
function onCompletePrevPage(result,context)
{
    PageBuffer_Prev = result;
    $get('nextPageButton').disabled = false;
}

function onFailPrevPage(result,context)
{
alert("previous page failed");
}

function onCompleteNextPage(result,context)
{
    if (result!="")
    {
        if (result=="END"){
            LastPage=CurrentPage;
            $get('nextPageButton').disabled=true;
        } else {
         PageBuffer_Next = result;
        $get('nextPageButton').disabled = false;
        }
        
       
    
     if (CurrentPage>1) {
                    $get('previousPageButton').disabled = false;
                } else {
                    $get('previousPageButton').disabled = true;
                }
    }
}

function onFailNextPage(result,context)
{
alert("sorry, next page failed");
}

//Iniating the paging process
//function onCompleteCurrentPage(result,context)
//{
//    $get(context).innerHTML = result;
//    
//    if (_totalNumOfPages>CurrentPage)
//    {
//        //Get the next one
//        Climate1StopWebService.GetCategorySearchResultPage((CurrentPage+1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,onCompleteNextPage,onFailNextPage,"PageView");
//    } else {
//        LastPage=CurrentPage;
//        $get("nextPageButton").disabled=true;
//    }
//}

function onFailCurrentPage(result,context)
{
alert("Error fetching current page");
}

//function onClientLoginSuccess(result,context)
//{
//   // alert("client login worked?");
//    
//    window.location.reload();
//}
//function onClientLoginFail(result,context)
//{
//    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Login Failed!</p><br/>";
//         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Your login attempt has failed, please check your credentials and try again.</p>";
//         messageHTML += "<br/>";
//         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
//         //validateHTML+= "</div>";
//         displayStaticMessage(messageHTML,false,370,200);
//}

//Web service fail handler
function onServiceFail(err,context)
{
   if (context!=null)
    {
       // alert("service failed");
        var rTop = $find(context);
        rTop._childDiv.innerHTML = "Sorry, there was a problem obtaining this content: "+ err.get_message();
    }
}
//Web service success handler
function onServiceSuccess(result,context)
{
    if (context!=null)
    {
   // alert("service succeed - " + context);
        if (result!=""){
             var elem;
            if (context.indexOf("|")!=-1)
            {
                var contextParts = context.split("|");
                var panel = contextParts[0];
                var sentMode = contextParts[1];
                
                if (sentMode.toUpperCase()==activeMode.toUpperCase()){
                    elem = $find(panel);
                    elem._childDiv.innerHTML = result;
                }
                      
            }
            else
            {
                //Just put the HTML into the appropriate panels, we're not concerned about whether the user switched modes
                //during the send/receive process
                elem = $find(context);
                elem._childDiv.innerHTML = result;
            }
            
            //if (context=="topMiddleContentBehavior"){
                //hideMainLoading();
           // }
           // alert(elem._childDiv.innerHTML);
           // alert(elem._childDiv.style.height);
            //alert(elem._childDiv.innerWidth);
            //alert(elem._childDiv.innerHeight);
        } else {
            //alert("Sorry, the website is experiencing some difficulties, try to reload the page");
        }
    }
//hideMainLoading();
}

function onGetStoryCacheSuccess(result,context)
{
    var storydiv = document.getElementById(context);
    storyCache = result;
    
     if (intervalID!=null) {
         clearInterval(intervalID);
         intervalID=null;
     }
 
    intervalID = setInterval("changeStory('forward');",8000);
    //var inter
    
}

function onGetStoryCacheFail(result,context)
{

}

var didNotifyProjAdded=false;
function onAddProjectEntryToMapSuccess(result,context)
{
//Check result for entry ID if you wish
  var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry Submitted!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Thanks for adding your project map!&nbsp;<img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
        // displayStaticMessage(messageHTML,false,370,160);
   // alert("Your entry was added successfully added!");
    //window.location = "Default.aspx";
   // setMode("modeHome",true);
   
       Ext.Msg.show({
       title      : 'Project Added to Map',
       msg        : 'Your project has successfully been added to the map!',
       width      : 300,
       buttons    : Ext.MessageBox.OK,
       fn:function(btn, text) {
       //if (!didNotifyProjAdded){
                Ext.net.Notification.show({
                                        iconCls  : 'icon-information',
                                        //pinEvent : 'click',
                                        //icon : Ext.Notification.INFO,
                                        html     : "People can also search for your project through the Climate 1-Stop!",
                                        title    : 'Project Entry Also Added',
                                        hideDelay:7000
                                     });
        //    didNotifyProjAdded=true;
   // }
      // Ext.Msg.notify("Project Entry Also Added", "People can also search for your project through the Climate 1-Stop!");
   
        },

       icon : Ext.MessageBox.INFO
    })
    
    //Now update the map's icons
   GetProjectLocations(activeMode);
}

function onAddEntrySuccess(result,context)
{
//Check result for entry ID if you wish
  var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry Submitted!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Thanks for contributing!&nbsp;<img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
   // alert("Your entry was added successfully added!");
    //window.location = "Default.aspx";
    setMode("modeHome",true);
}

function onAddEntryFail(err,context)
{
var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Add Entry Failed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem adding your entry, please try again.\n\n"+err.get_message()+"&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,200);
    //alert("There was a problem adding your entry, please try again.\n\n" + err.get_message());
}

function onGetCountriesFail(err,context)
{
    alert("There was a problem getting a list of countries for this continent.Try again.");
}

function onGetCountriesSuccess(result,context)
{
    var countriesDD = $get(context);
    if (result!=null){
        var countriesArray = result;
        
         //Clear the countries.
         countriesDD.options.length = 0;
         //Add the default choice of "all countries"
         countriesDD.options[0] = new Option("Choose Country...","-1");
        for(var i=0;i<countriesArray.length;i++) {
            var countryArray = countriesArray[i].split("|");
            var countryName = countryArray[0];
            var countryID = countryArray[1];
            countriesDD.options[countriesDD.options.length] = new Option(countryName, countryID);
        }
    } else {
         //Clear the countries.
         countriesDD.options.length = 0;
         //Add the default choice of "all countries"
         countriesDD.options[0] = new Option("Countries","-1");
    }
}

//load the content into an entry window.
function onGetEntrySuccess(result,windowVar)
{
    var resultParts = result.split("|~|");
    var title = resultParts[0];
    var content = resultParts[1];
    //title=escape(title);
    eval(windowVar +".load('inline',content,title)");

}

function onGetEntryFail(result,context)
{
    //alert("get entry failed");
    
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry not Available!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;This entry is currently not available, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onAddEntryCommentSuccess(result,context)
{
   var entryID = parseInt(context);
   //var entryName = result;
   refreshEntry(entryID);
   //displayEntry(entryID,
}

function onAddEntryCommentFail(result,context)
{
 var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Comment not added!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem adding the comment, try contacting the person directly.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onSubmitFeedbackSuccess(result,context)
{
  
  var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Feedback Submitted!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Thanks for your feedback!<br/>Your feedback helps us suggest relevant content.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,200);
  
  var entryID = parseInt(context);
  //var entryName = result;
  refreshEntry(entryID);
  
}

function onSubmitFeedbackFail(result,context)
{
var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Feedback not Received!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem submitting feedback, try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onBookmarkEntrySuccess(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry Bookmarked!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;This entry was added to your bookmarks area.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
          var entryID = parseInt(context);
          //var entryName = result;
          refreshEntry(entryID);
          
          //Refresh the bookmarks area
          UpdateBookmarksSection(activeMode);
          
          if (activeMode.toUpperCase()=="MODEDATAVISUALIZATION")
          {
            UpdateDataAndVisualizationTab(activeMode,"handpickedToolsTab");
          }
//          if (refreshToolsTab)
//          {
//            refreshToolsTab=false;
//            UpdateDataAndVisualizationTab(activeMode,"handpickedToolsTab");
//          }
       //   Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");
}

function onBookmarkEntryFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Bookmark Failed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem bookmarking this entry, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onDeleteBookmarksSuccess(result,deletedBookmarkEntryArrayID)
{
    var entryID;
    for(var i=0;i<deletedBookmarkEntryArrayID.length;i++)
    {
        entryID = parseInt(deletedBookmarkEntryArrayID[i]);
        refreshEntry(entryID);
    }   
    

    //Refresh the bookmarks area
    UpdateBookmarksSection(activeMode);
    
    if (activeMode.toUpperCase()=="MODEDATAVISUALIZATION")
          {
   //         refreshToolsTab=false;
            UpdateDataAndVisualizationTab(activeMode,"handpickedToolsTab");
          }
   // Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");

}

function onDeleteBookmarksFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Bookmark Delete Failed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem deleting the bookmark(s), please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onGroupBookmarkSuccess(result,context)
{    
    
    //Refresh the bookmarks area
    UpdateBookmarksSection(activeMode);
    //Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");

}

function onGroupBookmarkFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Bookmark Grouping Failed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem with grouping your bookmarks, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onSendMessageSuccess(result,textBoxID)
{    
   var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Message Sent!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Your message was sent successfully.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
         $get(textBoxID).value="";
    $get("sndMsgCD" + result).value="500";
}

function onSendMessageFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Problem sending message!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem sending your message, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onDeleteEntrySuccess(result,context)
{
     var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry Deleted!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;That entry is history!&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
         var entryID = parseInt(context);
         closeEntryByEntryID(entryID);
         
         //Refresh top, bottom, and bookmark area;
         if (isMainPage()){
         setMode(activeMode);
         //UpdateCommunitySection(activeMode);
       //  UpdateLatestEntriesSection(activeMode);
         UpdateBookmarksSection(activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleTopPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"topMiddleContentBehavior"+"|"+activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleLowerPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"bottomMiddleContentBehavior");
        
         }
       // Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");
}

function onDeleteEntryFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry not Deleted!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem deleting the entry, ask Dan why.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onChangeCatSuccess(result,context) 
{
var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Success!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;You've changed the entry category!&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
         var entryID = parseInt(context);
         refreshEntry(entryID);
         
         //Refresh top, bottom, and bookmark area;
         if (isMainPage()){
         UpdateCommunitySection(activeMode);
        // UpdateLatestEntriesSection(activeMode);
         UpdateBookmarksSection(activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleTopPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"topMiddleContentBehavior"+"|"+activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleLowerPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"bottomMiddleContentBehavior");
        
         }
        //Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");
}

function onChangeCatFail(result,context)
{
 var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry Category not Changed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem changing the entry category, ask Dan why.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onRemoveProfilePicSuccess(result,context) 
{
var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Success!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;You've removed someone's profile picture!&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
         var entryID = parseInt(context);
         refreshEntry(entryID);
         
         //Refresh top, bottom, and bookmark area;
         if (isMainPage()){
         UpdateCommunitySection(activeMode);
         //UpdateLatestEntriesSection(activeMode);
         UpdateBookmarksSection(activeMode);
          //Climate1StopWebService.FetchHTMLContent("middleTopPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"topMiddleContentBehavior"+"|"+activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleLowerPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"bottomMiddleContentBehavior");
        
         }
       // Climate1StopWebService.FetchHTMLContent("rightUpperPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"rightTopContentBehaviorID");
}

function onRemoveProfilePicFail(result,context)
{
 var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Profile pic not removed!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem removing the profile picture, ask Dan why.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onNotifyUserCheckSuccess(result,notifyBool)
{    
    var messageHTML="";
    if (notifyBool){
         messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Notification Active!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;You will be notified when a comment is added to this entry.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
     
     } else {
         messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Notification Inactive!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Notifications have been turned off for this entry.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
     }

}

function onNotifyUserCheckFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Problem setting notification!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem with setting your entry comment notification, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onGetDiscussionListSuccess(result,context)
{
    $get("sortedDiscussions").innerHTML = result;
}

function onGetDiscussionListFail(result,context)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Problem getting discussion list!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem with getting the discussion list, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
}

function onAddDiscussionSuccess(result,context)
{
$get("AddDiscussionButton").disabled = false;

var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Success!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:green'><img src='Images/Green_check.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Your discussion topic/question has been started!&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
          if (isMainPage()){
          UpdateCommunitySection(activeMode);
         // UpdateLatestEntriesSection(activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleTopPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"topMiddleContentBehavior"+"|"+activeMode);
         // Climate1StopWebService.FetchHTMLContent("middleLowerPanel",activeMode,null,null,onServiceSuccess,onServiceFail,"bottomMiddleContentBehavior");
        
         }
}

function onAddDiscussionFail(result,context)
{

var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Problem starting discussion topic!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;There was a problem starting your discussion topic/question, please try again later.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         $get("AddDiscussionButton").disabled = false;
}
//--------------------------------------------------------------------------------------
//Above this are the success/fail handlers for the webservice
//---------------------------------------------------------------------------------------

//function hoverPlayImg(featVizThumbElement)
//{
//alert("get the feat viz thumb and hover an image over it");
//}

function setGroupResultsFromSource(groupedBool)
{
  var groupYesNo = "";
    if (groupedBool)
    {
         groupYesNo="YES";
    } else {
         groupYesNo="NO";
    }
    currGroupYesNo = groupYesNo;
    
    var searchOptions = readCookie("searchOptions");
     var currentSortType="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentSortType = searchOptionsArray[0];
         createCookie("searchOptions",currentSortType+"|"+groupYesNo,0);
         
    } else {
        currentSortType=entrySortType;
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",currentSortType+"|"+groupYesNo,0);
    }
     //reset paging variables
            CurrentPage = 1;
            _totalNumOfPages = 0;
            
            //Check if the user wants the results grouped or not, take appropriate path
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                  GetResultsFromSourceGroupedByCat(_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,groupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
               
               //if the user doesn't want them grouped, initialize the paging right away
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;display:block;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>"
                html += "</div>";
                html += "<hr />";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchFromSourceNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                 html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousFromSourceNonCategoryPageClick()' disabled='disabled' class='cssTextButton'/>";
               html += "&nbsp;&nbsp;";
               // html += "&nbsp;&nbsp;&nbsp;&nbsp;";
               // html += "<span id='PagingDisplay' class='PagingNumbers'><a href=\"javascript:alert('doSomething');\">1</a>&nbsp;&nbsp;<b><a href=\"javascript:alert('doSomething');\">2</a></b>&nbsp;&nbsp;<a href=\"javascript:alert('doSomething');\">3</a></span>";
              //   html += "&nbsp;&nbsp;&nbsp;&nbsp;";
                html += "<input id='nextPageButton' type='button' value='Next' onclick='onNextFromSourceNonCategoryPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
               // var blah = document.getElementById('PageView');
               
               //Get the current sort type from cookie and use that
                //if (currSortType==undefined || currSortType=="undefined") currSortType="Latest";
               //GetSearchResultPagingNonCategory(CurrentPage,org,continentCode,country,startDate,endDate,keywords,activeMode,currSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
                
                
               GetResultsFromSourcePagingNonCategory(CurrentPage,_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,"onGetResultsFromSourcePagingNonCategorySuccess");
               }
   // GetResultsFromSource(_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,groupYesNo);
    
}

function setGroupResults(groupedBool)
{
    var groupYesNo = "";
    if (groupedBool)
    {
         groupYesNo="YES";
    } else {
         groupYesNo="NO";
    }
    currGroupYesNo = groupYesNo;
    
    var searchOptions = readCookie("searchOptions");
    var currentSortType="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentSortType = searchOptionsArray[0];
         createCookie("searchOptions",currentSortType+"|"+groupYesNo,0);
         
    } else {
        currentSortType=entrySortType;
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",currentSortType+"|"+groupYesNo,0);
    }
    
      
            
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                GetSearchResultsGroupedByCat(_lastCatIDArrayStr,_lastNumToTakeArrayStr,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currentSortType,groupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
              CurrentPage=1;
              _totalNumOfPages=1;
              LastPage=-1;
              
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;display:block;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>";
                html += "</div>";
                html += "<hr/>";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                   html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousNonGroupedPageClick();' disabled='disabled' class='cssTextButton'/>";
                html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextNonGroupedPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
                
                
               GetSearchResultPagingNonCategory(CurrentPage,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currentSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
                
            }
    
    
   
}

function doPagingCategorySearchResultSort(sortType,numPages)
{
    var searchOptions = readCookie("searchOptions");
     var currentGroupResultYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentGroupResultYesNo = searchOptionsArray[1];
         createCookie("searchOptions",sortType+"|"+currentGroupResultYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",sortType+"|"+groupByCatYesNo,0);
        currentGroupResultYesNo=groupByCatYesNo;
    }
    
    initSearchCategory(numPages,_lastCatName,_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords);
}

function doSearchResultSort(sortType)
{
    //Use the "_last..." js variables to run a new query, but send this new sortType
    //First set the sort type cookie,
    CurrentPage=1;
    _totalNumOfPages=0;
    LastPage=-1;
    
    
    var searchOptions = readCookie("searchOptions");
     var currentGroupResultYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentGroupResultYesNo = searchOptionsArray[1];
         createCookie("searchOptions",sortType+"|"+currentGroupResultYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",sortType+"|"+groupByCatYesNo,0);
        currentGroupResultYesNo=groupByCatYesNo;
    }
    
    if (currentGroupResultYesNo.toUpperCase()=="YES"){
        GetSearchResultsGroupedByCat(_lastCatIDArrayStr,_lastNumToTakeArrayStr,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",sortType,currentGroupResultYesNo);
    } else if (currentGroupResultYesNo.toUpperCase()=="NO") {
         
            $get('CurrentPageNum').value=CurrentPage;
         //$get("CurrentPage").innerHTML = 1;
         $get("NumPages").innerHTML = 1;
         GetSearchResultPagingNonCategory(CurrentPage,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",sortType,"onGetSearchResultPagingNonCategorySuccess");
              
    }
    
}

function doPagingSearchResultFromSourceSort(sortType,numOfPages)
{
    var searchOptions = readCookie("searchOptions");
    var currentGroupResultYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentGroupResultYesNo = searchOptionsArray[1];
         createCookie("searchOptions",sortType+"|"+currentGroupResultYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",sortType+"|"+groupByCatYesNo,0);
        currentGroupResultYesNo=groupByCatYesNo;
    }
    
    //Now do the sort for the paging view (from source result)
    initSearchFromSource(numOfPages,_lastSourceEntryID,_lastSourceIsOrg,_lastCatID,_lastCatName);
}

function doSearchResultFromSourceSort(sortType)
{
    //Use the "_last..." js variables to run a new query, but send this new sortType
    //First set the sort type cookie,
    
    var searchOptions = readCookie("searchOptions");
    var currGroupYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currGroupYesNo = searchOptionsArray[1];
         createCookie("searchOptions",sortType+"|"+currGroupYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",sortType+"|"+groupByCatYesNo,0);
        currGroupYesNo=groupByCatYesNo;
    }
    
     CurrentPage = 1;
            _totalNumOfPages = 0;
            
            //Check if the user wants the results grouped or not, take appropriate path
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                  GetResultsFromSourceGroupedByCat(_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",sortType,currGroupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
               
               //if the user doesn't want them grouped, initialize the paging right away
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;display:block;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>"
                html += "</div>";
                html += "<hr />";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchFromSourceNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                 html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousFromSourceNonCategoryPageClick()' disabled='disabled' class='cssTextButton'/>";
                html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextFromSourceNonCategoryPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
               // var blah = document.getElementById('PageView');
               
               //Get the current sort type from cookie and use that
                //if (currSortType==undefined || currSortType=="undefined") currSortType="Latest";
               //GetSearchResultPagingNonCategory(CurrentPage,org,continentCode,country,startDate,endDate,keywords,activeMode,currSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
               GetResultsFromSourcePagingNonCategory(CurrentPage,_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",sortType,"onGetResultsFromSourcePagingNonCategorySuccess");
               }
    
   // GetResultsFromSource(_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",sortType,currentGroupResultYesNo);

    
}
function userChangeStory(storyControl)
{
    if (storyControl!="pause" && storyControl!="play"){
          if (intervalID!=null){
             clearInterval(intervalID);
             intervalID=null;
          }
         
         changeStory(storyControl);
         
         if (isPaused==false){
            intervalID = setInterval("changeStory('forward');",8000);
         }
     }
     else if (storyControl=="pause") 
     {
        if (intervalID!=null){
             clearInterval(intervalID);
             intervalID=null;
          }
          var playOrPauseAnchor = $get("playOrPauseAnchor");
          var playOrPauseImg = $get("playOrPauseImg");
          
          playOrPauseAnchor.href = "javascript:userChangeStory('play');";
          playOrPauseImg.src = "Images/playStory.jpg";
         // playOrPauseImg.onmouseover = "javascript:this.src='Images/playStoryHover.jpg';";
         // playOrPauseImg.onmouseout = "javascript:this.src='Images/playStory.jpg';"; 
          playOrPauseImg.alt = "Play";
          playOrPauseImg.title = "Play";
          isPaused=true;
     }
     else if (storyControl=="play")
     {
        if (intervalID!=null){
             clearInterval(intervalID);
             intervalID=null;
          }
            var playOrPauseAnchor = $get("playOrPauseAnchor");
          var playOrPauseImg = $get("playOrPauseImg");
          
          playOrPauseAnchor.href = "javascript:userChangeStory('pause');";
          playOrPauseImg.src = "Images/pauseStory.jpg";
         // playOrPauseImg.onmouseover = "rollOverPlayImg('playOrPauseImg','Images/pauseStoryHover.jpg');";
         // playOrPauseImg.onmouseout = "javascript:this.src='Images/pauseStory.jpg';"; 
           playOrPauseImg.alt = "Pause";
           playOrPauseImg.title = "Pause";
          intervalID = setInterval("changeStory('forward');",8000);
          isPaused=false;
     }
}
function rollOutPlayPause(img)
{
    if (isPaused) {
        img.src = "Images/playStory.jpg";
    }else {
        img.src = "Images/pauseStory.jpg";
    }
}

function rollOverPlayPause(img)
{
    if (isPaused) {
        img.src = "Images/playStoryHover.jpg";
    }else {
        img.src = "Images/pauseStoryHover.jpg";
    }
}
function changeStory(backOrForward)
{
    //Set the global storyIndex, and make it wrap around if they click many times one way or the other
    if (backOrForward.toUpperCase()=="BACK")
    {
        if (storyIndex==0)
        {
            storyIndex=storyCache.length-1;
            
        }
        else
        {
            storyIndex--;
        }
    } 
    else if (backOrForward.toUpperCase()=="FORWARD")
    {
        if (storyIndex == storyCache.length -1 )
        {
            storyIndex=0;
        }
        else
        {
            storyIndex++;
        }
    }
    
    //Change the story html
    var storyDiv = document.getElementById("storyDiv");
    var statusDiv = $get("currentStoryIndexText");
    if (statusDiv!=null){
    statusDiv.innerHTML = (storyIndex+1) + " of " + storyCache.length;
    }
//alert(storyIndex +" of " + storyCache.length);
    if (storyDiv != null)
    {
        document.getElementById("storyDiv").innerHTML= storyCache[storyIndex];
    }
}

function doTopicSearch(searchStr,catID)
{
     if (searchStr!=""){
    
       //Search parameters have been validated...so set the mode to be search results, and then...
        setMode("SEARCHRESULTS",true);
        //showMainLoading("Searching Entries, one moment...");
        //Make the call to the webservice to get the search results
        var catIDArray = new Array();
        catIDArray[0] = catID;
        
        var numToTakeArray = new Array();
        numToTakeArray[0] = 7;
        
        var org = -1;
        var continentCode ="";
        var country = -1;
        var startDate = "";
        var endDate = "";
        var keywords =searchStr;
        
           var catStr = catIDArray.join("|");
         var numToTakeStr = numToTakeArray.join("|");
         
         //Get sort type and group setting from cookie
         var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
         GetSearchResultsGroupedByCat(catStr,numToTakeStr,org,continentCode,country,startDate,endDate,keywords,"SEARCHRESULTS",currSortType,currGroupYesNo);
    } else {
      
         var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>No Search Words!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;You must enter a search word/phrase.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,160);
         
    }
}

function discussionTopicSort(sortType)
{
    //alert(sortType);
    Climate1StopWebService.GetDiscussionList(sortType,onGetDiscussionListSuccess,onGetDiscussionListFail);
    //$get("sortedDiscussions").innerHTML = "blah blah";
}

function doAddDiscussion(discussionTitle)
{
    if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
        $get("AddDiscussionButton").disabled = true;
        if (discussionTitle!="") {
            Climate1StopWebService.AddDiscussionEntry(discussionTitle,onAddDiscussionSuccess,onAddDiscussionFail);
        } else {
            $get("AddDiscussionButton").disabled = false;
            var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>No Topic Specified!</p><br/>";
             messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;You must specify a topic/title for your discussion.&nbsp;</p>";
             messageHTML += "<br/>";
             messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
             //validateHTML+= "</div>";
             
             displayStaticMessage(messageHTML,false,370,160);
        }
         
    } else {
         notLoggedInMessage("You must be logged in start a discussion topic.");
    }
   
}

function notifyUserOfEntryComment(notifyUserBool,entryID)
{
     Climate1StopWebService.NotifyUserWhenCommentAdded(entryID,notifyUserBool,onNotifyUserCheckSuccess,onNotifyUserCheckFail,notifyUserBool);
}



//User is paging to a previous page
function onPreviousPageClick()
{

    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
 
    if (CurrentPage > 1)
       {
       PageBuffer_Next = $get('PageView').innerHTML;
       $get('PageView').innerHTML = PageBuffer_Prev;
    
       CurrentPage--;
       $get('CurrentPageNum').value=CurrentPage;
      // $get('CurrentPage').innerHTML = CurrentPage;    
       
          var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 var currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
            }
            
            showPagingProgress("Processing...");
          GetCategorySearchResultPage((CurrentPage-1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchPreviousPage");
    
          //ret = PageFetch.GetPage(ArticleNo, (CurrentPage-1), OnCompletePrev, OnTimeOutPrev, OnErrorPrev);              
         // $get('previousPageButton').disabled = false;
          
       } 
     else
       {
        $get('nextPageButton').disabled = false;
       } 

}

function onNextPageClick()
{

    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    if (CurrentPage != LastPage)     
       {   
           PageBuffer_Prev = $get('PageView').innerHTML;
           $get('PageView').innerHTML = PageBuffer_Next;

           CurrentPage++;
         $get('CurrentPageNum').value=CurrentPage;
          // $get('CurrentPage').innerHTML = CurrentPage;
           
           //Get search info cookie option
           var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
            
            showPagingProgress("Processing...");
           GetCategorySearchResultPage((CurrentPage+1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchNextPage");
    
       }
//    else
//       {
//        $get('previousPageButton').disabled = false;
//       }   

}

//User is paging to a previous page
function onPreviousNonGroupedPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
 
    if (CurrentPage > 1)
       {
       PageBuffer_Next = $get('PageView').innerHTML;
       $get('PageView').innerHTML = PageBuffer_Prev;
    
       CurrentPage--;
       $get('CurrentPageNum').value=CurrentPage;
     //  $get('CurrentPage').innerHTML = CurrentPage;    
       
          var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 var currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
            }
            
            showPagingProgress("Processing...");
             GetSearchResultPagingNonCategory((CurrentPage-1),_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currentSortType,"onGetSearchNonCategoryGroupPreviousPage");
          //GetCategorySearchResultPage((CurrentPage-1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchPreviousPage");
    
          //ret = PageFetch.GetPage(ArticleNo, (CurrentPage-1), OnCompletePrev, OnTimeOutPrev, OnErrorPrev);              
        //  $get('previousPageButton').disabled = false;
            
           
       } 
     else
       {
        $get('nextPageButton').disabled = false;
       } 

}

function onNextNonGroupedPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    if (CurrentPage != LastPage)     
       {   
           PageBuffer_Prev = $get('PageView').innerHTML;
           $get('PageView').innerHTML = PageBuffer_Next;

           CurrentPage++;
     
             $get('CurrentPageNum').value=CurrentPage;
           //$get('CurrentPage').innerHTML = CurrentPage;
           
           //Get search info cookie option
           var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
            
            showPagingProgress("Processing...");
            GetSearchResultPagingNonCategory((CurrentPage+1),_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currentSortType,"onGetSearchNonCategoryGroupNextPage");
         
          // GetCategorySearchResultPage((CurrentPage+1),_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetSearchNextPage");
    
       }
//    else
//       {
//        $get('previousPageButton').disabled = false;
//       }   

}

//User is paging to a previous page
function onPreviousSrcResultPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
 
    if (CurrentPage > 1)
       {
       PageBuffer_Next = $get('PageView').innerHTML;
       $get('PageView').innerHTML = PageBuffer_Prev;
    
       CurrentPage--;
       $get('CurrentPageNum').value=CurrentPage;
       //$get('CurrentPage').innerHTML = CurrentPage;    
   
          
          var searchOptions = readCookie("searchOptions");
            var currentSortType="";
             var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
            
            showPagingProgress("Processing...");
          GetCategorySourceSearchResultPage((CurrentPage-1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchPreviousPage");
    
    
          //ret = PageFetch.GetPage(ArticleNo, (CurrentPage-1), OnCompletePrev, OnTimeOutPrev, OnErrorPrev);              
         // $get('previousPageButton').disabled = false;       
       } 
     else
       {
        $get('nextPageButton').disabled = false;
       } 

}



function onNextSrcResultPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    if (CurrentPage != LastPage)     
       {   
           PageBuffer_Prev = $get('PageView').innerHTML;
           $get('PageView').innerHTML = PageBuffer_Next;

           CurrentPage++;
           
            $get('CurrentPageNum').value=CurrentPage;
           //$get('CurrentPage').innerHTML = CurrentPage;
           
           //Get search info cookie option
           var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
       
       showPagingProgress("Processing...");
          GetCategorySourceSearchResultPage((CurrentPage+1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchNextPage");
    
       }
//    else
//       {
//        $get('previousPageButton').disabled = false;
//       }   

}


//User is paging to a previous page
function onPreviousFromSourceNonCategoryPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
 
    if (CurrentPage > 1)
       {
       PageBuffer_Next = $get('PageView').innerHTML;
       $get('PageView').innerHTML = PageBuffer_Prev;
    
       CurrentPage--;
        $get('CurrentPageNum').value=CurrentPage;
      // $get('CurrentPage').innerHTML = CurrentPage;    
      
          var searchOptions = readCookie("searchOptions");
            var currentSortType="";
             var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
            
            
            showPagingProgress("Processing...");
             GetResultsFromSourcePagingNonCategory((CurrentPage-1),_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,"onGetResultsFromSourcePagingNonCategoryPreviousPage");
         // GetResultsFromSourcePagingNonCategory((CurrentPage-1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchPreviousPage");
    
    
          //ret = PageFetch.GetPage(ArticleNo, (CurrentPage-1), OnCompletePrev, OnTimeOutPrev, OnErrorPrev);              
         // $get('previousPageButton').disabled = false;
        
       } 
     else
       {
        $get('nextPageButton').disabled = false;
       } 

}



function onNextFromSourceNonCategoryPageClick()
{
    $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    if (CurrentPage != LastPage)     
       {   
           PageBuffer_Prev = $get('PageView').innerHTML;
           $get('PageView').innerHTML = PageBuffer_Next;

           CurrentPage++;
      $get('CurrentPageNum').value=CurrentPage;
         //  $get('CurrentPage').innerHTML = CurrentPage;
           
           //Get search info cookie option
           var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            var currentGroupYesNo="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
                 currentGroupYesNo=groupByCatYesNo;
            }
       
       showPagingProgress("Processing...");
       
        GetResultsFromSourcePagingNonCategory((CurrentPage+1),_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currentSortType,"onGetResultsFromSourcePagingNonCategoryNextPage");
        
         //  GetSourceSearchResultPage((CurrentPage+1),_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currentSortType,"onGetSourceSearchNextPage");
    
       }
//    else
//       {
//        $get('previousPageButton').disabled = false;
//       }   

}

function initSearchFromSource(numOfPages,sourceEntryID,isOrg,categoryID,catName)
{
   CurrentPage=1;
   LastPage=-1;
   
    _lastSourceEntryID=sourceEntryID;
    _lastSourceIsOrg=isOrg;
    _lastCatID=categoryID;
    _lastCatName = catName;
    _totalNumOfPages=numOfPages;
    
    var html = "";
    
//   var loadingHTML = "<div id='loadingSearch' style=\"text-align:left;vertical-align:middle;font-size:13px;color:Blue;width:100%;height:100%;\">";
//    loadingHTML += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"display:inline-table;vertical-align:middle;\">Loading "+catName+ " entries...</b>";
//    loadingHTML += "</div>";
     //showMainLoading("Loading "+catName+" entries...");
    
    html += "<div id='PageView' style='width:100%;text-align:center;'><a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b></div>";
    html += "<hr />";
    html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
    html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
   html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchFromSourceCategory(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
   // html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
    html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
    html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>"+numOfPages+"</span><br/><br/>";
    html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousSrcResultPageClick();' disabled='disabled' class='cssTextButton'/>";
    html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextSrcResultPageClick();' class='cssTextButton'/>";
    html += "</div>"
    
    if (html!="")
    {
       // var middleSection = $find("topMiddleContentBehavior");
       // middleSection._childDiv.innerHTML = html;
          var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
          communityPanel.getBody().update(html);
    }
   // var blah = document.getElementById('PageView');
   
   //Get the current sort type from cookie and use that
    var searchOptions = readCookie("searchOptions");
    var currentSortType="";
    var currentGroupYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentSortType = searchOptionsArray[0];
         currentGroupYesNo=searchOptionsArray[1];
         createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
         currentSortType=entrySortType;
         currentGroupYesNo=groupByCatYesNo;
    }
    
    GetCategorySourceSearchResultPage(CurrentPage,categoryID,sourceEntryID,isOrg,activeMode,currentSortType,"onGetCategorySourceSearchResultPageSuccess");
    
}

function initSearchCategory(numOfPages,catName,categoryID,org,continentCode,country,startDate,endDate,keywords)
{
        
    //Set the current page to 1 to start off.
    CurrentPage=1;
    LastPage=-1;
    
    //Set the global variables, storing the information about the exact search.
     _lastCatName = catName;
     _lastCatID=categoryID;
     _lastOrgAffID=org;
     _lastContinentCode=continentCode;
     _lastCountryID=country;
     _lastStartDate=startDate;
     _lastEndDate=endDate;
     _lastKeywords=keywords;
     _totalNumOfPages=numOfPages;
    
    var html = "";
    
//   var loadingHTML = "<div id='loadingSearch' style=\"text-align:left;vertical-align:middle;font-size:13px;color:Blue;width:100%;height:100%;\">";
//    loadingHTML += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"display:inline-table;vertical-align:middle;\">Loading "+catName+ " entries...</b>";
//    loadingHTML += "</div>";
     //showMainLoading("Loading "+catName+" entries...");
    
    html += "<div id='PageView' style='width:100%;text-align:center;'><a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b></div>";
    html += "<hr />";
    html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
    html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
    html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchCategory(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
    //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
    html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
    html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>"+numOfPages+"</span><br/><br/>";
    html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousPageClick();' disabled='disabled' class='cssTextButton'/>";
    html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextPageClick();' class='cssTextButton'/>";
    html += "</div>"
    
    if (html!="")
    {
       // var middleSection = $find("topMiddleContentBehavior");
       // middleSection._childDiv.innerHTML = html;
          var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
          communityPanel.getBody().update(html);
    }
   // var blah = document.getElementById('PageView');
   
   //Get the current sort type from cookie and use that
    var searchOptions = readCookie("searchOptions");
    var currentSortType="";
    var currentGroupYesNo="";
    if (searchOptions !=null && searchOptions!=undefined){
         var searchOptionsArray = searchOptions.split("|");
         currentSortType = searchOptionsArray[0];
         currentGroupYesNo=searchOptionsArray[1];
         createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
         
    } else {
        //Just use the current sort type, and the hard coded groupyesno...
        createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
         currentSortType=entrySortType;
         currentGroupYesNo=groupByCatYesNo;
    }
    
   GetCategorySearchResultPage(CurrentPage,categoryID,org,continentCode,country,startDate,endDate,keywords,activeMode,currentSortType,"onGetCategorySearchResultPageSuccess");

    
}

function adminChangeEntryCategory(entryID,newCatID)
{
    Climate1StopWebService.ChangeEntryCat(entryID,newCatID,onChangeCatSuccess,onChangeCatFail,entryID);
}

function deleteEntry(entryID)
{
    Climate1StopWebService.DeleteEntry(entryID,onDeleteEntrySuccess,onDeleteEntryFail,entryID);
}

function confirmEntryDelete(entryID)
{
    confirmMessage("Are you sure you want to delete this entry?","deleteEntry("+entryID+");");
}

function removePic(entryID)
{
    Climate1StopWebService.RemoveProfilePicture(entryID,onRemoveProfilePicSuccess,onRemoveProfilePicFail,entryID);
}

function confirmRemovePic(entryID)
{
    confirmMessage("Are you sure you want to remove this picture?","removePic("+entryID+");");
}

//function searchCatByPage(pageNum,categoryID,org,continentCode,country,startDate,endDate,keywords)
//{
//    Climate1StopWebService.GetCategorySearchResultPage(pageNum,categoryID,org,continentCode,country,startDate,endDate,keywords,onServiceSuccess,onServiceFail,"topMiddleContentBehavior");
//}

function getPreviousResultsFromSource()
{
    var searchOptions = readCookie("searchOptions");
    var currSortType = "";
    var currGroupYesNo = "";
    if (searchOptions !=null && searchOptions!=undefined){
        var searchOptionArray = searchOptions.split("|");
        currSortType=searchOptionArray[0];
        currGroupYesNo=searchOptionArray[1];

    } else {
    //  alert("no cookie yet");
        createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
        currSortType=entrySortType;
        currGroupYesNo=groupByCatYesNo;
    }
    
    GetResultsFromSourceGroupedByCat(_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currSortType,currGroupYesNo);
}

function getPreviousResults()
{
//    _lastCatIDArrayStr = catStr;
//    _lastNumToTakeArrayStr = numToTakeStr
//    _lastOrgAffID=org;
//    _lastContinentCode=continentCode;
//    _lastCountryID=country;
//    _lastStartDate=startDate;
//    _lastEndDate=endDate;
//    _lastKeywords=keywords;
     
     
     //Get the sort type and group by preferences fromthe cookie...if not, then use defaults
      var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
         GetSearchResultsGroupedByCat(_lastCatIDArrayStr,_lastNumToTakeArrayStr,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currSortType,currGroupYesNo);
}

//Load the google search control infrastructure
google.load('search', '1'); 
//google.setOnLoadCallback(onGoogleLoad);

    function onGoogleLoad()
    {
        if (searchControl==null) searchControl = new google.search.SearchControl();
    }
    
   function showGoogleResults(phrase)
   {
   
        setMode("SEARCHRESULTS",true);
       var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
         
        searchControl = new google.search.SearchControl();
        
       
        searchControl.addSearcher(new google.search.WebSearch());
        searchControl.addSearcher(new google.search.VideoSearch());
        searchControl.addSearcher(new google.search.BlogSearch());  
        
         searchControl.setNoResultsString("No results found...");
        
        var drawOptions = new google.search.DrawOptions(); 
        drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 
       
        //communityPanel.body.dom;
       // communityPanel.body.dom.style.width="100%";
         searchControl.draw(communityPanel.body.dom,drawOptions);
    
    if (phrase=="") phrase=_lastKeywords;
    if (phrase=="") phrase="climate change";
       
//     if (_lastKeywords=="" || _lastKeywords==null || _lastKeywords==undefined) {
//        searchPhrase="climate change";
//     } else {
//        searchPhrase=_lastKeywords;
//     }
    searchControl.execute(phrase);
        
   }
//Do the google search...output to the div "search_control"
function initGoogleSearch()
{
     var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
     
    if (searchControl==null) searchControl = new google.search.SearchControl();
    
    searchControl.addSearcher(new google.search.WebSearch());
    searchControl.addSearcher(new google.search.VideoSearch());
    searchControl.addSearcher(new google.search.BlogSearch());  
    
    
    var drawOptions = new google.search.DrawOptions(); 
    drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 
   // var googleResultCache = document.getElementById("googleResultCache");
    
    var googleResultTab = communityPanel.findById("googleResultTab");
    var theGoogleTabElement = googleResultTab.body;
    theGoogleTabElement.update("");
  //   theGoogleTabElement.applyStyles({'background-color':"red"});
   //  theGoogleTabElement.applyStyles({'background-color':""});
     
   // theGoogleTabElement.applyStyles("background-color:red");
    var theGoogleTabElementDom = theGoogleTabElement.dom;
    //theGoogleTabElementDom.style.backgroundColor = "";
   
    
//    var climate1stopResultTab = communityPanel.findById("climate1stopResultTab");
//    var climate1stopTabElement = climate1stopResultTab.body;
//    var climate1stopTabElementDom = climate1stopTabElement.dom;
//    climate1stopTabElementDom.style.backgroundColor = "";
   
    searchControl.draw(theGoogleTabElementDom,drawOptions);
    
        var searchPhrase="";
     if (_lastKeywords=="" || _lastKeywords==null || _lastKeywords==undefined) {
        searchPhrase="climate change";
     } else {
        searchPhrase=_lastKeywords;
     }
    searchControl.execute(searchPhrase);
    //setTimeout("alert(document.getElementById('googleResultCache').innerHTML);",6000);
   // addTab(searchResultTabsPanel,"googleResultTab","Google Results",googleResultCache.innerHTML);
    
//    //First add a tab to the search result tab panel
//    addTab(searchResultTabsPanel,"googleResultTab","Google Results");
//    
//    searchResultTabsPanel.doLayout();
//     //refresh the layout.
//     communityPanel.autoScroll=false;
//     communityPanel.doLayout();
//    
//    
     //   var googleResultTab = communityPanel.findById("googleResultTab");
        //googleResultTab.html = googleResultCache.innerHTML;
    //    googleResultTab.getBody().update(googleResultCache.innerHTML);
   //      communityPanel.doLayout();
        //googleResultTab.getBody().update(googleResultCache.innerHTML);
        
        //googleResultTab.getBody().update(googleResultCache.innerHTML);
//    googleResultTab.getBody().update("");
//    googleResultTab.getBody().update("dude");
//    googleResultTab.doLayout();
//     var theElement = googleResultTab.getEl();
//    
//    
//    searchControl.draw(theElement, drawOptions);
//                
//                
//    var searchPhrase="";
//     if (_lastKeywords=="" || _lastKeywords==null || _lastKeywords==undefined) {
//        searchPhrase="climate change";
//     } else {
//        searchPhrase=_lastKeywords;
//     }
//    searchControl.execute(searchPhrase); 
    
}


function doGoogleSearch()
{
    if (searchControl==null) searchControl = new google.search.SearchControl();
    
    searchControl.addSearcher(new google.search.WebSearch());
    searchControl.addSearcher(new google.search.VideoSearch());
    searchControl.addSearcher(new google.search.BlogSearch());  
    
    
    var drawOptions = new google.search.DrawOptions(); 
    drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 
    
    searchControl.draw(theElement, drawOptions);
    var searchPhrase="";
     if (_lastKeywords=="" || _lastKeywords==null || _lastKeywords==undefined) {
        searchPhrase="climate change";
     } else {
        searchPhrase=_lastKeywords;
     }
    searchControl.execute(searchPhrase);
}


function validateSearch()
{
    //Disable the search button
    //$get("mainSearchButton").disabled=true;
    
    var isOk=true;
    var catCheck=false;
    //var categoriesStr="";
    // var numToTakeFromCatsStr="";
    var organizationID=-1;
    //var continentCodeArray=new Array();
    var continentCode="";
    var countryID=-1;
    var startDate="";
    var endDate="";
    var keywords="";
    
   var  validateHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Search Criteria Problem</p><br/>";
         validateHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Please fix the following items:&nbsp;<img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
         validateHTML += "<ul style='text-indent:25px;text-align:left;font-family:Verdana,Arial;font-size:10px;color:navy;'>";
    
     //The rest
	    var orgBox = $get("ctl00_MainContentPlaceHolder_OrgAffiliation");
        //var orgAffiliation = $get("ctl00_OrgAffiliation").value;
        var org = parseInt(orgBox.options[orgBox.selectedIndex].value);
      //  var orgAffiliation = selOrg.options[selOrg.selectedIndex].value;
        
        var selContinent = document.getElementById("selContinent");
        var continent = selContinent.options[selContinent.selectedIndex].value;
        if (continent.toUpperCase()=="DEFAULT"){
        continentCode="";
        //    var continentOptions = $get("selContinent").options;
         //   for (var i=0;i<continentOptions.length;i++) {
         //       continentCodeArray[continentCodeArray.length] = continentOptions[i].value;
         //   }
        } else {
            continentCode=continent;
        }
        
        var selCountry = document.getElementById("selCountry");
        var country = parseInt(selCountry.options[selCountry.selectedIndex].value);
        
       // if (country!=-1) continentCodeArray[0]="null";
        
        var startDate = document.getElementById("startDate").value;
        var endDate = document.getElementById("endDate").value;
        var keywords = document.getElementById("entryKW").value;
    
    //Categories
    var categories = document.getElementsByName("CategoryChkBox");
     var categoryIDArray = new Array();
     //Default number of each category to get
     var numToTakeArray = new Array();
    
     
     //Check to see if all are selected
        for (var i=0;i<categories.length;i++)
        {
            //Add all of the entry IDs into an array, then send to them to the server for deletion.
            if (categories[i].checked==true){
                catCheck=true;
                //categoriesStr += categories[i].value+",";
                //numToTakeFromCatsStr+= numToTakeFromCatsStr=5 + ",";
                categoryIDArray[categoryIDArray.length]=categories[i].value;
                numToTakeArray[numToTakeArray.length]=5;
            }
        
        }
        
        if (catCheck){
           // categoriesStr = categoriesStr.substring(0,categoriesStr.length-1);
            //numToTakeFromCatsStr = numToTakeFromCatsStr.substring(0,numToTakeFromCatsStr.length-1);
        } else {
            isOk=false;
             validateHTML+= "<li>At least 1 checkbox must be checked (Step 1)</li>";
        }
        
        if (startDate!="" && endDate!=""){
            
            var sDateObj = Date.parse(startDate);
            var eDateObj = Date.parse(endDate);
            if (sDateObj>eDateObj) {
                isOk=false;
                validateHTML+= "<li>Start Date must be before End Date</li>";
            }
        }
        
         validateHTML+= "</ul><br/>";
         validateHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
    
    //------------------------------------------------------------------------------------------------
    if (isOk){
    
       //Search parameters have been validated...so set the mode to be search results, and then...
        setMode("SEARCHRESULTS",true);
       // showMainLoading("Searching Entries, one moment...");
        //Make the call to the webservice to get the search results
        
        
         //Keep the last searched parameters for sorting,etc (not the lastCatID, which is specifically for grouped searches, that will be stored when someone
        //(who is viewing a grouped sort) clicks the "more" button and starts paging through them.
        var catStr = categoryIDArray.join("|");
        var numToTakeStr = numToTakeArray.join("|");
                
        
        CurrentPage=1;
        LastPage=-1;
        
         _lastCatIDArrayStr = catStr;
         _lastNumToTakeArrayStr = numToTakeStr
        _lastOrgAffID=org;
     _lastContinentCode=continentCode;
     _lastCountryID=country;
     _lastStartDate=startDate;
     _lastEndDate=endDate;
     _lastKeywords=keywords;
     
       _totalNumOfPages=0;
     //Get the sort type and group by preferences fromthe cookie...if not, then use defaults
      var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                GetSearchResultsGroupedByCat(catStr,numToTakeStr,org,continentCode,country,startDate,endDate,keywords,"SEARCHRESULTS",currSortType,currGroupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
               
               //if the user doesn't want them grouped, initialize the paging right away
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>";
                html += "</div>";
                html += "<hr />";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousNonGroupedPageClick();' disabled='disabled' class='cssTextButton'/>";
                html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextNonGroupedPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
               // var blah = document.getElementById('PageView');
               
               //Get the current sort type from cookie and use that
//                var searchOptions = readCookie("searchOptions");
//                var currentSortType="";
//                var currentGroupYesNo="";
//                if (searchOptions !=null && searchOptions!=undefined){
//                     var searchOptionsArray = searchOptions.split("|");
//                     currentSortType = searchOptionsArray[0];
//                     currentGroupYesNo=searchOptionsArray[1];
//                     createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
//                     
//                } else {
//                    //Just use the current sort type, and the hard coded groupyesno...
//                    createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
//                     currentSortType=entrySortType;
//                     currentGroupYesNo=groupByCatYesNo;
//                }
                
               GetSearchResultPagingNonCategory(CurrentPage,org,continentCode,country,startDate,endDate,keywords,activeMode,currSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
                
            }
    } else {
      
         //validateHTML+= "</div>";
       //  $get("mainSearchButton").disabled=false;
         displayStaticMessage(validateHTML,false,370,225);
         return false;
    }
   
}

function validateSimpleSearch()
{
    //Disable the search button
    //$get("mainSearchButton").disabled=true;
    
    var isOk=true;
    var catCheck=false;
    //var categoriesStr="";
    // var numToTakeFromCatsStr="";
    var organizationID=-1;
    //var continentCodeArray=new Array();
    var continentCode="";
    var countryID=-1;
    var startDate="";
    var endDate="";
    var keywords="";
    
   var  validateHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Search Criteria Problem</p><br/>";
         validateHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Please fix the following items:&nbsp;<img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
         validateHTML += "<ul style='text-indent:25px;text-align:left;font-family:Verdana,Arial;font-size:10px;color:navy;'>";
    
    
        var org = -1;
        continentCode="";
        //    var continentOptions = $get("selContinent").options;
         //   for (var i=0;i<continentOptions.length;i++) {
         //       continentCodeArray[continentCodeArray.length] = continentOptions[i].value;
         //   }
        
    
        var country = -1;
        
       // if (country!=-1) continentCodeArray[0]="null";
        
        var startDate = "";
        var endDate = "";
        var keywords = document.getElementById("entryKWSimple").value;
    
    //Categories
    var categories = document.getElementsByName("CategoryChkBox");
     var categoryIDArray = new Array();
     //Default number of each category to get
     var numToTakeArray = new Array();
    
     
     //Check to see if all are selected
        for (var i=0;i<categories.length;i++)
        {
            //Add all of the entry IDs into an array, then send to them to the server for deletion.
                categoryIDArray[categoryIDArray.length]=categories[i].value;
                numToTakeArray[numToTakeArray.length]=5;        
        }
       
         validateHTML+= "</ul><br/>";
         validateHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
    
    //prepareTabsForDoubleSearch();
    if (isOk){
    
       //Search parameters have been validated...so set the mode to be search results, and then...
        setMode("SEARCHRESULTS",true);
       // showMainLoading("Searching Entries, one moment...");
        //Make the call to the webservice to get the search results
        
        //  _lastCatID=categoryID;
        //Keep the last searched parameters for sorting,etc (not the lastCatID, which is specifically for grouped searches, that will be stored when someone
        //(who is viewing a grouped sort) clicks the "more" button and starts paging through them.
          var catStr = categoryIDArray.join("|");
        var numToTakeStr = numToTakeArray.join("|");
        
        CurrentPage=1;
        LastPage=-1;
        
         _lastCatIDArrayStr = catStr;
         _lastNumToTakeArrayStr = numToTakeStr
     _lastOrgAffID=org;
     _lastContinentCode=continentCode;
     _lastCountryID=country;
     _lastStartDate=startDate;
     _lastEndDate=endDate;
     _lastKeywords=keywords;
     
      _totalNumOfPages=0;
     //_totalNumOfPages=numOfPages;
     
     //Get group by and sort type settings from cookie...otherwise use defaults
      var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                GetSearchResultsGroupedByCat(catStr,numToTakeStr,org,continentCode,country,startDate,endDate,keywords,"SEARCHRESULTS",currSortType,currGroupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
               
               //if the user doesn't want them grouped, initialize the paging right away
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;display:block;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>"
                html += "</div>";
                html += "<hr />";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                 html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousNonGroupedPageClick();' disabled='disabled' class='cssTextButton'/>";
                html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextNonGroupedPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
               // var blah = document.getElementById('PageView');
               
               //Get the current sort type from cookie and use that
                //if (currSortType==undefined || currSortType=="undefined") currSortType="Latest";
               GetSearchResultPagingNonCategory(CurrentPage,org,continentCode,country,startDate,endDate,keywords,activeMode,currSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
                
            }
        // GetSearchResults(catStr,numToTakeStr,org,continentCode,country,startDate,endDate,keywords,"SEARCHRESULTS",currSortType,currGroupYesNo);
    } else {
      
         //validateHTML+= "</div>";
       //  $get("mainSearchButton").disabled=false;
         displayStaticMessage(validateHTML,false,370,225);
         return false;
    }
   
}

//function prepareTabsForDoubleSearch()
//{
////Clear the content first,
//    var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
//    communityPanel.getBody().update("");
//    
//    //Create a tab panel with 2 search result tabs
//    tabs = new Ext.TabPanel({
//    renderTo: communityPanel.getBody(),
//    activeTab: 0,
//    xtype: 'tabpanel',
//    id:"searchResultTabPanel",
//    items: [{
//        title: 'Climate 1-Stop Results',
//        html: 'Searching Climate 1-Stop...',
//        id: 'climate1stopResultTab',
//        layout: 'fit'
//    },{
//        title: 'Google Results',
//        html: 'Google Results Processing...',
//        id: 'googleResultTab',
//        layout: 'fit'
//    }]
//});

////var tabs = new Ext.TabPanel("tabs1");
////tabs.addTab("script", "View Script");
////tabs.addTab("markup", "View Markup");
////tabs.renderTo: "ctl00_MainContentPlaceHolder_CommunityPane
////tabs.activate("script");

////add the tab panel to the community panel
//communityPanel.add(tabs);
// 
// //refresh the layout.
// communityPanel.doLayout();
//}

//function addTab(tabPanel, id, name,theHTML) {
//            var tab = tabPanel.getComponent(id);

//            if (!tab) {
//                tab = tabPanel.add({ 
//                    id       : id, 
//                    title    : name, 
//                    closable : true,
//                    autoScroll:true,
//                    html :"doody dum"                
////                    autoLoad : {
////                        showMask : true,
////                        url      : url,
////                        mode     : "iframe",
////                        maskMsg  : "Loading google results..."
////                    }                    
//                });

////                tab.on("activate", function () {
////                    var item = MenuPanel1.menu.items.get(id + "_item");
////                    
////                    if (item) {
////                        MenuPanel1.setSelection(item);
////                    }
////                }, this);
//            }
//            
//            //tabPanel.setActiveTab(tab);
//        }

function getAllEntriesForUserOrOrg (entryID,isOrg)
{
    //Search parameters have been validated...so set the mode to be search results, and then...
        setMode("SEARCHRESULTS",true);
      //  showMainLoading("Searching Entries, one moment...");
        //Make the call to the webservice to get the search results
        
         var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
            _lastSourceEntryID=entryID;
            _lastSourceIsOrg=isOrg;
            
            //reset paging variables
            CurrentPage = 1;
            _totalNumOfPages = 0;
            
            //Check if the user wants the results grouped or not, take appropriate path
            if (currGroupYesNo.toUpperCase()=="YES")
            {
                  GetResultsFromSourceGroupedByCat(entryID,isOrg,"SEARCHRESULTS",currSortType,currGroupYesNo);
            } 
            else if(currGroupYesNo.toUpperCase()=="NO")
            {
               
               //if the user doesn't want them grouped, initialize the paging right away
                var html = "";
    
                html += "<div id='PageView' style='width:100%;text-align:center;display:block;'>&nbsp;";
                html += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline-block;vertical-align:middle;\">Sorting Entries...</b>"
                html += "</div>";
                html += "<hr />";
                html += "<div style='padding-top:7px;width:100%;text-align:center;vertical-align:middle;'>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'>Page </span>";
                html += "<input type='text' id='CurrentPageNum' name='CurrentPageNum' onkeypress='checkEnterPageSwitchFromSourceNonGrouped(event);' style='vertical-align:middle;font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:right;width:30px;font-weight:bold;' value='"+CurrentPage+"' />";
                //html += "<span id='CurrentPage' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;'>"+CurrentPage+"</span>";
                html += "<span style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;vertical-align:middle;'> of </span>";
                html += "<span id='NumPages' style='font-size:Medium;font-family:Calibri,Verdana,Arial;text-align:center;width:100%;font-weight:bold;vertical-align:middle;'>1</span><br/><br/>";
                 html += "<input id='previousPageButton' type='button' value='Previous' onclick='onPreviousFromSourceNonCategoryPageClick()' disabled='disabled' class='cssTextButton'/>";
                html += "&nbsp;&nbsp;<input id='nextPageButton' type='button' value='Next' onclick='onNextFromSourceNonCategoryPageClick();' class='cssTextButton'/>";
                html += "</div><br/>"
                
                if (html!="")
                {
                   // var middleSection = $find("topMiddleContentBehavior");
                   // middleSection._childDiv.innerHTML = html;
                      var communityPanel = Ext.getCmp("ctl00_MainContentPlaceHolder_CommunityPanel");
                      communityPanel.getBody().update(html);
                }
               // var blah = document.getElementById('PageView');
               
               //Get the current sort type from cookie and use that
                //if (currSortType==undefined || currSortType=="undefined") currSortType="Latest";
               //GetSearchResultPagingNonCategory(CurrentPage,org,continentCode,country,startDate,endDate,keywords,activeMode,currSortType,"onGetSearchResultPagingNonCategorySuccess");
                //end intialize paging for non-grouped by category results
               GetResultsFromSourcePagingNonCategory(CurrentPage,entryID,isOrg,"SEARCHRESULTS",currSortType,"onGetResultsFromSourcePagingNonCategorySuccess");
            }
            
       
    
}

function clickCategoryBox(bmChkbox)
{
     var bookmarks = document.getElementsByName("CategoryChkBox");
     var bookmarkIDArray = new Array();
     var allChecked,allNotChecked;
     var selAllBox = document.getElementById("chkAll");
     
     //Check to see if all are selected
        for (var i=0;i<bookmarks.length;i++)
        {
            //Add all of the entry IDs into an array, then send to them to the server for deletion.
            if (bookmarks[i].checked==true){
                allChecked=true;
            } else {
                allChecked=false;
                break;
            }
        }
        if (allChecked) {
            selAllBox.checked=true;
        } else {
            selAllBox.checked=false;
        }
}

function selectAllCategories()
{
//    var chkboxGroup = Ext.getCmp("chkAll");
//    var categoryBoxes = chkboxGroup.items;
//    
//    for (var i=0;i<categoryBoxes.length;i++)
//    {
//        var chkBox = categoryBoxes.items[i];
//        
//        categoryBoxes[i].setValue("true");
//    }
    //var selAllChkBox = document.getElementById("chkAll");
   
     var bookmarks = document.getElementsByName("CategoryChkBox");
      var selAllChkBox = document.getElementById("chkAll");
        if (bookmarks.length!=0){
            for (var i=0;i<bookmarks.length;i++)
            {
                if (selAllChkBox.checked==true){
                    bookmarks[i].checked=true;
                } else {
                    bookmarks[i].checked =false;
                }
            }
        }
}


function validateSendMessage(msg,entryID,recipientUserID)
{
    if (msg!="") {
        sendMessage(msg,recipientUserID,"sendMessageArea"+entryID,entryID);
        //closeMessage();
        //return false;
    } else {
         var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Empty Message!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/redX.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Empty Messages are not permitted, please type your message and hit the Send button.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         displayStaticMessage(messageHTML,false,370,160);
         
        //alert("Your message is empty, please type your message and hit the Send button.");
        return true;
        $get("sendMessageArea"+entryID).focus();
       
    }
}

function sendMessage(msg,recipientUserID,msgTextBoxID,entryID)
{
    Climate1StopWebService.SendMessageToUser(msg,recipientUserID,entryID,onSendMessageSuccess,onSendMessageFail,msgTextBoxID);
}

function groupBookmarks(grouped)
{
    if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
        Climate1StopWebService.GroupBookmarks(grouped,onGroupBookmarkSuccess,onGroupBookmarkFail,"");
    } 
}


function deleteBookmarks(refreshToolsArea){

 if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
    //if (refreshToolsArea) refreshToolsTab=true;
         var bookmarks = document.getElementsByName("bookmarkCheck");
         var bookmarkIDArray = new Array();
         if (bookmarks.length!=0){
         //alert(bookmarks.length);
            for (var i=0;i<bookmarks.length;i++)
            {
                //Add all of the entry IDs into an array, then send to them to the server for deletion.
                if (bookmarks[i].checked==true){
                    var valueParts = bookmarks[i].value.split("|");
                    bookmarkIDArray[bookmarkIDArray.length] = valueParts[1];
                    
                }
           }
           var selAllBox = $get("bookmarkAllCheck");
           if (selAllBox.checked){
               confirmMessage("Are you sure you want to delete all bookmarks?","deleteAllBookmarks();");
            } else {
                Climate1StopWebService.DeleteBookmarks(bookmarkIDArray,onDeleteBookmarksSuccess,onDeleteBookmarksFail,bookmarkIDArray);
            }
        }
  } else {
  //notLoggedInMessage("
  }
}
function deleteAllBookmarks()
{
var bookmarks = document.getElementsByName("bookmarkCheck");
         var bookmarkIDArray = new Array();
         if (bookmarks.length!=0){
         //alert(bookmarks.length);
            for (var i=0;i<bookmarks.length;i++)
            {
                //Add all of the entry IDs into an array, then send to them to the server for deletion.
                var valueParts = bookmarks[i].value.split("|");
                bookmarkIDArray[bookmarkIDArray.length] = valueParts[1];
           }
           Climate1StopWebService.DeleteBookmarks(bookmarkIDArray,onDeleteBookmarksSuccess,onDeleteBookmarksFail,bookmarkIDArray);
         }
         
}

function clickBookmark(bmChkbox)
{
     var bookmarks = document.getElementsByName("bookmarkCheck");
     var bookmarkIDArray = new Array();
     var allChecked,allNotChecked;
     var selAllBox = $get("bookmarkAllCheck");
     
     //Check to see if all are selected
        for (var i=0;i<bookmarks.length;i++)
        {
            //Add all of the entry IDs into an array, then send to them to the server for deletion.
            if (bookmarks[i].checked==true){
                allChecked=true;
            } else {
                allChecked=false;
                break;
            }
        }
        if (allChecked) {
            selAllBox.checked=true;
        } else {
            selAllBox.checked=false;
        }
}

function selectAllBookmarks(selAllChkBox) {
    var bookmarks = document.getElementsByName("bookmarkCheck");
    if (bookmarks.length!=0){
        for (var i=0;i<bookmarks.length;i++)
        {
            if (selAllChkBox.checked==true){
                bookmarks[i].checked=true;
            } else {
                bookmarks[i].checked =false;
            }
        }
    }
    


}
//var refreshToolsTab=false;
function bookmarkEntry(entryID,refreshToolsArea)
{
if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
   // if (refreshToolsArea) refreshToolsTab=true;
    var loadingMsg = "<div style=\"text-align:left;vertical-align:middle;font-size:13px;color:Blue;width:100%;height:100%;\">";
        loadingMsg += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"display:inline-table;vertical-align:middle;\">Updating Bookmarks...</b>";
        loadingMsg += "</div>";
        
         //topRightCP = $find("rightTopContentBehaviorID");
          //topRightCP._childDiv.innerHTML = loadingMsg;
          Climate1StopWebService.BookmarkEntry(entryID,onBookmarkEntrySuccess,onBookmarkEntryFail,entryID);
         
    } else {
         notLoggedInMessage("You must be logged in to bookmark entries");
    }
}

function doEntryFeedback(entryID,feedbackType)
{
    
    if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
        if (feedbackType.toUpperCase()=="REPORT"){
             var commentHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Flag this entry!</p><br/>";
            commentHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/galf.png' style='width:35px;height:35px;vertical-align:middle;'/>&nbsp;Reason for reporting this entry:&nbsp;<img src='Images/galf.png' style='width:35px;height:35px;vertical-align:middle;'/></p>"
            commentHTML += "<br/>";
            commentHTML += "<div style='text-align:center;padding-left:10px;padding-right:10px;'>";
                commentHTML += "<textarea id='entryReportTextArea' name='entryCommentTextArea' style='width:100%;font-size:small;font-family:Calibri,Verdana,Arial;' rows='4' onKeyDown='limitText($get(\"entryReportTextArea\"),$get(\"entryReportCountdown\"),250);'";
                commentHTML += " onKeyUp='limitText($get(\"entryReportTextArea\"),$get(\"entryReportCountdown\"),250);'></textarea>";
                commentHTML += "</div>";
                commentHTML += "<div style='text-align:left;padding-left:10px;padding-right:10px;'>";
                commentHTML += "<font size='1'>You have <input readonly type='text' style='margin-top:4px;margin-bottom:4px;' id='entryReportCountdown' name='entryReportCountdown' size='2' value='250'> characters left.</font>";
                commentHTML += "</div><br/>";         
            commentHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='validateReportReason($get(\"entryReportTextArea\").value,\""+feedbackType+"\","+entryID+");' class='cssTextButton'/>&nbsp;&nbsp;<input type='button' value='Cancel' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
            //validateHTML+= "</div>";
            displayStaticMessage(commentHTML,false,370,265);
            //messageObj.onmouseover = mouseoverMessageObj;
            //alert("focussing");
            $get("entryReportTextArea").focus();
        } else {
            Climate1StopWebService.SubmitEntryFeedback(entryID,feedbackType,null,onSubmitFeedbackSuccess,onSubmitFeedbackFail,entryID);
        }
    } else {
       notLoggedInMessage("You must be logged in to submit feedback");
    }
    //Message the user that they may only provide feedback if they're logged in.
}

function validateReportReason(reason,feedbackType,entryID)
{
    if (reason!="") {
        reportEntry(reason,feedbackType,entryID);
        closeMessage();
        return false;
    } else {
        alert("You must provide a reason for reporting this entry. Why should it be removed?");
        return true;
        $get("entryReportTextArea").focus();
    }
}
function reportEntry(reportReason,feedbackType,entryID)
{
    if (Sys.Services.AuthenticationService.get_isLoggedIn())
    {
        Climate1StopWebService.SubmitEntryFeedback(entryID,feedbackType,reportReason,onSubmitFeedbackSuccess,onSubmitFeedbackFail,entryID);
    } else {
        notLoggedInMessage("You must be logged in to submit feedback");
    }
}

function showCommentEntry(entryID)
{
    var commentHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Add Comment!</p><br/>";
    commentHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/comment.jpg' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Add your comment below:&nbsp;<img src='Images/comment.jpg' style='width:25px;height:25px;vertical-align:middle;'/></p>"
    commentHTML += "<br/>";
    commentHTML += "<div style='text-align:center;padding-left:10px;padding-right:10px;'>";
        commentHTML += "<textarea id='entryCommentTextArea' name='entryCommentTextArea' style='width:100%;font-size:small;font-family:Calibri,Verdana,Arial;' rows='4' onKeyDown='limitText($get(\"entryCommentTextArea\"),$get(\"entryCommentCountdown\"),500);'";
        commentHTML += " onKeyUp='limitText($get(\"entryCommentTextArea\"),$get(\"entryCommentCountdown\"),500);'></textarea>";
        commentHTML += "</div>";
        commentHTML += "<div style='text-align:left;padding-left:10px;padding-right:10px;'>";
        commentHTML += "<font size='1'>You have <input readonly type='text' style='margin-top:4px;margin-bottom:4px;' id='entryCommentCountdown' name='entryCommentCountdown' size='2' value='500'> characters left.</font>";
        commentHTML += "</div><br/>";         
    commentHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='validateComment($get(\"entryCommentTextArea\").value,"+entryID+");' class='cssTextButton'/>&nbsp;&nbsp;<input type='button' value='Cancel' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
    //validateHTML+= "</div>";
    displayStaticMessage(commentHTML,false,370,265);
    //messageObj.onmouseover = mouseoverMessageObj;
    //alert("focussing");
    $get("entryCommentTextArea").focus();
    //Remember to check if the GUID is "" or not...message the user that they must be logged in to add comments.
}

//function mouseoverMessageObj()
//{
//alert("mouseover");
//var textArea = $get("entryCommentTextArea");
//if (textArea !=null)textArea.focus();
//}

function validateComment(commentText,entryID)
{
    if (commentText!=""){
        addEntryComment(commentText,entryID);
        closeMessage();
        return false;
    } else {
        alert("Empty comments cannot be submitted, please enter your comment and hit 'OK', or choose 'Cancel'");
        return true;
    }
}

//function addEntryComment(strUserGUID,threadID,commentText)
function addEntryComment(commentText,entryID)
{
    //Send the comment to the server, add the new comment
    //Try to refresh the window that is viewing this entry ID
     Climate1StopWebService.AddEntryComment(commentText,entryID,onAddEntryCommentSuccess,onAddEntryCommentFail,entryID);
}

//Add an entry with the given information
function doSubmitEntry()
{
    var isOk=true;
    
    //var validateMessage="Entry is incomplete:\n\n";
    //Get all the parameters using JS, then send to the web service
    //Entry Name
    var entryName = $get("entryNameTB").value;
    if (entryName=="" || entryName==null) isOk=false;
    
    //alert(entryName);
    
    //Description
    var entryDesc = $get("descriptionTextArea").value;
    if (entryDesc=="" || entryName==null) isOk=false;
    
    //alert(entryDesc);
    //Category
    var entryCatId="";

    for (var i=0; i<document.forms[0].catRadioGroup.length; i++)
    { 
        if (document.forms[0].catRadioGroup[i].checked)
        {
            entryCatId = document.forms[0].catRadioGroup[i].value;
        } 
    } 
    
    if (entryCatId=="" || entryCatId==null || entryCatId==undefined) isOk=false;
    
    //alert(entryCatId);
    //Entry URL
    var entryURL = $get("entryURLTB").value;
    if (entryURL=="" || entryURL==null) isOk=false;
    
    //alert(entryURL);
    
    //Entry Keywords
    var entryKeywords = $get("entryKeywordsTB").value;
    if (entryKeywords=="" || entryKeywords==null) isOk=false;
    
    for(var i=0;i<entryKeywords.length;i++)
    {
        
        if (entryKeywords[i]==' '){
        isOk=false;
        }
    }
    
    //alert(entryKeywords);
    //Start/End date
    var entryStartDate = $get("startDateAE").value;
    var entryEndDate = $get("endDateAE").value;
    if (entryStartDate=="" || entryStartDate==null){
        if (entryEndDate!=null && entryEndDate!="")isOk=false; 
    } else if(entryEndDate==null || entryEndDate==""){
        if (entryStartDate!=null && entryStartDate!="") isOk=false;
        
    }
    if (entryStartDate!="" && entryEndDate!=""){
        var sDateObj = Date.parse(entryStartDate);
        var eDateObj = Date.parse(entryEndDate);
        if (sDateObj>eDateObj) isOk=false;
    }
    
  //  alert(entryStartDate);
    //alert(entryEndDate);
    //Continent/Country
    var entryContinent="";
    var entryCountry="";
    var entryTheme="";
    var selContinents = $get("continentsDD");
    var selCountries = $get("countriesDD");
    
    //Sector/Theme
    var selThemes = $get("sectorThemesDD");
    
    entryContinent = selContinents.options[selContinents.selectedIndex].value;
    entryCountry = parseInt(selCountries.options[selCountries.selectedIndex].value);
    entryTheme = selThemes.options[selThemes.selectedIndex].value;

//alert(entryContinent);
//alert(entryCountry);
//alert(entryTheme);

    if (isOk){
        if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
        $get("submitEntryButton").disabled = true;
            //Make the call to the webservice to insert the information into the database
            Climate1StopWebService.AddEntry(entryName,entryDesc,entryCatId,entryURL,entryKeywords,entryStartDate,entryEndDate,entryContinent,entryCountry,entryTheme,clickedLat,clickedLong,onAddEntrySuccess,onAddEntryFail,"AddEntry");
        } else {
        notLoggedInMessage("You must be logged in to add an entry");return false;
           // alert("You must be logged in to add an entry");
           // window.location = "Login.aspx?ReturnMode=modeAddEntry";
           //window.location = "Login.aspx";
        }
    } else {
        //var validateHTML = "<div style='font-family:Verdana,Arial;>";
        
        validateHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Entry is Incomplete!</p><br/>";
         validateHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;Please fix the following items:&nbsp;<img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
         validateHTML += "<ul style='text-indent:25px;text-align:left;font-family:Verdana,Arial;font-size:10px;color:navy;'>";
         
         if (entryName=="" || entryName==null){
         validateHTML+= "<li>Entry Name/Title is required</li>";
         }
         
        if (entryDesc=="" || entryName==null){
            validateHTML+= "<li>Entry Description is required</li>";
        }
         
        if (entryCatId=="" || entryCatId==null || entryCatId==undefined){
             validateHTML+= "<li>Entry Category is required</li>";
        }
        if (entryURL=="" || entryURL==null){
            validateHTML+= "<li>Entry URL/Website is required</li>";
        }
        if (entryKeywords=="" || entryKeywords==null){
             validateHTML+= "<li>Entry Keywords are required</li>";
        } else {
          for(var i=0;i<entryKeywords.length;i++)
            {
                
                if (entryKeywords[i]==' '){
                validateHTML+= "<li>Use comma to separate Keywords, no spaces</li>";
                }
            }
        }
        
        if (entryStartDate=="" || entryStartDate==null)
        {
            if (entryEndDate!=null && entryEndDate!="") validateHTML+= "<li>Invalid Start Date</li>";
        }
        else if(entryEndDate==null || entryEndDate=="")
        {
            if (entryStartDate!=null && entryStartDate!="") validateHTML+= "<li>Invalid End Date</li>";
            
        }
        if (entryStartDate!="" && entryEndDate!=""){
        var sDateObj = Date.parse(entryStartDate);
        var eDateObj = Date.parse(entryEndDate);
        if (sDateObj>eDateObj) validateHTML+= "<li>Start Date must be before End Date</li>";
        }
         validateHTML+= "</ul><br/>";
         validateHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(validateHTML,false,370,225);return false;
         
         //alert(validateMessage);
    }
}

//Prevent users putting spaces in the keywords area.
function CheckKeyCode(event)
{
//alert("keycode check");
  if(event.keyCode == 32) {
    return false;
    }
  else {
    return true;
  }
}


//This is the display entry code, it pre-defines some variables to hold DHTML windows, then calls a web service to get the content
var entryWin0,entryWin1,entryWin2,entryWin3,entryWin4,entryWin5,entryWin6,entryWin7,entryWin8,entryWin9;
var entryWinNameArray = new Array("entryWin0","entryWin1","entryWin2","entryWin3","entryWin4","entryWin5","entryWin6","entryWin7","entryWin8","entryWin9");
var entryIDsViewedArray = new Array(10);
var entryPositionArray = new Array(10);
var startingLeft=150;
var startingTop=15;

function displayEntry(entryID)
{
    var entryAlreadyOpenIndex=-1;
    var tooManyOpen=false;
    
    //Check to see if the entry is already open, get the index in the array
    for (var i=0;i<entryIDsViewedArray.length;i++)
    {
        if (entryIDsViewedArray[i]==entryID){
            entryAlreadyOpenIndex=i;
        }
    }
    
    if (entryAlreadyOpenIndex==-1)
    {
        //The loading message
        var loadingMsg = "<div style=\"text-align:left;vertical-align:middle;font-size:13px;color:Blue;width:100%;height:100%;\">";
        loadingMsg += "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"display:inline-table;vertical-align:middle;\">Fetching Entry...</b>";
        loadingMsg += "</div>";
        
        for (i=0;i<entryIDsViewedArray.length;i++)
        {
            if (entryIDsViewedArray[i]==null) {
                tooManyOpen=false;
                entryIDsViewedArray[i] = entryID;
           if (i==0)
           {
          
           var strInitWindow = "new Ext.Window({id:'Entry-'+entryID,renderTo: Ext.getBody(),initCenter:false,resizable: true,closeAction:'close',listeners: {close: function(p){ closeEntry("+i+");}},collapsible:true,closable:true,title:\"Fetching Entry...\",autoScroll:true,height: 575,width: 500,x:"+startingLeft+",y:"+startingTop+"});";
             eval(entryWinNameArray[i] + " = " + strInitWindow);
             eval(entryWinNameArray[i] + ".show();");
             //eval(entryWinNameArray[i] +" = dhtmlwindow.open('Entry-'+entryID,'inline',loadingMsg,'Retrieving Entry...','width=450px,height=500px,left="+startingLeft+"px,top="+startingTop+"px,resize=1,scrolling=1', 'recal')");  
             entryPositionArray[i]=startingLeft+","+startingTop;
           } else {
               var lastPosStr = entryPositionArray[i-1].split(",");
               var lastX = parseInt(lastPosStr[0]);
               var lastY = parseInt(lastPosStr[1]);
               
               var newLeft = lastX + 25;
               var newTop = lastY + 25;
               entryPositionArray[i] = newLeft+"," + newTop;
           
                //eval(entryWinNameArray[i] +" = dhtmlwindow.open('Entry-'+entryID,'inline',loadingMsg,'Retrieving Entry...','width=450px,height=500px,left="+newLeft+"px,top="+newTop+"px,resize=1,scrolling=1', 'recal')");
                var strWindow = "new Ext.Window({id:'Entry-'+entryID,renderTo: Ext.getBody(),resizable: true, initCenter:false,closeAction:'close',listeners: {close: function(p){  closeEntry("+i+");}},collapsible:true,closable:true,title:\"Fetching Entry...\",autoScroll:true,height: 575,width: 500,x:"+newLeft+",y:"+newTop+"});"
                 eval(entryWinNameArray[i] + " = " + strWindow);
                 eval(entryWinNameArray[i] + ".show();");
           }
            // eval (entryWinNameArray[i] + ".onclose=function(){return closeEntry("+i+")}");
                //win.addListener('hide', function () {alert('xx');});
             //   eval (entryWinNameArray[i] + ".addListener('close', function () {return closeEntry("+i+");});");
                //Make the call to the web service
               // Climate1StopWebService.GetEntryContent(entryID,onGetEntrySuccess,onGetEntryFail,entryWinNameArray[i]);
                GetEntryContent(entryID,entryWinNameArray[i]);
                break;
            } else {
                tooManyOpen=true;
            }
        }
        if (tooManyOpen==true) {
        
         var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Too Many Open Entries!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;A maximum of 10 entries can be viewed simultaneously.&nbsp;</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,400,175);
           // alert("There is a limit of 10 entries that can be viewed at one time, you must close one before you can open another");
        }
        //alert(entryWin0.innerHTML);
    
    } else {
    
        //This entry is already open
//        var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Too Many Open Entries!</p><br/>";
//         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;This entry .&nbsp;<img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/></p>";
//         messageHTML += "<br/>";
//         messageHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
    //     displayStaticMessage(messageHTML,false,370,150);
    //if (forceRefresh){
    
   // } else {
        eval(entryWinNameArray[entryAlreadyOpenIndex]+".show();");
    //}
         
    }
   // win=dhtmlwindow.open("Entry-"+entryID, "inline", loadingMsg, "#2: Broadcast Title", "width=300px,height=120px,left=150px,top=10px,resize=1,scrolling=0", "recal")
    //win.onclose=function(){return window.confirm("Close window?")} //Run custom code when window is about to be closed
    //ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", "Entry.aspx", "#3: Ajax Win Title", "width=450px,height=300px,left=300px,top=100px,resize=1,scrolling=1")
    //ajaxwin.onclose=function(){return window.confirm("Close window 3?")} //Run custom code when window is about to be closed
}

function closeEntry(index)
{
    //The user closed the entry, so remove it from the "currently viewed array"
    // eval(entryWinNameArray[index] +".close();");
    entryIDsViewedArray[index]=null;
    return true;
}

function closeEntryByEntryID(entryID)
{
    var entryAlreadyOpenIndex=-1;
    
    //Check to see if the entry is already open, get the index in the array
    for (var i=0;i<entryIDsViewedArray.length;i++)
    {
        if (entryIDsViewedArray[i]==entryID){
            entryAlreadyOpenIndex=i;
        }
    }
    if (entryAlreadyOpenIndex !=-1) {
        //The entry is already open so close the physical window object
      eval(entryWinNameArray[entryAlreadyOpenIndex] +".close();");
      }
}

function refreshEntry(entryID)
{
    var entryAlreadyOpenIndex=-1;
    
    //Check to see if the entry is already open, get the index in the array
    for (var i=0;i<entryIDsViewedArray.length;i++)
    {
        if (entryIDsViewedArray[i]==entryID){
            entryAlreadyOpenIndex=i;
        }
    }
    if (entryAlreadyOpenIndex !=-1) {
   // alert(entryWinNameArray[entryAlreadyOpenIndex].id);
        //The entry is already open so close the physical window object
          eval(entryWinNameArray[entryAlreadyOpenIndex] +".close();");
       // entryIDsViewedArray[entryAlreadyOpenIndex]=null;
        
        //now that we've closed it and removed it from the array, display it again.
        displayEntry(entryID);
        //And then make sure the entryID is removed from the entryID array
        //closeEntry(entryAlreadyOpenIndex);
        
        //displayEntry(
    } else {
    
    }
}

function scrollToBottomOfTextArea(textarea)
{
    textarea.scrollTop = textarea.scrollHeight;
}
function duh()
{
alert("duh");
}
function limitText(limitField, limitCount, limitNum)
{
   // alert("got here");	
	if (limitField.value.length > limitNum) {
	
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
	//alert("something");
		limitCount.value = limitNum - limitField.value.length;
	}
	
	scrollToBottomOfTextArea(limitField);

}
function toggleCalendar(calendar)
{
//alert(calendar);
    if (calendar.toUpperCase()=="STARTDATEAE")
    {
        //if (addEntryStartCalendar==null)
        //{
       // alert("calendar is null");
            addEntryStartCalendar = new Epoch('cal','popup',document.getElementById('startDateAE'),false);
            addEntryStartCalendar.toggle();
            //var addEntryEndCalendar = new Epoch('cal','popup',document.getElementById('endDateAE'),false);
        //} else {
       // alert("just toggle");
       //     addEntryStartCalendar.toggle();
        //}
        
        if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryEndCalendar!=null) addEntryEndCalendar.hide();
         if (addEventEndCal!=null) addEventEndCal.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
    } 
    else if (calendar.toUpperCase()=="ENDDATEAE")
    {
        //if (addEntryEndCalendar==null)
        //{
            addEntryEndCalendar = new Epoch('cal','popup',document.getElementById('endDateAE'),false);
            addEntryEndCalendar.toggle();
            //var addEntryEndCalendar = new Epoch('cal','popup',document.getElementById('endDateAE'),false);
       // } else {
        //    addEntryEndCalendar.toggle();
        //}
        if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
         if (addEventEndCal!=null) addEventEndCal.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
    }
    else if (calendar.toUpperCase()=="STARTDATE")
    {
        //if (searchStartCalendar==null)
       // {
            searchStartCalendar = new Epoch('cal','popup',document.getElementById('startDate'),false);
            searchStartCalendar.toggle();
            //var addEntryEndCalendar = new Epoch('cal','popup',document.getElementById('endDateAE'),false);
       // } else {
        //    searchStartCalendar.toggle();
        //}
         //if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
        if (addEntryEndCalendar!=null) addEntryEndCalendar.hide();
            if (addEventEndCal!=null) addEventEndCal.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
    }
    else if (calendar.toUpperCase()=="ENDDATE")
    {
        //if (searchEndCalendar==null)
        //{
            searchEndCalendar = new Epoch('cal','popup',document.getElementById('endDate'),false);
            searchEndCalendar.toggle();
            //var addEntryEndCalendar = new Epoch('cal','popup',document.getElementById('endDateAE'),false);
        //} else {
       //     searchEndCalendar.toggle();
        //}
         if (searchStartCalendar!=null) searchStartCalendar.hide();
         if(addEntryEndCalendar!=null) addEntryEndCalendar.hide();
        //if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
            if (addEventEndCal!=null) addEventEndCal.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
    }
    else if (calendar.toUpperCase()=="EVENTCALSTARTDATE")
    {
        addEventStartCal= new Epoch('cal','popup',document.getElementById('ctl00_MainContentPlaceHolder_WhenStartDate'),false);
        addEventStartCal.toggle();
        
          
        if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryEndCalendar!=null) addEntryEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
        if (addEventEndCal!=null) addEventEndCal.hide();
        
    } 
    else if (calendar.toUpperCase()=="EVENTCALENDDATE")
    {
          addEventEndCal = new Epoch('cal','popup',document.getElementById('ctl00_MainContentPlaceHolder_WhenEndDate'),false);
          addEventEndCal.toggle();
          
        if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryEndCalendar!=null) addEntryEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
    } 
    else
    {
        if (searchStartCalendar!=null) searchStartCalendar.hide();
        if (searchEndCalendar!=null) searchEndCalendar.hide();
        if (addEntryEndCalendar!=null) addEntryEndCalendar.hide();
        if (addEntryStartCalendar!=null) addEntryStartCalendar.hide();
        if (addEventStartCal!=null) addEventStartCal.hide();
        if (addEventEndCal!=null) addEventEndCal.hide();
    }
}

//Call the web service method to get the list of countries for a continent.
function updateCountriesDropDown(selectedContinent,countriesDropdownID)
{
     Climate1StopWebService.GetCountries(selectedContinent,onGetCountriesSuccess,onGetCountriesFail,countriesDropdownID);
}

function notLoggedInMessage(msg)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Not Logged In!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;"+msg+"</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='Login' onclick='closeMessage();goLogin();' class='cssTextButton'/>&nbsp;&nbsp;<input type='button' value='Nevermind' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,150);
}
function confirmMessage(msg,isOnYesClick)
{
    var messageHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Please Confirm!</p><br/>";
         messageHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:25px;height:25px;vertical-align:middle;'/>&nbsp;"+msg+"</p>";
         messageHTML += "<br/>";
         messageHTML+= "<div style='text-align:center;'><input type='button' value='Yes' onclick='closeMessage();"+isOnYesClick+"return true;' class='cssTextButton'/>&nbsp;&nbsp;<input type='button' value='No' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
         //validateHTML+= "</div>";
         displayStaticMessage(messageHTML,false,370,150);
         
}

function displayMessage(url)
{
	
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(400,200);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	messageObj.display();
}

function displayStaticMessage(messageContent,cssClass,x,y)
{
	messageObj.setHtmlContent(messageContent);
	messageObj.setSize(x,y);
	messageObj.setCssClassMessageBox(cssClass);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(true);	// Disable shadow for these boxes	
	messageObj.display();
	
	
}
function initMessage()
{
    messageObj.setHtmlContent("");
	messageObj.setSize(0,0);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSource(false);	// no html source since we want to use a static message here.
	messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes	
	messageObj.display();
}
function closeMessage()
{
	messageObj.close();	
}

function hideStatus()
{
    window.status = "";
    return true;
}

//function clientLogin()
//{
//  var commentHTML = "<p style='text-align:center;width:100%;padding-top:5px;padding-bottom:5px;margin:0px;background-color:#0033FF;color:white;font-family:Verdana,Arial;font-weight:bold;font-size:Medium;'>Login</p><br/>";
//            commentHTML += "<p style='text-align:center;font-size:small;font-family:Verdana,Arial;color:red'><img src='Images/alert.png' style='width:35px;height:35px;vertical-align:middle;'/>&nbsp;Please enter your login information:&nbsp;<img src='Images/alert.png' style='width:35px;height:35px;vertical-align:middle;'/></p>"
//            commentHTML += "<br/>";
//            commentHTML += "<table cellpadding='0px' cellspacing='0px' style='padding-left:10px;width:100%;padding-right:10px;'>";
//            commentHTML += "<tr><td style='width:30%;text-align:right;'>Username:&nbsp;</td>";
//                commentHTML += "<td style='width:70%;text-align:left;'><input onkeypress='return checkEnter();' type='text' id='loginNameClient' name='loginNameClient' style='height:20px;width:75%;font-size:small;font-family:Calibri,Verdana,Arial;'</input></td></tr>";
//                commentHTML += "<tr><td style='width:30%;text-align:right;'>Password:&nbsp;</td>";
//                commentHTML += "<td style='width:70%;text-align:left;padding-top:5px;'><input onkeypress='return checkEnter();' type='password' id='loginPWClient' name='loginPWClient' style='width:75%;height:20px;'</input></td></tr>";
//                commentHTML += "<tr><td colspan='1'>&nbsp;</td><td colspan='1' style='width:100%;text-align:left;'><input type='checkbox' id='clientLoginRememberMeBox' name='clientLoginRememberMeBox' value='Remember Me'/>Remember Me</td></tr></table><br/>";     
//            commentHTML+= "<div style='text-align:center;'><input type='button' value='OK' onclick='doClientLogin($get(\"loginNameClient\").value,$get(\"loginPWClient\").value,$get(\"clientLoginRememberMeBox\").checked);' class='cssTextButton'/>&nbsp;&nbsp;<input type='button' value='Cancel' onclick='closeMessage();return false;' class='cssTextButton'/></div>";
//            //validateHTML+= "</div>";
//            displayStaticMessage(commentHTML,false,370,265);
//            $get("loginNameClient").focus();
//}
function goCreateUser()
{
    var entryString="";
   entryString = "";
   
   var entriesOpen=false;
   
    for (var i=0;i<entryIDsViewedArray.length;i++)
    {
        if (entryIDsViewedArray[i]!=undefined && entryIDsViewedArray[i]!=null){
        entryString+=entryIDsViewedArray[i]+",";
           entriesOpen=true;
        }
    }
    if (entriesOpen)
    {
        entryString=entryString.substring(0,entryString.length-1);
        window.location = "CreateUser.aspx?ReturnEntry="+entryString;
    } else {
        window.location = "CreateUser.aspx";
    }
}

 function goLogin()
 {
   var entryString="";
   entryString = "";
   
   var entriesOpen=false;
   
    for (var i=0;i<entryIDsViewedArray.length;i++)
    {
        if (entryIDsViewedArray[i]!=undefined && entryIDsViewedArray[i]!=null){
        entryString+=entryIDsViewedArray[i]+",";
           entriesOpen=true;
        }
    }
    if (entriesOpen)
    {
        entryString=entryString.substring(0,entryString.length-1);
        window.location = "Login.aspx?ReturnEntry="+entryString;
    } else {
        window.location = "Login.aspx";
    }
 }
 
 function checkEnterSearch(e)
 {
   var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
        validateSearch();
    } else {
       return true;
    }
 }
 
 function checkEnterPageSwitchFromSourceCategory(e)
 {
    var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
    
     $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    
       var tbPageNum = $get('CurrentPageNum').value;
       var newPageNum = 1;
       
       //Check if it's a number first, if not, reset to page #1
       if (isNaN(tbPageNum))
       {
            newPageNum=1;
       } else {
           newPageNum = parseInt(tbPageNum);
           
           if (newPageNum<1) newPageNum=1;
           if (newPageNum>_totalNumOfPages) newPageNum=_totalNumOfPages;
           
            var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
            
           
       }
       //Set the page num display (in case people enter in crap
        $get('CurrentPageNum').value = newPageNum;
        
        CurrentPage = newPageNum;
        
       showPagingProgress("Processing...");
          // GetResultsFromSourcePagingNonCategory(newPageNum,_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currSortType,"onGetResultsFromSourcePagingNonCategorySuccess");
          GetCategorySourceSearchResultPage(newPageNum,_lastCatID,_lastSourceEntryID,_lastSourceIsOrg,activeMode,currSortType,"onGetCategorySourceSearchResultPageSuccess");
    } else {
       return true;
    }
 }
 
 function checkEnterPageSwitchFromSourceNonGrouped(e)
 {
    var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
    
     $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    
       var tbPageNum = $get('CurrentPageNum').value;
       var newPageNum = 1;
       
       //Check if it's a number first, if not, reset to page #1
       if (isNaN(tbPageNum))
       {
            newPageNum=1;
       } else {
           newPageNum = parseInt(tbPageNum);
           
           if (newPageNum<1) newPageNum=1;
           if (newPageNum>_totalNumOfPages) newPageNum=_totalNumOfPages;
           
            var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
            
           
       }
       //Set the page num display (in case people enter in crap
        $get('CurrentPageNum').value = newPageNum;
        
        CurrentPage = newPageNum;
        
           showPagingProgress("Processing...");
           GetResultsFromSourcePagingNonCategory(newPageNum,_lastSourceEntryID,_lastSourceIsOrg,"SEARCHRESULTS",currSortType,"onGetResultsFromSourcePagingNonCategorySuccess");
          
    } else {
       return true;
    }
 }
 
 function checkEnterPageSwitchNonGrouped(e)
 {
    var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
    
     $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    
    
       var tbPageNum = $get('CurrentPageNum').value;
       var newPageNum = 1;
       
       //Check if it's a number first, if not, reset to page #1
       if (isNaN(tbPageNum))
       {
            newPageNum=1;
       } else {
           newPageNum = parseInt(tbPageNum);
           
           if (newPageNum<1) newPageNum=1;
           if (newPageNum>_totalNumOfPages) newPageNum=_totalNumOfPages;
           
            var searchOptions = readCookie("searchOptions");
         var currSortType = "";
         var currGroupYesNo = "";
           if (searchOptions !=null && searchOptions!=undefined){
             var searchOptionArray = searchOptions.split("|");
             currSortType=searchOptionArray[0];
             currGroupYesNo=searchOptionArray[1];
             
            } else {
           //  alert("no cookie yet");
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                currSortType=entrySortType;
                currGroupYesNo=groupByCatYesNo;
            }
            
            
           
       }
       //Set the page num display (in case people enter in crap
        $get('CurrentPageNum').value = newPageNum;
        
        CurrentPage = newPageNum;
        showPagingProgress("Processing...");
          GetSearchResultPagingNonCategory(newPageNum,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,"SEARCHRESULTS",currSortType,"onGetSearchResultPagingNonCategorySuccess");
     
          
    } else {
       return true;
    }
 }
 
 function checkEnterPageSwitchCategory(e)
 {
   var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
    
     $get('nextPageButton').disabled = true;
    $get('previousPageButton').disabled = true;
    
       var tbPageNum = $get('CurrentPageNum').value;
       var newPageNum = 1;
       
       //Check if it's a number first, if not, reset to page #1
       if (isNaN(tbPageNum))
       {
            newPageNum=1;
       } else {
           newPageNum = parseInt(tbPageNum);
           
           if (newPageNum<1) newPageNum=1;
           if (newPageNum>_totalNumOfPages) newPageNum=_totalNumOfPages;
           
            var searchOptions = readCookie("searchOptions");
            var currentSortType="";
            if (searchOptions !=null && searchOptions!=undefined){
                 var searchOptionsArray = searchOptions.split("|");
                 currentSortType = searchOptionsArray[0];
                 var currentGroupYesNo=searchOptionsArray[1];
                 createCookie("searchOptions",currentSortType+"|"+currentGroupYesNo,0);
                 
            } else {
                //Just use the current sort type, and the hard coded groupyesno...
                createCookie("searchOptions",entrySortType+"|"+groupByCatYesNo,0);
                 currentSortType=entrySortType;
            }
            
            
           
       }
       //Set the page num display (in case people enter in crap
        $get('CurrentPageNum').value = newPageNum;
         
         CurrentPage = newPageNum;
         showPagingProgress("Processing...");
         
         GetCategorySearchResultPage(newPageNum,_lastCatID,_lastOrgAffID,_lastContinentCode,_lastCountryID,_lastStartDate,_lastEndDate,_lastKeywords,activeMode,currentSortType,"onGetCategorySearchResultPageSuccess");
       
     
          
    } else {
       return true;
    }
 }
 
  function checkEnterSimpleSearch(e)
 {
    var Ucode=e.keyCode? e.keyCode : e.charCode;
    if (Ucode=="13"){
        validateSimpleSearch();
    } else {
       return true;
    }
 }
 
 function showPagingProgress(msg)
 {
   // var progressHTML = "<a href=\"#\" class=\"loadingImage\"></a>&nbsp;<b style=\"font-size:13px;color:blue;display:inline;vertical-align:middle;\">"+msg+"</b>";
    var progressImg = $get("pagingProgressImg");
    
    if (progressImg!=null && progressImg!=undefined)
    {
        progressImg.style.visibility = "visible";
    }
//    var progressDiv = $get("searchOptionsProgress");
//    if (progressDiv!=null && progressDiv!=undefined){
//        progressDiv.innerHTML = progressHTML;
//    } 
 }
 
 function hidePagingProgress()
 {
 var progressImg = $get("pagingProgressImg");
    
    if (progressImg!=null && progressImg!=undefined)
    {
    progressImg.style.visibility = "hidden";
    }
//    var progressDiv = $get("searchOptionsProgress");
//    if (progressDiv!=null && progressDiv!=undefined){
//        progressDiv.innerHTML = "";
//    } 
 }
 
 function showBatchProgress(msg)
 {
  
 var batchProgessMsg = $get("batchProgressMsg");
  batchProgessMsg.innerHTML = msg;
  var progressDiv = $get("batchProgressDiv");
  progressDiv.style.visibility = "visible";
  setTimeout('$get("batchProgImg").src="Images/loader2.gif"', 200);
 }
 
  function hideBatchProgress()
 {
  
 var batchProgessMsg = $get("batchProgressMsg");
  batchProgessMsg.innerHTML = "";
  var progressDiv = $get("batchProgressDiv");
  progressDiv.style.visibility = "hidden";
  //setTimeout('$get("batchProgImg").src="Images/loader2.gif"', 200);
 }
 
 
 function doValidateAddEvent()
 {
    var validated = Page_ClientValidate();
     if (validated) {
        showBatchProgress('Uploading event to calendar...');
     } else {
        hideBatchProgress();
     }
 }
 
 function getWebSvcString(result)
 {
    var strResult="";
    var stringElement = result.getElementsByTagName("string")[0];
    
    if (stringElement.text!=null && stringElement!=undefined){
        strResult=stringElement.text;
       // alert("IE: "+strResult.length);
    }
    else if (stringElement.textContent!=null && stringElement.textContent!=undefined)
    {
        strResult=stringElement.textContent;
      //  alert("FF: "+strResult.length);
    }
      
    return strResult;
 }
//function checkEnter() 
//{ 

//    getEvent=event.keyCode;
//     if (getEvent == "13")
//     {
//     doClientLogin($get("loginNameClient").value,$get("loginPWClient").value,$get("clientLoginRememberMeBox").checked);
//     return false;
//     }
//     else
//     {
//     return true;
//    }

//   
//} 
//function doClientLogin(username,password,rememberMeBool)
//{
////alert(username);
////alert(password);
// Climate1StopWebService.ClientLogin(username,password,rememberMeBool,onClientLoginSuccess,onClientLoginFail,username);
//closeMessage();
//return false;
////if (commentText!=""){
////        addEntryComment(commentText,entryID,threadID);
////        closeMessage();
////        return false;
////    } else {
////        alert("Empty comments cannot be submitted, please enter your comment and hit 'OK', or choose 'Cancel'");
////        return true;
////    }
//}

//function escape(str)
//{
//str = str.replace(/&/g, "&amp;");
//str = str.replace(/>/g, "&gt;");
//str = str.replace(/</g, "&lt;");
//str = str.replace(/"/g, "&quot;");
//str = str.replace(/'/g, "&#039;");
//return str;
//}

//Cookie functions (if necessary)
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//REQUIRED: Notifies the ScriptManager that the script has been loaded.    
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();