﻿// JScript File
// *************** checkUser.js file ***************************
var xmlHttpEmail;
var parentPageTemp;
var userPreviousURL;

var is_Safari = navigator.userAgent.indexOf('Safari');
var isMozilla;
 isMozilla = (document.all) ? 0 : 1;
function Authenticate(parentPage)
{ 
    var _userName;
    var _password;
    var loadstatustext;
    var url;
    _userName = document.getElementById("txtLoginUserName").value.replace("'","''");
    _password = document.getElementById("txtLoginPassword").value;
    parentPageTemp = parentPage;
    document.getElementById("divLogin").innerHTML="&nbsp;";
    
    if(_userName != "" && _password != "")
    {
        _userName = trim(_userName);
       // _password = trim(_password);
        if(_password.indexOf("&")!=-1)
        {
             //_password=_password.replace('&',"$100$");    
              _password= escape(_password);
        }
        if(parentPage.search(/home page/i) >= 0)
        {
             loadstatustext="<img src='Images/home page/loading.gif' /> Login in progress...";
        }
        else
        {
             loadstatustext="<img src='../../Images/home page/loading.gif' /> Login in progress...";
        }
       
        document.getElementById("spnRequestContents").innerHTML = loadstatustext;
        xmlHttpEmail=null;
        xmlHttpEmail=GetXmlHttpObject();
        if (xmlHttpEmail==null)
        {
            alert("Browser does not support HTTP Request.");
            return;
        } 
        if(parentPage.search(/home page/i) >= 0)
        {
             url="WebPages/EmailTemp.aspx";
        }
        else
        {
            url="../EmailTemp.aspx";     
        }
        //url=url;
        //url=url+"&sid="+Math.random()
        
        url=url + "?varUserName="+_userName+"&varPassword="+_password;
        
        var parameters="varUserName="+_userName+"&varPassword="+_password;
        
        xmlHttpEmail.onreadystatechange=stateChanged;
        xmlHttpEmail.open("GET",url,true);
        //xmlHttpEmail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        //xmlHttpEmail.setRequestHeader("Connection", "Keep-Alive");        
        xmlHttpEmail.send(null);
        return false;
    }
    else if(_userName == "")
    {
         loadstatustext="Email Id missing.";
        document.getElementById("spnRequestContents").innerHTML = loadstatustext;
        return false;
    }
    else if(_password == "")
    {
         loadstatustext="Password missing.";
        document.getElementById("spnRequestContents").innerHTML = loadstatustext;
        return false;
    }
}
//---------------------------------------------------------------------------------------------
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
//---------------------------------------------------------------------------------------------
function stateChanged() 
{ 
    if (xmlHttpEmail.readyState==4 )
    { 
       
       if((xmlHttpEmail.responseText).search(/Successfull/i) >= 0)
       {
         
            if (parentPageTemp.search(/home page/i) >= 0 )
            {
               self.location.href = "MyHomePage.aspx";
            }
            else
            {
               self.location.href = "../../MyHomePage.aspx";
            }
       }
       else
       {
            document.getElementById("spnRequestContents").innerHTML = "";
            //var xmlDoc=xmlHttpEmail.responseXML;
            var str;
            str=xmlHttpEmail.responseText;
            str=str.replace("<form","<div");
            document.getElementById("divLogin").innerHTML = str;
       }
 
    } 
}     

function checkEnterKeyHomePage(event)
{
    if(event.keyCode == 13)
    {      
        Authenticate("home page");
    }
    return false;
}
//To avoid post back
function IgnoreEnterKey(e)
{
    var controlTagName;
    var inputType;
    if(e.srcElement)
    {
        controlTagName = e.srcElement.tagName;
        inputType = e.srcElement.type;
    }
    else
    {
        controlTagName = e.target.tagName;
        inputType = e.target.getAttribute("type");       
    }
    
    var textBox = "";
    if(controlTagName == "INPUT" && inputType == "text" || inputType == "password")
    {
        textBox = "true";
    }
    else if(controlTagName == "INPUT")
    {
        textBox = "false";
    }
    
    if(controlTagName == "TEXTAREA" || controlTagName == "IMG" || controlTagName == "A" )
    {
        // Do nothing allow enter key 
    }
    else if(textBox == "true")
    {
        if (e.keyCode == 13)
        {
            if (e.stopPropagation) 
            {
                e.stopPropagation();  
            }
            else
            {
                e.returnValue=false;
                e.cancel = true;
            }
        }
    }
    else
    {
        if (e.keyCode == 13)
        {
            if (e.stopPropagation) 
            {
                e.stopPropagation();
            }
            else
            {
                e.returnValue=false;
                e.cancel = true;
            }
        }
    }
}

// ***************************** topframe.js file ******************************

// JScript File
var myTimer;
var inoout=false;

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function AdjustMenuZIndex(str)
{
    window.menu = document.getElementById('menu');
    if(str=="Rollover")
    {
        //document.getElementById("menu").style.zIndex=1000;
        
        if(!document.all)
        {
            if(document.getElementById("topbanner"))
            {
                document.getElementById("topbanner").style.display="none";
            }
        }
        
        //This is added for stopping the scroll news, since in firefox the expanded menus are flickering
        //inoout = true;
    }
    else if(str=="Rollout")
    {
        //document.getElementById("menu").style.zIndex=0;
        
        if(!document.all)
        {
            if(document.getElementById("topbanner"))
            {
                document.getElementById("topbanner").style.display="block";
            }
        }
        
        //This is added for stopping the scroll news, since in firefox the expanded menus are flickering
        //inoout = false;
    }
}

