var currentRootTabs=3;
var currentRootTab=1;
var currentInnerTab=1;
var xmlhttp;

function getRootTabId(tabNumber){
    return "RootTab"+tabNumber;
}

function getInnerTabId(rootTab,innerNumber){
    return "Tab"+rootTab+"Inner"+innerNumber;
}
function getInnerTabDivId(rootTab,innerNumber){
    return "Root"+rootTab+"Inner"+innerNumber;
}
function getRootTabDivId(tabNumber){
    return "Tab"+tabNumber+"Container";
}
function getAjaxPageURL(rootTab,childTab,pageNumber){
    if(rootTab==2)
        childTab-=1;
    return "/shop/categories/Tab"+rootTab+"/Category"+childTab+".php?page="+pageNumber;
}

function changeRootTab(current){
    if(current!=currentRootTab){
        try{
            newTabId=getRootTabId(current);
            oldTabId=getRootTabId(currentRootTab);
            newTabDivId=getRootTabDivId(current);
            oldTabDivId=getRootTabDivId(currentRootTab);
            for(i=1;i<=currentRootTabs;i++){
                document.getElementById(getRootTabId(i)).src="/graphics/shoponlinegrid-RootTab-"+i+".gif";
            }
            document.getElementById(oldTabId).src="/graphics/shoponlinegrid-RootTab-"+currentRootTab+".gif";
            document.getElementById(newTabId).src="/graphics/shoponlinegrid-RootTab-"+current+"-selected.gif";
            document.getElementById(oldTabDivId).style.display="none";
            newDiv=document.getElementById(newTabDivId);
        
            newDiv.style.display="";

            currentRootTab=current;
            currentInnerTab=1;
            if(currentRootTab==2)
                currentInnerTab=2;
            changeInnerTab(currentInnerTab);
        }catch(error){
        //alert('error root')
        }
    }
}
function changeInnerTab(currentInner){
    newTabId=getInnerTabId(currentRootTab,currentInner);
    for(i=1;i<7&&currentRootTab!=3;i++){
        try{
            tabId=getInnerTabId(currentRootTab,i);
            divId=getInnerTabDivId(currentRootTab,i);
            //document.getElementById(divId).innerHTML="";
            document.getElementById(divId).style.display="none";
            document.getElementById(tabId).src="/graphics/shoponlinegrid-tab-"+currentRootTab+"-"+i+".jpg";
        }catch(error){}
    }
    try{
        if(currentRootTab!=3)
            document.getElementById(newTabId).src="/graphics/shoponlinegrid-tab-"+currentRootTab+"-"+currentInner+"-selected.jpg";

        divId=getInnerTabDivId(currentRootTab,currentInner);
        document.getElementById(divId).style.display="";
    
        currentInnerTab=currentInner;
        pageURL=getAjaxPageURL(currentRootTab,currentInnerTab,1);
        retrievePageData(pageURL);
    }catch(error){
    //alert('error')
    }
}
function retrievePageDataByNumber(pageNumber){
    url=getAjaxPageURL(currentRootTab,currentInnerTab,pageNumber);
    retrievePageData(url);
}
function retrievePageData(URL)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url=URL;
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

function stateChanged()
{
    if (xmlhttp.readyState==4)
    {
        id=getInnerTabDivId(currentRootTab,currentInnerTab);
        document.getElementById(id).innerHTML=xmlhttp.responseText;
    }
}

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}
function addProductToCart(productId){

    document.getElementById("item1").value=productId;
    document.getElementById("ProductsForm").submit();
}
