function Init() {
	if(document.getElementById("iView")) {
		iView.document.designMode = "On";
	}
}

function cmdExec(cmd,opt) {
	if (viewMode == 2) {alert("Please switch to the 'WYSIWYG Editor'");return;}
	iView.document.execCommand(cmd,"",opt);iView.focus();
}

function selOn(ctrl)  {ctrl.className='butClassOver';}
function selOff(ctrl) {ctrl.className='butClass';}
function selDown(ctrl){ctrl.className='butClassDown';}
function selUp(ctrl)  {ctrl.className='butClass';}

function doForeColor() {
	var fCol = showModalDialog("./src/xpedit_getcolor.asp","","font-family:Verdana;font-size:12;dialogWidth:45em;dialogHeight:24em");
	if(fCol != null) {iView.document.execCommand('forecolor', false, fCol);}
}

function doBackColor() {
	var bCol = showModalDialog("./src/xpedit_getcolor.asp","","font-family:Verdana;font-size:12;dialogWidth:45em;dialogHeight:24em");
	if(bCol != null) {iView.document.execCommand('backcolor', false, bCol);}
}

function doLink() {
	iView.document.execCommand('createlink');
}

function uploadImages() {
	var newWindow;
	var props = 'scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width=500,height=440,left='+strLeft+',top='+strTop+'';
	newWindow = window.open('./src/xpedit_getimage.asp?action=add&saction=contentscreen', 'XPUpload', props);
}

function insertImage() {
	if (viewMode == 2) {alert("Please switch to the 'WYSIWYG Editor'");return;}
	var sImgSrc = showModalDialog("./src/xpedit_loadimage.asp?action=view","","dialogHeight:600px; dialogWidth:600px;dialogTop:'+strTop+';dialogLeft:'+strLeft+';edge:raised;center:yes;help:no;resizable:no;status:no;");
	if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
}

function insertImageLink() {
	if (viewMode == 2) {alert("Please switch to the 'WYSIWYG Editor'");return;}
	var sImgSrc=prompt("Insert Image File (You can use your local image file) : ", "http://www.microsoft.com/library/homepage/images/mslogo-blue.gif");
	if(sImgSrc!=null) cmdExec("InsertImage",sImgSrc);
}

function doRule() {
	iView.document.execCommand('inserthorizontalrule', false, null);
}

function SetParagraph(name,value) {
	iView.focus();
	if (value == '<body>') {iView.document.execCommand('formatBlock','','Normal');iView.document.execCommand('removeFormat');return;}
	iView.document.execCommand('formatblock','',value);
}

function doPreview() {
	temp = iView.document.body.innerHTML;
	preWindow = open('', 'previewWindow', 'width=500,height=440,status=yes,scrollbars=yes,resizable=no,toolbar=no,menubar=yes,left='+strLeft+',top='+strTop+'');
	preWindow.document.open();preWindow.document.write(temp);preWindow.document.close();
}

function doToggleView() {
	var tblCtrls = document.getElementById("tblCtrls");
	var tblObjCtrls = document.getElementById("tblObjCtrls");
	if(viewMode == 1) {
		iHTML = iView.document.body.innerHTML;
		iView.document.body.innerText = iHTML;
		// Hide all controls
		tblCtrls.style.display = 'none';
		tblObjCtrls.style.display = 'none';
		iView.focus();
		viewMode = 2; // Code
	} else {
		iText = iView.document.body.innerText;
		iView.document.body.innerHTML = iText;
		// Show all controls
		tblCtrls.style.display = 'inline';
		tblObjCtrls.style.display = 'inline';
		iView.focus();
		viewMode = 1; // WYSIWYG
	}
}