function foc()
{
    if(document.searchmusicinput.searchmusic.value=="Type song title, movie or singer name")
	        document.searchmusicinput.searchmusic.value="";		
}
function blurr()
{
    if(document.searchmusicinput.searchmusic.value=="")
	        document.searchmusicinput.searchmusic.value="Type song title, movie or singer name";	
}
function validate_musicsearch()
{	
	var keyword = document.getElementById('searchmusic').value;
	
	if(keyword == "" || keyword == 'Type song title, movie or singer name')
	{		
		document.getElementById('errormsg').className = 'MusicErrorMSG1';
		showErrMsg('errormsg','Please enter keyword to search');		
		return false;
	}
	else
	{		
		document.getElementById('action').value = 'proceed_search';		
		document.searchmusicinput.submit();
		return true;
	}
}
function showWait(waitId)
{	
	document.getElementById(waitId).style.display = '';
}

function hideWait(waitId)
{	
	document.getElementById(waitId).style.display = 'none';
}

function mw(u)
{
	var windowleft=parseInt((screen.width/2)-250);
	var windowtop=parseInt((screen.height/2)-200);
	try
	{
		var muW = window.open(urldecode(u),'musicwindow','scrollbars=yes,width=500,height=400,left='+ windowleft+
									   ',top='+windowtop+',screenX='+windowleft+',screenY='+windowtop+'');
		window.focus();
		muW.focus();
	}
	catch(e)
	{
	   //alert(e);
	}
}
function mw1(song_title,u)
{
	var windowleft=parseInt((screen.width/2)-250);
	var windowtop=parseInt((screen.height/2)-200);
	try
	{
		var url = 'mp3.php?surl='+urldecode(u)+'&stitle='+song_title;
		var muW = window.open(url,'musicwindow','scrollbars=yes,width=500,height=400,left='+ windowleft+
									   ',top='+windowtop+',screenX='+windowleft+',screenY='+windowtop+'');
		window.focus();
		muW.focus();
	}
	catch(e)
	{
	   //alert(e);
	}
}
function urldecode( str ) 
{     
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();    
    var replacer = function(search, replace, str) 
	{
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };    
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';    
    for (replace in histogram) 
	{
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret); 
    return ret;
}
function showMore(showId,showMoreIconId,showLessIconId)
{	
	document.getElementById(showId).style.display = '';
	document.getElementById(showLessIconId).style.display = '';
	document.getElementById(showMoreIconId).style.display = 'none';	
}
function showLess(showId,showMoreIconId,showLessIconId)
{	
	document.getElementById(showId).style.display = 'none';
	document.getElementById(showLessIconId).style.display = 'none';
	document.getElementById(showMoreIconId).style.display = '';	
}
function showMore1(showId,showMoreIconId,showLessIconId,showMoreLinkId,showLessLinkId,playUrl,others,mp3,stitle)
{	
	document.getElementById(showId).style.display = '';
	document.getElementById(showLessIconId).style.display = '';
	document.getElementById(showLessLinkId).style.display = '';	
	document.getElementById(showMoreLinkId).style.display = 'none';	
	document.getElementById(showMoreIconId).style.display = 'none';	
	
	if(others == '' && mp3 == 'exists')
		mw1(stitle,playUrl);
	else
		mw(playUrl);
}
function showLess1(showId,showMoreIconId,showLessIconId,showMoreLinknId,showLessLinkId,playUrl,others,mp3,stitle)
{	
	document.getElementById(showId).style.display = 'none';
	document.getElementById(showLessIconId).style.display = 'none';
	document.getElementById(showLessLinkId).style.display = 'none';
	document.getElementById(showMoreIconId).style.display = '';	
	document.getElementById(showMoreLinknId).style.display = '';	
}
function shuffleArray(array)
{
	return array.sort(function() {return 0.5 - Math.random()})
}
function callAjaxFile(queryString,resultId,page)
{	
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	var showId = resultId;	
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} 
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		 {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
		
	}
	
	// Create a function that will receive data sent from the server
	var ajaxDisplay = '';
	
	ajaxRequest.onreadystatechange = function()
	{	
		if(ajaxRequest.readyState == 4)
		{			
			var response = ajaxRequest.responseText;
			
			switch(page)
			{				
				case 'my_playlist':					
					showErrMsg(showId,splitResponse[1]);
					break;
				
				case 'search_results':
					
					var result = '';
					splitQueryString = queryString.split('&');
					
					var loopSplit = splitQueryString[2].split('=');
					
					var loop = loopSplit[1];
					
					result += '<table width="250" border="0" cellspacing="0" cellpadding="2" align="center">';
					
					result += '<tr><td colspan="2"><table width="100%"><tr><td width="93%;"><div id="showErrorMessage'+loop+'" class="MusicErrorMSG1"></div>&nbsp;</td><td width="7%;"><img src="images/but_close.gif" alt="" width="13" height="13" title="Close" border="0" style="cursor:pointer;" onClick="closeDiv(\'playList\');"/></td></tr></table></td></tr>';
					
					result += '<tr><td align="right" valign="middle">Playlist</td><td><span id="playListId'+loop+'">'+response+'</span></td></tr><tr><td align="center" valign="middle" colspan="2"><span id="newPlayList'+loop+'" style="display:none";><table width="100%"><tr><td width="26%" align="right">Title</td><td width="74%" align="left"><input name="new'+loop+'" id="new'+loop+'" type="text" class="TextFielsdBRDRNopadding"  style="padding:0" value=""/></td></tr></table></span></td></tr><tr><td>&nbsp;</td><td>';
					//result += '<img src="images/but_add.gif" alt="" width="35" height="19" border="0" title="Add to Playlist" onClick="validate_add_to_playlist(\'playListId'+loop+'\',\'newPlayList'+loop+'\','+loop+',\'playList\',0);"/>';
					result += '</td></tr></table>';					
					document.getElementById(showId).innerHTML = result;
					
					break;
				
				case 'search_results1':
					
					var result = '';
					splitQueryString = queryString.split('&');
					
					var loopSplit = splitQueryString[2].split('=');
					
					var loop = loopSplit[1];
					
					result += '<table width="250" border="0" cellspacing="0" cellpadding="2" align="center">';
					
					result += '<tr><td colspan="2"><table width="100%"><tr><td id="showErrorMessage'+loop+'" class="MusicErrorMSG1" width="93%;">&nbsp;</td><td width="7%;"><img src="images/but_close.gif" alt="" width="13" height="13" title="Close" border="0" style="cursor:pointer;" onClick="closeDiv(\'playList\');"/></td></tr></table></td></tr>';
					
					result += '<tr><td align="right" valign="middle">Playlist</td><td><span id="playListId'+loop+'">'+response+'</span></td></tr><tr><td align="center" valign="middle" colspan="2"><span id="newPlayList'+loop+'" style="display:none";><table width="100%"><tr><td width="26%" align="right">Title</td><td width="74%" align="left"><input name="new'+loop+'" id="new'+loop+'" type="text" class="TextFielsdBRDRNopadding"  style="padding:0" value=""/></td></tr></table></span></td></tr><tr><td>&nbsp;</td><td>';
					//result += '<img src="images/but_add.gif" alt="" width="35" height="19" border="0" title="Add to Playlist" onClick="validate_add_to_playlist(\'playListId'+loop+'\',\'newPlayList'+loop+'\','+loop+',\'playList\',1);"/>';
					result += '</td></tr></table>';					
					document.getElementById(showId).innerHTML = result;
					
					break;
				default:
					document.getElementById(showId).innerHTML = response;
					break;
			}// end switch case		
			
		}//end if		
	}	
	ajaxRequest.open("POST", queryString, true);
	ajaxRequest.send(null);	
}
function RemoveElement(elementnr,arrayName) 
{	
	var len = arrayName.length;	
	for (var i=elementnr;i<len;i++) 
	{		
		arrayName[i] = arrayName[i + 1];
	}	
	return arrayName.length-1;	
}
