// Client side scripts 21.04.2006 08:04:00
function init(){
 with (document) {
   cookie="width="+"; expires=Thu, 01-Jan-1970 00:00:01 GMT";
   cookie = "width="+body.offsetWidth;
//   session = '/session.php?src=img&width='+body.offsetWidth;
//   if (session) getElementById("session").src = session // set new vars for session
   if (getElementById("text_news")) getElementById("text_news").cols = body.offsetWidth/13;
   if (getElementById("title_news")) getElementById("title_news").size = body.offsetWidth/10;

   if (getElementById("headers")) getElementById("headers").cols = body.offsetWidth/11.5;

   if (getElementById("text")) getElementById("text").cols = body.offsetWidth/12.1;
   if (getElementById("title")) getElementById("title").size = body.offsetWidth/8.7;

   if (getElementById("descr")) getElementById("descr").size = body.offsetWidth/15;
   if (getElementById("name")) getElementById("name").size = body.offsetWidth/16;
   if (getElementById("file")) getElementById("file").size = body.offsetWidth/12.8;
 }
}
function PreviewText(text) {
   preview.innerHTML = "<p>Предварительный просмотр:</p><hr>"+text;
}
function get_obj(obj_name,parentobj,in_parent_only,deep){
 var obj;
 if (!deep) deep=0;
 if (!obj_name) return "";
 var sspa="";
 if (typeof(obj_name)=="string") {
  if (typeof(parentobj)=="object" && parentobj) {
   sspa = "parentobj="+parentobj+" id="+parentobj.id+" tag="+parentobj.tagName;
   if (!parentobj.childNodes) return "";//in_parent_only?"":document.getElementById(obj);
   for (var i=0;i<parentobj.childNodes.length;i++) {
     if (parentobj.childNodes[i].id==obj_name.toString()) {
      obj = parentobj.childNodes[i];
      break;
     }
     else {
      obj = get_obj(obj_name,parentobj.childNodes[i],in_parent_only,deep++);
      if (obj && obj.id==obj_name) return obj;
     }
   }
//   return false;
  } else obj = document.getElementById(obj_name);
//    if (typeof(obj)!="object") obj = document.getElementById(obj);
 
 } else obj=obj_name;

//  if (typeof(obj)=="object") alert (deep+" "+obj_name+": "+obj+" id="+obj.id+" tag=" +obj.tagName + " parentonly? "+in_parent_only+"\n"+sspa);
 
// if (typeof(obj)=="string") return in_parent_only?"":document.getElementById(obj);
 return obj;
}

function switcher (obj,parentobj,somevalue,replacevalue,nofocus) {
 obj = get_obj(obj,parentobj);
 if (obj == null) return;
 if (typeof(obj)=="object" && !obj.disabled)
  with (obj) {
   if (typeof(checked)=="boolean") checked=type=="radio"?true:!checked;
   if (nofocus==null) focus();
   if ((somevalue!=null && replacevalue) || (somevalue!=null && !value)) value = somevalue;
   else value = value;
  }
}
function Replace(Where,from,to) {
   ReWhere = Where.split(from)
   return ReWhere.join(to);
}
function t2s() {
   var he = arguments[0];
   var sh = arguments[1];
   for(var i=2;i<arguments.length;i++)
   document.write(arguments[i]?String.fromCharCode(sh+parseInt(arguments[i],he?16:10)):"");
}
function OnLoadDoc() {
 //  alert(document.body.clientWidth+" "+document.cookie );
   init();
}
function OnResizeDoc() {
   init();
//alert (document.getElementById("session").src);
}
function isTrue(value){
 if (value == "on" || value == "вкл" || value == "yes") return true;
 return false;
}
function trToEn(text) {
   text = text.toLowerCase();
   var transilt_table = {
   "1072":"a","1073":"b","1074":"v","1075":"g","1076":"d","1077":"e","1078":"zh","1079":"z","1080":"i",
   "1081":"y","1082":"k","1083":"l","1084":"m","1085":"n","1086":"o","1087":"p","1088":"r","1089":"s",
   "1090":"t","1091":"u","1092":"f","1093":"h","1094":"ts","1095":"ch","1096":"sh","1097":"sch","1098":"",
   "1099":"y","1100":"","1101":"e","1102":"yu","1103":"ya","1105":"ye"
  };
   for (i in transilt_table) text = text.replace(new RegExp(String.fromCharCode(i),"g"),transilt_table[i]);
   return text;
}
var src_max = "/src/maximized.gif";
var src_min = "/src/minimized.gif";
var show_hide_text="Show/Hide";
var show_hide_help_text="Show/Hide help";

