// JavaScript Document

function addpaymentdate(id)
{
  if(confirm("Add additional date?"))
  {
    window.location.href = 'processAction.php?action=addpaymentdate&id=' + id;
  }
}

function calculate(qty, price, amt)
{
  if(qty.value!="" && price.value!="")
  {
    amt.value = qty.value * price.value;
  }
  else
  {
    amt.value="";
  }
}


//added 11 march 2009
// Checks if a given date string is in YYYY-MM-DD format
function is_date(s)   
{          
  // make sure it is in the expected format       
  var df = /^\d{4}-\d{2}-\d{2}$/;
  if(!s.match(df)) return false;        
    
  var arrDateParts = s.split("-");
  // convert it into a date instance
  var dt = new Date(Date.parse(arrDateParts[0]+"/"+arrDateParts[1]+"/"+arrDateParts[2]));
  
  // check the components of the date       
  // since Date instance automatically rolls over each component       
  //var arrDateParts = s.split("-");    
  return (           
    dt.getFullYear() == arrDateParts[0] &&           
    dt.getMonth() == arrDateParts[1]-1 &&           
    dt.getDate() == arrDateParts[2]       
  );
  
}

//added 02 March 2009
// reset the field to an initial value(str)
function setBack(fieldname, str)
{
  if(fieldname.value=="")
  {
    fieldname.value=str;
  }
}

//sets the field to empty
function setNull2(fieldname)
{
  //check if the field value is not a numbers
  if(fieldname.value=="Contact Name" || fieldname.value=="Contact Number")
  {
    fieldname.value="";
  }
}

//added 09 Oct 2008
//check login form
function checkLogin()
{
  with(window.document.frmLogin)
  { 
    //btnLogin.disabled=true;
    document.getElementById("logining_in").innerHTML="<img src='ajax-loader.gif'>";
    if(txtUserId.value=="")
    {
      document.getElementById("logining_in").innerHTML="<input name='btnLogin' type='submit' value=' Login ' class='box'>";
      //alert('Please enter your login name');
      jAlert('Please enter your login name.', 'Alert Dialog');
      return false;
    }
    else if(password.value==hex_md5(challenge.value+hex_md5(salt.value+hex_md5(''))))
    {      
      document.getElementById("logining_in").innerHTML="<input name='btnLogin' type='submit' value=' Login ' class='box'>";
      //alert('Please enter your password.');
      jAlert('Please enter your password.', 'Alert Dialog');
      return false;
    }
    else
    {
      return true;
    }
  }
}


//added 26 Sep 2008
function chk_search_form()
{
  with(window.document.frm_search)
  {
    if(SearchField.value=='')
    {
      alert('Please Enter a variable to search.');
      return;
    }
    else
    {
      submit();
    }
  }
}

//added 13 June 2008
function addEvent()
{
  with(window.document.frmAddEvent)
  {
    if(txt_start_date.value == '' )
    {
      alert('Please Enter The Date!');
      return;
    }
    else if(txt_end_date.value != '' && (txt_end_date.value < txt_start_date.value))
    {
      alert('Please select a later date than the Start Date!');
      return;
    }
    else if(txtTitle.value == '')
    {
      alert('Please Enter The Title!');
      return;
    }
    else if(mtxDetail.value == '')
    {
      alert('Please Enter The Detail!');
      return;
    }
    else
    {
      submit();
      close();
    }
  }
}

//added 22 May 2008
function delLog(lid, asset_id)
{
  if(confirm("Delete this Log?"))
  {
    window.location.href = 'processAction.php?action=delLog&lid=' + lid + '&asset_id=' + asset_id;
  }
}

//added 21 May 2008
function addLog(asset_id)
{
  targetUrl = 'index.php?view=addLog&asset_id=' + asset_id ;
	window.location.href = targetUrl;
}

