function SelectAll(){
	for( var i=1; i < objForm.colour.obj.length; i++ ){
		objForm.colour.obj[i].checked = true;
	}
}

function InverseSelection(){
	for( var i=1; i < objForm.colour.obj.length; i++ ){
		objForm.colour.obj[i].checked = !objForm.colour.obj[i].checked;
	}
}

function customValidation() {
	if (objForm.colour.getValue() == '')
	 {
		objForm.colour.throwError("Select at least one colour.");
	 }
}

function PaletteChange() {
	if (objForm.saveto.getValue() == 0)
	{
		document.getElementById("paletteNameBox").style.display = "block";
		//objForm.palettename.reset();
	}
	else
	{
		document.getElementById("paletteNameBox").style.display = "none";
		// objForm.palettename.setValue conflicted with niceforms
		//objForm.palettename.obj.value = objForm.saveto.obj.options[objForm.saveto.obj.options.selectedIndex].text;
	}
}

function beforeDelete() {
	objForm.optional("palettename"); // don't validate palettename when deleting colours
}

function beforeSave() {
	if (objForm.saveto.getValue() == 0)
		objForm.required("palettename");
	else
		objForm.optional("palettename");
}

function showTip(n) {
	var tipObj = document.getElementById("tip" + n);
	tipObj.style.display = (tipObj.style.display == "block") ? "none" : "block";
}

function ToggleDisplay(id) {
	var togObj = document.getElementById(id);
	var togIco = document.getElementById(id + "Ico");
	if (togObj.style.display == "block" || togObj.style.display == "" ) {
		togObj.style.display = "none";
		togIco.src = "/images/folder.gif";
	}
	else {
		togObj.style.display =  "block";
		togIco.src = "/images/folder_open.gif";
	}
}

// Order test pots
// to make sure the order is not empty
function testpotsTotalValidate() 
{
	var count = 0;
	struct = objForm.getFields();
		
	for( key in struct )
	{
		if (key.indexOf('qty') == 0 || key.indexOf('pQty') == 0)
		{
			count += parseInt(objForm[key].getValue());
		}
		
	}
	
	if (count == 0) 
	{
		objForm.error.throwError("Order cannot be empty. Choose at least one colour or product.");
	}
}
