function createDiv(id, html, width, height, left, top)
{

	if(!document.getElementById(id))
	{
////
	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }
	var indicatorWidth = width; 
    var indicatorHeight = height; 
    var left = (availWidth/2) - (indicatorWidth/2); 
    var top = (availHeight/2) - (indicatorHeight/2); 

    //element.style.top=top+"px"; 
    //element.style.left=left+"px"; 

////
		windowWidth = document.body.clientWidth;
		windowCentre = windowWidth/2;
		offsetLeft = width / 2;
		left = windowCentre - offsetLeft;
		
		windowHeight = document.body.clientHeight;
		windowMiddle = windowHeight/2;
		offsetTop = height / 2;	
//	
		var newdiv = document.createElement('div');
	   	newdiv.setAttribute('id', id);	
	   	newdiv.style.width = width;
	   	newdiv.style.height = height;
	   	newdiv.style.position = "absolute";
	   	//newdiv.style.top = top;
	   	newdiv.style.top=top+"px"; 
	   	newdiv.style.left=left+"px"; 
	   	newdiv.style.left = left;
	   	newdiv.style.zIndex = 999;
		newdiv.style.border = "5px solid ffa500";
		newdiv.style.backgroundColor = "#FFFFFF";
		newdiv.style.position="fixed";
		newdiv.style.display="block";
		newdiv.innerHTML = "<form method=\"post\" action=\"upload.php\" enctype=\"multipart/form-data\" target=\"frm1\" onsubmit=\"closeLoader();\"><span style=\"padding: 10px; display: block;\">Please select the image to upload below</span><div class=\"frmUploadA\" style='text-align: center;'><input type=\"hidden\" name=\"txtSection\" id=\"txtSection\" /><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"90000000\"><div id=\"uFile\" style='text-align: center;'><input name=\"uploadfile\" type=\"file\" id=\"uploadfile\" onchange=\"enableButton();\" style=\"width: 350px;\"></div><div style=\"margin-top:20px;visibility:hidden;\" id=\"imgLoader\"><img src=\"../images/loader.gif\" style=\"width:100px;\" /></div></div><div class=\"frmUploadB\" style='text-align: center; margin-top: 20px;'><input type=\"button\" value=\"Cancel\" onclick=\"cancelUpload();\" class=\"buttonE\" /><input name=\"btnUpload\" type=\"submit\" id=\"btnUpload\" value=\"Upload\" class=\"buttonE\" disabled/><input name=\"btnClose\" id=\"btnClose\" type=\"hidden\" value=\"Close\" onclick=\"uploadImage();\" /><br /><iframe name=\"frm1\" id=\"frm1\" width=\"1px\" height=\"1px\" style=\"visibility:hidden\"></iframe></div></form>";
		//newdiv.innerHTML = "<div id=\"upload\">TESET</div>";

		document.body.appendChild(newdiv);
	}	
	else
	{
		document.getElementById(id).style.display = "block";
	}
}
function enableButton()
{
	document.getElementById('btnUpload').disabled = false;
}
function closeLoader()
{
	document.getElementById('addImage').style.display = "none";
}
function uploadImage()
{
 	var section = document.getElementById('txtSection').value;
	document.getElementById('txtImage'+section).value = document.frm1.txtUpload.value;
	document.getElementById('upload').style.display = "none";
	document.getElementById('fader').style.display = "none";
	var id = document.getElementById('txtImage'+section).value;
	var url = "iupload.php";
	var params = "id="+id+"&section="+section;
    xmlhttp=GetXmlHttpObject();
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('image'+section).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);	
}

function addFileToControl(file)
{
 	try
 	{
		var editor = tinyMCE.activeEditor;	
		
		//editor.selection.setContent('some added text');

		//editor.selection.setContent('some added text');
		editor.getWin().focus();		
		//editor.execCommand('mceRemoveNode', false, e);
	
	}
	catch(ex){}

//	tinyMCE.activeEditor.setContent("test");
	var editor = tinyMCE.activeEditor;	
editor.selection.setContent(file);
	//editor.selection.setContent('some added text');

	//editor.selection.setContent(file);
	
	//editor.selection.setContent(file);
//	editor.selection.setContent("file");
	editor.getWin().focus();
	//document.getElementById('addImage').style.display = "none"; 
	
}

