function openSearch( ){
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")){
		window.sidebar.addSearchEngine(
		"http://www.dilandau.com/opensearch/plugin.src",
		"http://www.dilandau.com/opensearch/plugin.gif",
		"Search, Download and Share Music for Free - Dilandau",
		"" );
		}
	else if ((typeof window.external == "object") && ((typeof window.external.AddSearchProvider == "unknown") || (typeof window.external.AddSearchProvider == "function"))) {
		window.external.AddSearchProvider("http://www.dilandau.com/opensearch/plugin.xml");

	}

}
//Load my mail and my name
function loadPersonalData(){
	var ShareCookie = new Hash.Cookie('Dilandau-Share',{path: "/",duration:300});
	myName = ShareCookie.get("myName");
	myMail = ShareCookie.get("myMail");
	if (!myMail) myMail = "";
	if (!myName) myName = "";

	var names = $$(".myName");
	for (var i=0; i < names.length; i++) {
		names[i].value = myName;
	};
	var mails = $$(".myMail");
	for (var i=0; i < mails.length; i++) {
		mails[i].value = myMail;
	};
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
/*Tips*/
window.addEvent('domready', function(){

				/* Tips 2 */
				var Tips2 = new Tips($$('.tip, .result .button'), {	 
					className: 'custom',
					initialize:function(){
						this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 300, wait: false}).set(0);
					},
					onShow: function(toolTip) {
						this.fx.start(1);
					},
					onHide: function(toolTip) {
						this.fx.start(0);
					}
				});
				loadPersonalData();
				
			});

var currentPage = 1;
			
function showPage(id){		
	if (nPages> 1){
		if (id<1) id=1;
		if (id>nPages) id=nPages;
		if(id ==1) document.getElementById("previous_page").className="ibutton";   
		else document.getElementById("previous_page").className="button";	
	
		if(id ==nPages) document.getElementById("next_page").className="ibutton";	
		else document.getElementById("next_page").className="button";	
	
		start = document.getElementById("start");
		end = document.getElementById("end");
	
		lastPage = document.getElementById(currentPage+"-page_results");
		lastButton = document.getElementById(currentPage+"-page_button");

		newPage = document.getElementById(id+"-page_results");
		newButton = document.getElementById(id+"-page_button");

		currentPage=id;		
		start.innerHTML=id*10;
		end.innerHTML = id*10 +10;
		lastPage.className = "page_inactive";
		lastButton.className = "button";

		newPage.className = "page_active";
		newButton.className = "ibutton";
	}
	
}

function search(query,lang,waitImage){
	var download="download";
	var kind = "music"
	query = query.trim();	
	if (lang =="es"){
		download ="descargar";
		kind="musica";
	}else if (lang =="fr"){
		download ="telecharger";
		kind = "musique"
	}else if (lang =="it"){
		download ="scaricare";
		kind = "musica"
	}
	if (query.length > 0){
		window.location = "/"+download+"_"+kind+"/" + query + "-1.html";
	}
	return false;
	
}

function wopen(url, name,w, h)
{

  w += 32;
  h += 136;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  if (wleft < 0) {
	w = screen.width;
	wleft = 0;
  }
  if (wtop < 0) {
	h = screen.height;
	wtop = 0;
  }
  win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no,directories=no');
  win.resizeTo(w, h);
  win.moveTo(wleft, wtop);
  win.focus();
}

function player(id,lang, w, h)
{
  var urlCGI = '/cgi/play.cgi?id='+id+'&lang=' + lang;
  wopen(urlCGI,"player_window",w,h);
	/* try{
		if(win.closed) {
			wopen(urlCGI,"player_window",w,h);
		}else{
			songXML = "<location>"+url+"</location><creator>"+author+"</creator><title>"+title+"</title>";
			playerSWF = win.ep_player
			playerSWF.EP_loadMP3(songXML);
			playerSWF.EP_play();
			win.focus();
		}
	}catch(err){
		wopen(urlCGI,"player_window",w,h);
	}*/
}

function close_share(objId){
	var obj = document.getElementById("share_frame_"+objId);
	Slides[objId].slideOut();
}



function load_cover(id,objId){ 
	var img = document.getElementById("cover_"+objId);
	if (img.src=="http://www.dilandau.com/images/nocover2.gif") {		
		url = "http://www.dilandau.com/cgi/cover.cgi?id="+id;
		new Ajax(url,
		  {
			method:'get',
			onComplete: function(response){
			  document.getElementById("cover_"+objId).src = response;
			}
			
		  }).request();
	};
}


function send_mail(id,objId,from,to,comment,name,lang){
	var cgi = "/cgi/sendEmail.cgi"
	var params = "id=" + id + "&from=" +from + "&to=" + to + "&comment=" + comment + "&name=" + name +"&lang=" + self
	var url=""
	url = cgi + "?" + params
	if (from == '')
		alert(introduceEmailError);		
	else if (to == '')
		alert(introduceFriendEmailError);
	else{
		/*Save the name and email*/
		var ShareCookie = new Hash.Cookie('Dilandau-Share',{path:"/",duration:300});
		settings = {myName : name, myMail : from}
		ShareCookie.extend(settings);
		var names = $$(".myName");
		for (var i=0; i < names.length; i++) {
			names[i].value = myName;
		};
		var mails = $$(".myMail");
		for (var i=0; i < mails.length; i++) {
			mails[i].value = myMail;
		};
		
		status_mail = document.getElementById("status_mail_"+objId);
		status_mail.innerHTML = mailSentStr; 
		status_mail.style.display = "block";
		close_share(objId);
		setTimeout("status_mail.style.display = 'none'",3000);
		new Ajax(url, {	 method:'get' }).request();
		
	}
}		
