var ie = 0;
var ie6 = 0;
//== Edit Html ==========================
var iWin;
var iDoc;
var iBODY;
//============================
function ResetAll(o_frm) {
  var num = o_frm.elements.length;
  var i,tt;
  for (i = 0; i < num; i++) {
    tt = o_frm.elements[i].type;
    if (tt == 'text' || tt == 'hidden') {o_frm.elements[i].value = '';}
    else if (tt == 'select-one') {o_frm.elements[i].selectedIndex = 0;}
    else if (tt == 'checkbox') {o_frm.elements[i].checked = false;}
  }
  return false;
}
//============================
function InitIFrame () {
	document.write("<iframe frameborder='no' src='#' id='frameId' name='frameId'></iframe><br/>");
	var isGecko = navigator.userAgent.toLowerCase().indexOf("gecko") != -1;
	var iframe = (isGecko) ? document.getElementById("frameId") : frames["frameId"];
	iWin = (isGecko) ? iframe.contentWindow : iframe.window;
	iDoc = (isGecko) ? iframe.contentDocument : iframe.document;

	if (!iDoc.designMode) alert("Визуальный режим редактирования не поддерживается Вашим браузером");
	else iDoc.designMode = (isGecko) ? "on" : "On";

	var str = document.getElementById('edit_html_old_val').innerHTML;
	if (!str || str == '<P></P>') {str = '<P>&nbsp;</P>';}

	var iHTML = "<html>\n<head>\n" + '<link href="/articles/articles.css" rel="stylesheet" type="text/css">';
	iHTML += '<body style="padding: 10px">' + "\n" + str + "\n</body>\n";
	iHTML += "</html>";

	iDoc.open();
	iDoc.write(iHTML);
	iDoc.close();

	iBODY = iDoc.getElementsByTagName('BODY')[0];
  if (ie) document.getElementById("frameId").focus();
}
//--------------------------
function Prepare2DB(o_frm,input_name) {
  if (!o_frm[input_name] || !iBODY) {return true;}
  o_frm[input_name].value = iBODY.innerHTML;
  return true;
}
//--------------------------------------------------------------------------
function ExCom(command,param) {
	if (!param) {param = ""};
	iWin.focus();
	iDoc.execCommand(command, null, param);
}
//--------------------------------------------------------------------------
function SetForeColor(color) {
	if (color) {ExCom("ForeColor", color)}
	CloseBlock('fore_color');
}
//---------------
function OpenCloseBlock(block) {
	var obj = document.getElementById(block);
  obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
}
//---------------
function CloseBlock(block) {
	document.getElementById(block).style.display = 'none';
}
//---------------
function SetBlockFormat(format) {
  if (format) {ExCom('formatblock','<' + format + '>');}
	CloseBlock('block_format');
}
//---------------
function OpenDivBlockFormat() {
  var bf = "";
  var frm = document.getElementById('block_format');
  var o_select = $('#block_format select')[0]
  o_select.selectedIndex = 0;
  for (var i = 0; i < o_select.length; i++) {
    bf = SelectParentElement(o_select.options[i].value);
  	if (bf) {o_select.selectedIndex = i;}
  }
  frm.style.display = (frm.style.display == 'block') ? 'none' : 'block';
  o_select.focus();
}
//---------------
function CloseDivBlockFormat() {
	var frm = document.getElementById('block_format');
  frm.style.display = 'none';
}
//---------------
function SelectParentElement(pElement) {
  if (ie) document.getElementById("frameId").focus();
  if (document.selection) obj = document.selection.createRange();
  else if (document.getSelection) obj = document.getSelection();
  else if (window.getSelection) obj = window.getSelection();

  if (!obj) {return false;}
  obj = obj.parentElement();

  while (obj.tagName != pElement) {
  	obj = obj.parentNode;
  	if (!obj) {return false;}
  }
  return obj;
}
//---------------
function Show_HTML() {
  alert(iBODY.innerHTML);
}
//---------------
function DeleteJustify() {
  iWin.focus();
  var obj = iDoc.selection.createRange().parentElement();
  while (obj && obj.tagName != "BODY") {
	  if (obj.getAttribute("align") != null) {
		  obj.removeAttribute("align");
		}
		obj = obj.parentNode;
  }
}
//== end of Edit Html ==========================
//--------------------------
function SetCookieSimple(c_name,c_val) {
  document.cookie = "cookie[" + c_name + "]=" + c_val + "; expires=" + CalcTime(30) + '; path=/';
}
//===============
function SetCookieSelect(c_name,o_sel) {
  SetCookieSimple(c_name,o_sel.value);
  location.reload();
}
//===============
function CalcTime(days) {
	var plusDays = days*24*60*60*1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + plusDays);
	return expDate.toGMTString();
}
//---------------
function _mouseover(node,ch) {
  node.className="over "+ ch;
}
//---------------
function _mouseout(node) {
  node.className="";
}
//---------------
//----------------------------------------------------------------------------
function vkl(node) {
  node.className="over ";
  if (!ie6) {return};
  arr_ul = node.getElementsByTagName("UL");
  if (arr_ul.length == 0) {return};
  arr_sel = document.getElementById("content_in").getElementsByTagName("SELECT");
  for (i = 0; i < arr_sel.length; i++) {
  	if (absPosition(arr_ul[0]).y + arr_ul[0].offsetHeight < absPosition(arr_sel[i]).y) {return;}
    arr_sel[i].style.visibility = 'hidden';
  }
}
//----------------------------------------------------------------------------
function vykl(node) {
  node.className="";
  if (!ie6) {return};
  arr_sel = document.getElementById("content_in").getElementsByTagName("SELECT");
  for (i = 0; i < arr_sel.length; i++) {
    arr_sel[i].style.visibility = 'visible';
  }
}
//----------------------------------------------------------------------------
var o;
var o_color = 'red';
var counter = 1;
var o_frm_now;
//----------------------------------------------------------------------------
function CheckRequared(o_frm,vars) {
  for (var k in vars) {
    if (o_frm[vars[k]].value && o_frm[vars[k]].value != '0') {continue;}
    o = o_frm[vars[k]];
    counter = 1;
    o_color = 'red';
    o.value = ' Введите данные';
    o.focus();
    setTimeout("ChangeBg()",10);
    return false;
  }
  if (o_frm.submit) {o_frm_now = o_frm;setTimeout("o_frm_now.submit.disabled = true;",300);}
  return true;
}
//----------------------------------------------------------------------------
function ChangeBg() {
  counter++;
  if (counter > 8) {o.value = '';return;}
  o_color = (o_color == 'red') ? 'white' : 'red';
  o.style.background = o_color;
  setTimeout("ChangeBg()",300)
}
//----------------------------------------------------------------------------

