function mc_login()
{
	form = document.getElementById('login-form');
	job_code = form.job_code.value;
	writeLoginCookie(job_code);
	//alert("log in in with job code " + job_code);
	document.location="/music_list/login_check.php";
}

function mc_logout()
{
	// destroyLoginCookie();
	
	// we don't kill the cookie any more because we have auto login
	
	//writeLoginCookie(0);
	parent.location="/mobileDisco.html";
}

function mc_admin_login(job_code)
{
	writeLoginCookie(job_code);
	//alert("log in in with job code " + job_code);
	document.location="/music_list/login_check.php";
}

function writeLoginCookie(value)
{
	var name="job_code";
	var hours = 24 * 30;
	
	// the path was changed to '/' to allow the auto login to work
	
	//var path = "/music_list/";
	var path = "/";
  var expire = "";
  
  // expire if value is 0
  
  
  if(value != 0)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
  }
  else
  {
	   expire = new Date((new Date()).getTime() - 60);
  }
    expire = "; expires=" + expire.toGMTString();
	path = "; path=" + path;
	
	
  document.cookie = name + "=" + escape(value) + expire + path;
}



function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}



/* auto executed code used for auto login */
/* wait 5 seconds before auto login */

window.setTimeout('setAutoLogin()', 5000);


function setAutoLogin()
{
	login_form = document.getElementById('login-form');
	if (login_form != null)
	{
		job_code = readCookie('job_code');
		if (job_code != '')
		{
			login_form.job_code.value = job_code;
		}
	}
}