function toggle(id) {
	if(document.getElementById(id).style.display != "block") {
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getArticle(article,num){
	var sendParams = "article=" + article + "&num=" + num;
	http.open("post","http://my.easander.com/getArticle.php");
	http.onreadystatechange = handleResponses; 
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send(sendParams);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleResponses(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		var article = "";
		var data = "";
		var update = response.split('|');
            	article = update[0];
            	data = update[1];
            	
		if (data != document.getElementById(article).innerHTML) {
			document.getElementById(article).innerHTML = data;
		}
	}
}


// remote scripting library
		// (c) copyright 2005 modernmethod, inc
		var sajax_debug_mode = false;
		var sajax_request_type = "POST";
		var sajax_target_id = "";
		var sajax_failure_redirect = "";
		
		function sajax_debug(text) {
			if (sajax_debug_mode)
				alert(text);
		}
		
 		function sajax_init_object() {
 			sajax_debug("sajax_init_object() called..")
 			
 			var A;
 			
 			var msxmlhttp = new Array(
				'Msxml2.XMLHTTP.5.0',
				'Msxml2.XMLHTTP.4.0',
				'Msxml2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP');
			for (var i = 0; i < msxmlhttp.length; i++) {
				try {
					A = new ActiveXObject(msxmlhttp[i]);
				} catch (e) {
					A = null;
				}
			}
 			
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				sajax_debug("Could not create connection object.");
			return A;
		}
		
		var sajax_requests = new Array();
		
		function sajax_cancel() {
			for (var i = 0; i < sajax_requests.length; i++) 
				sajax_requests[i].abort();
		}
		
		function sajax_do_call(args) {
			var i, x, n;
			var uri;
			var post_data;
			var target_id;
			
			sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
			target_id = sajax_target_id;
			if (typeof(sajax_request_type) == "undefined" || sajax_request_type == "") 
				sajax_request_type = "GET";
			
			uri = "http://my.easander.com/getArticle.php";
			if (sajax_request_type == "GET") {
			
				uri += "?article=" + args[0];
				uri += "&num=" + args[1];
				uri += "&rsrnd=" + new Date().getTime();
				
				post_data = null;
			} 
			else if (sajax_request_type == "POST") {
				post_data = "article=" + args[0];
				post_data += "&num=" + args[1];
				post_data += "&rsrnd=" + new Date().getTime();
			}
			else {
				alert("Illegal request type: " + sajax_request_type);
			}
			
			x = sajax_init_object();
			if (x == null) {
				if (sajax_failure_redirect != "") {
					location.href = sajax_failure_redirect;
					return false;
				} else {
					sajax_debug("NULL sajax object for user agent:\n" + navigator.userAgent);
					return false;
				}
			} else {
				x.open(sajax_request_type, uri, true);
				// window.open(uri);
				
				if (sajax_request_type == "POST") {
					x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
					x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
				
				sajax_requests[sajax_requests.length] = x;
				
				x.onreadystatechange = function() {
					if (x.readyState != 4) 
						return;

					sajax_debug("received " + x.responseText);
				
					try {
						var response = x.responseText;
						/* And now we want to change the product_categories <div> content.
							we do this using an ability to get/change the content of a page element 
							that we can find: innerHTML. */
						var article = "";
						var data = "";
						var update = response.split('|');
						article = update[0];
						data = update[1];

						if (data != document.getElementById(article).innerHTML) {
							document.getElementById(article).innerHTML = data;
						}
					} catch (e) {
						document.getElementById(args[0]).innerHTML = "Loading failed!  Click <a href=\"javascript:request('" + args[0] + "',10)\">here to retry</a>";
					}
				}
			}
			
			sajax_debug(" uri = " + uri + "/post = " + post_data);
			x.send(post_data);
			sajax_debug(" waiting..");
			delete x;
			return true;
		}
		
				
		// wrapper for rssReader		
		function x_rssReader() {
			sajax_do_call(x_rssReader.arguments);
		}
		
		
	function chooseSearch()
	{ 
		s = document.searchForm.engine.options[document.searchForm.engine.selectedIndex].value + document.searchForm.keywords.value;
		location = s;
	}
	
	function request(article,max) {
		if(document.getElementById(article).innerHTML != "Loading...") {
			document.getElementById(article).innerHTML = "Loading...";
		}
		x_rssReader(article,max,handleResponse);
	}

	function handleResponse(response) {
		var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
        }
}

var activeTab = "news";

function initialize() {
	document.getElementById(activeTab + "-div").style.backgroundPosition = "0% -42px";
	document.getElementById(activeTab + "-span").style.backgroundPosition = "100% -42px";
	document.getElementById(activeTab).style.display = "block";
}

function activateTab(id) {
	document.getElementById(activeTab + "-div").style.backgroundPosition = "0% 0px";
	document.getElementById(activeTab + "-span").style.backgroundPosition = "100% 0px";
	document.getElementById(id + "-div").style.backgroundPosition = "0% -42px";
	document.getElementById(id + "-span").style.backgroundPosition = "100% -42px";
	document.getElementById(activeTab).style.display = "none";
	activeTab = id;
	document.getElementById(activeTab).style.display = "block";
}

function swapTabs(id,dir) {
	if(dir == "in") {
		document.getElementById(id + "-div").style.backgroundPosition = "0% -42px";
		document.getElementById(id + "-span").style.backgroundPosition = "100% -42px";
	} else if(activeTab != id) {
		document.getElementById(id + "-div").style.backgroundPosition = "0% 0px";
		document.getElementById(id + "-span").style.backgroundPosition = "100% 0px";
	}
}

