// url: page that returns xml construct
// ID : id to swap content
var ID2Change;
var prev_character = "";

function getContentFromServer(url, ID) {
	ID2Change = ID;
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}


	http_request.onreadystatechange = getContents4Page;


	http_request.open('POST', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var postText = 'ID2change=' + ID2Change + '&';
	var postTextValue = '';
	for (var i = 0; i < document.forms[0].elements.length; ++i) {
		if (document.forms[0].elements[i].type == "checkbox" || document.forms[0].elements[i].type == 'radio' ) {
			if (document.forms[0].elements[i].checked) {
				postText = postText + '&' + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
			}
		} else {
			postTextValue = document.forms[0].elements[i].value;
			postTextValue = postTextValue.replace(/#/g,'_#_');
			postTextValue = postTextValue.replace(/&/g,'##');
			postText = postText + '&'  + document.forms[0].elements[i].name +'='+postTextValue;
		}
	}

	http_request.send(postText);
}

function OLD__getContentFromServer(url, ID) {
	ID2Change = ID;
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}


	http_request.onreadystatechange = getContents4Page;


	http_request.open('POST', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var postText = 'ID2change=' + ID2Change + '&';
	for (var i = 0; i < document.forms[0].elements.length; ++i) {
		if (document.forms[0].elements[i].type == "checkbox" || document.forms[0].elements[i].type == 'radio' ) {
			if (document.forms[0].elements[i].checked) {
				postText = postText + '&' + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
			}
		} else {
			postText = postText + '&'  + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
		}
	}

	http_request.send(postText);
}

/*
var g_base64_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';


function base64_decode(encStr)
{
var bits;
var decOut = '';
var i = 0;


for(; i < encStr.length; i += 4)
{
bits = (g_base64_table.indexOf(encStr.charAt(i))     & 0xFF) << 18 |
(g_base64_table.indexOf(encStr.charAt(i + 1)) & 0xFF) << 12 |
(g_base64_table.indexOf(encStr.charAt(i + 2)) & 0xFF) <<  6 |
(g_base64_table.indexOf(encStr.charAt(i + 3)) & 0xFF);

decOut += String.fromCharCode((bits & 0xFF0000) >> 16, (bits & 0xFF00) >> 8, bits & 0xFF);
}

if(encStr.charCodeAt(i - 2) == 61)
return(decOut.substring(0, decOut.length - 2));
else if(encStr.charCodeAt(i - 1) == 61)
return(decOut.substring(0, decOut.length - 1));
else
return(decOut);
}
*/

var Base64 = {
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}
}

function base64_encode(txt) {
	return Base64.encode(txt);
}

function base64_decode(txt) {
	return Base64.decode(txt);
}

function checkAll(nameElemente) {
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
			document.forms[0].elements[i].checked = true;
		}
	}
}

function nmbOfCheckedItems(nameElemente) {
	var nmb = 0;
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
			if(document.forms[0].elements[i].checked == true){
				nmb++;
			}
		}
	}
	return nmb;
}

function inverse(nameElemente) {
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		if( document.forms[0].elements[i].name.indexOf(nameElemente) == 0 ) {
			document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
		}
	}
}
function unCheckAll(nameElemente) {
	checkAll(nameElemente);
	inverse(nameElemente);
}

function checkUncheckInvert()
{
	if (document.getElementById('checkboxSelects').value == 'all') {
		checkAll('deleteItems');
	} else if(document.getElementById('checkboxSelects').value == 'none') {
		unCheckAll('deleteItems');
	} else if(document.getElementById('checkboxSelects').value == 'inverse') {
		inverse('deleteItems');
	}
}

function changeCssCheckbox(checkboxName) {
	if(document.getElementById(checkboxName).value == '1') {
		document.getElementById("icon_"+checkboxName).className = 'chbxIcon0';
		document.getElementById(checkboxName).value = '0';
	} else {
		document.getElementById("icon_"+checkboxName).className = 'chbxIcon1';
		document.getElementById(checkboxName).value = '1'
	}
}

function go2url(url) {
	document.forms[0].target="_self";
	document.forms[0].action=url;
	document.forms[0].submit();
}

