function cgMessagePos(obj)
{

    var currentObjX = findPosX(obj);
    var currentObjY = findPosY(obj);
    var currentObjH = obj.offsetHeight;
    var currentObjW = obj.offsetWidth;
    var top = parseInt(currentObjY) + currentObjH + 4;
    $('errorMsg').style.top = top + 'px';
    $('errorMsg').style.left = currentObjX + 'px';
    return;
}

function setupErrorMsg(obj)
{
    $$('input.cgGearSpec, select.cgGearSpec').each(function(s)
    {
        if (errorItems[s.id]) 
        {
            $(s.id).style.backgroundColor = '#cc0033';
            $(s.id).style.color;
			$('cadButton'+CGN).value = 'has errors';
			$('cadButton'+CGN).style.color = '#cc0033';
			$('cadButton'+CGN).style.backgroundColor = 'silver';
			
			//this if...then is used to color the tabs red if there is an error
            if (s.id == 'cgKeyWidth' || s.id == 'cgKeyDepth') 
            {
                tabsError[0] = 'keywayTab';
                colorTabs('keywayTab', true);
            }
            
            if (obj != 'none') 
            {
                if (s.id == obj.id) 
                {
                    $('errorMsg').innerHTML = errorReasons[s.id];
                    cgMessagePos(obj);
                    $('errorMsg').show();
                }
            }
        }
        else 
        {
            $(s.id).style.backgroundColor = '#ffffff';			
        }
    });        
    
    if (obj != 'none') 
    {
        //$('errorMsg').style.display = '';
    }
    return;
}

function clearErrorMsg(obj)
{
    $('errorMsg').hide()
    $('errorMsg').innerHTML = '';
    var bcm = '';
    $$('input.cgGearSpec, select.cgGearSpec').each(function(s)
    {
    
	    $('cadButton'+CGN).value = 'get CAD';
		$('cadButton'+CGN).style.color = '#ffffff';
		$('cadButton'+CGN).style.backgroundColor = '#708090';
        if (errorItems[s.id] === false && $(s.id).disabled === false) 
        {
            $(s.id).style.backgroundColor = '#ffffff';
            $(s.id).style.color = '#000000';
        }
        else 
        {
            if (!$(s.id).disabled) 
            {
                $(s.id).style.backgroundColor = '#cc0033';
                $(s.id).style.color = '#ffffff';
            }
        }
        
        
        if (s.id == 'cgKeyWidth' || s.id == 'cgKeyDepth') 
        {
            tabsError[0] = '';
            colorTabs('keywayTab', false);
        }
        
    });
    
    return;
}

function hideErrorMsg()
{
    $('errorMsg').hide();
}

function compareGears()
{
    var equalGear = new Array();
    var notEqualGear = new Array();
    var valArray = new Array();
	var diff = '';
    
    for (x = 1; x < gearCounter; x++) 
    {
        var bcm = '';
		
        for (y=0;y<gear[x].library.length;y++)
        {
			id=gear[x].library[y];
			
			if(id != 'partno')
            {
                if (typeof gear[x][id] != 'function' && typeof gear[x][id] != 'object') 
                {
                    if (gear[x][id] != gear[CGN][id]) 
                    {					
                        notEqualGear.push(x);
                        break;
                    }
                }
                else 
                {
					if (typeof gear[x][id] != 'object') 
					{
						val1 = gear[x][id]().toString();
						val2 = gear[CGN][id]().toString();
						
						if (val1 != val2) 
						{
							notEqualGear.push(x);
							break;
						}
					}
                }
            }
        }
		
        if (notEqualGear.indexOf(x) == '-1' && x != CGN) 
        {
            equalGear.push(x);
        }    		   
    }
		
    if (equalGear.length == 0) 
    {
        equalGear[0] = 'none';
    }	
	
    return equalGear;
}
