function returnFalse(obj){
	obj.focus();
	return false;
}

function checkLogin(){
	if (trim(document.loginFrm.pwd.value)=="")	{
		alert("Please enter password.");
		return returnFalse(document.loginFrm.pwd);
	}else{
		if (validatePassword(trim(document.loginFrm.pwd.value))==false){
			alert("Invalid password.");
			return returnFalse(document.loginFrm.pwd);
		}
	}
	document.loginFrm.submit();
}

function addeditCategory( paraFlag, id ){		
		if(trim(document.frmCategory.category_name.value)==""){
			alert('Please enter the Category name.');
			return returnFalse(document.frmCategory.category_name);
		}
		document.frmCategory.action="save_category.php?id="+id;
		document.frmCategory.actionFlag.value=paraFlag;
		document.frmCategory.submit();
}
	
function editCategory( paraFlag, id ){	
		if(trim(document.frmCategory.category_name.value)==""){
			alert('Please enter the Category name.');
			return returnFalse(document.frmCategory.category_name);
		}
		document.frmCategory.action="save_category.php?id="+id;
		document.frmCategory.actionFlag.value=paraFlag;
		document.frmCategory.submit();
}
	
function delCategory( paraid ){
	if (confirm("Are you sure you want to delete this Category?"))	{
		document.frmCategoryList.category_id.value = paraid;
		document.frmCategoryList.actionFlag.value = "delCategory";		
		document.frmCategoryList.submit();
	}
}
			
function getEquipments(category){
	var form = document.frm;
	form.categoryID.value=category;
	form.action = "equipments.php";
	form.submit();
}

function countChars(){
	var form = document.frm1;
	if(form.descTxt.value.length>500){
		form.descTxt.value = form.descTxt.value.substr(0,500);
		form.lengthTxt.value = 0;
	}
	else form.lengthTxt.value=500-form.descTxt.value.length;
}

function addeditEquipment( paraFlag, id, m ){	
		if(trim(document.frmEquipment.parent_category_id.selectedIndex)==0){
			alert('Please select Equipment category.');
			return returnFalse(document.frmEquipment.parent_category_id);
		}
		if(trim(document.frmEquipment.equipment_name.value)==""){
			alert('Please enter the Equipment name.');
			return returnFalse(document.frmEquipment.equipment_name);
		}
		
		switch (m) {
		case "n":
					break;
		case "sn":
					if(trim(document.frmEquipment.sale_amount.value)==""){
						alert("Please enter sale amount.");
						return returnFalse(document.frmEquipment.sale_amount);
					 }
					break;
		case "su":
					if(trim(document.frmEquipment.sale_amount.value)==""){
						alert("Please enter sale amount.");
						return returnFalse(document.frmEquipment.sale_amount);
					 }
					break;
		default:
					if((trim(document.frmEquipment.hrs2_rent.value)=="")&&
					  (trim(document.frmEquipment.hrs4_rent.value)=="")&&
					  (trim(document.frmEquipment.day1_rent.value)=="")&&
					  (trim(document.frmEquipment.week1_rent.value)=="")&&
					  (trim(document.frmEquipment.month1_rent.value)=="")){
						alert('Please enter the rent.');
						return returnFalse(document.frmEquipment.hrs2_rent);
					}
					
					if(trim(document.frmEquipment.hrs2_rent.value)!=""){
						if (!isFloat(trim(document.frmEquipment.hrs2_rent.value))){
							alert('Invalid rent amount for 2 hrs.');
							return returnFalse(document.frmEquipment.hrs2_rent);
						}
					}else document.frmEquipment.hrs2_rent.value=0;
					
					if(trim(document.frmEquipment.hrs4_rent.value)!=""){
						if (!isFloat(trim(document.frmEquipment.hrs4_rent.value))){
							alert('Invalid rent amount for 4 hrs.');
							return returnFalse(document.frmEquipment.hrs4_rent);
						}
					}else document.frmEquipment.hrs4_rent.value=0;
					
					if(trim(document.frmEquipment.day1_rent.value)!=""){
						if (!isFloat(trim(document.frmEquipment.day1_rent.value))){
							alert('Invalid rent amount for 1 day.');
							return returnFalse(document.frmEquipment.day1_rent);
						}
					}else document.frmEquipment.day1_rent.value=0;
					
					if(trim(document.frmEquipment.week1_rent.value)!=""){
						if (!isFloat(trim(document.frmEquipment.week1_rent.value))){
							alert('Invalid rent amount for 1 week.');
							return returnFalse(document.frmEquipment.week1_rent);
						}
					}else document.frmEquipment.week1_rent.value=0;
					
					if(trim(document.frmEquipment.month1_rent.value)!=""){
						if (!isFloat(trim(document.frmEquipment.month1_rent.value))){
							alert('Invalid rent amount for 1 month.');
							return returnFalse(document.frmEquipment.month1_rent);
						}
					}else document.frmEquipment.month1_rent.value=0;

					break;
		}
		
		
		
		document.frmEquipment.action="save_equipment.php?id="+id+"&m="+m;
		document.frmEquipment.actionFlag.value=paraFlag;
		document.frmEquipment.submit();
	}
	
