
function j21p_showPodcast(entryId) {
    var j21p_podcast = window.open("/weblogEntries/showPodcast.htm?entryId="+entryId,"j21p_podcast","width=480,height=300,scrollbars=no,resizable=no");
    j21p_podcast.focus();
}

function formHub(id) {
    switch(document.body.id) {
        case 'blog': return checkInput(); break;
    }
    return true;
}

function formHubAjax(id, submitFunction) {
  return formHub(id) & submitFunction() & false;
}

function buttonHub(buttonObject) {
    return true;
}

function checkInput() {
    var errorMessage = '';
    try {

        var userName = document.getElementsByName("userName")[0];
        var email = document.getElementsByName("email")[0];
        var homepage= document.getElementsByName("homepage")[0];

        var hasEmail;
        var hasHomepage;

        if (!(userName.value != null & userName.value != ""))
            errorMessage += "Bitte geben sie einen Namen an." + "\n";

        if ( (email.value == null || email.value == "") & (homepage.value == null || homepage.value == ""))
            errorMessage += "Bitte geben sie entweder eine gültige E-Mail-Adresse oder eine Homepage an." + "\n";

        var emailAddress;
        if ((emailAddress = email.value) != null) {
            if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddress)))
                errorMessage += "Bitte geben sie eine gültige E-Mail-Adresse ein.";
        }

        var securityCode = document.getElementsByName("securityCode")[0];

        if (!(securityCode.value != null & securityCode.value != ""))
            errorMessage += "Bitte geben sie den Sicherheitscode ein.";

    } catch (e) {
    }


    if (errorMessage != '') {
        alert(errorMessage);
        return false;
    }
    return true;
}
function renderCommentPreview(el) {
	document.getElementById('commentpreview').innerHTML=el.value.split(/\n/).join('<br />');
}

function bodyHub(id) {
	return true;
}

// photoblogs

function j21p_photo_addImage(entryId) {
	indexList[entryId] = entryList.length;
	entryList.push(entryId);
}

function j21p_photo_hasNextImage(entryId) {
	var index = indexList[entryId];
	if (index>=entryList.length-1) return false;
	return true;
}
function j21p_photo_hasPreviousImage(entryId) {
	var index = indexList[entryId];
	if (index<1) return false;
	return true;
}
function j21p_photo_nextImage(entryId,weblogRootURL) {
	var index = indexList[entryId];
	var newLocation;
	if (index<0) newLocation = entryList[0];
	else if (index>=entryList.length-1) newLocation = entryList[entryList.length-1];
	else newLocation = entryList[index+1];
	newLocation = weblogRootURL + '/weblogEntry/'+newLocation;
	document.location = newLocation;
}
function j21p_photo_previousImage(entryId,weblogRootURL) {
	var index = indexList[entryId];
	var newLocation;
	if (index<=1) newLocation = entryList[0];
	else if (index>entryList.length) newLocation = entryList[entryList.length-1];
	else newLocation = entryList[index-1];
	newLocation = weblogRootURL + '/weblogEntry/'+newLocation;
	document.location = newLocation;
}
function j21p_photo_checkNavi(entryId) {
	if (document.getElementById("j21p_photoBack")) { if (!j21p_photo_hasPreviousImage(entryId)) { document.getElementById("j21p_photoBack").style.display = "none"; } }
	if (document.getElementById("j21p_photoNext")) { if (!j21p_photo_hasNextImage(entryId)) { document.getElementById("j21p_photoNext").style.display = "none"; } }
}
function j21p_socialWeb(type,url,title,text) {
	switch(type) {
		case 'digg':
			var gotourl = "http://digg.com/submit?phase=2&url="
			 + encodeURI(url)
			 + "&title="
			 + encodeURI(title)
			 + "&bodytext="
			 + encodeURI(text);
			break;
		case 'delicious':
			var gotourl = "http://del.icio.us/post?v=4&noui&jump=close&url="
			 + encodeURI(url)
			 + "&title="
			 + encodeURI(title);
			break;
	}
	var socialwin = window.open(gotourl);
	socialwin.focus();
}

function j21p_displayPrintVersion(entryId) {
  if (window.open){
    var printPopup = window.open("/weblogEntries/printView?entryId=" + entryId, "printView", "width=600,height=400,status=yes,scrollbars=yes,resizable=yes");
    printPopup.focus();
    return true;
  }
  return false;
}

function j21p_toggleComments(commentsDiv) {
  var comments = document.getElementById(commentsDiv);
  if (comments) {
    var commentsStyle = comments.style;
    if (commentsStyle.display == 'none') {
      commentsStyle.display = '';
    } else {
      commentsStyle.display = 'none';
    }
  }
}

function j21p_toggleTrackbacks(trackbacksDiv) {
  var trackbacks = document.getElementById(trackbacksDiv);
  if (trackbacks) {
    var trackbacksStyle = trackbacks.style;
    if (trackbacksStyle.display == 'none') {
      trackbacksStyle.display = '';
    } else {
      trackbacksStyle.display = 'none';
    }
  }
}

