﻿var md7_fd = new Array();
var md7_mn = '';
var md7fsls = new Array ('','cheldu4','usr29Bl');
md7fsls[101] = 'message';
md7fsls[102] = 'brief';

function md7getObj(sd) {
	return sd.indexOf(".")==-1?document.getElementById(sd):document.forms[sd.split('.')[0]].elements[sd.split('.')[1]];
}

function md7RD (ma,mdl) {
	for (i=0;i<ma.length;i++) {
		md = document.getElementById(mdl+ma[i][0]);
		if (md!=null) {
			if(ma[i][1]!=null) md.innerHTML=ma[i][1]+':';
			if(ma[i][2]!=null) md.innerHTML=md.innerHTML + '<div class="catDescr">'+ma[i][2]+'</div>';
		}
	}
}

function md7FIVWSV (iid,s) {
	v=s.options[s.selectedIndex].innerHTML;
	document.getElementById(iid).value = (v=='- выбрать -')?'':v;	
}

function md7FIVWSVP (o1,o2,s) {
	v1=s.options[s.selectedIndex].value;
    v2=s.options[s.selectedIndex].innerHTML;
	document.getElementById(o1).value = (v1=='- выбрать -')?'':v1;
    document.getElementById(o2).value = (v2=='- выбрать -')?'':v2;
}


function md7PISG (iid,s,d) {
	io=document.getElementById(iid);
	if(d) io.style.display='none';
	ic=io.parentNode; sh='<OPTION>- выбрать -</OPTION>';
	for (i=0;i<s.length;i++) sh=sh+'<OPTION '+((io.value==s[i])?'selected':'')+'>'+s[i]+'</OPTION>';
	sh='<SELECT onChange=md7FIVWSV("'+iid+'",this)>'+sh+'</SELECT>';
	ic.innerHTML=ic.innerHTML+sh;
}

function md7PISGP (n,s,d1,d2,p) {
	io1=document.getElementById(s[0]);
    io2=document.getElementById(s[1]);
	if(d1) io1.style.display='none';
	if(d2) io2.style.display='none';
	ic=(p==1)?io1.parentNode:io2.parentNode;
	sh='<OPTION>- выбрать -</OPTION>';
	for (i=2;i<s.length;i=i+2) sh=sh+'<OPTION '+((io1.value==s[i])?'selected':'')+' value="'+s[i]+'">'+s[i+1]+'</OPTION>';
	sh='<SELECT onChange=md7FIVWSVP("'+s[0]+'","'+s[1]+'",this)>'+sh+'</SELECT>';
	ic.innerHTML+= '<DIV class="ad7ext"><div class="ad7extc"><B>'+n+'</B><br/>'+sh+'</div></div>';
}


function md7PIS (iid,s) {
	md7PISG(iid,s,true);
}

function md7PIS2 (iid,s) {
	md7PISG(iid,s,false);
}

function md7PISL (iid,s) {
	ft = '<DIV class="ad7ext"><div class="ad7extc">';
	for (i=0;i<s.length;i++) ft+='<a href="javascript://" rel="nofollow" onClick=document.getElementById("'+iid+'").value=this.innerHTML>'+s[i]+'</A> | ';	
	ft = ft.substr(0,ft.length-3)+'</div></DIV>';
	document.getElementById(iid).parentNode.innerHTML += ft;	
}


function md7sortpos(a,b) {
  return a[1] - b[1];
}

function md7sortarr(arr) {
  sar = new Array;
  uar = new Array;
  for(i=0;i<arr.length;i++) if(typeof(arr[i])=='object') sar.push([arr[i][0],arr[i][1],i]); else uar.push([arr[i],null,i]);
  return sar.sort(md7sortpos).concat(uar);}


