function prepNameForFlash(string) {
    string = encodeURIComponent(string);
    //string = string.replace(/\+/g, '%2B');
    return string;
}

function updateCartview (count, price) {
	alert(price);
}

function deleteLM (lmid, wmencpid, slid, uotid) {
	url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./cart/applycart.html&UpdateCart='+lmid+':'+slid+':0:'+wmencpid+':0:'+uotid+':0' ;
	servercomm.location.href = url;
}

function deleteLMfromWishList (lmid, wmencpid, slid, uotid) {
	deselectLM(lmid, wmencpid, 'sel');
}

function showAdvSearch() {
	document.getElementById('adv_search').style.display = 'block';
	document.getElementById('search').style.display = 'none';
	document.getElementById('search_help').style.display = 'none';
}

function hideAdvSearch() {
	document.getElementById('adv_search').style.display = 'none';
	document.getElementById('search').style.display = 'block';
}

function showHelp() {
	document.getElementById('search_help').style.display = 'block';
	document.getElementById('search').style.display = 'none';
	document.getElementById('adv_search').style.display = 'none';
}

function hideHelp() {
	document.getElementById('search_help').style.display = 'none';
	document.getElementById('search').style.display = 'block';
}

function getGenre(genre, displaygenre) {
	self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/genre.html&genre='+genre+'&displaygenre='+displaygenre;	
}

function getTickets(artistID, artist) {
	//alert(artistID);
	var url = 'http://www.eventim.de/cgi-bin/tinfo.html?fun=erbyku&doc=search/search&detailadoc=erdetaila&extkuid1='+artistID+'&suchbegriff='+artist;
	window.open(url, 'eventim');	
}

function deleteCert (certid, certcode) {
	url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./giftcert/delcert.html&certid='+certid+'&certcode='+certcode ;
	servercomm.location.href = url;
}

function Drill(lmtype, id) {
    self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/viewlm.html&lmtype='+lmtype+'&lmid='+id;
}

function viewMore(action) {
	
	if(action == 'recomm'){
		//alert('Album');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Empfehlungen';
	}
	else if(action == 'newrel'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Neuheiten';
	}
	else if(action == 'topdl_track'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Top Downloads Songs&startline=1&endline=20&lmtype=track';
	}
	else if(action == 'topdl_album'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Top Downloads Alben&startline=1&endline=20&lmtype=album';
	}
	else if(action == 'topdl_video'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Top Downloads Video&startline=1&endline=20&lmtype=video';
	}
	else if(action == 'topdl_art'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Top Interpreten&startline=1&endline=20';
	}
	else if(action == 'video'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/list.html&action=Musikvideos&startline=1&endline=20';
	}
	else if(action == 'help'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./help/help.html';
	}
	else if(action == 'contact'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./help/help.html#5';
	}
	else if(action == 'system'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./help/help.html#1';
	}
}

function preListen(lmid) {
    var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/prelisten_shop.html&lmid='+lmid;
    window.open(url,'Prelisten','width=560, height=440, location=yes');
}
function preListenEve(lmid) {
    var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/prelisten_eventim.html&lmid='+lmid;
    window.open(url,'Prelisten','width=560, height=440');
}

function preView(lmid) {
	var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/preview.html&lmid='+lmid;
	window.open(url,'PreView','width=560, height=440');
}
function preViewEve(lmid) {
    var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/preview_eventim.html&lmid='+lmid;
    window.open(url,'PreView','width=560, height=440');
}
function preAdvice(lmid, lmtype) {
    var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./general/prelisten_advice.html&lmid='+lmid+'&lmtype='+lmtype;
    window.open(url,'PreAdvice','width=560, height=440');
}
function sliceString(elementname, length) {
    var m=0;
    var artistArray=document.getElementsByName(elementname);
    var text;
    for(m=0; m<artistArray.length; m++) {
        text = artistArray[m].innerHTML;
        artistArray[m].innerHTML = sliceStringGiven(text, length);
    }
}
function sliceStringGiven(string, length) {
    if (string.length > length) {
      string = string.substr(0, length);
      string = string + '...';
    }
    return string;
}

function setLength() {
    sliceString('titletag', 15);
    sliceString('artisttag', 15);
}

function setRightLength(length) {
    sliceString('artisttoptag', length);
    sliceString('titletoptag', length);
}

function setPageNavi_Artist( tCount, artCrit, sLine, eLine, lmType) {
	url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./artist/overview.html&artistcrit='+artCrit+'&startline='+sLine+'&endline='+eLine ;
	self.location.href = url;
}

