
var http = null;
    
//************************************
// returns the HTTP object
//************************************
function getHttpObject( )
{   
    httpObj = null;
    
    try
    {
        if( window.ActiveXObject )
            httpObj = new ActiveXObject("Microsoft.XMLHTTP");
        else
            httpObj = new XMLHttpRequest();
    }
    catch( exception )
    {
        httpObj = null;
    }
        
    return httpObj;
}

//******************************************
// shows the pictures window
//******************************************
function displayPhotos( coupleID )
{
    window.open( "pictures.aspx?couple=" + coupleID, '_blank', 'width=600, height=400, top=200, left=200' );
}

//*********************************************
// displays a small window
//*********************************************
function showSmallWindow( url )
{
    window.open( url, '_blank', 'width=600, height=200, top=200, left=200' );
}

// *****************************************
// gets the resolution and changes the width
// of the site if the resolution is 800
// *****************************************
function checkResolution( div1, div2 )
{
    try
    {
        if( (screen.width <= 800) || (document.body.clientWidth <= 800) )
        {
            document.getElementById( div1 ).style.width = '100%';
            document.getElementById( div2 ).style.width = '100%';
        }
        else if( (screen.width <= 1024) || (document.body.clientWidth <= 1024) )
        {
            document.getElementById( div1 ).style.width = '85%';
            document.getElementById( div2 ).style.width = '85%';
        }
    }
    catch( exception )
    {
        // stay with default
    }
}

//***************************************************************
// changes the color of the message row when it's clicked on
//***************************************************************
function colorMessageRow( rowid, checkbox, checkedClass, uncheckedClass )
{
    var messageRow = document.getElementById( rowid );
    messageRow.className = (checkbox.checked? checkedClass : uncheckedClass);
}

//***************************************
// checks all the message checkboxes
//***************************************
function CheckAllMessages( checkAllBox )
{
    var checkboxes = document.getElementsByName( "message_checkbox" );
    for( var i = 0; i < checkboxes.length; i++ )
    {
        checkboxes[i].checked = checkAllBox.checked;
        var rowClass = "checked_message_row";
        if( !checkAllBox.checked )
        {
            rowClass = "odd_message_row";
            if( (i%2) == 0 )
                rowClass = "even_message_row";
        }
        document.getElementById( "row_" + checkboxes[i].value ).className = rowClass;
    }
}

//************************************************
// resets the profile views by reloading the page
// and passing the action=resetviews parameter
//************************************************
function resetProfileViews( )
{   
    if( !confirm("Are you sure you want to reset your profile views?") )
        return;
        
    http = getHttpObject( );
                
    // if we are able to get the http object let's do it ajax style
    if( http != null )
    {
        http.open( "GET", "ajax/ajax.aspx?func=ResetProfileViews", true );
        http.onreadystatechange = resetProfileViews_Callback;
        http.send( null );
    }
    else
        window.location = "profile.aspx?action=resetviews";
}

//******************************************
// gets the response from the ajax function
//******************************************
function resetProfileViews_Callback( )
{   
     if( http.readyState == 4 ) 
     {
        if( http.responseText.indexOf("ok") == -1 )
            alert( "Error: " + http.responseText );
        else
        {
            document.getElementById( "profile_views_span" ).innerHTML = "0";
        }
     }
}

//***************************************
// when the "don't know" link is clicked
//***************************************
function onSearchModeClick( )
{
    var zipCtrls = document.getElementById("zipCtrls");
    var cityCtrls = document.getElementById("cityCtrls");
    var stateCtrls = document.getElementById("stateCtrls");
    var searchModeField = document.getElementById("searchmode");
    var zipMode = (zipCtrls.style.display == 'block');
    
    // switch it from whatever it was
    if( zipMode )
    {
        zipCtrls.style.display = 'none';
        cityCtrls.style.display = 'block';
        stateCtrls.style.display = 'block';
        searchModeField.value = '1';
    }
    else
    {
        zipCtrls.style.display = 'block';
        cityCtrls.style.display = 'none';
        stateCtrls.style.display = 'none';
        searchModeField.value='0';
    }
}

//*******************************************************
// gets the reponse from the GetStateComboItems function
//*******************************************************
function getStateCombo( currState )
{       
    http = getHttpObject( );
                
    // if we are able to get the http object let's do it ajax style
    if( http != null )
    {
        http.open( "GET", "ajax/ajax.aspx?func=GetStateCombo&currstate=" + currState, true );
        http.onreadystatechange = getStateCombo_Callback;
        http.send( null );
    }
    else
        window.location = "profile.aspx?action=resetviews";
}

//*******************************************************
// gets the reponse from the GetStateComboItems function
//*******************************************************
function getStateCombo_Callback( )
{
    if( http.readyState == 4 ) 
     {
        if( http.responseText.indexOf("error") != -1 )
            alert( http.responseText );
        else
        {
            /* IE and Netscape don't set the innerHTML of a select tag very well. Instead we will set the innerHTML of
               the span tag that contains the select tag
            // set the inner HTML of the state combo
            document.getElementById( "state" ).innerHTML = http.responseText;
            */
            
            // through ajax, we got the entire HTML for the <select> element
            document.getElementById( "stateComboSpan" ).innerHTML = http.responseText;
        }
     }
}