// PNG fix for IE5.5 & IE6
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
       var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
       var imgTitle = (myImage.title) ? 
                     "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
       var imgStyle = "display:inline-block;" + myImage.style.cssText
       var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
       myImage.outerHTML = strNewHTML	  
    }
}

// gray out the Match button to prevent multiple clicks
function DisableMatchColorButton()
{           
    document.getElementById('btnMatch').style['color'] = '#AFAFAF';
    document.getElementById('btnMatch').style['background'] = '#EFEFEF'; 
    document.getElementById('btnMatch').style['border'] = '1px solid #7F9DB9';
    document.getElementById('btnMatch').value = 'searching...';       
    var cbn = document.getElementById('cbncode').innerHTML;
    document.location.href = 'results.aspx?find=' + cbn;            
}        
                                         

// arrays to reduce flicker
var arr;
var arrCBN;
var arrRating;
var arrGamut

// flash colorchart color is clicked
function callback(colorpos, name, color){
    var cb = document.getElementById("productid");
    var productid = cb.value;    
                                   
    document.getElementById('colorname').innerHTML = '<h4>' + name + '</h4>';
    document.getElementById('color').style.backgroundColor = '#'+color;   
    
    document.getElementById('cbncode').innerHTML = arrCBN[colorpos];
    document.images["rating"].src = '../images/' + arrRating[colorpos] + 'star.gif';
    
    if(arrRating[colorpos] > 2)
        document.getElementById('btnMatch').style.display = "inline";            
    else
        document.getElementById('btnMatch').style.display = "none";
        
    if(arrGamut[colorpos] == -1)
        document.getElementById('gamutwarning').style.visibility = 'visible';
    else
        document.getElementById('gamutwarning').style.visibility = 'hidden';    
}      

// Return data from the Call back function
function ReceiveServerData(rValue)
{     
    arr = rValue.split("^") 
                
    if(arr[0] == "fandeck"){     
        arrCBN = arr[7].split("~");
        arrRating = arr[8].split("~");
        arrGamut = arr[9].split("~");  
        SetColorChartValues(arr);
    }    
} 

function SetColorChartValues(arr){
    document.getElementById('productsdata').style.display = 'none';
    document.getElementById('cbfandeck').style.display = 'block';
    document.getElementById('flashcontent').style.display = 'block';
    document.getElementById('cbcolordata').style.display = 'block';
            
    // flash object   
    var so = new SWFObject('../include/colors.swf', 'colors', 748, 260 , '8', '#ffffff');
    so.addParam('wmode', 'transparent');
		so.addParam('menu', 'false');
    so.addVariable('FlashVars', arr[1]);
    so.write('flashcontent');            
     
    callback(arr[2], arr[3], arr[4]);
}
