// JavaScript Document
function AjaxRequestbyDiv(div_id,queryString){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if (ajaxRequest.readyState == 0){
			var ajaxDisplay = document.getElementById(div_id);
			ajaxDisplay.innerHTML = "<b>Sending...</b>"; 
		}
		if (ajaxRequest.readyState == 1){
			var ajaxDisplay = document.getElementById(div_id);
			ajaxDisplay.innerHTML = "<b>Loading...</b>"; 
		}
		if (ajaxRequest.readyState == 2){
			var ajaxDisplay = document.getElementById(div_id);
			ajaxDisplay.innerHTML = "<b>Loaded...</b>"; 
		}
		if (ajaxRequest.readyState == 3){
			var ajaxDisplay = document.getElementById(div_id);
			ajaxDisplay.innerHTML = "<b>Ready!</b>"; 
		}
		if (ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(div_id);
			ajaxDisplay.innerHTML = ajaxRequest.responseText; 
		}
	}
	
	ajaxRequest.open("GET", queryString, true);
	ajaxRequest.send(null); 
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function in_array(needle,haystack)
{
	var exists = false;
	for (var i = 0; i < haystack.length; i++)
	{
		if(haystack[i] == needle) {
    		exists = true;
    	}
	}
	return exists;
}

function ays(action,thing,form_id,input_id,new_value) {
	
		var question = 'Are you sure you want to '+ action + ' this ' + thing + '?';
		var result = confirm(question);
		if (result) {
			document.getElementById(input_id).value = new_value;
			document.getElementById(form_id).submit();
		} 
		
}

function bg(id,color) {
	document.getElementById(id).style.backgroundColor = color;
}

function form_submit(form_id,input_id,set_id) {
	var change_value = document.getElementById(set_id).value;
	document.getElementById(input_id).value = change_value;
	document.getElementById(form_id).submit();
}

function form_submit_tinymce(form_id,input_id1,set_id1,input_id2,set_id2) {
	var change_value1 = document.getElementById(set_id1).value;
	var change_value2 = tinyMCE.getInstanceById(set_id2).getContent();
	document.getElementById(input_id1).value = change_value1;
	document.getElementById(input_id2).value = change_value2;
	document.getElementById(form_id).submit();
}

function hide_me(id) {
	document.getElementById(id).style.height = '0';
	document.getElementById(id).style.visibilty = 'hidden';
	document.getElementById(id).style.display = 'none';
}
