function HTMLvalidator(code){

	//var pattern = /<\/(([a-z]*[0-9]*)+)>/g;										//Match any closeing tag
	//var pattern = /<(([a-z]*[0-9]*)+( [^>]*)?\/?)>/g;								//Match any opening or self-closeing tag
	
	//var pattern = /(<\/(([a-z]*[0-9]*)+)>)|(<(([a-z]*[0-9]*)+( [^>]*)?\/?)>)/g; 	//Match all tags
	var pattern = /(<\/([a-z0-9]+)>)|(<([a-z0-9]+\s*([a-z0-9]+\=\"[^\"]*\"\s*)*)>)/g;		//Match non self-closeing tags
	var result = code.match(pattern);
	var RetVal=1;
	var str;
	var opened=new Array();
	var poptag;
	
	if(result){
		for(i = 0; i < result.length; i++) 
		{
			pattern = /<\/(([a-z0-9]*)+)>/
			if(result[i].match(pattern)){		//closeing tag discovered
				str=result[i].match(pattern)[0];
				tagname=str.substring(2,str.length-1);
				poptag=opened.pop();
				if(tagname!=poptag){
					alert("Unexpected closeing tag # "+(i+1)+" : "+tagname+"\nOpened tags: "+opened+","+poptag);
					RetVal=0;
					break;
				}
				
			}else{								//opening tag discovered
				pattern = /<([a-z0-9]+)/
				str=result[i].match(pattern)[0];
				tagname=str.substring(1,str.length);
				opened.push(tagname);
			}
		}
		if(opened.length>0){
			alert("Tags left open: "+opened);
			RetVal=0;
		}
	}
	return RetVal;
}
