var LastTabId = 1;

/*** PRELOAD TAB IMAGES ****/
var img1 = new Image();
img1.src = "/images/shopper_step2_earrings_on.jpg";
var img2 = new Image();
img2.src = "/images/shopper_step2_pendants_on.jpg";
var img3 = new Image();
img3.src = "/images/shopper_step2_fashion_rings_on.jpg";
var img4 = new Image();
img4.src = "/images/shopper_step2_bracelets_on.jpg";
var img5 = new Image();
img5.src = "/images/shopper_step2_watches_on.jpg";
var img6 = new Image();
img6.src = "/images/shopper_step2_earrings_off.jpg";
var img7 = new Image();
img7.src = "/images/shopper_step2_pendants_off.jpg";
var img8 = new Image();
img8.src = "/images/shopper_step2_fashion_rings_off.jpg";
var img9 = new Image();
img9.src = "/images/shopper_step2_bracelets_off.jpg";
var img10 = new Image();
img10.src = "/images/shopper_step2_watches_off.jpg";
var img11 = new Image();
img11.src = "/images/shopper_step2_eringsolitaire_off.jpg";
var img12 = new Image();
img12.src = "/images/shopper_step2_eringsidestones_off.jpg";
var img13 = new Image();
img13.src = "/images/shopper_step2_wbmens_off.jpg";
var img14 = new Image();
img14.src = "/images/shopper_step2_wbladies_off.jpg";
var img15 = new Image();
img15.src = "/images/shopper_step2_eringsolitaire_on.jpg";
var img16 = new Image();
img16.src = "/images/shopper_step2_eringsidestones_on.jpg";
var img17 = new Image();
img17.src = "/images/shopper_step2_wbmens_on.jpg";
var img18 = new Image();
img18.src = "/images/shopper_step2_wbladies_on.jpg";

function SetPostData()
{
    document.refine_form.doRedirect.value = "1"; 
    document.refine_form.updateFilters.value = "1";
    document.refine_form.submit();
    AlertOnSaveSearch();
}

function ReplaceImageWith( currElement, replaceWith )
{
    currElement.src = replaceWith;
}

function DoImageClick( imageElement, checkboxElement, onImage, offImage )
{   
    if( document.getElementById( checkboxElement ).checked ) 
    {
        // Return if no box is checked 
        var checkedCatsArray = BuildCheckedCategoriesArray();
        if( checkedCatsArray.length <= 1 ) {
            alert( "You must have at least on category selected." );
            return;
        }
        document.getElementById( checkboxElement ).checked = false;
        ReplaceImageWith( document.getElementById( imageElement ), offImage );
    }
    else 
    {
        document.getElementById( checkboxElement ).checked = true; 
        ReplaceImageWith( document.getElementById( imageElement ), onImage );
    }
    
    // Get the current classname of the current tab
    var highlightedGroup = document.getElementById( "highlightedGroup" ).value;
    var currMinClassName = document.getElementById( highlightedGroup + "_minHeightDiv" ).className;
    document.getElementById( highlightedGroup + "_minHeightDiv" ).className = "";
    
    // Remove/Add category info based on the selected element
    ShowHideCategoryInfo( checkboxElement );
    
    // Set new mininum class based on the number of active tabs
    document.getElementById( highlightedGroup + "_minHeightDiv" ).className = SetMinimumClassName();
}	  
 
function SetMinimumClassName()
{
    var totalActiveTabs = 0;
    var newMinClass = "bodyMinHeight";
    
    // In order to set minimum class name, we need a total ACTIVE tab count.
    // The most accurate way to do this is to loop through all tables and 
    // check the tab image as it currently is.  if that tab image is hidden, 
    // then it's not currently active.
    currGroups = document.getElementById( "currGroups" ).value;
    var groupArray = currGroups.split( "," );
    for( i = 0; i <= groupArray.length - 1; i++ )
    {
        var currTabImg = document.getElementById( groupArray[i] + "_tab" );
        if( currTabImg.style.visibility != "hidden" ) { totalActiveTabs++; }
    }
    
    // Only set a minimum height if the total number of active tabs greater than 7
    if( totalActiveTabs > 7 ) {
        newMinClass = "bodyMinHeight" + totalActiveTabs;
    }
    
    return( newMinClass );
}
        