function checkfrmLog()
{
  with(window.document.frmLog)
  {
    if(txtLog.value == '')
    {
      alert('Please Enter The Log Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}

//added 14 May 2008
function searchLbl(val1)
{
  if(val1=="")
  {
    alert('Please enter a label to search.');
  }
  else
  {
    //if (confirm('Search?')) 
    //{
      targetUrl = 'viewHW.php?label='+val1;
    	window.open(targetUrl);
    //}
  }
}

//added 11 apr 2008
function checkfrmQte()
{
  with(window.document.frmQte)
  {
    if(txtQte.value == "")
    {
      alert('Please Fill in the Quotation Number!');
      return;
    }
    else
    {
      submit();
      close();
    }
  }
}

function checkfrmInv2()
{
  with(window.document.frmInv)
  {
    if(txtYr.value == '')
    {
      alert('Please Enter The Year!');
      return;
    }
    else if(txtInv.value == '')
    {
      alert('Please Enter The Invoice Number!');
      return;
    }
    else
    {
      submit();
      close();
    }
  }
}

//added 02 apr 2008
function changeLocation(menuObj)
{
   var i = menuObj.selectedIndex;

   if(i >= 0)
   {
      window.location = menuObj.options[i].value;
   }
}

function ccl(id)
{
  if (confirm('Cancel leave(s)?')) 
  {
  	//window.document.frmApplication.submit();
  	targetUrl = 'processAction.php?action=cancel&id='+id;
	  window.location.href = targetUrl;
  }
}

function checkfrmAddLeave()
{
  with(window.document.frmLeave)
  {
    if(txtReason.value == "")
    {
      alert('Please Fill in the Reason!');
      return;
    }
    else if(txtLeave.value == "")
    {
      alert('Please Fill in the Number of leaves!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function addLve(id)
{
  targetUrl = 'index.php?view=add';
	window.location.href = targetUrl + '&u_id=' + id ;
}

function editLveApp()
{
  with(window.document.frmApplication)
  {
    if(mtxReason.value == "")
    {
      alert('Please Fill in the Reason!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function cfmApp(id)
{
  if (confirm('Approve this leave?')) 
  {
  	//window.document.frmApplication.submit();
  	targetUrl = 'processAction.php?action=approve&id='+id;
	  window.location.href = targetUrl;
  }
}
function checkfrmLveApply()
{
  with(window.document.frmLeave)
  {
    if(mtxReason.value == "")
    {
      alert('Please Fill in the Reason!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function applyLeave()
{
	targetUrl = 'index.php?view=apply';
	window.location.href = targetUrl;
}

function checkfrmPackage()
{
  with(window.document.frmPackage)
  {
    if(txtTitle.value == "")
    {
      alert('Please Fill in the Title!');
      return;
    }
    else if(txtNum.value == "")
    {
      alert('Please Fill in the Number of Leaves!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function addPackage()
{
	targetUrl = 'index.php?view=add';
	window.location.href = targetUrl;
}

function addRMA()
{
	targetUrl = 'index.php?view=add';
	window.location.href = targetUrl;
}

function checkfrmRMA()
{
  with(window.document.frmRMA)
  {
    if(txtTitle.value == "")
    {
      alert('Please Fill in the Title!');
      return;
    }
    else if(txtIn.value == "")
    {
      alert('Please Fill in the In Date!');
      return;
    }
    else
    {
      submit();
    }
  }
}
//--------------------------------------------------------------------------

function addLead()
{
	targetUrl = 'index.php?view=add';
	window.location.href = targetUrl;
}

function checkfrmLead()
{
  with(window.document.frmLead)
  {
    if(txtTitle.value == "")
    {
      alert('Please Fill in the Title!');
      return;
    }
    else if(txtDesc.value == "")
    {
      alert('Please Fill in the Description!');
      return;
    }
    else if(elements[17].checked==false && elements[18].checked==true)
    {
      alert('Please Invoice Before Closing this Lead!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function checkfrmLead2()
{
  with(window.document.frmLead)
  {
    if(txtTitle.value == "")
    {
      alert('Please Fill in the Title!');
      return;
    }
    else if(txtDesc.value == "")
    {
      alert('Please Fill in the Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function chkFrmSend()
{
  with(window.document.frmPastTask)
  {
    if(!isValidEmail(email.value))
    {
      alert('Please Enter a Email to send!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function checkfrmSetting(){
  with(window.document.frmSetting)
  {
    if(!isValidEmail(from_email.value))
    {
      alert('Please Enter a Valid From Email!');
      return;
    }
    else if(smtp_user.value=='')
    {
      alert('Please Enter SMTP User Name!');
      return;
    }
    else if(smtp_pword.value=='')
    {
      alert('Please Enter SMTP Password!');
      return;
    }
    else if(smtp_host.value=='')
    {
      alert('Please Enter SMTP Host!');
      return;
    }
    else if(expiry.value=='')
    {
      alert('Please Enter the value for expiry!');
    }
    else if(!isValidEmail(ser_rpt_email.value))
    {
      alert('Please Enter a Valid Email for service report!');
    }
    else if(!isValidEmail(req_ser_email.value))
    {
      alert('Please Enter a Valid Email for request email!');
    }
    else if(!isValidEmail(req_chg_email.value))
    {
      alert('Please Enter a Valid Email for request change!');
    }
    else
    {
      submit();
    }
  }
}

function chkDate(){
  with(window.document.frmDate)
  {
    if(txtExpiry.value=='')
    {
      alert('Please Select the Expiry Date!');
      return;
    }
    else
    {
      submit();
      close();
    }
  }
}

function decom(asset_id)
{
  if (confirm('Are you sure you want to decomission this item?')) 
  {
  	targetUrl = 'processAction.php?action=decom&asset_id=' + asset_id ;
  	window.location.href = targetUrl;
  }
}

function selectCus(val)
{
  if(val.value==4 || val.value==3)
  {
    targetUrl = 'index.php?view=add&opt='+val.value+'&s=1';
  }
  else if(val.value==1 || val.value==2 || val.value==5)
  {
    targetUrl = 'index.php?view=add&opt='+val.value+'&s=2';
  }
  else
  {
    targetUrl = 'index.php?view=add&opt='+val.value+'&s=0';
  }
	window.location.href = targetUrl;

  return false;
}

function checkMain()
{
  with(window.document.frmMain)
  {
    if(total_visit.value == '')
    {
      alert('Please Enter The Number of Total Visit!');
      return;
    }
    else if(allocated_visit.value == '')
    {
      alert('Please Enter The Number of Allocated Visit!');
      return;
    }
    else if(e_visit.value == '')
    {
      alert('Please Enter The Number of E-Visit!');
      return;
    }
    else if(start_date.value == '')
    {
      alert('Please Enter The Start Date!');
      return;
    }
    else if(duration.value=='')
    {
      alert('Please Enter The Duration!');
      return;
    }
    else if(sch_pack[0].checked==false && sch_pack[1].checked==false && sch_pack[2].checked==false && sch_pack[3].checked==false && sch_pack[4].checked==false && sch_pack[5].checked==false)
    {
      alert('Please select the scheduled package!')
    }
    else if(total_visit.value != parseInt(allocated_visit.value) + parseInt(e_visit.value))
    {
      alert('Number of Allocated Visit and E-Visit does not tally with Total Visit.\n\rPlease check your numbers!')
    }
    else
    {
      submit();
    }
  }
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

function textCounter(field, countfield, maxlimit)
{
  if (field.value.length > maxlimit)
  {
    field.value = field.value.substring(0, maxlimit);
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}

function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function addFW(fid, cus_id)
{
	targetUrl = 'index.php?view=add&fid=' + fid + '&cus_id=' + cus_id;
	window.location.href = targetUrl;
}
/*
function delFW()
{
	if (confirm('Are you sure you want to delete this firewall?')) 
  {
		window.document.listFW.submit();
	}
}*/

function massDecomFW()
{
	if (confirm('Are you sure you want to decom the following firewall?')) 
  {
		window.document.listFW.submit();
	}
}

function checkfrmFW()
{
  var chkExpiry = false;
  var chkReg = false; 
  
  with(window.document.frmFW)
  {
    if(txtExpiry.value !='')
    {
      if(is_date(txtExpiry.value))
      {
        chkExpiry=true;
      }
      else
      {
        chkExpiry=false;
      }
    }
    else
    {
      chkExpiry=false;
    }
    
    if(txtReg.value !='')
    {
      if(is_date(txtReg.value))
      {
        chkReg=true;
      }
      else
      {
        chkReg=false;
      }
    }
    else
    {
      chkReg=false;
    }
    
    
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(!chkReg)
    {
      alert('Please Enter The Register Date in the Proper Format!');
      return;
    }
    else if(!chkExpiry)
    {
      alert('Please Enter The Expiry Date in the Proper Format!');
      return;
    }
    else if(txtModel.value == '')
    {
      alert('Please Enter The Model!');
      return;
    }
    else if(txtWAN.value == '')
    {
      alert('Please Enter The WAN URL!');
      return;
    }
    else if(txtLAN.value == '')
    {
      alert('Please Enter The LAN URL!');
      return;
    }
    else if(txtPword.value == '')
    {
      alert('Please Enter The Password!');
      return;
    }
    else
    {
      submit();
    }
  }
}


/*
arg:
asset_id - id of asset
user_id - the id of current user who activated the function
v - 1=from list
    0=from detail
t - 2=HT
    1=AV
    0=FW
*/
function renew(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=renew&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
	}
}
function qte(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=qte&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
	}
}
function cfm(asset_id, user_id, v, t, opt1, field, oid, con, page)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=cfm&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t + '&opt1=' + opt1 + '&field=' + field + '&oid=' + oid + '&con=' + con + '&page=' + page;
  }
}
function odr(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=odr&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
  }
}
function dlv(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=dlv&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
  }
}
function inv(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=inv&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
  }
}
function act(asset_id, user_id, v, t)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=act&asset_id=' + asset_id + '&user_id=' + user_id + '&v=' + v + '&t=' + t;
  }
}
//------------------------------------------------------------------------------


function addAV(fid, cus_id)
{
	targetUrl = 'index.php?view=add&fid=' + fid + '&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delAV()
{
	if (confirm('Are you sure you want to delete this anti-virus?')) 
  {
		window.document.listAV.submit();
	}
}*/

function massDecomAV()
{
	if (confirm('Are you sure you want to decom the selected anti-virus software?')) 
  {
		window.document.listAV.submit();
	}
}

function checkfrmAV()
{
  var chkExpiry = false;
  
  with(window.document.frmAV)
  {
  
    if(txtExpiry.value !='')
    {
      //alert('Please Enter The Expiry Date!');
      if(is_date(txtExpiry.value))
      {
        //alert(txtExpiry.value+' is not in the correct format.');
        //return;
        chkExpiry=true;
      }
      else
      {
        chkExpiry=false;
      }
    }
    else
    {
      chkExpiry=false;
    }
  
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(!chkExpiry)
    {
      alert('Please Enter The Expiry Date in a Proper Format.');
      return;
    }
    else if(txtBrand.value == '')
    {
      alert('Please Enter The Brand!');
      return;
    }
    else if(txtPack.value == '')
    {
      alert('Please Enter The Package!');
      return;
    }
    else if(txtVersion.value == '')
    {
      alert('Please Enter The Version!');
      return;
    }
    else if(txtQty.value == '')
    {
      alert('Please Enter The Quantity!');
      return;
    }
    else if(txtSerial.value == '')
    {
      alert('Please Enter The Mte Serial No!');
      return;
    }
    else
    {
      submit();
    }
  }
}


function addHT(fid, cus_id)
{
	targetUrl = 'index.php?view=add&fid=' + fid + '&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delHT()
{
	if (confirm('Are you sure you want to delete this Hosting?')) 
  {
		window.document.listHT.submit();
	}
}*/

function massDecomHT()
{
	if (confirm('Are you sure you want to decom the following Hosting?')) 
  {
		window.document.listHT.submit();
	}
}

function checkfrmHT()
{
  var chkExpiry = false;
  var chkRegister = false; 
   
  with(window.document.frmHT)
  {
  
    if(txtExpiry.value !='')
    {
      if(is_date(txtExpiry.value))
      {
        chkExpiry=true;
      }
      else
      {
        chkExpiry=false;
      }
    }
    else
    {
      chkExpiry=false;
    }
    
    if(txtRegister.value !='')
    {
      if(is_date(txtRegister.value))
      {
        chkRegister=true;
      }
      else
      {
        chkRegister=false;
      }
    }
    else
    {
      chkRegister=false;
    }
  
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(!chkRegister)
    {
      alert('Please Enter The Register Date in the Proper Format!');
      return;
    }
    else if(!chkExpiry)
    {
      alert('Please Enter The Expiry Date in the Proper Format!');
      return;
    }
    else if(mtxPackage.value == '')
    {
      alert('Please Enter The Package!');
      return;
    }
    else if(txtReg.value == '')
    {
      alert('Please Enter The Registrar!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function checkfrmHT2()
{
  with(window.document.frmHT)
  {
    if(txtRegister.value == '')
    {
      alert('Please Enter The Register Date!');
      return;
    }
    else if(txtExpiry.value == '')
    {
      alert('Please Enter The Expiry Date!');
      return;
    }
    else if(mtxPackage.value == '')
    {
      alert('Please Enter The Package!');
      return;
    }
    else if(txtReg.value == '')
    {
      alert('Please Enter The Registrar!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function addIA(fid, cus_id)
{
	targetUrl = 'index.php?view=add&fid=' + fid + '&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delIA()
{
	if (confirm('Are you sure you want to delete this firewall?')) 
  {
		window.document.listIA.submit();
	}
}*/

function decomIA()
{
	if (confirm('Are you sure you want to decom the following item(s)?')) 
  {
		window.document.listIA.submit();
	}
}

function checkfrmIA()
{
  with(window.document.frmIA)
  {
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}


function addPW(cus_id)
{
	targetUrl = 'index.php?view=add&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delPW()
{
	if (confirm('Are you sure you want to delete this Password List?')) 
  {
		window.document.listPW.submit();
	}
}*/

function decomPW()
{
	if (confirm('Are you sure you want to decom the following Password List?')) 
  {
		window.document.listPW.submit();
	}
}

function checkfrmPW()
{
  with(window.document.frmPW)
  {
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function addOT(cus_id)
{
	targetUrl = 'index.php?view=add&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delOT()
{
	if (confirm('Are you sure you want to delete?')) 
  {
		window.document.listOT.submit();
	}
}*/

function decomOT()
{
	if (confirm('Are you sure you want to decom the following?')) 
  {
		window.document.listOT.submit();
	}
}

function checkfrmOT()
{
  with(window.document.frmOT)
  {
    var ext = oth_attach.value;
    ext = ext.substring(ext.length-3,ext.length);
    ext = ext.toLowerCase();
    
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else if(oth_attach.value != '')
    {
      switch(ext)
      {
        case 'doc' :
          submit();
          break;
        case 'xls' :
          submit();
          break;
        case 'ppt' :
          submit();
          break;
        case 'txt' :
          submit();
          break;
        case 'jpg' :
          submit();
          break;
        case 'gif' :
          submit();
          break;
        case 'pdf' :
          submit();
          break;
        case 'tif' :
          submit();
          break;
        case 'vsd' :
          submit();
          break;
        default :
          alert('File Extension Not Accepted!');
          return;
      }
    }
    else
    {
      submit();
    }
  }
}

function del_attachment(id)
{
  if(confirm("Delete this attachment?"))
  {
    window.location.href = 'processAction.php?action=del_attach&id=' + id;
  }
}

function del_attachment2(id, cus_id)
{
  if(confirm("Delete this attachment?"))
  {
    window.location.href = 'processAction.php?action=del_attach&id=' + id + '&cus_id=' + cus_id;
  }
}

function addOS(fid, cus_id)
{
	targetUrl = 'index.php?view=add&fid=' + fid + '&cus_id=' + cus_id ;
	window.location.href = targetUrl;
}
/*
function delOS()
{
	if (confirm('Are you sure you want to delete this Outstanding Matters?')) 
  {
		window.document.listOS.submit();
	}
}*/

function decomOS()
{
	if (confirm('Are you sure you want to delete the following Outstanding Matters?')) 
  {
		window.document.listOS.submit();
	}
}

function checkfrmOS()
{
  with(window.document.frmOS)
  {
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function checkfrmOS2()
{
  with(window.document.frmOS)
  {
    if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}


function chk(asset_id)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=cfm&asset_id=' + asset_id;
	}

}


function addInvoice(asset_id)
{
  targetUrl = 'index.php?view=addInvoice&asset_id=' + asset_id ;
	window.location.href = targetUrl;
}

function delInvoice(nid, asset_id)
{
	if (confirm('Are you sure you want to delete this invoice?')) 
  {   
    targetUrl = 'processAction.php?action=delInvoice&nid=' + nid + '&asset_id=' + asset_id ;
		window.location.href = targetUrl;
	}
}

function checkfrmInv()
{
  with(window.document.frmInv)
  {
    if(txtYr.value == '')
    {
      alert('Please Enter The Year!');
      return;
    }
    else if(txtInv.value == '')
    {
      alert('Please Enter The Invoice Number!');
      return;
    }
    else
    {
      submit();
    }
  }
}


function addLoan(fid)
{
	targetUrl = 'index.php?view=add&fid=' + fid;
	window.location.href = targetUrl;
}
/*
function delLoan()
{
	if (confirm('Are you sure you want to delete this Outstanding Matters?')) 
  {
		window.document.listLoan.submit();
	}
}*/

function decomLoan()
{
	if (confirm('Are you sure you want to decom the following Outstanding Matters?')) 
  {
		window.document.listLoan.submit();
	}
}

function checkfrmLoan()
{
  with(window.document.frmLoan)
  {
    if(cboCustomer.value == '')
    {
      alert('Please select the customer');
      return;
    }
    else if(txtStart.value == '')
    {
      alert('Please Enter The Start Date!');
      return;
    }
    else if(txtName.value == '')
    {
      alert('Please Enter The Name!');
      return;
    }
    else if(mtxDesc.value == '')
    {
      alert('Please Enter The Description!');
      return;
    }
    else
    {
      submit();
    }
  }
}

function chk(asset_id, fid)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=cfm&asset_id=' + asset_id + '&fid=' + fid ;
	}

}

function reopen(asset_id)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=reopen&asset_id=' + asset_id ;
	}
}

function archiveLoan(asset_id)
{
  if (confirm('Archive this item?')) 
  {
	   window.location.href = 'processAction.php?action=archive&asset_id=' + asset_id;
	}
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

//added 26 June 2008
function checkfrmInv2()
{
  with(window.document.frmInv)
  {
    if(txtInv.value == '')
    {
      alert('Please Enter The Invoice Number!');
      return;
    }
    else
    {
      submit();
      close();
    }
  }
}

function cfm2(main_id, c, sort)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=cfm&main_id=' + main_id +'&c=' + c + '&sort' + sort;
  }
}
function setup(main_id, c, sort)
{
  if (confirm('Confirm with this action?')) 
  {
	   window.location.href = 'processAction.php?action=setup&main_id=' + main_id +'&c=' + c + '&sort' + sort;
  }
}


