var ch = 0;
var checks = 1;
var checkboxes = new Array;


function initCB() {
	ch = 0;
	checks = 1;
	checkboxes = new Array;
}

function getAddForm(url) {
	if ($('#addlayer').length == 0) {
		var d = $('<div id="addlayer"></div>');
		$('body').append(d);
	} else {
		d = $('#addlayer');
	}

	getviewpoint();

	elemBlur();

//	url = '/add.php?feed=' + encodeURI(url);
	url = '/add.php?feed=' + encodeURIComponent(url);

	$.ajax({
	type: "GET",
	url: url,
	success: function(html){
	        d.html("");
	        d.append(html);

		if ($('#saverssform')) {
			initCB();
			$('#saverssform :checkbox[class="catCheckbox"]').each(function (i) {
				$(this).css({visibility:'hidden'});
			});

		}
		var dw = d.width();
		var dh = d.height();
		var dtop = (dh >= docheight)? '0px' : (docheight/2 - dh/2)+'px';
		var dleft = (dw >= docwidth)? '0px' : (docwidth/2 - dw/2)+'px';
		d.css({top:dtop,left:dleft});
		}

	});


}

function saveFeed (formID, id) {
	var myform = $('#'+formID);
	if (ch <= 0) { initCB(); alert("You must select only 1 category."); return false;}
        else { return true; }
}

function testcheckbox(chkid,formID) {
	var lab = $('#chklabel'+chkid);
	var chk = $('#catCheck'+chkid);
	$('#saverssform input:checkbox:checked[class="catCheckbox"]').each(function (i) {
		if ($(this) != chk) {
		$(this).removeAttr('checked');
		var ll = $(this).parent().find('label');
		ll.css({background:'url(/img/cb.gif) no-repeat 0 -13px',color:'#303030',textDecoration:'none'});
		ch--;
		}
	});

	if ($(chk).attr('checked') != false) {
		$(chk).removeAttr('checked');
		lab.css({background:'url(/img/cb.gif) no-repeat 0 -13px',color:'#303030',textDecoration:'none'});
		ch--;
	} else if (ch < checks) {
		chk.attr('checked','checked');
		lab.css({background:'url(/img/cb.gif) no-repeat 0 5px',color:'#000000',textDecoration:'underline'});
		ch++;
	}
	return false;
}