function show_hide (obj_id,show,parentobj) {
 var shimg=document.getElementById('shicon_'+obj_id);
 var obj = get_obj(obj_id,parentobj)
 if (obj)
  with(obj) {
   if (!style.display && !show) {
    style.display = 'none';
    if (shimg) shimg.src=src_max;
    return false;
   } else {
    if (shimg) shimg.src=src_min;
    style.display='';
    return true;
   }
  }
}
function show_hide_icon(obj_id,hided,help,locationhr) {
 if (!locationhr) locationhr=help;
 document.write('<div style="float: right;cursor:pointer">'+
   (help?'<a style="cursor:help" onClick="show_hide(\''+obj_id+'\',1);if (show_hide(\''+help+'\') && \''+locationhr+'\'!=\'#\') window.location.href=\'#'+locationhr+'\';" '+
      'title="'+show_hide_help_text+'"><b>?</b></a>&nbsp;':'')+
   '<img id="shicon_'+obj_id+'" '+
   ' onClick="show_hide(\''+obj_id+'\');" border="0"></div>');
   with(document.getElementById('shicon_'+obj_id)) {
     title = show_hide_text;
     src = hided?src_max:src_min;
   }
}
function tdChL(td_obj){ // change location by click on td
   if (td_obj.childNodes[0].href) location.href=td_obj.childNodes[0].href;
}

function enabled_disabled(switcher,objects,parentobj,checked_disabled) {
 if (!parentobj) parentobj = this.parentNode;
 switcher = get_obj(switcher,parentobj);
// alert (switcher.tagName+" "+switcher.id+" "+objects +" "+typeof(objects));
 if (typeof(objects) == "string") objects = new Array(objects);
 for (i=0;i<objects.length;i++){
  objects[i] = get_obj(objects[i],parentobj);
//  alert (objects[i].tagName+" "+objects[i].id+" "+switcher.checked+" "+checked_disabled);
  if (switcher.checked) {
   objects[i].disabled = checked_disabled;
  } else { 
   objects[i].disabled = !checked_disabled;
  }
 }
 return switcher.checked;
}

function transferHTML(srcFrame,outerDisplay) {
 var srcContent = (srcFrame.contentDocument) ?
 srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML :
 (srcFrame.contentWindow) ?
 srcFrame.contentWindow.document.body.innerHTML : ""
 if (typeof(outerDisplay)=="string")  outerDisplay = document.getElementById(outerDisplay);
 if (srcContent) { 
   outerDisplay.innerHTML = srcContent;
 }
}
function loadOuter(doc,srcFrame) {
 if (typeof(srcFrame)=="string") 
  srcFrame = document.getElementById(srcFrame);
 srcFrame.src = doc;
 if (!srcFrame.onload) {
  setTimeout("transferHTML(srcFrame,'sending')", 1000);
 }
}
function check_mails() {
  for (var arg=0;arg<arguments.length;arg++) {
    var str = ""+arguments[arg].value;
    if (!str.match(/[\w.\d-_]+\@[\w\d-_]+\.[\w.\d-_]+/)) {
    	alert ("Неверный адрес электронной почты - \"" + str + "\"");
	arguments[arg].select();
     arguments[arg].focus();
	return false;
   }
  }
 return true;
}

function cl_sp(text) {
   return text.replace(/\s+[\r\n]+/g,"\n");
}