function delEquipment( paraid ){
	if (confirm("Are you sure you want to delete this Equipment?"))
	{
		document.frmEquipmentList.equipment_id.value = paraid;
		document.frmEquipmentList.actionFlag.value = "delEquipment";		
		document.frmEquipmentList.submit();
	}
}

function validateChangedPassword(){
	if(trim(document.pwdFrm.old_pwd.value)==""){
		alert("Please enter old password.");
		return returnFalse(document.pwdFrm.old_pwd);
	}
	if(trim(document.pwdFrm.new_pwd.value)==""){
		alert("Please enter new password.");
		return returnFalse(document.pwdFrm.new_pwd);
	}
	else{
		if(validatePassword(document.pwdFrm.new_pwd.value)==false){
			alert("Invalid new password");
			return returnFalse(document.pwdFrm.new_pwd);
		}
	}
	if(trim(document.pwdFrm.new_pwd.value)!=trim(document.pwdFrm.conf_pwd.value)){
		alert("Confirm password failed.");
		return returnFalse(document.pwdFrm.conf_pwd);
	}
	document.pwdFrm.submit();
}
function validateSalexfer(){
	if(trim(document.frm.sale_amount.value)==""){
		alert("Please enter sale amount.");
		return returnFalse(document.frm.sale_amount);
	}
	else if (!isFloat(trim(document.frm.sale_amount.value))){
		alert('Invalid sale amount.');
		return returnFalse(document.frm.sale_amount);
	}
	document.frm.submit();
}
function validateRentxfer(){
	if((trim(document.frm.hrs2_rent.value)=="")&&
					  (trim(document.frm.hrs4_rent.value)=="")&&
					  (trim(document.frm.day1_rent.value)=="")&&
					  (trim(document.frm.week1_rent.value)=="")&&
					  (trim(document.frm.month1_rent.value)=="")){
						alert('Please enter the rent.');
						return returnFalse(document.frm.hrs2_rent);
					}
					
					if(trim(document.frm.hrs2_rent.value)!=""){
						if (!isFloat(trim(document.frm.hrs2_rent.value))){
							alert('Invalid rent amount for 2 hrs.');
							return returnFalse(document.frm.hrs2_rent);
						}
					}else document.frm.hrs2_rent.value=0;
					
					if(trim(document.frm.hrs4_rent.value)!=""){
						if (!isFloat(trim(document.frm.hrs4_rent.value))){
							alert('Invalid rent amount for 4 hrs.');
							return returnFalse(document.frm.hrs4_rent);
						}
					}else document.frm.hrs4_rent.value=0;
					
					if(trim(document.frm.day1_rent.value)!=""){
						if (!isFloat(trim(document.frm.day1_rent.value))){
							alert('Invalid rent amount for 1 day.');
							return returnFalse(document.frm.day1_rent);
						}
					}else document.frm.day1_rent.value=0;
					
					if(trim(document.frm.week1_rent.value)!=""){
						if (!isFloat(trim(document.frm.week1_rent.value))){
							alert('Invalid rent amount for 1 week.');
							return returnFalse(document.frm.week1_rent);
						}
					}else document.frm.week1_rent.value=0;
					
					if(trim(document.frm.month1_rent.value)!=""){
						if (!isFloat(trim(document.frm.month1_rent.value))){
							alert('Invalid rent amount for 1 month.');
							return returnFalse(document.frm.month1_rent);
						}
					}else document.frm.month1_rent.value=0;

	document.frm.submit();
}