/************************************* this is the default handle function of ajax*****************************************/
function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function searchHeader()
{ //alert('surendra');
 	    s_search_by=document.getElementById("search_by").value;
	    s_search_text=document.getElementById("search_text").value;
		s_channel_id=document.getElementById("song_channel").value;
	    		
		var url="searchResult.php?search_by="+s_search_by+"&search_text="+s_search_text+"&channel_id="+s_channel_id+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(searchconta_div)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 
function searchMainIndex(id)
{ 
 	   s_start=document.getElementById("slider:startPrice").value;
		s_end=document.getElementById("slider:endPrice").value;
	   var url="searchResult.php?search_t="+id+"&startYear="+s_start+"&endYear="+s_end+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(searchconta_div)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

}
function searchconta_div() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("searchresultDiv").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("indexDiv").innerHTML=''
		document.getElementById("searchresultDiv").innerHTML=xmlHttp.responseText 
	}
} 
function pagingsearchHeader(j)
{ 

 	 	s_search_by=document.getElementById("search_by").value;
	    s_search_text=document.getElementById("search_text").value;
		s_channel_id=document.getElementById("song_channel").value;
		s_search_letter=document.getElementById("search_letter").value;
		
		s_start=document.getElementById("slider:startPrice").value;
		s_end=document.getElementById("slider:endPrice").value;
			    		
		var url="searchResult.php?pageNum_rr="+j+"&selectme="+j+"&search_by="+s_search_by+"&search_text="+s_search_text+"&channel_id="+s_channel_id+"&search_t="+s_search_letter+"&startYear="+s_start+"&endYear="+s_end+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(searchconta_div)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 


function getCategory(id)
{ 
		var url="cat_div.php?channel="+id+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(getcat_div)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 
function getcat_div() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("chan_cat").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("chan_cat").innerHTML=xmlHttp.responseText 
	}
}

function getGenre(id)
{ 

    		
		var url="genre_div.php?category="+id+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(getgener_div)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 
function getgener_div() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("chan_genre").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("chan_genre").innerHTML=xmlHttp.responseText 
	}
}

function checkall()
{
		var ss;
		var allCheckbox=document.getElementById("totalSongs").value;
		if(document.getElementById("selectall").checked == true )
		{
		   for(ss=1;ss<allCheckbox;ss++)
		   {
			   document.getElementById("selectSong"+ss).checked=true;
		   }
		   document.getElementById("selectall2").checked = true;
		}
		else
		{
		   for(ss=1;ss<allCheckbox;ss++)
		  {
			 document.getElementById("selectSong"+ss).checked=false;
		  }
		  document.getElementById("selectall2").checked = false;
		}

}
function checkall2()
{
		var ss;
		var allCheckbox=document.getElementById("totalSongs").value;
		if(document.getElementById("selectall2").checked == true )
		{
		   for(ss=1;ss<allCheckbox;ss++)
		   {
			   document.getElementById("selectSong"+ss).checked=true;
		   }
		   document.getElementById("selectall").checked = true;
		}
		else
		{
		   for(ss=1;ss<allCheckbox;ss++)
		  {
			 document.getElementById("selectSong"+ss).checked=false;
		  }
		  document.getElementById("selectall").checked = false;
		}

}
function AdvanceSearch()
{
	
	s_searchKeyword=document.getElementById("searchKeyword").value;
	s_movie=document.getElementById("movie").value;
	s_channel=document.getElementById("channel").value;
	s_category=document.getElementById("category").value;
	
	s_genre=document.getElementById("genre").value;
	s_song_themes=document.getElementById("song_themes").value;
	s_singers=document.getElementById("singers").value;
	s_lyricist=document.getElementById("lyricist").value;
	
	s_musician=document.getElementById("musician").value;
	s_actor=document.getElementById("actor").value;
	s_actress=document.getElementById("actress").value;
	s_song_year=document.getElementById("song_year").value;
	
	var url="advanceSearchResult.php?searchKeyword="+s_searchKeyword+"&movie="+s_movie+"&channel="+s_channel+"&category="+s_category+"&genre="+s_genre+"&song_themes="+s_song_themes+"&singers="+s_singers+"&lyricist="+s_lyricist+"&musician="+s_musician+"&actor="+s_actor+"&actress="+s_actress+"&song_year="+s_song_year+"&search=y";
	//alert(url);
	xmlHttp=GetXmlHttpObject(advance_divS)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
}

function pagingsearchAdvance(j)
{ 

 	s_searchKeyword=document.getElementById("searchKeyword").value;
	s_movie=document.getElementById("movie").value;
	s_channel=document.getElementById("channel").value;
	s_category=document.getElementById("category").value;
	
	s_genre=document.getElementById("genre").value;
	s_song_themes=document.getElementById("song_themes").value;
	s_singers=document.getElementById("singers").value;
	s_lyricist=document.getElementById("lyricist").value;
	
	s_musician=document.getElementById("musician").value;
	s_actor=document.getElementById("actor").value;
	s_actress=document.getElementById("actress").value;
	s_song_year=document.getElementById("song_year").value;
			    		
		
		var url="advanceSearchResult.php?pageNum_rr="+j+"&selectme="+j+"&searchKeyword="+s_searchKeyword+"&movie="+s_movie+"&channel="+s_channel+"&category="+s_category+"&genre="+s_genre+"&song_themes="+s_song_themes+"&singers="+s_singers+"&lyricist="+s_lyricist+"&musician="+s_musician+"&actor="+s_actor+"&actress="+s_actress+"&song_year="+s_song_year+"&search=y";
	//alert(url);
		
		xmlHttp=GetXmlHttpObject(advance_divS)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 

function advance_divS() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("advanceSearchresultDiv").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("advanceSearchresultDiv").innerHTML=xmlHttp.responseText 
	}
}


