var xmlHttp = RequestObject();

// create xmlHTTP request for different browsers. 

	function RequestObject()

	{

		var xmlHttp;

		if(window.ActiveXObject)

		{

			var tryPossibleVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];

			

			for(i=0;i<tryPossibleVersions.length;i++) {

				try

				{

					xmlHttp = new ActiveXObject(tryPossibleVersions[i]);

					break;

				}

				catch (e)

				{

				xmlHttp = false;

				}

			}

		}

		else

		{

			try

			{

			xmlHttp = new XMLHttpRequest();

			}

			catch (e)

			{

			xmlHttp = false;

			}

		}

		if (!xmlHttp)

		alert("Error creating the XMLHttpRequest object.");

		else

		return xmlHttp;

	}

/**

	** script to send the request to server for status change.

	** @param : The php script name which will process the request, query string, http object

	**/

	function send_request(server_script, query_string)

	{



		try

		{

			

			if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) 

			{



			xmlHttp.open("POST", server_script, true);

			xmlHttp.setRequestHeader ("Content-Type","application/x-www-form-urlencoded");

			xmlHttp.onreadystatechange = function() {



					try

						{

							if (xmlHttp.readyState == 4)

							{

								if (xmlHttp.status == 200)

								{

									xmlResponse = xmlHttp.responseText;

									/** call function to hadle the response and update browser**/

									response_handler(xmlResponse);

									

								}

								else

								{

								alert("There was a problem accessing the server: " +

								xmlHttp.statusText);

								}

							}

						}

						catch (e)

						{

							// hide it

							//alert("Error in server response pls try after some time"+e.toString());

						}



				}

			

			xmlHttp.send(query_string);

			}

		}

		catch (e)

		{

			alert("Error : Uncaught :"+e.toString());

		}



	}

/** Function to handle all responses returned by controller php script **/

	function response_handler(xmlResponse)

	{

		try

		{

			//alert(xmlResponse);

			var parm = xmlResponse.split('*');

			if(parm.length<0) {

				alert('error');

				return;

			}

			var re = /\s*((\S+\s*)*)/;
   

			var tmp = parm[1].replace(re, "$1");
			var tmp2 = parm[0].replace(re, "$1");
							
			//alert(tmp)
			if(tmp == '1')
			{
				hide_processing_image();
				document.getElementById(tmp2).submit();
				if(tmp=='frmquote')
				{
					document.MM_returnValue=true;
				}
			}
			else if(tmp=='0')
			{
				hide_processing_image();
				alert("Please Enter Correct Captcha Code");
				return false;
			}
			

			
			
			
		}

		catch (e)

		{

			alert(e.toString());

		}

	}


		
	


/** function to show busy image at the top of form. This function will execute each time

	** when a request take place.

	**/



	function show_processing_image() 

	{

		var o_proc_image_div = document.getElementById('waiting_image');

		o_proc_image_div.style.display="inline";

	}



	/** This function will execute each time when a response will occure.

	**  hide the processing image showen by "show_processing_image" function.

	**/



	function hide_processing_image() 

	{

		var o_proc_image_div = document.getElementById('waiting_image');

		o_proc_image_div.style.display="none";

	}


	

	// Function to Save the comments
	function check_captcha(frmname)
	{
		try
		{
				
			show_processing_image();
			
			/*
			if(frmname=='feedback')
			{
				document.MM_returnValue=false;
			}
			*/
			var code = document.getElementById('captchacode').value;
			var query_string = "action=check_captcha&code="+escape(code)+"&frmname="+escape(frmname);
			
		
			var server_script = window.location.protocol+"//"+window.location.hostname+"/check_captcha.php";
			///alert(server_script);
			//alert(query_string);
			
			send_request(server_script, query_string);	
		}
		catch (e)
		{
			alert("Error while saving comment :" + e.toString());
		}
	}
	

	
	
	
	
	
	
	


	
