/**************************************************************
 * Hexprobe Hex Editor Internal JScript definitions
 *
 * File:     template_01.js
 * Author:   Hexprobe System
 * Revision: 3.7
 * Purpose:  It is placed here just for debugging.
 * Comment:  Don't make any modification. If error source 
 *           points to the file, please trace back to find 
 *           where your source refers to error line.
 *************************************************************/
 
//-- Jump forward support
var _jmpCount = 0;

//-- Data types of the return value of Evaluate
var _EVAL_DATATYPE_ERROR	= -1;
var _EVAL_DATATYPE_NULL		= 0;
var _EVAL_DATATYPE_INTEGER	= 1;
var _EVAL_DATATYPE_FLOAT	= 2;
var _EVAL_DATATYPE_STRING	= 3;

function RegisterStaticType(strDef)
{
	return Docmap.RegisterStaticType(strDef);
}

function RegisterDynamicType(nType, strName, strProp, bLocal)
{
	return Docmap.RegisterDynamicType(nType, strName, strProp, bLocal);
}

function BeginDeclareVariable(strVar)
{
	return Docmap.BeginDeclareVariable(strVar);
}

function EndDeclareVariable()
{
	return Docmap.EndDeclareVariable();
}

function BeginAddElement(strVar)
{
	return Docmap.BeginAddElement(strVar);
}

function EndAddElement()
{
	return Docmap.EndAddElement();
}

function SetDocOnlineHelp(strAddr)
{
	Docmap.SetDocOnlineHelp(strAddr);
}

function DeclareVariable(strType, strVar, strProps)
{
	var strDef;
	if (strProps.length > 0) {
		strDef = strType + " " + strVar + " " + strProps + ";";
	}
	else {
		strDef = strType + " " + strVar + ";";
	}
	if (Docmap.IsRegisterDynamicType(strType)) {
		BeginDeclareVariable(strDef);
		eval(strType + "();");
		EndDeclareVariable();
	}
	else {
		Evaluate(strDef);
	}
}

function GetDocOnlineHelp()
{
	return Docmap.GetDocOnlineHelp();
}

function GetMappingStart()
{
	return Docmap.GetMappingStart();
}

function SetMappingStart(nNewOffset)
{
	return Docmap.SetMappingStart(nNewOffset);
}

function GetEditPosition()
{
	return Docmap.GetEditPosition();
}

function IsBigEndian()
{
	return Docmap.IsBigEndian();
}

function IsLittleEndian()
{
	return Docmap.IsLittleEndian();
}

function SetBigEndian()
{
	Docmap.SetBigEndian();
}

function SetLittleEndian()
{
	Docmap.SetLittleEndian();
}

function IsHexadecimal()
{
	if (Docmap.GetNumberRadix() == 16) {
		return true;
	}
	return false;
}

function IsDecimal()
{
	if (Docmap.GetNumberRadix() == 10) {
		return true;
	}
	return false;
}

function IsOctal()
{
	if (Docmap.GetNumberRadix() == 8) {
		return true;
	}
	return false;
}

function SetHexadecimal()
{
	Docmap.SetNumberRadix(16);
	return IsHexadecimal();
}

function SetDecimal()
{
	Docmap.SetNumberRadix(10);
	return IsDecimal();
}

function SetOctal()
{
	Docmap.SetNumberRadix(8);
	return IsOctal();
}

function Message(strMsg)
{
	Docmap.Message(strMsg);
}

function GetDocSize()
{
	return Docmap.GetDocSize();
}

function GetMappingPos()
{
	return Docmap.GetMappingPos();
}

function IsEof()
{
	var nSize, nPos;
	nSize = GetDocSize();
	if (nSize > 0) {
		nPos = GetMappingPos();
		return !(nPos >= 0 && nPos < nSize);
	}
	return true;
}

function SetMappingPos(nNewPos)
{
    var strJump;
	var nSize, nStart, nLen;
	var bEof = IsEof();
	var nPos = GetMappingPos();

	if (nNewPos > nPos && !bEof) {
		nSize = GetDocSize();
		nStart = GetMappingStart();
		nLen = nNewPos - nStart;
		if (nLen > nSize) {
			nNewPos = nStart + nSize;
		}
		nLen = nNewPos - nPos;
		nPos = nNewPos;

		_jmpCount ++;
		strJump = "BYTE JS_SKIPBYTES_" + _jmpCount + "[" + nLen + "];";
        Evaluate(strJump);
	}
	return nPos;
}

function ReadChars(pos, len)
{
	return Docmap.ReadDocChars(pos, len);
}

function ReadByte(pos)
{
	return Docmap.ReadDocInt(pos, 1, false);
}

function ReadShort(pos)
{
	var bSwap = IsBigEndian();
	return Docmap.ReadDocInt(pos, 2, bSwap);
}

function ReadInt(pos)
{
	var bSwap = IsBigEndian();
	return Docmap.ReadDocInt(pos, 4, bSwap);
}

function ReadFloat(pos)
{
	var bSwap = IsBigEndian();
	return Docmap.ReadDocFloat(pos, false, bSwap);
}

function ReadDouble(pos)
{
	var bSwap = IsBigEndian();
	return Docmap.ReadDocFloat(pos, true, bSwap);
}

function ReadTypeData(pos, strMem)
{
	var strRes = Docmap.ReadDocTypeData(pos, strMem);
	var nDataType = Docmap.GetEvalType();
	if (nDataType != _EVAL_DATATYPE_ERROR) {
		if (nDataType == _EVAL_DATATYPE_INTEGER) {
			return parseInt(strRes);
		}
		else if (nDataType == _EVAL_DATATYPE_FLOAT) {
			return parseFloat(strRes);
		}
		else if (nDataType == _EVAL_DATATYPE_STRING) {
			return strRes;
		}
	}
	return null;
}

function Evaluate(strEva)
{
	var strRes = Docmap.Evaluate(strEva);
	var nDataType = Docmap.GetEvalType();
	if (nDataType != _EVAL_DATATYPE_ERROR) {
		if (nDataType == _EVAL_DATATYPE_INTEGER) {
			return parseInt(strRes);
		}
		else if (nDataType == _EVAL_DATATYPE_FLOAT) {
			return parseFloat(strRes);
		}
		else if (nDataType == _EVAL_DATATYPE_STRING) {
			return strRes;
		}
	}
	return null;
}

function EvaluateMembers(strType, strEva)
{
	Docmap.EvaluateMembers(strType, strEva);
}

function IsExistent(strVar)
{
	return (Docmap.GetSizeof(strVar) >= 0);
}

function GetSizeof(strVar)
{
	return Docmap.GetSizeof(strVar);
}

function GetStartof(strVar)
{
	return Docmap.GetStartof(strVar);
}

function GetVariableInt(strVar)
{
	var strRes = Docmap.Evaluate(strVar);
	return parseInt(strRes);
}

function GetVariableFloat(strVar)
{
	var strValue = Docmap.Evaluate(strVar);
	return parseFloat(strValue);
}

function GetVariableString(strVar)
{
	return Docmap.Evaluate(strVar);
}

