// JavaScript Document
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function hl_element (id, flag) {
	if (flag==1) { 
		document.getElementById(id).style.backgroundColor = '#FFFDD0'; 
		document.getElementById(id).style.border = '1px solid #AAAAAA'; 

	}
	else { 
		document.getElementById(id).style.backgroundColor = '#FFFFFF'; 
		document.getElementById(id).style.border = '1px solid #CCCCCC'; 
	}
}
function open_image(id) {
	lstr="index.php?p=gallery&image="+id;
	window.location=lstr;
}
function open_gallery(id) {
	lstr="index.php?p=gallery&gallery="+id;
	window.location=lstr;
}
// Function to delete a listing from the database
function delete_listing (id, path) {
	string = "Are you sure you want to delete this listing?";
	if (window.confirm(string)) {
		idstring = "control/delete.php?id="+id+"&path="+path;
		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;
}
