// -----------------------------------------------------------------------------
// Ebscripts - Javascript file
// -----------------------------------------------------------------------------
var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;
// -----------------------------------------------------------------------------
// Hide Show
// -----------------------------------------------------------------------------
function show_hide(id) {
    var d = document.getElementById(id);
    if (d) {
	if (d.style.display=='' || d.style.display=='none') d.style.display='block';
	else d.style.display='none';
    }
}
function hide_show(id, id2) {
    var d = document.getElementById(id);
    var d2 = document.getElementById(id2);
    if (d) {
	if (d.style.display=='' || d.style.display=='block') d.style.display='none';
	else d.style.display='block';
    }
    if (d2) {
	if (d2.style.display=='' || d2.style.display=='none') d2.style.display='block';
	else d2.style.display='none';
    }
}
// -----------------------------------------------------------------------------
// Drop Down Menu
// -----------------------------------------------------------------------------
function mopen(id) {	
    // cancel close timer
    mcancelclosetime();
    // close old layer
    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose() {
    if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
	window.clearTimeout(closetimer);
	closetimer = null;
    }
}
function writeScreenResolutionCookie (curpage) {
    document.cookie="screen_resolution="+screen.width+"x"+screen.height;	 
    window.location.href=curpage;
}
// -----------------------------------------------------------------------------
// 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";
}
// -----------------------------------------------------------------------------
// 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 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) {
  var d = document.getElementById(id);
      for (var i = 1; i<=10; i++) {
          if (document.getElementById('menu'+i)) {document.getElementById('menu'+i).style.display='none';}
      }
  if (d) {d.style.display='block';}
}
// -----------------------------------------------------------------------------
// 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;
    }
}
// -----------------------------------------------------------------------------
// 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;
    }
}
// -----------------------------------------------------------------------------
// Function to update the custom housall
// -----------------------------------------------------------------------------
function update_custom_housall_form(root, name, value) {
	var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) { document.getElementById("custom_housall_form").innerHTML=xmlHttp.responseText; }
	}
	controlstr = root+"/control/customize_housall.php?name="+name+"&value="+value;
	xmlHttp.open("GET",controlstr,true);
	xmlHttp.send(null);
}
// -----------------------------------------------------------------------------
// Function to update the custom housall image
// -----------------------------------------------------------------------------
function update_custom_housall_image(root, name, value) {
	var xmlHttp = get_xmlHttp();
	xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) { document.getElementById("custom_housall_image").innerHTML=xmlHttp.responseText; }
	}
	controlstr = root+"/control/customize_housall.php?image=1&name="+name+"&value="+value;
	xmlHttp.open("GET",controlstr,true);
	xmlHttp.send(null);
}
// -----------------------------------------------------------------------------
// Delete a custom housall
// -----------------------------------------------------------------------------
function delete_from_custom_cart(root, uid) {
    msg="Are you sure you want to remove this HousAll unit from your cart?";
    if (window.confirm(msg)==true) {
            idstring = root+"/control/customize_housall.php?delete="+uid;
            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;
}

