//====================================================================================================
//    File Name        :    hub.js
//    # File Version: v 1.0
//    # Created By: Maulik Chandarana
//    # Created On: 20 June 2007
//    # Last Modified By:
//    # Last modified On:
//  # Purpose : This is file carries validation and other related function for HUB page.
//----------------------------------------------------------------------------------------------------

//====================================================================================================
//    Function Name    :    View_Full_Photo()
//    Created By: Maulik Chandarana
//    Created On: 21 June 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Open the member's full photo in pop up window
//  Parameters: intUserId : User Id.
//----------------------------------------------------------------------------------------------------
function View_Full_Photo(intUserId)
{
    window.open('member_photo.php?hdUserId='+intUserId+'&page=enlarge&pid=1&amp;h=420&amp;w=350&amp;popup=1','enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=550, height=450');
    return false;
}
var url = "getTextVal.php?user_id=";
var isWorking = false;
var http = getHTTPObject();
//====================================================================================================
//    Function Name    :    fnGetOnlineOfflineStatus()
//    Created By: Maulik Chandarana
//    Created On: 02 August 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Get the online/offline status for entered user id
//  Parameter : intUserId : User Id
//----------------------------------------------------------------------------------------------------
function fnGetOnlineOfflineStatus(strUserIds)
{
    if (!isWorking)
    {
        if (window.XMLHttpRequest)
        {            
            http = new XMLHttpRequest();
            http.open("GET", url + strUserIds, true);
            isWorking = true;
            http.onreadystatechange = handleHttpResponse;                        
            http.send(null);
            // branch for IE/Windows ActiveX version
        }
        else if (window.ActiveXObject)
        {            
            http = new ActiveXObject("Microsoft.XMLHTTP");
            if (http)
            {                                
                http.open("GET", url + strUserIds, true);
                isWorking = true;                
                http.onreadystatechange = handleHttpResponse;
                http.send();
            }
        }
    }
    setTimeout("fnGetOnlineOfflineStatus('"+strUserIds+"')", 1000); 
}
//====================================================================================================
//    Function Name    :    handleHttpResponse()
//    Created By: Maulik Chandarana
//    Created On: 02 August 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Getting values from XML data
//  Parameters:
//----------------------------------------------------------------------------------------------------
function handleHttpResponse()
{    
    if (http.readyState == 4)
    {
        isWorking = false;
        
        if (http.responseText.indexOf('invalid') == -1)
        {
            var xmlDocument = http.responseXML;            
            var number = xmlDocument.getElementsByTagName('status').length;
            for(i=0;i<number;i++)
            {
                var strStatus = xmlDocument.getElementsByTagName('status').item(i).firstChild.data;
                var intUserId = xmlDocument.getElementsByTagName('id').item(i).firstChild.data;
                document.getElementById("idStatus_"+intUserId).innerHTML = strStatus;
                isWorking = false;
            }
        }
    }
}
var urlComments = "getTextVal.php?user_id=";
var isWorkingComments = false;
var httpComments = getHTTPObject();
//====================================================================================================
//    Function Name    :    fnGetOnlineOfflineStatusComments()
//    Created By: Maulik Chandarana
//    Created On: 16 October 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Get the online/offline status for entered user id for comments section
//  Parameter : strUserId : User Ids
//----------------------------------------------------------------------------------------------------
function fnGetOnlineOfflineStatusComments(strUserIds)
{
    if (!isWorkingComments)
    {
        if (window.XMLHttpRequest)
        {            
            httpComments = new XMLHttpRequest();
            httpComments.open("GET", urlComments + strUserIds + "&page_type=comments", true);
            isWorkingComments = true;
            httpComments.onreadystatechange = handleHttpResponseComments;                        
            httpComments.send(null);
            // branch for IE/Windows ActiveX version
        }
        else if (window.ActiveXObject)
        {            
            httpComments = new ActiveXObject("Microsoft.XMLHTTP");
            if (httpComments)
            {                                
                httpComments.open("GET", urlComments + strUserIds + "&page_type=comments", true);
                isWorkingComments = true;                
                httpComments.onreadystatechange = handleHttpResponseComments;
                httpComments.send();
            }
        }
    }
    setTimeout("fnGetOnlineOfflineStatusComments('"+strUserIds+"')", 1000); 
}
//====================================================================================================
//    Function Name    :    handleHttpResponseComments()
//    Created By: Maulik Chandarana
//    Created On: 16 October 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Getting values from XML data for comments section
//  Parameters:
//----------------------------------------------------------------------------------------------------
function handleHttpResponseComments()
{    
    if (httpComments.readyState == 4)
    {
        isWorkingComments = false;
        
        if (httpComments.responseText.indexOf('invalid') == -1)
        {
            var xmlDocument = httpComments.responseXML;            
            var number = xmlDocument.getElementsByTagName('status').length;
            for(i=0;i<number;i++)
            {                
                var strStatus = xmlDocument.getElementsByTagName('status').item(i).firstChild.data;
                var intUserId = xmlDocument.getElementsByTagName('id').item(i).firstChild.data;
                document.getElementById("idStatus_"+i+"_"+intUserId).innerHTML = strStatus;
                isWorkingComments = false;
            }
        }
    }    
}
//====================================================================================================
//    Function Name    :    Click_Change_Tag()
//    Created By: Maulik Chandarana
//    Created On: 30 November 2007
//    Last Modified By:
//    Last modified On:
//  Purpose : Redirect user to member section
//  Parameters:
//----------------------------------------------------------------------------------------------------
function Click_Change_Tag(intTagId,intSessUserId)
{   	
	if(intSessUserId != "")
    {
        if(confirm("Are You Sure That You Want To TAG This User Now?"))
        {            
            frmHub.hdMode.value = "Add Tag";
            frmHub.submit();
        }     
    }
	else
	{
    	var intEncryptedUserId = frmHub.hdEncryptedUserId.value;
		window.location.href="member/hub.php?hdUserId="+intEncryptedUserId;	
	}
}
