function xmlhttpvdidPlaylist(strURL,a,b,c,d,e,f,MP_ROOTPATH,divid) {
    var xmlHttpReqPlaylist = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReqPlaylist = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReqPlaylist = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReqPlaylist.open('POST', strURL, true);
    self.xmlHttpReqPlaylist.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReqPlaylist.onreadystatechange = function() {
        if (self.xmlHttpReqPlaylist.readyState == 4) {
            generateplaylist(self.xmlHttpReqPlaylist.responseText,divid);
			}
	 }
    self.xmlHttpReqPlaylist.send(getquerynextvdidPlaylist(a,b,c,d,e,MP_ROOTPATH));
   }

function getquerynextvdidPlaylist(a,b,c,d,e,MP_ROOTPATH)
{
	if(document.getElementById('thumbPL'))
	var thumbBlock = document.getElementById('thumbPL').style.display;
	else
	var thumbBlock ='block';
	if(document.getElementById('listPL'))
	var listBlock = document.getElementById('listPL').style.display;
	else
	var listBlock = 'none';
	
	if(a == 'showplaylist')
	{
		qstr ='embedplaylist='+escape(MP_ROOTPATH)+"||"+escape(b)+"||"+escape(thumbBlock)+"||"+escape(listBlock);
	}
	else if(a == 'addtoplaylist')
	{
		var playlist = document.getElementById('playlistids').value;
		if(playlist != '')
		b = playlist+"*"+b;
		qstr ='embedplaylist='+escape(MP_ROOTPATH)+"||"+escape(b)+"||"+escape(thumbBlock)+"||"+escape(listBlock);
	}
	else
	{
		qstr ='Playlsit=' + escape(b)+"||||*****||||"+escape(c)+"||||*****||||"+escape(d)+"||||*****||||"+escape(e)+"||||*****||||"+escape(MP_ROOTPATH);
	}
	return qstr;
}
function generateplaylist(str,divid)
{
	document.getElementById(divid).innerHTML =str;
	if(document.getElementById('searchboxLoader')){
		document.getElementById('searchboxLoader').style.display='none';
	}
}


function minimizePlaylist(MP_ROOTPATH)
{
	if(document.getElementById('playlistData').style.display=='none')
	{
		document.getElementById('playlistData').style.display='block';
		if(document.getElementById('playlist_sendsaveSection')){
			document.getElementById('playlist_sendsaveSection').style.display='block';
		}
		document.getElementById('PlaylistFooter').style.display='block';
		document.getElementById('plMaxMin').src= MP_ROOTPATH+"playlist/images/minus.gif";
	}
	else
	{
		document.getElementById('playlistData').style.display='none';
		if(document.getElementById('playlist_sendsaveSection')){
			document.getElementById('playlist_sendsaveSection').style.display='none';		
		}
		document.getElementById('PlaylistFooter').style.display='none';
		document.getElementById('plMaxMin').src=MP_ROOTPATH+'playlist/images/plus.gif';
	}
}

//when mouse over + mark reacting the playlist as it is adding to that place