function ShowHideCategoryInfo( checkboxElement )
{   
    // Build checkbox categorys to get the actual elemetnts affected by the checked element
    var localCheckedCats = BuildAllCheckboxCategoriesArray();
    var currCats = "";
    for( i = 0; i <= localCheckedCats.length - 1; i++ )
    {
        if( localCheckedCats[i][0] == checkboxElement ) {
            currCats = localCheckedCats[i][1];
        }
    }
    
    // If we got here, things are not right.  Just return.  Sorry buddy.
    if( currCats == "" ) { return; }
    
    // The following elements may or may not be affected by checking this box
    // 1. _tab (image)
    // 2. _options (container)
    // 3. _optionGroup (internal containers for individual elements)
    // If the tab exists only for this grouping, we need to remove both the _tab and _options.
    // To find the grouping, we need to check the _matchingCats elements of each group and compare 
    // it to the categories affected by the element checked.
    currGroups = document.getElementById( "currGroups" ).value;
    var groupArray = currGroups.split( "," );
    var actionArray = new Array();
    var removeArray = new Array(); // For items that are removed (i.e. don't match at all)
    var highlightedGroup = document.getElementById( "highlightedGroup" ).value;
    var highlightedGroupRemoved = false; // This is to check if we are hiding the currently selected tab
    
    for( i = 0; i <= groupArray.length - 1; i++ )
    {
        // Add all possible options (some checkboxes are linked to multiple categories, i.e. watches)
        if( currCats.indexOf( "," ) > -1 ) 
        {
            var currCatsArray = currCats.split( "," )
            for( j = 0; j < currCatsArray.length; j++ ) {
                actionArray[actionArray.length] = groupArray[i] + "_" + currCatsArray[j] + "_optionGroup";
            }
        }
        // If there is not ",", then its not multiple and we just need this one category
        else {
            actionArray[actionArray.length] = groupArray[i] + "_" + currCats + "_optionGroup";
        }
        
        // Find all matching categories and compare.
        var matchingCategories = document.getElementById( groupArray[i] + "_matchingCats" ).value;
        matchingCategories = matchingCategories.substr( 0, matchingCategories.length - 1 );
        
        // If an EXACT match is found, hide/show the whole group including tab.
        if( currCats == matchingCategories ) 
        {
            if( parseInt( groupArray[i] ) == parseInt( highlightedGroup ) ) { highlightedGroupRemoved = true; }
            actionArray[actionArray.length] = groupArray[i] + "_tab";
            actionArray[actionArray.length] = groupArray[i] + "_options";
        }
        /****
        If the category is not an exact match, we need to see if any of the other
        categories are actually selected.  If they are not, we have to remove this
        tab as well becuse all other categories found is this group are already 
        gone.
        ****/
        else
        {
            var checkedCatsArray = BuildCheckedCategoriesArray();
            var matchingCategoriesArray = matchingCategories.split(",");
            isChecked = false;
            
            // Iterate through all currently matching categories found
            for( j = 0; j < matchingCategoriesArray.length; j++ ) 
            {
                // Check categories against groups that are checked currently
                for( k = 0; k < checkedCatsArray.length; k++ ) 
                {
                    // Some checked groups are linked to multiple categories via comma (,)
                    if( checkedCatsArray[k][1].indexOf( "," ) > 0 ) 
                    {
                        var currCatCheckArray = checkedCatsArray[k][1].split(",");
                        for( m = 0; m < currCatCheckArray.length; m++ ) 
                        {
                            if( currCatCheckArray[m] == matchingCategoriesArray[j] ) {
                                isChecked = true;
                            }
                        }
                    
                    }
                    // If there is no comma then its a 1/1 ratio
                    else
                    {
                        if( matchingCategoriesArray[j] == checkedCatsArray[k][1] ) {
                            isChecked = true;
                        }
                    }
                }
            }
            
            // Add actions as necessary
            if( ! isChecked &&  ! document.getElementById( checkboxElement ).checked )
            {
                if( parseInt( groupArray[i] ) == parseInt( highlightedGroup ) ) { highlightedGroupRemoved = true; }
                actionArray[actionArray.length] = groupArray[i] + "_tab";
                actionArray[actionArray.length] = groupArray[i] + "_options";
            }
            else if( isChecked &&  document.getElementById( checkboxElement ).checked )
            {
                actionArray[actionArray.length] = groupArray[i] + "_tab";
                actionArray[actionArray.length] = groupArray[i] + "_options";
            }
        }              
    }
    
    // Iterate through action array and show/hide as necessary
    // Note: We are not hiding any information within the currently highlighted container (if applicable).
    for( i = 0; i <= actionArray.length - 1; i++ ) 
    {   
        if( document.getElementById( actionArray[i] ) )
        {
            if( document.getElementById( checkboxElement ).checked )
            {
                var highlightedGroup = document.getElementById( "highlightedGroup" ).value;
                var localLoopGroup = actionArray[i].substr( 0, actionArray[i].indexOf( "_" ) );
                if( highlightedGroup == localLoopGroup || actionArray[i].indexOf( "_tab" ) > -1 )
                {
                    document.getElementById( actionArray[i] ).style.visibility = "visible";
                    document.getElementById( actionArray[i] ).style.position = "relative";
                    document.getElementById( actionArray[i] ).style.left = "0px";
                    document.getElementById( actionArray[i] ).style.top = "0px";
                }
            }
            else 
            {
                document.getElementById( actionArray[i] ).style.visibility = "hidden";
                document.getElementById( actionArray[i] ).style.position = "absolute";
                document.getElementById( actionArray[i] ).style.left = "-400px";
                document.getElementById( actionArray[i] ).style.top = "-400px";
            }
        }
    }
    
    // If the currently hightlighted group was removed, show the first group that isn't hidden
    if( highlightedGroupRemoved )
    {
        var validGroupId = FindGroupIdMatchForCategoryString();
        if( validGroupId ) { ShowTab( validGroupId ); }
    }
}
 
