

function AddNewOption(argElement, argValue, argText )
{
    var el      =   document.createElement( "OPTION" );
    el.text     =   argText;
    el.value    =   argValue;
    document.all[argElement].options.add( el );
}


function SetListViewHeader(parListViewObj, parHeaderArray)
{
	 var k,i;
	 
	 parListViewObj.ClearHeader();
	 
	 for(k=0, i=0; k < (parHeaderArray.length/2); k++, i=i+2)
	 {
		 parListViewObj.SetHeader( k, parHeaderArray[i], parseInt(parHeaderArray[i+1]) ); 
	 }
	 
}


function ReplaceDicomDelimiterToBlank(argString)
{
	if(typeof(argString) != "string")
	{
		return argString;
	}
	argString = argString.replace(/\^/g, " ");
	return argString;
}

function ConvertDicomPatientNameOutput(argFormat, argString)
{
	var patParts = new Array();
	if (argFormat == "")
	{
		argFormat = "%FAMILYNAME%, %GIVENNAME%,%PREFIX%,%MIDDLENAME%,%SUFFIX%"
	}
		 
	if(typeof(argFormat) != "string")
	{
		return argString;
	}
		 
	if(typeof(argString) != "string")
	{
		return argString;
	}
	
	patParts = argString.split("^");
	
	for (var i=0; i < 5; i++)
	{
		  if (typeof(patParts[i]) == "undefined")
		  {
				 patParts[i] = "";
		  }
	}
	
	var formatParts = new Array();	 
	formatParts = argFormat.split("%");	 
	var newString = "";
	var lastDelim = "";
	
	for(var n=0; n < formatParts.length; n++)
	{	 
			if(formatParts[n] == "FAMILYNAME")
			{
				 newString += TrimFirstLast(patParts[0]); 
				 if(patParts[0] != "") {
					   lastDelim = formatParts[++n];
						newString += lastDelim;
				  }
				  else  {
						n++;
				  }
			}
			else if(formatParts[n] == "GIVENNAME")
			{
				  newString += TrimFirstLast(patParts[1]); 
				  if(patParts[1] != "")  {   
					   lastDelim = formatParts[++n];
						newString += lastDelim;
				  }
				  else  {
						n++;
				  }
			}
			else if(formatParts[n] == "MIDDLENAME") 
			{
				  newString += TrimFirstLast(patParts[2]);
				  if(patParts[2] != "") {
					   lastDelim = formatParts[++n];
						newString += lastDelim;
				  }
				  else {
						n++;
				  }
			}
			else if(formatParts[n] == "PREFIX") 
			{
				  newString += TrimFirstLast(patParts[3]);
				  if(patParts[3] != "") {
					   lastDelim = formatParts[++n];
						newString += lastDelim;
				  }
				  else {
						n++;
				  }
			}
			else if(formatParts[n] == "SUFFIX") 
			{
				  newString += TrimFirstLast(patParts[4]);
				  if(patParts[4] != "") {
					   lastDelim = formatParts[++n];
						newString += lastDelim;
				  }
				  else {
						n++;
				  }
			}
	}
  
	var lastDelimPos = newString.lastIndexOf(lastDelim);
	if(lastDelimPos == (newString.length-(lastDelim.length)))
	{
			argString = newString.substring(0, lastDelimPos);
	}
	else
	{
		    argString = newString;
	}
	
	return argString;
}


function TrimFirstLast(argString) 
{
  while(argString.substring(0,1) == ' ')
  {
    argString = argString.substring(1,argString.length);
  }
  
  while(argString.substring(argString.length-1,argString.length) == ' ') 
  {
    argString = argString.substring(0,argString.length-1);
  }
  return argString;
}

function ClientSiteErrorConvert(argModule, argCallingFunction, argCallingLevel, argErrDesc, argErrNo)
{
	 var arrError = new Array();
	 arrError[0] = "" 
	 arrError[1] = argModule
	 arrError[2] = argCallingFunction
	 arrError[3] = argCallingLevel
	 arrError[4] = argErrDesc 
	 arrError[5] = argErrNo
	 CallErrorPageExt(arrError);	  
}


function CallErrorPageExt(argArr)
{
	var url = "/client/error/error.asp?"
	url += "mod=" + argArr[1]
	url += "&func=" + argArr[2]	 
	url += "&level=" + argArr[3]	 
    url += "&desc=" + escape(argArr[4])	 		 	 
	url += "&no=" + escape(argArr[5])	 		 	 	 
    window.location.href = url;
}


function SetLangbyElement(argElement,argValue,argType)
{
	  switch(argType)
	  {
		  case "innerHTML" :
				if(typeof(document.all[argElement]) == "object")
				{
					  document.all[argElement].innerHTML = argValue
				}
		  break;
		  case "value":
		  if(typeof(document.all[argElement]) == "object")
				{
					  document.all[argElement].value = argValue
				}
		  break;
	  }
}



function SetFocus(argElem)
{
	if(typeof(document.all[argElem]) == "object")
	{
		document.all[argElem].focus();
	}
}
function EnableElement(argElem)
{
	 if(typeof(document.all[argElem]) == "object")
	 {
		  document.all[argElem].disabled =  false;
	 }
}

