window.offscreenBuffering=true;

function SpecialCharacter(sName)
{
	var iWidth = 500;
	var iHeight = 400;
	
	if (BrowserIsInternetExplorer()) {
		var oTarget = document.getElementById(sName);
		if (!oTarget.disabled) {
			var sCharCode = window.showModalDialog('../../../../private/accs/tools/specialcharacters/listChar.aspx', null, "dialogwidth=" + iWidth + "px;dialogheight=" + iHeight + "px;status:1;");
			if(sCharCode!=undefined){
				insertAtCaret(oTarget, sCharCode);
				// fire onchange event after insert.
				oTarget.onchange();
			}
		}
	}
}

function SpecialCharacterTextArea(sName) {
	var iWidth = 500;
	var iHeight = 400;

	if (BrowserIsInternetExplorer()) {
		var oTarget = document.getElementById(sName);
		if (!oTarget.disabled) {
			eval('document.forms[0].' + sName + '.focus()');
			sel = document.selection.createRange();
			var sCharCode = window.showModalDialog('../../../../private/accs/tools/specialcharacters/listChar.aspx', null, "dialogwidth=" + iWidth + "px;dialogheight=" + iHeight + "px;status:1;");
			if(sCharCode!=undefined){
				sel.text = String.fromCharCode(sCharCode);
			}
		}
	}
}


function SpecialCharacterDiv(sName)
{
	var iWidth = 500;
	var iHeight = 400;
	
	if (BrowserIsInternetExplorer()) {
		var oTarget = document.getElementById(sName);
		if (!oTarget.disabled) {
			var sCharCode = window.showModalDialog('../../../../private/accs/tools/specialcharacters/listChar.aspx', null, "dialogwidth=" + iWidth + "px;dialogheight=" + iHeight + "px;status:1;");
			if(sCharCode!=undefined){
				oTarget.focus();
				InsertTextInDiv(sCharCode)
				oTarget.onchange();
			}
		}
	}
}

function setCaretToEnd (el) {
  if (el.createTextRange) {
    var v = el.value;
    var r = el.createTextRange();
    r.moveStart('character', v.length);
    r.select();
  }
}
function insertAtEnd (el, txt) {
  el.value += String.fromCharCode(txt);
  setCaretToEnd (el);
}

function insertAtCaret (el, txt) {
	if (el.currRange) {
		el.currRange.text =	el.currRange.text.charAt(el.currRange.text.length - 1) != ' ' ? String.fromCharCode(txt) : String.fromCharCode(txt) + ' ';
		el.currRange.select();
	}else{
		insertAtEnd(el, txt);
	}
}

function storeCaret (editEl) {
  if (editEl.createTextRange)
    editEl.currRange = document.selection.createRange().duplicate();
}

function InsertTextInDiv(txt)
{
 document.execCommand("InsertInputButton",null,"InsertedTempButton");
 document.all.InsertedTempButton.outerHTML = String.fromCharCode(txt);
}

function SetTheElementState(sTarget, sSource)
{
	if(document.all[sSource].checked)
	{
		if (document.all[sTarget].getAttribute("allow-enable") && document.all[sTarget].getAttribute("allow-enable") == "true") {
			document.all[sTarget].disabled=false;
		}
	}else{
		document.all[sTarget].disabled=true;
	}
}

function SetElementState(sTarget, sSource)
{
	if(document.all[sSource].checked)
	{
		document.all[sTarget].disabled=false;
	}else{
		document.all[sTarget].disabled=true;
	}
}

function chkSelectAll(sTarget)
{
	var bValue = event.srcElement.checked;
	var aCheckBoxList = document.all[sTarget];
	for (var iNdx=0; iNdx < aCheckBoxList.length; iNdx++) {
		aCheckBoxList[iNdx].checked = bValue;
	}
}