/* --------------------------------------------------------
 * MMG-CRM - developed for Fullhouse Group
 * Copyright (C) 2004-2006 MMG interactive
 * 
 * MMG interactive versioning:
 * ---------------
 * $Revision: 857 $
 * $Author: Mark $
 * $Date: 2010-02-17 09:40:51 +1100 (Wed, 17 Feb 2010) $ 
 * 
 * --------------------------------------------------------
 */


function ge(id) { 
	return document.getElementById(id); 
}

function show(id) {
	if (ge(id)) ge(id).style.display = '';
}

function hide(id) {
	if (ge(id)) ge(id).style.display = 'none';
}

function divreplace(id, text) {
	if (ge(id)) ge(id).innerHTML = text;
}

function divbefore(id, text) {
	if (ge(id)) ge(id).innerHTML = text + ge(id).innerHTML;
}

function divafter(id, text) {
	if (ge(id)) ge(id).innerHTML = ge(id).innerHTML + text;
}

function divremove(id) {
	if (ge(id)) ge(id).parentNode.removeChild(ge(id));
}

function autoParseJSON(s) {
	var obj = eval("(" + s + ")");
	if (obj.d.show) {
	 	for (x = 0; x < obj.d.show.length; x++) {
			show(obj.d.show[x]);
		}
	}
	if (obj.d.hide) {
		for (x = 0; x < obj.d.hide.length; x++) {
			hide(obj.d.hide[x]);
		}
	}
	if (obj.d.divremove) {
	 	for (x = 0; x < obj.d.divremove.length; x++) {
			divremove(obj.d.divremove[x]);
		}
	}
	if (obj.d.divreplace) {
	 	for (x = 0; x < obj.d.divreplace.length; x++) {
			divreplace(obj.d.divreplace[x][0], obj.d.divreplace[x][1]);
		}
	}
	if (obj.d.divbefore) {
	 	for (x = 0; x < obj.d.divbefore.length; x++) {
			divbefore(obj.d.divbefore[x][0], obj.d.divbefore[x][1]);
		}
	}
	if (obj.d.divafter) {
	 	for (x = 0; x < obj.d.divafter.length; x++) {
			divafter(obj.d.divafter[x][0], obj.d.divafter[x][1]);
		}
	}
}

function ajax($url, $vars, $object){
	if (window.XMLHttpRequest){
		var $class = new XMLHttpRequest();
	} else {
		var $class = new ActiveXObject("MSXML2.XMLHTTP.3.0");
	}
       
	$class.open("POST", $url, true);
	$class.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	$class.onreadystatechange = function() {
		if ($class.readyState == 4 && $class.status == 200) {
			if ($class.responseText){
				$obj = $class.responseText;
				$object($obj);
			}
		}
	}
	$class.send($vars);
}