function speichern() {
	document.forms[0].target="_self";
	document.forms[0].saveData.value="1";
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function getInfo() {
	document.forms[0].target="_self";
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function showPage(pagename, url) {
	document.forms[0].target=pagename;
	document.forms[0].action=url;
	document.forms[0].submit();
}

function change_lang(lang) {
	document.forms[0].target="_self";
	document.forms[0].action=document.URL;
	document.forms[0].plangcode.value=lang;
	document.forms[0].submit();
}

function change_lang4photographer(lang, url2go) {
	document.forms[0].target="_self";
	document.forms[0].action=url2go;
	document.forms[0].plangcode.value=lang;
	document.forms[0].submit();
}

function startSearch() {
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].action="/index.php?module=result";
	document.forms[0].submit();

}
function checkEnter4Searchkey(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		startSearch();
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}
}
function checkEnter4SearchkeyAdvanced(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		startAdvSearch();
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}
}
function checkEnter4Startsearch(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		view(0);
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}

}

function checkEnter4Key(e) {
	var characterCode;
	if(e && e.which){
		e = e
		characterCode = e.which
	} else {
		e = event
		characterCode = e.keyCode
	}

	if(characterCode == 13) {
		return false;
	} else {
		return true;
	}
}
function checkEnter4Email(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;
	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		doLogin();
		return false;
	} else {
		prev_character = characterCode;
		return true;
	}
}

function checkEnter4Password(e) {
	var characterCode;
	if(e && e.which){
		e = e
		characterCode = e.which
	} else {
		e = event
		characterCode = e.keyCode
	}

	if(characterCode == 13) {
		doLogin();
		return false;
	} else {
		return true;
	}
}

function enterPressed(e) {
	var characterCode;
	if (!e) var e = window.event;
	if (e.keyCode) characterCode = e.keyCode;
	else if (e.which) characterCode = e.which;

	//alert(characterCode+' '+prev_character);
	if(characterCode == 13 && prev_character!=40 && prev_character!=38) {
		return true;
	} else {
		prev_character = characterCode;
		return false;
	}
}
function changeCheckedStatus(itemToChange) {
	if (document.getElementById(itemToChange).checked == 1) {
		document.getElementById(itemToChange).checked = 0;
	} else {
		document.getElementById(itemToChange).checked = 1;
	}
}

function showHideObj(whichObject) {
	if (document.getElementById(whichObject).style.display == "block") {
		document.getElementById(whichObject).style.display = 'none';
	} else {
		document.getElementById(whichObject).style.display = 'block';
	}
}

function showObj(whichObject) {
	document.getElementById(whichObject).style.display = 'block';
}

function hideObj(whichObject) {
	document.getElementById(whichObject).style.display = 'none';
}

function checkEnter4Login(e) {
	var characterCode;
	if(e && e.which){
		e = e;
		characterCode = e.which;
	} else {
		e = e;
		characterCode = e.keyCode;
	}

	if(characterCode == 13) {
		saveNlStatus();
		return false;
	} else {
		return true;
	}
}


function validate_email(field) {
	with (field) {
		apos=value.indexOf("@")
		dotpos=value.lastIndexOf(".")
		if (apos<1||dotpos-apos<2) {
			return false
		} else {
			return true
		}
	}
}

function wpreviewBACKUP(url, modus) {
	var maxwidth = 1040;
	var maxheight = 750;

	if(screen.width < maxwidth) {
		var winwidth = (screen.width - 40);
	} else {
		var winwidth = maxwidth;
	}

	if(screen.height < maxheight) {
		var winheight = (screen.height - 60);
	} else {
		var winheight = maxheight;
	}

	if(modus == 'single') {
		var target_url = url;
		var winheight = winheight - 100;
	} else {
		var target_url = url + '&pics='+document.forms[0].thg.value;
	}

	if (typeof fenster == 'undefined' || fenster.closed == true) {
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+winwidth+',height='+winheight+',top=50,left=20,resizable=yes');
	} else {
		fenster.focus();
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	}
	if (parseInt(navigator.appVersion) >= 4) {fenster.window.focus();}
}

function wpreview(url, modus) {
	var maxwidth = 1040;
	var maxheight = 750;

	if(screen.width < maxwidth) {
		var winwidth = (screen.width - 40);
	} else {
		var winwidth = maxwidth;
	}

	if(screen.height < maxheight) {
		var winheight = (screen.height - 60);
	} else {
		var winheight = maxheight;
	}

	if(modus == 'single') {
		var target_url = url;
		var winheight = winheight - 100;
	} else {
		var target_url = url + '&pics='+document.forms[0].thg.value;
	}

	fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+winwidth+',height='+winheight+',top=50,left=20,resizable=yes');
	fenster.focus();
}

