// add trim function to string type

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


// check valid data entered in call back form
function check_submit(){

	areabox = document.callback.area;
	
	var error = 0;
	var nameStr = new String;
	var numberStr = new String;
	var msg1 = '';
	var msg2 = '';
	var msg3 = '';
	
	nameStr = document.callback.name.value;
	nameStr.trim();
	
	numberStr = document.callback.number.value;
	numberStr.trim();
	
	if(nameStr == '') {
	
		error++;
		msg1 = '--> You have not entered your name';
		
	}	

	if(numberStr == '') {
	
		error++;
		msg2 = '--> You have not entered a contact telephone number';
		
	}
	
	if(areabox.selectedIndex == 0) {
	
		error++;
		msg3 = '--> You have not selected your nearest location area';
				
	}
		
	if(error != 0){
	
		var plural = '';
		
		if(error > 1) { plural = 's'; }
		
			var msg = '';
			
			if(error == 1){
			
				msg = msg1 + msg2 + msg3;
				
			} else if (error == 2 && msg1 != '') {
			
				msg = msg1 + '\n' + msg2 + msg3;
				
			} else if (error == 2) {
			
				msg = msg2 + '\n' + msg3;
				
			} else if (error == 3) {
			
				msg = msg1 + '\n' + msg2 + '\n' + msg3;
				
			}
		
			alert("We're sorry, but the following problem" + plural + " occurred when sending your call back request:\n\n"+msg+"\n\nPlease correct your request and press the 'Send' button again. Thank you.");
		
	} else {
	
		document.callback.submit();
		return true;
		
	}

}
