/* GLOBAL vars */
//var url = 'http://212.143.234.216:8080/sugar/modules/Customers/sugar_by_pass/sbp_general.php';
var url = '/send_contact_us_form.php';
//var url = 'http://62.90.125.29:8090/darel_crm/modules/Customers/sugar_by_pass/sbp_general.php';
//var url ;
var send_params='';
var con_obj; // Connection object for Ajux request
var func_name; // the function name to execute after Ajux request

/*
/ open Ajux connection to server and execute URL with the params
/
*/
function	send_server_request	(method)
{
	//alert(url);
//	var obj = document.getElementById(id);
	if (window.XMLHttpRequest)
	{
		//var XmlHttp = new XMLHttpRequest();
		con_obj = new XMLHttpRequest();
	}   else    {
//		var XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		con_obj = new new ActiveXObject("Microsoft.XMLHTTP");
	}
	// for GET method
	if (method == 'GET')
	{
		var send_url = url + "?" + send_params ;
		//var send_url = url + send_params ;
	//	alert(send_url);
		con_obj.open("GET", send_url, false);
		con_obj.setRequestHeader("Content-type", "text/html");
		con_obj.setRequestHeader("charset", "UTF-8");
		con_obj.send(null);
	} else if (method == 'POST') {
	//	con_obj.open("POST", url, true);
		con_obj.open("POST", url, false);
		con_obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//	con_obj.setRequestHeader("Content-type", "text/html");
		con_obj.setRequestHeader("charset", "UTF-8");
	//	alert(send_params);
		con_obj.send(send_params);
		//con_obj.send(null);
	}
	var res = con_obj.responseText;
	alert(res);
	if (res == 1)
	{
		alert('There were an Error in sending your message ! Please try agine later.');
	}
/*
	var res = con_obj.responseText;
alert(res);
	con_obj.onreadystatechange=check_change;
	con_obj.getAllResponseHeaders();
	var res = con_obj.responseText;
alert(res);
//	alert('1');
//	con_obj.setRequestHeader("Content-length", parameters.length);
//	this.request.setRequestHeader("Connection", "close");
*/
}

/*
/ when the request status is Done and the server response is OK (200) then execute the function with the response text
/
*/
function	check_change	()
{
	try
	{
		// 
	if (con_obj.readyState == 4)
		{
			if (con_obj.status == 200)
			{
		//		var res = obj.getAllResponseHeaders();
				var res = unescape(con_obj.responseText);
				//alert(res);
				var str_eval = func_name + "(\"" + res +"\");";
	//			alert("str eval = " + str_eval);
				eval(str_eval);
			} else {
				var res = con_obj.getAllResponseHeaders();
				var status_text = con_obj.statusText;
				alert('status = ' + status_text);
			}
		} 
	} 
	catch (er)
	{
		alert(er);
	}
}

function	ajux_request_manager(type,method)
{
//	alert('type = ' + type);
	assemble_elements_manager(type);
	content_str = content_str.substr(0, content_str.length - 1);
	send_params = content_str;
	//alert(send_params);
	send_server_request(method);
}
