var on_print= new Array();

function OnDelete(id, title, goto, params)
{
	if (!confirm("Удалить '"+title+"'?"))
		return false;

	var href = "?id="+id
	
	if (params)
		href += "&" + params;
		
	window.location.href = goto+href;
	return false;
}

function OpenPopUp(url, width, height)
{
	ClosePopup();
	
	wndPopup = window.open(url, "_blank", "height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
}

function set_towns(towns)
{
  var  country_id= document.getElementById('country_id').value;
  var str = '';
  var s = "";
  document.getElementById('div_town_id').innerHTML ='';
  str = '<select name="town_id" id="town_id" onChange="set_raions(raions)"; ' + form_class + ' >'+
	  '<option value="-1"> - Город не выбран - </option>';
  for (var i = 0; i < towns.length; i++) {
     if (default_town == towns[i][1]) s = " selected "; else s="";
     if (towns[i][0] == country_id) 
        str = str + '<option value ="'+towns[i][1]+'" '+s+' > '+towns[i][2]+ '</option>';
   }
    str=str+"</select>";	
  document.getElementById('div_town_id').innerHTML = str;
   }
   
function set_raions(raions)
{
  var  town_id= document.getElementById('town_id').value;
  var str = '';
  var s = "";
  document.getElementById('div_raion_id').innerHTML ='';
  str = '<select name="raion_id" id="raion_id" ' + form_class + ' >'+
	  '<option value="-1"> - Район не выбран - </option>';
  for (var i = 0; i < raions.length; i++) {
     if (default_raion == raions[i][1]) s = " selected "; else s="";
     if (raions[i][0] == town_id) 
        str = str + '<option value ="'+raions[i][1]+'" '+s+' > '+raions[i][2]+ '</option>';
   }
    str=str+"</select>";	
  document.getElementById('div_raion_id').innerHTML = str;
   }   
   

function OnClickPrint(id){
  if (document.getElementById('id'+id).checked)
    on_print[id]=document.getElementById('id'+id).value;
  else  
    on_print[id]="";
}


function makePrint($path){
  str="";
  count=0;
  for (var i = 0; i < on_print.length; i++) {
   
   if (on_print[i]!="") {
 	if (str!="") str="&"+str;
	str="id"+count+"="+on_print[i]+str;
      count++;
   }
   
  
}
if (str!="")
 OpenPopUp($path+"?"+str, 700, 500)

}


function onChange_textarea(name){
str = new String;
str = document.getElementById(name).value;
len=0;
if (str != null) 
   len = str.length;

correct=0;
for (i=0; i<len; i++ ) {
	
 if (str.charAt(i)=="'") correct = correct+6;
 if (str.charAt(i)=='"') correct = correct+5;
 if (str.charAt(i)=="<") correct = correct+3;
 if (str.charAt(i)==">") correct = correct+3;
}
len=len+correct;

max_len =  document.getElementById(name+'_max').value;
if (len==0) {
  if (max_len==0)
     text = 'Пустое текстовое поле.';
  else
     text = 'Максимум '+max_len+' символов.';
} else {
  if (max_len==0)
     text = 'Введено символов: '+len;
  else {
     text = 'Введено '+len+' символов из '+max_len+' возможных.';
	if (len>=max_len) text = "<font color=#ff3333>Внимание! "+text+"</font>"; 
  }
  

}

document.getElementById(name+'_kol').innerHTML =text;
}



function update_price(name) {

s = document.getElementById(name).value;
res="";
for (i=0; i<s.length; i++ ) {
   if (s.charAt(i)=="0") continue;
   if (s.charAt(i)=="1") continue;
   if (s.charAt(i)=="2") continue;
   if (s.charAt(i)=="3") continue;
   if (s.charAt(i)=="4") continue;
   if (s.charAt(i)=="5") continue;
   if (s.charAt(i)=="6") continue;
   if (s.charAt(i)=="7") continue;
   if (s.charAt(i)=="8") continue;
   if (s.charAt(i)=="9") continue;
   err_stat_price='"'+s.charAt(i)+'"';
   if (s.charAt(i)==" ")
     err_stat_price="пробелы";
     
   document.getElementById(name+'_price').innerHTML = "(Ошибка: уберите "+err_stat_price+" )"; 
   return;
}
if (s.length<=3) 
   res=s;
else {
   s = "     "+s;
   for (i=s.length-3; i>=0; i=i-3) 
      res=s.substr(i,3)+" "+res;
    }
if (res!="")
  res="( Цена: "+res+" )";
  
document.getElementById(name+'_price').innerHTML = res;  
}

function update_squire(name) {

s = document.getElementById(name).value;
res="";
if (s!="") 
   res=s/100;
if (res!="")
  res="( "+res+" соток )";
  
document.getElementById(name+'_squire').innerHTML = res;  
}



function screenWidth(){
var swidth=0; 
var sheight=0; 
if (self.screen) {  
  swidth = screen.width; 
  sheight = screen.height 
  }
return  swidth;
}


function screenHeight(){
var swidth=0; 
var sheight=0; 
if (self.screen) {  
  swidth = screen.width; 
  sheight = screen.height 
  }
return  sheight;
}

//-------------------------------------------------

function Toggle(oImg)
{
	var oChildNodes = oImg.parentNode.childNodes;
	for (var i = 0; i < oChildNodes.length; i++)
	{
		var oNode = oChildNodes[i];			
		if (oNode.className == 'children-hide')
		{
			oNode.className = 'children';
			oImg.className = 'c';
			oImg.src = "/i/c.gif";
			break;
		}
		else if (oNode.className == 'children')
		{
			oNode.className = 'children-hide';
			oImg.className = 'e';
			oImg.src = "/i/e.gif";
			break;
		}
	}

	return false;
}



function OnMoveUp(id)
{
	window.location.href = "?up="+id;
	return false;
}

function OnMoveDown(id)
{
	window.location.href = "?down="+id;
	return false;
}

function GoTo(url)
{
	window.location.href = url;
}

var wndPopup = null;

function ClosePopup()
{
	if (wndPopup && !wndPopup.closed)
		wndPopup.close();
}