function DisableElement(argElem)
{
	 if(typeof(document.all[argElem]) == "object")
	 {
		  document.all[argElem].disabled =  true;
	 }
}

function GetCbx(argElem)
{
	if(typeof(document.all[argElem]) == "object")
	{ 
		if(document.all[argElem].checked == true)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
}

function SetCbx(argElem, argStat)
{
	if(typeof(document.all[argElem]) == "object")
	{ 
		document.all[argElem].checked = (argStat == 1) ? true : false;
	}
}


function GetValueByElement(argElem)
{
	if(typeof(document.all[argElem]) == "object")
	{ 
		return document.all[argElem].value;
	}
	else
	{
		return "";
	}
}

function SetValueByElement(argElem, argValue)
{
	if(typeof(document.all[argElem]) == "object")
	{ 
		document.all[argElem].value = argValue;
	}
}


function DeleteAllOptions(argElement)
{
	for(var i=document.all[argElement].length; i >= 0 ; i--)
	{
		document.all[argElement].options[i] = null	
	}
	
}

function isValueCheck(parRetValue)
{
	var retVal;
	var ReallyRetValue;
	 
	if(!ParseRSAdmin( parRetValue.status, parRetValue.data))
	{
		 return( -1 );
	}
	else
	{
		 ReallyRetValue = parRetValue.return_value;
	}

	return ReallyRetValue;

}

function ParseRSAdmin(argStatus,argData)
{
   if( argStatus == -1 )
	  {
		var strErrMsg = langdep.strRSError
			strErrMsg += argData;

			strErrMsg = strErrMsg.replace(parent.User, "LoginName");
			strErrMsg = strErrMsg.replace(parent.Pass, "LoginPassword");

		ShowMessageBox(strErrMsg, g_MsgError);

		return false;
	  }
	return true;
}


function String2Array( argString, argSep )
{
	var i;
	var strSeparator = argSep;
	var arrRet = new Array();
	var tmp_str = "";
	var chrTmp;
	var tmp_curElement = 0;

	for( i=0; i < argString.length; i++ )
	{
		chrTmp  = argString.charAt(i);
		if( chrTmp == strSeparator )
		{
			arrRet[tmp_curElement] = tmp_str;
			tmp_curElement++;
			tmp_str = "";
		} else {
			tmp_str	+= chrTmp;
		}
	}
	arrRet[tmp_curElement] = tmp_str;
	return arrRet;
}

function TrimStringExt( argString, argStat, argLength, argStringEnd )
{
	var strLength;
	var i;
	var buffer;
	var isChar = false
	var isLastChar = 0;
	
	if(argString == "")
	{
		return argString;
	}
	
	isLastChar = argString.length
		 
	for(var j = argString.length-1; j >= 0; j--)
	{
		if( argString.charAt( j ) != " " ) 
		{                                                                
			 isLastChar = j;
			 j = -1;
		}
	}
	
	strLength = isLastChar;
	
	if(argLength < isLastChar && argLength != 0)
	{
		 strLength = argLength;
	}
	else
	{
		 argStringEnd = ""
	}
	
   for ( buffer = "", i = 0; i <= strLength; i++) 
   {
      if(isChar == false) 
		{
				if( argString.charAt( i ) == " " ) 
				{                                                                
					 buffer+="";
				}
				else
				{
					 buffer+= argString.charAt(i);
					 isChar = true;
				}
		}
		else
      {
          buffer+= argString.charAt(i);
      }
   }
	return( buffer + argStringEnd );
}

function SetElementTitle(argElement, argValue)
{
	if(typeof(document.all[argElement]) == "object")  document.all[argElement].title = argValue;
}

function DisplayPatientInfoExOLd( argoStartView )
{
	var tmp_capt;
	if( typeof( argoStartView ) == "object" )
	{
		 tmp_capt = "<table height=100% width=100% cellspacing=0 cellpadding=0 border=0><tr><td class='btPatientHeader'>";
		 tmp_capt += "<div style='position:absolute;left:3;top:1;width:2000'>";
		 tmp_capt += langdep.strPatientName;
		 tmp_capt += "<b>" + argoStartView.PatientName + "</b>";
		 tmp_capt += langdep.strPatientID;
		 tmp_capt +=	"<b>" + argoStartView.PatientID + "</b>";
		 tmp_capt += langdep.strBirthdate
		 tmp_capt += "<b>" + argoStartView.PatientDOB + "</b>";
		 tmp_capt +=	"</div>";
		 tmp_capt +=	"</td></tr></table>";
	} 
	else 
	{
		   tmp_capt = "";
	}
	return tmp_capt;
}

function DisplayPatientInfoEx( argoStartView )
{
	var tmp_capt;
	if( typeof( argoStartView ) == "object" )
	{
		 tmp_capt = "<nobr>&nbsp;" + langdep.strPatientName;
		 tmp_capt += "<b>" + argoStartView.PatientName + "</b>";
		 tmp_capt += "&nbsp;&nbsp;" + langdep.strPatientID;
		 tmp_capt +=	"<b>" + argoStartView.PatientID + "</b>";
		 tmp_capt += "&nbsp;&nbsp;" + langdep.strBirthdate
		 tmp_capt += "<b>" + argoStartView.PatientDOB + "</b>";
		 tmp_capt +=	"</nobr>";
	} 
	else 
	{
		   tmp_capt = "";
	}
	return tmp_capt;
}



function GetDisplayPatientInfo(argPatientName, argPatientID, argBirthDate, argShow)
{
    var tmp_capt = "";
	if(argShow)
	{
		tmp_capt = "<nobr>&nbsp;";
		tmp_capt += langdep.strPatientName;
		tmp_capt += "<b>"
		tmp_capt += ConvertDicomPatientNameOutput("", argPatientName);
		tmp_capt += "</b>&nbsp;&nbsp;";
		tmp_capt += langdep.strPatientID;
		tmp_capt += "<b>" + argPatientID + "</b>&nbsp;&nbsp;";
		tmp_capt += langdep.strBirthdate;
		tmp_capt += "<b>" + argBirthDate + "</b>";
		tmp_capt += "</nobr>";
	}
    return tmp_capt;
}


function DisplayStudyInfo( argStudyDesc, argStudyDate, argStudyTime )
{
	var tmp_capt;
    tmp_capt = "<nobr>&nbsp;" + langdep.strStudyDescription;
	tmp_capt += "<b>&nbsp;" + argStudyDesc + "</b>&nbsp;&nbsp;";
	tmp_capt += langdep.strStudyDateTime;
	tmp_capt +=	"<b>&nbsp;" + argStudyDate + "</b>";
	tmp_capt += "<nobr>&nbsp;";
	tmp_capt += "<b>" + argStudyTime + "</b>";
	tmp_capt +=	"</nobr>";
	return tmp_capt;
}

function DisplayStudyInfoPSDesc( argStudyDesc, argStudyDate, argStudyTime, argPSDesc )
{
	var tmp_capt;
    tmp_capt = "<nobr>&nbsp;" + langdep.strStudyDescription;
	tmp_capt += "<b>&nbsp;" + argStudyDesc + "</b>&nbsp;&nbsp;";
	tmp_capt += langdep.strStudyDateTime;
	tmp_capt +=	"<b>&nbsp;" + argStudyDate + "</b>";
	tmp_capt += "<nobr>&nbsp;";
	tmp_capt += "<b>" + argStudyTime + "</b>&nbsp;&nbsp;";
	tmp_capt += langdep.strColPS[2];
	tmp_capt +=	"<b>&nbsp;" + argPSDesc + "</b>";
	tmp_capt +=	"</nobr>";
	return tmp_capt;
}

function StudyInfoPSDescTT( argStudyDesc, argStudyDate, argStudyTime, argPSDesc )
{
	var tmp_capt;
    tmp_capt = langdep.strStudyDescription;
	tmp_capt += " " + argStudyDesc + "\n";
	tmp_capt += langdep.strStudyDateTime;
	tmp_capt +=	" " + argStudyDate + " ";
	tmp_capt += " ";
	tmp_capt += "" + argStudyTime + "\n";
	tmp_capt += langdep.strColPS[2] + "";
	tmp_capt +=	" " + argPSDesc;
	return tmp_capt;
}

function PatientInfoTT( argoStartView )
{
    var tmp_capt;
	if( typeof( argoStartView ) == "object" )
	{
		 tmp_capt = ReplaceExpr(langdep.strPatientName,"&nbsp;"," ");
		 tmp_capt += " " + ReplaceExpr(argoStartView.PatientName,"&nbsp;","") + "\n";
		 tmp_capt += ReplaceExpr(langdep.strPatientID, "&nbsp;"," ");
		 tmp_capt += " " + ReplaceExpr(argoStartView.PatientID,"&nbsp;","") + "\n";
		 tmp_capt += ReplaceExpr(langdep.strBirthdate, "&nbsp;"," ");
		 tmp_capt += " " + ReplaceExpr(argoStartView.PatientDOB, "&nbsp;","");
	} 
	else 
	{
		   tmp_capt = "";
	}
	return tmp_capt;
}

function ReplaceExpr( argStr, argExpression, argValue )
{
	var tmp_bExprfound = true;	 
	var tmp_var = -1;  
	var tmp;
	
	do
	{
		tmp_var = argStr.search(argExpression);
		if( tmp_var	== -1 )
		{
		   tmp_bExprfound = false; 
		}
		tmp = argStr.replace(argExpression,argValue );
		argStr = tmp;
	} 
	while ( tmp_bExprfound  );
	return argStr;
}

function StudyInfoTT( argStudyDesc, argStudyDate, argStudyTime )
{
	var tmp_capt;
    tmp_capt = langdep.strStudyDescription;
	tmp_capt += " " + argStudyDesc + "\n";
	tmp_capt += langdep.strStudyDateTime;
	tmp_capt +=	" " + argStudyDate + " ";
	tmp_capt += " ";
	tmp_capt += "" + argStudyTime;
	return tmp_capt;
}

function IsSpecialCharacterInString( argString )
{
	for (var i = 0; i <= argString.length; i++) 
	{
		if ( argString.charAt( i ) == "|" || argString.charAt( i ) =="\\" || argString.charAt( i ) =="+" ) 
		{                                                                
			return true;
		}

	}
	return false;
}

function ReplaceSign( argParam )
{
	var buffer;
	var i;
    for ( buffer = "", i = 0; i <= argParam.length; i++) 
    {
        if ( argParam.charAt( i ) == "\"" ) 
        {                                                                
				 buffer+="'";
        }
		  else if( argParam.charAt( i ) == "\+" )
		  {
				 buffer+="\+";
		  }
		  else if( argParam.charAt( i ) == "\\" )
		  {
				 buffer+= "\\\\";
		  }
		  else if( argParam.charAt( i ) == "|" )
		  {
				 buffer+= "\|";
		  }
		  else
        {
				buffer+= argParam.charAt(i);
        }
    }
	return( buffer );
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: replace characters
//END FUNCTION -------------------------------------------------------------
function CutSign( argParam )
{
	var buffer;
	var i;
	for (  buffer = "", i = 0; i <= argParam.length; i++) 
	{
		  if( argParam.charAt( i ) == "|" )
		  {
				 buffer+= "";
		  }
		  else if( argParam.charAt( i ) == "\+" )
		  {
				 buffer+= "";
		  }
		  else
        {
				buffer+= argParam.charAt(i);
        }
   }
	return( buffer );
}


function ReplaceBackSlashBack( argParam )
{
	var regExpr	  = /\\\\/g;
	var retString = argParam.replace(regExpr, "\\" );
	return( retString );
}




// CommonJavaScript section. //

function remove_paddingspaces( argStr )
{
	var re_begin = /^[\x20\t]+/;
	var re_end = /[\x20\t]+$/;

	argStr = argStr.replace( re_begin, "" );
	argStr = argStr.replace( re_end, "" );

	return argStr;
}

function FixDate( argTime )
{
	var	strRet = ""; var tmpval;
	strRet += argTime.getFullYear();
	strRet += "-"; tmpval = argTime.getMonth() + 1;
	if( tmpval < 10 )	strRet += "0";
	strRet += tmpval; strRet += "-";
	tmpval = argTime.getDate();
	if( tmpval < 10 )	strRet += "0";
	strRet += tmpval; return strRet;
}
function FixTime( argTime )
{
	var	strRet = ""; var tmpval;
	tmpval = argTime.getHours();
	if( tmpval < 10 )	strRet += "0";
	strRet += tmpval; strRet += ":";
	tmpval = argTime.getMinutes();
	if( tmpval < 10 )	strRet += "0";
	strRet += tmpval; strRet += ":";
	tmpval = argTime.getSeconds();
	if( tmpval < 10 )	strRet += "0";
	strRet += tmpval; return strRet;
}
function N2M( argObj )
{
	if( typeof( argObj ) == "string" )
	{
		if( !argObj.length )	return "-";
		return argObj;
	}
	return "-";
}
function FixDateTime( argDateTime )
{
	return FixDate( argDateTime ) + " " + FixTime( argDateTime );
}

//*****************************************************************
// function uneval(obj) 
//	This function takes a given jscript object and creates a 
//	string representing the object instance in its current state, 
//	such that when the string is "evaluated" with the "eval" 
//	function, the object will be recreated. This function is used 
//	to to "marshall" jscript objects across the client/server
//	boundary.
//
//*****************************************************************
var unevalInitialized;
var unevalNextIdentifier;
function unevalGetNextID()
{
	return '_o' + unevalNextID++;
}

function uneval(obj)
{
	if (!unevalInitialized)
	{
		initUneval();
		unevalInitialized = true;
	}
	unevalNextID = 0;
	var s = 'var undefined;' + unevalDecl(obj) + unevalInst(obj);
	unevalClear(obj);
	return s;
}

function unevalDecl(obj)
{
	var s = '';
	switch (typeof(obj))
	{
		case 'undefined':
		case 'boolean':
		case 'number':
		case 'string':
			break;

		default:
			if (null != obj && !obj.__mark && 'string' != typeof(obj.__decl))
				{
				obj.__mark = true;
				obj.__decl = unevalGetNextID();
				s = obj.__unevalDecl();
				delete obj.__mark;
				}
			break;
	}
	return s;
}

function unevalInst(obj)
{
	var s = '';
	switch (typeof(obj))
	{
		case 'undefined':
			s = 'undefined';
			break;
		case 'boolean':
		case 'number':
			s = String(obj);
			break;
		case 'string':
			s = unevalString(obj);
			break;

		default:
			if (null == obj)
				s = 'null';
			else if (obj.__mark)
				s = '"ERROR: Cycle in uneval graph."';
			else
				{
				obj.__mark = true;
				s = obj.__unevalInst();
				delete obj.__mark;
				}
			break;
	}
	return s;
}

function unevalClear(obj)
{
	switch (typeof(obj))
	{
		case 'undefined':
		case 'boolean':
		case 'number':
		case 'string':
			break;

		default:
			if (null != obj && !obj.__mark && 'string' == typeof(obj.__decl))
			{
				obj.__mark = true;
				obj.__unevalClear();
				delete obj.__mark;
			}
			break;
	}
	return ;
}

function unevalDoNothing() 
{	}

function unevalConvertToString(obj)
{	return String(obj);		}

function unevalString(str) 
{
// CHANGED:
	var replaceStr = str.replace(/"/g, "\\\"");
	var test = '"' + replaceStr + '"';

//	var test =  '"' + replaceStr.replace(/([^\\])'/g,'$1\\"') + '"';
	return test;

	return '"' + str.replace(/([^\\])'/g,'$1\\"') + '"'; 
}


//*****************************************************************
// function initUneval()
//
//	This function sets up the prototype __uneval functions that
//  are used to support uneval function for all data types.
//
//*****************************************************************
function initUneval()
{
	// instrinsic objects
	Object.__unevalDecl = unevalDoNothing;
	Object.__unevalInst = function () { return 'Object'; }
	Object.__unevalClear = unevalDoNothing;

	Boolean.__unevalDecl = unevalDoNothing;
	Boolean.__unevalInst = function () { return 'Boolean'; }
	Boolean.__unevalClear = unevalDoNothing;

	Number.__unevalDecl = unevalDoNothing;
	Number.__unevalInst = function () { return 'Number'; }
	Number.__unevalClear = unevalDoNothing;

	String.__unevalDecl = unevalDoNothing;
	String.__unevalInst = function () { return 'String'; }
	String.__unevalClear = unevalDoNothing;

	Date.__unevalDecl = unevalDoNothing;
	Date.__unevalInst = function () { return 'Date'; }
	Date.__unevalClear = unevalDoNothing;

	Function.__unevalDecl = unevalDoNothing;
	Function.__unevalInst = function () { return 'Function'; }
	Function.__unevalClear = unevalDoNothing;

	Array.__unevalDecl = unevalDoNothing;
	Array.__unevalInst = function () { return 'Array'; }
	Array.__unevalClear = unevalDoNothing;

	// object members
	Object.prototype.__enumMembers = function(retval,func)
	{
		var isPublicMember = this.__isPublicMember;
		if ('object' == typeof(this.__unevalProperties))
		{
			var unevalProperties = this.__unevalProperties;
			var length = unevalProperties.length;
			for (var i = 0; i < length; i++)
			{
				if (isPublicMember(unevalProperties[i]))
					func(retval, this, unevalProperties[i]);
			}
		}
		else
		{
			for (var i in this)
			{
				if (isPublicMember(i))
					func(retval, this, i);
			}
		}
	}

	Object.prototype.__unevalDeclMember = function (retval, obj, member)
	{
		retval.otherDecl += unevalDecl(obj[member]);
		retval.myDecl += obj.__decl + '[' + unevalString(member) + ']=' + unevalInst(obj[member]) + ';';
	}

	Object.prototype.__unevalDecl = function()
	{
		var retval = { otherDecl:'', myDecl:'' };
		this.__enumMembers(retval, this.__unevalDeclMember);
		return retval.otherDecl + 'var ' + this.__decl + '=' + this.__unevalConstructor() + ';' + retval.myDecl;
	}

	Object.prototype.__unevalInst = function ()
	{	return this.__decl;		}

	Object.prototype.__unevalClearMember = function(retval, obj, member)
	{	unevalClear(obj[member]);	}

	Object.prototype.__unevalClear = function()
	{
		delete this.__decl;
		this.__enumMembers(null, this.__unevalClearMember);
	}

	Object.prototype.__isPublicMember = function(member)
	{	return '__' != member.substr(0,2);		}

	Object.prototype.__unevalConstructor = function ()
	{	return 'new Object';		}

	// overrides for simple types
	Boolean.prototype.__unevalConstructor = function()
	{	return 'new Boolean(' + String(this) + ')';	}
	Number.prototype.__unevalConstructor = function()
	{	return 'new Number(' + String(this) + ')';	}
	String.prototype.__unevalConstructor = function()
	{	return 'new String(' + unevalString(this) + ')';	}
	Date.prototype.__unevalConstructor = function()
	{	return 'new Date(Date.parse("' + String(this) + '"))';	}

	// overrides for function
	Function.prototype.__unevalDecl = function()
	{	return String(this).replace(/function ([^\(]*)/,'function ' + this.__decl);	}

	// overrides for array
	Array.prototype.__unevalDecl = function()
	{
		var decl = this.__decl;
		var r = '';    
		var s = 'var ' +  decl + '= new Array(' + this.length + ');';
		var length = this.length;
		for (var i = 0; i < length; i++)
		{
			r += unevalDecl(this[i]);
			s += decl + '[' + i + ']=' + unevalInst(this[i]) + ';';
		}
		return r + s;
	}

}	// end of initUneval

//BEGIN FUNCTION -----------------------------------------------------------
//Description: encodes more than escape() - also @,/,* and +
//It seems like unescape() also decodes the additional chars - so
// you don't HAVE to use moreUnescape to decode strings which were encoded with
// moreEscape().
//END FUNCTION -------------------------------------------------------------
function moreEscape(argString) 
{
	var strResult=escape(argString);
	
	strResult=strResult.replace(/@/g,'%40');
	strResult=strResult.replace(/\+/g,'%2B');
	strResult=strResult.replace(/\*/g,'%2A');
	strResult=strResult.replace(/(\/)/g,'%2F');
	return strResult;

}



/******************************************************************************/



// EmbedControl.JS
//BEGIN FUNCTION -----------------------------------------------------------
//Description: function to join a array or a number
//Parameters : argTableWidth  -  init table width
//           : argTableHeight -  init table height
//END FUNCTION -------------------------------------------------------------
function JoinArray(argArr, argSep)
{
	 var retString = ""
	 if(typeof(argArr) == "number")
	 {
		 retString = argArr;
	 }
	 else if (typeof(argArr) == "object")
	 {
		for(var i=0; i < argArr.length; i++)
		{
			  retString += (retString == "") ? argArr[i] : argSep + argArr[i];
		}		 
	 }
	return retString; 
}


//BEGIN FUNCTION -----------------------------------------------------------
//Description: resize modal dialogs
//Parameters : argTableWidth  -  init table width
//           : argTableHeight -  init table height
//END FUNCTION -------------------------------------------------------------
function ResizeDialog(argTableWidth, argTableHeight, argInitWidth, argInitHeight)
{
	 window.dialogWidth = argTableWidth + "px"; 
	 window.dialogHeight = argTableHeight + "px";

	 var oldDialogHeight = window.dialogHeight;
	 var oldDialogWidth = window.dialogWidth;

	 var tmpDialogWidth = oldDialogWidth.replace('px','')
	 oldDialogWidth = parseInt(tmpDialogWidth,10);
	 var tmpDialogHeight = oldDialogHeight.replace('px','')
	 oldDialogHeight = parseInt(tmpDialogHeight,10);

	 var viewWidth = document.body.clientWidth;
	 var viewHeight = document.body.clientHeight;
	 var DeltaWidth = oldDialogWidth - viewWidth;		 
	 var DeltaHeight = oldDialogHeight - viewHeight;

	 var windowWidth = argTableWidth + DeltaWidth + argInitWidth;
	 var windowHeight = argTableHeight + DeltaHeight + argInitHeight;
	 //alert("oldDialogWidth: " + oldDialogWidth + "\nSichtweite: " + viewWidth + "\nTabellenbreit" + argTableWidth + "\nDeltaWidth: " + DeltaWidth + "\nNeueWeite: " + windowWidth);
	 //alert("oldDialogHeight: " + oldDialogHeight + "\nSichthöhe: " + viewHeight + "\nTabellenhöhe" + argTableHeight + "\nDeltaHeight: " + DeltaHeight + "\nNeueHöhe: " + windowHeight);
	 window.dialogWidth  = windowWidth + "px";
	 window.dialogHeight =  windowHeight + "px";

}


//BEGIN FUNCTION -----------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates an InterProcComm
//              object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//           : argName        -  The name for the object / string
//END FUNCTION -------------------------------------------------------------
function CreateInterProcComm(argDivElement, argName, argID)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.name = argName;
	myObject.id= argID;
	myObject.classid = "CLSID:C373556D-C8CD-40F6-A5E2-46EF827EF714";
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a WebClientInstall
//              object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string 
//			 : argWidth	      -  The width value for the object / string
//			 : argHeight	  -  The height value for the object / string
//			 : argStyle	      -  The style class for the object / string
//           : argName        -  The name for the object / string
//			 : argCodebase	  -  The code version for the object / string
//END FUNCTION -------------------------------------------------------------
function CreateWebClientInstall(argDivElement, argElement, argWidth, argHeight, argStyle, argName, argCodebase)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.width = argWidth;
	myObject.height = argHeight;
	myObject.className = argStyle;
	myObject.name = argName;
	myObject.codeBase = argCodebase;
	myObject.classid = "CLSID:A7B17C34-D894-11D3-AE37-0050DA39FE5C";
}

//BEGIN FUNCTION -------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a ListView object
//				dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//           : argElement     -  The ID for the object / string
//		     : argWidth		  -  The width value for the object / string
//			 : argHeight	  -  The height value for the object / string
//			 : argData		  -  The data attribute for the object / string
//END FUNCTION ---------------------------------------------------------------
function CreateListView(argDivElement, argElement, argWidth, argHeight, argStyle, argData)
{
    var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.width = argWidth;
	myObject.height = argHeight;
	myObject.className = argStyle;
	myObject.classid = "CLSID:1115D8B6-0889-11D3-85DA-006097C4BDE0";
	myObject.data = argData;    // Varies...
}

//BEGIN FUNCTION -------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a CmpPreload object
//				dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//           : argElement     -  The ID for the object / string
//END FUNCTION ---------------------------------------------------------------
function CreateCmpPreload(argDivElement, argElement)
{
    var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.classid = "CLSID:1C641965-8EE8-4DBD-91D0-2D98B8C3BB62";
}

//BEGIN FUNCTION -------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a cmpSync3D object
//				dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//           : argElement     -  The ID for the object / string
//END FUNCTION ---------------------------------------------------------------
function CreateCmpSync3D(argDivElement, argElement)
{
    var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.classid = "CLSID:CEDA7501-4552-4EC5-9621-13107EAC9EE9";
}

//BEGIN FUNCTION -------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates an IEControl object
//				dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//           : argElement     -  The ID for the object / string
//			 : argStyle		  -  The style class for the object / string
//END FUNCTION ---------------------------------------------------------------
function CreateIEControl(argDivElement, argElement, argStyle)
{
    var myObject = document.createElement('object');
    argDivElement.appendChild(myObject);
    myObject.id = argElement;
    myObject.className = argStyle;
    myObject.classid= "CLSID:62465353-2C44-4873-B511-426BA3DB6C1C"; 
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates an RSProxyControl
//              object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string 
//			 : argWidth		  -  The width value for the object / string
//			 : argHeight	  -  The height value for the object / string
//           : argName        -  The name for the object / string
//END FUNCTION -------------------------------------------------------------
function CreateRSProxy(argDivElement, argElement, argWidth, argHeight, argName)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.width = argWidth;
	myObject.height = argHeight;
	myObject.name = argName;
	myObject.classid = "CLSID:5D5F097C-295C-4065-9F6E-C9B96A018310";
}



//BEGIN FUNCTION -------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a MultiButton 
//              object dynamically. / Common version.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string 
//           : argStyle       -  The name of the object's style class / string
//END FUNCTION ---------------------------------------------------------------
function CreateMultiButton(argDivElement, argElement, argStyle)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.className = argStyle;      
	myObject.classid = "CLSID:B7D65891-DA84-4AFA-9A38-FCA6AE93CF2D";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a MultiButton 
//              object dynamically. / Version for  vw_main.htm .
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string 
//           : argStyle       -  The name of the object's style class / string
//           : argData        -  The application data associated with the object / string
//END FUNCTION --------------------------------------------------------------------------
function CreateMultiButtonClose(argDivElement, argElement, argStyle, argData)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.className = argStyle;      
	myObject.classid = "CLSID:B7D65891-DA84-4AFA-9A38-FCA6AE93CF2D";
	myObject.data = argData;
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a MultiButton 
//              object dynamically. / Version for  SB.htm .
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string 
//           : argWidth       -  The width value for the object / string
//           : argHeight      -  The height value for the object / string
//           : argData        -  The application data associated with the object / string
//END FUNCTION --------------------------------------------------------------------------
function CreateMultiButtonAuditWarn(argDivElement, argElement, argWidth, argHeight, argData)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.width = argWidth;
	myObject.height = argHeight; 
	myObject.classid = "CLSID:B7D65891-DA84-4AFA-9A38-FCA6AE93CF2D";
	myObject.data = argData;
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a DateTimePicker 
//              object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argStyle       -  The name of the object's style class / string
//END FUNCTION --------------------------------------------------------------------------
function CreateDateTimePicker(argDivElement, argElement, argStyle)
{
	var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.className = argStyle;      
	myObject.classid = "clsid:B07C89A5-12D9-11D3-85E4-006097C4BDE0";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a CtlPreview 
//              object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argStyle       -  The name of the object's style class / string
//           : argData        -  The application data associated with the object / string
//END FUNCTION --------------------------------------------------------------------------
function CreateCtlPreview(argDivElement, argElement, argStyle)
{
   var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.className = argStyle;
	myObject.classid = "CLSID:D24E5FEF-8A46-451E-90DE-73ED8FA17214";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a CtlView object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argWidth       -  The width value for the object / string
//           : argHeight      -  The height value for the object / string
//END FUNCTION --------------------------------------------------------------------------
function CreateCtlView(argDivElement, argElement, argWidth, argHeight)
{
   var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.width = argWidth;
	myObject.height = argHeight;
	myObject.classid = "CLSID:56A8C3B7-3E62-4854-8D79-95CAB618F459";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a ScrollBar object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argHeight      -  The height value for the object / string
//END FUNCTION --------------------------------------------------------------------------
function CreateScrollBar(argDivElement, argElement, argHeight)
{
   var myObject = document.createElement('object');
	argDivElement.appendChild(myObject);
	myObject.id = argElement;
	myObject.height = argHeight;
	myObject.classid = "CLSID:688CE9A0-084A-11D3-85DA-006097C4BDE0";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a TrackBar object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argStyle       -  The name of the object's style class / string
//END FUNCTION --------------------------------------------------------------------------
function CreateTrackBar(argDivElement, argElement, argStyle)
{
    var myObject = document.createElement('object');
    argDivElement.appendChild(myObject);
    myObject.id = argElement;
    myObject.className = argStyle;
    myObject.classid = "CLSID:F027A543-0D37-11D3-85DF-006097C4BDE0";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a TrackBar object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argStyle       -  The name of the object's style class / string
//END FUNCTION --------------------------------------------------------------------------
function CreateViewFPS(argDivElement, argElement, argStyle)
{
    var myObject = document.createElement('object');
    argDivElement.appendChild(myObject);
    myObject.id = argElement;
    myObject.className = argStyle;
    myObject.classid = "CLSID:E672F058-14C3-414B-B2CD-2A96A23419E5";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a PalettePicker object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argStyle       -  The name of the object's style class / string
//END FUNCTION --------------------------------------------------------------------------
function CreatePalettePicker(argDivElement, argElement, argStyle)
{
    var myObject = document.createElement('object');
    argDivElement.appendChild(myObject);
    myObject.id        = argElement;
    myObject.className = argStyle;
    myObject.classid   = "CLSID:3DC2C97B-DE4E-4AFD-B95E-3ED31411909D";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a 2DViewer object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argWidth       -  The width value for the object / string
//           : argHeight      -  The height value for the object / string
//           : argTop         -  The top position of the object / string
//           : argLeft        -  The left position of the object / string
//END FUNCTION --------------------------------------------------------------------------
function Create2DViewer(argDivElement, argElement, argLeft, argTop, argWidth, argHeight)
{
    var myObject = document.createElement('object');
    argDivElement.appendChild(myObject);
    myObject.id        = argElement;
	 myObject.width = argWidth;
	 myObject.height = argHeight;
	 myObject.top = argTop;
	 myObject.left = argLeft;	 
    myObject.classid   = "CLSID:56A8C3B7-3E62-4854-8D79-95CAB618F459";
}

//BEGIN FUNCTION ------------------------------------------------------------------------
//Description: Called from DIV's InnerHTML, creates a 3DViewer object dynamically.
//Parameters : argDivElement  -  The name of the calling DIV / name
//	         : argElement     -  The ID for the object / string
//           : argWidth       -  The width value for the object / string
//           : argHeight      -  The height value for the object / string
//           : argTop         -  The top position of the object / string
//           : argLeft        -  The left position of the object / string
//END FUNCTION --------------------------------------------------------------------------
function Create3DViewer(argDivElement, argElement, argLeft, argTop, argWidth, argHeight)
{
     var myObject = document.createElement('object');
     argDivElement.appendChild(myObject);
     myObject.id        = argElement;
	 myObject.width = argWidth;
	 myObject.height = argHeight;
	 myObject.top = argTop;
	 myObject.left = argLeft;	 
     myObject.classid   = "CLSID:BCBFDEEE-BB92-421E-8550-95238F5DA473";
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: ConvertDicomPatientNameOutput 
//Parameters :      argDateTime: 20070512....
//					argFormat: "YYYY-MM-DD HH:MM:SS"
//					argString: "-" this is the defautl to check an set 
//END FUNCTION -------------------------------------------------------------
function ConvertIntDateToString(argDateTime, argFormat, argDefault)
{
  	var retString = ""
  	var theTimeString = ""
  	var tmpDateYear = "";
  	var tmpDateMonth = "";
  	var tmpDateDay = "";
  	if(typeof(argDateTime) == "string")
  	{
  		 if( argDateTime != argDefault )
  		 {
  			  tmpDateYear = argDateTime.substring(0,4);
  			  tmpDateMonth =argDateTime.substring(4,6);
  			  tmpDateDay = argDateTime.substring(6,8);
  			  theTimeString = argDateTime.substring(9,argDateTime.length);
  			  
  			  switch (argFormat)
  			  {
   				  case "YYYY-MM-DD HH:MM:SS" :   retString = tmpDateYear + "-" + tmpDateMonth + "-" + tmpDateDay + " " + theTimeString;                 										  
   															 break;
   				  case "YYYY-MM-DD" :   retString = tmpDateYear + "-" + tmpDateMonth + "-" + tmpDateDay;                 										  
   												break;
   				  case "HH:MM:SS" :   retString = theTimeString;                 										  
   												break;
  			  }
  		 }
  		 else
  		 {
  			  return argDefault;
  		 }
  		 
  		 return retString;
  	}
  	else
  	{
  		 return argDefault;
  	}
  	
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: ReplaceDicomDelimiterToBlank 
//Parameters : 
//          replaces ^ by SPACE   
//END FUNCTION -------------------------------------------------------------
function ReplaceDicomDelimiterToBlank(argString)
{
	if(typeof(argString) != "string")
	{
		return argString;
	}
	argString = argString.replace(/\^/g, " ");
	return argString;
}


//BEGIN FUNCTION -----------------------------------------------------------
//Description: get the protocol "http:" or "https:" back bei encryptionflag 
//END FUNCTION -------------------------------------------------------------
function GetRootURLProtocol(argEncryption)
{
	return (argEncryption == 1) ? "https:" : "http:";
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: Trim the first and the last space characters
//Parameters : 
//END FUNCTION -------------------------------------------------------------
function TrimFirstLast(argString) 
{
  while(argString.substring(0,1) == ' ')
  {
    argString = argString.substring(1,argString.length);
  }
  
  while(argString.substring(argString.length-1,argString.length) == ' ') 
  {
    argString = argString.substring(0,argString.length-1);
  }
  return argString;
}

//BEGIN FUNCTION -----------------------------------------------------------
//Description: displaying of patient info	ext
//END FUNCTION -------------------------------------------------------------
function GetDisplayPatientInfo(argPatientName, argPatientID, argBirthDate, argShow)
{
    var tmp_capt = "";
	if(argShow)
	{
		tmp_capt = "<nobr>&nbsp;";
		tmp_capt += langdep.strPatientName;
		tmp_capt += "<b>"
		tmp_capt += ConvertDicomPatientNameOutput(parent.g_strPatientNameDisplayFormat, argPatientName);
		tmp_capt += "</b>&nbsp;&nbsp;";
		tmp_capt += langdep.strPatientID;
		tmp_capt += "<b>" + argPatientID + "</b>&nbsp;&nbsp;";
		tmp_capt += langdep.strBirthdate;
		tmp_capt += "<b>" + argBirthDate + "</b>";
		tmp_capt += "</nobr>";
	}
    return tmp_capt;
}
 




