////////////////////////////////////////////
// Function: nextPage
//
// Purpose:
//  updates the pageStart value and send the
//    browser to the next page
//
// Arguments:
//    listSize,pageStart,pageSize
//
////////////////////////////////////////////
function nextPage(theForm,listSize,pageStart,pageSize){
    if (listSize && (parseInt(pageStart) + parseInt(pageSize)) <= listSize){
        theForm.pageStart.value = parseInt(pageStart) + parseInt(pageSize);
        theForm.submit();
    }
return false;
}

////////////////////////////////////////////
// Function: prevPage
//
// Purpose:
//  updates the pageStart value and send the
//    browser to the previous page
//
// Arguments:
//    listSize,pageStart,pageSize
//
////////////////////////////////////////////
function prevPage(theForm,listSize,pageStart,pageSize){
    if (listSize && pageStart > 1){
        theForm.pageStart.value = parseInt(pageStart) - parseInt(pageSize);
        theForm.submit();
    }
return false;
}

////////////////////////////////////////////
// Function: clearSearch
//
// Purpose:
//    Clears the current search params.
//
// Arguments:
//    None.
//
////////////////////////////////////////////
function clearSearch(theForm)
{
    if(theForm.searchBy){
        theForm.searchBy.value = '';
    }

    if(theForm.assetType){
        theForm.assetType.value = '';
    }

    if(theForm.Search){
        theForm.Search.value = '';
    }

    if(theForm.query){
        theForm.query.value = "";
    }

    if(theForm.pageStart){
        theForm.pageStart.value = 1;
    }

    if (theForm.shouldClose) {
        theForm.shouldClose.value='false';
    }
    theForm.submit();
}

function CheckAll()
{
  for (var i=0; i < document.pageForm.elements.length; i++)
  {
     var elems = document.pageForm.elements[i];
     if (elems.type == 'checkbox' && elems.name != 'checkAllBox')
        elems.checked = document.pageForm.checkAllBox.checked;
  }
}

////////////////////////////////////////////
// Function: validateDate
//
// Purpose:
//	Used in form field validation to test
//	whether or not a given date is
//	valid.
//
// Arguments:
//    year   year value
//		month  month value
//		day		 day value
//
////////////////////////////////////////////
function validateDate(year, month, day){
	var leap = 0;
	if (year <= 0){
		return false;
	}

	if ((month < 1) || (month > 12)){
		return false;
	}

	/* Validation of day*/
	if (day < 1){
		return false;
	}

	/* Validation leap-year / february / day */
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)){
		leap = 1;
	}

	if ((month == 2) && (leap == 1) && (day > 29)){
		return false;
	}
	if ((month == 2) && (leap != 1) && (day > 28)){
		return false;
	}

	/* Validation of other months */
	if (day > 31){
		if ((month == 1) || (month == 3) || (month == 5) ||
			(month == 7) || (month == 8) || (month == 10) ||
			(month == 12)){
			return false;
		}
	}

	if (day > 30){
		if ((month == 4) || (month == 6) || (month == 9) ||
			(month == 11))		{
			return false;
		}
	}

	return true;
}