function cancelUpload()
{
    var fader = document.getElementById('addImage').style.display = "none"; 
}
function showAppearance()
	{	
		document.getElementById('general').style.display = 'none';
		document.getElementById('appearance').style.display = 'block';
	
		document.getElementById('generalTab').style.background = 'url(jscript/tiny_mce/images/tabOff.jpg)';
		document.getElementById('appearanceTab').style.background = 'url(jscript/tiny_mce/images/tabOn.jpg)';
	}
	
	function showGeneral()
	{	
		document.getElementById('general').style.display = 'block';
		document.getElementById('appearance').style.display = 'none';
	
		document.getElementById('generalTab').style.background = 'url(jscript/tiny_mce/images/tabOn.jpg)';
		document.getElementById('appearanceTab').style.background = 'url(jscript/tiny_mce/images/tabOff.jpg)';
	}
	
	function showImagePreview()
	{	 	
	 	var currentImage = document.getElementById('existingImage').value;
	 	if(currentImage != "")
	 	{
			document.getElementById('imagePreview').innerHTML = '<img src='+currentImage+' >';
		}
		else
		{
			document.getElementById('imagePreview').innerHTML = '';
		}

	}

	function previewFileUpload()
	{
		var currentImage = document.getElementById('uploadImage').value;
		
		var re = /\\/gi;

		while(re.test(currentImage))
		{
			currentImage = currentImage.replace(re, "/" );
		}
	
		re = /\s/gi;
		while(re.test(currentImage))
		{
			currentImage = currentImage.replace(re, "%20" );
		}

		currentImage = 'file:///' + currentImage;
		
		if(currentImage != "")
	 	{
			document.getElementById('imagePreview').innerHTML = '<img src='+currentImage+' >';
		}
		else
		{
			document.getElementById('imagePreview').innerHTML = '';
		}
		//file:///C:/Documents%20and%20Settings/dtiffin.ATLAS/My%20Documents/My%20Pictures/princessCheryl.jpg
	}

	function changeExample()
	{
		var align = document.getElementById('alignment').value;
		
		switch(align)
		{
			case '0':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/notSet.jpg />';
				break;
			case '1':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/notSet.jpg />';
				break;
			case '2':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/top.jpg />';
				break;
			case '3':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/middle.jpg />';
				break;
			case '4':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/bottom.jpg />';
				break;
			case '5':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/bottom.jpg />';
				break;
			case '6':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/notSet.jpg />';
				break;
			case '7':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/left.jpg />';
				break;
			case '8':
				document.getElementById('example').innerHTML = '<img src=jscript/tiny_mce/images/right.jpg />';
				break;
		}
	}
	
	function showFileUpload(value)
	{
		if(value == 1)
		{
			document.getElementById('lblNewImage').style.display = 'block';
			document.getElementById('lblExistingImage').style.display = 'none';
			
			document.getElementById('spanUploadImage').style.display = 'block';
			document.getElementById('spanExistingImage').style.display = 'none';
			
			document.getElementById('existingImage').value = '';
			
		}
		else
		{
			document.getElementById('lblNewImage').style.display = 'none';
			document.getElementById('lblExistingImage').style.display = 'block';
			
			document.getElementById('spanUploadImage').style.display = 'none';
			document.getElementById('spanExistingImage').style.display = 'block';	
					
			document.getElementById('spanUploadImage').innerHTML = '<input type=\'file\' name=\'uploadImage\' id=\'uploadImage\' style=\'font-family: verdana; font-size: 8pt; height: 19px; width: 204px;\' onchange=\'previewFileUpload()\' />';
		}
		document.getElementById('imagePreview').innerHTML = '';
	}


function addImageToControl(image)
{
 	
 	
//	tinyMCE.activeEditor.setContent("test");
	var editor = tinyMCE.activeEditor;	
	//editor.selection.setContent('some added text');
	editor.getWin().focus();
	alert(tinyMCE.activeEditor.selection.getNode().nodeName);
	editor.execCommand('mceInsertContent', false, image);
	
	
	document.getElementById('addImage').style.display = "none";

}

function stripWordFomatting()
{
	var content = tinyMCE.activeEditor.getContent();
           		
	var re = /(style="[.]*)|(class="[.]*)/gi;

	while(re.test(content))
	{
		content = content.replace(re, "" );
	}

	tinyMCE.activeEditor.setContent(content);
}

function showpostnote()
{
	showFader();		

	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }
    
    var indicatorWidth = 540; 
    var indicatorHeight = 190; 
    var left = (availWidth/2) - (indicatorWidth/2); 
    var top = (availHeight/2) - (indicatorHeight/2); 

    var element = document.getElementById('postnote'); 
    element.style.border="5px solid #ffa500"; 
    element.style.background="#ffffff"; 
    element.style.position="absolute"; 
    element.style.zIndex="999"; 
    element.style.top=top+"px"; 
    element.style.left=left+"px"; 
    element.style.display="block";
    element.style.position="fixed";
}

function showFader()
{
	if(typeof(window.innerWidth) == 'number')
	{ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))					
	{ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }
	else if(document.body && (document.body.clientWidth || document.body.clientHeight))
	{ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    }	
    var element = document.getElementById('fader'); 
    element.style.border="0px"; 
    element.style.background="black"; 
    element.style.position="absolute"; 
    element.style.zIndex="900"; 
//    element.style.top=top+"px"; 
//    element.style.left=left+"px"; 
    element.style.height = availHeight+"px";
    element.style.width = availWidth+"px";
    element.style.display="block";
    element.style.position="fixed";

}

function savepost()
{
	var text =  tinyMCE.activeEditor.getContent();
	var dashboard = document.getElementById('dashboardOwner').value;

	var key = document.getElementById('key').value;
	
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="savepost.php";
    
    var parameters = "post="+text+"&dash="+dashboard+"&key="+key+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("addpost").innerHTML=xmlhttp.responseText;
//	alert(xmlhttp.responseText);
	location.reload(true);
}
function showCommentBox(ForumID)
{
    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="showComment.php";
    var parameters = "forum="+ForumID+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("comment"+ForumID).innerHTML=xmlhttp.responseText;
	//location.reload(true);
}

function saveComment(ForumID)
{
 	var comment = document.getElementById('commentTextarea'+ForumID).value;

    var date = new Date();
    var xmlhttp;

    xmlhttp=GetXmlHttpObject()

    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="saveComment.php";

    var parameters = "comment="+comment+"&forum="+ForumID+"&t="+date.getSeconds();

    xmlhttp.open("GET",url+"?"+parameters,false);
    xmlhttp.send(null);

    document.getElementById("comment"+ForumID).innerHTML=xmlhttp.responseText;
	location.reload(true);

}
