function scrollReports() {
	document.getElementById("deliveries2").scrollTop += 1;
	if(document.getElementById("deliveries2").scrollTop >= (document.getElementById("deliveries2").scrollHeight - document.getElementById("deliveries2").offsetHeight)) { document.getElementById("deliveries2").scrollTop = 0; }
	if (!reportsPaused) { window.setTimeout("scrollReports()", 50); }
}


function midd(text, pos, leng) {
	var outted="";
	for (m=(pos-1);m<(pos+leng-1);m++)
	{	outted+=text.charAt(m); }
	return outted;
}


function scrub(incoming) {
    var cleaned="";
	for (n=0;n<=incoming.length;n++) {
	if (incoming.charAt(n)=="`") { cleaned=cleaned+"'"; }
	else if (incoming.charAt(n)=="<") { cleaned=cleaned+" "; }
	else cleaned=cleaned+incoming.charAt(n);  }
	return cleaned; }

function checkNewUser() {
	responz="true"; 
	var messg="";
	var check=0;
	
	
	
	if (!document.newuser.agree.checked) { messg="Please indicate that you understand the Terms and Conditions."; responz=""; }

	if (!document.newuser.vercode.value) { messg="Please enter the human verification code shown in the block."; responz=""; }
	
	if (!document.newuser.fromwhere.value) { messg="Please indicate how you discovered our services."; responz=""; }
	
	if (document.newuser.pass.value!=document.newuser.passcheck.value) { messg="Your passsword is entered differently in both fields - they need to match."; responz=""; }
	for (h=0;h<document.newuser.pass.value.length;h++) { 
		if (document.newuser.pass.value.charCodeAt(h)<48 || document.newuser.pass.value.charCodeAt(h)>122 || (document.newuser.pass.value.charCodeAt(h)>57 && document.newuser.pass.value.charCodeAt(h)<65) || (document.newuser.pass.value.charCodeAt(h)>90 && document.newuser.pass.value.charCodeAt(h)<97)) { responz=""; messg="Please enter letters and numerals only into the password field.";  } } 
	if (!document.newuser.pass.value) { messg="Please enter a password."; responz=""; }
	if (document.newuser.pass.value.length<6) { messg="Please enter a password that is at least 6 characters in length."; responz=""; }

	for (h=0;h<document.newuser.usernam.value.length;h++) { 
		if (document.newuser.usernam.value.charCodeAt(h)<48 || document.newuser.usernam.value.charCodeAt(h)>122 || (document.newuser.usernam.value.charCodeAt(h)>57 && document.newuser.usernam.value.charCodeAt(h)<65) || (document.newuser.usernam.value.charCodeAt(h)>90 && document.newuser.usernam.value.charCodeAt(h)<97)) { responz=""; messg="Please enter letters and numerals only into the username field.";  } } 
	if (!document.newuser.usernam.value) { messg="Please enter a username."; responz=""; }
	if (document.newuser.usernam.value.length<6) { messg="Please enter a username that is at least 6 characters in length."; responz=""; }
	
	for (h=0;h<document.newuser.phone.value.length;h++) { 
		if (document.newuser.phone.value.charCodeAt(h)<48 || document.newuser.phone.value.charCodeAt(h)>57) { responz=""; messg="Please enter numerals only into the contact number field.";  } }
	if (document.newuser.phone.value.charAt(0)=="+") { responz=""; messg="No leading + allowed in the contact number field.";  }
	if (document.newuser.alerts.checked && document.newuser.phone.value.charAt(0)=="0") { responz=""; messg="No leading zeros allowed in the contact number field.";  }
	if (!document.newuser.phone.value) { messg="Please enter a contact number."; responz=""; }
	
	for (h=0;h<document.newuser.email.value.length;h++) { 
			if (document.newuser.email.value.charCodeAt(h)==64) { check=1; } 
			if (document.newuser.email.value.charCodeAt(h)==46 && check==1) { check=2; } } 
	if (check<2) { messg="Please enter a valid email address."; responz=""; }
	if (!document.newuser.email.value) { messg="Please enter your email address."; responz=""; }
	
	if (!document.newuser.business.value) { messg="Please enter your company name."; responz=""; }
	if (!document.newuser.firstname.value) { messg="Please enter your full name."; responz=""; }

	if (responz=="") { alert(messg); }
	else { document.newuser.mode.value="addingnew"; }
	return responz;
}

function checkUserUpdate() {
	responz="true"; 
	var messg="";
	var check=0;
	
	if (document.useredit.pass.value!=document.useredit.passcheck.value) { messg="Your passsword is entered differently in both fields - they need to match."; responz=""; }
	for (h=0;h<document.useredit.pass.value.length;h++) { 
		if (document.useredit.pass.value.charCodeAt(h)<48 || document.useredit.pass.value.charCodeAt(h)>122 || (document.useredit.pass.value.charCodeAt(h)>57 && document.useredit.pass.value.charCodeAt(h)<65) || (document.useredit.pass.value.charCodeAt(h)>90 && document.useredit.pass.value.charCodeAt(h)<97)) { responz=""; messg="Please enter letters and numerals only into the password field.";  } } 
	if (!document.useredit.pass.value) { messg="Please enter a password."; responz=""; }
	if (document.useredit.pass.value.length<6) { messg="Please enter a password that is at least 6 characters in length."; responz=""; }
	
	for (h=0;h<document.useredit.phone.value.length;h++) { 
		if (document.useredit.phone.value.charCodeAt(h)<48 || document.useredit.phone.value.charCodeAt(h)>57) { responz=""; messg="Please enter numerals only into the contact number field.";  } }
	if (document.useredit.phone.value.charAt(0)=="+") { responz=""; messg="No leading + allowed in the contact number field.";  }
	if (document.useredit.alerts.checked && document.useredit.phone.value.charAt(0)=="0") { responz=""; messg="No leading zeros allowed in the contact number field.";  }
	if (!document.useredit.phone.value) { messg="Please enter a contact number."; responz=""; }
	
	for (h=0;h<document.useredit.email.value.length;h++) { 
			if (document.useredit.email.value.charCodeAt(h)==64) { check=1; } 
			if (document.useredit.email.value.charCodeAt(h)==46 && check==1) { check=2; } } 
	if (check<2) { messg="Please enter a valid email address."; responz=""; }
	if (!document.useredit.email.value) { messg="Please enter your email address."; responz=""; }
	
	if (!document.useredit.business.value) { messg="Please enter your business name."; responz=""; }
	if (!document.useredit.lastname.value) { messg="Please enter your last name."; responz=""; }
	if (!document.useredit.firstname.value) { messg="Please enter your first name."; responz=""; }

	if (responz=="") { alert(messg); }
	else { document.useredit.mode.value="updateuser"; }
	return responz;
}

