﻿		var Utf8 = {

		    // public method for url encoding
		    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;
		    },

		    // public method for url decoding
		    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;
		    }

		}
		
		var AIM = {
    frame : function()
	{
        var n = 'RequesterFrame';
		if(!document.getElementById(n))
		{
	        var d = document.createElement('DIV');
	        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.onLoadHandler()"></iframe>';
	        document.body.appendChild(d);
		}
        return n;
    },
    form : function(formObj, name)
	{
        formObj.setAttribute('target', name);
    },
	onLoadHandler : function()
	{
	},
    submit : function(formObj)
	{
		var iframeId = AIM.frame();
		var iframeObj = document.getElementById(iframeId);
		
        AIM.form(formObj, iframeId);	
		var i = document.getElementById(formObj.id + '_load');
		if(i){i.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
		AIM.onLoadHandler = function()
		{
			if(i)
			{
				setTimeout(function()
				{
					i.innerHTML = "&nbsp;";
				}, 1000); 
			}
		};

    },
    submitEx : function(formObj, divid, contentfile, showloader)
	{
		var iframeId = AIM.frame();
		var iframeObj = document.getElementById(iframeId);
        AIM.form(formObj, iframeId);
		var i = document.getElementById(formObj.id + '_load');
		var j = document.getElementById(divid + '_load');
		if(showloader && i){i.innerHTML = "<IMG width='160' height='24' src='../style/ajax-loader.gif'/>";}
		if(j){j.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
		AIM.onLoadHandler = function()
		{
			if(contentfile)
			{
				LoadContent(divid, contentfile, showloader);
			}
			else
			{
				var d;
				if (iframeObj.contentDocument)
				{
					d = iframeObj.contentDocument;
				}
				else if (iframeObj.contentWindow)
				{
					d = iframeObj.contentWindow.document;
				}
				else
				{
					d = window.frames[iframeId].document;
				}
				document.getElementById(divid).innerHTML = d.body.innerHTML;
				reload_images(divid);
			}
		}
    }
}
		
function getHttpRequest()
{
	var xmlHttp = null;
	if (typeof XMLHttpRequest != 'undefined') {
		xmlHttp = new XMLHttpRequest();
		try
		{
			//xmlHttp.overrideMimeType('text/xml; charset=ISO-8859-1');
		}
		catch(e)
		{

		}			
	}
	if (!xmlHttp) {
		// Internet Explorer 6 und 孴er
		try {
			xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp  = null;
			}
		}
	}
	return xmlHttp;
}

function FormToSendstring(objForm)
{
	var string = "";
	if(objForm)
	{
		for (var i = 0; i < objForm.length; i++)
		{
			if(i != 0)
			{
				string += "&";
			}					
			
			string += objForm.elements[i].name + "=" + objForm.elements[i].value;
		}
	}
	return string;
}

function SendContentData(objForm, divid, actionfile, showloader)
{
	if(showloader){document.getElementById(divid).innerHTML = "<IMG width='160' height='24' src='../style/ajax-loader.gif'/>";}
	var xmlHttp = getHttpRequest();
	var loaddiv = document.getElementById(objForm.id + "_load");
	if(loaddiv){loaddiv.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
	var parameters = FormToSendstring(objForm);
	var j = document.getElementById(divid + '_load');
	if(j){j.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4)
		{	
			document.getElementById(divid).innerHTML = xmlHttp.responseText;
		}
	};
	xmlHttp.open('POST', actionfile, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function SendData(objForm, actionfile)
{
	var xmlHttp = getHttpRequest();
	var parameters;
	if(!objForm)
	{
		var loaddiv = document.getElementById(objForm.id + "_load");
		if(loaddiv){loaddiv.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
		parameters = FormToSendstring(objForm);
	}
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4)
		{	
			if(loaddiv){ setTimeout(function(){loaddiv.innerHTML = "";}, 1000); }
		}
	};
	xmlHttp.open('POST', actionfile, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function LoadContent(divid, contentfile, showloader, animation)
{
	if(showloader){document.getElementById(divid).innerHTML = "<IMG width='160' height='24' src='../style/ajax-loader.gif'/>";}
	var xmlHttp = getHttpRequest();
	xmlHttp.open("GET", contentfile, true);
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4)
		{					
			var loaddiv = document.getElementById(divid);
			if(animation)
			{
				loaddiv.style.opacity = 0.0;
			}
			loaddiv.innerHTML = xmlHttp.responseText;
			var l = document.getElementById(divid + '_load');
			if(l){l.innerHTML = "&nbsp;";}
			if(animation)
			{
				window.setTimeout("fadediv('" + divid + "', " + true + ", 0)", 1000);
			}
		}
	};
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	xmlHttp.send(null);
}

function fadediv(divid, inof, op)
{
	var go = false;
	if(inof && op < 100)
	{
		op = op + 30;
		go = true;
	}
	if(!inof && op > 0)
	{
		op = op - 30;
		go = true;
	}
	if(go)
	{
		window.setTimeout("fadediv('"+divid+"', "+inof+", "+op+")", 1);			
	}
	
	op = (op > 100) ? 100 : ((op < 0) ? 0 : op);		
	var mydiv = document.getElementById(divid);
	mydiv.style.filter="Alpha(opacity=" + op + ")"
	mydiv.style.opacity = op/100;
}

function fadediv2(divid, max, inof, op)
{
	var go = false;
	if(inof && op < max)
	{
		op = op + 30;
		go = true;
	}
	if(!inof && op > 0)
	{
		op = op - 30;
		go = true;
	}
	if(go)
	{
		window.setTimeout("fadediv2('" + divid + "', " + max + ", " + inof + ", " + op + ")", 1);			
	}
	
	op = (op > max) ? max : ((op < 0) ? 0 : op);		
	var mydiv = document.getElementById(divid);
	
	mydiv.style.filter="Alpha(opacity=" + op + ")"
	mydiv.style.opacity = op/100;
}

function SendDataLoadContent(objForm, divid, actionfile, contentfile, showloader)
{
	var l = document.getElementById(divid + '_load');
	if(l){l.innerHTML = "<IMG width='16' height='16' src='style/ajax-mini.gif'/>";}
	var xmlHttp = getHttpRequest();
	var parameters;
	if(!objForm)
	{
		var loaddiv = document.getElementById(objForm.id + "_load");
		if(loaddiv){loaddiv.innerHTML = "<IMG width='16' height='16' src='../style/ajax-mini.gif'/>";}
		parameters = FormToSendstring(objForm);
	}
	xmlHttp.onreadystatechange = function ()
	{
		if (xmlHttp.readyState == 4)
		{	
			if(loaddiv){setTimeout(function(){loaddiv.innerHTML = "";}, 1000);}
			LoadContent(divid, contentfile, showloader);
		}
	};
	xmlHttp.open('POST', actionfile, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(parameters);
}

function reload_images(divid)
{
	var all_images= document.getElementById(divid).getElementsByTagName('IMG');
	for (i=all_images.length; i--;)
	{
		with (all_images[i])
		{
			src= src.replace(/(\?ts=\d+)?$/,'?ts='+(1*new Date()));
		}
	}
}
   
function ChangePrice (ob) {
	ob.parentNode.pcount.value = prompt("Anzahl ändern", ob.parentNode.pcount.value);
	ob.parentNode.price.value = prompt("Preis ändern", ob.parentNode.price.value);
	ob.parentNode.submit();
}

function ChangeName (ob) {
	ob.parentNode.pname.value = prompt("Namen ändern", ob.parentNode.pname.value);
	ob.parentNode.submit();
}

SimpleContextMenu.setup({'preventDefault':true, 'preventForms':false});
SimpleContextMenu.attach('E1', 'CM1');
SimpleContextMenu.attach('E2', 'CM2');
SimpleContextMenu.attach('E3', 'CM3');
SimpleContextMenu.attach('E4', 'CM4');

function StartMultiImgViewer(immo, group, lang, id)
{
	window.setTimeout(function() {document.getElementById("imgview_frame").src = 'imgmultiview.inc.php?LANG=' + lang + '&IMMOID=' + immo + '&GROUPID=' + group + '&PICID=' + id;}, 0);
	window.setTimeout(function() {document.getElementById("imgview_bg").style.zIndex = 5; fadediv2("imgview_bg", 75, true, 0);}, 0);
	window.setTimeout(function() {document.getElementById("imgview_viewer").style.zIndex = 5; fadediv2("imgview_viewer", 100, true, 0);}, 500);
}

function StartImgViewer(imgfile)
{
	window.setTimeout(function() {document.getElementById("imgview_frame").src = 'imgview.inc.php?IMGFILE=' + imgfile;}, 0);
	window.setTimeout(function() {document.getElementById("imgview_bg").style.zIndex = 5; fadediv2("imgview_bg", 75, true, 0);}, 0);
	window.setTimeout(function() {document.getElementById("imgview_viewer").style.zIndex = 5; fadediv2("imgview_viewer", 100, true, 0);}, 500);
}

function EndImgViewer()
{
	fadediv2("imgview_viewer", 100, false, 100);
	fadediv2("imgview_bg", 100, false, 75);
	document.getElementById("imgview_bg").style.zIndex = -1;
	document.getElementById("imgview_viewer").style.zIndex = -1;
}

function ChangeDivText(divid, text)
{
	var divobj = document.getElementById(divid);
	divobj.innerHTML = text;
}

function fade(view, div)
{
	
}

function supportTrans()
{
	ret = true;
	if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0, 1) <= 6)
	{
		ret = false;
	}
	return ret;
}

function sizeall(ie)
{
	var WndOfHeight = document.documentElement.offsetHeight + document.body.scrollHeight;
	var WndOfWight  = document.documentElement.offsetWidth + document.body.scrollWidth;
	var WndClHeight = document.documentElement.clientHeight + document.body.scrollHeight;
	var WndClWight  = document.documentElement.clientWidth + document.body.scrollWidth;

	var IF_height = ie ? WndOfHeight : WndClHeight;
	var IF_width  = ie ? WndOfWight : WndClWight;
	
	document.getElementById('imgview_bg').style.width = IF_width + 'px';
	document.getElementById('imgview_bg').style.height = IF_height + 'px';
	
	window.setTimeout('sizeall(' + ie + ')', 50);
}

function getImgDirectory(source) {

    return source.substring(0, source.lastIndexOf('/') + 1);

}

var lastElement = 0;

function toggleElement(id)
{
	id = id == lastElement ? 0 : id;
	schowElement("element_1_a", id == 1);
	schowElement("element_2_a", id == 2);
	schowElement("element_3_a", id == 3);
	schowElement("element_4_a", id == 4);
	schowElement("element_5_a", id == 5);
	schowElement("element_6_a", id == 6);
	schowElement("element_7_a", id == 7);
	lastElement = id;
}

function schowElement(divid, show)
{
	var node = document.getElementById(divid); 
	var nextDIV = node.nextSibling;
	while(nextDIV.nodeName != "DIV")
	{
		nextDIV = nextDIV.nextSibling;
	}	

	if (show)
	{
		if (node.childNodes.length > 0)
		{
			if (node.childNodes.item(0).nodeName == "IMG")
			{
				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "minus.gif";
			}
		}
		nextDIV.style.display = 'block';
	}
	else {
		if (node.childNodes.length > 0)
		{
			if (node.childNodes.item(0).nodeName == "IMG")
			{
  				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "plus.gif";
			}
		}
		nextDIV.style.display = 'none';
	}
}