

function change_image_val(id1,id2){
	if(!document.getElementById(id2).value)
	document.getElementById(id1).src="/images/1x1.gif";
	else
	document.getElementById(id1).src="/"+document.getElementById(id2).value;
}

function change_bg(id1,color){
	document.getElementById(id1).style.background=color;
}

// Функции даты ******************
function date_now(){//текущая дата
	var dt	= new Date();
	dt.getDate();
	year	= dt.getFullYear();
	month	= dt.getMonth()+1;
	day		= dt.getDate();
	str_month=month<10?"0"+month:month;
	return year+'-'+str_month+'-'+day;
}

function date_Plus(date,month){//добавление месяцев к дате
	date1	= date.split("-");
	day1	= parseInt(date1[2],10);
	month1	= parseInt(date1[1],10);
	year1	= parseInt(date1[0],10);

	month1 = month1+month;
	while (month1>12){
		month1=month1-12;
		year1++;
	}
	str_month=month1<10?"0"+month1:month1;
	return year1+'-'+str_month+'-'+day1;
}

function date_Comparison(date01,pr,date02){//сравнени дат
	date1	= date01.split("-");
	day1	= parseInt(date1[2],10);
	month1	= parseInt(date1[1],10);
	year1	= parseInt(date1[0],10);

	date2	= date02.split("-");
	day2	= parseInt(date2[2],10);
	month2	= parseInt(date2[1],10);
	year2	= parseInt(date2[0],10);

	znak = pr.split("");
	result=false;
	if(date01==date02 && znak[1]=='=')result=true;
	else if(znak[0]=='>'){
		if(year1>year2)	result=true;
		else if(month1>month2 && year1==year2)	result=true;
		else if(day1>day2 && month1==month2)	result=true;
	}else{
		if(year1<year2)	result=true;
		else if(month1<month2 && year1==year2)	result=true;
		else if(day1<day2 && month1==month2)	result=true;
	}
//	return date01+" "+pr+" "+date02+" = "+result;
	return result;
}





function emo_pop1(url,w,h)
{
if(!w)w=400;
if(!h)h=580;
  window.open(url,'ipvisits','width='+w+',height='+h+',resizable=no ,scrollbars=yes');
}

// Блокировка на ввод символов кроме цыфр , -
function EnsureNumeric(){
var k = window.event.keyCode; 
	if (k==45)
		window.event.keyCode=46;

	if ((k < 48 || k > 57) && k!=46)
		window.event.returnValue = false; 
}

// все кроме русских букв
function NoRussian(){
var k = window.event.keyCode; 

	if (k > 192)
		window.event.returnValue = false; 
}


function insert(url) {
	var count=window.prompt('Введите количество элементов для добавления (1-50):', 5);
	if (count && count>0) {
		if (count>50){	count=50;	}
		fast_insert.href=url+'&count='+count;
		fast_insert.click();
	}
}

function del_one(url,n) {
	if (confirm("Удалить запись #"+n+"?")) {
		fast_insert.href=url;
		fast_insert.click();
	}
}


function show_hide_id(id,array){
	if(document.getElementById(id).style.display==""){
		document.getElementById(id).style.display="none";
	}else{
		document.getElementById(id).style.display = "";	
	}
}

function treeSimb(id){
	if(document.getElementById(id).style.display==""){
		document.getElementById(id+"Yes").style.display="none";
		document.getElementById(id+"No").style.display="";
//-
	}else{
//+
		document.getElementById(id+"Yes").style.display="";
		document.getElementById(id+"No").style.display="none";
	}
}



function show_hide_id_array(id,array){
	tt=new Array();
	tt = array.split(",");
	aa = tt.length;
	for (var i = 0; i < aa; i++){
		if(document.getElementById(id+"["+tt[i]+"]").style.display==""){
			document.getElementById(id+"["+tt[i]+"]").style.display="none";
		}else{
			document.getElementById(id+"["+tt[i]+"]").style.display = "";	
		}
	}	

}


function do_once(id,id2)
{
	if(document.getElementById(id2).style.display==""){
		document.getElementById(id2).style.display="none";
		document.getElementById(id2).disabled = "false";
		document.getElementById(id).style.display = "";
	}else{
		document.getElementById(id2).style.display = "";	
		document.getElementById(id2).disabled = "true";
		document.getElementById(id).style.display = "none";
	}
}




function Check_Form_One(fobj,El,Txt,mail){
	if (fobj.elements[El]) {
		if(mail)
			res = isNotEmail(fobj.elements[El].value);
		else
			res = isEmpty(fobj.elements[El].value);
	}
	if (res) {
		err=res.replace('%d', Txt);
		alert(err);
		fobj.elements[El].focus();
		return false;
	}
	return true;
}

// на пустоту (! '' или '   ')
function isEmpty(text) {
  var msg = "Поле \"%d\". Должно быть заполнено;\n";
  text = "" + text;
  for (var i=0; i < text.length; i++) {
    if (text.substring(i, i+1) != " ") {return false} 
  }
  return msg;
}

// Проверка на E-mail (@ в строке и . после @ и более 2 символов после .)
function isNotEmail(text) {
	var msg = "Поле \"%d\". Должно иметь формат адреса эл. почты (user@domain.ru)";
  if(isEmpty(text)) return isEmpty(text);
  var pos_amp= text.indexOf("@");
  var pos_point= text.lastIndexOf(".");
  if (pos_amp == -1) return msg; 
  if (pos_point < pos_amp) return msg;
  if (2 > (text.length - pos_point)) return msg; 
  return false;
}

 function CheckMulti(multiname,count,contextid){
 var str="",a='',v="",nn="";
for (i = 0; i < count ; i++){
	ell=multiname+'['+i+']';
	a=document.getElementById(ell).selected;
	if(a==true){
		v=document.getElementById(ell).text;
		str+=nn+v;
		nn=", ";
	}
}

ell=contextid;
document.getElementById(ell).value=str;
//document.getElementById(contextid).innerHTML=(str);
}

// cb_lst(this.form, 'ehide', '1,25')
function cb_lst(fm, name, idstr) {
  var ids=idstr.split(','); 
	if (!ids[0] || !fm.elements[name+'['+ids[0]+']']) {return} 
	var status=(fm.elements[name+'['+ids[0]+']'].checked ? 0 : 1); 
	for(var i=0; i<ids.length; i++) {fm.elements[name+'['+ids[i]+']'].checked=status;} 
}
