﻿function checknojunk(test){
	var tbox=new getObj("item_name_1");
	tboxv=tbox.obj.value.toLowerCase();
	var errm=new getObj("errm");
	if(tboxv.length<4){
		errm.obj.innerHTML= "You must put something meaningful in the text box, eg the invoice number or a short description of what you are paying for.";
		return false; 
	
	}
	if(tboxv.indexOf("<a ")>-1){
		
		errm.obj.innerHTML= "Please do not put links to websites under what the payment is for - for that makes it look like you're trying to send out junk mails - and you wouldn't be such a boring timewaster as to want to do that now, would you?";
		return false; 
	} else {
		return checkmoneyvalue(errm, test);
	}

}

function checkmoneyvalue(errm, test){
	var goodstring="|.0123456789";
	var mbox=new getObj("amount_1");
	mboxv=mbox.obj.value;
	if(!mboxv.length){
		
		errm.obj.innerHTML= "A blank amount to pay is not meaningful.";
		return false;
	} 
	var ch1;
	var dotpos=-1;
	var pos1=-1;
	var value=0;
	var firstchar=-1;
	for(var i=0; i<mboxv.length;i++){
		ch1=mboxv.substr(i,1);
		pos1=goodstring.indexOf(ch1);
		if(!pos1){
			
			if(ch1=="-"){
				errm.obj.innerHTML="You may not specify a negative amount.";
			} else {	
				errm.obj.innerHTML= "The amount needs to be a number.";
			}	
			return false;
		}
		if(ch1=="."){
			if(dotpos>-1){
				
				errm.obj.innerHTML= "Only one decimal point in the number, please.";
				return false;			
			}
			dotpos=i;	
	
		} else {
			if((firstchar<0)&&(ch1>0)){
				firstchar=i;
			}
			value=(value*10)+ch1;
		}
	}
	if(dotpos>-1){
		if(dotpos==(mboxv.length-1)){
			mboxv=mbxoxv.substr(0,mboxv.length-1);
		} else if(dotpos<(mboxv.length-3)){
			errm.obj.innerHTML= "Too many numbers after the decimal point.";
			return false;			
		} else if(dotpos==(mboxv.length-2)){
			errm.obj.innerHTML= "Too few numbers after the decimal point.";
			return false;			
				
			
		}
	}	

	if(!parseFloat(value)){
		
		errm.obj.innerHTML= "Amount must be at least 1.00";
		return false;			
	}	
	var hbox=new getObj("quantity_1");
	
	hbox.obj.value="1";
	
	return true;
}