function advSearch(action, crit, startline, endline) {
	if(action == 'track'){
		document.ActualSearchForm.keyword.value = crit;
		document.ActualSearchForm.startline.value = startline;
		document.ActualSearchForm.endline.value = endline;
		document.ActualSearchForm.lmtype.value = 'track';
		document.ActualSearchForm.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/searchres_track.html';
		document.ActualSearchForm.submit();		
	}
	else if(action == 'artist'){
		//alert('track');
		self.location.href = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./artist/overview.html&artistcrit='+crit;
	}
	else if(action == 'album'){
		document.ActualSearchForm.keyword.value = crit;
		document.ActualSearchForm.startline.value = startline;
		document.ActualSearchForm.endline.value = endline;
		document.ActualSearchForm.lmtype.value = 'album';
		document.ActualSearchForm.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/searchres_album.html';
		document.ActualSearchForm.submit();		
	}
	else if(action == 'video'){
		document.ActualSearchForm.keyword.value = crit;
		document.ActualSearchForm.startline.value = startline;
		document.ActualSearchForm.endline.value = endline;
		document.ActualSearchForm.lmtype.value = 'video';
		document.ActualSearchForm.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/searchres_video.html';
		document.ActualSearchForm.submit();		
	}
	else if(action == 'adv'){
		document.ActualSearchForm.startline.value = startline;
		document.ActualSearchForm.endline.value = endline;
		document.ActualSearchForm.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/adv_searchres.html';
		document.ActualSearchForm.submit();		
	}

}

function editSearch(){
	if(document.Edit_Search_Form.yearcrit.value == 'Jahr'){
		document.Edit_Search_Form.yearcrit.value = '';
	}
	if(document.Edit_Search_Form.titlecrit.value == 'Titel'){
		document.Edit_Search_Form.titlecrit.value = document.Edit_Search_Form.keyword.value;
	}
	else{
		document.Edit_Search_Form.keyword.value = ' '+document.Edit_Search_Form.titlecrit.value;
	}
	if(document.Edit_Search_Form.artistadvcrit.value == 'Interpret'){
		document.Edit_Search_Form.artistadvcrit.value = document.Edit_Search_Form.keyword.value;
	}
	else{
		//document.Edit_Search_Form.keyword.value += ' '+document.Edit_Search_Form.artistcrit.value;
		document.Edit_Search_Form.artist.value = 'true';
	}
	document.Edit_Search_Form.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/adv_searchres.html';
	//alert('Titlecrit:'+document.Edit_Search_Form.titlecrit.value);
	document.Edit_Search_Form.submit();		
	
}

function editAdvSearch(){
	if(document.Edit_Search_Form.yearcrit.value == 'Jahr'){
		document.Edit_Search_Form.yearcrit.value = '';
	}
	if(document.Edit_Search_Form.titlecrit.value == 'Titel'){
		document.Edit_Search_Form.titlecrit.value = '';
	}
	if(document.Edit_Search_Form.artistcrit.value == 'Interpret'){
		document.Edit_Search_Form.artistcrit.value = '';
	}
	document.Edit_Search_Form.action = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./lm/adv_searchres.html';
	document.Edit_Search_Form.submit();		
	
}

var pwbox_oldhtml = "";
function lostPass(){
	$('#password_box').show();
    pwbox_oldhtml = parent.document.getElementById('password_text').innerHTML;
}

function hidePass(){
	parent.document.getElementById('password_box').style.display = 'none';			  
    parent.document.getElementById('password_text').innerHTML = pwbox_oldhtml;

}

function sendPass(){
    pwbox_oldhtml = parent.document.getElementById('password_text').innerHTML;
	parent.document.getElementById('password_text').innerHTML = 'Ihr Passwort wurde versendet!';
	window.setTimeout('hidePass();',2000);

}
function sendPassUserUnknown(){
    pwbox_oldhtml = parent.document.getElementById('password_text').innerHTML;
    parent.document.getElementById('password_text').innerHTML = 'Der Benutzer ist uns nicht bekannt!';
    window.setTimeout('hidePass();',2000);
}


function showAGB(){
	var url = XMLSERVERNAME+XMLSERVLETNAME+'Call?htmltemplate=./help/agb_popup.html';
	window.open(url,'AGB','width=600, height=800, scrollbars=1');
}