function playSelectedSongs()
{
	
	var flag=0;
	var allIds;
	var allCheckbox=document.getElementById("totalSongs").value;
	for(ss=1;ss<allCheckbox;ss++)
	{
	   if(document.getElementById("selectSong"+ss).checked==true)
	   {
		   if(allIds)
		   {
			   allIds=allIds+","+document.getElementById("selectSong"+ss).value;
		   }
		   else
		   {
			   allIds=document.getElementById("selectSong"+ss).value
		   }
		   flag=1;	   
	   }
	}
	if(flag==0)
	{
		alert('Please select atleast one????');
		return false;
	}
	
		var url="player/player.php?songsIds="+allIds;
          mywindow =window.open(url,"Play Songs", "toolbar=no,directories=no,location=no,height=300,width=450,status=no,menubar=no,resizable=yes,scrollbars=yes");
  mywindow.moveTo(1,1);
	
} 


///////////////////////////////////
function showAdd()
 {
  	document.getElementById("fornewPl").style.display="block";
 }
 function hideAdd()
 {
  	document.getElementById("fornewPl").style.display="none";
 }


function addPlaylist()
{ 

		m_name=document.getElementById("movie_name").value;
		var url="u_playlist.php?playlist_name="+m_name+"&search=y";
		//alert(url);
		xmlHttp=GetXmlHttpObject(newplDiv)
		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)

} 
function newplDiv() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("userPlalist").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("fornewPl").style.display="none";
		document.getElementById("userPlalist").innerHTML=xmlHttp.responseText 
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////
function addSongsinPlaylist()
{
	
	var flag=0;
	var allIds;
	var allCheckbox=document.getElementById("totalSongs").value;
	for(ss=1;ss<allCheckbox;ss++)
	{
	   if(document.getElementById("selectSong"+ss).checked==true)
	   {
		   if(allIds)
		   {
			   allIds=allIds+","+document.getElementById("selectSong"+ss).value;
		   }
		   else
		   {
			   allIds=document.getElementById("selectSong"+ss).value
		   }
		   flag=1;	   
	   }
	}
	if(flag==0)
	{
		alert('Please select atleast one????');
		return false;
	}
	 if(document.getElementById("playlist").value=='')
	 {
		alert('Please select playlist to add song????');
		document.getElementById("playlist").focus();
		return false;
	 }
	 var playlist=document.getElementById("playlist").value;
	var url="advanceSearchResult.php?songsIds="+allIds+"&playlistS="+playlist+"&search=y&action=addPlaylisy";
	//alert(url);
    xmlHttp=GetXmlHttpObject(addsong_divS)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
} 

function addsong_divS() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("advanceSearchresultDiv").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("advanceSearchresultDiv").innerHTML=xmlHttp.responseText 
	}
}


///////////////////////////////////////////////////////////////////////////

function playPlayList()
{
		
	 if(document.getElementById("playlist").value=='')
	 {
		alert('Please select playlist to play songs????');
		document.getElementById("playlist").focus();
		return false;
	 }
	var allplaylist=document.getElementById("playlist").value;
	
	var url="player/player.php?PlayListId="+allplaylist;
	//alert(url);
          mywindow =window.open(url,"Play Songs", "toolbar=no,directories=no,location=no,height=300,width=450,status=no,menubar=no,resizable=yes,scrollbars=yes");
  mywindow.moveTo(1,1);
	
} 



////////////////////////////////////////////////////////////////////////////////////////////////
function addSongsinPlaylist2()
{
	
	var flag=0;
	//var allIds;
//	var allCheckbox=document.getElementById("totalSongs").value;
//	for(ss=1;ss<allCheckbox;ss++)
//	{
//	   if(document.getElementById("selectSong"+ss).checked==true)
//	   {
//		   if(allIds)
//		   {
//			   allIds=allIds+","+document.getElementById("selectSong"+ss).value;
//		   }
//		   else
//		   {
//			   allIds=document.getElementById("selectSong"+ss).value
//		   }
//		   flag=1;	   
//	   }
//	}
//	if(flag==0)
//	{
//		alert('Please select atleast one????');
//		return false;
//	}
    var s_search_letter= document.getElementById("search_letter").value
    var s_start=document.getElementById("slider:startPrice").value;
	var s_end=document.getElementById("slider:endPrice").value;
		
     var allIds=document.getElementById("allSongs").value;
	 if(document.getElementById("playlist").value=='')
	 {
		alert('Please select playlist to add song????');
		document.getElementById("playlist").focus();
		return false;
	 }
	 var playlist=document.getElementById("playlist").value;
	var url="searchResult.php?songsIds="+allIds+"&playlistS="+playlist+"&search_t="+s_search_letter+"&startYear="+s_start+"&endYear="+s_end+"&search=y&action=addPlaylisy";
	//alert(url);
    xmlHttp=GetXmlHttpObject(addsong_divS2)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
	
} 

function addsong_divS2() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("searchresultDiv").innerHTML="<img src='images/loading.gif'>&nbsp;&nbsp;" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("searchresultDiv").innerHTML=xmlHttp.responseText 
	}
}


///////////////////////////////////////////////////////////////////////////

function scheduleSongs(){
	
    if( document.getElementById("playlist").value=='')
	{
		alert('Please select playlist');
		return false;
	}
	var id= document.getElementById("playlist").value;   
	emailwindow=dhtmlmodal.open('UserBox', 'iframe', 'schedule_song.php?playlist_id='+id, 'Schedule Playlist', 'width=650px,height=350px,center=1,resize=1,scrolling=1')

}
