// Remote Scripting (C) Virtual Technologies Ltd. 
// http://www.virtech.ru

function divShowHide(divID, divAlter, imgID)
{
	var obj = document.getElementById(divID);
	var objAlter = null;
	if (divAlter)
		objAlter = document.getElementById(divAlter);
	var objIMG = null;
	if (imgID)
		objIMG = document.getElementById(imgID);
	if (obj.style.display == "none")
	{
		obj.style.display = "block";
		if (objAlter)
			objAlter.style.display = "none";
		if (objIMG)
		{
//			objIMG.src = '@@CommonPath@@re/img/up.gif';
			objIMG.src = objIMG.src.replace("down.gif", "up.gif");
			objIMG.alt = 'Свернуть';
		}
	}
	else
	{
		obj.style.display = "none";
		if (objAlter)
			objAlter.style.display = "block";
		if (objIMG)
		{
//			objIMG.src = '@@CommonPath@@re/img/down.gif';
			objIMG.src = objIMG.src.replace("up.gif", "down.gif");
			objIMG.alt = 'Развернуть';
		}
	}
}

function RS_set(targetElement, txt)
{
	var obj = document.getElementById(targetElement);
	if (obj)
		obj.innerHTML = txt;
}
function RS_call(url, frm)
{
	var doc;
	var obj = document.getElementById("RS_iframe");
	if (obj.contentDocument)
	{	// NS6
		doc = obj.contentDocument; 
	}
	else if (obj.contentWindow)
	{	// IE5.5, IE6
		doc = obj.contentWindow.document;
	}
	else if (obj.document)
	{	// IE5
		doc = obj.document;
	}
	else
	{
		alert("Не поддерживаются фреймы!");
		return true;
	}
	if (frm && url && url != "")
		frm.action = url;
	doc.location.replace(url);
	if (event)
		event.cancelBubble = true;
	return false;
}
function setSelectorMessage(obj, txt)
{
	if (!obj)
		return;
	if (obj.selectedIndex)
	{
		obj.selectedIndex = 0;
		while(obj.length > 1)
			obj.remove(1);
		var opt = obj.options[0];
		opt.text = txt;
		opt.value = "";
		opt.style.color = "red";
		opt.style.backgroundColor = "yellow";
	}
	else
	{
		obj.value = "";
	}
}
document.write('<iframe id="RS_iframe" name="RS_iframe" style="border:0px;width:0px;height:0px;"></iframe>');

//Преобразование символов в JSON-безопасные
function JSONEncode(txt)
{
	return txt
		.replace(/&/g, "&amp;")
		.replace(/\\/g, "&_backslash;")
		.replace(/'/g, "&apos;")
		.replace(/"/g, "&quot;")
		.replace(/\r/g, "&_curr;")
		.replace(/\n/g, "&_curn;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/,/g, "&_coma;")
		.replace(/\t/g, "&_tab;")
		.replace(/\b/g, "&_back;")
		;
}
//Обратное преобразование символов из JSON-безопасных
function JSONDecode(txt)
{
	return txt
		.replace(/&_back;/g, "\b")
		.replace(/&_tab;/g, "\t")
		.replace(/&_coma;/g, ",")
		.replace(/&gt;/g, ">")
		.replace(/&lt;/g, "<")
		.replace(/&_curn;/g, "\n")
		.replace(/&_curr;/g, "\r")
		.replace(/&quot;/g, '"')
		.replace(/&apos;/g, "'")
		.replace(/&_backslash;/g, "\\")
		.replace(/&amp;/g, "&")
		;
}
