/*
 ****************************************************************************
 * Programa: tarabu_websearch_AJAX.js                                     *
 * Creador: Diego Alonso                                                    *
 * Fecha de creación: 21/06/2007                                            *
 * Descripción: Contiene todas las funciones necesarias para desplegar
				correctamente el Websearch de Tarabu.
 *                                                                          *
 * Derechos reservados(c) Comercio Mas S.A. de C.V. 2007                    *
 * El contenido de este programa es confidencial y propietario,             *
 * prohibida su utilización y/o modificación sin el consentimiento          *
 * de Comercio Mas S.A. de C.V.                                             *
 *                                                                          *
 ****************************************************************************
*/

/* =================================== INICIA RESULTADOS =================================== */

function ajax (type, row)
{
	var xmlHttp; //Reference: <www.w3schools.com>

	try {  //Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
    } catch (e) { //Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function ()
	{
		if(xmlHttp.readyState == 4)
		//si pasa
			window.document.getElementById(type).innerHTML = xmlHttp.responseText;
	}
	href =  "tarabu_websearch_inc_AJAX.php?t=";
	if (isInPlayer)
		href =  "tarabu_websearch_inc_AJAX.php?p=1&t=";
	xmlHttp.open("GET", href + type + "&n=" + total(type) + "&q=" + searchWords + "&i=" + row, true);
	xmlHttp.send(null);
}

function total (type)
{
	if (type == 'artists')
		return totalArtists
	else if (type == 'albums')
		return totalAlbums;
	else if (type == 'songs')
		return totalTracks;
	else if  (type == 'videomusical')
		return totalVideosM;
	else if  (type == 'tonosreales')
		return totalTonReales;
	else if  (type == 'sonidosreales')
		return totalSonReales;
	else if  (type == 'polifonicos')
		return totalPolifonicos;
	else //juegos
		return totalMonofonicos;
}

/* =================================== TERMINA RESULTADOS =================================== */



/* =================================== INICIA DISCOGRAFÍA =================================== */

function getSubstrTitle (str) {
	if(str.length > 14)
		str = str.substring(0, 12) + "...";
	
	return str;
}

function writeDiscography () {
	
var detect = navigator.userAgent.toLowerCase();
var OS,total,thestring;

if(navigator.userAgent.indexOf('Mac') != -1)
    {
	 var mac=1;
    }
else 
	{
	var mac=0;	
	}
	
	lis = '';
	
	ul = document.getElementById('discography');
	for (i = 0; i < numAlbum; i++) {
		lis += '<li>' +
				//'<a href="http://www.tarabu.com/MicWeb/ep_album.aspx?upc=' + albumes[i][3] + '"><img class="album" src="' + albumes[i][8] + '"/></a>' +
				'<a href="tarabu_websearch_album.php?albumID=' + albumes[i][0] + '"><img class="album" src="' + albumes[i][8] + '"/></a>' +
				'<span class="title-disc">' + getSubstrTitle(albumes[i][2]) + '</span>' +
				'<span class="artist">' + albumes[i][1] + '</span>' +
				'<span class="year">Lanzamiento ' + albumes[i][6] + '</span>' ;
		/*Precio Especial para warner    2008-05-05*/
	if(albumes[i][10]=="8" && (albumes[i][11]=="A03" || albumes[i][11]=="A04" || albumes[i][11]=="A05" || albumes[i][11]=="A06" || albumes[i][11]=="A07" ))
		lis+="<span class='price'><table class='titAlbum' width='135' border=0><tr><td><img src='img/ep/btn_solo_yllw.gif' border=0/></td><td><strong>Precio Especial</strong></td></tr>"								
		/*+"<tr><td colspan=2><p style='color:#FF0000;font-size:12px;'><strong> $"+albumes[i][5]+"</strong></p></td></tr></table></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";*/
		+"<tr><td colspan=2><p style='color:#FF0000;font-size:12px;'><strong></strong></p></td></tr></table></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	else
		/*lis+='<span class="price">$' + albumes[i][5] + '</span>' ;*/
		lis+='<span class="price"></span>' ;
		
		if(albumes[i][5]<="0.00") {
		if (mac==0) 
		lis +='<a href="javascript:OpenOnPlayer(\'http://store.tarabu.com/tarabu_album.php?albumID=' + albumes[i][0] + '\')"><img class="buy" alt="Comprar" src="img/websearch/tarabu_websearch_btn_decarg.gif"/></a>';
		else
		lis +='<img  src="http://store.tarabu.com/img/websearch/tarabu_websearch_btn_pc.gif"/>';
		}
		else {
		if (mac==0) 
		/*lis +='<a href="javascript:OpenOnPlayer(\'http://store.tarabu.com/tarabu_album.php?albumID=' + albumes[i][0] + '\')"><img class="buy" alt="Comprar" src="img/websearch/tarabu_websearch_btn_comprar.gif"/></a>';*/
		lis +='';
		else
		lis +='<img src="http://store.tarabu.com/img/websearch/tarabu_websearch_btn_pc.gif"/>';
		}

		lis +='</li>';		
	}
	ul.innerHTML = lis;
}


function load () {
	document.getElementById('artist').innerHTML = artist;
	
	s = document.getElementById('search');
	if (numAlbum == 1)
		s.innerHTML = 'Resultados de tu búsqueda: 1 álbum';
	else
		s.innerHTML = 'Resultados de tu búsqueda: ' + numAlbum + ' álbumes';
	
	writeDiscography();
}

/* =================================== TERMINA DISCOGRAFÍA =================================== */



/* =================================== INICIA ÁLBUM =================================== */
	var last = null;

	function play (hrf) {
		/*document.getElementById('sound').innerHTML = '<embed type="audio/x-ms-wma" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + hrf + '" name="MediaPlayer1" autostart="1" showcontrols="1"></embed>';*/
		document.getElementById('sound').innerHTML = '<object width="300" height="68" id="MediaPlayer" codetype="audio/x-ms-wax" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab# Version=5,1,52,701" standby="Loading Microsoft Windows® Media Player components...">' + 
	'<param name="fileName" value="' + hrf + '" />' +
	'<param name="transparentatStart" value="true" />' +
	'<param name="autoStart" value="true" />' +
	'<param name="showControls" value="true" />' +
	'<param name="ShowStatusBar" value="true" />' +
	'<param name="ShowDisplay" value="false" />' +
	'<embed width="300" height="70" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + hrf + '" name="MediaPlayer1" autostart="1" showcontrols="1" showstatusbar="1" showdisplay="0"></embed>' +
'</object>';
	}
	
	function changeUlHeight () {
		ul = document.getElementById('tracks');
		h = ul.offsetHeight;
		if (h < 220)
			ul.style.height = '220px';
	}
	
	function setTrack (element) {
			if (last != null) {
				last.parentNode.style.backgroundImage = 'url(img/websearch/tarabu_websearch_play.gif)';
				last.style.fontWeight = "normal";
			}
			element.parentNode.style.backgroundImage = 'url(img/websearch/tarabu_websearch_stop.gif)';
			element.style.fontWeight = "bold";
			last = element;
	}
	
	function autoPlay(hrf) {
			node = document.getElementById("autoPlay");
			if (node) {
				setTrack(node);
				play(hrf);
			}
	}

/* =================================== TERMINA ÁLBUM =================================== */