var xmlHttp;

function init_ajax() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function send_ajax(transfer_type,url,parameters) {
	xmlHttp.abort();
	if (transfer_type == "POST") {
		xmlHttp.open(transfer_type,url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	}
	else if (transfer_type == "GET") {
		if ( (parameters != null) || (parameters != "") ) {
			url = url+"?"+parameters;
		}
		xmlHttp.open(transfer_type,url,true);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(null);
	}
}

function edit(mod) {
	checked_box = 0;
	id_array = new Array();
	for (i = 0; i < document.getElementsByName('item_id[]').length; i++) {
		if (document.getElementsByName('item_id[]')[i].checked == true) {
			checked_box = checked_box + 1;
			id_array.push(document.getElementsByName('item_id[]')[i].value);
		}
	}
	if (checked_box == 0) { alert('no selection'); return; }
	if (checked_box > 1) { alert('only one item can be edited'); return; }
	id_item = id_array[0];
	window.location.href = "?mod="+mod+"&task=edit_item&item="+id_item;
}

function frontpage(formid,actionurl) {
	checked_box = 0;
	for (i = 0; i < document.getElementsByName('item_id[]').length; i++) {
		if (document.getElementsByName('item_id[]')[i].checked == true) {
			checked_box = 1;
			break;
		}
	}
	if (checked_box == 0) { alert('no selection'); return; }
	frm = document.getElementById(formid);
	frm.setAttribute("method","POST");
	frm.setAttribute("action",actionurl);
	frm.formaction.setAttribute("value","frontpage");
	frm.submit();
}

function publish(formid,actionurl) {
	checked_box = 0;
	for (i = 0; i < document.getElementsByName('item_id[]').length; i++) {
		if (document.getElementsByName('item_id[]')[i].checked == true) {
			checked_box = 1;
			break;
		}
	}
	if (checked_box == 0) { alert('no selection'); return; }
	frm = document.getElementById(formid);
	frm.setAttribute("method","POST");
	frm.setAttribute("action",actionurl);
	frm.formaction.setAttribute("value","publish");
	frm.submit();
}

function erase(formid,actionurl) {
	checked_box = 0;
	for (i = 0; i < document.getElementsByName('item_id[]').length; i++) {
		if (document.getElementsByName('item_id[]')[i].checked == true) {
			checked_box = 1;
			break;
		}
	}
	if (checked_box == 0) { alert('no selection'); return; }
	frm = document.getElementById(formid);
	frm.setAttribute("method","POST");
	frm.setAttribute("action",actionurl);
	frm.formaction.setAttribute("value","delete");
	frm.submit();
}

function saveorder(formid,actionurl) {
	for (i = 0; i < document.getElementsByName('item_id[]').length; i++) {
		document.getElementsByName('item_id[]')[i].checked = true;
	}
	frm = document.getElementById(formid);
	frm.setAttribute("method","POST");
	frm.setAttribute("action",actionurl);
	frm.formaction.setAttribute("value","saveorder");
	frm.submit();
}

function openFM() {
	win_height = screen.height/2;
	win_width = screen.width/2;
	pos_x = (screen.width/2) - (win_width/2);
	pos_y = (screen.height/2) - (win_height/2);
	window.open("../external/filemanager/","FM","width="+win_width+",height="+win_height+",left="+pos_x+",top="+pos_y+",scrollbars,status=no,menubar=no");
}

function openGALAdmin() {
	win_height = screen.height/2;
	win_width = screen.width/2;
	pos_x = (screen.width/2) - (win_width/2);
	pos_y = (screen.height/2) - (win_height/2);
	window.open("../external/gallery/admin/note.php","GAdmin","width="+win_width+",height="+win_height+",left="+pos_x+",top="+pos_y+",scrollbars,status=no,menubar=no");
}

function chgColor(obj,color){
	obj.style.backgroundColor = color;
}

function chCSS(obj,classname) {
	obj.setAttribute("class",classname);
}

function showTxt(txt){
    document.getElementById('viewMenu').innerHTML = txt;
}

function loadPg(mod){
    window.location.href="?mod="+mod;
}

function uppercase(obj) {
	obj.value = obj.value.toUpperCase();
}

function check_box(){
	if(document.getElementsByName('online')[0].checked == true){
		document.getElementById('onlineTxt').innerHTML = '<font color="green">Online</font>';
	}else{
		document.getElementById('onlineTxt').innerHTML = '<font color="red">Not online</font>';
	}
}