// -----------------------------------------------------------------------------
// Ebscripts - Javascript file
// -----------------------------------------------------------------------------
// Create a Cookie
// -----------------------------------------------------------------------------
function bakeCookie(n,v) {
    document.cookie=n+"="+v+";";
    link = window.location.href;
    newlink = link.split("#")[0];
    window.location.href=newlink;
}
// -----------------------------------------------------------------------------
// Change text size
// -----------------------------------------------------------------------------
function resizeText(multiplier) {
    p = document.getElementById("textsize");
    if (p.style.fontSize == "") {
	p.style.fontSize = "1.0em";
    }
    p.style.fontSize = parseFloat(p.style.fontSize) + (multiplier * 0.2) + "em";
}
// -----------------------------------------------------------------------------
// Delete secure post
// -----------------------------------------------------------------------------
function delete_secure_post (id, root) {
    msg="Are you sure you want to delete this item?";
    if (window.confirm(msg)==true) {
            idstring = root+"/index.php?delete-secure-post="+id;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// Delete a page from the content database
// -----------------------------------------------------------------------------
function delete_page(id) {
    msg="Are you sure you want to delete this page?";
    if (window.confirm(msg)==true) {
            idstring = "content/control/delete_content.php?m=page&id="+id;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// Drop down menu
// -----------------------------------------------------------------------------
function show(id, nid, root) {
    var d = document.getElementById(id);
    var nd = document.getElementById(nid);
    for (var i = 0; i<=20; i++) {
      if (document.getElementById('menu'+i)) {
	  document.getElementById('menu'+i).style.display='none';
	  document.getElementById('nav'+i).style.backgroundImage='none';
      }
    }
    if (d) {
      d.style.display='block';
      nd.style.backgroundImage='url('+root+'/images/bg/mainnav_bg.png)';
      nd.style.backgroundPosition='0% 100%';
      nd.style.backgroundRepeat='repeat-x';
    }
}
// -----------------------------------------------------------------------------
// Sitemap drop down
// -----------------------------------------------------------------------------
function show_sm(id) {
    var d = document.getElementById(id);
    if (d) {
	/*
	if (d.style.display=='none') d.style.display='block';
	else if (d.style.display=='block') d.style.display='none';
	*/
	if (d.style.display=='' || d.style.display=='none') d.style.display='block';
	else d.style.display='none';
    }
}
// -----------------------------------------------------------------------------
// Show the form to email someone
// -----------------------------------------------------------------------------
function show_mail (id) {
    var d = document.getElementById("mform"+id);
    if (d) {
	/*
	if (d.style.display=='none') d.style.display='block';
	else if (d.style.display=='block') d.style.display='none';
	*/
	if (d.style.display=='' || d.style.display=='none') d.style.display='block';
	else d.style.display='none';
    }
}
// -----------------------------------------------------------------------------
// Delete a subcategory from the content database
// -----------------------------------------------------------------------------
function delete_subcategory(id) {
    msg ="Are you sure you want to delete this subcategory?\n";
    msg+="All pages and sub-subcategories in this subcategory will be deleted!\n";
    msg+="Hit OK to continue";
    if (window.confirm(msg)==true) {
            idstring = "content/control/delete_content.php?m=subcategory&id="+id;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// Calendar Popups
// -----------------------------------------------------------------------------
function show_calpopup(id) {
  var d = document.getElementById(id);
      for (var i = 1; i<=31; i++) {
          if (document.getElementById('calpopup'+i)) {document.getElementById('calpopup'+i).style.display='none';}
      }
  if (d) {d.style.display='block';}
}
// -----------------------------------------------------------------------------
// Delete a sub-subcategory from the content database
// -----------------------------------------------------------------------------
function delete_subsubcategory(id) {
    msg ="Are you sure you want to delete this subsubcategory?\n";
    msg+="All pages in this subsubcategory will be deleted also!\n";
    msg+="Hit OK to continue";
    if (window.confirm(msg)==true) {
            idstring = "content/control/delete_content.php?m=subsubcategory&id="+id;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// Delete a draft page
// -----------------------------------------------------------------------------
function delete_draft_page(id,cp) {
    msg="Are you sure you want to delete this draft?";
    if (window.confirm(msg)==true) {
            idstring = "content/control/delete_draft.php?id="+id+"&cp="+cp;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// Delete a member from the members database
// -----------------------------------------------------------------------------
function delete_member(id) {
    msg = "Are you sure you want to delete this member?";
    if (window.confirm(msg)) {
            idstring = "control/members/member_control.php?m=delete&id="+id;
            window.location.href=idstring;
    }
}
// -----------------------------------------------------------------------------
// 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;
}
// -----------------------------------------------------------------------------
// Timer function
// -----------------------------------------------------------------------------
function polling_timer_ajax(root) {
    if (1==1) {
	output_election_results_ajax(root);
	t = setTimeout(function(){polling_timer_ajax(root)},2000);
    }
}
// -----------------------------------------------------------------------------
// Output Election Results
// -----------------------------------------------------------------------------
function output_election_results_ajax (root) {
    var xmlHttp = get_xmlHttp();
    xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) { document.getElementById("election_results").innerHTML=xmlHttp.responseText; }
    }
    controlstr = root+"/data/election_results.php";
    xmlHttp.open("GET", controlstr, true);
    xmlHttp.send(null);
}

