/****************************************************************************
* functions.js
* Common JavaScript functions: win-opener, image-swap, NN4-resize-bugfix,
* Layer An / Aus
* author: oh@vsn-munich.de | date: 2002-08-08
*
* produced by VSN VISUAL SOLUTIONS NETWORK GBR
* http://www.vsn-munich.de
*
* Version: 1.1    Datum: 2002-08-08
***************************************************************************/

//______________________________________________________________________
// framset nachladen
function buildFrameset() {
	if(self == top) location.href = "/index.php";
}


//______________________________________________________________________
// banner laden
function loadBanners(path1,path2) {
	if(path2 == "praxis") { path1 = path2; }
	window.parent.frames[1].location.href = "/banner.php?bannerTag="+path1;
}

//______________________________________________________________________
// allgemeine Funktionen - cross-browser
function getImage(bildName,layerID)
{
	return (document.all||document.getElementById?window.document.images[bildName]:layerID?document.layers[layerID].document.images[bildName]:window.document.images[bildName]);
}

function getLayer(layerID)
{
	return (document.getElementById?document.getElementById(layerID).style:document.all?document.all[layerID].style:document.layers[layerID]);
}


//______________________________________________________________________
// Bildwechsel mit Vorlader
var aktivBild = "";
var aktivLayer = "";

var Bilder=new Array();					
function vorLader(bildName,src1,src2)
{
	Bilder[bildName]=new Array();
	Bilder[bildName]["aus"]=new Image();
	Bilder[bildName]["aus"].src=src1;
	Bilder[bildName]["an"]=new Image();
	Bilder[bildName]["an"].src=src2;
}

function bildAn(bildName,layerID)
{
	getImage(bildName,layerID).src=Bilder[bildName]["an"].src;
}
	
function bildAus(bildName,layerID)
{
	getImage(bildName,layerID).src=Bilder[bildName]["aus"].src;
}

function bildFest(bildName,layerID)
{
	if(aktivBild != "" && aktivBild != bildName)
		getImage(aktivBild,aktivLayer).src = Bilder[aktivBild]["aus"].src;
		
	aktivBild = bildName;
	aktivLayer = layerID;
}

//______________________________________________________________________
// Layer ein- / ausschalten
function layerAn()
{
	for(i=0;i<arguments.length;i++) { getLayer(arguments[i]).visibility="visible"; }
}
 	
function layerAus()
{
	for(i=0;i<arguments.length;i++) { getLayer(arguments[i]).visibility="hidden"; }
}