function md7fill_l(tp,nm,lst,id,sd,hb,he) {
  ov = document.getElementById(sd).value;  md7nh = '';

  lst=md7sortarr(lst);

	for(i=0;i<lst.length;i++) {
  s = ov.lastIndexOf('{'+nm+'_v'+lst[i][2]+'}')<0?'':'checked';
  md7nh+= '<INPUT onClick=md7reval(this,"'+sd+'") name="'+nm+'" value="v'+lst[i][2]+'" id="ms7'+nm+lst[i][2]+'" '+s+' type="checkbox"><label for="ms7'+nm+lst[i][2]+'">'+lst[i][0]+'</label><br/>';
	}
  md7fill_c(tp,id,sd,ov,hb,md7nh,he);
}

function md7fill_ls(tp,nm,lst,id,sd,hb,he) {
  ov = document.getElementById(sd).value;
  lst=md7sortarr(lst);
  md7nh = '<select onChange=md7revals(this,"'+sd+'") name="'+nm+'" id="ms7'+nm+'"><OPTION value="_null_">- выбрать -</OPTION>';
  for(i=0;i<lst.length;i++) {
    s = ov.lastIndexOf('{'+nm+'_v'+lst[i][2]+'}')<0?'':'selected';
    md7nh+= '<option '+s+' value="v'+lst[i][2]+'">'+lst[i][0]+'</option>';
  }
  md7nh+='</select>';
  md7fill_c(tp,id,sd,ov,hb,md7nh,he);
}

function md7fill_li(tp,nm,id,sd,hb,he) {
  ov = md7getObj(sd).value;
  v = ov.indexOf('{'+nm+'}')==-1?'':ov.replace(new RegExp('.*{'+nm+'}', "gi"),'').replace(new RegExp('{/'+nm+'}.*', "gi"),'');
  md7nh = '<input onBlur=md7revali(this,"'+md7getObj(sd).name+'") class="inp" type=text value="'+v+'" name="'+nm+'" id="ms7'+nm+'">';
  md7fill_c(tp,id,sd,ov,hb,md7nh,he);
}


function md7fill_lis(tp,nm,len,id,sd,hb,he) {
  ov = md7getObj(sd).value;
  v = ov.indexOf('{'+nm+'}')==-1?'':ov.replace(new RegExp('.*{'+nm+'}', "gi"),'').replace(new RegExp('{/'+nm+'}.*', "gi"),'');
  md7nh = '<input onBlur=md7revali(this,"'+md7getObj(sd).name+'") class="inp"  maxlength="'+len+'" type=text value="'+v+'" name="'+nm+'" id="ms7'+nm+'">';
  md7fill_c(tp,id,sd,ov,hb,md7nh,he);
}

function md7fill_c(tp,id,sd,ov,hb,md7nh,he) { //?
  if(tp=='new') document.getElementById(id).innerHTML='<INPUT  type="hidden" id="'+sd+'" value="'+ov+'" name="'+sd+'"/>';
  document.getElementById(id).innerHTML+=hb+md7nh+he;
  document.getElementById(id).style.visibility='visible';
}

function md7reval(o,f) {
 tma = '{'+o.name+'_'+o.value+'}';
 o.form[f].value = (o.checked)?(o.form[f].value+tma):o.form[f].value.replace(new RegExp(tma, "gi"),'');
}

function md7revals(o,f) {
 tma = '{'+o.name+'_'+o.value+'}';
 o.form[f].value = o.form[f].value.replace(new RegExp('{'+o.name+'_.[^}]*}', "gi"),'')+tma;
}

function md7revali(o,f) {
 tma = '{'+o.name+'}'+o.value+'{/'+o.name+'}';
 o.form[f].value = o.form[f].value.replace(new RegExp('{'+o.name+'}.*{/'+o.name+'}', "gi"),'')+tma;
}


function f_id_removeHTML(lc_in) {
  inObj  =  md7getObj(lc_in);

  lc_text = inObj.value;
  lc_text = lc_text.replace(/\n/gi, " " );
  lc_text = lc_text.replace(/<\/*[\w][^<]*>/gi,'');
  return lc_text;
}

function f_id_selfremoveHTML(lc_in) {
  md7getObj(lc_in).value =  f_id_removeHTML(lc_in);
}



