function activateFeatureDescription(x) {
    i = 0;
    got = false;
    dojo.query("#feature_description > div.feature_tabs > div").forEach(
        function(node) {
            if (!got)
                i++;
            if (node.className != "clear")
                node.className = "feature_not_active";
            if (!got && node == x) {
                got = true;
            }
        });
    j = 0;
    dojo.query("#feature_description > div.feature_text > span").forEach(
        function(node) {
            j++;
            if (j == i) {
                node.style.display = "inline";
            } else {
                node.style.display = "none";
            }
        });
    x.className = "feature_active";
}

//function loadSizesForColor(productId, SzinId) {
//    colorBox.disabled = true;
//    dojo.xhrPost( {
//        url : '/ajaxrequests.php?r=getcolorsizes',
//        load : function(response, ioArgs) {
//            document.getElementById("sizes_table").innerHTML=response;
//            colorBox.disabled = false;
//        },
//        error : function(){},
//        content : {
//            colorid:colorBox.value,
//            productid:productId
//        }
//    });
//}

//function loadSizesForCover(productId, coverId) {
//    //	coverBox.disabled = true;
//    dojo.xhrPost( {
//        url : 'ajaxrequests.php?r=getcoversizes',
//        load : function(response, ioArgs) {
//            document.getElementById("sizes_table").innerHTML=response;
//        //coverBox.disabled = false;
//        },
//        error : function(){},
//        content : {
//            coverid:coverId,
//            productid: productId
//        }
//    });
//}
function loadSizesForColor(productId, SzinId) {
    //colorBox.disabled = true;
    dojo.xhrPost( {
        url : '/ajaxrequests.php?r=getcolorsizes',
        load : function(response, ioArgs) {
            document.getElementById("sizes_table").innerHTML=response;
            //colorBox.disabled = false;
        },
        error : function(){},
        content : {
            colorid: SzinId,
            productid: productId
        }
    });
}

function loadSizesForCover(productId, coverId) {
    //	coverBox.disabled = true;
    dojo.xhrPost( {
        url : 'ajaxrequests.php?r=getcoversizes',
        load : function(response, ioArgs) {
            document.getElementById("sizes_table").innerHTML=response;
        //coverBox.disabled = false;
        },
        error : function(){},
        content : {
            coverid:coverId,
            productid: productId
        }
    });
}

function loadSizesForMaterial(productId, materialId) {
    //	coverBox.disabled = true;
    // dojo.xhrPost( {
        // url : 'ajaxrequests.php?r=getcoversizes',
        // load : function(response, ioArgs) {
            // document.getElementById("sizes_table").innerHTML=response;
        // //coverBox.disabled = false;
        // },
        // error : function(){},
        // content : {
            // coverid:materialId,
            // productid: productId
        // }
    // });
}

function createSexyComboBox(id, elements, onChange) {
    container = document.getElementById(id);
    var sexyOver = false;;
    if (elements.length == 0)
        return;
    button = document.createElement("div");
    button.className = "sexyComboBoxButton";
    current = document.createElement("div");
    current.className = "current";
	current.id = "current"+id;
    container.appendChild(current);
    current.appendChild(createSexyElement(elements[0]));
    current.appendChild(button);
    cleardiv = document.createElement("div");
    cleardiv.className = "clear";
    current.appendChild(cleardiv);
    dropdown = document.createElement("div");
    dropdown.id = "sexyComboBoxDropDown"+id;
    dropdown.style.display = "none";
    dropdown.style.position = "absolute";
    container.onclick = function (e) {
		var id = this.id;
		var dv = document.getElementById("sexyComboBoxDropDown"+id);
        dv.style.display = "block";
    };
    current.onmouseover = function (e) {
        sexyOver = true;
		
		var divid = this.id;
		sexyOverColors = false;
		sexyOverCovers = false;
		sexyOverMaterials = false;
		switch (divid) {
			case 'currentcolors': sexyOverColors = true; break;
			case 'currentcovers': sexyOverCovers = true; break;
			default: sexyOverMaterials = true; break;
		}
    }
    current.onmouseout = function () {
        sexyOver = false;
		
		sexyOverColors = false;
		sexyOverCovers = false;
		sexyOverMaterials = false;
    }
		
    document.onclick = function (event) {
        // if (!sexyOver){
		// alert('?');
		// dropdown.style.display = "none";
		var dropd;
		if (!sexyOverColors){
			dropd = document.getElementById("sexyComboBoxDropDown"+"colors");
            if (dropd) dropd.style.display = "none";
		}
		if (!sexyOverCovers){
			dropd = document.getElementById("sexyComboBoxDropDown"+"covers");
            if (dropd) dropd.style.display = "none";
		}
		if (!sexyOverMaterials){
			dropd = document.getElementById("sexyComboBoxDropDown"+"materials");
            if (dropd) dropd.style.display = "none";
		}
    };
    for (i = 0; i < elements.length; i++) {
        sexyElem = createSexyElement(elements[i], id);
        sexyElem.onclick = function (){
			var currentCombo = document.getElementById("current"+id);
            onChange(this.sexyId);
            currentCombo.firstChild.innerHTML = this.innerHTML;
            dropdown.style.display = "none";
        }
        dropdown.appendChild(sexyElem);
    }
    container.appendChild(dropdown);
    document.getElementById("cover_hidden").value=elements[0].id;
}

function createSexyElement(data, parentid) {
    elem = document.createElement("div");
    elem.className = "sexyElement";
    elem.sexyId = data.id;
	elem.parentId = parentid;
    img = document.createElement("img");
    if (data.image != null)
        img.src = "/termek_kepek/"+data.image;
    else
        img.src = "/img/no_img_cover_color.jpg";
    elem.appendChild(img);
    textdiv = document.createElement("div");
    textdiv.innerHTML = data.text;
    elem.appendChild(textdiv);
    return elem;
}

function featureTabImageResize(image) {
    x = image.width / image.height;
    if (x < 1){
        x = (64 - 64 * x) / 2;
        image.style.height = "64px";
        image.style.marginLeft = x.toString() + "px";
    }
    else {
        x = ((64 - 64 * (1 / x)) / 2);
        image.style.width = "64px";
        image.style.marginTop = x.toString() + "px";
    }
}
