function refreshFilters(search)	{
	var f = document.filters;
	filt = f.filt.value;
	debt = f.debt.value;
	window.location = "clients.php?filt="+filt+"&debt="+debt;	
}


function refreshIFilters(filt, debt, did, type)	{
	var f = document.ifilters;
	idebt = f.idebt.value;
	if (type == "normal")	{
		window.location = "clients.php?filt="+filt+"&debt="+debt+"&idebt="+idebt+"&act=inv_list&did="+did;	
	} else {
		window.location = "clients.php?filt="+filt+"&debt="+debt+"&idebt="+idebt+"&act=inv_statement&did="+did;	
	}
}

function addClient()	{
	var f = document.addClient;
	f.submit();
}

function modifyClient()	{
	var f = document.modClient;
	f.submit();
}

function deleteClient(did, filt, debt)	{
	var ok = confirm("Are you sure you wish to delete this client?");
	if (ok) window.location = "clients.php?filt="+filt+"&debt="+debt+"&act=del_client&did="+did;
}

function addInvoice()	{
	var f = document.addInvoice;
	f.submit();
}

function modifyInvoice()	{
	var f = document.modifyInvoice;
	f.submit();
}

function deleteInvoice(did, dtid, filt, debt, idebt, report)	{
	var ok = confirm("Are you sure you wish to delete this invoice?");
	if (ok) window.location = "clients.php?filt="+filt+"&debt="+debt+"&idebt="+idebt+"&act=del_invoice&did="+did+"&dtid="+dtid+"&report="+report;
}

function addAdjustment()	{
	var f = document.addAdjustment;
	f.submit();
} 

function modifyAdjustment()	{
	var f = document.modifyAdjustment;
	f.submit();
}

function deleteAdjustment(did, dtid, tid, filt, debt, idebt)	{
	var ok = confirm("Are you sure you wish to delete this adjustment?");
	if (ok) window.location = "clients.php?filt="+filt+"&debt="+debt+"&idebt="+idebt+"&act=del_adjustment&did="+did+"&dtid="+dtid+"&tid="+tid;
}

function processLegalPayment(amount)	{
	var f = document.pay;
	if (f.name.value.length < 3)	{
		alert("Please enter the name shown on card!");
	} else {
		if (f.address.value.length < 10)	{
			alert("Please enter the cardholder's address!");
		} else {
			if (f.tel.value.length < 5) {
				alert("Please enter the cardholder's telephone number!");
			} else {
				bOK = confirm("Are you sure you wish to continue with this transaction it will cost £"+amount);
				if (bOK) f.submit();
			}
		}
	}
}

function processPayment()	{
	var f = document.pay;
	cost = document.getElementById("cost");
	if (cost)	{	
		if (!cost.value.length)	{
			alert("Please enter an amount to top up your Debttrack Account by!");
		} else {
			if (f.name.value.length < 3)	{
				alert("Please enter the name shown on card!");
			} else {
				if (f.address.value.length < 10)	{
					alert("Please enter the cardholder's address!");
				} else {
					if (f.tel.value.length < 5) {
						alert("Please enter the cardholder's telephone number!");
					} else {
						f.submit();
					}
				}
			}
		}
	} else {
		if (f.name.value.length < 3)	{
			alert("Please enter the name shown on card!");
		} else {
			if (f.address.value.length < 10)	{
				alert("Please enter the cardholder's address!");
			} else {
				if (f.tel.value.length < 5) {
					alert("Please enter the cardholder's telephone number!");
				} else {
					f.submit();
				}
			}
		}
	}
}

function changeStatementDate()	{
	var f = document.sdate;
	var stat_date = f.stat_date.value;
	window.location = "statement.php?date="+stat_date;
}

function changeAdminStatementDate(uid, signup_date)	{
	var f = document.sdate;
	var stat_date = f.stat_date.value;
	window.location = "users_trans.php?act=view_trans&uid="+uid+"&signup_date="+signup_date+"&date="+stat_date;
}

function changeAdminStatementDatePM(cid, uid, signup_date)	{
	var f = document.sdate;
	var stat_date = f.stat_date.value;
	window.location = "users_trans.php?act=view_trans&pm_uid="+uid+"&pm_cid="+cid+"&pm=1&signup_date="+signup_date+"&date="+stat_date;
}

function changeSignupDate()	{
	var f = document.sdate;
	var signup_date = f.signup_date.value;
	window.location = "users_trans.php?date="+signup_date;
}

function changePortfolioDate(pm, pm_cid, pm_uid, signup_date)	{
	var f = document.sdate;
	var stat_date = f.stat_date.value;
	if (!pm)	{
		window.location = "portfolio.php?date="+stat_date;
	} else {
		window.location = "portfolio.php?pm_cid="+pm_cid+"&pm_uid="+pm_uid+"&pm="+pm+"&signup_date="+signup_date+"&date="+stat_date;
	}
}