function FindGroupIdMatchForCategoryString()
{
    var checkedCatsArray = BuildCheckedCategoriesArray();
    var currGroups = document.getElementById( "currGroups" ).value;
    var currGroupArray = currGroups.split( "," );
    var returnGroupId = null;
    
    for( var i = 0; i < currGroupArray.length; i++ )  
    {
        var matchingCategories = document.getElementById( currGroupArray[i] + "_matchingCats" ).value;
        matchingCategories = matchingCategories.substr( 0, matchingCategories.length - 1 );
        matchingCatsArray = matchingCategories.split( "," );
        for( var j = 0; j < matchingCatsArray.length; j++ )
        {
            for( var k = 0; k < checkedCatsArray.length; k++ ) 
            {
                if( checkedCatsArray[k][1].indexOf( "," ) > -1 ) 
                {
                    var currCatsArray = checkedCatsArray[k][1].split( "," );
                    for( l = 0; l < currCatsArray.length; l++ ) 
                    {
                        if( parseInt( currCatsArray[l] ) == parseInt( matchingCatsArray[j] ) ) {
                            returnGroupId = currGroupArray[i];
                            break;
                        }
                    }
                }
                else 
                {
                    if( parseInt( checkedCatsArray[k][1] ) == parseInt( matchingCatsArray[j] ) ) {
                        returnGroupId = currGroupArray[i];
                        break;
                    }
                }
                
                if( returnGroupId ) { break; }
            }
            
            if( returnGroupId ) { break; }
        }
        
        if( returnGroupId ) { break; }
    }
    
    return( returnGroupId );
}
            
function DoCheckBoxClick( imageElement, checkboxElement, onImage, offImage )
{   
	if( ! document.getElementById( checkboxElement ).checked ) 
    {
        // Return if no box is checked 
        var checkedCatsArray = BuildCheckedCategoriesArray();
        if( checkedCatsArray.length == 0 ) {
            alert( "You must have at least on category selected." );
            return;
        }
        ReplaceImageWith( document.getElementById( imageElement ), offImage );
    }
    else 
    {
        ReplaceImageWith( document.getElementById( imageElement ), onImage );
    }
    
    // Get the current classname of the current tab
    var highlightedGroup = document.getElementById( "highlightedGroup" ).value;
    var currMinClassName = document.getElementById( highlightedGroup + "_minHeightDiv" ).className;
    document.getElementById( highlightedGroup + "_minHeightDiv" ).className = "";
    
    // Remove/Add category info based on the selected element
    ShowHideCategoryInfo( checkboxElement );
    
    // Set new mininum class based on the number of active tabs
    document.getElementById( highlightedGroup + "_minHeightDiv" ).className = SetMinimumClassName();
}	   
  
