/**********************************************************
Sleight
(c) 2001, Aaron Boodman
http://www.youngpup.net
**********************************************************/

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
    document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
    window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
    var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

    for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
        if (itsAllGood && img.src.match(/(.*)\/com_virtuemart\/(.*)\.png/i) != null) {        
            fnFixPng(img);
            img.attachEvent("onpropertychange", fnPropertyChanged);
        }
        img.style.visibility = "visible";
    }

    var nl = document.getElementsByTagName("INPUT");
    for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
        if (e.className && e.className.match(/\bimage\b/i) != null) {
            if (e.src.match(/\.png$/i) != null) {
                fnFixPng(e);
                e.attachEvent("onpropertychange", fnPropertyChanged);
            }
            e.style.visibility = "visible";
        }
    }
}

function fnPropertyChanged() {
    if (window.event.propertyName == "src") {
        var el = window.event.srcElement;
        if (!el.src.match(/x\.gif$/i)) {
            el.filters.item(0).src = el.src;
            el.src = "x.gif";
        }
    }
}

function dbg(o) {
    var s = "";
    var i = 0;
    for (var p in o) {
        s += p + ": " + o[p] + "\n";
        if (++i % 10 == 0) {
            alert(s);
            s = "";
        }
    }
    alert(s);
}

function fnFixPng(img) {
    var src = img.src;
    img.style.width = img.width + "px";
    img.style.height = img.height + "px";
    img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
    img.src = "components/com_virtuemart/shop_image/blank.gif";
}

function KeepScroll(heidi,link,attnames) {
	
	var VertPos = document.documentElement.scrollTop;
	var debut = 0;
	var highd = "";
	var z = attnames.length;
	link += "&scrolle=" + VertPos;
	
	for (i=0;i < z;i++) {
		glue = attnames.charAt(i);
		if (glue == '|') {
			var longueur = i - debut;
			highd = attnames.substr(debut,longueur);
			highdf = highd + "_liste";
			debut = i + 1;
			link += "&" + highd + "=" + parent.attribute_selection.document.getElementById(highdf).value;
			//document.getElementById(highd).value = parent.attribute_selection.document.getElementById(highdf).value;
		}
		if (i == z - 1) {
			var longueur = i - debut + 1;
			highd = attnames.substr(debut,longueur);
			highdf = highd + "_liste";
			link += "&" + highd + "=" + parent.attribute_selection.document.getElementById(highdf).value;
			//document.getElementById(highd).value = parent.attribute_selection.document.getElementById(highdf).value;			
		}
	}	
	document.getElementById(heidi).href = link;
}

function MemScrollPost (heidi,form_id) {
	document.getElementById(heidi).value = document.documentElement.scrollTop;
	document.getElementById(form_id).submit();
}

function getAttrSelection (attnames) {
	
	var debut = 0;
	var heidi = "";
	var z = attnames.length;
	
	for (i=0;i < z;i++) {
		glue = attnames.charAt(i);
		if (glue == '|') {
			var longueur = i - debut;
			heidi = attnames.substr(debut,longueur);
			heidif = heidi + "_liste";
			debut = i + 1;
			document.getElementById(heidi).value = parent.attribute_selection.document.getElementById(heidif).value;
		}
		if (i == z - 1) {
			var longueur = i - debut + 1;
			heidi = attnames.substr(debut,longueur);
			heidif = heidi + "_liste";
			document.getElementById(heidi).value = parent.attribute_selection.document.getElementById(heidif).value;			
		}
	}
	document.getElementById("product_id").value = parent.attribute_selection.document.getElementById("productid").value;
}

function show_big(img,nb) {
	var target = "";
	
	for (var i = 1;i < nb+1;i++) {
		target = "big_" + i.toString();
		if (document.getElementById(target))
			document.getElementById(target).style.display = "none";
	}
	target = "big_" + img.toString();
	if (document.getElementById(target))
			document.getElementById(target).style.display = "block";
}












