var globalEval = function globalEval(src) {
    if (window.execScript) {
        window.execScript(src);
        return;
    }
    var fn = function() {
        window.eval.call(window,src);
    };
    fn();
};


	function JSParser (_stream)
	{
		this.stream = _stream;
		this.currentIndex = 0;
		this.jsCode="";
		this.htmlCode="";
	};

	JSParser.prototype.stream;
	JSParser.prototype.currentIndex;
	JSParser.prototype.jsCode;
	JSParser.prototype.htmlCode;

	JSParser.prototype.getJSCode = function ()
	{
		return this.jsCode;
	};

	JSParser.prototype.getHTMLCode = function ()
	{
		return this.htmlCode;
	};

	JSParser.prototype.getJavaScript = function (start)
	{
		var startTagIndex  = this.stream.indexOf ("[CWESTART]",start);
		if ( startTagIndex== -1 ) return false;
		else
		{
			var codeStart = startTagIndex+10;
			var endTagIndex = this.stream.indexOf ("[CWEEND]",start);
			if ( endTagIndex== -1 ) return false;
			else
			{
				this.jsCode+=this.stream.substring(codeStart,endTagIndex);
				this.currentIndex = endTagIndex+8;
			}
		}
		return true;
	};
	JSParser.prototype.getHTML = function (start)
	{
		var endTagIndex  = this.stream.indexOf ("[CWESTART]",start);
		if ( endTagIndex == -1) 
		{
			this.htmlCode+=this.stream.substring(start);
			this.currentIndex  = this.stream.length;
			return false;
		}
		else
		{
			this.htmlCode+=this.stream.substring(start,endTagIndex);
			this.currentIndex = endTagIndex-1;
			if ( this.stream.indexOf ("[CWEEND]",this.currentIndex) == -1 || this.stream.indexOf ("[CWESTART]",this.currentIndex) == -1) return false;
			else return true;
		}
		return true;
	};

	JSParser.prototype.inference = function ()
	{
		var flag = true;
		for (i = 0;flag && this.currentIndex < this.stream.length && i < 20;i++)
		{
			flag = this.getHTML(this.currentIndex);
			this.getJavaScript(this.currentIndex);
		}
		this.htmlCode = this.htmlCode.replace(/^\s+|\s+$/g, '') ;
	};

	JSParser.prototype.getSlicedHtmlCode = function ()
	{
		var temp1 = this.htmlCode;
		var temp = temp1.replace("\n","") ; 
		for ( ;temp != temp1; )
		{
			temp1 = temp;
			temp = temp1.replace("\n","");
		}
		temp = temp1.replace("\r","") ; 
		for ( ;temp != temp1; )
		{
			temp1 = temp;
			temp = temp1.replace("\r","");
		}
		return temp;
	};
	function packField (variable,value)
	{
		var sParam = encodeURIComponent (variable);
		sParam += "=";
		sParam += encodeURIComponent (value);
		return sParam;
	};

	function getFormRequestBody (oForm)
	{
		var aParams = new Array ();
		for (var i = 0 ; i < oForm.elements.length ;i++){
			var sParam;
			if (oForm.elements[i].type=="radio" ) 
			{
				if (oForm.elements[i].checked )
				{
					sParam = encodeURIComponent (oForm.elements[i].name);
					sParam += "=";
					sParam += encodeURIComponent (oForm.elements[i].value);
				}
			}
			else 
			{
				sParam = encodeURIComponent (oForm.elements[i].name);
				sParam += "=";
				if (oForm.elements[i].type=="checkbox"  )
				{
					 if (oForm.elements[i].checked)
						sParam += encodeURIComponent ("on");
					else sParam += encodeURIComponent ("");
				}
				else sParam += encodeURIComponent (oForm.elements[i].value);
			}
			aParams.push(sParam);
		}
		return aParams.join("&");
	};

	function servePostRequest(script,oForm,targetId)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
					}
				}
			};
			oXmlHttp.send(formBody);
	};

	function servePostRequestAndExecAfter(script,oForm,targetId,jsscript)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
						eval(jsscript);
					}
				}
			};
			oXmlHttp.send(formBody);
	};


	function servePostRequestAndAdjustTo(script,oForm,targetId,adjust_to)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
						document.getElementById(targetId).style.height = document.getElementById(adjust_to).offsetHeight+'px';
					}
				}
			};
			oXmlHttp.send(formBody);
	};

	function servePostRequestAndExecJS(script,oForm)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						globalEval(oXmlHttp.responseText);
