// JavaScript Document

function search(){
	var err = 0;
	
	if ((isBlank(txtYear.value) == false) && ((isInteger(txtYear.value) == false) || (txtYear.value.length != 4))) {
		spYear.style.display = 'inline';
		txtYear.focus();
		err = 1;
	}
	
	// validate email address
	if (isBlank(txtEmail.value) == true) {
		spEmail.style.display = 'inline';
		spEmail.innerHTML = 'Your email address is needed!';
		txtEmail.focus();
		err = 1;
	} else if ((txtEmail.value.indexOf("@") == -1) || (txtEmail.value.indexOf(".") == -1)){
		spEmail.style.display = 'inline';
		spEmail.innerHTML = 'Please enter email correctly!';
		txtEmail.focus();
		err = 1;
	}

	// if has error: exit function
	if (err == 1){return;}
	
	var strSearch = "";
	
	if (ddlStatus.value != "ALL"){
		strSearch = " AND co.status = "+ddlStatus.value;
	}
	if (txtYear.value != ""){strSearch = strSearch + " AND YEAR(OrderDate) = '"+txtYear.value+"'";}
	xajax_Search(1,strSearch,txtEmail.value,1);
}

// either 'page' or 'no data' is displayed 
function setDisplay(dataExist){
	switch(dataExist){
		case 'exist':
			divNoData.style.display = 'none';
			tblPage.style.display = 'block';
			break;
		case 'no':
			divNoData.style.display = 'block';
			tblPage.style.display = 'none';
			break;
	}
} // setDisplay()

function viewDetails(displayMode){
	tblViewDetails.style.display = displayMode;
} // viewDetails()

function setDetailsPos(){
	divDetails.style.display = 'block';
	divDetails.style.top = 250;
}

// Format to have only two decimal digits
function format(value){
  	var temp =  Math.round(value * 100);
  	temp = temp / 100;
	var tempStr = String(temp);
	if (tempStr.indexOf(".") == -1){
			tempStr = tempStr.concat(".00");
	}else if (tempStr.substring(tempStr.indexOf(".")).length == 2){
		tempStr = tempStr.concat("0");
	}
  	return tempStr;
}