function ShowFilters()
{
    HideAllOptions();
    document.getElementById( "showButton" ).src = "/images/filter_tab_show_on.jpg";
    document.getElementById( "hideButton" ).src = "/images/filter_tab_hide_off.jpg";
    document.getElementById( "hideContent" ).style.visibility = "hidden";
    document.getElementById( "hideContent" ).style.position = "absolute";
	document.getElementById( "hideContent" ).style.left = "-400px";
    document.getElementById( "hideContent" ).style.top = "-400px";
    document.getElementById( "showContent" ).style.visibility = "visible";
    document.getElementById( "showContent" ).style.position = "relative";
	document.getElementById( "showContent" ).style.left = "0px";
    document.getElementById( "showContent" ).style.top = "0px";
     
    var LastTabId = document.getElementById( "initialGroup" ).value;
    if( document.getElementById( "highlightedGroup" ).value != "" ) {
        LastTabId = document.getElementById( "highlightedGroup" ).value;
    }
    
    
    if( isShopper )
    {
        var checkedCats = BuildCheckedCategoriesArray();
        for( var i = 0; i < checkedCats.length; i++ ) {
            ShowHideCategoryInfo( checkedCats[i][0] );
        }
        document.getElementById( "999_tab" ).style.visibility = "visible";
        document.getElementById( "999_tab" ).style.position = "relative";
        document.getElementById( "999_tab" ).style.left = "0px";
    	document.getElementById( "999_tab" ).style.top = "0px";
	
        // Set new mininum class based on the number of active tabs
        document.getElementById( LastTabId + "_minHeightDiv" ).className = SetMinimumClassName();
    }
    else 
    {
        var currTab = document.getElementById( "highlightedGroup" ).value;
        currGroups = document.getElementById( "currGroups" ).value;
        var groupArray = currGroups.split( "," );
        for( i = 0; i <= groupArray.length - 1; i++ )
        {   
            document.getElementById( groupArray[i] + "_tab" ).style.visibility = "visible";
            document.getElementById( groupArray[i] + "_tab" ).style.position = "relative";
			document.getElementById( groupArray[i] + "_tab" ).style.left = "0px";
	    	document.getElementById( groupArray[i] + "_tab" ).style.top = "0px";
        }
    
        document.getElementById( "999_tab" ).style.visibility = "visible";
        document.getElementById( "999_tab" ).style.position = "relative";
		document.getElementById( "999_tab" ).style.left = "0px";
    	document.getElementById( "999_tab" ).style.top = "0px";
    }
    
    ShowTab( LastTabId );
}   

function HideFilters()
{
    var currTab = document.getElementById( "highlightedGroup" ).value;
    currGroups = document.getElementById( "currGroups" ).value;
    var groupArray = currGroups.split( "," );
    for( i = 0; i <= groupArray.length - 1; i++ )
    {   
        document.getElementById( groupArray[i] + "_tab" ).style.visibility = "hidden";
        document.getElementById( groupArray[i] + "_tab" ).style.position = "absolute";
		document.getElementById( groupArray[i] + "_tab"  ).style.left = "-400px";
    	document.getElementById( groupArray[i] + "_tab" ).style.top = "-400px";
    }
    
    HideAllOptions();
    document.getElementById( "showButton" ).src = "/images/filter_tab_show_off.jpg";
    document.getElementById( "hideButton" ).src = "/images/filter_tab_hide_on.jpg";
    document.getElementById( "hideContent" ).style.visibility = "visible";
    document.getElementById( "hideContent" ).style.position = "relative";
	document.getElementById( "hideContent" ).style.left = "0px";
    document.getElementById( "hideContent" ).style.top = "0px";
    document.getElementById( "showContent" ).style.visibility = "hidden";
    document.getElementById( "showContent" ).style.position = "absolute";
	document.getElementById( "showContent" ).style.left = "-400px";
    document.getElementById( "showContent" ).style.top = "-400px";
}

