﻿function highlight(obj, show) {
    if (show) {
        obj.className = 'highlighted';
    } else {
        obj.className = 'input';
    }
}


function focusObj(objectName) {
    obj = document.getElementById(objectName);
    if (obj != null) {
        window.setTimeout('document.getElementById("' + objectName + '").focus();', 250);
    }
}

function testUrl(urlTextboxObjName) {
    obj = document.getElementById(urlTextboxObjName);
    
    if (obj != null) {
        if (obj.value.length > 0) {
            window.open(obj.value, "lol");
        }
    }
}

function showBoughtByDiv(iconObj, visitorName) {
    obj = document.getElementById('showBoughtByDiv_div');
    
    if (obj == null) {
        obj = document.createElement('div');
        obj.id = 'showBoughtByDiv_div';
        document.body.appendChild(obj);
    }

    if (obj.hasChildNodes()) { obj.removeChild(obj.childNodes[0]); }


    if (visitorName != null) {
        obj.style.display = "block";
        obj.appendChild(document.createTextNode(visitorName));

        obj.style.top  = (findPos(iconObj)[1] - 8) + "px";
        obj.style.left = (findPos(iconObj)[0] + 16) + "px";
        
    } else {
        obj.style.display = "none";
    }
}



function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	    do {
	        curleft += obj.offsetLeft;
	        curtop += obj.offsetTop;
	    } while (obj = obj.offsetParent);
	}

	return [curleft,curtop];
}

function toggleWishImage(parentObj, objName, showImage) {
    obj = document.getElementById(objName);
    if (obj != null) {
        if (obj.getAttribute("src").indexOf("spacer.gif") == -1) {
        
            if (showImage) {
                obj.style.display = 'block';
                
                topPos = findPos(parentObj)[1];
                leftPos = findPos(parentObj)[0] + 30;

                bodyHeight = getInnerHeightXY()[1] + getScrollXY()[1];
                
                picHeight = 195;

                if (obj.height != null) {
                    picHeight = obj.height;
                }

                if ((bodyHeight - topPos - picHeight) < 35) {
                    topPos = bodyHeight - picHeight - 35;
                }
                
                obj.style.top = topPos + "px";
                obj.style.left = leftPos + "px";
                
            } else {
                obj.style.display = 'none';
            }
        }
    }
}

function getInnerHeightXY() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}