/****************************************************
*	Ajax.js											*
* helpers functions to be used along with ajax		*
* applications or framework							*
*													*
* coded by: Mostafa E. Saleh (msaleh83@gmail.com	*
*	Dec 26	2007 - 10:19 am							*						  
/****************************************************/


/* to solve the problem that browser doesn't parse javascript 
/* inside a requested page by ajax, i exctract the javascript from its contents, then eval it in the main page
*/
function parseJS(htmlString)
{
	if(htmlString == '')	return 0;
	 var re = /<script\b.*?>([\s\S]*?)<\//ig; // assumes HTML well formed	and then loop through it as:
	 var matchs;
	 var contents = "";
	 var head1;
	 var scriptTag;
	 while (matchs = re.exec(htmlString)) {
	  contents = contents + matchs[1];		  
	 }
	 if(contents == "")	return;
	 var head1 = document.getElementsByTagName('head').item(0);
	 var scriptTag = document.getElementById('loadScript');
	 if(scriptTag) head1.removeChild(scriptTag);
	 script1 = document.createElement('script');
	 script1.text = contents;
	 script1.type = 'text/javascript';
	 script1.id = 'loadScript';
	 head1.appendChild(script1);
}
