﻿function _(id)
{
	return document.getElementById(id);
}

function imageZoom(id)
{
	var w = openCenteredWindow('/site/imageZoom/' + id, 'imageZoom', 400, 400);
	w.focus();
}

function openCenteredWindow(url, n, w, h)
{
	var l = (screen.availWidth / 2) - (w / 2);
	var t = (screen.availHeight / 2) - (h / 2);
	return openWindow(url, n, w, h, l, t);
}

function openWindow(url, n, w, h, l, t)
{
	if(l == undefined) l = 200;
	if(t == undefined) t = 100;

	var params = new Array();

	if(w > 0) params.push('width='  + w);
	if(h > 0) params.push('height=' + h);
	params.push('left=' + l);
	params.push('top='  + t);

	params.push('location=no');
	params.push('statusbar=no');

	return window.open(url, n, params.join(','));
}

function refreshImprintForm(formId, imprintSelectId, colorSelectId)
{
	var eImp = _(imprintSelectId);
	if(!eImp || imprintTypes[eImp.value] == undefined) return;

	var imp = imprintTypes[eImp.value];
	var hasColors = (imp.has_colors != 0);
	var div = _(colorSelectId);

	var inputs = div.getElementsByTagName('input');
	for(var i=0; i < inputs.length; i++) {
		if(hasColors) {
			inputs[i].removeAttribute('disabled');
		} else {
			inputs[i].setAttribute('disabled', 'disabled');
		}
	}
}

function highlight(id)
	{
	state = document.getElementById(id).checked;

	if (state)
		{
		document.getElementById(id + '-img').setAttribute('style', 'border: #fee7cc 2px solid;');
		}
	else
		{
		document.getElementById(id + '-img').setAttribute('style', 'border: #ff8712 2px solid;');
		}
	}


function highlightCheckbox(el,id)
	{
	state = el.checked;

	if (!state)
		{
		document.getElementById(id + '-img').setAttribute('style', 'border: #fee7cc 2px solid;');
		}
	else
		{
		document.getElementById(id + '-img').setAttribute('style', 'border: #ff8712 2px solid;');
		}
	}



function addInputSubmitEvent(form, input) {
	input.onkeydown = function(e) {
		e = e || window.event;
		if (e.keyCode == 13) {
			form.submit();
			return false;
		}
	};
}

window.onload = function() {
    var forms = document.getElementsByTagName('form');

    for (var i=0;i < forms.length;i++) {
        var inputs = forms[i].getElementsByTagName('input');

        for (var j=0;j < inputs.length;j++)
            addInputSubmitEvent(forms[i], inputs[j]);
    }
};
