﻿var _text = 'z.B. Titel, Autor, Verlag';
$(document).ready(function () {
    $(".submit_freetext").each(function () {
        if ($(this).attr('value') == '') { $(this).attr('value', _text); $(this).css({ color: 'gray' }); }
        $(this).focus(function () { $(this).css({ color: 'black' }); if ($(this).attr('value') == _text) { $(this).attr('value', ''); } });
        $(this).blur(function () { if ($(this).attr('value') == '') { $(this).attr('value', _text); $(this).css({ color: 'gray' }); } });
    });

    $(":input").focus(function () {
        var btn = $("#default_submit"); btn.click(function () { $("#default_submit_x").attr('name', $(this).attr('name') + '.x'); $("#default_submit_y").attr('name', $(this).attr('name') + '.y'); });
        var classesRegExp = new RegExp("submit_\\w+", "g"); var removeRegExp = new RegExp("^submit_", "g");
        var classes = $(this).attr('class'); var name = classes.match(classesRegExp);
        if (name != null) { name = name[0].replace(removeRegExp, ""); btn.attr('name', $('.' + name + '_submit').attr('name')); }
    });

    $("select").keydown(function (event) {
        switch (event.keyCode) {
            case 13:
                var classesRegExp = new RegExp("submit_\\w+", "g"); var removeRegExp = new RegExp("^submit_", "g");
                var classes = $(this).attr('class'); var name = classes.match(classesRegExp);
                if (name != null) { name = name[0].replace(removeRegExp, ""); $('.' + name + '_submit').click(); }
                break;
        }
    });
});


function facebook_init(key, basicUrl, callback) {
    FB.Bootstrap.requireFeatures(["Connect"], function () {
        FB.init(key, basicUrl);
        FB.ensureInit(function () { if (callback) { callback(); } });
    });
}

function facebook_button_onclick(key, basicUrl, url) {
    if (document.getElementById('flash') != null) {
        document.getElementById('flash').style.display = "none";
    }

    facebook_init(key, basicUrl, function () {
        FB.Connect.get_status().waitUntilReady(function (status) {
            switch (status) {
                case FB.ConnectState.connected: window.location = url + 'fb=1'; break;
                case FB.ConnectState.appNotAuthorized: break;
                default:
                    FB.Connect.requireSession();
                    FB.Facebook.get_sessionState().waitUntilReady(function () { window.location = url + 'fb=2'; });
                    break;
            }
        });
    });
    return false;
}

function fbLogout(key, basicUrl) {
    try {
        flash_block = document.getElementById('flash');
        if (flash_block) { flash_block.style.display = "none"; }
        facebook_init(key, basicUrl, function () { FB.Connect.logout(function () { window.location = "/Logout.aspx"; }); });
    } catch (err) { }
    return true;
}

var boxes = ["Geo", "Time", "Clustern", "ASN", "Product"];
function toggleBox(id) {
    for (var i = 0; i < boxes.length; i++) {
        if ("leftContent" + boxes[i] != id) {
            var e = document.getElementById("leftContent" + boxes[i]); if (e != null) { e.className = "leftContentBox off"; }
        }
    }
    var e = document.getElementById(id);
    if (e != null) {
        var boxStyle = e.className;
        if (boxStyle.indexOf(" off") != -1) { e.className = "leftContentBox"; }
		else { e.className = "leftContentBox off"; }
    }
}
function toggleBoxActive(id) {
    for (var n = 0; n < boxes.length; n++) {
        if ("leftSearch" + boxes[n] != id) {
            var e = document.getElementById("leftSearch" + boxes[n]); if (e != null) { e.className = "leftSearchBox";}
        }
    }
    var e = document.getElementById(id)
    if (e != null) {
        boxActive = e.className;
        if (boxActive.indexOf("Active ") != 0) { e.className = "Active leftSearchBox"; } 
		else { e.className = "leftSearchBox"; }
    }
}
function openContentBox(boxID) {
  for (var x = 1; x <= 7; x++) {
   var closeBoxID = x;
   if (closeBoxID < 10) closeBoxID = "0" + closeBoxID;
   var ea = document.getElementById("topicBox" + closeBoxID + "_opened");
   if(ea != null) {ea.style.display = "none";}
   var eb = document.getElementById("topicBox" + closeBoxID + "_closed");
   if (eb != null) {eb.style.display = "block";}
  }
  var boxo = document.getElementById("topicBox" + boxID + "_opened");
  var boxc = document.getElementById("topicBox" + boxID + "_closed");
  if (boxo != null && boxo.style.display == "block") { boxo.style.display = "none"; boxc.style.display = "block"; } 
  else if (boxo != null && boxo.style.display == "none") { boxo.style.display = "block"; boxc.style.display = "none"; }
 }