function wpreviewSingle(url) {
	var width = 770;
	var height = 650;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var target_url = url;

	if (typeof fenster == 'undefined' || fenster.closed == true) {
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	} else {
		fenster.focus();
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	}
	if (parseInt(navigator.appVersion) >= 4) {fenster.window.focus();}
}

function openRMcalculator(url) {
	var width = 770;
	var height = 650;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var target_url = url;

	if (typeof fenster == 'undefined' || fenster.closed == true) {
		fenster = window.open(target_url,'RM Calculator','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	} else {
		fenster.focus();
		fenster = window.open(target_url,'RM Calculator','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	}
	if (parseInt(navigator.appVersion) >= 4) {fenster.window.focus();}
}

function openBonusOrderWindow(item_id) {
	var width = 600;
	var height = 400;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var target_url = '/cms_bonus_order.php?item_id='+item_id;

	if (typeof fenster == 'undefined' || fenster.closed == true) {
		fenster = window.open(target_url,'BonusOrder','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	} else {
		fenster.focus();
		fenster = window.open(target_url,'BonusOrder','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	}
	if (parseInt(navigator.appVersion) >= 4) {fenster.window.focus();}
}


function getContentFromServer4Login(url, ID) {
	ID2Change = ID;
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		//alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}


	http_request.onreadystatechange = getContents4Page4Login;


	http_request.open('POST', url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var postText = 'ID2change=' + ID2Change + '&';
	for (var i = 0; i < document.forms[0].elements.length; ++i) {
		if (document.forms[0].elements[i].type == "checkbox" || document.forms[0].elements[i].type == 'radio' ) {
			if (document.forms[0].elements[i].checked) {
				postText = postText + '&' + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
			}
		} else {
			postText = postText + '&'  + document.forms[0].elements[i].name +'='+document.forms[0].elements[i].value;
		}
	}

	http_request.send(postText);
}

function getContents4Page4Login() {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
			var nodes = xmldoc.getElementsByTagName("root").item(0);
			switch (ID2Change) {
				case 'loginW':
				var error_msg = base64_decode(nodes.getElementsByTagName("error_msg")[0].firstChild.data);
				if (error_msg == 'none') {
					var userLoginInfoContent = base64_decode(nodes.getElementsByTagName("userLoginInfo")[0].firstChild.data);
					//document.getElementById("userLoginInfo").innerHTML = userLoginInfoContent;
					var loginWContent = base64_decode(nodes.getElementsByTagName("loginWInfo")[0].firstChild.data);
					document.getElementById("login_logout").innerHTML = loginWContent;
					document.getElementById('loginW').style.display = 'none';
					document.getElementById('customerNavigation').style.display = 'block';
					document.getElementById("error_msg").innerHTML = '&nbsp;';
				} else {
					document.getElementById("error_msg").innerHTML = error_msg;
					document.forms[0].login_passwort.value = "";
				}
				break;
			}
		} else {
			alert('Es ist ein Verbindungsproblem aufgetreten ('+http_request.status+'). Bitte versuchen Sie es erneut....');
		}
	}
}

function reloadSessionData() {
	var width = 100;
	var height = 50;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var target_url = "/session_refresh.php";

	if (typeof fenster == 'undefined' || fenster.closed == true) {
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=yes');
	} else {
		fenster.focus();
		fenster = window.open(target_url,'Detail','scrollbars=yes,menubar=no,toolbar=no,status=yes,directories=no,location=no,width='+width+',height='+height+',resizable=yes');
	}
	if (parseInt(navigator.appVersion) >= 4) {fenster.window.focus();}
}

function newwindow(url)
{
	var params;
	var agent = navigator.userAgent;
	var windowName = "SodapixWindow";

	params = "";
	params += "height=556,"
	params += "width=603,"
	params += "left=50,"
	params += "top=50,"
	params += "alwaysRaised=0,"
	params += "directories=0,"
	params += "fullscreen=0,"
	params += "location=0,"
	params += "menubar=b,"
	params += "resizable=1,"
	params += "scrollbars=1,"
	params += "status=0,"
	params += "toolbar=0"

	var win = window.open(url,windowName,params);

	if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1)
	{
		win = window.open(url, windowName , params);
	}

	if (!win.opener)
	{
		win.opener = window;
	}
}

function changeBorderAndGo(pic_id) {
	var elementId = "pic_element_"+pic_id;
	document.getElementById(elementId).className = 'detailHeaderThumbActive';
	if(document.forms[0].previous_pic_id.value != pic_id) {
		var prevElementId = "pic_element_"+document.forms[0].previous_pic_id.value;
		document.getElementById(prevElementId).className = 'detailHeaderThumbPassive';
	}
	document.forms[0].previous_pic_id.value = pic_id;
	parent.detailContent.location.href = '/cms_detail_base.php?pic_id='+pic_id+'&nologo=1';
}

function showHideExtendedSearch() {
	if(document.getElementById('mainNavExtended').style.display == 'none') {
		document.getElementById('mainNavExtended').style.display = 'block';
	} else {
		document.getElementById('mainNavExtended').style.display = 'none';
	}
}
function postEmailToNewsletterForm() {
	document.forms[0].target="_self";
	document.forms[0].action="/index.php?module=newsletter";
	document.forms[0].nl_email.value = document.forms[0].newsletterEmail.value;
	document.forms[0].submit();
}

function doLogin() {
	document.forms[0].target="_self";
	document.forms[0].login.value="1";
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function doLogout() {
	document.forms[0].target="_self";
	document.forms[0].logout.value="1";
	document.forms[0].action='/';
	document.forms[0].submit();
}

// >>>>>>>>>>> functions from cms_result.php <<<<<<<<<<<<<<<<<
function view(page) {
	document.forms[0].target="_self";
	document.forms[0].page.value=page;
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}
function setNrPics(nrOfPics) {
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].epp.value=nrOfPics;
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function checkEnter4search(e){
	characterCode = getCharacterCode(e);
	if(characterCode == 13){
		startSearch();
		return false;
	} else{
		return true;
	}
}
function show_vcds()
{
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].show_vcd_search.value = 1;
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}

function show_pictures()
{
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].show_vcd_search.value = 0;
	document.forms[0].action=document.URL;
	document.forms[0].submit();
}
function startNewSearch(searchkey)
{
	document.forms[0].searchKey.value = searchkey;
	startSearch();
}
function startSearchSelect() {
	document.forms[0].target="_self";
	document.forms[0].page.value=0;
	document.forms[0].action = "/index.php?module=result";
	document.forms[0].submit();
}
function showLicenced() {
	document.forms[0].page.value=0;
	document.forms[0].licenceType.value=document.forms[0].licenseFilter.value;
	document.forms[0].target="_self";
	document.forms[0].action = "/index.php?module=result";
	document.forms[0].submit();
}
function showStyle(style) {
	document.forms[0].page.value=0;
	document.forms[0].styleFilter.value=style;
	document.forms[0].target="_self";
	document.forms[0].action = "/index.php?module=result";
	document.forms[0].submit();
}

function setThumbText(text, pic) {
	document.getElementById("functionText_"+pic).innerHTML = text;
}
function resetThumbText(text, pic) {
	document.getElementById("functionText_"+pic).innerHTML = text;
}

function removeFromLightbox(div_id, pic_id)
{
	document.getElementById(div_id).style.display = 'none';
	document.forms[0].removeFromLighbox.value = pic_id;
	getContentFromServer("ajax/a_cms_result.php","remove_pic_from_lbox");
	showLightboxContent();
}

function createThisLightbox()
{
	if (document.forms[0].lightboxname.value == "") {
		document.getElementById("lightboxName").style.backgroundColor = "#F7D3DC";
	} else {
		getContentFromServer("ajax/a_cms_lightbox.php","addLightboxFromResult");
	}
}
function tMouseOver(tId){
	var tDate = new Date();
	lastPictureId = tId;
	mouseOverStartTime = tDate.getTime();
}

function tMouseOut(tId){
	if( tId == lastPictureId ){
		var tDate = new Date();
		mouseOutEndTime = tDate.getTime();
		mouseOverTime = mouseOutEndTime - mouseOverStartTime;

		storeMouseOver(lastPictureId, mouseOverTime);
		delayedSendMouseOverStatistics();
	}
}

function storeMouseOver( tId, tMilliSec ){
	var i = 0;
	var found = false;
	while(i < mouseOverList.length){
		if( mouseOverList[i][0] == tId ){found = true;break;}
		i++;
	}
	if( found ){
		if(mouseOverList[i][1] < tMilliSec){
			mouseOverList[i][1] = tMilliSec;
			mouseOverList[i][2] = 0;
			countRegistredMO++;
		}
	} else {
		mouseOverList[i] = new Array( tId, tMilliSec, 0 );
		countRegistredMO++;
	}
}

function mouseOverListAsStream(){
	var i = 0;
	var tString = "";
	if( i < mouseOverList.length){
		if( mouseOverList[i][2] == 0 ){
			tString += mouseOverList[i][0] + "," + mouseOverList[i][1];
			mouseOverList[i][2] = 1;
		}
		i++;
		while(i < mouseOverList.length){
			if( mouseOverList[i][2] == 0 ){
				tString += ";" + mouseOverList[i][0] + "," + mouseOverList[i][1];
				mouseOverList[i][2] = 1;
			}
			i++;
		}
	}
	return tString;
}
function delayedSendMouseOverStatistics()
	{
		if( countRegistredMO > 2 ){
			countRegistredMO = 0;
			sendStatisticsMO();
		}
	}
	
// >>>>>>>>>>> functions from cms_detail_base.php <<<<<<<<<<<<<<<<<
function setRMToolResult(article_id){
	getContentFromServer("ajax/a_cms_basket.php","addRMLicenseToArticles");
}

function removeFromBasket(article_id, pic_id) {
	document.forms[0].pic2remove.value = pic_id;
	document.forms[0].article_id.value = article_id;
	getContentFromServer("ajax/a_cms_basket.php","removeFromBasket");
}

function showInfoBlock(infoblock) {
	var det=["picDetailDescription",'picDetailPricing','picDetailLightbox','picDetailSearch','picDetailDownload'];
	for(var i=0; i<det.length;i++){
		if ( document.getElementById(det[i]) ) {
			document.getElementById(det[i]+'Tab').className = 'picDetailTabInactive';
			document.getElementById(det[i]).style.display = 'none';
		}
	}
	document.getElementById(infoblock+"Tab").className = 'picDetailTabActive';
	document.getElementById(infoblock).style.display = 'block';

	document.forms[0].tab_status.value = infoblock;
	getContentFromServer("ajax/a_cms_detail.php","writeTabStatusToSession");
}

function showLightboxContent() {
	if(document.forms[0].lightbox.value != 0) {
		document.getElementById('lightbox_content_picDetail').style.display = 'block';
		document.getElementById('lightbox_content_table_picDetail').style.display = 'block';
		document.getElementById('add_lightbox').style.display = 'none';
		document.forms[0].show_in_detail.value = 1;
		getContentFromServer("/ajax/a_cms_lightbox.php","showLightboxContent_a");
		if( parent.opener.document.forms[0].lightbox != null ) { 
			parent.opener.document.forms[0].lightbox.value=document.forms[0].lightbox.value;
		}
		//parent.opener.showLightboxContent();
		parent.opener.document.forms[0].submit();
	} else {
		document.getElementById('lightbox_content_picDetail').style.display = 'none';
		document.getElementById('lightbox_content_table_picDetail').style.display = 'none';
	}
}
function cancelAddLighbox() {
	document.getElementById('add_lightbox').style.display = 'none';
	document.getElementById('lightbox_content_table_picDetail').style.display = 'block';
}

function setThisRFPrice(article_id, pic_id, price, info, size) {
	document.forms[0].rf_pic_id.value = pic_id;
	document.forms[0].rf_info.value = info;
	document.forms[0].rf_price.value = price;

	document.getElementById('rfElement_'+pic_id+'_'+info).checked = true;
	getContentFromServer("ajax/a_cms_basket.php","putRFtoArticles");
}

function hideLightboxContent() {
	document.getElementById('lightbox_content_picDetail').style.display = 'block';
	document.getElementById('lightbox_content_table_picDetail').style.display = 'block';
	document.getElementById('add_lightbox').style.display = 'none';
}

function resetParentFields()
{
    parent.window.opener.document.forms[0].searchKey.value = '';
    parent.window.opener.document.forms[0].coll_id.value = '';
    parent.window.opener.document.forms[0].photographersSearch.value = '';
    parent.window.opener.document.forms[0].externalSearch.value = 1;
}
function searchThisKeywords() {
	var searchkeys = '';

	for(i=0;i<document.forms[0].keyword.length;i++) {
		if(document.forms[0].keyword[i].checked == true) {
			searchkeys +='"'+ document.forms[0].keyword[i].value+'" ';
		}
	}
	if (document.forms[0].detailKeyword.value != '') {
		searchkeys = document.forms[0].detailKeyword.value+" "+searchkeys;
	}
	parent.window.opener.focus();
    resetParentFields();
	if(document.forms[0].pixFromThisPhotographer.checked == true) {
		//parent.window.opener.document.forms[0].pcode.value = document.forms[0].pixFromThisPhotographer.value;
		parent.window.opener.document.forms[0].photographersSearch.value = document.forms[0].pixFromThisPhotographer.value;
	} else {
		// parent.window.opener.document.forms[0].searchkey.value = searchkeys;
	}
	if(document.forms[0].pixFromThisCollection.checked == true) {
		parent.window.opener.document.forms[0].coll_id.value = document.forms[0].pixFromThisCollection.value;
	}
	if (searchkeys!='') {
		parent.window.opener.document.forms[0].searchKey.value = searchkeys;
	} else {
		parent.window.opener.document.forms[0].searchKey.value = '';
	}
	parent.window.opener.startSearch();
	parent.self.close();
}

function searchThisPhotographer(pid) {
	parent.window.opener.focus();
    resetParentFields();
	parent.window.opener.document.forms[0].photographersSearch.value = pid;
	parent.window.opener.document.forms[0].searchKey.value = '';
	parent.window.opener.startSearch();
	parent.self.close();
}

function searchThisCollection(cid) {
	parent.window.opener.focus();
    resetParentFields();
	parent.window.opener.document.forms[0].coll_id.value = cid;
	parent.window.opener.document.forms[0].searchKey.value = '';
	parent.window.opener.startSearch();
	parent.self.close();
}
function closeAndLoadBasket() {
	parent.window.opener.location = '/index.php?module=basket';
	parent.self.close();
}
function checkEnter4LoginDetail(e) {
	var characterCode;
	if(e && e.which){
		e = e;
		characterCode = e.which;
	} else {
		e = event
		characterCode = e.keyCode;
	}

	if(characterCode == 13) {
		doDetailLogin();
		return false;
	} else {
		return true;
	}
}
function showVCDinParent(vcd_id) {
	parent.window.opener.location = '/index.php?module=result&vcd='+vcd_id;
}
function moveVcdToBasket(id) {
    if(parent && parent.window && parent.window.opener) {
        tValue = parent.window.opener.document.forms[0].nmb_basket_articles.value;
        tValue = parseInt(tValue);
        tValue += 1;
        parent.window.opener.document.forms[0].nmb_basket_articles.value = tValue;
        tInfoString = "";
        if( tValue > 0 ){
            if( tValue == 1 ){
                tPicturesText = parent.window.opener.document.forms[0].text_basket_single_article.value;
            } else {
                tPicturesText = parent.window.opener.document.forms[0].text_basket_multiple_articles.value;
            }
            tInfoString = "("+tValue+"&nbsp;"+tPicturesText+")";
            document.getElementById("vcdWasMovedToBasket").innerHTML = '- ok';
        }
        parent.window.opener.document.getElementById('info_basket_articles').innerHTML = "WARENKORB&nbsp;"+tInfoString;
        document.forms[0].pic2basket.value = id;
        getContentFromServer("ajax/a_cms_basket.php","addVcdToBasket");
    } else {
        if( document.forms[0].pic2basket != null ) {
            document.forms[0].pic2basket.value = id;
        } else if( parent.window.opener.document.forms[0].pic2basket != null ) {
            parent.window.opener.document.forms[0].pic2basket.value = id;
        } else {
            return;
        }
        getContentFromServer("ajax/a_cms_basket.php","addVcdToBasket");
    }
        
}


//Event.observe(window, 'load', function() {
//  var list = $$('img');
//  for( var i=0; i<list.length; i++ ) {
//	  if (!list[i].complete || typeof list[i].naturalWidth == "undefined" || list[i].naturalWidth == 0) {
//		  list[i].src   = '/img/coming_soon.png';
//	  }
//  }
//});
