var type;

var	isHTMLMode=false

function insertAtCursor(myField, myValue) 
{

//IE support
	if (document.selection) 
	{
	myField.focus();
	sel = document.selection.createRange();
	sel.text = myValue;
	
	}
//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') 
	{
	var startPos = myField.selectionStart;
	var endPos = myField.selectionEnd;
	myField.value = myField.value.substring(0, startPos)
	+ myValue
	+ myField.value.substring(endPos, myField.value.length);
	} else {
	myField.value += myValue;
	}
//	isHTMLMode = isHTMLMOdeBackup;
	
}

function InsertImage(imgname)
{
	var txtContent = document.getElementById('txtContent');
	var linkText = '<img src="' + imgname + '" />';
	if (txtContent.style.display!='none')
	{	
		insertAtCursor(txtContent, linkText);
	}
	else
	{	
		 if (isHTMLMode)
			insertAtCursor(NewsBody_rich, linkText);
		else
			cmdExec('insertimage', imgname);	
	}
}
/*
function document.onReadyStateChange()
{	
	try
	{
		var elem = getElementById('NewsBody_rich');
		
		if (elem)
		{
			elem.document.designMode="On";		
			elem.document.write('<p>Enter your text</p>');		
		}
	}
	catch (err)
	{}		
} // end document.onreadystatechange
*/
function document.onreadystatechange()
	{
		NewsBody_rich.document.designMode="On";		
		NewsBody_rich.document.write('<p>Enter your text</p>');
	} // end document.onreadystatechange
		
function cmdExec(cmd,opt) 
	{
		if (isHTMLMode)
		{
			alert(cmd + " " + opt + ": Formatting happens only in Normal mode");
			return;
		}
		NewsBody_rich.focus();
		NewsBody_rich.document.execCommand(cmd,"",opt);
		NewsBody_rich.focus();
	} // end cmdExec

var intHCount = 0;
var intNCount = 0;

function setMode(Nbut, Hbut) 
	{
		var	sTmp;
		isHTMLMode = Hbut;
		isNormalMode = Nbut;

		if(Hbut == 1)
		{
			intHCount++;
			intNCount = 0;
		}

		if(Nbut == 1)
		{
			intNCount++;
			intHCount = 0;
		}	

		if (isHTMLMode && intHCount == 1)
		{
			sTmp=NewsBody_rich.document.body.innerHTML;NewsBody_rich.document.body.innerText=sTmp;
			changeImage ('HTMLbut','./images/HTML_on.jpg');
			changeImage ('Normalbut','./images/Normal_off.jpg'); return true;			
		}
		if(isNormalMode && intNCount == 1)
		{
			sTmp=NewsBody_rich.document.body.innerText;NewsBody_rich.document.body.innerHTML=sTmp;
			changeImage ('HTMLbut','./images/HTML_off.jpg');
			changeImage ('Normalbut','./images/Normal_on.jpg'); return true;			
		}
		NewsBody_rich.focus();
	} // end setMode
	
function createLink()
	{
		if (isHTMLMode){alert("Please uncheck 'Edit	HTML'");return;}
		cmdExec("CreateLink");
	} // end createLink
	
function foreColor()
	{
		var	arr	= showModalDialog("colorpanel.htm","","font-family:Verdana;	font-size:12; dialogWidth:30em;	dialogHeight:35em" );
		if (arr	!= null) cmdExec("ForeColor",arr);	
	} // end foreColor

function setImage()	
{ 
	var	imgSrc = " ";
	var	flag = 0;	
	while(imgSrc ==	" ")
	{
	//	imgSrc = prompt('Enter image location with image name ', ''); 
	//	if (imgSrc == "	") alert("Please enter the required	URL");		
		if (isHTMLMode)
			imgSrc=window.showModalDialog('../Content/SelectImage.aspx?mode=html',null,'status:no;dialogWidth:470px;dialogHeight:470px;dialogHide:true;help:no;scroll:no');
		else
			imgSrc=window.showModalDialog('../Content/SelectImage.aspx?mode=normal',null,'status:no;dialogWidth:470px;dialogHeight:470px;dialogHide:true;help:no;scroll:no');
	
		if(imgSrc != "")
		{
		    if (isHTMLMode)
				insertAtCursor(NewsBody_rich, imgSrc);
			else
				cmdExec('insertimage', imgSrc);	
	
	//		cmdExec('insertInputText', imgSrc);		
	//		
			
			//NewsBody_rich.focus();
			//NewsBody_rich.document.write(imgSrc);
			//NewsBody_rich.focus();
		}
	} // end while
} // end setImage



function document.ShowCM(t,headerText)
{		
	if (divContent.style.display=="block")
	{
		divContent.style.display="none";
	}
	else	
	{
		divContent.style.display="block";
	}

	type = t;
	spnHeader.innerText=headerText;
	var myText = document.getElementById(t).value;
	//alert('Enabling rich text');
	NewsBody_rich.document.designMode='On';
	try
	{	
		
		NewsBody_rich.document.body.innerHTML=myText;	
		//
	}
	catch (err)
	{
		alert(err.description);
	}
	
	document.getElementById('cmdSave').style.display = "none";
	document.getElementById('txtContent').style.display = "none";
	document.getElementById('imgOpen').style.display = "none";
	if (document.getElementById('cmdSave2'))
		document.getElementById('cmdSave2').style.display = "none";
	
}

function fillTxt()
{
		document.getElementById(type).value=NewsBody_rich.document.body.innerHTML;
		divContent.style.display="none";
		document.getElementById('cmdSave').style.display = "block";
		document.getElementById('txtContent').style.display = "block";
		document.getElementById('imgOpen').style.display = "block";
		if(document.getElementById('cmdSave2'))
		{
			document.getElementById('cmdSave2').style.display = "block";
		}
}
				
function ClearIFrame()
	{
	NewsBody_rich.document.body.innerHTML ='';
	divContent.style.display="none";
	document.getElementById('txtContent').style.display = "block";
	document.getElementById('cmdSave').style.display = "block";
	document.getElementById('imgOpen').style.display = "block";
	if(document.getElementById('cmdSave2'))
	    {
		document.getElementById('cmdSave2').style.display = "block";
		
		}

	}
function DisableSave(bool)
	{
		document.getElementById("btnSaveHead").style.display="none";
		
		if(bool=='show')
		{	
			if(document.getElementById("btnSaveHead").style.display=="none")
			{
				document.getElementById("btnSaveHead").style.display="block";
			}
			else
			{
				document.getElementById("btnSaveHead").style.display="none";
			}
		}
	}
	

