// ajax
function setChilds(id){
  elem = document.getElementById("check_"+id);
  res = elem.checked;
  
  JsHttpRequest.query('/ajax/getchilds.php',{id:id,res:true}, 
	function(result, errors) {_setChilds(result);}, true); 
}
function _setChilds(result){
	if (!result)
		return false;
  elem = document.getElementById("check_"+result['id']);
  if (elem && result['count'] > 0){  
    res = elem.checked;     
    for( i = 0; i < result['count']; i++ ){
      elem = document.getElementById("check_"+result['arr'][i]);
      if (elem){
        elem.disabled = res;
        elem.checked = res;
      }  
    }          
  }    
  cnt = document.fCalc.elements.length;
  idArr = new Array;
  p = 0;
  for( i=0; i<cnt; i++){
    el = document.fCalc.elements[i];
    if (el.type == "checkbox")
      if (el.disabled == false && el.checked == true){
        idArr[p] = el.id;
        p++;
      }    
  }
  JsHttpRequest.query('/ajax/getsum.php',{arr:idArr}, 
	function(result, errors) {_setSum(result);}, true); 
}

function _setSum(result){
	if (!result)
		return false;
  elem = document.getElementById("sum");
  elem.value = result;
}  
// end ajax

function setFavorities($url,$title){
	window.external.addFavorite($url, $title); 
  return false; 
}
function popImage(img, title) {
 picfile = new Image();
 picfile.src = (img);
 fileCheck(img, title);
}

function fileCheck(img, title) {
 if( (picfile.width!=0) && (picfile.height!=0) ) {
 makeWindow(img, title);
 } else {
 funzione="fileCheck('"+img+"')";
 intervallo=setTimeout(funzione, 50);
 }
}

function makeWindow(img, title) {
 wd = picfile.width;
 ht = picfile.height;

 var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
 var args = "resizable=yes";
 if (window.screen) {
 var avwd = screen.availWidth;
 var avht = screen.availHeight;

 if (avwd < wd || avht < ht) { args += ",scrollbars=yes"; }

 var xcen = (avwd > wd) ? (avwd - wd) / 2 : 0;
 var ycen = (avht > ht) ? (avht - ht) / 2 : 0;
 args += ",left=" + xcen + ",screenX=" + xcen;
 args += ",top=" + ycen + ",screenY=" + ycen;

 if (avwd < wd) {
 wd = avwd;
 if (isIE) wd -= 12;
 }
 if (avht < ht) {
 ht = avht;
 if (isIE) ht -= 32;
 }
 }
 args += ",width=" + wd + ",innerWidth=" + wd;
 args += ",height=" + ht + ",innerHeight=" + ht;

 popwin = window.open(img, 'fullSize', args);
 popwin.document.open();
 popwin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
 popwin.document.write('<html>');
 popwin.document.write('<head>');
 popwin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
 popwin.document.write('<title>'+title+'</title>');
 popwin.document.write('</head>');
 popwin.document.write('<body style="margin:0px"><a href="javascript:window.close()"><img src="'+img+'" border="0" alt="'+title+'"/></a></body>');
 popwin.document.write('</html>');
 popwin.document.close();
}
