global_vars = new Array;

function toggle_tab(tab_id) {
	switch(tab_id) {
		case "home":
			location.href	= "/";
			break;
		case "products":
			location.href	= "/products/";
			break;
		case "services":
			location.href	= "/services/";
			break;
		case "contact_crescent":
			location.href	= "/contact_crescent/";
			break;
	
	}
}


function ajax_content(url, div_id, callback_function) {
	var req = null;
	try { req = new XMLHttpRequest();	} catch (trymicrosoft) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) {
			try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) {
				req = null;
			}
		}
	}
	if (req == null) {
		alert("AJAX Error","Unable to create request object.");
		return;
	}
	
	// Retrieve data
	req.open('GET', url, true);
	req.onreadystatechange=function() {
		if (req.readyState==4) { 
			var content					= req.responseText;
			get_el(div_id).innerHTML	= content;
			if(typeof(callback_function) == "function")
				callback_function();		
		}
	}
	req.send(null)
	return "";
}

function contact_form() {
	content		= document.getElementById("two_col_left");

	document.getElementById("contact-status").className		= "display_block status";
	document.getElementById("contact-status").innerHTML		= "Sending Comments...";


	var queryString		= $("#form-contact").formSerialize();
	var response		= ajax_post("/contact_crescent/ajax_contact_submit/", queryString);
	contact_response 	= $.parseJSON(response);

	contact_function	= function() {
		if(typeof(contact_response["error"]) != "undefined") {
			document.getElementById("contact-status").className		= "display_none";
			document.getElementById("contact-status").innerHTML		= contact_response["error"];
			document.getElementById("contact-status").className		= "display_block error";
		} else {
			document.getElementById("two_col_left").innerHTML			= contact_response["success"];
		}
	}

	setTimeout("contact_function()",1000);
	
	// content.innerHTML		= "hello";
}


function ajax_post(url,parameters,callback_function) {
	req = null;
	try {
		req		= new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				req = null;
			}
		}
	}

	if (req == null) {
		salert("AJAX Error","Unable to create request object.");
		return;
	}

	// Retrieve data
	var sync_val		= (typeof(callback_function) == "function") ? true : false;
	req.open('POST', url, sync_val);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", parameters.length);
	req.setRequestHeader("Connection", "close");
	req.send(parameters);

	global_vars["ajax_callback"]		= callback_function;
	if(sync_val == true) 
		req.onreadystatechange = ajax_response;
	else {
		if(req.status == 200) {
			var http_value = req.responseText;
			if(http_value != "")
				return http_value;
		}
	}
}
