//All rights reserved. OxfordHousing. 2006.

var chckbxcnt=0;

function checkall()
{
	if (document.AdsTable.allbox.checked)
		chckbxcnt=0;
	for(var i=0;i<document.AdsTable.elements.length;i++)
	{
		var e=document.AdsTable.elements[i];
		if(e.name.substring(0,2)=='ad' || e.name.substring(0,2)=='ag')
		{
			e.checked=document.AdsTable.allbox.checked;
			checkme(e);
		}
	}
	if (!document.AdsTable.allbox.checked)
		chckbxcnt=0;
}

function checkme(checkedbox)
{
	if (checkedbox.name.substring(0,2)=='ad')
		rowtype='adrow';
	else
		rowtype='agrow';

	var clickedrow=document.getElementById(rowtype+checkedbox.name.substring(3));

	var oddeven=checkedbox.name.substring(2,3);
	if (oddeven=='0')
	{
		originalcolor='#EFF7FA';
		newcolor='#A9C2DC';
	}
	else
	{
		originalcolor='#E4E4E4';
		newcolor='#9AB3CD';
	}

	var chkbxheader=document.getElementById('chkbxheader');

	if (checkedbox.checked)
	{
		clickedrow.style.backgroundColor=newcolor;
		chckbxcnt=chckbxcnt+1;
	}
	else
	{
		clickedrow.style.backgroundColor=originalcolor;
		chckbxcnt=chckbxcnt-1;
	}

	if (chckbxcnt>0)
	{
		chkbxheader.style.fontWeight='bold';
	}
	else
	{
		chkbxheader.style.fontWeight='normal';
		document.AdsTable.allbox.checked=false;
	}

}

function addwatch()
{
	if (chckbxcnt==0)
	{
		alert('You did not select any advertisement.');
	}
	else
		document.AdsTable.submit();
}

function deletewatch()
{
	if (chckbxcnt==0)
	{
		alert('You did not select any advertisement.');
		return;
	}
	if (confirm('Are you sure to remove these ads from your favourites?')==true)
		document.AdsTable.submit();
}

function deletesubmit()
{
	if (chckbxcnt==0)
	{
		alert('You did not select any of your advertisements.');
		return;
	}
	if (confirm('Are you sure to remove these ads from our database?\n\n    If you just want to prevent your ad from being listed publicly but still store it on OxfordHousing.co.uk, please click CANCEL now and click the "hide" button under the control column.')==true)
		document.AdsTable.submit();
}