function setupPageNaviArtist(totalcount, thisStartline, artistid, lmtype) {
    var rownumber=10;  // Titel pro Seite
    var thisEndline = thisStartline + (rownumber - 1);
    var page = parseInt(thisStartline/rownumber,10) + 1; // aktuelle Seite
    var pages = Math.ceil(totalcount/rownumber); // Seiten insgesamt
    var LastStartline = pages * 10 -9;
    var offset = 1; // erste Page in Navi-Leiste
    var navstring = '<table cellpadding="0" cellspacing="0" border="0" height="16px" id="nav_table"><tr><td class="dis_arrow">&laquo;</td>'; // das Navi-HTML
    var linkbody = '';
    var counter = '';
    //alert('totalcount: '+totalcount+'\nStartline: '+thisStartline+'\nPage: '+page+'\nPages: '+pages+'\nOffset: '+offset);
    
    // Berechnung des Offsets: welche Seite soll vorne stehen (Bsp. 1 oder 11 oder 21, etc...)
    for(var p=5; p<=pages; p+=5) {
        if(page > p) {
            offset=p+1;
        }
    }
    
    if(page > 1) { // wenn nicht erste Seite, dann link zur nächst kleineren seite generieren
        navstring = '<table cellpadding="0" cellspacing="0" border="0" height="16px" id="nav_table"><tr><td class="act_arrow"><a href="javascript:setPageNavi(' + totalcount + ',' + artistid + ','+((page-1)*rownumber-9)+','+((page-1)*rownumber)+',\'' + lmtype + '\')" style="font-weight:normal;">&laquo;</a></td>';
    }
    
    for (var i=offset;i<=pages;i++) {
        if(i > 9) { counter = ''; }
        if(i==page) { // aktive seite bekommt eine andere Klasse und keinen Link
            navstring += '<td class="active_nav">'+counter+i+'</td>';
        }
        // alle anderen seiten bekommen Link
        else {
            navstring += '<td><a href="javascript:setPageNavi(' + totalcount + ',' + artistid + ','+(i*rownumber-9)+','+(i*rownumber)+',\'' + lmtype + '\')" style="font-weight:normal;">'+counter+i+'</a></td>';
        }
        if(i==offset+4) break;
    }
    
    if(page < pages) { // wenn nicht letzte seite, dann link zur nächst höheren seite generieren
        navstring += '<td class="act_arrow_l"><a href="javascript:setPageNavi(' + totalcount + ',' + artistid + ','+((page+1)*rownumber-9)+','+((page+1)*rownumber)+',\'' + lmtype + '\')" style="font-weight:normal;">&raquo;</a></td></tr></table>';
    } else {
        navstring += '<td class="dis_arrow_l">&raquo;</td></tr></table>';
    }
        
    //alert(totalcount);
    if (totalcount == 'NaN' || totalcount == '') {
        document.getElementById('navi').innerHTML = '';
        document.getElementById('pages').innerHTML = 'Seite 1';
    } else {
        document.getElementById('navi').innerHTML = navstring;
        document.getElementById('pages').innerHTML = 'Seite '+counter+page+'/'+pages;
    }   
}

/**
 * author: DST
 * this class handles rating of 
 */
var LMRating = {
    initrating: 0,
    img_url_white: "",
    img_url_yellow: "",

    init: function(initratingvalue) {
        LMRating.initrating = initratingvalue;
        LMRating.restoreStarsForInitRating();
        LMRating.registerEventHandlers();
    },

    registerEventHandlers: function() {
        $("#rating_product a").hover(function() {
            LMRating.setStarsYellow($(this).find("img").attr("alt"));
        }, function() {
            LMRating.setStarsWhite($(this).find("img").attr("alt"));
        });
    },
    
    setupImages: function(white, yellow) {
        LMRating.img_url_white  = white;
        LMRating.img_url_yellow = yellow;
    },
    
    setStarsYellow: function(value) {
        if ($("#rating_status_ok").is(":visible")) {
            return false;
        }
        if (value >= 1 && value <= 5) {
            $("#rating_product img:lt(" + value + ")").attr("src", rating_imgsrc_gelb);
        } else {
            $("#rating_product img:lt(5)").attr("src", rating_imgsrc_gelb);
        }
    },

    setStarsWhite: function(value) {
        if ($("#rating_status_ok").is(":visible")) {
            return false;
        }
        if (value >= 1 && value <= 5) {
            $("#rating_product img:lt(" + value + ")").attr("src", rating_imgsrc_weiss);
        } else {
            $("#rating_product img:lt(5)").attr("src", rating_imgsrc_weiss);
        }
        LMRating.restoreStarsForInitRating();
    },
    
    restoreStarsForInitRating: function() {
        if (LMRating.initrating > 0) {
            LMRating.setStarsYellow(LMRating.initrating);
            //$("#rating_status_rate").hide();
            //$("#rating_status_ok").show();
        }
    }
};
