function setCheckboxes(the_form, do_check)
{
    var elts = document.forms[the_form].elements;
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;
    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        } // end for
    } else {
        elts.checked = do_check;
    } // end if... else
    return true;
}

function ShowImage(img_file, img_width, img_height, comment) {
	var name;
	var winHead;
	var winName;
	var winString;
	var winProperties;
	winHead	= VIEW_IMAGE;
	winString  = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">';
	winString += '<title>' + winHead + '</title>';
	winString += '<link rel="stylesheet" type="text/css" href="image.css"></head>';
	winString += '<body onBlur="self.focus();"><div id="all"><div id="header">' + comment + '</div>';
	winString += '<div id="image"><img src="' + img_file + '" hspace="2" vspace="2"></div>';
	winString += '<div id="btn"><form><input type="button" value="' + CLOSE_WINDOW + '" onClick="self.close()"></form></div></div></body></html>';
	winName = "ShowImg";
	if (img_width < 150) { 
		img_width = 200; 
	} else {
		img_width += 20;
	}
	if (img_height < 150) { 
		img_height = 250; 
	} else {
		img_height += 100;
	}
	winProperties = "width=" + img_width + ",height=" + img_height;
	nameWin = window.open("",winName,winProperties);
	if(nameWin !=null) {
		nameWin.document.open();
		nameWin.document.write(winString);
		nameWin.document.close();
	}
}

function clearField(fldname, fldctrl) {
	if (confirm(CLEAR_FIELD + ' "' + fldname + '" ?')) { 
		if (document.fmDataSet.elements[fldctrl]) {
			document.fmDataSet.elements[fldctrl].value=' '; 
		}
		if (tinyMCE) {
			tinyMCE.updateContent(fldctrl); 
		}
		return 1
	} else {
		return 0
	}
}

function saveAndExit(pageName) {
	if (document.fmDataSet.addRow != undefined) { 
		if (confirm(ADD_RECORD_AND_GO_TO_THE_PAGE + ' "' + pageName + '" ?')) { 
			document.fmDataSet.addRow.click(); 
		}
	} else { 
		if (confirm(SAVE_CHANGES_AND_GO_TO_THE_PAGE + ' "' + pageName + '" ?')) { 
			document.fmDataSet.saveRows.click(); 
		}
	}	
	return 0
}

function checkLength(fld_name, maxlength) {
	if (document.fmDataSet.elements['_count_' + fld_name]) {
		lastlength = parseInt(maxlength) - document.fmDataSet.elements['_fld_' + fld_name].value.length;
		if (lastlength <= 0) {
			document.fmDataSet.elements['_fld_' + fld_name].value = document.fmDataSet.elements['_fld_' + fld_name].value.substring(0, maxlength);
			lastlength = parseInt(maxlength) - document.fmDataSet.elements['_fld_' + fld_name].value.length;
		}
		document.fmDataSet.elements['_count_' + fld_name].value = lastlength;
	}
	return 0
}

function previewImage(fld_ctrl_id, subdir) {
	if (subdir == undefined) { subdir = ''; }
	if (document.getElementById('previmg_' + fld_ctrl_id) && document.getElementById(fld_ctrl_id)) {
		if (document.getElementById(fld_ctrl_id).value) {
			document.getElementById('previmg_' + fld_ctrl_id).innerHTML = '<a href="javascript:ShowImage(\'' + files_url + subdir + document.getElementById(fld_ctrl_id).value + '\', document.images[\'previmage_' + fld_ctrl_id + '\'].width + 100, document.images[\'previmage_' + fld_ctrl_id + '\'].height + 100, \'' + document.getElementById(fld_ctrl_id).value + '\');"><img id="previmage_' + fld_ctrl_id + '" src="' + files_url + subdir + document.getElementById(fld_ctrl_id).value + '" border="0"></a>';
		} else {
			document.getElementById('previmg_' + fld_ctrl_id).innerHTML = '&nbsp;';
		}
	}
	return 0
}

function urlImage(fld_ctrl_id, subdir) {
	if (subdir == undefined) { subdir = ''; }
	if (document.getElementById('urlimg_' + fld_ctrl_id) && document.getElementById(fld_ctrl_id)) {
		if (document.getElementById(fld_ctrl_id).value) {
			fileurl = files_url + subdir + document.getElementById(fld_ctrl_id).value;
			document.getElementById('urlimg_' + fld_ctrl_id).innerHTML = '<b>' + FILE_URL + ':</b> <a href="' + fileurl + '" target=_blank>' + fileurl + '</a>';
		} else {
			document.getElementById('urlimg_' + fld_ctrl_id).innerHTML = '&nbsp;';
		}
	}
	return 0
}