﻿function ShowPalette(obj)
{
    var PosLeft = GetAbsoluteLeft(obj);
    var PosTop = GetAbsoluteTop(obj);
    var DivPalette = document.getElementById("Palette");
    //var ColorWindow = window.parent.document.frames["IframeColor"];   
    var ColorWindow = document.getElementById("IframeColor").contentWindow;
    var SelectedIndex = ColorWindow.top.document.getElementById("SelectedImage").value;    
    
    if ((DivPalette != null) && (SelectedIndex == ""))
    {  
        DivPalette.style.display = "inline";
        DivPalette.style.left = PosLeft - 20 + 'px';
        DivPalette.style.top = PosTop + 25 + 'px';
    } 
}

function HidePalette(obj)
{
    obj.style.display = "none";
}

function onEnter(obj)
{
    obj.style.border = "2px solid #363636";
    obj.style.width = "18px"; 
    obj.style.height = "18px";  
    obj.style.cursor = "pointer";  
}

function onLeave(obj)
{
    obj.style.border = "0px";
    obj.style.width = "23px"; 
    obj.style.height = "23px";  
    obj.style.cursor = "default";  
}

function ShowColor(obj)
{
    //var ColorWindow = window.parent.document.frames["IframeColor"];   
    var ColorWindow = this.parent.document.getElementById("IframeColor").contentWindow;
    var DivColor = ColorWindow.top.document.getElementById("Color");
    var btn =  ColorWindow.top.document.getElementById("Btn");
    btn.click();
    if (DivColor != null) 
    {  
        DivColor.style.backgroundColor = obj.bgColor;
        DivColor.value = obj.id;
        DivColor.style.display = "";
    } 
    
    SelectedColor(obj, ColorWindow);
    ClickHidePalette(ColorWindow); 
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    if (ImageWindow == null) return;
    var CategoryId = ColorWindow.top.document.getElementById("Category").value; 
    var ColorIndex = ColorWindow.top.document.getElementById("Color").value;
    //var SelectedIndex = ColorWindow.top.document.getElementById("SelectedImage").value; 
    //if ((SelectedIndex != "") && (ColorIndex != ""))     
    //    ImageWindow.location.href = "Image.aspx?SelectedIndex=" + SelectedIndex + "&ColorIndex=" + ColorIndex; 
    if ((CategoryId != "") && (ColorIndex != ""))
        ImageWindow.location.href = "Image.aspx?NowNode=" + CategoryId + "&ColorIndex=" + ColorIndex; 
}

function HideColor(obj)
{
    //var ColorWindow = window.parent.document.frames["IframeColor"];  
	var ColorWindow = this.parent.document.getElementById("IframeColor").contentWindow;
    var DivColor = ColorWindow.top.document.getElementById("Color");
    var btn =  ColorWindow.top.document.getElementById("Btn");
    btn.click();
    if (DivColor != null) 
    {  
        DivColor.style.backgroundColor = "";
        DivColor.value = "";
        DivColor.style.display = "none";
    }  
    UnSelectedColor(ColorWindow);
    ClickHidePalette(ColorWindow);
    
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    if (ImageWindow == null) return; 
    var CategoryId = ColorWindow.top.document.getElementById("Category").value; 
    if (CategoryId != "") 
        ImageWindow.location.href = "Image.aspx?NowNode=" + CategoryId;    
}

function SelectedColor(obj, ColorWindow)
{
    var Cell = ColorWindow.document.getElementsByTagName("td");
    for (var i = 0; i < Cell.length; i++)
    {
        if (Cell[i].className == "ColorCell") 
        {
            if (Cell[i].id == obj.id) 
            {
                Cell[i].onmouseover = "";  
                Cell[i].onmouseout = ""; 
                Cell[i].style.border = "2px solid #363636";
                Cell[i].style.width = "18px"; 
                Cell[i].style.height = "18px";  
            }
            else
            {
                Cell[i].onmouseover = function() {onEnter(this);};
                Cell[i].onmouseout = function() {onLeave(this);};
                Cell[i].style.border = "0px";
                Cell[i].style.width = "23px"; 
                Cell[i].style.height = "23px";
            }
        }
    }  
}

function UnSelectedColor(obj)
{
    var Cell = obj.document.getElementsByTagName("td");
    for (var i = 0; i < Cell.length; i++)
    {
        if (Cell[i].className == "ColorCell") 
        {
            Cell[i].onmouseover = function() {onEnter(this);};
            Cell[i].onmouseout = function() {onLeave(this);};
            Cell[i].style.border = "0px";
            Cell[i].style.width = "23px"; 
            Cell[i].style.height = "23px";
        }
    }  
}

function ClickHidePalette(obj)
{
    var DivPalette = obj.top.document.getElementById("Palette");
    if (DivPalette != null)
        DivPalette.style.display = "none";  
}

function FilterOver(obj)
{
    obj.src = "images/Slices/menu_over.jpg"
    obj.style.cursor = "pointer"; 
}

function FilterOut(obj)
{
    obj.src = "images/Slices/menu_up.jpg";
    obj.style.cursor = "default"; 
}

function GetPosition()
{
    var obj = document.getElementById("Filter");
    var color = document.getElementById("Color");
    var left = GetAbsoluteLeft(obj);
    var top =  GetAbsoluteTop(obj);
    color.style.left = left + 10;
    color.style.top = top + 12;
    color.style.width = "68px"; 
    color.style.height = "8px";
    color.style.overflow = "hidden"; 
}

function GetAbsoluteLeft(obj)
{
      var objLeft = obj.offsetLeft;
      while(obj.offsetParent)
      {
        objLeft += obj.offsetParent.offsetLeft;
        obj = obj .offsetParent;
      }
      return objLeft ;
}

function GetAbsoluteTop(obj)
{
      var objTop = obj.offsetTop;
      while(obj.offsetParent)
      {
        objTop += obj.offsetParent.offsetTop;
        obj = obj.offsetParent;
      }
      return objTop ;
}

function NavigatorsDifferent()
{
	if (window.navigator.userAgent.indexOf("MSIE") >= 1)
	{
	    window.attachEvent("onresize", Loc_Timer);
	}
	else
	{
	    window.addEventListener("onresize", Loc_Timer, true);
	}	
}

function Loc_Timer()
{	   
	loctimer = setTimeout(GetPosition, 10); 
}






