if(!String.prototype.trim){
    String.prototype.trim = function(){
        return this.replace(/^\s+/, '').replace(/\s+$/, '');    
    };
}
if(!String.prototype.startsWith){
	String.prototype.startsWith = function(pattern) {
	    return this.indexOf(pattern) === 0;
	};
}

jQuery(document).ready(function(){
	jQuery('#submitPingsForm').submit(function(){
		var s = jQuery("#url").val().trim();
		var a = s.split("\n");
		var line;
		var p="";
		var index = 1;
		var errors = 0;
		for(var i=0;i<a.length;i++){
			line = a[i].trim();  
			if( !line.startsWith("http://") ||
				 line.startsWith("http://localhost") ||
				 line.startsWith("http://127.0.0.1")
			  ){
				p+="Invalid URI at line no ["+index+"] ["+line+"]\n";
				errors++;
			}
			index++;
			if(errors>=20){
				p+="\nToo many wrong lines. Fix them and submit again\n";
				break;	
			}
		}

		if(errors<20){
			p+="\nFix above and submit again\n";
		}
		
		if(errors>0){
			alert( p );
			return false;
		}else{
			// replaced typed string with trimmed one 
			jQuery("#url").val(s);
			return true;
		}
	});
});