//						eval (oXmlHttp.responseText);
					}
				}
			};
			oXmlHttp.send(formBody);
	};
	function syncServePostRequestAndExecJS(script,oForm,targetId)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.send(formBody);
			globalEval(oXmlHttp.responseText);
//			eval (oXmlHttp.responseText);
	};

	function servePostStreamRequest(script,stream,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
					}
				}
			};
			oXmlHttp.send(stream);
	};
	function syncServePostStreamAndExecJS(script,stream)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.send(stream);
			globalEval(oXmlHttp.responseText);

//			eval (oXmlHttp.responseText);
	};
	function servePostStreamRequestWithJSParser(script,stream,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "")
							document.getElementById(targetId).innerHTML = parser.getHTMLCode();
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
	//						eval (parser.getJSCode());
						}
					}
				}
			};
			oXmlHttp.send(stream);
	};
	function servePostRequestWithJSParser(script,oForm,targetId)
	{
			var formBody = "" ;
			if (oForm != "" ) formBody=getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "") document.getElementById(targetId).innerHTML = parser.getHTMLCode();
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
//							eval (parser.getJSCode());
						}
					}
				}
			};
			oXmlHttp.send(formBody);
	};


	function serveGetRequestWithJSParser(script,qs,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "") 
						{
							if (document.getElementById(targetId))
								document.getElementById(targetId).innerHTML = parser.getHTMLCode();
						}
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
//							eval (parser.getJSCode());
						}
					}
				}
			};
			oXmlHttp.send(null);
	};


	function syncServeGetRequestWithJSParser(script,qs,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.send(null);
			var parser = new JSParser(oXmlHttp.responseText);
			parser.inference();
			if ( parser.getSlicedHtmlCode() != "") document.getElementById(targetId).innerHTML = parser.getHTMLCode();
			if (parser.getJSCode()!="") 
			{
				globalEval(parser.getJSCode());
//				eval (parser.getJSCode());
			}
	};

	function serveGetRequestAndExecAfter(script,qs,targetId,jsscript)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			if ( qs == "" ) oXmlHttp.open("post",script,true);
			else oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
						eval (jsscript);
					}
				}
			};
			oXmlHttp.send(null);
	};

	function serveGetRequest(script,qs,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			if ( qs == "" ) oXmlHttp.open("post",script,true);
			else oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
				}
			};
			oXmlHttp.send(null);
	};


	function serveGetRequestAndAdjustTo(script,qs,targetId,adjust_to)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			if ( qs == "" ) oXmlHttp.open("post",script,true);
			else oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
						document.getElementById(targetId).style.height = document.getElementById(adjust_to).offsetHeight+'px';
					}
				}
			};
			oXmlHttp.send(null);
	};


	function SyncServeGetRequest(script,qs,targetId)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.send(null);
			if (document.getElementById(targetId)) document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
	};

	function serveGetRequestAndExecJS(script,qs)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						globalEval(oXmlHttp.responseText);
//						eval(oXmlHttp.responseText);
					}
				}
			};
			oXmlHttp.send(null);
	};


	function SyncServeGetRequestAndExecJS(script,qs)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.send(null);
			globalEval(oXmlHttp.responseText);