function reactPlaylist(MP_ROOTPATH)
{ 
	if(document.getElementById('thumbPL').style.display=='block')
	{
		if(document.getElementById('react').value==1)
		{
			if(document.getElementById('react_Thumb_view_1').style.backgroundImage == "url("+MP_ROOTPATH+"playlist/images/empty_thumbnail_background.gif)")
			{document.getElementById('react_Thumb_view_1').style.backgroundImage = "url("+MP_ROOTPATH+"playlist/images/thumbnail_moodio_background_active.gif)";}
			else
			{document.getElementById('react_Thumb_view_1').style.backgroundImage =  "url("+MP_ROOTPATH+"playlist/images/empty_thumbnail_background.gif)";}
			
			window.setTimeout("reactPlaylist('"+MP_ROOTPATH+"')",105);
		}
		else
		{
			document.getElementById('react_Thumb_view_1').style.backgroundImage =  "url("+MP_ROOTPATH+"playlist/images/empty_thumbnail_background.gif)";
		}
	}
	else
	{
		if(document.getElementById('react').value==1)
		{
			if(document.getElementById('react_List_view_1').style.backgroundImage == "url("+MP_ROOTPATH+"playlist/images/mini_thumbnail_moodio_background.gif)")
			{document.getElementById('react_List_view_1').style.backgroundImage = "url("+ MP_ROOTPATH+"playlist/images/mini_thumbnail_moodio_background_active.gif)";}
			else
			{document.getElementById('react_List_view_1').style.backgroundImage =  "url("+MP_ROOTPATH+"playlist/images/mini_thumbnail_moodio_background.gif)";}

			window.setTimeout("reactPlaylist('"+MP_ROOTPATH+"')",105);
		}
		else
		{
			document.getElementById('react_List_view_1').style.backgroundImage =  "url("+MP_ROOTPATH+"playlist/images/mini_thumbnail_moodio_background.gif)";
		}
	}
}
function removePlaylist(id)
{
	var playlistItems = '';
	var ExistPlaylist = document.getElementById('playlistids').value;
	var ExistPlaylist1 = ExistPlaylist.split('*');
	
    for(var i = 0; i<ExistPlaylist1.length;i++)
	{
		if(playlistItems != '' && ExistPlaylist1[i] != id)
		{
			playlistItems = playlistItems+"*"+ExistPlaylist1[i];
		}
		if(playlistItems == '' && ExistPlaylist1[i] != id)
		{
			playlistItems = ExistPlaylist1[i];
		}		
	}
    
	playlist = playlistItems;    
    xmlhttpvdidPlaylist(MP_ROOTPATH+'playlist/playlist.php','showplaylist',playlistItems,'','','','',MP_ROOTPATH,'forPlaylist');
	
} 
function clearPlaylist()
{	
	playlist = '';	
    xmlhttpvdidPlaylist(MP_ROOTPATH+'playlist/playlist.php','showplaylist',playlist,'','','','',MP_ROOTPATH,'forPlaylist');
}

function checkPlaylistEmailBox(defaultValue){
	var email_Format = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;
	var emailAdd = RTrim(LTrim(document.getElementById('playlist_email').value));
	if(emailAdd == '' || emailAdd.search(email_Format) == -1){
		document.getElementById('playlist_email').style.border='1px solid red';
	}else{
		document.getElementById('sendplaylistBox').style.display='block';
		showplaylistSendBox();
		document.getElementById('playlist_email').style.border='1px solid #E2DCD7';
		document.getElementById('playlist_email').value = defaultValue;
	}
}

function showplaylistSendBox()
{
	xmlhttpvdidPlaylistBOX(MP_ROOTPATH+'playlist/sendplaylist.php','showbox','','','','','',MP_ROOTPATH)
}
//*************************************************************
function xmlhttpvdidPlaylistBOX(strURL,a,b,c,d,e,f,MP_ROOTPATH) {
    var xmlHttpReqPlaylistBOX = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReqPlaylistBOX = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReqPlaylistBOX = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReqPlaylistBOX.open('POST', strURL, true);
    self.xmlHttpReqPlaylistBOX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReqPlaylistBOX.onreadystatechange = function() {
        if (self.xmlHttpReqPlaylistBOX.readyState == 4) {
            generateplaylistBOX(self.xmlHttpReqPlaylistBOX.responseText);
			}
	 }
    self.xmlHttpReqPlaylistBOX.send(getquerynextvdidPlaylistBOX(a,b,c,d,e,f,MP_ROOTPATH));
   }

function getquerynextvdidPlaylistBOX(a,b,c,d,e,f,MP_ROOTPATH)
{
	var sendPlaylistEmail;
	if(a == 'showbox'){
		sendPlaylistEmail = document.getElementById('playlist_email').value;
		qstr ='showbox=' +escape(MP_ROOTPATH)+"**##**"+escape(sendPlaylistEmail);
	}
	return qstr;
}
function generateplaylistBOX(str,divid)
{
	document.getElementById('sendplaylistBoxHolder').innerHTML =str;
}


