function checkFrame(directory, level) {
  if (top == self && confirm( "You have linked directly to a page in Claudia's Diversity. Do you want to restore the full menus?") ) {
	var locn = "";
	for (var i = 0; i < level; i++) { locn += "../"; }

	if( directory.length > 0 ) directory += "/";

	locn += getHomepage()
	locn += "?page="+directory+location.pathname.substring( location.pathname.lastIndexOf("/")+1 );
    self.location.href = locn;
  }
}

function setVis( name ) {
	index = document.cookie.indexOf(name+'-cookie=');
	if( index < 0 ) {
		showSection(name);
	}
	else {
		index += ((name+'-cookie=').length);
	    end = document.cookie.indexOf(";", index);
		if (end == -1) end = document.cookie.length;
		value = document.cookie.substring(index, end);
		if( value == "hide" ) {
			hideSection(name);
		}
		else if( value == "show" ) {
			showSection(name);
		}
	}
}

function hideSection( which ) {
	document.getElementById(which).style.display = "none";
	document.getElementById(which+"-r").style.display = "block";
	introCookie( which, "hide" );
}

function showSection( which ) {
	document.getElementById(which).style.display = "block";
	document.getElementById(which+"-r").style.display = "none";
	introCookie( which, "show" );
}

function introCookie( name, value ) {
	var expireDate = new Date ();
	expireDate.setTime(expireDate.getTime() + (365 * 24 * 3600 * 1000));
	document.cookie = name+'-cookie='+value+'; expire='+expireDate.toGMTString()
}

function getHomepage() {
  if (document.all) {
	// IE4+ code
    // note, this code would also run in IE5+, which has partial support for the W3C DOM. 
	// You could also add check for !DOM here (&& !(document.getElementById)) and 
    // equate dissimilar IE/W3C DOMs with prototype function, and run all IE5+/NS6+ browsers with
    // only DOM-standards-compliant code. IE5+  browsers would then drop down to third elseif below.
    version=0
    if (navigator.appVersion.indexOf("MSIE")!=-1){
      temp=navigator.appVersion.split("MSIE")
      version=parseFloat(temp[1])
    }	  
	
	if( version >= 6 ) return "homepage.html";
	return "basic_index.html";
  } else if (document.layers) {
    // NS4+ code 
    return "basic_index.html";
  } else if (document.getElementById) {
	// NS6+ code
    // and IE5+ code you flatten differences 
    // between MS DOM and W3C DOM
    return "homepage.html";
  } 
}

function clearMenus() {
	if( top.ypSlideOutMenu ) top.ypSlideOutMenu.hideAll();
}

function getCookie(NameOfCookie) {
  if (document.cookie.length > 0) {
    begin = document.cookie.indexOf(NameOfCookie+"=");
    if (begin != -1) {
      begin += NameOfCookie.length+1;
      end = document.cookie.indexOf(";", begin);
      if (end == -1) end = document.cookie.length;
      
	  return unescape(document.cookie.substring(begin, end)); 
    }
  }
  return null;
}

function setCookie(NameOfCookie, value, expiredays) {
  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  document.cookie = NameOfCookie + "=" + escape(value) +
                   ((expiredays == null) ? "" : "; expires=" + 
	               ExpireDate.toGMTString());
}

function needToLocateUser() {
  var cookieEnabled=(navigator.cookieEnabled)? true : false

  //if not IE4+ nor NS6+
  if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled) { 
    document.cookie="testcookie"
    cookieEnabled=(document.cookie=="testcookie")? true : false
    document.cookie="" //erase dummy value
  }

  if( !cookieEnabled ) return false; // We can't set cookies, so assume the US

  if( getCookie("locale") != null ) return false; // The user has told us

  return true;
}

function showMenubar() {
  var ie = document.all ? 1 : 0
  var ns4 = document.layers ? 1 : 0
  var dom = document.getElementById ? 1 : 0
  
  var menuId="menubar"
  var menubar = dom ? d.getElementById(menuId) : ie ? d.all[menuId] : d.layers[menuId]

  if (ns4) {
	menubar.visibility="visible"
  }
  else {
	menubar.style.visibility="visible"
  }
}

function checkContent() {
	if( needToLocateUser() ) {
		window.frames['content'].location = "location.html";
	}
	else goHome()
}

function goHome() {
   showMenubar();

   var start = -1

   if( location.search.length > 0 ) {
	  start = location.search.indexOf("page=");
	  var end = location.search.indexOf(";");
	  if( end < 0 ) end = location.search.length;
   }

   var dest = "welcome.html";

   if( start >=0 ) {
	  dest = location.search.substring( start+5, end );
   }
   
   setTimeout( "window.frames['content'].location = '"+dest+"'", 200 );
}

function welcomeTo( location ) {
	setCookie( "locale", location, 90 );
	goHome();
}

function enterSite( location ) {
	setCookie( "locale", location, 90 );
    setTimeout( "window.location = '"+getHomepage()+"'", 200 );
}
