
     /*
     * Function to set the contents by ajax requests, does some nice fading too
     */
     var nTemp = '';
     
     function SetContainer(httpRequest)
     {
         if(httpRequest.readyState == 4) {
             if(httpRequest.status == 200) {
                 nTemp = httpRequest.responseText;
                 FadeContainer(0, 1);
		     } else {
                 alert('Error #1');
             }
         }
     }
     
     function FadeContainer(step, opacity)
     {
         if(step == 0){
             opacity -= 0.05;
             document.getElementById('content').style.opacity = opacity;
             
             if(opacity <= 0){
                 step = 1;
             }
         } else if(step == 1) {
             document.getElementById('content').innerHTML = nTemp;
             step = 2;
         } else if(step == 2){
             opacity += 0.05;
             document.getElementById('content').style.opacity = opacity;
             
             if(opacity >= 1){
                 step = 3;
             }
         }
         
         if(step < 3){
             setTimeout('FadeContainer('+step+', '+opacity+')', 20);
         }
     }
     
     
     /*
     * Functions to show charts on stockexchange page
     * Adds the new chart - unless the image is there, then it's just removed :-)
     */
     
     var chart_showid = -1;
     
     function ToggleChart(id)
     {
         // Hide from showid
         if(chart_showid != -1)
         {
             var chartimg = document.getElementById('chart_'+chart_showid);
             
             document.getElementById('cell_'+chart_showid).removeChild(chartimg);
         } 
         
         // Show the new one - if it is a new one
         if(id != chart_showid)
         {
             chart_showid = id;
             
             var chartimg = document.createElement('img');
             chartimg.src = 'content/chartcreator.php?id='+id;
             chartimg.alt = 'Loading chart...';
             chartimg.title = 'Chart';
             chartimg.id = 'chart_'+id;
             chartimg.style.position = 'absolute';
			 chartimg.style.border = '1px solid #000000';
             
             document.getElementById('cell_'+id).appendChild(chartimg);
         }
         else
         {
             chart_showid = -1;
         }
     }
     
     /*
     * Validation function for names while registering
     */

	 function validate(sid, fid)
	 {
		var result 				= '';
		var str 					= document.getElementById(sid).value;
		
		if(str.length < 3)
		{
			result					= '<span style="color: #FF0000; font-weight: bold">Too short</span>';
		}
		
		for(var a = 0; a < str.length; a++)
		{
			var t = str[a];
			
			if((t < 'a' || t > 'z') && (t < 'A' || t > 'Z') && (t < '0' || t > '9') && t != ' ' && t != '-')
			{
				result 				= '<span style="color: #FF0000; font-weight: bold">Only a-z, A-Z, 0-9, - and spaces allowed.</span>';
				break;
			}
		}
		
		document.getElementById(fid).innerHTML = result;
	}
	
	function validatep(sid, fid)
	{
		var result 				= '';
		var str 					= document.getElementById(sid).value;
		
		if(str.length < 6)
		{
			result					= '<span style="color: #FF0000; font-weight: bold">Password is too short</span>';
		}
	
		/*
		if(result == '')
		{
			if(document.getElementById('psid').value != document.getElementById('p2sid').value)
			{
				result				= '<span style="color: #FF0000; font-weight: bold;">Passwords do not match.</span>';
			}
		}*/
		
		document.getElementById(fid).innerHTML = result;
	}
	 
     /*
     * PM functions
     * Send request to server to view this private message 
     */
     
     var pm_id = 0;
     
     function GetPM(id)
     {
         // Set the ID we want
         pm_id = id;
         
		// Clear the 'new'-icon
		document.getElementById('icon_'+id).innerHTML = '';
         
		// Set the ajax loading icon
		var pmicon = document.createElement('img');
		pmicon.src = 'images/icons/ajax.gif';
		pmicon.alt = '[...]';
		pmicon.style.marginBottom = '-3px;';
		pmicon.id = 'iconimg_'+id;
		pmicon.title = 'Loading...';
			
		document.getElementById('icon_'+id).appendChild(pmicon);

		// Send the ajax request
		return SendGet('ajax.php?module=pm&id='+id, SetPM);
     }
     
     function SetPM(httpRequest)
     {
         // Ready?
         if(httpRequest.readyState == 4) 
         {
             // Was the result OK?
             if(httpRequest.status == 200) 
             {
                 // Remove the ajax loading icon
                 document.getElementById('icon_'+pm_id).removeChild(document.getElementById('iconimg_'+pm_id));
                 
                 // Set the PM
                 document.getElementById('pmshowbox').innerHTML = httpRequest.responseText;
		     }
             // Nope...
             else 
             {
                 alert('Could not process request.');
             }
         }
     }
     
     /*
     * A simple moderation result function
     * Alerts if it's ok or not
     */
     function AlertOK(httpRequest)
     {
         // Ready?
         if(httpRequest.readyState == 4) 
         {
             // Was the result OK?
             if(httpRequest.status == 200) 
             {
                 var params = httpRequest.responseText.split('|');
                 var id = params[0];
                 var text = params[1];
                 
                 document.getElementById('mbutton'+id).innerHTML = text;
		     }
             // Nope...
             else 
             {
                 alert('Moderation action failed!');
             }
         }
     }
     
     /* 
     * Some ajax moderation
     * Changing title of a thread
     */
     var oldid = -1;
     
     function ChangeTitle(id)
     {
         // We might need to set the old one back to it's state
         if(oldid != -1)
         {
             // Get the current title
             var title = document.getElementById('box_'+oldid).value;
             
             // Set the link
             var link = '<a href="index.php?site=viewtopic&id='+oldid+'" id="link_'+oldid+'">'+title+'</a>';
             document.getElementById('title_'+oldid).innerHTML = link;
             
             // Send ajax request to set the title
             SendGet('ajax.php?module=tthread&id='+id+'&title='+title, FinishChangeTitle);
         }
         
         // If we're opening a new one, open it
         if(oldid != id)
         {
             // Get the current title
             var title = document.getElementById('link_'+id).innerHTML.replace(/^\s+|\s+$/g, "");
             
             // Replace the topic title with a nice textbox :-)
             var size = 50 < title.length+5 ? 50 : title.length+5;
             document.getElementById('title_'+id).innerHTML = '<input type="text" value="'+title+'" id="box_'+id+'" size="'+size+'" class="text" />';
             
             // Set the old id
             oldid = id;
         }
         // Otherwise just make sure we won't close this one again :P
         else
         {
             oldid = -1;
         }
     }
     
     function FinishChangeTitle(httpRequest)
     {
         if(httpRequest.readyState == 4)
         {
             if(httpRequest.status != 200)
             {
                 alert('Something went wrong with the AJAX-request.');
             }
         }
     }