function showOnlyBox(contentid, searchid) {
    for (var i = 0; i < boxes.length; i++) {
        if ("leftContent" + boxes[i] != contentid) { var e = document.getElementById("leftContent" + boxes[i]); if (e != null) e.className = "leftContentBox off"; }
        if ("leftSearch" + boxes[i] != searchid) { var e = document.getElementById("leftSearch" + boxes[i]); if (e != null) e.className = "leftSearchBox"; }
    }
	var e = document.getElementById(contentid);
    if (e != null) {e.className = "leftContentBox";} 
	e = document.getElementById(searchid);
    if (e != null) {e.className = "Active leftSearchBox";}
}
function emptyAllBut(id) {
    if (id != "Geo") { emptySelect("searchGeoContinent"); emptyTextBox("searchGeoCountry"); emptyTextBox("searchGeoCity"); }
    if (id != "Time") { emptyTextBox("searchTimeYear"); emptySelect("searchTimeSeason"); emptySelect("searchTimeFrameReader"); }
    if (id != "Clustern") { emptyTextBox("searchClusternColor"); emptyTextBox("searchClusternBook"); }
    if (id != "Product") { emptyTextBox("abstractBookTitle"); emptyTextBox("abstractBookAuthor"); }
}
function emptyTextBox(id) { var e = document.getElementById("ctl00_" + id); if (e != null) { e.value = "";} }
function emptySelect(id) { var e = document.getElementById("ctl00_" + id); if (e != null) {e.selectedIndex = 0;}}
function emptyCheckBox(id) { var e = document.getElementById("ctl00_" + id); if (e != null) {e.checked = false;}}
function SetOpenContent() {
	if(window.location.search=="?ueberbilandia") { openContentBox('01'); }
	if(window.location.search=="?bilandiaSuche") { openContentBox('02'); }
	if(window.location.search=="?bibliothek") { openContentBox('03'); }
	if(window.location.search=="?abstracts") { openContentBox('04'); }				
	if(window.location.search=="?provision") { openContentBox('05'); }
	if(window.location.search=="?meinbilandia") { openContentBox('06'); }	
	if(window.location.search=="?datensicherheit") { openContentBox('07'); }		
}
function ChangeValue(id) { var e = document.getElementById("ctl00_" + id); if (e != null){ e.value=""; e.style.color="#000000"; } }
function ChangeValueCPH(id) { var e = document.getElementById("ctl00_cphBox_" + id); if (e != null){ e.value=""; e.style.color="#000000";} }
function doCustomSortSelect(selects) { for (var i = 0; i < selects.length; i++) { var e = document.getElementById(selects[i]); if (e != null) { customSortSelect(e); } } }
function customSortSelect(select) {
    if (select == null){ return false; }
    var options = new Array(select.options.length);
    for (var i = 0; i < options.length; i++) { options[i] = new Option( select.options[i].text, select.options[i].value, select.options[i].defaultSelected, select.options[i].selected); }
    options.sort(customCompareFunction);
    select.options.length = 0;
    for (var i = 0; i < options.length; i++) { select.options[i] = options[i]; }
}
function customCompareFunction(o1, o2) {
    if (o1.text == "Andere") { return 1;  } 
	else if (o2.text == "Andere") { return -1; } 
	else { return (o1.text < o2.text) ? -1 : ((o1.text > o2.text) ? 1 : 0); }
}
function toggleDisplay(id) { var e = document.getElementById(id); if (e != null) { var current = e.style.display; e.style.display = (current == "none") ? "" : "none"; } }
function friendsMenuT(id, one, two, three, txt){ var empty_con = document.getElementById('empty_details'); try { empty_con.innerHTML = txt; } catch (err) { } friendsMenu(id, one, two, three); }
function friendsMenu(id, one, two, tree) {
	var e = document.getElementById("ctl00_cphBox_Community_" + id); if ( e != null) { e.style.display = "block"; }
	e = document.getElementById("ctl00_cphBox_Community_"+one); if (e != null) {e.style.display = "none"; }
    e = document.getElementById("ctl00_cphBox_Community_"+two); if (e != null) {e.style.display = "none"; }
    e = document.getElementById("ctl00_cphBox_Community_"+tree); if (e != null){ e.style.display = "none"; }
}
	
$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

String.prototype.startsWith = function (str) { return (this.match("^" + str) == str) }
String.prototype.endsWith = function (str) { return (this.match(str + "$") == str) }

jQuery(function ($) {
    $.datepicker.regional['de'] = { clearText: 'löschen', clearStatus: 'aktuelles Datum löschen',
        closeText: 'schließen', closeStatus: 'ohne Änderungen schließen',
        prevText: '&#x3c;zurück', prevStatus: 'letzten Monat zeigen',
        nextText: 'Vor&#x3e;', nextStatus: 'nächsten Monat zeigen',
        currentText: 'heute', currentStatus: '',
        monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
                'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
        monthNamesShort: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun',
                'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
        monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
        weekHeader: 'Wo', weekStatus: 'Woche des Monats',
        dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
        dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
        dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
        dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'Wähle D, M d',
        dateFormat: 'dd.mm.yy', firstDay: 1,
        initStatus: 'Wähle ein Datum', isRTL: false
    };
    $.datepicker.setDefaults($.datepicker.regional['de']);
});
