var flag=0;

function change_checkbox(obj) {
	if (obj.checked)
		flag++;
	else
		flag--;
	with (document.all("but_submit")) {
		if (flag)
			disabled=false;
		else
			disabled=true;
	}
	if (document.all("Update")) {
		with (document.all("Update")) {
			if (flag)
				disabled=false;
			else
				disabled=true;
		}
	}
	if (document.all("Next")) {
		with (document.all("Next")) {
			if (!flag)
				disabled=false;
			else
				disabled=true;
		}
	}
}

function checkCity(obj) {
	if (obj.value=='zona') {
		alert('Вы должны выбрать город!');
		if (document.all("city_other").style.visibility!="visible")
			obj.value=0;
		else
			obj.value=14;
		return false;
	} else if (obj.value==14) {
		with (document.all("city_other")) {
			style.visibility="visible";
			focus();
		}
	} else {
		with (document.all("city_other")) {
			style.visibility="hidden";
			value="";	
		}
	}
	return true;
}

function actForm(tbl_name,id) {
	with (document) {
		all("table_name").value=tbl_name;
		all("id").value=id;
		fo.submit();
	}
}

function replace_string(find_string, replace_string) {
    var temp_string = this
    var left_string
    var right_string
    var start_location
    var replace_location = temp_string.indexOf(find_string)
    while (replace_location != -1) {
        left_string = temp_string.left(replace_location)
        right_string = temp_string.substring(replace_location + find_string.length)
        temp_string = left_string + replace_string + right_string
        start_location = replace_location + replace_string.length
        replace_location = temp_string.indexOf(find_string, start_location)
    }
    return temp_string   
}

function extract_left(total_chars) {
    return this.substring(0, total_chars)
}

String.prototype.left = extract_left
String.prototype.replace = replace_string


function reset_checkbox() {
	flag=0;
	document.all("Submit").disabled=true;
}

function select_all(form_name,f_name) {
	document.all("Submit").disabled=false;
	var el=document.forms[form_name].elements[f_name];
	for (i=0;i<el.length;i++) {
		el[i].checked=true;
		flag++;
	}
}

function setMonthYear() {
	document.forms[0].submit();
}

function confirm_del(obj) {
	if (flag>0)
		return confirm("Вы действительно хотите удалить выбранные записи?");
	else
		return false;
}