function ShowRefineFromPS()
{
    menu1.closeDivSelection('personalShopper', 'personalShopperContents');
    ShowFilters();
    location.href = "#jumpToContent";
}

function ShowTab( currTabId )
{   
    HideAllOptions();
    
    // Build category array with items that are checked
    var checkedCatsArray = BuildCheckedCategoriesArray();
    
    // Build matching groups for this tab
    var matchingCategories = document.getElementById( currTabId + "_matchingCats" ).value;
    matchingCategories = matchingCategories.substr( 0, matchingCategories.length - 1 );
    matchingCatsArray = matchingCategories.split( "," );
                    
    // Show necessary elements based on what is tab was clicked
    document.getElementById( currTabId + "_tab" ).src = document.getElementById( currTabId + "_tabOnImg" ).value;
    document.getElementById( currTabId + "_tab" ).style.position = "relative";
    document.getElementById( currTabId + "_tab" ).style.visibility = "visible";
	document.getElementById( currTabId + "_tab" ).style.left = "0px";
    document.getElementById( currTabId + "_tab" ).style.top = "0px";
	
    document.getElementById( currTabId + "_options" ).style.position = "relative";
    document.getElementById( currTabId + "_options" ).style.visibility = "visible";
	document.getElementById( currTabId + "_options" ).style.left = "0px";
    document.getElementById( currTabId + "_options" ).style.top = "0px";
    document.getElementById( currTabId + "_options" ).style.width = "507px";
	
    document.getElementById( "highlightedGroup" ).value = currTabId;               
    LastTabId = currTabId;
		
    // Show all internal elements that need to be shown        
    for( var j = 0; j < matchingCatsArray.length; j++ )
    {   
		var optionGroupElement = document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" );
		
        if( optionGroupElement ) 
        {
            // verify that the category is ok to show
            for( var k = 0; k < checkedCatsArray.length; k++ ) 
            {
                // Add all possible options (some checkboxes are linked to multiple categories, i.e. watches)
                if( checkedCatsArray[k][1].indexOf( "," ) > -1 ) 
                {
                    var currCatsArray = checkedCatsArray[k][1].split( "," );
                    for( l = 0; l < currCatsArray.length; l++ ) 
                    {
                        if( parseInt( currCatsArray[l] ) == parseInt( matchingCatsArray[j] ) )
                        {
                            document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.visibility = "visible";
                            document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.position = "relative";
                            document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.left = "0px";
                            document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.top = "0px";
                            document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.width = "475px";
                        }
                    }
                }
                // If there is not ",", then its not multiple and we just need this one category
                else 
                {
                    if( parseInt( checkedCatsArray[k][1] ) == parseInt( matchingCatsArray[j] ) )
                    {
                        document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.visibility = "visible";
                        document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.position = "relative";
                        document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.left = "0px";
                        document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.top = "0px";
                        document.getElementById( currTabId + "_" + matchingCatsArray[j] + "_optionGroup" ).style.width = "475px";
                    }
                }
            }
        }
    }
    
    // Set new minimum class here
    document.getElementById( currTabId + "_minHeightDiv" ).className = SetMinimumClassName();
}