function ShowPage(page)
{
    var currUrl;
    currUrl=String(self.location);
    var arr;
    var seperator = '/';
    arr=currUrl.split(seperator);
    var url;
    
    //Get the URL
    switch(page)
    {
    //menu 1
    
        case "Home":
            url="HomePage.aspx";
            break;      
       
    //menu 2   
            
        case "Workout":
            url="WebPages/LogBook/LogDetails.aspx";
            break; 
            
        case "Workout Calendar":
            url="WebPages/LogBook/LogDetails.aspx";
            break; 
            
        case "Import/Export":
            url="WebPages/LogBook/GPSDataUpload.aspx";
            break;    
            
        case "Workout Settings":
            setCookie("CookieLogSettings", "LogSettings", 3600);
            url="WebPages/LogBook/LogDetails.aspx?enc=1";
            break;
            
         case "Utilities":
            url="WebPages/LogBook/ShoeDetails.aspx";
            break;
            
        case "Threshold Limit":
            url="WebPages/Coaching/ThresholdLimitDetails.aspx";
            break;
            
            
         case "Report":
            url="WebPages/LogBook/LogReports.aspx";
            break;  
            
        case "Routes":
            url="WebPages/LogBook/SearchTrainingRoutes.aspx";
            break;   
                
      case "Athlete Tools":
         url="WebPages/AthleteTools/AthleteTools.aspx?calc=3";
        break;
        
       case "Goals":
            url="WebPages/LogBook/MyGoals.aspx";
            break;
            
            
       case "Challenges":
            url="WebPages/LogBook/GlobalChallenges.aspx";
            break;
            
    //menu 3
        case "Training":
            //url="WebPages/TrainingAndCoaching/ViewCoaches.aspx"; 
            url="WebPages/Coaching/TrainingPlans.aspx"; 
            break;
        
        case "Training plans":
            //url="WebPages/TrainingAndCoaching/ViewCoaches.aspx"; 
            url="WebPages/Coaching/TrainingPlans.aspx"; 
            break;
            
         case "My Training plans":
            url="WebPages/Coaching/PlanDetails.aspx"; 
            break;    
            
         case "Training Coach":
            url="WebPages/Coaching/FindCoach.aspx"; 
            break;
            
            
          case "My Coach":
            url="WebPages/Coaching/MyTrainingCoaches.aspx"; 
            break;
            
            
    //menu 4        
           case "Events":
            url="WebPages/EventCalendar/EventList.aspx";
            break;  
            
            case "Global Events":
            url="WebPages/EventCalendar/EventCalendar.aspx";
            break;
            
            case "My Events":
            url="WebPages/SportsLifeEventsList/EventsList.aspx";
            break;
            
            case "Bucket List":
            //url="WebPages/SportsLifeEventsList/EventsList.aspx";
            url="WebPages/LifeEventList/LifeEventListTrial.aspx";
            break;
            
    //menu 5    
           case "My Stuff":
            url="MyHomePage.aspx";
            break;  
            
           case "My Home Page":
            url="MyHomePage.aspx";
            break;
            
            
             case "My Profile":
            var hidDisplayName = document.getElementById('TopFrame1_hidDisplayName');
            //alert("hidDisplayName= " + hidDisplayName);
            if(hidDisplayName!=null)
            {
            //alert("hidDisplayName.value = " + hidDisplayName.value);
                url= hidDisplayName.value;
            }
            else
            {
                url="WebPages/User/PageNotFound.aspx";
            } 
            break;
            
              case "My Photos":
            url="WebPages/User/MyPhotos.aspx";
            break;
            
              case "My Achievements":
            url="WebPages/LogBook/MyAchievement.aspx";
            break;
            
            
            case "Browse Users":
            url="WebPages/User/UserList.aspx";
            break;
            
             case "My Friends":
            url="WebPages/User/FriendRequest.aspx";
            break;
              
            case "User Management":
            url="WebPages/User/UserManagement.aspx";
            break;
            
            
             case "Settings":
            url="WebPages/User/EditProfile.aspx";
            break;
           
     //menu 6  
            case "Social Network":
            url="WebPages/Blogs/BlogHomePage.aspx";
            break; 
          case "Community":
            url="WebPages/Blogs/ViewBlogs.aspx";
            break; 
       
         case "Blogs":
            url="WebPages/Blogs/BlogHomePage.aspx";
            break; 
       
        case "Forums":
            url="WebPages/Community/ViewForums.aspx"; 
            break;
            
         case "Communities":
            url="WebPages/Community/ViewCommunities.aspx"; 
            break;    
            
            
      //meun 7    
      case "Extra":
            url="WebPages/Widgets/GetWidget.aspx";
            break;
      
       case "Widgets and Badges":
            url="WebPages/Widgets/GetWidget.aspx";
            break;  
       
        case "Newsletter":
            url="WebPages/NewsLetters/ViewNewsLetters.aspx";
            break;
            
        case "Glossary":
            url="WebPages/Coaching/GlossaryDetails.aspx";
            break;    
            
       case "Online Registration":
            url="WebPages/User/OnlineRegistration.aspx";
            break;     
            
           case "Event Setup & Registration":
            url="WebPages/EventCalendar/EventList.aspx";
            break;
            
//            
//        case "Athlete Tools":
//            url="WebPages/AthleteTools/AthleteTools.aspx"; 
//        break;
//        
//        case "My Events":
//            url="WebPages/SportsLifeEventsList/EventsList.aspx";
//            break;
//       
//        case "Online Registration":
//            url="WebPages/User/OnlineRegistration.aspx";
//            break;
//            
//        case "Edit Profile":
//            url="WebPages/User/EditProfile.aspx";
//            break;
//                
//        case "RSS Feeds":
//            url="WebPages/RSSFeedViewer/RSSFeedViewer.aspx";
//            break;
//             
//        case "Pace Calculator":
//        SubmitQueryString("WebPages/AthleteTools/AthleteTools.aspx?calc=1");
//        return;
//        break;
//        
//        case "Heart Rate Calculator":
//        SubmitQueryString("WebPages/AthleteTools/AthleteTools.aspx?calc=2");
//        return;
//        break;
//            
//        case "Calorie Calculator":
//        SubmitQueryString("WebPages/AthleteTools/AthleteTools.aspx?calc=3");
//        return;
//        break;
//        
//        case "Race Time Predictor":
//        SubmitQueryString("WebPages/AthleteTools/AthleteTools.aspx?calc=5");
//        return;
//        break;
//        
//        case "Food Diary":
//        url="WebPages/FoodDiary/SearchFoodDiary.aspx";
//        break;
//                        
//        case "Conversion Calculator":
//        SubmitQueryString("WebPages/AthleteTools/AthleteTools.aspx?calc=4");
//        return;
//        break;
//        
//        case "Metric Conversion":
//        url="WebPages/AthleteTools/AthleteTools.aspx?calc=4"; 
//        break;  
//              
//        case "Shopping":
//            url="WebPages/Other/Comingsoon.aspx";
//            break;
//            
//        case "Classifieds":
//            url="WebPages/Other/Comingsoon.aspx";
//            break;
//            
//        case "Products":
//            url="WebPages/Other/Comingsoon.aspx";
//            break;
//            
//        case "More":
//            url="WebPages/RSSFeedViewer/RSSFeedViewer.aspx";
//            break;
//        case "Widgets":
//            url="WebPages/Widgets/GetWidget.aspx";
//            break;  
       
                
        default:
            return;
    }    
    self.location=url;    
    return "";    
}
function CollapseMenus()
{
    if(document.getElementById("menu")!=null)
    {
        window.document.menu.SetVariable("outsideclick", "pageclick");
    }
}

////This function will be called from the flash file to get the variables
//function GetRecentUsersList()
//{
//    window.recentusers = document.getElementById('recentusers');
//    
//    document.recentusers.SetVariable("UserIds",document.getElementById("hidrecentUserIds").value);
//    document.recentusers.SetVariable("UserNames",document.getElementById("hidrecentUsersNames").value);
//    document.recentusers.SetVariable("UserImages",document.getElementById("hidrecentUsersImages").value);
//    document.recentusers.SetVariable("imagepath","UserImages/");    
//}

//function ShowUserProfile(userID)
//{
//    window.recentusers = document.getElementById('recentusers');
//    
//    var url="WebPages/User/MyProfile.aspx?userId=" + userID;
//    self.location=url;
//}

////This function will be called from the flash file to get the variables for video
//function GetHomePageVideo()
//{
//    window.videoPlayer = document.getElementById('videoPlayer');
//    //Displaying the video on the home page
//    var filename=document.getElementById("CurrentVideo").value;
//    document.videoPlayer.SetVariable("VideoFileName","../../Videos/" + filename);
//}

function ShowMenus()
{    
    if(document.getElementById("PageFooter_hUserId").value!="")
    {
        //Make the panels visible/invisible
        checkSessionTimeout();
        if(document.getElementById("PageFooter_hidUserRole").value == 2 ||document.getElementById("PageFooter_hidUserRole").value == 1 ) 
        {
             if(document.getElementById("TopFrame1_divCoachLink") != null)
             {
            document.getElementById("TopFrame1_divCoachLink").style.visibility = 'visible';
            document.getElementById("TopFrame1_divCoachBar").style.visibility = 'visible';
            }
        }
        else
        {
              if(document.getElementById("TopFrame1_divCoachLink") != null)
              {
               document.getElementById("TopFrame1_divCoachLink").style.display = 'none';
              document.getElementById("TopFrame1_divCoachBar").style.display = 'none';
              }
        }
//        document.getElementById("TopFrame1_pnlLogin").style.display = 'none';
//        document.getElementById("TopFrame1_pnlAfterLogin").style.display = 'block';
       // document.getElementById("diveditFBProfile").style.display='none';
        document.getElementById("TopFrame1_lblLoginName").innerHTML = document.getElementById("PageFooter_hUserName").value;
    }
    else
    {
       if(document.getElementById("PageFooter_hFBAfterLoginId").value!="")
       {
          document.getElementById("PageFooter_hFBUserName").value="";
       }

//       if(document.getElementById("PageFooter_hFBUserName").value!="")
//       {
//           document.getElementById("TopFrame1_pnlAfterLogin").style.display = 'block';
//           document.getElementById("TopFrame1_pnlLogin").style.display = 'none';
//           document.getElementById("diveditFBProfile").style.display='block';
//           if(document.getElementById("TopFrame1_divCoachLink") != null)
//           {
//              document.getElementById("TopFrame1_divCoachLink").style.display = 'none';
//              document.getElementById("TopFrame1_divCoachBar").style.display = 'none';
//           }
//           document.getElementById("TopFrame1_lblLoginName").innerHTML = document.getElementById("PageFooter_hFBUserName").value +"!";
//       }
//       else
//       {
//           document.getElementById("TopFrame1_pnlAfterLogin" ).style.display = 'none';
//           document.getElementById("TopFrame1_pnlLogin").style.display = 'block';
          // document.getElementById("diveditFBProfile").style.display='none';
//       }
    }
    var Path, PageName;
    Path = self.location.href ;
    PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
    
    //Check the browser type and accordingle set the properties on the menu container
    if(document.all)
    {
        //for IE
        //document.getElementById("menucontainer").style.overflow="hidden";
        document.getElementById("topframe").style.overflow="hidden";
    }
    else
    { 
        //For Firefox
        //document.getElementById("menucontainer").style.overflow="visible";
        document.getElementById("topframe").style.overflow="visible";
    } 
    
    document.body.onclick=CollapseMenus;
    
    
//    if(document.getElementById("PageFooter_hUserId").value!="")
//    {
//        FetchData();
//        document.menu.SetVariable("MenuOption", "User");
//    }
//    else
//    {
//        document.menu.SetVariable("MenuOption", "Normal");
//    }
   
    if(document.getElementById("PageFooter_hidUserRole").value=="2")
    {
        FetchData();
        //document.menu.SetVariable("MenuOption", "admin");
    }
    else if(document.getElementById("PageFooter_hidUserRole").value=="1")
    {
        FetchData();
        //document.menu.SetVariable("MenuOption", "coach");
    }
    else if(document.getElementById("PageFooter_hUserId").value!="")
    {
       FetchData();
        //document.menu.SetVariable("MenuOption", "User");
    }
    else
    {
        //document.menu.SetVariable("MenuOption", "Normal");
    }
    
    AdjustMenuZIndex("Rollout");
    
    if(document.getElementById("PageFooter_hUserId").value!="")
    {
        var obj;
	    obj =  document.getElementById("TopFrame1_hidShowMessanger");
	    if (obj != null)
	    {
	        if (obj.value == "true")
	        {
	            setTimeout("setVisible('TopFrame1_pnlIMPopUp')",1000);
	            obj.value = "false";
	        }
	    }
	} 
	else
    {
        //Check if any IM chat pop ups are open
        if (arrWindow != null)
        { 
            var objWindow;
            for (var key in  arrWindow)
            {
                objWindow = arrWindow[key]; 
                if (objWindow != null)
                {
                objWindow.close();
                }
            }
        }        
    }
}