function openPortfolioWindow(cid, pid)	{
	window.open("show_portfolio_item.php?cid="+cid+"&pid="+pid, "Portfolio","toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=750,height=350")
}

function changeReport()	{
	var sel = document.rs.report;
	window.location = "reports.php?report="+sel.value;
}

function checkSignupForm()	{
	var f = document.signup_form;
	if (f.email.value.length < 5) {
		alert("Please enter your email address!");
	} else {
		if (f.email2.value.length < 5)	{
			alert("Please verify your email address!");
		} else {
			if (f.email.value != f.email2.value)	{
				alert("Email addresses do not match!");
			} else {
				if (f.pword.value.length < 4)	{
					alert("Password must be at least four characters!");
				} else {
					if (f.pword.value != f.pword2.value)	{
						alert("Password's do not match!");	
					} else {
						if (f.title.value == "") {
							alert("Please enter your title!");
						} else {
							if (f.fname.value == "")	{
								alert("Please enter your first name!");
							} else {
								if (f.lname.value == "")	{
									alert("Please enter your surname!");
								} else {
									if (f.cname.value == "")	{
										alert("Please enter your company name!");
									} else {
										if (f.pcode.value.length < 6)	{
											alert("Please enter your postcode!");
										} else {
											if (f.tel.value.length < 5)	{
												alert("Please enter your telephone number!");
											} else {
												if (!f.tandc.checked)	{
													alert("Please check that you have read and agreed to Debttrack's terms and conditions!");
												} else {
													f.submit();
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function checkAddUserForm()	{
	var f = document.agent_form;
	if (f.email.value.length < 5) {
		alert("Please enter your email address!");
	} else {
		if (f.email2.value.length < 5)	{
			alert("Please verify your email address!");
		} else {
			if (f.email.value != f.email2.value)	{
				alert("Email addresses do not match!");
			} else {
				if (f.pword.value.length < 4)	{
					alert("Password must be at least four characters!");
				} else {
					if (f.pword.value != f.pword2.value)	{
						alert("Password's do not match!");	
					} else {
						if (f.title.value == "") {
							alert("Please enter your title!");
						} else {
							if (f.fname.value == "")	{
								alert("Please enter your first name!");
							} else {
								if (f.lname.value == "")	{
									alert("Please enter your surname!");
								} else {
									f.submit();
								}
							}
						}
					}
				}
			}
		}
	}
}


function checkQuickBuyForm()	{
	var f = document.signup_form;
	if (f.email.value.length < 5) {
		alert("Please enter your email address!");
	} else {
		if (f.email2.value.length < 5)	{
			alert("Please verify your email address!");
		} else {
			if (f.email.value != f.email2.value)	{
				alert("Email addresses do not match!");
			} else {
				if (f.pword.value.length < 4)	{
					alert("Password must be at least four characters!");
				} else {
					if (f.pword.value != f.pword2.value)	{
						alert("Password's do not match!");	
					} else {
						f.submit();
					}
				}
			}
		}
	}
}

function checkModUserForm()	{
	var f = document.agent_form;
	if (f.email.value.length < 5) {
		alert("Please enter your email address!");
	} else {
		if (f.pword.value.length < 4)	{
			alert("Password must be at least four characters!");
		} else {
			if (f.pword.value != f.pword2.value)	{
				alert("Password's do not match!");	
			} else {
				if (f.title.value == "") {
					alert("Please enter your title!");
				} else {
					if (f.fname.value == "")	{
						alert("Please enter your first name!");
					} else {
						if (f.lname.value == "")	{
							alert("Please enter your surname!");
						} else {
							f.submit();
						}
					}
				}
			}
		}
	}
}

function checkDelUser(uid)	{
	var ok = confirm("Are you sure you wish to delete this user?");
	if (ok)	{
		window.location = "agents.php?act=del_user&uid="+uid;
	}
}

function checkContactForm()	{
	var f = document.contact_form;
	if (f.title.value.length < 1) {
		alert("Please enter your title!");
	} else {
		if (f.first_name.value.length < 1)	{
			alert("Please enter your first name!");
		} else {
			if (f.surname.value.length < 2)	{
				alert("Please enter your surname!");
			} else {
				if (f.company_name.value.length < 2)	{
					alert("Please enter company name!");
				} else {
					if (f.telephone.value.length < 2)	{
						alert("Please enter your telephone number!");
					} else {
						if (f.email.value.length < 5) {
							alert("Please enter your email address!");						
						} else {
							if (f.enquiry.value.length < 10) {
								alert("Please enter your enquiry!");		
							} else {
								document.contact_form.subject.value = f.subject.value+f.nature_of_enquiry.value;
								f.submit();
							}
						}
					}
				}	
			}
		}
	}
}

function checkEmail()	{
	var f = document.your_email;
	if (f.email.value.length > 5)	{
		if (f.email.value == f.re_email.value) {
			f.submit();
		} else {
			alert("Email addresses do not match!");
		}	
	} else {
		alert("No email address entered!");
	}
}

function checkUserName()	{
	var f = document.fp_form;
	if (f.user_name.value.length > 3)	{
		f.submit();
	} else {		
		alert("Please enter your user name!");
	}
}

function checkSendToFriend()	{
	var f = document.stf_form;
	if (f.your_name.value.length && f.your_email.value.length && f.their_name.value.length && f.their_email.value.length)	{
		f.submit();
	} else {
		alert("Please fill in all required fields!");
	}
}

function openTANDCWindow() {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open('terms_of_use_no.php', '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=350,ScreenX=500,ScreenY=0,resizable=yes,alwaysLowered=false');");
}

function lbaPrev(act)	{
	document.lba.action = "letter_before_action.php?act="+act;
	document.lba.submit();
}

function takeAction(act, step, did, dtid)	{
	var f = document.ta;
	switch (step)	{
		default:
			did = f.did.value;
			if (did == 0)	{
				window.location = "take_action.php?act="+act+"&step="+step+"&did=0";
			} else {
				window.location = "take_action.php?act="+act+"&step="+step+"&did="+did;
			}
		break;
		case "2":
			dtid = f.dtid.value;
			if (dtid == 0)	{
				window.location = "take_action.php?act="+act+"&step="+step+"&did="+did+"&dtid=0";
			} else {
				window.location = "take_action.php?act="+act+"&step="+step+"&did="+did+"&dtid="+dtid;
			}
		break;	
	}
}

function takeActionForward(act, step, did, dtid, lno)	{
	var f = document.ta;
	if (document.getElementById("did")) did = f.did.value;
	switch (step)	{
		case 2: 
			document.ta.action = "take_action.php?act="+act+"&step="+step+"&did="+did; 
			check = checkTaLBA(1);
			if (check)	{
				document.ta.submit();
			}
		break;
		case 3: 
			if (act == "ccj" || act == "sdm")	{
				mode = "&mode="+act;
			} else {
				mode = "";
			}	
			document.ta.action = "take_action.php?act="+act+"&step="+step+"&did="+did+"&dtid="+dtid+mode; 
			check = checkTaLBA(2);
			if (check)	{
				document.ta.submit();
			}
		break;
		case 4: 
			lno = f.lno.value;
			document.ta.action = "take_action.php?act="+act+"&step="+step+"&did="+did+"&dtid="+dtid+"&lno="+lno; 
			document.ta.submit();
		break;
	}
}

function takeActionBack(act, step, did, dtid)	{
	document.ta.action = "take_action.php?act="+act+"&step="+step+"&did="+did+"&dtid="+dtid;
	document.ta.submit();
}

function legalTABack(did, dtid, act)	{
	document.pay.action = "take_action.php?act="+act+"&did="+did+"&dtid"+dtid+"&mode="+act+"&ta=1&step=3&lstep=5";
	document.pay.submit();
}

function setLimited()	{
	var f = document.rep_f;
	if (f.stype.value == "st")	{
		document.rep_f.action = "xml.php?act=search&stype=st";
	} else {
		document.rep_f.action = "xml.php?act=search";
	}
	document.rep_f.submit();
}

function checkTaLBA(step)	{
		var f = document.ta;
		switch (step)	{
			default:
			if (!f.cname.value.length && (!f.fname.value.length || !f.lname.value.length) && f.did.value == "0")	{
				alert("Please enter your either your debtor's company name or their full name!")
				return 0;
			} else {
				if (!f.hsname.value.length && !f.hsno.value.length)	{
					alert("Please enter either your debtor's building name or number!")
					return 0;
				}	else {
					if (!f.street.value.length)	{
						alert("Please enter your debtor's street!")
						return 0;
					}	else {					
						if (!f.town.value.length)	{
							alert("Please enter your debtor's town!")
							return 0;														
						}	else {
							if (!f.pcode.value.length)	{
								alert("Please enter your debtor's postcode!")
								return 0;
							}	else {													
								return 1;
							}
						}
					}
				}		
			}
				break;
			case "2":
			case 2:
				if (!f.ino.value.length && f.dtid.value == "0")	{
					alert("Please enter invoice/debt number!");
					return 0;
				} else {
					if (!f.ivalue.value.length)	{
						alert("Please enter invoice/debt amount!");
						return 0;
					} else {	
						if (!f.idate.value.length || f.idate.value == "/14/")	{
							alert("Please enter invoice/debt date!");
							return 0;
						} else {	
							if (!f.ddate.value.length || f.ddate.value == "/14/")	{
								alert("Please enter invoice/debt due date!");
								return 0;								
							} else {							
								return 1;
							}
						}
					}
				}																					
			break;
		}											
	}