/*	CMSLite v1.0
 *	Author: Matus Gazo (gazo.mato@web.de)
 *	Copyright (c) 2004 by Hörcompany.de
 * 	See index.php for more Information
 *  Edited By Florian Meyer
 */

function trim(str) {
	return str.replace(/^\s+/, '');
}
	
var switchSlideshowMenu_duration = 1000;

function switchSlideshowMenuLink()
{
  var url = this.href;
  //$('DIV#slidemenu').html(this.title);
  $('DIV#slidemenu').unbind();
  $('DIV#slidemenu').click(function() {
     window.location.href = url;
  });
}

 $(document).ready(function() {
  $('.slideshow').cycle({
      fx: 'fade',
      random: 1,
      timeout: switchSlideshowMenu_duration,
      after: switchSlideshowMenuLink
    });
});

// Rückwärtskompatibilität zu NS4
var ns4class='';

/* Hoerbuch-Popup */
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=340,height=380,left = 465,top = 337');");
}

function popUp_v(URL, w, h) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = 465,top = 337');");
}


/*
 * Hoerbuch - Verwaltung
 */

function windowOpen(page, name, atrib)	{
	window.open(page, name, atrib);
	name.focus();
}

function QuickJump(i, element, Formular)//Funktion zum eintragen von Autoren und Sprecher in andere Listen
{
	var Element = element.selectedIndex;
	var neuerEintrag = element.options[Element].value;
	NeuerEintrag = new Option(element.options[Element].text, neuerEintrag, false, true);
    Formular.elements[i].options[Formular.elements[i].length] = NeuerEintrag;
	Formular.elements[i].options[Formular.elements[i].length].selected = true;
}

function delList(Formular, x)	{
	var Element = Formular.elements[x].selectedIndex;
	Formular.elements[x].options[Element] = null;
	var i=0;
	for(i=0;i<=Formular.elements[x].length;i++)	{
		Formular.elements[x].options[i].selected = true;
	}
}



/*
 *  Als Startseite
 */
function SetAsHP(msg)	
{
	if ((navigator.appVersion.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') == -1) && (navigator.appVersion.indexOf('Windows')>-1) && Boolean(document.getElementById) && (parseInt(navigator.appVersion) >= 4)) 
		{ 
		    document.body.style.behavior = "url(#default#homepage)";
		    document.body.setHomePage('http://www.hoercompany.de');
		} else {
			alert(msg);
			}
	}



/*
 *  Zu Favoriten adden
 */
function Bookmark(msg){
	if ((navigator.appVersion.indexOf('MSIE') > 0) && (navigator.userAgent.indexOf('Opera') == -1) && (navigator.appVersion.indexOf('Windows')>-1) && Boolean(document.getElementById) && (parseInt(navigator.appVersion) >= 4)) 
		{
			window.external.AddFavorite(location.href, document.title);
		} else {
			alert(msg);
			}; 

	}


/*
 *  Loeschen bestätigen
 */
function CheckDelMsg()
    {
      if(!confirm("Wirklich löschen?")) return false;
      return true; 
    }

/*
 *   Nur Zahleneingabe
 */


function CheckNumerical(Objekt){
		var allowed="0123456789";
		var input = document.getElementById(Objekt);

		for(var i=0; i<input.value.length; i++){
			if(allowed.indexOf(input.value.charAt(i))<0){ alert('Keine Zahl!'); focus(Objekt); return false; }
		}
		return true;
}

/*
 *  PopUp Window 
 */
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
//  End -->


/*
 * Menu
 */
 
/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Modified by Matus Gazo (no menu folding when clicking a item)
***********************************************/

function SwitchMenu(obj,url){  			 	// Added 2nd parameter
    if(url!='nourl'){ location.href=url; }	// Added
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}



/*
 * Farbmarkierung der Tabellen
 * (übernommen von PhpMyAdmin - www.phpmyadmin.net )
 */



// This array is used to remember mark status of rows in browse mode
var marked_row = new Array;
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function CellColor(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


/*
 * Email-Kontrolle
 */
 function checkEmail(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {    
	    //alert("The username doesn't seem to be valid.")
    return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
    	// this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
	    	    //alert("Destination IP address is invalid!")
			return false
		    }
	    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	if (len<2) {
	   //var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false
	}
	
	return true;
}
