function openWindow(fileName,scroll,w,h) {
	window.open(fileName,'openWindow','scrollbars='+scroll+',width='+w+',height='+h+',location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,screenX=10,screenY=10,top=10,left=10');
	return false;
}


function openWindowWithId(fileName,id,scroll,w,h) {
	window.open(fileName,id,'scrollbars='+scroll+',width='+w+',height='+h+',location=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,screenX=10,screenY=10,top=10,left=10');
	return false;
}


function openDoctorProfile(url){
    window.open(url ,"doctor","width=400,height=450,toolbar=0,scrollbars=1");
}

function profile(id){
    window.open('/users/'+id+'.html', id, "width=440,height=450,toolbar=0,scrollbars=1");
}

function jump(obj) {
	var to = obj.options[obj.selectedIndex].value;
	if (to != '') { 
		document.location.replace(to);
	};
}


function subscribeFormSubmit(mode) {
	var subscribeForm = document.getElementById('newsSubscribeForm');
	if (mode == 0) {
		subscribeForm.action = '/news/unsubscribe';
	} else {
		subscribeForm.action = '/news/subscribe';
	}
	subscribeForm.submit();
	return false;
}

var Poll = {
    process: function(vote) {
        var poll_id = document.getElementById('poll_id').value;
        if (vote) {
            var choice_made = false;
            for (var i=1; i<10; i++) {
                var choice = document.getElementById('choice_' + i);
                if (choice && choice.checked) {
                    choice_made = i;
                }
            }
            if (!choice_made) {
                alert('Сделайте выбор, пожалуйста');
                return false;
            }
        } 
        var url = 'http://www.likar.info/services/Poll/results?poll='+poll_id;
        if (choice_made) url = url + '&choice=' + choice_made;
        openWindowWithId(url, 'poll', '1', 500, 350);
        return false;
    },
    results: function() {
        this.process(false);
    },
    submit: function() {
        this.process(true);
    }
}

function toggleConsultCheckbox() {
    var doctorButton = document.getElementById('doctorButton');
    var consultCheckBoxForm = document.getElementById('consultCheckboxForm');
    var consultCheckBox = document.getElementById('consultCheckbox');
    if (doctorButton.checked) {
        consultCheckBoxForm.style.display = '';
    } else {
        consultCheckBoxForm.style.display = 'none';
        consultCheckBox.checked = false;
    }
    toggleDoctorRegForm(consultCheckBox);
    return true;
}

function toggleDoctorRegForm(elem) {
    var doctorFields = document.getElementById('doctorFields');
    if (elem.checked) {
        doctorFields.style.display = '';
    } else {
        doctorFields.style.display = 'none';
    }
    return true;
}

function toggleChildrenForm() {
    var fields = document.getElementById('childrenFields');
    var elem = document.getElementById('haveChildren');
    if (elem.checked) {
        fields.style.display = '';
    } else {
        fields.style.display = 'none';
    }
    return true;
}