// To avoid passing query string to web page.
// Sending query string by post action of form in hidden fields.
function SubmitQueryString(URLQueryStr)
{  
    var form=document.createElement("form");
    form.method = 'post';
	form.id="submitQueryForm";
	form.name="submitQueryForm";
	form.style.visibility = 'hidden';
	
	var lengthOfURL = URLQueryStr.length;
    var posOfQueryStr = URLQueryStr.indexOf("?");
    var actionURL;
    var queryStr;
    if(posOfQueryStr == -1)
    {
        actionURL = URLQueryStr;
        queryStr = "" ;
    }
    else
    {
        actionURL = URLQueryStr.substring(0,posOfQueryStr);
        queryStr = URLQueryStr.substring(posOfQueryStr+1,lengthOfURL);
    }
    
    var queryStrPair = queryStr.split("&");
    var keyValuePair;
    var i=0;
    
    for(i=0;i<queryStrPair.length;i++)
    {
        keyValuePair =  queryStrPair[i].split("=");                      
        addInput(document, form, 'hidden', keyValuePair[0], keyValuePair[1]);
    }
    
	document.body.appendChild(form);
	form.action = actionURL;
	form.submit();
	document.body.removeChild(form);
    return false;
}

function addInput(doc, form, type, name, value) 
{
	  var e = doc.createElement('input');
	  e.type = type;
	  e.name = name;
	  e.id = name;
	  e.value = value;	 
	  form.appendChild(e);
}
function load()
{
     window.onbeforeunload = function () {UpdateWindowArray();};    
}
function MM_swapImgRestore() 
{  //v3.0
   var i,x,a=document.MM_sr; 
   for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
   {    x.src=x.oSrc;
   }
}

//function MM_swapImage() 
//{  //v3.0

//  var i,j=0,x,a=MM_swapImage.arguments; 
//  document.MM_sr=new Array; 
//  for(i=0;i<(a.length-2);i+=3)
//  {
//       if ((x=MM_findObj(a[i]))!=null)
//       {
//            document.MM_sr[j++]=x; 
//            if(!x.oSrc) 
//            {
//                x.oSrc=x.src; x.src=a[i+2];
//            }
//       }
//   }
//}
function MM_swapImage() 
{  //v3.0
   var i,j=0,x,a=MM_swapImage.arguments; 
   document.MM_sr=new Array; 
   for(i=0;i<(a.length-2);i+=3)
   {
      if ((x=MM_findObj(a[i]))!=null)
      {  document.MM_sr[j++]=x; 
          if(!x.oSrc) 
          {  x.oSrc=x.src; 
          }
          x.src=a[i+2];
      }
   }
}
function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  
  if(!d) 
  {
    d=document; 
  }
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) 
  {  x=d.all[n]; 
  }
  for (i=0;!x&&i<d.forms.length;i++) 
  {  x=d.forms[i][n];
  }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  {  x=MM_findObj(n,d.layers[i].document);
  }
  if(!x && d.getElementById) 
  {
     x=d.getElementById(n); 
  }
  return x;
}

 function toggleOnlineList(ctrlId)
{
    var ctrl;
    ctrl = document.getElementById(ctrlId);
    if (ctrl != null)
    {
        if ((ctrl.style.display == 'block') || (ctrl.style.display == ''))
        {
            ctrl.style.display = 'none';
        }
        else 
        if (ctrl.style.display == 'none')
        {
            ctrl.style.display = 'block';     
        }           
    }
}

// ***************************** AccordianNews.js ***************************
// JScript File
var xmlHttpAccordian;
var accordianPaneNo;
var hidNewsTabCount;
var newsTabCount;
    
function loadXmlForAccordian(paneNo)
{ 
    accordianPaneNo = paneNo;
    
    //Get total count of news tab 
    if(document.getElementById("hidNewsTabCount")!= null)
    {
        newsTabCount = document.getElementById("hidNewsTabCount").value;
    }    
    
    //display the loading bar
    var divId = "divLoadingBar" + paneNo;
    var hidAccordianRSSURLId = "hidAccordianRSSURL" + paneNo;
    var accordianPaneRssUrl;
    if(document.getElementById(hidAccordianRSSURLId)!= null)
    {
        accordianPaneRssUrl= document.getElementById(hidAccordianRSSURLId).value;
    }
    if (document.getElementById(divId) != null)
    {
        document.getElementById(divId).style.display="block";

        xmlHttpAccordian=null;
        xmlHttpAccordian=GetXmlHttpObject();
        
        if (xmlHttpAccordian == null)
        {
            alert ("Browser does not support HTTP Request.");
            return;
        } 
        var url = "WebPages/RssTemp.aspx";
        url=url+"?xmlFile="+accordianPaneRssUrl; 
        
        xmlHttpAccordian.onreadystatechange=ShowAccordianNewsStateChanged;     
        xmlHttpAccordian.open("GET",url,true);
        xmlHttpAccordian.send(null);
    }
    return(false);
}

function ShowAccordianNewsStateChanged() 
{     
    if (xmlHttpAccordian.readyState==4 )
    { 
       try
       {
            //make the loading bar invisible
            var divId = "divLoadingBar" + accordianPaneNo;
            document.getElementById(divId).style.display="none";            
            accordianNewsImageTextSettings(accordianPaneNo);            
       }
       catch (exception)
       {
            alert(exception);
       }        
    }    
} 

function accordianNewsImageTextSettings(accordianPaneNo1)
{
    var newsTabCounter;
    var divId = "divNewsPane";
    var imgPaneId = "imgPane";
    
    for(newsTabCounter=1; newsTabCounter<= newsTabCount; newsTabCounter++)
    {
        if(newsTabCounter == accordianPaneNo1)
        {
            divId = "divNewsPane" + newsTabCounter;
            imgPaneId = "imgPane" + newsTabCounter;
            if(newsTabCounter != newsTabCount)
            {
                document.getElementById(divId).innerHTML=xmlHttpAccordian.responseText; 
            }
            document.getElementById(divId).style.display = 'block'; 
        }
        else
        {
            divId = "divNewsPane" + newsTabCounter;
            imgPaneId = "imgPane" + newsTabCounter;
            document.getElementById(divId).style.display = 'none'; 
        }
     }
    
     return true;    
}

//function setNewsTabCount(totalTabsCount)
//{
//    newsTabCount = totalTabsCount;
//}

// ************************** PageCustomization.js ******************************
// JScript File

var dragapproved=false;
var minrestore=0;
var initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;