function HideAllOptions()
{
    var currGroups = document.getElementById( "currGroups" ).value;
    var currGroupArray = currGroups.split( "," );
    
    for( var i = 0; i < currGroupArray.length; i++ )  
    {
        document.getElementById( currGroupArray[i] + "_tab" ).src = document.getElementById( currGroupArray[i] + "_tabOffImg" ).value;
        document.getElementById( currGroupArray[i] + "_options" ).style.visibility = "hidden";
        document.getElementById( currGroupArray[i] + "_options" ).style.position = "absolute";
        document.getElementById( currGroupArray[i] + "_options" ).style.left = "-400px";
        document.getElementById( currGroupArray[i] + "_options" ).style.top = "-400px";
        var matchingCategories = document.getElementById( currGroupArray[i] + "_matchingCats" ).value;
        matchingCategories = matchingCategories.substr( 0, matchingCategories.length - 1 );
        matchingCatsArray = matchingCategories.split( "," );
        for( var j = 0; j < matchingCatsArray.length; j++ )
        {
            var optionGroupElement = document.getElementById( currGroupArray[i] + "_" + matchingCatsArray[j] + "_optionGroup" );
            if( optionGroupElement ) 
            {
                document.getElementById( currGroupArray[i] + "_" + matchingCatsArray[j] + "_optionGroup" ).style.visibility = "hidden";
                document.getElementById( currGroupArray[i] + "_" + matchingCatsArray[j] + "_optionGroup" ).style.position = "absolute";
                document.getElementById( currGroupArray[i] + "_" + matchingCatsArray[j] + "_optionGroup" ).style.left = "-400px";
                document.getElementById( currGroupArray[i] + "_" + matchingCatsArray[j] + "_optionGroup" ).style.top = "-400px";
            }
        }
    }
}

function BuildCheckedCategoriesArray()
{
    var checkedCatsArray = new Array();
    var checkboxCategories = document.getElementById( "checkboxGroups" ).value;
    checkboxCategories = checkboxCategories.substr( 0, checkboxCategories.length - 1 );
    checkboxCatsArray = checkboxCategories.split( ";" );
    
    // Iterate through checkbox categories to find which categories link to which checkboxes
    for( var i = 0; i < checkboxCatsArray.length; i++ )
    {
        var checkboxData = checkboxCatsArray[i].split( "=" );
        if( isShopper ) 
        {
        	if( document.getElementById( checkboxData[0] ) )
        	{
        	    if( document.getElementById( checkboxData[0] ).checked ) 
        	    {
        	        checkCatsArrayTemp = checkboxData[1].split( "," );                                     
        	         var index = checkedCatsArray.length;
        	         checkedCatsArray[index] = new Array( checkboxData[0], checkboxData[1] );
        	    }
        	}
		}
		else // Its not the shopper, so its checked (hidden)
		{
			checkCatsArrayTemp = checkboxData[1].split( "," );                                     
        	var index = checkedCatsArray.length;
			checkedCatsArray[index] = new Array( checkboxData[0], checkboxData[1] );
		}			
			        	
    }
    
    return( checkedCatsArray );
}

function BuildAllCheckboxCategoriesArray()
{
    var checkedCatsArray = new Array();
    var checkboxCategories = document.getElementById( "checkboxGroups" ).value;
    checkboxCategories = checkboxCategories.substr( 0, checkboxCategories.length - 1 );
    checkboxCatsArray = checkboxCategories.split( ";" );
    
    for( var i = 0; i < checkboxCatsArray.length; i++ )
    {
        var checkboxData = checkboxCatsArray[i].split( "=" );
        if( document.getElementById( checkboxData[0] ) )
        {
            var index = checkedCatsArray.length;
            checkedCatsArray[index] = new Array( checkboxData[0], checkboxData[1] );
        }
    }
    
    return( checkedCatsArray );
}

function ClearBox()
{
  if( document.getElementById( "SaveSearchBox" ).value == "Choose a name" ) {
      document.getElementById( "SaveSearchBox" ).value = "";
  }
}

function AlertOnSaveSearch()
{
    if( document.getElementById( "SaveSearchBox" ).value != "" && document.getElementById( "SaveSearchBox" ).value != "Choose a name" ) {
          var msg = "You have requested to save this search.\n\n"
                  + "You will be able to access this search by moving your mouse\n"
                  + "over the Personal Shopper image at the top right hand corner\n"
                  + "of the page.\n\nYour last 5 saved searches will be shown.";
                  
          alert( msg );              
     }
} 

function ResetAllFilters()
{
	var msg = "You have requested to reset all of your criteria.\n\n"
	        + "Click OK to continue or CANCEL to leave your criteria\n"
	        + "as is.";
	if( confirm( msg ) ) 
	{
		checkboxes=document.getElementsByTagName('input');
		for(i in checkboxes)
		{
			var currName = checkboxes[i].name;
			if( currName ) 
			{
				if( currName.indexOf( "checkbox_" ) >= 0 ) {
					checkboxes[i].checked = true;
				}
			}
		}
	}		
}