function changePage(page){
	var pageText = document.getElementById('pageText');
	pageText.value = page;
	var form = document.getElementById('pageForm');
	form.submit();
}

function sort(param){
	var sortParam = document.getElementById('sortParam');
	sortParam.value = param;
	var form = document.getElementById('sortForm');
	form.submit();
}

function validateCheckbox(param){
	var checkbox = document.getElementById('checkbox' + param);
	var qty = document.getElementById('qty' + param);
	
	if(checkbox.checked){
		qty.value = 1;
	}else{
		qty.value = "";
	}
}

function validateQuantity(param){
	var checkbox = document.getElementById('checkbox' + param);
	var qty = document.getElementById('qty' + param);
	
	if(qty != null && qty != ""){
	
		if(!isNumeric(qty.value)){
			qty.value = "";
			checkbox.checked = false;
			return;
		}	
	
		if(qty.value < 0){
			qty.value = "";
		}	
		if(qty.value != 0){
			checkbox.checked = true;
		}else{
			checkbox.checked = false;
		}
	}else{
		checkbox.checked = false;
	}
}

function isNumeric(strString){
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++){
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1){
		 blnResult = false;
		}
	}
	return blnResult;
}

function clearAll(){
	var addToForm = document.getElementById('addToForm');
	len = addToForm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if(addToForm.elements[i].name.length > 8){
			subSection = addToForm.elements[i].name.substring(0,8);
			if(subSection == 'checkbox'){
				addToForm.elements[i].checked = false;
				addToForm.elements[i+1].value = "";
			}
		}
	}
}