//			eval (oXmlHttp.responseText);
	};

	function serveGetRequestWithJSParserAndExecAfter(script,qs,targetId,jsscript)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("get",script+"?"+qs,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{
				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{
						
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "") 
						{
							if (document.getElementById(targetId))
							{
								document.getElementById(targetId).innerHTML = parser.getHTMLCode();
							}
						}
//						alert (parser.getHTMLCode());
//						alert (parser.getJSCode());
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
							//eval (parser.getJSCode());
						}
						eval (jsscript);

					}
				}
			};
			oXmlHttp.send(null);
	};


	function servePostRequestWithJSParserAndExecAfter(script,stream,targetId,jsscript)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{

				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{	
									
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "") document.getElementById(targetId).innerHTML = parser.getHTMLCode();
						
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
							//eval (parser.getJSCode());
						}
						eval (jsscript);

					}
				}
			};
			oXmlHttp.send(stream);
	};

	function serveFormPostRequestWithJSParserAndExecAfter(script,oForm,targetId,jsscript)
	{
			var oXmlHttp = zXmlHttp.createRequest ();
			if (oForm != "" ) formBody=getFormRequestBody(oForm);
			else return;
			oXmlHttp.open("post",script,true);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
			oXmlHttp.onreadystatechange =function()
			{

				if ( oXmlHttp.readyState == 4 )
				{
					if (oXmlHttp.responseText != "")
					{	
									
						var parser = new JSParser(oXmlHttp.responseText);
						parser.inference();
						if ( parser.getSlicedHtmlCode() != "") document.getElementById(targetId).innerHTML = parser.getHTMLCode();
						
						if (parser.getJSCode()!="") 
						{
							globalEval(parser.getJSCode());
							//eval (parser.getJSCode());
						}
						eval (jsscript);

					}
				}
			};
			oXmlHttp.send(formBody);
	};

	function SyncServeGetRequestAndReturnValue(script,qs)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		if ( qs != '' )
			oXmlHttp.open("get",script+"?"+qs,false);
		else oXmlHttp.open("get",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(null);
		return  oXmlHttp.responseText;
	};
	function SyncServePostRequestAndReturnValue(script,oForm)
	{
		var formBody = "" ;
		if (oForm != "" ) formBody=getFormRequestBody (oForm);
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(formBody);
		return  oXmlHttp.responseText;
	};

	function SyncServePostRequestStreamAndReturnValue(script,stream,targetId)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(stream);
		return  oXmlHttp.responseText;
	};
	function SyncServePostRequestAndReturnValue(script,oForm)
	{
		var formBody = "" ;
		if (oForm != "" ) formBody=getFormRequestBody (oForm);
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(formBody);
		return  oXmlHttp.responseText;
	};

	function SyncServePostRequestStreamAndReturnValue(script,stream,targetId)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(stream);
		return  oXmlHttp.responseText;
	};

	function syncServePostStreamRequest(script,stream,targetId)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(stream);
		document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
	};


	function syncServePostStreamRequestWithJSParser(script,stream,targetId)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("post",script,false);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=windows-1256");
		oXmlHttp.send(stream);
		document.getElementById(targetId).innerHTML = oXmlHttp.responseText;

		var parser = new JSParser(oXmlHttp.responseText);
		parser.inference();
		if ( parser.getSlicedHtmlCode() != "") document.getElementById(targetId).innerHTML = parser.getHTMLCode();
//              alert (parser.getHTMLCode());
		if (parser.getJSCode()!="")
		{
//              alert (parser.getJSCode());
			globalEval(parser.getJSCode());
		}
	};
	function serveRequestWithBlock(script,oForm,targetId)
	{
			var formBody = "";
			if ( oForm != null )
				formBody = getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXmlHttp.send(formBody);
			document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
	};

	function serveGetRequestWithBlock(script,qs,targetId)
	{
		var oXmlHttp = zXmlHttp.createRequest ();
		oXmlHttp.open("get",script+"?"+qs,false);
		oXmlHttp.send(null);
		document.getElementById(targetId).innerHTML = oXmlHttp.responseText;
	};
	function serveRequestAndEval(script,oForm,targetId)
	{
			var formBody = "";
			if ( oForm != null )
				formBody = getFormRequestBody (oForm);
			var oXmlHttp = zXmlHttp.createRequest ();
			oXmlHttp.open("post",script,false);
			oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oXmlHttp.send(formBody);
			eval(oXmlHttp.responseText);
	};
