function CheckUpload ()
{
	var oForm = document.forms['uploadform'];
	var file_no_text = trim (oForm.file_no_text.value);
	var file_text = trim (oForm.file_text.value);
	var file_original_text = trim (oForm.file_original_text.value);
	var ext_no_text = file_no_text.substring (file_no_text.length, file_no_text.length - 4).toLowerCase();
	var ext_original_text = file_original_text.substring (file_original_text.length, file_original_text.length - 4).toLowerCase();
	var ext_text = file_text.substring (file_text.length, file_text.length - 4).toLowerCase();

	if (file_no_text.length == 0 || file_text.length == 0)
	{
		alert ('Bitte geben Sie die Dateien an, die Sie hochladen möchten!');
	}
	else if (ext_no_text != 'tiff' && ext_no_text != '.tif')// && ext_no_text != '.jpg' && ext_no_text != '.ai' && ext_no_text != '.eps' && ext_no_text != '.swf')
	{
		alert ('Es können nur .tiff, .tif  Formate als Original hochgeladen werden!');
		oForm.file_no_text.focus ();
	}
	else if (ext_text != '.jpg')
	{
		alert ('Es können nur .jpg Formate als Preview hochgeladen werden!');
		oForm.file_no_text.focus ();
	}
	else
	{
		document.forms['uploadform'].uploadbutton.disabled = "true";
		document.forms['uploadform'].submit ();
	}
}

