function toggleDisplay(id1,id2) {
	// if id1 is hidden, then show it and hide id2. else do the opposite.
	if (document.getElementById(id1).style.display == 'none') {
		document.getElementById(id1).style.display = 'block'
		document.getElementById(id2).style.display = 'none'
	} else {
		document.getElementById(id1).style.display = 'none'
		document.getElementById(id2).style.display = 'block'
	}
	return false;
}

function toggleDisplayInline(id1,id2) {
	// if id1 is hidden, then show it and hide id2. else do the opposite.
	if (document.getElementById(id1).style.display == 'none') {
		document.getElementById(id1).style.display = 'inline'
		document.getElementById(id2).style.display = 'none'
	} else {
		document.getElementById(id1).style.display = 'inline'
		document.getElementById(id2).style.display = dtype
	}
	return false;
}

// For more explicit on and off switching
function turnDisplay(id, onOrOff)  {
    if (onOrOff == 'off') {
		 document.getElementById(id).style.display = 'none'
    } else if (onOrOff == 'on') {
		 document.getElementById(id).style.display = 'block'
    }
    return false;
}

// Yellow Fade Technique (tm 37 Signals)
var Color= new Array();
Color[2] = "ee";
Color[3] = "dd";
Color[4] = "cc";
Color[5] = "bb";
Color[6] = "aa";
Color[7] = "99";

function waittofade() {
	if (document.getElementById('fade')) {
    setTimeout("fadeIn(10)", 1000);
	 }
}

function fadeIn(where) {
    if (where >= 1) {
        document.getElementById('fade').style.backgroundColor = "#ffff" + Color[where];
		  if (where > 1) {
			  where -= 1;
			  setTimeout("fadeIn("+where+")", 200);
			} else {
			  where -= 1;
			  setTimeout("fadeIn("+where+")", 200);
			  document.getElementById('fade').style.backgroundColor = "transparent";
			}

    }
}

function popWindow(url,name,options){
        var ContextWindow = window.open(url,name,options);
        ContextWindow.opener = this;
        ContextWindow.focus();
}

var classElements = new Array();
function getElementsByClass(classname){
    var inc=0
    var alltags = document.all? document.all : document.getElementsByTagName("LI")

    for (i=0; i<alltags.length; i++){
        if (alltags[i].className==classname){
            classElements[inc] = alltags[i]
            inc += 1
        }
    }
    return classElements
}

function showMatureItems(){
    elements = getElementsByClass('mature')

    for (i=0; i<elements.length; i++){
        elements[i].style.display = 'list-item'
    }
    document.getElementById('matureLink').style.display = 'hidden'
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
        } else {
            begin += 2;
            var end = document.cookie.indexOf(";", begin);
            if (end == -1){
                end = dc.length;
            }
        }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, domain) {
      var curCookie = name + "=" + escape(value) +
              ((expires) ? "; expires=" + expires.toGMTString() : "") +
              "; path=/" +
              ((domain) ? "; domain=" + domain : "");
      document.cookie = curCookie;
}


function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" + 
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function validatePeriod(chooser, selectId, elementId) {
  var period = chooser.form.elements[selectId].value;
  if (period == 'i_know_exact_date') {
    var blockTimePeriod = document.getElementById(selectId);
    blockTimePeriod.style.display = "none";

    var blockExactDate = document.getElementById(elementId);
    blockExactDate.style.display = "block";
  }
}
