// JavaScript Document
var viewMode = 1; // WYSIWYG
//var viewColor = 1; //Hidden
//var viewColor2 = 1; //Hidden
//var shwEmo = 1; //Hidden

function Init() {
  iView.document.designMode = 'On';
  iView.focus();    
  //ColorBar.style.display = 'none';
  //ColorBar2.style.display = 'none';
  //shwEmoS.style.display = 'none';
}
//----------------- Zone 1 --------------------------------------------------------------------------------------------
function selOn(ctrl) {
	ctrl.style.borderColor = '#FF6600'; 
	ctrl.style.backgroundColor = '#FFCC99';
	ctrl.style.cursor = 'hand';	
  }
  
  function selHand(ctrl) {
	//ctrl.style.borderColor = '#FF6600'; 
	//ctrl.style.backgroundColor = '#FFCC99';
	ctrl.style.cursor = 'hand';	
  }
  
function selOff(ctrl) {
	ctrl.style.borderColor = '#ECF5FF'; 
	ctrl.style.backgroundColor = '#ECF5FF';
  }
  
function selDown(ctrl) {
	ctrl.style.backgroundColor = '#FFCC99';
  }
  
function selUp(ctrl) {
    ctrl.style.backgroundColor = '#FFCC99';
  }
//----------------- Zone 2 --------------------------------------------------------------------------------------------
function doBold() {
	iView.focus();
	iView.document.execCommand('bold', false, null);
  }

function doItalic() {
	iView.focus();
	iView.document.execCommand('italic', false, null);
  }

function doUnderline() {
	iView.focus();
	iView.document.execCommand('underline', false, null);
  }
//----------------- Zone 3 --------------------------------------------------------------------------------------------
function doLeft() {
	iView.focus();
    iView.document.execCommand('justifyleft', false, null);
  }

function doCenter() {
	iView.focus();
    iView.document.execCommand('justifycenter', false, null);
  }

function doRight() {
	iView.focus();
    iView.document.execCommand('justifyright', false, null);
  }
  //----------------- Zone 4--------------------------------------------------------------------------------------------
function doOrdList() {
	iView.focus();
    iView.document.execCommand('insertorderedlist', false, null);
  }

function doBulList() {
	iView.focus();
    iView.document.execCommand('insertunorderedlist', false, null);
  }
  
function doOutdent() {
	iView.focus();
    iView.document.execCommand('outdent', false, null);
  }
  
function doIndent() {
	iView.focus();
    iView.document.execCommand('indent', false, null);
  }
  
function doSub() {
	iView.focus();
    iView.document.execCommand('subscript', false, null);
  }
  
function doPub() {
	iView.focus();
    iView.document.execCommand('superscript', false, null);
  }
//----------------- Zone 4--------------------------------------------------------------------------------------------
function doLink(){
	iView.focus();
    iView.document.execCommand('createlink');
  }
  
function doRule() {
	iView.focus();
    iView.document.execCommand('inserthorizontalrule', false, null);
  }
  
function doImage() {
	iView.focus();
    var imgSrc = prompt('Enter image location', '');
    if(imgSrc != null)    
     iView.document.execCommand('insertimage', false, imgSrc);
  }
//----------------- Zone 5--------------------------------------------------------------------------------------------  
function doCut() {
	iView.focus();
	iView.document.execCommand('cut', false, null);
  }
 
function doCopy() {
	iView.focus();
	iView.document.execCommand('copy', false, null);
  }
 
function doPaste() {
	iView.focus();
	iView.document.execCommand('paste', false, null);
  }
  //----------------- Zone 6--------------------------------------------------------------------------------------------  
function doHead(hType) {
	iView.focus();
    if(hType != '') {
      iView.document.execCommand('formatblock', false, hType);      
    }
  }
  
function doFont(fName) {
	iView.focus();
    if(fName != '')
      iView.document.execCommand('fontname', false, fName);
  }
  
function doSize(fSize) {
	iView.focus();
    if(fSize != '')
      iView.document.execCommand('fontsize', false, fSize);
  }
  
function doFunnyImage(imgSrc) {
	iView.focus();
    if(imgSrc != null) {
     	iView.focus();    
     	iView.document.execCommand('insertimage', false, imgSrc);
    }
  }
//----------------- Zone 7--------------------------------------------------------------------------------------------  
//function doForeCol(fCol) {
//      if(fCol != '')
//      iView.document.execCommand('forecolor', false, fCol);
//	  ColorBar2.style.display = 'none';
//	   viewColor2 = 1;
// }

//function doBackCol(bCol) {
//    if(bCol != '')
//      iView.document.execCommand('backcolor', false, bCol);
//  	ColorBar.style.display = 'none';
//	   viewColor = 1;
//  }
 
 function selOnCol(ctrl) {
	//ctrl.style.borderColor = '#316AC5'; 
	//ctrl.style.backgroundColor = '#D3E5FB';
	ctrl.style.cursor = 'hand';	
  }
//----------------- Zone Options --------------------------------------------------------------------------------------------  
/*function shwColorF(clr) {
    if(clr != '')
      ExamCol.bgColor = clr;
	  ans_frm.Tcolor.value = clr;
  }
  
function shwColorF2(clr) {
    if(clr != '')
      ExamCol2.bgColor = clr;
	  ans_frm.Tcolor2.value = clr;
  } 
  
 function showColorBar() {
 	if (viewColor == 1) {
		ColorBar.style.display = 'inline';
		viewColor = 2; // Display
		if (viewColor2 = 2) {
				ColorBar2.style.display = 'none';
				viewColor2 = 1;
		}
	}else {
		ColorBar.style.display = 'none';
		viewColor = 1;
	}
  } 
  
function showColorBar2() {
 	if (viewColor2 == 1) {
		ColorBar2.style.display = 'inline';
		viewColor2 = 2; // Display
		if (viewColor = 2) {
				ColorBar.style.display = 'none';
				viewColor = 1;
		}
	}else {
		ColorBar2.style.display = 'none';
		viewColor2 = 1;
	}
  } 
  
  function shwEmotions() {
 	if (shwEmo == 1) {
		shwEmoS.style.display = 'inline';
		shwEmo = 2; // Display
	//	if (viewColor = 2) {
//			ColorBar.style.display = 'none';
//				viewColor = 1;
	//	}
	}else {
		shwEmoS.style.display = 'none';
		shwEmo = 1;
	}
  } */
//----------------- Zone Code View --------------------------------------------------------------------------------------------    
function doToggleView(){  
    if(viewMode == 1){
      iHTML = iView.document.body.innerHTML;
      iView.document.body.innerText = iHTML;
      // Hide all controls
      tblCtrls.style.display = 'none';
      //selFont.style.display = 'none';
      //selSize.style.display = 'none';
      //selHeading.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';
      //selFont.style.display = 'inline';
      //selSize.style.display = 'inline';
      //selHeading.style.display = 'inline';
      iView.focus();
      viewMode = 1; // WYSIWYG
    }
  }
//----------------- Zone Main --------------------------------------------------------------------------------------------     
function ProcessA(){ 
  // Assign the HTML code to a hidden form variable 
  var htmlCode = iView.document.body.innerHTML; 
  document.ans_frm.answer.value = htmlCode; 
  document.ans_frm.target = "_self";
  //ans_frm.Submit.disabled=true;
  return true; 
} 