function ImageEdit (url, windowname)
{
	var width = 920;
	var height = 680;
	var w = window.open ('' + url + '','' + windowname + '','fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function OpenRegistrationPrint (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=yes,status=no,menubar=yes,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenAGBWindow (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=yes,status=no,menubar=yes,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenUCWindow (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=yes,status=no,menubar=yes,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenLicensingWindow (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenPictureRequestWindow (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenUsageInfoWindow (url, name)
{
	window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenPopupHelp (url, name)
{
	var width = 432;
	var height = 504;
	var w = window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function OpenOrder (url, name)
{
	var width = 600;
	var height = 400;
	var w = window.open ('' + url + '','' + name + '','fullscreen=no,titlebar=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function OpenHelpWindow (w_url, name)
{
	window.open ('' + w_url + '','' + name + '','fullscreen=no,titlebar=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=800,height=600');
}

function OpenLoginWindow (url, width, height)
{
	window.open ('' + url + '','','fullscreen=no,titlebar=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height + '');
}

function OpenLogoutWindow (url)
{
	return window.open ('' + url + '','','fullscreen=no,titlebar=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=221,height=97');
}

function OpenFormWindow (url, width, height)
{
	window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height + '');
}

function ImagePreviewDetails (url, windowname)
{
	var width = 920;
	var height = 700;
	var w = window.open ('' + url + '','' + windowname + '','fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function FlashPreviewDetails (url, windowname)
{
	window.open ('' + url + '','' + windowname + '','fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=340,height=280');
}

function ImagePreviewNoDetails (url)
{
	var width = 540;
	var height = 600;
	var w = window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function InvisibleWindow (url)
{
	window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=1,height=1');
}

function OpenWindow (url, windowname, width, height)
{
	var w = window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height + '');
	MoveWindowToCenter (w, width, height);
}

function MoveWindowToCenter (w, width, height)
{
	var Ycor = (screen.height-height) / 2;
	var Xcor = (screen.width-width) / 2;
	w.moveTo (Xcor, Ycor);
}

function GetFrameByName (oFrame, framename)
{
	if (framename == '') return oFrame;

	var frameCount = oFrame.frames.length;
	for (var i = 0; i < frameCount; i++)
	{
		if (oFrame.frames[i].name == framename)
		{
			return oFrame.frames[i];
		}
		if (oFrame.frames[i].frames != null && oFrame.frames[i].frames.length > 0) return GetFrameByName (oFrame.frames[i], framename);
	}
}

function ChangeColor (objID)
{
	var bChecked = document.forms['changes_form'].elements[objID].className == 'Y'; // if it was initially checked (dummy class)
	var obj = document.getElementById (objID);
	var oldclass = obj.className;

	if (bChecked)
	{
		obj.className = (oldclass == 'cbSuspended' ? 'cbChecked' : 'cbSuspended');
	}
	else
	{
		obj.className = (oldclass == 'cbSuspended' ? 'cbNotChecked' : 'cbSuspended');
	}

	obj1 = document.getElementById ('apply_changes1');
	obj2 = document.getElementById ('apply_changes2');

	if (obj1) obj1.className = 'cbLinkSuspended';
	if (obj2) obj2.className = 'cbLinkSuspended';
}

function ClearColor ()
{
	var oForm = document.forms['changes_form'];
	var len = oForm.elements.length;

	for (var i = 0; i < len; i++)
	{
		if (oForm.elements[i].type == 'checkbox')
		{
			var objID = oForm.elements[i].name;
			var objRef = document.getElementById (objID);
			newclass = oForm.elements[i].checked ? 'cbChecked' : 'cbNotChecked';
			newcbclass = oForm.elements[i].checked ? 'Y' : 'N';
			objRef.className = newclass;
			oForm.elements[i].className = newcbclass;
		}
	}
	document.getElementById ('apply_changes1').className = 'cbLinkNotChecked';
	document.getElementById ('apply_changes2').className = 'cbLinkNotChecked';
}

function HideWaitDiv ()
{
	document.getElementById ('waitDiv').style.display = 'none';
}

function ToggleButton (elName, img_true, img_false, alt_true, alt_false)
{
	oField = document.getElementById (elName);
	oField.disabled = !(oField.disabled);
	img_id = elName + '_img';
	document.images[img_id].src = (!(oField.disabled) ? img_true : img_false);
	document.images[img_id].alt = (!(oField.disabled) ? alt_true : alt_false);
	document.images[img_id].title = (!(oField.disabled) ? alt_true : alt_false);
	document.forms['changes_form'].submit ();
	self.focus ();
}

function OrderChangeQuality (elName, class_true, class_false, totalCount)
{
	oField = document.getElementById (elName);
	oField.disabled = !(oField.disabled);
	link_id = 'link_' + elName;
	var oLink = document.getElementById (link_id);
	oLink.className = (!(oField.disabled) ? class_true : class_false);

	var notprev_marked = 0;
	for (i = 1; i <= totalCount; i++)
	{
		var element1 = document.getElementById ('highres' + i);
		var element2 = document.getElementById ('ai' + i);
		if (!element1.disabled || !element2.disabled)
		{
			notprev_marked++;
			break;
		}
	}
	if (notprev_marked == 0)
	{
		document.getElementById ('preview_free_download').style.display = 'block';
		document.getElementById ('highres_download').style.display = 'none';
	}
	else
	{
		document.getElementById ('preview_free_download').style.display = 'none';
		document.getElementById ('highres_download').style.display = 'block';
	}
	document.forms['changes_form'].submit ();
	self.focus ();
}

function ToggleButtonPreview (elName, img_true, img_false, alt_true, alt_false)
{
	try
	{
		oOpenerField = opener.document.getElementById (elName);
		if (oOpenerField != null)
		{
			oOpenerField.disabled = !(oOpenerField.disabled);
			opener.document.images[elName + '_img'].src = (!(oOpenerField.disabled) ? img_true : img_false);
		}
	}
	catch (e)
	{

	}

	oField = document.getElementById (elName);
	oField.disabled = !(oField.disabled);
	img_id = elName + '_img';
	document.images[img_id].src = (!(oField.disabled) ? img_true : img_false);
	document.images[img_id].alt = (!(oField.disabled) ? alt_true : alt_false);
	document.images[img_id].title = (!(oField.disabled) ? alt_true : alt_false);
	document.forms['changes_form'].submit ();
	window.focus ();
	setTimeout ('window.focus ()', 200);
}

function SubmitAdvFormSchema (oForm)
{
	oForm.target = oForm.schema_target.value;
	oForm.action = oForm.schema_action.value;
	oForm.submit ();
}

function ToggleCartTable (bFlag, img_true, img_false)
{
	oForm = document.forms['changes_form'];
	for (i = 0; i < oForm.elements.length; i++)
	{
		if (oForm[i].type == 'hidden' && oForm[i].name.substr (0, 4) == 'cart')
		{
			oForm[i].disabled = (bFlag ? 0 : 1);
			document.getElementById (oForm[i].name + '_img').src = (bFlag ? img_true : img_false);
		}
	}
	oForm.submit ();
	self.focus ();
}

function OpenFromIndex (open_url)
{
	ImagePreviewDetails (open_url, '');
	//self.top.location = self_url;
}

function OpenFromGalleries (self_url, objSelect)
{
	content_id = objSelect.options[objSelect.selectedIndex].value;
	ImagePreviewDetails ('preview_box.php?page_num=0&content_id=' + content_id, '');
	self.top.location = self_url;
}

function MakeSearchFocus ()
{
	oFrame = GetFrameByName (top, 'topframe');
	if (oFrame) oFrame.document.forms['searchform'].search.focus ();
}

function ToggleSchool (element_checked)
{
	var school_block = document.getElementById ('school_block');
	if (element_checked) school_block.style.display = 'block';
	else school_block.style.display = 'none';
}

function OpenSchoolWindow (url, windowname)
{
	var width = 450;
	var height = 500;
	var school_user_id = document.forms['form_reg'].school_user_id.options[document.forms['form_reg'].school_user_id.selectedIndex].value;

	if (school_user_id == '')
	{
		alert ('Bitte wählen Sie die Schule!');
		return;
	}
	url = url + '?user_id=' + school_user_id;
	var w = window.open ('' + url + '','' + windowname + '','fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}


function TogglePutCart (content_id)
{
	var cart_image_custom = document.getElementById ("cart_image_custom_" + content_id);
	var cart_hidden_custom = document.getElementById ("cart_hidden_custom_" + content_id);
	var cart_image = document.getElementById ("cart_image_" + content_id);
	var cart_hidden = document.getElementById ("cart_hidden_" + content_id);
	
	var lt_cart_image = document.getElementById ("lt_cart_image_" + content_id);
	var lt_cart_hidden = document.getElementById ("lt_cart_hidden_" + content_id);
	var url_put = "table_cart_ajax.php?action=cart_add&content_id=" + content_id;
	var url_remove = "table_cart_ajax.php?action=cart_remove&content_id=" + content_id;
	var new_url;
	var new_src;
	var new_value;

	if (cart_image_custom != null || cart_image != null)
	{
		var hidden_value = parseInt (cart_hidden.value);

		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.gif";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.gif";
			new_value = 1;
		}
		if (cart_image != null)
		{
			cart_image.src = new_src;
			cart_hidden.value = new_value;
		}
		if (cart_image_custom != null)
		{
			cart_image_custom.src = new_src;
			cart_hidden_custom.value = new_value;
		}
	}
	if (lt_cart_image != null)
	{
		var hidden_value = parseInt (lt_cart_hidden.value);
		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.gif";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.gif";
			new_value = 1;
		}
		lt_cart_image.src = new_src;
		lt_cart_hidden.value = new_value;
	}
	$("#cartblock").load (new_url);
}

function TogglePutCartFromPreview (content_id)
{
	var cart_image = opener.document.getElementById ("cart_image_" + content_id);
	var cart_hidden = opener.document.getElementById ("cart_hidden_" + content_id);
	var cart_image_custom = opener.document.getElementById ("cart_image_custom_" + content_id);
	var cart_hidden_custom = opener.document.getElementById ("cart_hidden_custom_" + content_id);

	var lt_cart_image = opener.document.getElementById ("lt_cart_image_" + content_id);
	var lt_cart_hidden = opener.document.getElementById ("lt_cart_hidden_" + content_id);
	var preview_cart_hidden = document.getElementById ("preview_cart_hidden_" + content_id);
	var url_put = "table_cart_ajax.php?action=cart_add&content_id=" + content_id;
	var url_remove = "table_cart_ajax.php?action=cart_remove&content_id=" + content_id;
	var new_url;
	var new_src;
	var new_value;

	if (cart_image != null)
	{
		var hidden_value = parseInt (cart_hidden.value);

		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.gif";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.gif";
			new_value = 1;
		}
		if (cart_image != null)
		{
			cart_image.src = new_src;
			cart_hidden.value = new_value;
		}
		if (cart_image_custom != null)
		{
			cart_image_custom.src = new_src;
			cart_hidden_custom.value = new_value;
		}
	}
	if (lt_cart_image != null)
	{
		var hidden_value = parseInt (lt_cart_hidden.value);
		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.gif";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.gif";
			new_value = 1;
		}
		lt_cart_image.src = new_src;
		lt_cart_hidden.value = new_value;
	}
	if (parseInt (preview_cart_hidden.value) == 1)
	{
		$("#cart_image_preview_" + content_id).attr("src", "images/cart.gif");
		preview_cart_hidden.value = 0;
		new_url = url_remove;
	}
	else
	{
		$("#cart_image_preview_" + content_id).attr("src", "images/cart_active.gif");
		preview_cart_hidden.value = 1;
		new_url = url_put;
	}

	if (preview_cart_hidden.value == 0)
	{
		$("#price_block").hide ();
	}
	else
	{
		$("#price_block").show ();
	}

	$("#cartblock", opener.document).load (new_url);
}

function CartSavePrice (page, content_id, price)
{
	// pass the price params
	var preis = document.forms[0].pr0.value;
	var plf1field0 = document.forms[0].plf1field0.value;
	var plf2field = document.forms[0].plf2field.value;
	var plf3field0 = document.forms[0].plf3field0.value;
	var plf4field = document.forms[0].plf4field.value;
	var plf5field0 = document.forms[0].plf5field0.value;
	var divson = document.forms[0].divson.value

	var price_params = 'preis=' + preis + ';plf1field0=' + plf1field0 + ';plf2field=' + plf2field + ';plf3field0=' + plf3field0 + ';plf4field=' + plf4field + ';plf5field0=' + plf5field0 + ';divson=' + divson;

	$("#cartblock", opener.document).load ("table_cart_ajax.php?action=price_add&content_id=" + content_id + "&page=" + page + "&price=" + price + "&price_params=" + price_params);
	$("#cartprice", opener.document).load ("table_cart_ajax.php?action=get_cart_price", function()
	{
		$("#cartprice_currency", opener.document).show ();
		$("#price_" + content_id, opener.document).html (price);
		$("#hide_" + content_id, opener.document).show ();
		$("#total_price_postfix", opener.document).show ();
		self.close ();
	});
}