///Play list functions to send box
//Toadd more emails in send playlist
function add_moreemails()
{
	var oRows = document.getElementById('addtable').getElementsByTagName('tr');
	var iRowCount = oRows.length;
	var row = parseInt(iRowCount) ;
   // alert(row)
	var fid = parseInt(row)- 6;
	//alert(fid);
	var newrow = document.getElementById('addtable').insertRow(row);
	var b = newrow.insertCell(0);

	var numurls = document.getElementById('numberofemails').value;
	document.getElementById('numberofemails').value = parseInt(numurls)+1;
	document.getElementById('send_emailfiled').value = parseInt(document.getElementById('send_emailfiled').value)+1;
	var newurlrow =  parseInt(numurls)+1;
	var emailvalue=document.getElementById('emailvalue').value;
	var acontent ='';
	var bcontent  ='';
	   bcontent  +='<input type="text" name="pll_emails'+newurlrow+'" id="pll_emails'+newurlrow+'" style="border:1px solid #E2DCD7;margin-top:2px;background-color:#DCD3CE;width:224px; padding:1px; " size="30" value="" onFocus=select()>';
	   bcontent  +='<a style="cursor:pointer;font-size:10px;font-weight:normal; color:#15A1C6;" title="Delete Email" onclick="remove_moreemails(this);">(remove)</a>';
	b.innerHTML = bcontent;
}
function remove_moreemails(tis)
{
	var table = document.getElementById('addtable');
	var i = tis.parentNode.parentNode.rowIndex;
	table.deleteRow(i);
}
function showhidestringcode()
{
	if(document.getElementById('captchacode').style.display=='block')
	{document.getElementById('captchacode').style.display='none';}
	else
	{document.getElementById('captchacode').style.display='block';}
}

//for captcha refresh
function xmlhttpvdpartner12cap(strURL) {
	//document.getElementById('loader_playlist').style.display='block';
    var xmlHttpReq2 = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq2 = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq2.open('POST', strURL, true);
    self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq2.onreadystatechange = function() {
        if (self.xmlHttpReq2.readyState == 4) {
            updatenextvdpartner12cap(self.xmlHttpReq2.responseText);
			//document.getElementById('loader_playlist').style.display='none';
        }
	 }
    self.xmlHttpReq2.send(getquerynextvdpartner12cap());
   }

function getquerynextvdpartner12cap()
{
	qstr ='refresh='+escape('x');
	return qstr;
}