function iecompattest(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function drag_drop(e){
    if (ie5&&dragapproved&&event.button==1)
    {
        document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px";
        document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px";
    }
    else if (ns6&&dragapproved)
    {
        document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px";
        document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px";
    }
}

function initializedrag(e)
{
    offsetx=ie5? event.clientX : e.clientX;
    offsety=ie5? event.clientY : e.clientY;
    //document.getElementById("dwindowcontent").style.display="none" //extra
    tempx=parseInt(document.getElementById("dwindow").style.left);
    tempy=parseInt(document.getElementById("dwindow").style.top);

    dragapproved=true;
    document.getElementById("dwindow").onmousemove=drag_drop;
}

function ShowCustomizationPage(pagename,width,height,title)
{

    //Check if the customization is for home page
    if(pagename=="HomePage.xml")
    {
        url="WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    else
    {
        url="../../WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    
    document.getElementById("cframe").src=url;
    
    //Call the Modal popup to display the customization window
    ShowModalPopup('dwindow',title + ' - Customization','l');
                
}


function closepopupandreload()
{
    closepopup('dwindow');
    //document.location.reload(true);
    ReloadPageCSSFile();
    //RefreshPage();
}

var xmlHttpObject;

function ReloadPageCSSFile()
{  
    var objCSS;
    objCSS=document.getElementById("dynamicCSS");
    
    if(objCSS!=null)
    {
        document.body.removeChild(objCSS);
    }
    
    var obj;
    obj=document.createElement("link",obj);
    obj.setAttribute("id","dynamicCSS");
    obj.setAttribute("rel","stylesheet");
    obj.setAttribute("type","text/css");
    
    var date = new Date();
    
    var cssPageCSS;
    
    if(cssFileName=="MyProfile.css")
    {   
        var userId=document.getElementById("PageFooter_hUserId").value;
        cssPageCSS="../../CustomizedCSS/" + userId+cssFileName;
    }
    else
    {
        cssPageCSS=cssFileName;
    }
        
    obj.setAttribute("href",cssPageCSS + "?" + date.getTime());
    
    document.body.appendChild(obj);         
   //GetChangedCSS();    
}

function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}


function stopdrag()
{
    dragapproved=false;
    document.getElementById("dwindow").onmousemove=null;
    document.getElementById("dwindowcontent").style.display=""; //extra
    //window.self.location=window.self.location;
}


//function RefreshPage()
//{
//    //document.body.innerHTML=document.body.innerHTML;
//    document.getElementById("UpdatePanel1").innerHTML=document.getElementById("UpdatePanel1").innerHTML;
//}

// *********************************** popup.js file ********************************
// JScript File
var rolloverobject;
var objX=0;
var objY=0;
var Popupdata="";

//This function is used to display the event details
//function ShowHomePageEventPopup(e,eventDate,strID)
//{

////    Popupdata="";    
////    xmlHttpEvent= null;
////    xmlHttpEvent=GetXmlHttpObject();
////    
////    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
////    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
////    
////    if(is_Safari>0)
////    {
////        objX=e.clientX + 10; //document.body.scrollLeft;
////        objY=e.clientY + 10; //document.body.scrollTop;
////    }
////    else
////    {    
////        objX=e.clientX+objX + 10; //document.body.scrollLeft;
////        objY=e.clientY+objY; //document.body.scrollTop;        
////    }
////    
////    rolloverobject=strID;
////     
////    var objpopup;
////   objpopup=document.getElementById("divLeftArrowPopup");
////   document.getElementById("divCalendarpopup").style.display="none";
////    objpopup.style.display="block";
////    //Check if the popup is already created
////    if(objpopup!=null)
////    {
////        if(document.getElementById("eventcalendarpopup_lblTitle")!=null)
////        {   document.getElementById("eventcalendarpopup_lblTitle").innerHTML="&nbsp;&nbsp;"+"Event Details";
////        }
////          
//////        document.getElementById("popupLoadingImage").src="Images/home page/loading.gif";
////        document.getElementById("popupLeftLoadingImage").src="Images/home page/loading.gif";
////        
////     document.getElementById("imgArrow").src = "Images/BackgroundImages/RolloverPopup/arrow_left.png";
////       var total=parseInt(objX)-(parseInt(objpopup.style.width)+parseInt('10'));
////     //var topPos = parseInt(total) - 70;  
////    // var totLeft = parseInt(total) - 1;  
////        var topPos=parseInt(objY);
////        var topLeft=parseInt(total)-15;
////        //alert(topPos);
////        var topPos=parseInt(topPos)-60;
////        objpopup.style.left=topLeft+"px";
////        objpopup.style.top=topPos+"px";
////        objpopup.style.display="block";
//////        document.getElementById("calendarpopupHeader").style.display="block";
////         document.getElementById("calendarpopupLeftHeader").style.display="block";
////        document.getElementById("eventcalendarpopup_lblLeftEventDetails").innerHTML="";
////        
////    }
////    
////    if (xmlHttpEvent==null)
////    {
////        alert("Browser does not support HTTP Request.");
////        return;
////    } 
////    var url="WebPages/EventCalendar/EventCalenderpopup.aspx";
////    //url=url+"?date="+date; 
////    url=url+"?eventDate=" + eventDate; 
////    
////    //alert("test1");
////    xmlHttpEvent.onreadystatechange=stateChangedShowHomePagePopup;
////    xmlHttpEvent.open("GET",url,true);
////    xmlHttpEvent.send(null);     

//    

//    Popupdata="";
//     
//    EventPagexmlHttpEvent= null;
//    EventPagexmlHttpEvent=GetXmlHttpObject();
//    
//    objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
//    objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
//    
//    if((is_Safari >0))
//    {     
//          
//         objX= window.event.clientX+objX + 10;
//         objY=window.event.clientY+objY+10;
//    }
//    else
//    {
//        objX=e.clientX+objX; //document.body.scrollLeft;
//        objY=e.clientY+objY; //document.body.scrollTop;
//    }
//    
//    rolloverobject=strID;
//     var objpopup;
//   objpopup=document.getElementById("divCalendarpopup");
//    var objpopup_left;
//    objpopup_left = document.getElementById("divLeftArrowPopup");
//   
//    //Check if the popup is already created
//    if(objpopup!=null)
//    {       
//    
//       if(document.getElementById("eventcalendarpopup_lblPopupTitle")!=null )
//        {   
////            if(categeoryID != 0)
////            {
//                document.getElementById("eventcalendarpopup_lblPopupTitle").innerHTML="&nbsp;&nbsp;&nbsp;"+"Event Details";
////            }
////            else if(categeoryID == 0)
////            {
////                document.getElementById("eventcalendarpopup_lblPopupTitle").innerHTML="&nbsp;&nbsp;"+"Events of the day";
////            }
//        }
//         if(document.getElementById("eventcalendarpopup_lblTitle")!=null)
//        {   
////            if(categeoryID != 0)
////            {
//                document.getElementById("eventcalendarpopup_lblTitle").innerHTML="&nbsp;&nbsp;"+"Event Details";
////            }
////             else if(categeoryID == 0)
////            {
////                document.getElementById("eventcalendarpopup_lblTitle").innerHTML="&nbsp;&nbsp;"+"Events of the day";
////            }
//        }
//        
//        
//        document.getElementById("imgRightArrow").src = "Images/BackgroundImages/RolloverPopup/arrow.png";
//        document.getElementById("popupLoadingImage").src="Images/home page/loading.gif";
//        document.getElementById("popupLeftLoadingImage").src="Images/home page/loading.gif";
//     
//       //objpopup.style.display="block";  
//        var topPos = parseInt(objY) -70;  
//        var totLeft = parseInt(objX) - 330; 
//       if(objX < 650)
//       {
//       //left arrow
//         
//           objpopup_left.style.display="block";
//            objpopup.style.display="none";
//            var topPos=parseInt(objY);
//            var topLeft=parseInt(objX) + 10;
//            topPos=parseInt(topPos)-60;
//           
//            objpopup_left.style.left=topLeft+"px";
//            objpopup_left.style.top=topPos+"px";
//       }
//       else
//        {
//          objpopup_left.style.display="none";
//          objpopup.style.display="block";
//       //   topLeft = topLeft + 50;
//          objpopup.style.left=totLeft+"px";
//          objpopup.style.top=topPos+"px";
//        }
//       
//       
//       
//       
//        document.getElementById("calendarpopupHeader").style.display="block";
//        document.getElementById("calendarpopupLeftHeader").style.display="block";
//        document.getElementById("eventcalendarpopup_lblEventDetails").innerHTML="";
//        document.getElementById("eventcalendarpopup_lblLeftEventDetails").innerHTML="";
//    }

//    if (EventPagexmlHttpEvent==null)
//    {
//        alert("Browser does not support HTTP Request.");
//        return;
//    } 
////    var url="EventCalenderpopup.aspx";
////   //var url="../../UserControls/CalenderPopup.ascx";
////    //url=url+"?date="+date; 
////    url=url+"?eventDate=" + eventDate; 
//////    url=url+"&categeoryID=" + categeoryID; 
////    //url=url+"&userID=" + 0; 
////    EventPagexmlHttpEvent.onreadystatechange=stateChangedShowEventPagePopup;
////    EventPagexmlHttpEvent.open("GET",url,true);
////    EventPagexmlHttpEvent.send(null); 
//}
function stateChangedShowHomePagePopup() 
{ 
    if (xmlHttpEvent.readyState==4 )
    {       
         Popupdata=xmlHttpEvent.responseText;
     
        // objpopup.innerHTML=Popupdata;
        
        
        if(document.getElementById("eventcalendarpopup_lblEventDetails")!=null)
        {  
           document.getElementById("eventcalendarpopup_lblEventDetails").innerHTML=Popupdata;
          document.getElementById("calendarpopupHeader").style.display="none";  
          
  document.getElementById("calendarpopupLeftHeader").style.display="none";   
        }        
    } 
} 
function CreatePopup()
{
    var objpopup;
    objpopup=document.getElementById("divEventpopup");
    
    //Check if the popup is already created
    if(objpopup==null)
    {
        try
        {
            //For IE
            objpopup=document.createElement("<div id=\"divEventpopup\" style=\"z-index: 1000; position: absolute; display: none;left:0px; top:0px; \">");
        }
        catch(e)
        {
            //for firefox
            objpopup=document.createElement("div");
            objpopup.setAttribute("id", "divEventpopup");
            objpopup.setAttribute("style", "z-index: 1000; position: absolute; display: none; left:0px; top:0px; ");
        }
            
    }
    document.body.appendChild(objpopup);
    return(objpopup);
}

//function CloseEventPopup()
//{
//    var objpopup;
//    objpopup=document.getElementById("divCalendarpopup");
//    
//    var visibility = document.getElementById("divCalendarpopup").style.display;
//    
//    //alert(visibility);
//    if((objpopup!=null)&&(visibility=="block"))
//    {
//        objpopup.style.display="none";
//    }
//}

//function MoveEventPopup(e)
//{ 
////        var objpopup;
////         objpopup=document.getElementById("divLeftArrowPopup");
////       
////      if(objpopup)
////      {
////      
////         if(objpopup.style.display=="block")
////         { 
////           objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
////           objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
//////    document.getElementById("imgRightArrow").src = "Images/BackgroundImages/RolloverPopup/arrow.png";
////    document.getElementById("imgArrow").src = "Images/BackgroundImages/RolloverPopup/arrow_left.png";
////           if(is_Safari>0)
////           {
////               objX=e.clientX + 10; //document.body.scrollLeft;
////               objY=e.clientY + 10; //document.body.scrollTop;
////           }
////           else
////           {    objX=e.clientX+objX + 10; //document.body.scrollLeft;
////                objY=e.clientY+objY; //document.body.scrollTop;      
////           }
////           
////         var total=parseInt(objX)-(parseInt(objpopup.style.width));
////        var topPos=parseInt(objY);
////        var topLeft=parseInt(total)-15;
////        var topPos=parseInt(topPos)-60;
////          objpopup.style.top=topPos+"px";
////          objpopup.style.left=topLeft+"px";
////        
////           objpopup.style.display="block";         }
////      }
//        var objpopup;
//           
//      objpopup=document.getElementById("divCalendarpopup");
//        var objpopup_left;
//    objpopup_left = document.getElementById("divLeftArrowPopup");
//    
//      if(objpopup)
//      {      
//         if(objpopup.style.display=="block" || objpopup_left.style.display=="block")
//         { 
//           objX=(document.all)?document.documentElement.scrollLeft:window.pageXOffset;
//           objY=(document.all)?document.documentElement.scrollTop:window.pageYOffset;
//    
//           if((is_Safari >0))
//            {     
//                  
//                 objX= window.event.clientX+objX-10;
//                 objY=window.event.clientY+objY+10;
//            }
//            else
//            {
//                objX=e.clientX+objX; //document.body.scrollLeft;
//                objY=e.clientY+objY; //document.body.scrollTop;
//            }
//             var arrWeekDays;
//        var total;
////        var tempDate=new Date(logDate);
//        var startDay=parseInt("0");
////        if(document.getElementById("hidDefaultDay").value!="")
////        {
////            startDay =parseInt(document.getElementById("hidDefaultDay").value);
////        }
////         var currentDay =tempDate.getDay();
////        // var arrDays =[ 0, 1, 2, 3, 4, 5, 6 ];
////         switch (startDay)
////            {
////                case 0:
////                    arrWeekDays =[ 0, 1, 2, 3, 4, 5, 6 ];//[ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ];
////                    break;
////                case 1:
////                    arrWeekDays = [1, 2, 3, 4, 5, 6,0 ];//[ "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday" ];
////                    break;
////                case 2:
////                    arrWeekDays =[ 2, 3, 4, 5, 6,0,1 ]; //[ "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday" ];
////                   
////                    break;
////                case 3:
////                    arrWeekDays =[ 3, 4, 5, 6,0,1, 2];//[ "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" ];
////                  
////                    break;
////                case 4:
////                    arrWeekDays =[ 4, 5, 6,0,1, 2, 3];// ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday" ];
////                  
////                    break;
////                case 5:
////                    arrWeekDays = [ 5, 6,0,1, 2, 3, 4 ];//[ "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ];
////                   
////                    break;
////                case 6:
////                    arrWeekDays = [ 6,0,1, 2, 3, 4, 5 ];//["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
////                    //calLogCalendar.FirstDayOfWeek = (FirstDayOfWeek)0;
////                    break;
////                default: break;
////            }
////            var total;
////            var i;
////           if(parseInt(currentDay)!=0)
////               {
////                    currentDay=parseInt(currentDay)-parseInt('1');
////                }
////                else
////                {
////                     currentDay=parseInt('6');
////                }
////         for(i=0;i<8;i++)
////         {
////            if(arrWeekDays[i]==currentDay)
////            {
////              break;
////            }
////         }
//        if(i<3)
//         {
//           
//            objpopup_left.style.display="block";
//            objpopup.style.display="none";
//            var topPos=parseInt(objY);
//            var topLeft=parseInt(objX)+ 15;
//            topPos=parseInt(topPos)-60;
//            objpopup_left.style.left=topLeft+"px";
//            objpopup_left.style.top=topPos+"px";
//         }
//         else
//         {
//             total=parseInt(objX)-parseInt(objpopup.style.width)+parseInt('15');
//             var topPos=parseInt(objY);
//             var topLeft=parseInt(total)-30;
//             var topPos=parseInt(topPos)-60;
//             objpopup.style.left=topLeft+"px";
//             objpopup.style.top=topPos+"px";  
//             objpopup_left.style.display="none";  
//             objpopup.style.display="block";  
//              
//         }
//        
//       }
//      }    
//}

// *************************** OpinionPoll.js file *******************************

// JScript File

 // Function To Validate that at least one Choice is selected for Voting  
function VoteOpinionPoll()
{   
     
    var rdo = document.getElementsByName("optPollChoice");

    for(i=0;i<rdo.length;i++)
    {
        if(rdo[i].checked)
        {
           flag = true;
           return(flag);
           break;
        }
        else
        {
           flag = false;       
            
        }
      
    }
   if(flag ==false)
   {        
//        document.getElementById("lblPollVoteMessage").innerHTML = " Please select an option to cast your vote.";
//        document.getElementById("divWarningInfo").style.display="block";
        var registrationErrorsDiv = document.getElementById("WarningMsgsControl_RegistrationErrors");
        if(registrationErrorsDiv!=null)
        {
            registrationErrorsDiv.style.display = "block";
            registrationErrorsDiv.innerHTML = " Please select an option to vote ";
            document.getElementById("WarningMsgsControl_divWarningInfo").style.display = "block";
        }
         return(flag);
   }
}

function LoadOpinionPollResult()
{
   document.pollID1.SetVariable("LegendText",document.getElementById('hidLegendText').value);
    document.pollID1.SetVariable("LegendValues",document.getElementById('hidLegendValues').value);
}

function loadUPEventHandler()
{  
   var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(UPEndRequestHandler);
    
    if(document.getElementById('hidPollId').value != null)
    {
        if(document.getElementById('hidPollId').value !=0 )
        {
            LoadOpinionPollResult();
        }
    }
    
}

function UPEndRequestHandler(sender, args) 
{
    var err = args.get_error();
    if (err)
    {
      if (err.name == "Sys.WebForms.PageRequestManagerServerErrorException")
       {
             args.set_errorHandled(true);
        }
        if (err.name == "Sys.WebForms.PageRequestManagerParserErrorException") 
          {
            e.set_errorHandled(true);
          }
    }
    var UserMessage = null;
    var EditMessage = null;
    UserMessage = document.getElementById("hidUserMessage");  
    if(UserMessage != null && UserMessage.value != "")
    {
       var UserMessageVal = UserMessage.value;
    }
    
    switch(UserMessageVal)
    {               
        case "CallFlashFile":
            setTimeout('LoadOpinionPollResult()',500);
             LoadOpinionPollResult();    
             break;     
             
        case "ReloadFlashFile":
             LoadOpinionPollResult();   
             break; 
                           
       case "ErrorCallFlashFile":
            closepopup();             
             alert("Error occurred while loading the flash file. Please try again."); 
              break;    
               
      case "InvitationDoneSuccess":
           closepopup('divInviteOtherPopup');
                    ShowMessageBox("Invitation sent successfully.");
                    UserMessage.value = "";  
                    break;  
              
        default:
            return;         
    }    
    UserMessage.value = "";    
}
    
// ****************************** IM.js file ***********************************
//// JScript File

var _winHandler;
var objTimer;
//This function will open the Instant Message window
function ShowInstantMessagePopUp()
{
    var _queryString;
    var width=screen.width;
	var height=screen.height;
	var top= height/2-200;
	var left= width/2-200;
    var Path; 
    var PageName;
    var toUserIDs="",toUserID="",fromUserID="";
    
    if(document.getElementById("hidInstantMessage") != null )
	{
	    if (document.getElementById("hidInstantMessage").value  != "")
	    {
	        //alert(document.getElementById("hidInstantMessage").value); 
	        //document.getElementById("hidInstantMessage").value = "";
	        return false;
	    }
	}
	
	if(document.getElementById("hidFromUserID") != null && document.getElementById("hidToUserID") != "")
    {    
        //get the FromUserID
        fromUserID = document.getElementById("hidFromUserID").value;
        //get the ToUserID
        toUserIDs = document.getElementById("hidToUserID").value;
    	
    	Path = self.location.href;
        
        PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
       
        var AryUserid = toUserIDs.split(",");
              
        for (iIndex = 0; iIndex < AryUserid.length; iIndex++)
        {               
            toUserID = AryUserid[iIndex];
            
            if (toUserID != "")
            {
                if ((PageName  == "MyHomePage.aspx") || ((PageName  == "HomePage.aspx")))
                {   
                    _queryString = "Webpages/IM/InstantMessage.aspx?FromUserID=" + fromUserID + "&ToUserID=" + toUserID;
                }
                else
                {
                    _queryString = "../IM/InstantMessage.aspx?FromUserID=" + fromUserID + "&ToUserID=" + toUserID;
                }
               
               _winHandler = window.open(_queryString,"InstantMessage_" + fromUserID + "_" + toUserID,"height=375,width=525,toolbars=0,scrollbars=0,resizable=0");     
            }
        }                 
     }       
}

var xmlHttpFetchObject;
var xmlHttpFetchChatObject;
function UpdateWindowArray()
{
    if (arrWindow != null)
    {
        for (var key in  arrWindow)
        {
            if (key != null)
            {
                var objWindow = arrWindow[key];
                //Enable the timer on the opened window
                if (objWindow != null)
                {    
                    objWindow.UpdateParentData();       
                }
            }
        }
   }     
}

function FetchData()
{ 
    var Path,PageName;
    var _queryString;

    xmlHttpFetchObject=GetXmlHttpObject();
    if (xmlHttpFetchObject==null)
    {
        alert("Browser does not support HTTP Request");
        return;
    } 
    
    Path = self.location.href;

    PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);       

    if ((PageName  == "MyHomePage.aspx") || ((PageName  == "HomePage.aspx")))
    {   
        _queryString = "Webpages/IM/ProcessAction.aspx";
    }
    else
    {
        _queryString = "../IM/ProcessAction.aspx";
    }       
    
    xmlHttpFetchObject.onreadystatechange=stateChangedFetchData;
    xmlHttpFetchObject.open("GET",_queryString,true);
    xmlHttpFetchObject.send(null);
    return false;
}

function stateChangedFetchData() 
{ 
    var data,msgData,ChatLog="";
    var Message="",toUserid,responseData,FriendData;
    var fromUserId,key;
    var windowHandler;
    var OnlineFriends,PrevOnlineFriends;
    var OnlineUsers,PrevOnlineUsers;
    
    var updateFlag;
    
    if(xmlHttpFetchObject==null)
    {
        return;
    }
    
    if (xmlHttpFetchObject.readyState==4 )
    {   
       //Send the data to the flash program
       var virtualdata=xmlHttpFetchObject.responseText;
       
       if(virtualdata!="")
       {
             //Check if Online Friends are present for this user           

            FriendData = virtualdata.split("%%^%%");
            if (FriendData != null)
            {
                if (FriendData[0] != null)
                {   
                    var objDiv  = document.getElementById("TopFrame1_pnlIMPopUp");
                    if (objDiv != null)
                    {
                        if (objDiv.style.display != 'none')
                        {  
                            OnlineFriends = FriendData[0].replace("OnlineFriendList=", "");
                            OnlineUsers = FriendData[1].replace("OnlineUserList=", "");
//                                    if (OnlineFriends != "" )
//                                    { 
                             //Here check if the Online friend list is updated 
                             // OnlineFriends is the updated one and PrevOnlineFriends is previous list
                             PrevOnlineFriends = document.getElementById("TopFrame1_hidPrevOnlineFriendsList").value;
                             
                             PrevOnlineUsers = document.getElementById("TopFrame1_hidPrevOnlineUsersList").value;
                              
                             updateFlag = CheckWhetherUpdated(OnlineFriends,PrevOnlineFriends);
                             
                             //If the online friend list has updated, then no need to check for the online users list
                             if (updateFlag == false)
                             {
                                updateFlag = CheckWhetherUpdated(OnlineUsers,PrevOnlineUsers);
                             }  
                             
                             if (updateFlag == true)
                             {
                                 //document.getElementById("TopFrame1_hidActiveChatUsers").value = OnlineFriends + "," + OnlineUsers;
                                 CheckForOfflineMessage(OnlineFriends + "," + OnlineUsers);
                                 var btnGetFriends = document.getElementById("TopFrame1_btnGetFriends");
                                
                                 if (btnGetFriends != null)
                                 {                        
                                        var _onlineFriends = document.getElementById("TopFrame1_hidOnlineFriendsList");
                                        if (_onlineFriends != null)
                                        {
                                            _onlineFriends.value = OnlineFriends;
                                        }                                        
                                        var _onlineUsers = document.getElementById("TopFrame1_hidOnlineUsersList");
                                        if (_onlineUsers != null)
                                        {
                                            _onlineUsers.value = OnlineUsers;
                                        }
                                        var is_Safari = navigator.userAgent.indexOf('Safari');
                                        if(is_Safari != -1)
                                        {                                           
                                            btnGetFriends.click();
                                        }
                                        else
                                        {
                                            //Fire the click event
                                            if (document.all)
                                            {
                                                // IE
                                                btnGetFriends.click();
                                            }
                                            else
                                            {
                                                // FireFox 
                                                var e = document.createEvent("MouseEvents");
                                                e.initEvent("click", true, true);
                                                btnGetFriends.dispatchEvent(e);
                                            }
                                        }
                                 }//End If : if (btnGetFriends != null)
                                 
                             }//End IF : if (updateFlag == true )
                               
                        }//End If : if (objDiv.style.display != 'none')
                       
                    }//End If : if (objDiv != null)

                   virtualdata = virtualdata.replace(FriendData[0]+ "%%^%%" , "");
                   virtualdata = virtualdata.replace(FriendData[1]+ "%%^%%" , "");
                }//End If : if (FriendData[0] != null)
                
            }//End If :  if (FriendData != null)    

            if (virtualdata != "")
            {
            //%%$%% is the delimeter for user
            responseData = virtualdata.split("%%$%%");
            if (responseData != null)
            {
                for (count= 0; count < responseData.length ; count++)
                {
                    //##$$@$$## is the delimeter for particular user data
                    data = virtualdata.split("##$$@$$##");
               
                    if (data[0] != null)
                    {   
                       toUserid  = data[0];
                       toUserid = toUserid.replace("toUserID=","");               
                    }
                    if (data[1] != null)
                    {  
                        ChatLog = data[1].replace("ChatLog=" ,"");
                    }
                    if (data[2] != null)
                    {  
                        OnlineFriends = data[1].replace("OnlineFriends=" ,"");
                    }
                             
                    //Check if for this user window is open or not in the arrayWindow
                    fromUserId = document.getElementById("PageFooter_hUserId").value;
                    
                    key = "IM-" + fromUserId + "-" + toUserid;
                    
                    if (arrWindow[key] != null)
                    {
                        //Window is open
                        windowHandler = arrWindow[key];
                    }
                    else
                    {
                        key = "IM-" + toUserid + "-" + fromUserId;
                        if (arrWindow[key] != null)
                        {
                            //Window is open
                            windowHandler = arrWindow[key];
                        }    
                    }
                    if (windowHandler != null)
                    {
                        if (ChatLog != "" )
                        {
                            //Window is open, so update the Chat Log
                            if (windowHandler.divChatMsg != null)
                            {
                                windowHandler.divChatMsg.innerHTML = ChatLog;
                                windowHandler.divChatMsg.scrollTop = windowHandler.divChatMsg.scrollHeight;
                                //windowHandler.blur();
                            }
                            if (windowHandler.txtChatMsg != null)
                            {
                                windowHandler.txtChatMsg.focus();           	
                            }
                        }
                    }
                    else
                    {
                        if (ChatLog != "")
                        {
                            //Window is not open, so open
                            ShowInstantMessageWin(toUserid);                     
                        }
                    }
                }    
            }
         }       
      }
      setTimeout("FetchData()",1000);       
    }     
} 

//This function will open the Instant Message window
function ShowInstantMessageWin(toUserID)
{
    var _queryString;
    var width=screen.width;
	var height=screen.height;
	var top= height/2-200;
	var left= width/2-200;
    var Path; 
    var PageName;
    var fromUserID="";    
    
	if(document.getElementById("PageFooter_hUserId") != null && toUserID != "")
    {   
        //get the FromUserID
        fromUserID = document.getElementById("PageFooter_hUserId").value;
       
       //Check if window is already open in the arrWindow array of Parent window
       var key = "IM-" + fromUserID + "-" + toUserID;

        if(document.getElementById("PageFooter_hidInstantMessage") != null )
        {
            if (document.getElementById("PageFooter_hidInstantMessage").value  != "")
            {
                //alert(document.getElementById("PageFooter_hidInstantMessage").value); 
                document.getElementById("PageFooter_hidInstantMessage").value = "";
                return false;
            }
        }
        //Window is not open, so open the IM window
        Path = self.location.href;
        PageName = Path.substring(Path.lastIndexOf("/")+1 ,Path.length);
    	
        if (toUserID != "")
        {
            if ((PageName  == "MyHomePage.aspx") || ((PageName  == "HomePage.aspx")))
            {   
                _queryString = "Webpages/IM/InstantMessage.aspx?FromUserID=" + fromUserID + "&ToUserID=" + toUserID;
            }
            else
            {
                _queryString = "../IM/InstantMessage.aspx?FromUserID=" + fromUserID + "&ToUserID=" + toUserID;
            }
            //window.open(_queryString,"InstantMessage_" + fromUserID + "_" + toUserID,"height=430,width=487,top=" + top + ",left=" + left + ",toolbars=0,scrollbars=0,resizable=0");     
            window.open(_queryString,"InstantMessage_" + fromUserID + "_" + toUserID,"height=375,width=525,toolbars=0,scrollbars=0,resizable=0");     
        }
    }
 }
 
 function CheckForOpenIMWindow(toUserID,AllowedMsg)
 {
     
    //It means AllowedMsgFlag is false then user is not allowed to send this message
    if(AllowedMsg==0)
    {           
        ShowInformationMessageBox("Sorry, you do not have access to send Instant Message to this user.");
        return;
    }
    
    if(document.getElementById("PageFooter_hUserId") != null && toUserID != "")
    { 
        var windowHandler;
        //Check if for this user window is open or not in the arrayWindow
        var fromUserID = document.getElementById("PageFooter_hUserId").value;
        
        var key = "IM-" + fromUserID + "-" + toUserID;
        //check if window is alreay opened
        if (arrWindow[key] != null)
        {
            //Window is open
            windowHandler = arrWindow[key];
        }
        else
        {
            key = "IM-" + toUserID + "-" + fromUserID;
            if (arrWindow[key] != null)
            {
                //Window is open
                windowHandler = arrWindow[key];
            }    
       }
       if (windowHandler == null)
       {
           //Open the window 
           ShowInstantMessageWin(toUserID);    
       }
    }
 }
 
 //This function will compare OnlineFriends and PrevOnlineFriends list and will identify if the list is updated
 function CheckWhetherUpdated(OnlineFriends,PrevOnlineFriends)
 {
    var matchFound; 
    //If PrevOnlineFriends is blank and OnlineFriends is not blank means the new list is updated
    if ((PrevOnlineFriends == "") && (OnlineFriends != ""))
    {
        return true;
    }
 
    if ((PrevOnlineFriends != "") && (OnlineFriends == ""))
    {
        return true;
    }
        
    if ((PrevOnlineFriends == "") && (OnlineFriends == ""))
    {
        return false;
    }
 
    //Both are not blank, so compare them one by one
    var AryPrevOnlineFriends , AryOnlineFriends;
    var lenPrevOnlineFriends , lenOnlineFriends;
    
    AryPrevOnlineFriends = PrevOnlineFriends.split(",");
    
    AryOnlineFriends = OnlineFriends.split(",");
    
    if ((AryPrevOnlineFriends != null) && (AryOnlineFriends != null))
    {
        lenPrevOnlineFriends = AryPrevOnlineFriends.length;
        lenOnlineFriends = AryOnlineFriends.length;
        if (lenOnlineFriends != lenPrevOnlineFriends)
        {
            return true;
        }
            
        var count1,count2;
        
        for (count1 = 0 ; count1 < lenPrevOnlineFriends; count1++)
        {
            matchFound = 0 ;
            for (count2 = 0 ; count2 < lenOnlineFriends; count2++)
            {
                if (AryPrevOnlineFriends[count1] == AryOnlineFriends[count2])
                {
                    matchFound = 1;
                    break;                
                }
            }
            if (matchFound == 0)
            {
                //for one id in PrevOnlineFriends there is not match present in OnlineFriends, so return true
                return true;
            }
        }
        
        return false;
        
    }//End If : if ((AryPrevOnlineFriends != null) && (AryOnlineFriends != null))    
 }
 
function CheckForMessageWin()
{
    //Check if the chat is updated by someone
    var objHidden = document.getElementById("hidUpdateChatLogFlag");
    if(objHidden != null && objHidden != "")
    {
        if(objHidden.value=="yes")
        {
           objHidden.value="";
           document.getElementById("divChatMsg").innerHTML = document.getElementById("hidCurrentChatLog").value ;
           document.getElementById("divChatMsg").scrollTop = document.getElementById("divChatMsg").scrollHeight;
        }       
        document.getElementById("txtChatMsg").focus();           	
    }          
}

function CheckForOfflineMessage(onlineUserList)
{
    var aryOnlineUserList=new Array();
    var objWindow;
    var flag,count;
    aryOnlineUserList = onlineUserList.split(",");

    if (arrWindow != null)
    {
        for (var key in  arrWindow)
        {
            if (key != null)
            {  
                 var AryUserId = key.split("-");
                 if (AryUserId != null)
                 {
                     var toUserid = AryUserId[2];
                     flag = false;
                     for (count = 0; count < aryOnlineUserList.length; count++)
                     {
                        if (aryOnlineUserList[count] == toUserid)
                        {
                            flag = true;
                            break;
                        }
                     }
                     if (flag == false)
                     {
                        //User is now offline
                        objWindow = arrWindow[key]; 
                        if (objWindow != null)
                        {
                            objWindow.divChatMsg.innerHTML =  objWindow.divChatMsg.innerHTML + "User is now offline ....";
                        }                    
                     }
                 }
            }
        }
    }  
}

// ************************* IMPopup.js file ************************************

function toggleIMDisplay(objId)
{
	obj = document.getElementById(objId);
	if (obj.style.display == 'none')
	{
	    obj.style.display = 'block';
	}
	else if (obj.style.display == 'block')
	{
	    obj.style.display = 'none';
	}
}
function setVisible(objId)
{ 
    var width=screen.width;
	var left= width-350;
	var obj = document.getElementById(objId);
	obj.style.left = left;
	obj.style.top = "200px";
	obj.style.width = "300px";
	obj.style.height = "500px";
	//obj.style.display = 'block';
	
	var objCurrentStatus;
	objCurrentStatus =  document.getElementById("TopFrame1_hidCurrentStatus");
	
	if (obj.style.display == 'block') 
	{  
	    obj.style.display  = 'none';
	    if (objCurrentStatus != null)
	    {
	      objCurrentStatus.value = "Reset";
	      }
	}
	else 
	{
	    obj.style.display  = 'block';
	    if (objCurrentStatus != null)
	    {
	      objCurrentStatus.value = "Set";
	    }
	}
	
	//Call the button click event to set the session variable : MessangerOpen
	 var btn;
	 btn = document.getElementById("TopFrame1_btnUpdateSession");
	 
     if (document.all)
     {
         // IE
         btn.click();
     }
     else
     {
         // FireFox 
         var e = document.createEvent("MouseEvents");
         e.initEvent("click", true, true);
         btn.dispatchEvent(e);
     }
}

var x = screen.width - 350;
var y = 200;
function placeIt(obj)
{

	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px' ;
	obj.style.top = theTop + 'px' ;
	setTimeout("placeIt('TopFrame1_pnlIMPopUp')",500);
}

function loadHomePageContents()
{
    //Load each blocks data by trigerring the button click event of the hidden button
    //Load upcoming events page
    LoadUpcomingEvents();
    
    //Load latest reviews
    //setTimeout(LoadLatestReview,500);
    
    //Load the advertisements on the page
    //LoadAdvertisementBanners();
    
}

function LoadUpcomingEvents()
{
    var is_Safari = navigator.userAgent.indexOf('Safari');
  
    var btn;
	btn = document.getElementById("btnLoadUpccomingEvents");
	if (document.all || is_Safari >0)
    {
        // IE
        btn.click();
    }
    else
    {       
            // FireFox 
            var e = document.createEvent("MouseEvents");
            e.initEvent("click", true, true);
            btn.dispatchEvent(e);
        
    }
}

function LoadLatestReview()
{
    var btn;
	btn = document.getElementById("btn_loadReviews");
	 
    if (document.all)
    {
        // IE
        btn.click();
    }
    else
    {
        // FireFox 
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        btn.dispatchEvent(e);
    }
}
function ShowFullPageView(_startDate)
{
   //self.location.href="WebPages/EventCalendar/EventCalendar.aspx?eventmonth="+_startDate+"";
   SubmitQueryString("WebPages/EventCalendar/EventCalendar.aspx?eventmonth="+_startDate+"");
}
//for checking login for add reviews
 function CheckUserForAddReviews()
    {
        var hidAddReviewsEnable = document.getElementById("hidAddReviewsEnable").value;
        if(hidAddReviewsEnable == "true")
        {
         return true;
            
        }
        else
        {
             ShowInformationMessageBox("You need to login to the system for accessing this feature.");
            return false;
        }

    }
    
//function reload()
//{
//    self.location.href="WebPages/User/Logout.aspx?mode=1";
//}
function refresh_page()
{
    //setTimeout("reload()",1000);
    self.location.href="WebPages/User/Logout.aspx?mode=1";
}

function FBLogout()
{
   FB.ensureInit(function() {       
        FB.Connect.logout(function() { refresh_page(); });
    });
}


    function fullScreen(strUrl)
    {
       window.open(strUrl);
       return false;
    }
    var flag = false;
var timerId=null;  

function checkSessionTimeout()
{

  registerHandlers();
  startSessionTimer();
}
function resetTimer()
{
     timeoutValue = 1200000; //20 minutes
        //timeoutValue = 60000; //1 Minute for testing
}
function startSessionTimer() 
{
  //if(timerId!=null)
  
      clearTimeout(timerId);
      resetTimer();
      timerId = setTimeout(showMsg,timeoutValue); 
}
 function CallToReset(e)
 {
    startSessionTimer();
}
function registerHandlers() 
{
    document.onclick =CallToReset;
    document.oncontextmenu = CallToReset;
    document.onkeypress =CallToReset;
    document.ondblclick =CallToReset;
    document.onfocusin  =CallToReset;  
    document.documentElement.onclick = CallToReset;
    window.onscroll = CallToReset;

    if (document.captureEvents) 
    {  
        document.captureEvents(Event.keyUp);
    }
    document.onkeyup = keyUp;  
}
function keyUp(e) 
{
    var isIE = (document.all)? true:false;
    var KeyID = 0;
	if (isIE)
	{
		KeyID=event.keyCode;
	} 
	else
	{
		KeyID=e.which;
	}  
   switch(KeyID)
   {
	  case 9 : /// For TAB Key
	   CallToReset();
	   break;
	  case 13: /// For ENTER Key
	   CallToReset();
	   break;
			
	}
}
function showMsg()
{
	 //path = "WebPages/User/Logout.aspx?mode=1";
	 //top.location.href = path;
	 FBLogout();			 
      //Your redirection
}
//getAnchorPosition


function ShowTour()
{
    fullScreen('VirtualTour/Main.htm');
    return false;
}

function CallFBRequireFeatures()
{
    var currUrl;
    
    var posURL1,posURL2,posURL3,posURL4,posURL5,posURL6;
    
    currUrl = String(self.location);
    
    currUrl = currUrl.toLowerCase();
    	 
    posURL1 = currUrl.indexOf("http://www.go-ultra.com");
    
    posURL2 = currUrl.indexOf("http://go-ultra.com");
    
    posURL3 = currUrl.indexOf("http://www.goultrasports.com");
    
    posURL4 = currUrl.indexOf("http://goultrasports.com");
	
	//posURL5 = currUrl.indexOf("http://goultratest2");
	
	posURL5 = currUrl.indexOf("http://192.168.200.8");
	
	posURL6 = currUrl.indexOf("http://121.241.77.229");
	
	if(posURL1 >= 0)
	{
	    FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"89fb9a953dc4eb0adf700008bbf22940", 
							"xd_receiver.htm"
						); 
					}
				); 
	}
   else if(posURL2 >= 0)
   {
       FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"89fb9a953dc4eb0adf700008bbf22940", 
							"xd_receiver.htm"
						); 
					}
				); 
   }
   else if(posURL3 >= 0)
   {
        FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"89fb9a953dc4eb0adf700008bbf22940", 
							"xd_receiver.htm"
						); 
					}
				); 
   }
   else if(posURL4 >= 0)
   {
        FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"89fb9a953dc4eb0adf700008bbf22940", 
							"xd_receiver.htm"
						); 
					}
				);    
   }
   else if(posURL5 >= 0)
   {
          FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"21fc39d41c399f7383e75ab4e8d05ae6", 
							"xd_receiver.htm"
						); 
					}
				);       
   }
   else if(posURL6 >= 0)
   {
        FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"9ff0f0c98159ed46f8ed389e890abab7", 
							"xd_receiver.htm"
						); 
					}
				);     
   }
   else
   {
       FB_RequireFeatures(
					["XFBML"], 
					function(){ 
						FB.Facebook.init(
							"21fc39d41c399f7383e75ab4e8d05ae6", 
							"xd_receiver.htm"
						); 
					}
				);     
   }
}

function setCookie(name, value, seconds) 
{
	if (typeof(seconds) != 'undefined') 
	{
		var date = new Date();
		date.setTime(date.getTime() + (seconds*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else 
	{
		var expires = "";
	}

	document.cookie = name+"="+value+expires+"; path=/";
}
 
function getCookie(name) 
{
	name = name + "=";
	var carray = document.cookie.split(';');
	for(var i=0;i < carray.length;i++) {
		var c = carray[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
	}
    return null;
}
 
function deleteCookie(name) 
{
	setCookie(name, "", -1);
}

function swapImage(btnId,cssClassName) 
{ 
    document.getElementById(btnId).className =cssClassName; 
}

