function getListCheckBoxes(form){
	var allCheckBoxes = new Array();
	var usersForm = form.elements;
	for (var i = 0; i < usersForm.length; i++){
		if ((usersForm[i].type == 'checkbox') && (usersForm[i].name.indexOf("d_m") == 0)){
			allCheckBoxes[allCheckBoxes.length] = new Array(usersForm[i].name, usersForm[i].checked);
		}
	}
	return allCheckBoxes;
}

function toggleAllCheckboxes(checkbox){
	var checked = checkbox.checked;
	var checkBoxes = getListCheckBoxes(checkbox.form);
	for (var i = 0; i < checkBoxes.length; i++){
		checkbox.form.elements[checkBoxes[i][0]].checked = checked;
	}
	checkbox.form.checkall.checked = checked;
	checkbox.form.checkall1.checked = checked;
}

function isAllChecked(form){
	var checkBoxes = getListCheckBoxes(form);
	for (var i = 0; i < checkBoxes.length; i++){
		if (!checkBoxes[i][1]) return false;
	}
	return true;
}

function toggleCheckbox(checkbox){
	if (!checkbox.checked)
	{
		checkbox.form.checkall.checked = false;
		checkbox.form.checkall1.checked = false;
	}
	if (checkbox.checked && isAllChecked(checkbox.form))
	{
		checkbox.form.checkall.checked = true;
		checkbox.form.checkall1.checked = true;
	}
}

var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function validateDate(form, daySel, monthSel, yearSel)
{
	//alert("Validate!!!");
	var daySel 	 = form.elements[daySel];
	var monthSel = form.elements[monthSel];
	var yearSel	 = form.elements[yearSel];
	//alert("Selected month number is " + monthSel.value);
	if (monthSel.value == '') return;
	//alert(monthDays[monthSel.value-1] + " days in current month");
	if (monthDays[monthSel.value-1] != 31)
	{
		var days = 30;
		if (monthSel.value == 2)
		{
			days = 28;
			if ((yearSel.value != '') && (yearSel.value % 4 == 0)) days = 29;
		}
		//alert("Should in pull-down-list " + days + " days");
		if (daySel.options.length > days + 1)
		{
			//alert("There are " + (daySel.options.length - days - 1) + " odd days in pull-down-list");
			for (i = daySel.options.length - days - 1; i > 0; i--)
			{
				//alert("Deleting " + (daySel.options.length - 1) + " day");
				daySel.options.remove(daySel.options.length - 1);
			}
		}
		if (daySel.options.length < days + 1)
		{
			//alert("It's missed " + (days + 1 - daySel.options.length) + " days in pull-down-list");
			for (i = daySel.options.length; i < days + 1; i++)
			{
				//alert("Adding " + i + " day");
				var oOption = document.createElement("OPTION");
				daySel.options.add(oOption);
				oOption.text = i;
				oOption.Value = i;
			}
		}
	}
	else
	{
		if (daySel.options.length < 32)
		{
			//alert("It's missed " + (31 + 1 - daySel.options.length) + " days in pull-down-list");
			for (i = daySel.options.length; i < 32; i++)
			{
				//alert("Adding " + i + " day");
				var oOption = document.createElement("OPTION");
				daySel.options.add(oOption);
				oOption.text = i;
				oOption.Value = i;
			}
		}
	}
}
function setzen(select, target, validation){
	var text = select.options[select.selectedIndex].text;
	var alt_add= select.form.elements[target].value;
	if(select.value){
		if(alt_add){
			var addr=", " + text;
		} else {
			var addr= text;
		}
		select.form.elements[target].value += addr;
		if (validation)
			checkAddresses(select.form.elements[target]);
	}
}
function checkAddresses(target)
{
	//alert(warnMsg);
	var addr_val= target.value;
	addr_val= addr_val.replace(/;/gi, ',');
	target.value = addr_val;
	if(addr_val){
		var addr = addr_val.split(',');
		if (addr.length <= 50)
		{
			return true;
		} else {
			addr = addr.slice(0, 50);
			addr_val= addr.join(',');
			target.value = addr_val;
			alert(warnMsg);
		}
	}
	return true;
}
function checkFileSelect(form)
{
	var result = false;
	for (i = 0; i < 10; i++)
	{
		if (form.elements["datei["+i+"]"].value != "")
		{
			result = true;
		}
		form.elements["cfile["+i+"]"].value = form.elements["datei["+i+"]"].value;
	}
	if (!result) return false;
	//alert("old="+form.cfile.value+"\nnew="+form.datei.value);
	return true;
}

function openAttachWindow(sid)
{
    var h = 430;
	var sAgent = navigator.userAgent.toLowerCase() ;
	var aMatch = sAgent.match( / opera (\d+\.\d+)/ ) ;
	var aMatch1 = sAgent.match( / netscape\/(\d+\.\d+)/ ) ;
	if ( aMatch || aMatch1) h = 475;
    var w = 710;
    var t = (window.screen.height - h) / 2;
    var l = (window.screen.width - w) / 2;
	window.open("addfiles.php?sid="+sid, "addFilesWindow", "channelmode=no,directories=no,fullscreen=no,height="+h+",width="+w+",top="+t+",left="+l+",location=no,menubar=no,resizable=no,status=yes,titlebar=yes,toolbar=yes");
}
function openWindow(type, sid)
{
    var h = 350;
	var sAgent = navigator.userAgent.toLowerCase() ;
	var aMatch = sAgent.match( / opera (\d+\.\d+)/ ) ;
	var aMatch1 = sAgent.match( / netscape\/(\d+\.\d+)/ ) ;
	if ( aMatch || aMatch1) h = 395;
    var w = 710;
    var t = (window.screen.height - h) / 2;
    var l = (window.screen.width - w) / 2;
    var name = "";
    var url = "";
    if (sid) sid = "?sid=" + sid;
    else sid = "";
    switch (type)
    {
    	case "cm":
    		url = "comments.php" + sid;
			name = "comments";
			break;
    	case "ad":
    		url = "advert.php" + sid;
			name = "advert";
			break;
    	case "li":
    		url = "lawinfo.php" + sid;
			name = "lawinfo";
			break;
    	case "cn":
    	default:
    		url = "contactus.php" + sid;
			name = "contactus";
			break;
    }
	window.open(url, name, "channelmode=no,directories=no,fullscreen=no,height="+h+",width="+w+",top="+t+",left="+l+",location=no,menubar=no,resizable=no,status=yes,titlebar=yes,toolbar=no");
}
