/* 
	simple browser check
*/
var dom = (document.getElementById)? true : false;
var ie4 = (document.all)? true : false;
var ns4 = (document.layers)? true : false;

var thefinaldomain = 'http://corpcomm.qualcomm.com';

function toggle_visibility(id) {
	if (ie4) obj = document.all[id];
	if (dom) obj = document.getElementById(id);	
	if (ns4) return;

	imageID = id + "Image";
    if (obj.style.display == "block") {
    	obj.style.display='none';
		document.images[imageID].src = thefinaldomain + '/images/tabs/saved_resrouces.gif'
    } else {
    	obj.style.display='block';
		document.images[imageID].src = thefinaldomain + '/images/tabs/saved_resrouces.gif'
    }
    return false;
}


function toggle_visibility2(id) {
	if (ie4) obj = document.all[id];
	if (dom) obj = document.getElementById(id);	
	if (ns4) return;

	imageID = id + "Image";
    if (obj.style.display == "block") {
    	obj.style.display='none';
		document.images[imageID].src = '/images/tabs/saved_images.gif'
    } else {
    	obj.style.display='block';
		document.images[imageID].src = '/images/tabs/saved_images.gif'
    }
    return false;
}

function toggle_visibility3(id) {
	if (ie4) obj = document.all[id];
	if (dom) obj = document.getElementById(id);	
	if (ns4) return;

	imageID = id + "Image";
    if (obj.style.display == "block") {
    	obj.style.display='none';
		document.images[imageID].src = '/images/tabs/recent_searches.gif'
    } else {
    	obj.style.display='block';
		document.images[imageID].src = '/images/tabs/recent_searches.gif'
    }
    return false;
}


//Receives an array of checkboxes and uncheck all of them
function unCheckCheckboxes(array) {
	for(i=0 ; i < array.length ; i++)
	{
		id = array[i];
		if (ie4) obj = document.all[id];
		if (dom) obj = document.getElementById(id);	
		if (ns4) return;
		obj.checked = false;
	}
    return false;
}

//  variables used to keep track of previous shown elements
var oldDropDown = "";

// generic function to show or hide an element. Will also close the previously opened element called by this function
function showHide(id, dragIt)
{
    var element = document.getElementById(id);
    if(oldDropDown != "" && oldDropDown != element)
    {
        oldDropDown.style.display = "none";
        element.style.display = "block";
    }
    else
    {
        element.style.display = (element.style.display == "block") ? "none" : "block";
    }
    
    oldDropDown = element;
    if(dragIt)
        new Draggable(id,{revert:false});
}

// simulates a drop down menu - id of element to show, parent element of id, the option the user clicked is clicking on
function pullDown(id, parentElement, selectedFilter)
{
    showHide(id);
    var parentElement = document.getElementById(parentElement);
    var filterChoice = parentElement.firstChild;
    filterChoice.innerHTML = selectedFilter;
}

// shows and hides the event detail box
function showHideEvent(id)
{
    var eventParent = document.getElementById(id);
    var element = document.getElementById(id + "Details");
    var eventRow = document.getElementById(id + "Row");
    eventRow.className = "";    // erase the background color of the row
    
    // this section changes the expand icon
    var tds = eventParent.getElementsByTagName("td");
    for(var x = 0; x < tds.length; x++)
    {
        //alert(x);
        if(tds[x].className == "nameCol")
        {
            var expandLink = tds[x].firstChild;
            if (expandLink.style.backgroundImage == "url(" + safariPath + "media/icon_contract.gif)")
                expandLink.style.backgroundImage = "url(" + safariPath + "media/icon_expand.gif)"
            else    
                expandLink.style.backgroundImage = "url(" + safariPath + "media/icon_contract.gif)";
            x = tds.length;
            var backgroundImage = expandLink.style.backgroundImage
            //alert(backgroundImage);
        }
        
    }
    
    var number = (id.substring(5, 7) % 2);      // check to see if the row is an odd number
    // if this is the first time the function is called
    if(oldEvent != "" && oldEvent != element)
    {
        oldEvent.style.display = "none";
        oldParent.style.backgroundImage = "none";
        var number2 = (oldRow.id.substring(5, 7) % 2);
        // if the old row is even, give it a background color
        if(!number2)
            oldRow.className = "altRow";
        element.style.display = "block";
        eventParent.style.background = "url(" + safariPath + "media/event_details_back_top2.gif) no-repeat left top";
    }
    else
    {
        element.style.display = (element.style.display == "block") ? "none" : "block";
        // check to see if a background image has been applied. The "none" check is for IE since it sees url() as none
        if(eventParent.style.background == "" || eventParent.style.backgroundImage == "url()" || eventParent.style.backgroundImage == "none")
        {
            eventParent.style.background = "url(" + safariPath + "media/event_details_back_top2.gif) no-repeat left top";
        }
        else
        {
            eventParent.style.background = "none";
            // if the row is even, give it a background color
            if(!number)
                eventRow.className = "altRow";
        }
    }
    oldEvent = element;         // tracking the last event detail
    oldParent = eventParent;    // tracking the last event box
    oldRow = eventRow;          // tracking the last event row to help with assigning row background color
    //alert(oldRow.id);
}