function checkNewDebtor() {
	responz="true"; 
	var messg="";
	
	for (h=0;h<document.newcontact.year.value.length;h++) { 
		if (document.newcontact.year.value.charCodeAt(h)<48 || document.newcontact.year.value.charCodeAt(h)>57) { responz=""; messg="Please enter numerals only into the year field.";  } } 
	
	for (h=0;h<document.newcontact.day.value.length;h++) { 
		if (document.newcontact.day.value.charCodeAt(h)<48 || document.newcontact.day.value.charCodeAt(h)>57) { responz=""; messg="Please enter numerals only into the day field.";  } } 

	for (h=0;h<document.newcontact.phone.value.length;h++) { 
		if (document.newcontact.phone.value.charCodeAt(h)<48 || document.newcontact.phone.value.charCodeAt(h)>57) { responz=""; messg="Please enter numerals only into the mobile number field.";  } }
	if (document.newcontact.phone.value.charAt(0)=="+") { responz=""; messg="No leading + allowed in the mobile number field.";  }
	if (document.newcontact.phone.value.charAt(0)=="0") { responz=""; messg="No leading zeros allowed in the mobile number field.";  }
	if (!document.newcontact.phone.value) { messg="Please enter the mobile number in international format."; responz=""; }
	if (!document.newcontact.firstname.value) { messg="Please enter a first name."; responz=""; }

	if (responz=="") { alert(messg); }
	else { document.newcontact.mode.value="newcontact"; }
	return responz;
}


function checkTell1() {
	responz="true"; 
	var messg="";
	var check='';
	
	for (h=0;h<document.tf.emailadd.value.length;h++) { 
		if (document.tf.emailadd.value.charCodeAt(h)==64) { check=1; } 
		if (document.tf.emailadd.value.charCodeAt(h)==46 && check==1) { check=2; } } 
	if (!document.tf.emailadd.value || document.tf.emailadd.value=='email address' || check<2) { messg="Please enter their email address."; responz=""; }
	
	if (!document.tf.name.value || document.tf.name.value=='your name') { messg="Please enter your name."; responz=""; }

	if (responz=="") { alert(messg); }
	else { document.tf.text.value=scrub(document.tf.name.value)+'`'+scrub(document.tf.emailadd.value); document.tf.submit(); }
	return responz;
}


function checkTell2() {
	responz="true"; 
	var messg="";
	var check='';
	
	if (!document.tellpal.messgtex.value) { messg="Please enter a short message."; responz=""; }
	
	for (h=0;h<document.tellpal.theiremail.value.length;h++) { 
		if (document.tellpal.theiremail.value.charCodeAt(h)==64) { check=1; } 
		if (document.tellpal.theiremail.value.charCodeAt(h)==46 && check==1) { check=2; } } 
	if (!document.tellpal.theiremail.value || check<2) { messg="Please enter their email address."; responz=""; }
	
	if (!document.tellpal.theirname.value) { messg="Please enter their name."; responz=""; }
	
	if (responz=="") { alert(messg); }
	else { document.tellpal.text.value=scrub(document.tellpal.theirname.value)+'`'+scrub(document.tellpal.theiremail.value)+'`'+scrub(document.tellpal.messgtex.value); document.tellpal.submit(); }
	return responz;
}


function checkTestimonial() {
	responz="true"; 
	var messg="";
	
	if (!document.test.showfirst.checked && !document.test.showlast.checked && !document.test.showcompany.checked && !document.test.showurl.checked) { messg="Please select at least one method of identification - anonymous posts will not be accepted."; responz=""; }
	
	if (!document.test.messg.value) { messg="Please enter your testimonial."; responz=""; }
	
	if (document.test.messg.value.length>2000) { messg="Please reduce the length of your testimonial."; responz=""; }
	
	if (responz=="") { alert(messg); }
	else { 	document.test.text.value=scrub(document.test.messg.value)+'`';
		if (document.test.showfirst.checked) { document.test.text.value+='1'+'`'; }
		else { document.test.text.value+='0'+'`'; }
		if (document.test.showlast.checked) { document.test.text.value+='1'+'`'; }
		else { document.test.text.value+='0'+'`'; }
		if (document.test.showcompany.checked) { document.test.text.value+='1'+'`'; }
		else { document.test.text.value+='0'+'`'; }
		if (document.test.showurl.checked) { document.test.text.value+='1'+'`'; }
		else { document.test.text.value+='0'+'`'; }
		document.test.submit(); }
	return responz;
}