function updatenextvdpartner12cap(str4){
	document.getElementById("ref").innerHTML = str4;
	//alert(str4);

}
//to check the captcha string
function checkstringvalidate(ses_string)
{
	var entered_string = document.getElementById('sessioncheck').value;
	var ses_string = document.getElementById('ses_string').value;
	if(entered_string != ses_string)
	{
		document.getElementById('sessioncheck').style.border='1px solid red';
	}
	else
	{
		document.getElementById('sessioncheck').style.border='1px solid #E2DCD7';
	}
}
function reversestate()
{
	document.getElementById('sendplaylistBox').style.display='none';
}
//check the form of the playlist
// Removes ending whitespaces
function RTrim( value ) 
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
function LTrim( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

function checkform()
{
   	var numofemails = document.getElementById('numberofemails').value;
	//this line commented because there is no captcha anymore
	//var ses_string = document.getElementById('ses_string').value;
	var email_Format = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;
	var done = 1;
	var email_Value1 = RTrim(LTrim(document.getElementById('myemail').value));
	if(email_Value1 == '')
	{
		done = 0;
		document.getElementById('myemail').value='';
		document.getElementById('myemail').style.border='1px solid red';
	}
	else if(email_Value1.search(email_Format)== -1)
	{
		done = 0;
		document.getElementById('myemail').style.border='1px solid red';
	}	
	else
	{
		done = 1;
		document.getElementById('myemail').style.border='0px solid red';
	}
	if(done == 1){
		for(var i = 1;i <= numofemails;i++)
		{
			if(document.getElementById('pll_emails'+i))
			{
				var email_Value = document.getElementById('pll_emails'+i).value;
				if(email_Value.search(email_Format)== -1)
				{
					done = 0;
					document.getElementById('pll_emails'+i).style.border='1px solid red';
				}
				else
				{
					done = 1;
					document.getElementById('pll_emails'+i).style.border='0px solid red';
				}
			}
		}
	}
	
	if(done == 1)
	{
		//validate captcha
		xmlhttpvdcaptcha(MP_ROOTPATH+'playlist/sendplaylist.php','validate_captcha')
	}
}

//sending
function xmlhttpvdcaptcha(strURL,a) {//alert('here');
    var xmlHttpReqEmail = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReqEmail = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReqEmail = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReqEmail.open('POST', strURL, true);
    self.xmlHttpReqEmail.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReqEmail.onreadystatechange = function() {
        if (self.xmlHttpReqEmail.readyState == 4) {
            response_xmlhttpvdcaptcha(self.xmlHttpReqEmail.responseText);
			$('#loader_comment').hide();
        }
	 }
    self.xmlHttpReqEmail.send(getqueryvdcaptcha(a));
   }

function getqueryvdcaptcha(a)
{
	if(a == 'validate_captcha')
	{
		var numofemails = document.getElementById('numberofemails').value;

		var emails = '';
		for(var i = 1;i<=numofemails;i++)
		{
			if(document.getElementById('pll_emails'+i))
			{
				if(emails == '')
				{
					emails = document.getElementById('pll_emails'+i).value;
				}
				else
				{
					emails = emails+"*"+document.getElementById('pll_emails'+i).value;
				}
			}
		}
		var  names ='';
		var playlistitems = document.getElementById('playlistids').value;
		var subject = document.getElementById('playlistmsg').value;
		var myname = document.getElementById('myemail').value;
		var titleplaylist ='';
		var entered_string = document.getElementById('sessioncheck').value;		
        var titleplaylist = '0';
		qstr ='validate=' + escape(subject)+"##-##"+escape(myname)+"##-##"+escape(titleplaylist)+"##-##"+escape(numofemails)+"##-##"+escape(emails)+"##-##"+escape(names)+"##-##"+escape(playlistitems)+"##-##"+escape(entered_string);
	}
	return qstr;
}

function response_xmlhttpvdcaptcha(str6)
{
	if(str6 == 'CAPCHA_ERROR')
	{
		document.getElementById('sessioncheck').style.border='1px solid red';done = 0;
	}
	else
	{
		xmlhttpvdidemail(MP_ROOTPATH+'playlist/sendplaylist.php','sendemails')
	}
}

//sending
function xmlhttpvdidemail(strURL,a) {
	document.getElementById('loader_email').style.display='block';
    var xmlHttpReqEmail = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReqEmail = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReqEmail = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReqEmail.open('POST', strURL, true);
    self.xmlHttpReqEmail.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReqEmail.onreadystatechange = function() {
        if (self.xmlHttpReqEmail.readyState == 4) {
            updatenextvdidemail(self.xmlHttpReqEmail.responseText);
            $('#loader_comment').hide();
        }
	 }
    self.xmlHttpReqEmail.send(getquerynextvdidemail(a));
   }

function getquerynextvdidemail(a)
{
	if(a == 'sendemails')
	{
		var numofemails = document.getElementById('numberofemails').value;

		var emails = '';
		for(var i = 1;i<=numofemails;i++)
		{
			if(document.getElementById('pll_emails'+i))
			{
				if(emails == '')
				{
					emails = document.getElementById('pll_emails'+i).value;
				}
				else
				{
					emails = emails+"*"+document.getElementById('pll_emails'+i).value;
				}
			}
		}
		var  names ='';
		var playlistitems = document.getElementById('playlistids').value;
		var subject = document.getElementById('playlistmsg').value;
		var myname = document.getElementById('myemail').value;
		var titleplaylist ='';
		var entered_string = document.getElementById('sessioncheck').value;
		//var titleplaylist = document.getElementById('titleplaylist').value;
        var titleplaylist = '0';
		qstr ='sendmails=' + escape(subject)+"##-##"+escape(myname)+"##-##"+escape(titleplaylist)+"##-##"+escape(numofemails)+"##-##"+escape(emails)+"##-##"+escape(names)+"##-##"+escape(playlistitems)+"##-##"+escape(entered_string);
	}
	return qstr;
}

function updatenextvdidemail(str6)
{
	if(str6 == 'CAPCHA_ERROR')
	{
		document.getElementById('sessioncheck').style.border='1px solid red';done = 0;
		document.getElementById('loader_email').style.display='none';
	}
	else
	{
		document.getElementById("sendplaylistBoxHolder").innerHTML = str6;
		window.setTimeout('closemsgplaylistsent()',4500);
	}
}
function closemsgplaylistsent()
{
	document.getElementById("SPdiv2").style.display='none';
    document.getElementById("SPdiv1").style.display='block';
	document.getElementById("sendplaylistBox").style.display='none';
}
//for memberpage 
function setplaylistMP(value)
{
	//Folowing section to check wheather added or not
	var add =1;
	var playlist1 = playlist.split('*');
	for(var i = 0 ; i<playlist1.length;i++)
	{
		if(playlist1[i] == value)
		add = 0;
	}
	//End of Folowing section to check wheather added or not
	if(add == 1)
	{
		//addthis to the html playlist
		xmlhttpvdidPlaylist(MP_ROOTPATH+'playlist/playlist.php','addtoplaylist',value,'','','','',MP_ROOTPATH,'forPlaylist');	
		if(playlist == '')
		playlist = value;
		else
		playlist =playlist+"*"+value;
	}
}

