﻿function SelectNode(CategoryId)
{
    //var ColorWindow = window.parent.document.frames["IframeColor"]; 
    var ColorWindow = window.parent.document.getElementById("IframeColor").contentWindow;
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    var SponsorWindow = this.parent.document.getElementById("IframeSponsor").contentWindow;
   
    //save text category id 
    var Category = window.top.document.getElementById("Category"); 
    if (Category != null)
        Category.value = CategoryId; 
    //clear selected index 
    var SelectedImage = window.top.document.getElementById("SelectedImage");
    if (SelectedImage != null)
        SelectedImage.value = "";   
    
    var DivColor = ColorWindow.top.document.getElementById("Color"); 
    if (DivColor == null) return;
    DivColor.style.backgroundColor = "";
    DivColor.value = "";
    DivColor.style.display = "none";
    UnSelectedColor(ColorWindow);   
    
    ImageWindow.location.href = "Image.aspx?NowNode=" + CategoryId; 
    SponsorWindow.location.href = "SponsoredAdv.aspx?TextCatId=" + CategoryId;

    var Back = window.top.document.getElementById("Back");
    if (Back != null)
    {
        Back.style.display = "none"; 
        window.top.document.getElementById("BackCounter").value = 1;
    }        
} 

function goNext(TextCatId, SelectedIndex)
{
    var ColorWindow = window.parent.document.getElementById("IframeColor").contentWindow;
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    var SponsorWindow = this.parent.document.getElementById("IframeSponsor").contentWindow;
    
    //save selected index 
    var SelectedImage = window.top.document.getElementById("SelectedImage");
    if (SelectedImage != null)
        SelectedImage.value = SelectedIndex;   
    
    var DivColor = ColorWindow.top.document.getElementById("Color"); 
    if (DivColor == null) return;

    var ColorCode = DivColor.style.backgroundColor; 
    if ((ColorCode != null) && (ColorCode != ""))
    {
        var ColorIndex = ColorWindow.top.document.getElementById("Color").value;    
        ImageWindow.location.href = "Image.aspx?SelectedIndex=" + SelectedIndex + "&ColorIndex=" + ColorIndex;
    }
    else
        ImageWindow.location.href = "Image.aspx?SelectedIndex=" + SelectedIndex;
//    if (SelectedIndex != "-100")
//    {
//    }  
//    else
//    {
//        ImageWindow.location.href = "CheckOut.aspx";
//        DivColor.style.display = "none";
//    }    
    SponsorWindow.location.href = "SponsoredAdv.aspx?TextCatId=" + TextCatId;        
    
    var Div = window.top.document.getElementsByTagName("div");
    for (var i = 0; i < Div.length; i++)
    {
        if (Div[i].id == "Back")
        {
            Div[i].style.display = "inline";
            Div[i].value = TextCatId; 
            var Input = window.top.document.getElementsByTagName("input");
            for (var j = 0; j < Input.length; j++)
            {
                if (Input[j].id == "BackCounter")
                    Input[j].value = eval(parseInt(Input[j].value) + 1);
            }  
        } 
    }  
}

function goBack()
{
    var Div = window.top.document.getElementsByTagName("div");
    for (var i = 0; i < Div.length; i++)
    {
        if (Div[i].id == "Back")
            var CategoryId = Div[i].value;
    } 
   
    var ColorWindow = window.parent.document.getElementById("IframeColor").contentWindow;  
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    var SponsorWindow = this.parent.document.getElementById("IframeSponsor").contentWindow; 
    
    var DivColor = ColorWindow.top.document.getElementById("Color"); 
    if (DivColor == null) return;
    //DivColor.style.display = "";
    var ColorCode = DivColor.style.backgroundColor; 
    if ((ColorCode != null) && (ColorCode != ""))
    {
        var ColorIndex = ColorWindow.top.document.getElementById("Color").value;    
        ImageWindow.location.href = "Image.aspx?BackTextId=" + CategoryId + "&ColorIndex=" + ColorIndex;
    }
    else
        ImageWindow.location.href = "Image.aspx?BackTextId=" + CategoryId;      
    SponsorWindow.location.href = "SponsoredAdv.aspx?BackTextCatId=" + CategoryId;
   
    var Input = window.top.document.getElementsByTagName("input"); 
    for (var i = 0; i < Input.length; i++)
    {
        if (Input[i].id == "BackCounter")
        {
            Input[i].value = eval(parseInt(Input[i].value) - 1);
            if (Input[i].value == "1") 
            {
                var Div = window.top.document.getElementsByTagName("div"); 
                for (var j = 0; j < Div.length; j++)
                {
                    if (Div[j].id == "Back")
                    {
                        Div[j].style.display = "none";
                        //clear selected index 
                        var SelectedImage = window.top.document.getElementById("SelectedImage");
                        if (SelectedImage != null)
                            SelectedImage.value = "";
                    }   
                }     
            } 
        } 
    } 
}

function onOver(obj)
{
    obj.className = "BackOver"; 
}

function onOut(obj)
{
    obj.className = "BackOut";
}

function HideTrack()
{
    var count = 0;
    var ImageWindow =  this.parent.document.getElementById("IframeImage").contentWindow;
    var Track = window.top.document.getElementById("Track");
    if (Track == null) return;
      
    var ImageList = ImageWindow.document.getElementsByTagName("img"); 
    for (var i = 0; i < ImageList.length; i++)
    {
        if (ImageList[i].id.indexOf("Img_") != -1)
            count += 1;
    }

    if (count < 13) 
        Track.style.display = "none";
    else
        Track.style.display = "inline";  
}



