// JavaScript Document
function setCookie(name,value) {
    var dstr=name+"="+value;
    document.cookie=dstr+"; path=/";
    window.location.reload();
}
// Create a Cookie
function bakeCookie_root(n,v) {
    document.cookie=n+"="+v+"; path=/";
    window.location.href=window.location.href
}
function altLanguage() {
	document.cookie="language_s=fr; path=/";
	//history.go(0);
    window.location.reload();
}
function defaultLanguage() {
	document.cookie="language_s=en; path=/";
	//history.go(0);
    window.location.reload();
}

function get_image(id,language)
{  
  var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) {
		document.getElementById("largeimage").innerHTML=xmlHttp.responseText;
      }
    }
	//controlstr = "http://bluenorth.no-ip.info/rccfdc/images/limage.php?id="+id+"&lan="+language;
    controlstr = "http://www.rccfdc.org/images/limage.php?id="+id+"&lan="+language;
    xmlHttp.open("GET",controlstr,true);
    xmlHttp.send(null);
}

function hl_image (id, flag) {
	if (flag==1) { 
		//document.getElementById(id).style.backgroundColor = '#FFFDc0'; 
		document.getElementById(id).style.borderColor = '#555599'; 
	}
	else { 
		//document.getElementById(id).style.backgroundColor = '#FFFFFF';
		document.getElementById(id).style.borderColor = '#CCCCCC'; 
	}
}
function get_content_list(cat,subcat,m,id,page)
{  
	var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) { document.getElementById("contentlist").innerHTML=xmlHttp.responseText; }
    }
	controlstr = "control/getcontent.php?c="+cat+"&s="+subcat+"&m="+m+"&id="+id+"&page="+page;
    xmlHttp.open("GET",controlstr,true);
    xmlHttp.send(null);
}

// Function to delete a listing from the database
function delete_listing (id, path) {
	string = "Are you sure you want to delete this entry?";
	if (window.confirm(string)) {
		idstring = "control/delete.php?id="+id+"&path="+path;
		window.location.href=idstring;		
	}
}

function delete_subcategory(cat,subcat,usergroup) {
	string = "Are you sure? All items in this subcategory will be lost.";
	if (window.confirm(string)) {
		idstring = "control/addsubcat.php?cat="+cat+"&subcat="+subcat+"&usergroup="+usergroup;
		window.location.href=idstring;
	}
}

function edit_subcategory(subcat,category,usergroup) {
	var newcat;	
	if (newcat=window.prompt("Old Subcategory: "+subcat, "Enter the name for the new subcategory")) {
		idstring = "control/addsubcat.php?cat="+category+"&subcat="+subcat+"&new="+newcat+"&usergroup="+usergroup;
		window.location.href=idstring;
	}
}

function check_username (username) {
	var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) { document.getElementById("unerror").innerHTML=xmlHttp.responseText; }
	}
	controlstr = "control/checkusername.php?un="+username;
	xmlHttp.open("GET",controlstr,true);
	xmlHttp.send(null);	
}

function get_member_list(sortmethod,toggle,checkall)
{  
	var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) { document.getElementById("memberlist").innerHTML=xmlHttp.responseText; }
    }
	controlstr = "control/getmemberlist.php?sort="+sortmethod+"&toggle="+toggle+"&checkall="+checkall;
    xmlHttp.open("GET",controlstr,true);
    xmlHttp.send(null);
}

function get_member(id)
{  
  var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
      if(xmlHttp.readyState==4) {
		document.getElementById("memberview").innerHTML=xmlHttp.responseText;
      }
    }
	controlstr = "control/getmember.php?id="+id;
    xmlHttp.open("GET",controlstr,true);
    xmlHttp.send(null);
}

// This function will return a XMLHttp connection
function get_xmlHttp () {
  var xmlHttp;
  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;  
	}}}
	return xmlHttp;
}

// Form Verification
function check_for_empty(value,divid,message) {
	if (value == "") return_message = message;	
	else return_message = "";
	document.getElementById(divid).innerHTML=return_message;
}