//______________________________________________________________________
// new window opener
function openViewer(url,name,width,height)
{
	var xpos = (screen.availWidth-width)/2;
	var ypos = (screen.availHeight-height)/2;
	popUp = window.open(url,name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width="+width+",height="+height+",resizable=no,left="+xpos+",top="+ypos);
}

function openArt(url,name,width,height)
{
	var xpos = (screen.availWidth-width)/2;
	var ypos = (screen.availHeight-height)/2;
	popUp = window.open(url,name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width="+width+",height="+height+",resizable=yes,left="+xpos+",top="+ypos);
}


//______________________________________________________________________
// select form
function menu(type,item)
{
	var external;
	var Suche;
	
	if (item=="nix")
	{
		document.formular.reset();
		document.formular.liste.blur();
		return;
	}
	else if (type=="link")
	{
		document.location.href="#"+item;
	}
		document.formular.reset();
		document.formular.filter.blur();
}

//______________________________________________________________________
// Fix NetscapeNavigator4.5 resize bug

function reDo() {
	if (innerWidth != origWidth || innerHeight != origHeight) {
		history.go(0);		
	}
}
if (document.layers) {
    origWidth = innerWidth;
    origHeight = innerHeight;		
    onresize = reDo;
}


/**
* Methode zum versenden des Bewertungsformulares
* Hinweis: Benoetigt die globale JS-Variable urlPath
*
* @access 	public
* @param	string	formaction 	Action des Formulares
* @param	string	formname	Name des Formulares
*
* @return 	void
*/
function submitDocVoting(formaction, formname) {
	var newwinVoting = 0;
	var isVoting = 0;
	with(document.forms[formname]) {
		if (formaction == urlPath + "votemail.php") {
			for (var i = 3; i <= 5; i++) {
				  if (elements[i].checked  == true) isVoting = 1;
			}
		}
		if (isVoting==0 && formaction == "votemail.php") {
			alert("Zuerst bitte eine Bewertung wählen!");
		}
		else {
			if (typeof(newwinVoting) == "object" && !newwinVoting.closed) { newwinVoting.close(); }
			var newwinVoting = window.open('', 'winVoting', 'left=' + ((screen.width - 320) / 2) + ',top=' + ((screen.height - 260) / 2) + ',width=600,height=400,scrollbars=0,resizable=0');
			action = formaction;
			submit();
			newwinVoting.focus();
		}
	}
}


/**
* Methode versendet das Suchformular im Template
*
* @access 	public
* @param	object	searchForm 		Referenz auf das Suchformular
* @param	string	formActionNormal 	Action des Formulares, wenn es die nicht auf Online Werke eingeschraengt ist
* @param	string	formActionOnlineWerke 	Action des Formulares, nur bei Online-Werken
*
* @return 	boolean
*/
function checkSearchAction(searchForm, formActionNormal, formActionOnlineWerke) {
	if(!searchForm || !document.getElementById("searchfield") || !formActionNormal || !formActionOnlineWerke){
		return false;	
	}
	with (searchForm) {
		if (document.getElementById("searchfield").name == "query") {	// Cache-Problem bei einigen Browsern -> Daten wewrden bei Back-Button nicht zurückgesetzt
			action = formActionNormal;
			target = "_self";
			method = "post";
			document.getElementById("searchfield").name = "qs";
		}
		if (elements["searchfield"].value == "") {
			return false;
		} else {
			selField = elements["selectKategorie"];
			/*
			if (selField.options[selField.selectedIndex].value.indexOf("1322034") != -1) {
				action = formActionOnlineWerke;
				target = "_blank";
				method = "post";
				document.getElementById("searchfield").name = "query";
				return true;
			}else { 
				return true; 
			}
			*/
			return true;
		}
	}
}


/**
* Methode versucht bei Auswahl einer Kategorie in der Suchseite die entsprechende Kategorie zu setzen
*
* @access 	public
* @param	string	setValue 		Kategorie-Wert auf das Suchformular
*
* @return 	boolean
*/
function setValueInMasterSearchForm(setValue) {
	if(!setValue){
		return false;
	}
	var category_ids = setValue.split(",");
	if(category_ids.length > 0 || setValue == ""){ // bestehende Kategorie-Einschraenkungen zuruecksetzen
		var inputElements = document.getElementsByTagName("input");
		for(var eCount=0; eCount < inputElements.length; eCount++){
			if(inputElements[eCount].type == "checkbox" && inputElements[eCount].name.indexOf("data[categories][kategorien][") == 0 ){
				inputElements[eCount].checked = false;	
			}
		}
	}
	if(setValue != ""){
		for(var i=0; i < category_ids.length; i++){ // neue Kategorie-Einschraenkungen setzen
			var categoryElements = document.getElementsByName("data[categories][kategorien][" + category_ids[i] + "]");
			for(var eCount=0; eCount < categoryElements.length; eCount++){
				if(categoryElements[eCount].type == "checkbox"){
					categoryElements[eCount].checked = true;
				}
			}
		}
	}
	return true;
}

/**
* Social Bookmarks
*/
function bookThis(bookTarget) {
    var doc=encodeURIComponent(location.href);
    var title=encodeURIComponent(document.title);
    switch(bookTarget) {
        case 'delicious':
            window.open('http://del.icio.us/post?url='+doc+'&title='+title);
            break;
        case 'mrwong':
            window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url='+doc+'&bm_description='+title);
            break;
        case 'blinkList':
            window.open('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url='+doc+'&Title='+title);
            break;
        case 'yahoo':
            window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+doc+'&t='+title);
            break;
        case 'yigg':
            window.open('http://yigg.de/neu?exturl='+doc+'&exttitle='+title);
            break;  
        case 'furl':
            window.open('http://www.furl.net/storeIt.jsp?u='+doc+'&t='+title);
            break;
        case 'oneview':
            window.open('http://beta.oneview.de:80/quickadd/neu/addBookmark.jsf?URL='+doc+'&title='+title);
            break;
        case 'folkd':
            window.open('http://www.folkd.com/submit/page/'+doc);
            break;
        case 'linkarena':
            window.open('http://linkarena.com/bookmarks/addlink/?url='+doc+'&title='+title+'&desc=&tags=');
            break;
        case 'google':
            window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+doc+'&title='+title);
            break;
        case 'webnews':
            window.open('http://www.webnews.de/einstellen?url='+doc+'&title='+title);
            break;
    }
}

/**
* Bookmarklink
*/
function CreateBookmarkLink() {

    var url=encodeURIComponent(location.href);
    var title=encodeURIComponent(document.title);

    if (window.sidebar) {
        window.sidebar.addPanel(title, url,'');
    } else if (window.external) {
        window.external.AddFavorite(url, title); 
    } else if(window.opera && window.print) {
        return true; 
    }
}

