<!--

/*****************************************************************
JavaScript for SpandauGo / Kontakt
 	- Doc Holiday Data -

created by 	Dr.Holger Maerz 
version: 1.0 
Last Date Changes: 25.02.2007 
edited by: (pls enter name and date)

this class is for proving user input if JavaScript is enabled
bind key events to input fields ; input trimming ; bgColor for mandatory fields ;
switching color after input validation ; enables and disables button ; emailCheck  
*******************************************************************/

/////////////////////////////////////////////////////////////////////////////////////
//News CLASS
/////////////////////////////////////////////////////////////////////////////////////
 	
function ShoutBox(){
	
	this.bgColorError="#E9967A";
	this.bgColor="#587498";
	this.name=document.getElementsByName("sbname")[0];
	this.nr=document.getElementsByName("sbnr")[0];
	this.msg=document.getElementsByName("sbmsg")[0];
	this.ip=document.getElementsByName("sbip")[0];
	this.email=document.getElementsByName("sbmail")[0];
	this.resetBtn=document.getElementsByName("sbreset")[0];
	this.sentBtn=document.getElementsByName("sbsend")[0];
	this.adminPic="images/admin1.png";
	this.userPic="images/world2.png";
	
	this.getActualPage=function(){
		try {
				
				if(document.getElementsByName("sb_page")[0])
					return parseInt(document.getElementsByName("sb_page")[0].value);
				
				return parseInt(1);
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.getActualPage()\r\n\r\n" +e);
		}
	}
	
	this.setActualPage=function(page){
		try {
				
				
				new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "setActualPage", param: page} 
						
				});
				
				if(document.getElementsByName("sb_page")[0])
					document.getElementsByName("sb_page")[0].value=page;
				
				
				
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.setActualPage()\r\n\r\n" +e);
		}
	}
	
	this.init=function(){
	
		try {
				var myObj=this;
				var page = myObj.getActualPage();
				
				//init smilies
				myObj.initSmilies();
				
				//init HelpBox
				myObj.initHelp();
				myObj.addDragDrop("menuebar");
				
				//init allBtns & input fields
				myObj.initButtons();
				
				//if first page periodical updating
				//if(page==1)myObj.showActualShouts();
				
				/*		
				new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "getTotalPages"} ,
						
						onComplete: function(json) {
						
							var data = eval('(' + json.responseText + ')');
							
							myObj.makeStepper(page,data.total)	;			
						}
						
				});
				
				
				*/
				
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.init()\r\n\r\n" +e);
		}		
	}
	
	this.initButtons=function(){
		
		try{
				var myObj=this;
			
				//deaktiviere formular onsubmit
				//if(document.getElementsByName("sb_inputform")[0])
				//	document.getElementsByName("sb_inputform")[0].onsubmit=function(){return false};
				
				//deaktiviere formular onsubmit
				//if(document.getElementsByName("sb_adminform")[0])
				//	document.getElementsByName("sb_adminform")[0].onsubmit=function(){return false};
					
				//deaktiviere formular onsubmit
				if(document.getElementsByName("sb_helpclose")[0])
					document.getElementsByName("sb_helpclose")[0].onsubmit=function(){return false};			
			
				//deaktiviere formular onsubmit
				if(document.getElementsByName("sb_helpshow")[0])
					document.getElementsByName("sb_helpshow")[0].onsubmit=function(){return false};		
				
				//deaktiviere formular onsubmit
				if(document.getElementsByName("sb_helpclose2")[0])
					document.getElementsByName("sb_helpclose2")[0].onsubmit=function(){return false};		
						
				//init reset
				//if(myObj.resetBtn)myObj.resetBtn.onclick = myObj.reset;
				
				//init sent
				//if(myObj.sentBtn)myObj.sentBtn.onclick  = myObj.sent;
				
				//init input name
				//myObj.name.onkeyup=myObj.testUI;
								
				//init input msg
				//myObj.msg.onkeyup=myObj.testUI;
								
				//init input email
				//myObj.email.onkeyup=myObj.testUI;
				/*
				if(document.getElementsByName("sb_adminTrigger")[0]){
					document.getElementsByName("sb_adminTrigger")[0].onclick=myObj.triggerAdmin;
				}	
				
				if(document.getElementsByName("sbedit")[0]){
					document.getElementsByName("sbedit")[0].onclick=myObj.editShout;
				}
				
				if(document.getElementsByName("sbdelete")[0]){
					document.getElementsByName("sbdelete")[0].onclick=myObj.deleteShout;
				}
			
				if(document.getElementsByName("sbspam")[0]){
					document.getElementsByName("sbspam")[0].onclick=myObj.spamShout;
				}
				
				if(document.getElementsByName("sbham")[0]){
					document.getElementsByName("sbham")[0].onclick=myObj.hamShout;
				}
				*/
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.initButtons()\r\n\r\n" +e);
		}	
		
	}
	
	this.triggerAdmin=function(){
		
		try {		
			var trigger=document.getElementsByName("sb_adminTrigger")[0];
			if(!trigger)return;
			
			var sb = new ShoutBox();
			var imgName=sb.getImgName(trigger.src);
			var imgAdmin=sb.getImgName(sb.adminPic);
			var admin=true;
			var page=sb.getActualPage();
			
			if(imgName==imgAdmin){
					admin=false;
					trigger.src=sb.userPic;
					trigger.title="<u> - User View";
					trigger.alt="User";
					trigger.access="u";
			}
			else{
					trigger.src=sb.adminPic;
					trigger.title="<a> - Administration";
					trigger.alt="Admin";
					trigger.access="a";
			}
			
			//evaluating admin access
			document.getElementsByName("sbadminEdit")[0].value=admin;
			//making shouts						
			sb.makeShouts(page);
			
					
			//making buttons for edit etc
			if(admin){
				document.getElementById("shouts_button").style.display="none";
				document.getElementById("shouts_adminbtn").style.display="block";
			}
			else{
				sb.msg.value="";
				document.getElementById("shouts_button").style.display="block";
				document.getElementById("shouts_adminbtn").style.display="none";
			}
			
			
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.triggerAdmin()\r\n\r\n" +e);
		}
	
	}
	
	this.makeShouts=function(page){
		try{
			var sb = new ShoutBox();
			var container = document.getElementById("shouts_container");
			
			//casting is shitty in JS
			var isEdit = false;
			if(document.getElementsByName("sbadminEdit")[0])
				isEdit=(document.getElementsByName("sbadminEdit")[0].value.toLowerCase() == "true");
				
			sb.stopActualShouts();
			
			new Ajax.Request('AJAX/AJAXManager.php',{ 
					
					method: 'post', 
					parameters: {method: "makeShoutBox", param: page} ,
					
					onComplete: function(json) {
					
						var data = eval('(' + json.responseText + ')');
						
						container.innerHTML=data.allShouts;	
						
						if(isEdit)sb.addEvents();
						else sb.removeEvents();
						
						if(!isEdit && page==1)sb.showActualShouts();//periodical updater
					}
			});
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.makeShouts()\r\n\r\n" +e);
		}	
		
	}
	
	this.addEvents=function(){
		try{
			var container = document.getElementById("shouts_container");
			var myObj = new ShoutBox();
			var nr 	= myObj.nr.value;
									
			for(var i=0; i<container.childNodes.length;i++){
				
				if(nr!=container.childNodes[i].getElementsByTagName("input")[0].value)
					container.childNodes[i].style.background=myObj.bgColor;
				container.childNodes[i].style.cursor="pointer";
				container.childNodes[i].onclick=myObj.selectShout;
				container.childNodes[i].onmouseover=myObj.onFocus;
				container.childNodes[i].onmouseout=myObj.onFocus;
			}
			
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.addEvents()\r\n\r\n" +e);
		}		
		
	}
	
	this.removeEvents=function(){
		try{
			var container = document.getElementById("shouts_container");
			var myObj = new ShoutBox();
				
			for(var i=0; i<container.childNodes.length;i++){
				
				container.childNodes[i].style.background=myObj.bgColor;
				container.childNodes[i].style.cursor="default";
				container.childNodes[i].onclick=null;
				container.childNodes[i].onmouseover=null;
				container.childNodes[i].onmouseout=null;
			}
			
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.removeEvents()\r\n\r\n" +e);
		}		
		
	}
	
	this.onFocus=function(ev){
		//set color
		try{
			//get event source
			if (!ev){	source = window.event.srcElement;
						type   = window.event.type;
			}
			else { 		source=ev.target;
						type   = ev.type;
			}
			//parent div
			while(source!=null){
				if(source.tagName=="DIV")break;
				source=source.parentNode;	
			}	if(source==null)return;	
			
			var sb = new ShoutBox();
			if(type=="mouseover")
				source.style.background=sb.bgColorError;
			else if(type=="mouseout")
				source.style.background=sb.bgColor;
				
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.onFocus()\r\n\r\n" +e);
		}	
	}
	
	
	this.selectShout=function(ev){
		//admin action: shout is selected for edit
		try{
				//get event source
				if (!ev)	source = window.event.srcElement;
				else  source=ev.target;
				
				while(source!=null){
					if(source.tagName=="DIV")break;
					source=source.parentNode;	
				}	if(source==null)return;	
				
				var sb = new ShoutBox();
				sb.removeEvents();
				sb.addEvents();//set mouse events
				
				//current is selected
				source.style.background=sb.bgColorError;
				source.onmouseout=null;
				source.onmouseover=null;
				
				var allInput = source.getElementsByTagName("input");
				var shoutNr  = -1;
				for(var i=0; i<allInput.length; i++){
					if(allInput[i].name=="actual_sbnr"){
						shoutNr=allInput[i].value;
						break;
					}
				}
				if(shoutNr<0)return;
					sb.nr.value=shoutNr;// actual shout
				
				new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "getShout", param: shoutNr} ,
						
						onComplete: function(json) {
							
							var data = eval('(' + json.responseText + ')');
						   
						   	sb.name.value=data.shout["NAME"];	
						   	sb.email.value=data.shout["EMAIL"];		
						   	sb.msg.value=data.shout["MSG"];		
							
						}
						
				});
			
				
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.selectShout()\r\n\r\n" +e);
		}	
		
	}
			
	
	this.makeAttribute=function(element,attribute,value){
		
		try{
				var att	= document.createAttribute(attribute);
				att.nodeValue =value;
				element.setAttributeNode(att);
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.makeAttribute()\r\n\r\n" +e);
		}
		
	}
	
	this.getImgName=function(path){
		
		try{
			var res="";
			var REG=/^(.*\/)*(.*\..{3,})$/;
			if(REG.exec(path)) res=RegExp.$2;
				
			
			return res;
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.getImgName()\r\n\r\n" +e);
		}
	}
	
	
	this.initHelp=function(){
		
		try{
			document.getElementsByName("sb_info_btn")[0].onclick=this.triggerHelp;
			var sbcloseBtn=document.getElementsByName("sbinfo_close_btn")[0];
			var sbcloseBtn2=document.getElementsByName("sbinfo_close")[0];
			
			sbcloseBtn.onclick=this.closeHelp;
			sbcloseBtn2.onclick=this.closeHelp;
			this.makeHelpPanel();
			
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.initHelp()\r\n\r\n" +e);
		}	
		
	}
	
	this.closeHelp=function(){
		
		try{
				var sbHelpBox=document.getElementById("shoutbox_info");
				sbHelpBox.style.visibility="hidden";
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.closeHelp()\r\n\r\n" +e);
		}		
	}
	
	this.makeHelpPanel=function(){
	
		try{	
				YAHOO.util.Event.onDOMReady(
				
		        function() {
		
		            // Setup constants
		            // QUIRKS FLAG, FOR BOX MODEL
		            var IE_QUIRKS = (YAHOO.env.ua.ie && document.compatMode == "BackCompat");
		
		            // UNDERLAY/IFRAME SYNC REQUIRED
		            var IE_SYNC = (YAHOO.env.ua.ie == 6 || (YAHOO.env.ua.ie == 7 && IE_QUIRKS));
		
		            // PADDING USED FOR BODY ELEMENT (Hardcoded for example)
		            var PANEL_BODY_PADDING = (10*2) // 10px top/bottom padding applied to Panel body element. The top/bottom border width is 0
	
		            // Create a panel Instance, from the 'resizablepanel' DIV standard module markup
		            var panel = new YAHOO.widget.Panel('shoutbox_info', {
		                draggable: true,
		                width: '500px',
		                visible:false,  
		                xy:[50,100],  
		                context: ["", "tl", "bl"]
		            });
		       		
		       		panel.render();
		
		            // Create Resize instance, binding it to the 'resizablepanel' DIV 
		            var resize = new YAHOO.util.Resize('shoutbox_info', {
		                handles: ['br'],
		                autoRatio: true,
		                minWidth: 300,
		                minHeight: 100,
		                status: true
		            });
			
		            // Setup resize handler to update the size of the Panel's body element
		            // whenever the size of the 'resizablepanel' DIV changes
		            resize.on('resize', function(args) {
							
		                var panelHeight = args.height;
		                var headerHeight = this.header.offsetHeight; // Content + Padding + Border
		                var footerHeight = this.footer.offsetHeight; // Content + Padding + Border
		
		                var bodyHeight = (panelHeight - headerHeight - footerHeight);
		                var bodyContentHeight = (IE_QUIRKS) ? bodyHeight : bodyHeight - PANEL_BODY_PADDING;
		
		                YAHOO.util.Dom.setStyle(this.body, 'height', bodyContentHeight + 'px');
		
		                if (IE_SYNC) {
		
		                    // Keep the underlay and iframe size in sync.
		
		                    // You could also set the width property, to achieve the 
		                    // same results, if you wanted to keep the panel's internal
		                    // width property in sync with the DOM width. 
		
		                    this.sizeUnderlay();
		
		                    // Syncing the iframe can be expensive. Disable iframe if you
		                    // don't need it.
		
		                    this.syncIframe();
		                }
		            }, panel, true);
		            
		        }
		    );
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.makeHelpPanel()\r\n\r\n" +e);
		}	
	}
	//drag&drop YUI
	this.addDragDrop=function(id) {
		
		try{
			/*uses Yahoo UI Lib for drag&drop of helper window*/		
			function ddParent(id, sGroup, onDragStyleClass, onStopStyleClass) {

				  if (id) {
				    // get parent id (window block element) and store it
				    this.parentId = document.getElementById(id).parentNode.id;
						
				    // invoke init method from superclass with parent id to set parent as
				    // drag and drop element
				    this.init(this.parentId);
						
				    // Set a child element of set element in init method which should be
				    // used to initiate the drag operation. In this case the given id
				    // vi constructor (window head element) should be initiat the drag operation.
				    this.setHandleElId(id);
						
				    
				    }
				}
			
			// extend from class DD
			ddParent.prototype = new YAHOO.util.DD();
			var dragElement = new ddParent(id, "", "", "");
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.addDragDrop()\r\n\r\n" +e);
		}		
	}
		
	this.triggerHelp=function(){
		
		try{
				var sbHelpBox=document.getElementById("shoutbox_info");
				
				if(sbHelpBox.style.visibility=="visible")
					 sbHelpBox.style.visibility="hidden";
				else sbHelpBox.style.visibility="visible";	
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.triggerHelp()\r\n\r\n" +e);
		}	
	}
	
	this.initSmilies=function(){
		
		try{
			
			var parent=document.getElementById("shouts_smilies");
			
			var smilies = parent.getElementsByTagName("input");
			for(var i=0;i<smilies.length;i++){
				smilies[i].onclick=this.setSmilie;
			}
		
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.initSmilies()\r\n\r\n" +e);
		}
		
	}
	
	this.testUI=function(ev){
		
		try{
			
			//get event source
			if (!ev)	source = window.event.srcElement;
			else  source=ev.target;
			
			var sb = new ShoutBox();
			var val = sb.trim(source.value);
								
			if(source==sb.name)	
				sb.setErrorColor(source, !(source.value.length>0 && source.value!="Name"));
			
			if(source==sb.msg)	
				sb.setErrorColor(source, !(source.value.length>0 && source.value!="Nachricht"));
			
			if(source==sb.email){
				var okEmail=true;
				if(source.value.length>0 && source.value!="Email") okEmail = sb.checkEmail(source.value);
				sb.setErrorColor(source, !(okEmail));
			}	
					
			
			
			
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.testUI()\r\n\r\n" +e);
		}
	}
	
	
	this.isValid=function(){
		
		try{
			var sb = new ShoutBox();
			
			var nameVal = sb.trim(sb.name.value);
			var msgVal = sb.trim(sb.msg.value);
			var emailVal = sb.trim(sb.email.value);
					
			var okName = nameVal.length>0 && nameVal!="Name"; 	
			sb.setErrorColor(sb.name, !okName);
			
			var okMsg = msgVal.length>0 && msgVal!="Nachricht";
			sb.setErrorColor(sb.msg, !okMsg);
			
			
			var okEmail=true;
			if(emailVal.length>0 && emailVal!="Email") 
				okEmail = sb.checkEmail(emailVal);
			
			sb.setErrorColor(sb.email, !okEmail);
			
			return okName && okMsg && okEmail;
			
			
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.isValid()\r\n\r\n" +e);
		}
		
	}
	
	this.setErrorColor=function(target, error){
		try{
				(error)?target.style.background=this.bgColorError:target.style.background=this.bgColor;
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.setErrorColor()\r\n\r\n" +e);
		}
		
	}
	
	this.reset=function(){
		
		try{
			
			var sb = new ShoutBox();
			sb.name.value="Name";
			sb.email.value="Email";
			sb.msg.value="Nachricht";			
			
			sb.setErrorColor(sb.name, false);
			sb.setErrorColor(sb.msg, false);
			sb.setErrorColor(sb.email, false);
				
			sb.removeCookie("ShoutBoxName");
			sb.removeCookie("ShoutBoxEmail");
		
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.reset()\r\n\r\n" +e);
		}
	}
	
		
	this.sent=function(){
		
		try{
			
			var sb = new ShoutBox();
			var name = sb.trim(sb.name.value);
			var email =sb.trim(sb.email.value);
			var msg  = sb.trim(sb.msg.value);	
			
			//if input not valid 
			if(!sb.isValid())return;
			
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "isSPAM", param: name, param2: msg, param3: email} ,
						
						onComplete: function(json) {
							
									var isSPAM = eval('(' + json.responseText + ')');
									
									if(isSPAM){
										
										sb.msg.value="";
										sb.name.value="";
										sb.email.value="";
										return;
									}
									new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
												method: 'post', 
												parameters: {method: "writeShoutBox", param: name, param2: msg, param3: email} ,
												
												onComplete: function() {
													
															sb.setActualPage(1);
															sb.makeShouts(1);
															sb.msg.value="";
															sb.setCookie("ShoutBoxName", name);
															sb.setCookie("ShoutBoxEmail",email);
												}
												
									});
			
									new Ajax.Request('AJAX/AJAXManager.php',{ 
											
											method: 'post', 
											parameters: {method: "getTotalPages"} ,
											
											onComplete: function(json) {
											
												var data = eval('(' + json.responseText + ')');
												sb.makeStepper(1,data.total)	;			
											}
									});
											
						}
						
			});
			
			
		
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.sent()\r\n\r\n" +e);
		}
		
	}
	
	this.editShout=function(){
		
		try{
			
			var sb = new ShoutBox();
			var name = sb.trim(sb.name.value);
			var email =sb.trim(sb.email.value);
			var msg  = sb.trim(sb.msg.value);	
			var nr 	= sb.nr.value;
	
			//if input not valid 
			if(!sb.isValid())return;
			
			
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "editShout", param: name, param2: msg, param3: email, param4: nr} ,
						
						onComplete: function() {
							
							var page = sb.getActualPage();
							sb.msg.value="";
							sb.makeShouts(page);
							
						}
						
			});
						
		
		}
		catch(e){		
				alert("JavScript Exception: ShoutBox.editShout()\r\n\r\n" +e);
		}
		
	}
	
	
	
	
	this.spamShout=function(){
		
		try{
			
			var sb = new ShoutBox();
			var nr 	= sb.nr.value;
			
			
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "getShout", param: nr } ,
						
						onComplete: function(json) {
							
							var data = eval('(' + json.responseText + ')');		
							var name=data.shout["NAME"];	
							var email=data.shout["EMAIL"];
							var msg=data.shout["MSG"];
							var ip=data.shout["IP"];
							sb.registerSPAM(name, msg, email, ip, nr);
						   		
						}					
						
						
			});
			
			
		
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.spamShout()\r\n\r\n" +e);
		}
		
	}
	
	this.registerSPAM=function(name, msg, email, ip, nr){
		
		try{
			
			var sb = new ShoutBox();
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "registerSPAM", param:name, param2:msg, param3:email, param4:ip } ,
						
						onComplete: function(json) {
							
							
							var data = eval('(' + json.responseText + ')');		
							//alert(data.error);
							sb.deleteSPAM(nr);			
						}					
						
						
			});
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.registerSPAM()\r\n\r\n" +e);
		}
			
		
	}
	
	this.deleteSPAM=function(nr){
		
		try{
			
			var sb = new ShoutBox();
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "deleteShout", param:nr } ,
						
						onComplete: function() {
							
							var page = sb.getActualPage();
							sb.makeShouts(page);
							
							sb.msg.value="";
							sb.email.value="";
							sb.name.value="";	
							
						}					
						
						
			});
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.deleteSPAM()\r\n\r\n" +e);
		}
			
		
	}
	
	this.hamShout=function(){
		
		try{
			
			var sb = new ShoutBox();
			var nr 	= sb.nr.value;
			
			
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "getShout", param: nr } ,
						
						onComplete: function(json) {
							
							var data = eval('(' + json.responseText + ')');		
							
							var msg=data.shout["MSG"];
							sb.registerHAM(msg);
						   		
						}					
						
						
			});
		
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.hamShout()\r\n\r\n" +e);
		}
		
	}
	
	this.registerHAM=function(msg){
		
		try{
			
			
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "registerHAM", param:msg } ,
						
						onComplete: function(json) {
							
							
							var data = eval('(' + json.responseText + ')');		
							//alert(data.error);
										
						}					
						
						
			});
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.registerHAM()\r\n\r\n" +e);
		}
			
		
	}
	
	this.deleteShout=function(){
		
		try{
			
			var sb = new ShoutBox();
			var nr 	= sb.nr.value;
	
				
			new Ajax.Request('AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "deleteShout", param: nr} ,
						
						onComplete: function() {
							
							var page = sb.getActualPage();
							sb.makeShouts(page);
							
							sb.msg.value="";
							sb.email.value="";
							sb.name.value="";		
							
							
							
						}
						
			});
						
		
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.deleteShout()\r\n\r\n" +e);
		}
		
	}
	
	
	this.findCookie=function(name){
		
		try {
			//cookies löschen
			if(!document.cookie)return false;
			
			var allCookies=document.cookie.split(";");
			for(var i=0;i<allCookies.length;i++){
				
				//name
				var end=allCookies[i].indexOf("=");
				if(end==-1)next;
				
				if(name==allCookies[i].substring(0,end)) return true;
				
			}
			return false;
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.findCookie()\r\n\r\n" +e);
		}
	}
	
	this.getCookieValue=function(name){
		
		try {
			//cookies auslesen
			if(!document.cookie)return "";
			
			var allCookies=document.cookie.split(";");
			for(var i=0;i<allCookies.length;i++){
				
				//name
				var end=allCookies[i].indexOf("=");
				if(end==-1)next;
				if(name==allCookies[i].substring(0,end))
					return allCookies[i].substring(end+1);
				
			}
			return "";
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.getCookieValue()\r\n\r\n" +e);
		}
			
	}
	
	this.removeCookie=function(name){
		
		try {
			
			var value=this.getCookieValue(name);
			var cookie=name+'='+value+"; expires=Fri, 02-Jan-1970 00:00:00 GMT";
			document.cookie=cookie;
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.removeCookie()\r\n\r\n" +e);
		}
			
	}
	
	this.setCookie=function(name, value){
		
		try {
			
			var verfallsdatum=(new Date((new Date).getTime()+3600000*24*30*3)).toGMTString();
			var cookie=name+'='+value+";expires="+verfallsdatum;
			document.cookie=cookie;
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.setCookie()\r\n\r\n" +e);
		}
			
	}
	
	this.showActualShouts=function(){
		
		try {
			
			var container = document.getElementById("shouts_container");
			shoutBoxUpdater = new Ajax.PeriodicalUpdater('', 'AJAX/AJAXmanager.php',{ 
						
						method: 'post', 
						parameters: {method: "makeShoutBox", param: 1} ,
						frequency : 12,
 						decay : 1,
						
						onSuccess: function(json) {
						
							var data = eval('(' + json.responseText + ')');
							container.innerHTML=data.allShouts;		
						}
			});
			
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.showActualShouts()\r\n\r\n" +e);
		}
			
	}
	
	this.stopActualShouts=function(){
		
		try {
			
				if(shoutBoxUpdater)	shoutBoxUpdater.stop();
		
			
		}
		catch(e){		
				alert("JavaScript Exception: ShoutBox.stopActualShouts()\r\n\r\n" +e);
		}
			
	}
	
	this.makeStepper=function(page,total){
	
		try {
			
				var node = document.getElementById("shouts_stepper");
				node.innerHTML="";
				var accesskey ="<";
				var tabindex=8;
				var title="["+accesskey+"] zur ersten Seite";
				
				
				if(page>1){
					var img = document.createElement("img");
					img.src="images/first.png";
					img.alt=title;
					img.tabindex=tabindex++;
					img.accesskey=accesskey;
					img.onclick=this.firstPage;
					node.appendChild(img);
					
					var img = document.createElement("img");
					accesskey ="-";
					var title="["+accesskey+"] eine Seite zurück";
					img.src="images/prev.png";
					img.alt=title;
					img.tabindex=tabindex++;
					img.accesskey=accesskey;
					img.style.marginRight="2px";
					img.onclick=this.prevPage;
					node.appendChild(img);
					
					var anchor = document.createElement("a");
					anchor.href="javascript:void(0)";
					anchor.title=title;
					anchor.onclick=this.prevPage;
					var text = document.createTextNode(page-1);
					anchor.appendChild(text);
					node.appendChild(anchor);
				}
				
				var span = document.createElement("span");
				span.title="aktuelle Seite";
				var text = document.createTextNode(page);
				span.appendChild(text);
				node.appendChild(span);
				
				if(page<total){
					var anchor = document.createElement("a");
					accesskey ="+";
					var title="["+accesskey+"] zur nächsten Seite";
					anchor.href="javascript:void(0)";
					anchor.title=title;
					anchor.style.marginRight="2px";
					anchor.onclick=this.nextPage;
					var text = document.createTextNode(page+1);
					anchor.appendChild(text);
					node.appendChild(anchor);
					
					var img = document.createElement("img");
					img.src="images/next.png";
					img.alt=title;
					img.tabindex=tabindex++;
					img.accesskey=accesskey;
					img.onclick=this.nextPage;
					node.appendChild(img);
					
					var img = document.createElement("img");
					accesskey =">";
					var title="["+accesskey+"] zur letzten Seite";
					img.src="images/last.png";
					img.alt=title;
					img.tabindex=tabindex++;
					img.accesskey=accesskey;
					img.onclick=this.lastPage;
					node.appendChild(img);
				}
				
			
				
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.makeStepper()\r\n\r\n" +e);
		}		
	}
	
	this.nextPage=function(){
		
		try {
		
			var sb = new ShoutBox();
			var page = sb.getActualPage()+1;
			
			
			sb.setActualPage(page);
			sb.makeShouts(page);
			
			new Ajax.Request('AJAX/AJAXManager.php',{ 
					
					method: 'post', 
					parameters: {method: "getTotalPages"} ,
					
					onComplete: function(json) {
					
						var data = eval('(' + json.responseText + ')');
						sb.makeStepper(page,data.total)	;			
					}
			});
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.nextPage()\r\n\r\n" +e);
		}
	}
	
	this.prevPage=function(){
		try {
		
			var sb = new ShoutBox();
			var page = sb.getActualPage()-1;
			sb.setActualPage(page);
			sb.makeShouts(page);
			
			new Ajax.Request('AJAX/AJAXManager.php',{ 
					
					method: 'post', 
					parameters: {method: "getTotalPages"} ,
					
					onComplete: function(json) {
					
						var data = eval('(' + json.responseText + ')');
						sb.makeStepper(page,data.total)	;			
					}
			});
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.prevPage()\r\n\r\n" +e);
		}
	}
	
	this.firstPage=function(){
		try {
		
			var sb = new ShoutBox();
			var page = 1;
			sb.setActualPage(page);
			sb.makeShouts(page);
			
			
			new Ajax.Request('AJAX/AJAXManager.php',{ 
					
					method: 'post', 
					parameters: {method: "getTotalPages"} ,
					
					onComplete: function(json) {
					
						var data = eval('(' + json.responseText + ')');
						sb.makeStepper(page,data.total)	;			
					}
			});
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.firstPage()\r\n\r\n" +e);
		}
	}
	
	this.lastPage=function(){
		try {
		
			var sb = new ShoutBox();
						
			new Ajax.Request('AJAX/AJAXManager.php',{ 
					
					method: 'post', 
					parameters: {method: "getTotalPages"} ,
					
					onComplete: function(json) {
					
						var data = eval('(' + json.responseText + ')');
						var page = parseInt(data.total);
						
						sb.makeShouts(page);
						sb.setActualPage(page);
						sb.makeStepper(page,page)	;			
					}
			});
		}	
	    catch(e){		
				alert("JavaScript Exception: ShoutBox.firstPage()\r\n\r\n" +e);
		}
	}
	
	
	
	this.trim = function(str){
	
		try{
			
			return(str.replace(/^\s*|\s*$/g, ""));
			
		}catch(e){alert("JavaScript Exception: ShoutBox.trim()\r\n\r\n"+ e);	}
	}
	
	this.checkEmail=function(str){
	
		try{
		
			var reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
	                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
	                   '(\\.)([a-zA-Z]{2,4})$');
	  		return (reg.test(str));
		
		}catch(e){alert("JavaScript Exception: ShoutBox.checkEmail()\r\n\r\n"+ e);	}
	}
	
	this.setSmilie=function(ev){
		
		try{
			
			//get event source
			if (!ev)	source = window.event.srcElement;
			else  source=ev.target;
			
			var txt=" "+source.value+" ";
			
			var sb=new ShoutBox();
			sb.insertAtCaret(sb.msg,txt);
			
		}	catch(e){alert("JavaScript Exception: ShoutBox.insertAtCaret()\r\n\r\n"+ e);	}
	}
	
	this.insertAtCaret=function(obj, text){
		
		try{
			if(document.selection) {   
		        // Go the IE way 
		        /* 	First of all, focus the object, we want to work with  
		   			If we do not do so, it is possible, that the selection  
		   			is not, where we expect it to be  
				*/  
				obj.focus();   
		  
				/* Create a TextRange based on the document.selection  
				   This TextRanged can be used to replace the selected  
				   Text with the new one  */  
				var range = document.selection.createRange();   
		  
				/* If the range is not part of our Object (remember the  
				   textarea or input field), stop processing here  */  
				if(range.parentElement() != obj) return false;   
		  
				/*  Save the current value. We will need this value later  
		   			to find out, where the text has been changed */  
				var orig = obj.value.replace(/rn/g, "n");   
		  
				/* Replace the Text */  
				range.text = text;   
		  
				/* Now get the new content and save it into  
				   a temporary variable	*/  
				var actual = obj.value.replace(/rn/g, "n");   
				var tmp	= obj.value.replace(/rn/g, "n");	  
				/* Find the first occurance, where the original differs  
				   from the actual content. This could be the startposition  
				   of our text selection, but it has not to be. Think of the  
				   selection "ab" and replacing it with "ac". The first  
				   difference would be the "c", while the start position  
				   is the "a"	*/  
				for(var diff = 0; diff < orig.length; diff++)    
					    if(orig.charAt(diff) != actual.charAt(diff)) break;   
					   
					 
				/* To get the real start position, we iterate through  
				   the string searching for the whole replacement  
				   text - "abc", as long as the first difference is not  
				   reached. If you do not understand that logic - no  
				   blame to you, just copy & paste it ;)*/ 
				var start=0;    
				for(var index = 0; (tmp = tmp.replace(text, "")) && index <= diff; index = start + text.length) {   
				    start = actual.indexOf(text, index);   
					}  
	          
	    	} else if(obj.selectionStart) {   
		        // Go the Gecko way  
			        /* Find the Start and End Position */  
					var start = obj.selectionStart;   
					var end   = obj.selectionEnd;   
					  
					/* Remember obj is a textarea or input field */  
					obj.value = obj.value.substr(0, start)   
					    + text   
					    + obj.value.substr(end, obj.value.length);  
				  
	    	} if(start != null)  this.setCaretTo(obj, start + text.length);   
	       	else {   
	        	// Fallback for any other browser
	          	obj.value+=' 8-o';  
	    	}   
		}catch(e){alert("JavaScript Exception: ShoutBox.insertAtCaret()\r\n\r\n"+ e);	}	
		
	}
	
	this.setCaretTo=function(obj, pos) {   
	    
	    try{
		    if(obj.createTextRange) {   
		        /* Create a TextRange, set the internal pointer to  
		           a specified position and show the cursor at this  
		           position    */  
		        var range = obj.createTextRange();   
		        range.move("character", pos);   
		        range.select();   
		    } else if(obj.selectionStart) {   
		        /* Gecko is a little bit shorter on that. Simply  
		           focus the element and set the selection to a  
		           specified position      */  
		        obj.focus();   
		        obj.setSelectionRange(pos, pos);   
		    }   
		    
	    }catch(e){alert("JavaScript Exception: ShoutBox.setCaretTo()\r\n\r\n"+ e);	}
	}  
	
}	


//-->