document.cookie = "CookiesEnabled=true";
var cookieCheck = document.cookie;

if (cookieCheck.indexOf("CookiesEnabled=true") == -1)
{
    document.location = "http://www.skinit.com/enableCookies.php";
}


var pinSubmit = function() {
	if (window.pinEntered && !window.confirm('Valid pin code already was entered. Do you want to replace it?')) {
		return false;
	}
	document.getElementById('formredeem').submit();
	return false;
}


var oldOnLoad = window.onload;

window.onload = function() {
    var fr = document.getElementById('formredeem');
    if (fr) {
        var pin = fr.getElementsByTagName('input');
        if (pin.length > 0) {
            pin = pin[0];
            pin.onfocus = function() {
                var pin = document.getElementById('formredeem').getElementsByTagName('input')[0];
                if (pin.value == 'enter code here') {
                    pin.value = '';
                }
            }
            pin.onblur = function() {
                var pin = document.getElementById('formredeem').getElementsByTagName('input')[0];
                if (pin.value == '') {
                    pin.value = 'enter code here';
                }
            }
        }
    }
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++)
    {
        if (!links[i].onmousedown)
        {
            links[i].onmousedown = function(p) {
                this.blur();
                this.hideFocus = true;
                this.style.outline = 'none';
            }
        }
        if (!links[i].onmouseup)
        {
            links[i].onmouseup = function(p) {
                this.blur();
                this.hideFocus = true;
                this.style.outline = null;
            }
        }
        if (!links[i].onmouseout)
        {
            links[i].onmouseout = function(p) {
                this.blur();
                this.hideFocus = true;
                this.style.outline = null;
            }
        }
    }
    fixSomeRoundBugs($('middleArea')); 
    if (oldOnLoad) {
    	oldOnLoad();
    }
}

function enterKey(myfield, e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
	   myfield.form.submit();
	   return false;
	}
	else
	   return true;
}

function popup(a)
{
	window.open(a.href);
	return false;
}

function fixSomeRoundBugs(start)
{
	var count = parseInt(start.childNodes.length);
	for (var i = 0; i < count; i++)
	{
		var el = start.childNodes[i];
		if ((getIEStyle(el, 'position') == 'absolute') && ((getIEStyle(el, 'top') == 'auto') || (getIEStyle(el, 'left') == 'auto')))
		{
			var par = el.parentNode;
			do {
				if (getIEStyle(par, 'position') == 'relative')
				{
					break;
				}
			} while (par = par.parentNode);
			if (par)
			{
				var parOffset = Element.cumulativeOffset(par);
				var elOffset = Element.cumulativeOffset(el);
				var bottomDiff = Element.getHeight(par) - elOffset.top + parOffset.top - Element.getHeight(el);
				var rightDiff = Element.getWidth(par) - elOffset.left + parOffset.left - Element.getWidth(el);
				if ((getIEStyle(el, 'bottom') == '0px') && bottomDiff)
				{
					el.style.bottom = '' + (parseInt(getIEStyle(el, 'bottom')) - bottomDiff) + 'px';
				}
				if ((getIEStyle(el, 'right') == '0px') && rightDiff)
				{
					el.style.right = '' + (parseInt(getIEStyle(el, 'right')) - rightDiff) + 'px';
				}
			}
		}
		fixSomeRoundBugs(el);
	}
}

function getIEStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
//		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}
