Array.prototype.inArray = function(index) {
	for(var i = 0; i < this.length; i++) {
		if(this[i]["index"] === index) {
			return i;
		}
	}

	return -1;
};

function stockMessage(color, size) {
	alert("Die Farbe " + color + " ist leider nicht in der Größe " + size + " erhältlich.");
}

function nextOption(target) {
	var formIdent = "document.forms['productsform']." + target;
	var formField = eval(formIdent);
	var selOption = formField.selectedIndex;
	
	formField.selectedIndex = (selOption == formField.length - 1) ? 0 : selOption + 1;
}

function popImage(document,name,w,h,options) {
	cornerTop = 0;
	cornerLeft = 0;
	
	if(w < screen.width && h < screen.height) {
		cornerLeft = (Math.round((screen.width - w) / 2));
		cornerTop = (Math.round((screen.height - h) / 2)) - 30;
	}
	
	options += (options ? ',' : '') + 'width=' + w + ',height=' + h + ',top=' + cornerTop + ',left=' + cornerLeft;
	
	return window.open(document, name, options);
}

function switchColor(layer,folder,color,side,name) {
	var backSide = (side == "_backside") ? side : "";
	var imgTag = "<IMG src=\"../img/products/" + folder + "/" + color + backSide + "_medium.jpg\" border=\"0\" width=\"200\" height=\"200\" alt=\"Vergrößern\" onclick=\"popImage('../functions/popup.func.php?folder=" + folder + "&color=" + color + "&backside=" + backSide + "', 'popImage', 650, 650, 'resizable=no');\" class=\"content-products-img\" />\n";
	var pTag = "<P class=\"content-products-link\"><IMG src=\"../img/link_extern.gif\" border=\"0\" width=\"13\" height=\"11\" /><A href=\"javascript:void(null);\" onclick=\"popImage('../functions/popup.func.php?folder=" + folder + "&color=" + color + "&backside=" + backSide + "', 'popImage', 650, 650, 'resizable=no');\">Vergrößern</A></P>";
	
	document.getElementById(layer).innerHTML = imgTag + pTag;
	
	if(side.length > 0) {
		switchLink(folder,color,side,name);
	}
}

function switchLink(folder,color,side,name) {
	var tagIdent = "backside_" + color;
	
	switch(side) {
		case "_backside":
			var bsTag = "<DIV id=\"backside_" + color + "\"><P class=\"content-products-link clear-margin\"><IMG src=\"../img/link-icon_mehr.gif\" border=\"0\" width=\"13\" height=\"11\" /><A href=\"javascript:void(null);\" onclick=\"switchColor('content-products-display','" + folder + "','" + color + "','_frontside','" + name + "');\">Frontseite " + name + "</A></P></DIV>";
			break;
		case "_frontside":
			var bsTag = "<DIV id=\"backside_" + color + "\"><P class=\"content-products-link clear-margin\"><IMG src=\"../img/link-icon_mehr.gif\" border=\"0\" width=\"13\" height=\"11\" /><A href=\"javascript:void(null);\" onclick=\"switchColor('content-products-display','" + folder + "','" + color + "','_backside','" + name + "');\">Rückseite " + name + "</A></P></DIV>";
			break;
		default:
			var bsTag = "<DIV></DIV>";
			break;
	}
		
	document.getElementById(tagIdent).innerHTML = bsTag;
}

function onSubmitForm() {
	return true;
}

function resellerLogout() {
	if(confirm('Beim Verlassen des Resellerportals werden Sie ausgeloggt. Möchten Sie zum Kundenportal wechseln?')) {
		document.location.href = '../start/index.php?action=logout';
	}
}

function confirmDelete() {
	if(confirm('Soll dieser Datensatz gelöscht werden?') == false) {
		return false;
	}
}

function check() {
	if(window.document.reseller.login.value == '') {
		alert('Bitte ein Login eingeben.');
		
		return false;
	}
	
	if(window.document.reseller.login.value.length < 6) {
		alert('Das Login muss aus mindestens sechs Zeichen bestehen.');
		
		return false;
	}
	
	if(window.document.reseller.password.value != '' && window.document.reseller.password.value.length < 6) {
		alert('Das Passwort muss aus mindestens sechs Zeichen bestehen.');
		
		return false;
	}
	
	if(window.document.reseller.email.value == '') {
		alert('Bitte eine E-Mail-Adresse eingeben.');
		
		return false;
	}
}