/**
 * FunRock Javascripts
 */
var FunRock = {};

FunRock.i18n = {
	less: 'less',
	more: 'more',
	confirmDelete: 'Are you sure you want to delete?'
};

FunRock.Datagrid = {
	handleSort:function(e){
		if ($(this).closest('table').hasClass('not-grid')) {
			return false;
		}
		var newclass = 'sortedAscend';
			var sort = $(this).attr('rel');
			if (sort == '') {
				e.stopPropagation();
				e.preventDefault();
				return false;
			}

			if ($(this).hasClass('sortedAscend')) {
				newclass = 'sortedDescend';
			}
			$(this).closest('tr').find('th a').removeClass('sortedAscend').removeClass('sortedDescend');
			$(this).addClass(newclass);
						
			var $parent = $(this).closest('form');
			
			
			$parent.block({
		    	message: $('.ajax_data_container')
	    			.html('<img src="/img/ajax-loader.gif" alt=""/>')
			});

			var $table = $parent.find('table.data_container');
			var action = $parent.attr('action');

			var action_params = '/page:1/sort:' + sort + '/direction:' + (newclass == 'sortedDescend' ? 'desc' : 'asc') + '/index.json'
			if (-1 != action.indexOf('?')) {
				action = action.split('?');
				action = action[0] + action_params + '?' + action[1];
			} else {
				action += action_params;
			}
			jQuery.getJSON(action, {}, function(resp) {
				$parent.unblock();
				if (resp.status) {
					$table.find('tr:gt(0)').remove();
					$table.append(resp.data);
								
					$('tr:even', $table).addClass('alt');
				}
			});

			e.stopPropagation();
			e.preventDefault();
	},
	paging: function (e) {
		var page = $(this).attr('href');

		page = page.split('page:')[1];
		page = parseInt(page);

		var $form_data = null;
		var $parent = null;
		var action = null;
		var data_type='json';
		$parent = $('form.ajax_search_form:visible');

		var $div = $('div.ajax_data_container:visible');

		var $page_bar_container = $('p.pagination');
		
	  	var action_params =  '/page:' + page + '/index.json';

		if($parent.is('form')){
			action = $parent.attr('action');
		  	$form_data = $('form.ajax_search_form:visible').serialize();
		}
		else{
			action = $(this).attr('href').split('/page:')[0];
			data_type = 'html';
			action_params =  '/page:' + page
		}

		if (-1 != action.indexOf('?')) {
			action = action.split('?');
			action = action[0] + action_params + '?' + action[1];
		} else {
			action += action_params;
		}

		$.ajax({
			type:'POST',
			beforeSend:FunRock.Loader.enable,
			url:action,
			data:$form_data,
			dataType:data_type,
			success:function(resp) {
				
				if (resp.status){
					$div.html(resp.data);
					if (resp.pagination) {
						$page_bar_container.replaceWith(resp.pagination);
					}
					$('.toon_icon').filter('.Drum').addClass('big_icon');
					FunRock.Icon.hideIconInBasket();
				}else{
					$div.replaceWith(resp);
				}
			},
			complete:FunRock.Loader.disable
		});

		e.stopPropagation();
		e.preventDefault();
		return false;		
	}
	

};

FunRock.Cookie={
	list:function(){
		var cookies = { };
		if (document.cookie && document.cookie != '') {
			var split = document.cookie.split(';');
			for (var i = 0; i < split.length; i++) {
				var name_value = split[i].split("=");
				name_value[0] = name_value[0].replace(/^ /, '');
				cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
			}
		}
		return cookies;
	}
}

FunRock.Dialog={
    open:function(message,style,options){

            var basic_style={
                title:'',
                message:'Put Some message here',
                headClass:'head_error',
                headText:'Change me'
            };

            style = $.extend(basic_style,style);

            $('#FunRockWindow').attr('title',style.title);

            $('#FunRockWindow h2#head').addClass(style.headClass);
            $('#FunRockWindow h2#head').html(style.headText)
            $('#FunRockWindow #message_box').html(message);

            var basic_options = {
                    width:330,
                    height:'auto',
                    bgiframe: true,
                    modal: true,
                    resizable:false,
                    draggable:false,
                    buttons:{
                            'Ok':function(){
                                    $(this).dialog('close');
                            }
                    },
                    close:function(e){
                            $(this).dialog('destroy');
                    }
            }
            var dialog_options = $.extend(basic_options,options);
            $('#FunRockWindow').dialog(dialog_options);

	},
	close:function(){
		$('#FunRockWindow').dialog('destroy');
	}
}

FunRock.Icon={
	hideIconInBasket:function(){
		var $selected_toons = $('div#selected .toon_icon a,div#dress_selected .toon_icon a')
		if($selected_toons){
			$.each($selected_toons.get(),function(idx,link){
				var hide_instrment_by_this_rel = $(link).attr('rel');
				var hide_dress_by_part =$(link).attr('rev');
				$('div#selectors  .toon_icon a[rel='+hide_instrment_by_this_rel+']').closest('.toon_link,.toon_link_vip,.toon_link_credit').hide();
				$('div#dress_selectors  .toon_icon a[rel='+hide_instrment_by_this_rel+'][rev='+hide_dress_by_part+']').closest('.toon_link,.toon_link_vip').hide();
			});
		}
	},
	edit:function(){
        var $link =$(this);
        var dt = new Date();
        $link.closest('.NW4').addClass('current_icon');
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url:'/userbandmembers/dress_for/'+$link.attr('id')+'/_=?'+dt.getTime(),
			success:function(data){
				FunRock.Dialog.open(data,{
					headClass:'success',
					title:'Appearance',
					headText:'How cool this is!'
					},
					{
					buttons:{
						Cancel:function(){
							FunRock.Dialog.close();		
						},
						Save:function(){
							$('form#assign_dress').submit();
						}
					}});
			},
			complete:FunRock.Loader.disableOnIcon
		});
	
	},
	points:function(){
		$('div.points').each(function(i,data){
			var value=parseInt($(data).attr('rel'));
			var bar_value = value;
			$(data).progressbar({value:bar_value});
		});
	},
	vip:function(e){
		e.stopPropagation();
		e.preventDefault();
		FunRock.Dialog.open("You can buy this member, when you become a VIP member","Invalid Selection",{title:'VIP\'s Only'});
	}
}

String.prototype.ReplaceAllString = function(stringToFind, stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
    while(index != -1){
        temp = temp.replace(stringToFind,stringToReplace);
        index = temp.indexOf(stringToFind);
    }
    return temp;
}


FunRock.Comment = {
	save:function(e){
			var timeAgo = '<p class="new_time_ago">few seconds ago</p>';			
			var $comment_form = $(this);
			var comment = $comment_form.find('textarea').val();
			var myNewString = comment.ReplaceAllString("\n", "<br />");
			var action = $comment_form.attr('action');
			$.ajax({
				type:'POST',
				dataType:'json',
				url:action+'/index.json',
				data:$comment_form.serialize(),
				beforeSend:function(){
					$comment_form.closest('div').block();
				},
				success:function(resp){
					if(resp.status){
						var band_link = $('#band_user').html();					
						$comment_form.closest('.comments_holder')
							.find('.comments_list')
							.append('<div class="comment"><p class="comment_para">'+band_link+': '+myNewString+'</p>'+timeAgo+'</div>');
						$comment_form.find('textarea').each(function(i,txt){
							$(txt).val('');
						});					
					}
				},
				complete:function(){
					$comment_form.closest('div').unblock();
				}
			});
			e.stopPropagation();
			e.preventDefault();	
		}
}


FunRock.Show={
	help:function(data){
		$('.ajax_data_container').html(data);
	}
}
FunRock.Loader={
	enable:function(options){
		$('.ajax_data_container').block({
			message:"<img src='/img/ajax-loader.gif' alt=''>",
			centerY:1
		});		
	},
	disable:function(){
		$('.ajax_data_container,.current_icon').unblock();
	},
	enableOnIcon:function(){
		$('.current_icon').block({
			message:"<img src='/img/ajax-loader.gif' alt=''>",
			centerY:1
		});		
	},
	disableOnIcon:function(){
		$('.current_icon').unblock();
		$('.current_icon').removeClass('current_icon');
	}
}

FunRock.Browser={
	check:function(){
		if($.browser.msie && Math.round($.browser.version)<8){
			FunRock.Dialog.open('Please Update your Browser');
		}
	}
}

jQuery(function() {
	// td.note -> td 
	//FunRock.Browser.check();
	
	$('form.datagrid table tr td a.more').live('click', function(e) {
		if ($(this).text() == FunRock.i18n.more) {
			$(this).closest('td').find('span:first').hide();
			$(this).closest('td').find('span.full_text').show();
			$(this).text(FunRock.i18n.less);
		}else{
			$(this).closest('td').find('span.full_text').hide();
			$(this).closest('td').find('span:first').show();
			$(this).text(FunRock.i18n.more);
		}		
		e.stopPropagation();
		e.preventDefault();
	});
	
	$('p.pagination a').live('click', FunRock.Datagrid.paging);
	FunRock.Icon.points();
	
	$('.toon_icon').draggable({revert:true,zIndex:9999,opacity:.8});
	
	$('a.toon_link_vip').live('click',FunRock.Icon.vip);
	 
	$("#tabs").tabs({
            spinner:'<img src="/img/loading.gif" alt="ajax-loader"/>',
            fx: {
                opacity: 'toggle'
            },
            select:function(e,ui){
            }
        });
});

$(function() {
		$("#buyitems_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});

function closeBuyItemDialog()
{
  $('#buyitems_dialog').dialog('close');
}

function linkFromBuyItemToVip()
{
  $('#buyitems_dialog').dialog('close');
  location.href = '/memberships/vip';
}

function linkFromBuyItemToCredit()
{
  $('#buyitems_dialog').dialog('close');
  location.href = '/credits/getCredit';
}

function linkFromGigToVip()
{
  closeGigReportWindow();
  location.href = '/memberships/vip';
}
	
function setItem(img_name, itemid, item_name, price, credit, txtprice, txtcredit, lessmoney, bandmoney, bandcredits, isvipitem, isvipuser)
{   
  document.getElementById('priceorcredit').style.display = 'none';
  document.getElementById('buyitem_err_msg').style.display = 'none';
  document.getElementById('buyitem_vip_err').style.display = 'none';
  document.getElementById('buyitemclose').style.display = 'none';
  document.getElementById('buybuttons').style.display = 'none';	
   
  var img_src = "/img/items/" + img_name;
  document.getElementById('itemimage').setAttribute("src", img_src);
  
  $('#itemname').html(item_name);
  
  var flag = 0;
  
  if((isvipitem == 1) && (isvipuser == 0))
  {
	document.getElementById('buyitem_vip_err').style.display = 'inline';	
	document.getElementById('buyitemclose').style.display = 'inline';	  
  }
  else
  {
	  if(price > 0)
	  {
		 document.getElementById('priceorcredit').innerHTML  = '<span style="color:white;">Price: </span><span style="color:yellow;">'+'$' + price + '</span>';
		 document.getElementById('priceorcredit').style.display = 'inline';
		 
		 if(parseInt(price) > parseInt(bandmoney))	 
		 {
			document.getElementById('errs_buyitem').innerHTML = '<span>' + 'You do not have enough money to buy this item.' + '</span>';
			document.getElementById('buyitem_err_msg').style.display = 'inline';
			
			document.getElementById('buyitemclose').style.display = 'inline';		
		 }
		 else
		 {
			document.getElementById('buyitemid').value = itemid;
			document.getElementById('buybuttons').style.display = 'inline';	 
		 }
	  }  
	  else
	  {
		 if(credit > 0)
		 {
			document.getElementById('priceorcredit').innerHTML  = '<span style="color:white;">Credit: </span><span style="color:yellow;">'+'$' + credit + '</span>';
			document.getElementById('priceorcredit').style.display = 'inline';	 
			
			if(parseInt(credit) > parseInt(bandcredits))		
			{
				document.getElementById('errs_buyitem').innerHTML = '<span>' + 'You do not have enough credits to buy this item. Buy more credits, ' + '</span>' + '<span style="font-weight:bold; font-size:14px; color:blue; text-decoration:underline;"><a href="javascript:linkFromBuyItemToCredit();">' + 'Click here' + '</a></span>';
				document.getElementById('buyitem_err_msg').style.display = 'inline';	

				document.getElementById('buyitemclose').style.display = 'inline';			
			}
			else
			{
				document.getElementById('buyitemid').value = itemid;
				document.getElementById('buybuttons').style.display = 'inline';	
			}
		 }
	  }
  }  
  
  $('#buyitems_dialog').dialog('open'); 
  
}

function buyItemForUser()
{
	location.href = '/users/myband/' + document.getElementById('buyitemid').value;
	$('#buyitems_dialog').dialog('close');
}

function setCountryId(id)
{
   	$.ajax({
			url:'/gigs/travel_ajax.json?countryid=' + id,
			dataType:'json',
			success:function(resp) {
				if(resp.status == 'moneyerror'){
					 $('#travelmoney_error').dialog('open');
			    }
				else
				{
				    if(resp.status == 'fanserror'){
					    $('#travelfans_error').dialog('open');
			        }
                    else
                    {
				        if(resp.status == 'successfull'){
							$("#travel_confirm").data("buttons.dialog", {
								No: function() {
									$('#travel_confirm').dialog('close');
								},									
								Yes: function() {
									$.ajax({
											url:'/gigs/savetraveldata_ajax.json?countryid=' + id,
											dataType:'json',
											success:function(resp) {
												if(resp.status){
													location.href = '/gigs/currentGig';
												}
										
										}
									});				
								}				
							});  						
						
					        $('#travel_confirm').dialog('open');
			            }	
                    }					
				}
		
		}
	});
}

$(function() {
		$("#travel_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true
		});
});

$(function() {
		$("#travelmoney_error").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			buttons: {
				Ok: function() {
				    $('#travelmoney_error').dialog('close');
				}			
			}
		});
});

$(function() {
		$("#travelfans_error").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			buttons: {
				Ok: function() {
				    $('#travelfans_error').dialog('close');
				}			
			}
		});
});

$(function() {
		$("#changepwd_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});


$(function() {
		$("#errormsg_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			buttons: {
				Ok: function() {
				    $('#errormsg_dialog').dialog('close');
				}	
			}
		});
});

$(function() {
		$("#changeemail_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

$(function() {
		$("#changepwd_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function closeChangeEmailConfirmDialog()
{
	$('#changeemail_confirm').dialog('close');
}
function closeband_memberDialog()
{
	$('#add_band_member_dialog').dialog('close');
}
function closeChangePwdConfirmDialog()
{
	$('#changepwd_confirm').dialog('close');
}

function closeChangePwdDialog()
{
	$('#changepwd_dialog').dialog('close');
}

function checkChangePassword()
{
	var oldpassword  = document.getElementById('old_password').value;
	var userpassword = document.getElementById('user_password').value;
	var confpassword = document.getElementById('confirm_password').value;
		
	if(oldpassword == '' || userpassword == '' || confpassword == '')
	{
	    if(oldpassword == '')
	    {
	       document.getElementById('errs_pwd_change').innerHTML = '<span>Please input the old password.</span>';
	       document.getElementById('changepwd_err_msg').style.display = 'inline';
		}
		else
        {		
		   if(userpassword == '')
		   {
	           document.getElementById('errs_pwd_change').innerHTML = '<span>Please input the new password.</span>';
	           document.getElementById('changepwd_err_msg').style.display = 'inline';		
		   }
           else
           {
			   if(confpassword == '')
			   {
				  document.getElementById('errs_pwd_change').innerHTML = '<span>Please input the confirm password.</span>';
				  document.getElementById('changepwd_err_msg').style.display = 'inline';		
			   }
           }		   
		}
	}
	else
	{
	    var re = /^[a-z0-9\s]+$/i;
	    if(!re.test(userpassword))
		{
	        document.getElementById('errs_pwd_change').innerHTML = '<span>Only Alphanumeric characters are allowed.</span>';
	        document.getElementById('changepwd_err_msg').style.display = 'inline';		
		}
		else
		{
		    if(userpassword.length < 6)
			{
	            document.getElementById('errs_pwd_change').innerHTML = '<span>Password must be at least 6 characters long.</span>';
	            document.getElementById('changepwd_err_msg').style.display = 'inline';			
			}
			else
			{				
				var $icon= $('.change_pwd_container').addClass('current_icon');
				
				$.ajax({
				    beforeSend:FunRock.Loader.enableOnIcon,
					url:'/users/passwordcheck_ajax?oldpwd=' + oldpassword + '&userpwd=' + userpassword + '&confpwd=' + confpassword,
					cache: false,
					success:function(html) {
					    	
						if(html == 'oldnotmatched'){
							document.getElementById('errs_pwd_change').innerHTML = '<span>Old password did not match.</span>';
							document.getElementById('changepwd_err_msg').style.display = 'inline';															
						}
						else
						{
						   if(html == 'confnotmatched')
						   {
							  document.getElementById('errs_pwd_change').innerHTML = '<span>Confirm password did not match.</span>';
							  document.getElementById('changepwd_err_msg').style.display = 'inline';							  
						   }
						   else
						   {
						      if(html == 'changeok')
							  {
								 $('#changepwd_dialog').dialog('close');								 
								 $('#changepwd_confirm').dialog('open');
							  }
						   }
						}
					},
					complete:FunRock.Loader.disableOnIcon
				});		    
			}
		}
	}
}

function changePassword()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    document.getElementById('changepwd_err_msg').style.display = 'none';
    $('#changepwd_dialog').dialog('open');
}  

function changeEmail()
{
	document.getElementById('changeemail_err_msg').style.display = 'none';
    $('#changeemail_dialog').dialog('open');
}

function closeChangeEmailDialog()
{
	$('#changeemail_dialog').dialog('close');
}

$(function() {
		$("#changeemail_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});


function checkChangeEmail()
{
	var emailaddress  = document.getElementById('email_address').value;
	
	if(emailaddress == '')
	{
	    document.getElementById('errs_email_change').innerHTML = '<span>Please input the email address.</span>';
	    document.getElementById('changeemail_err_msg').style.display = 'inline';	
	}
	else
	{
	    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		if(!emailRegEx.test(emailaddress))
		{
	        document.getElementById('errs_email_change').innerHTML = '<span>Please input a correct email address.</span>';
	        document.getElementById('changeemail_err_msg').style.display = 'inline';			   
		}
		else
		{
			var $icon= $('.change_email_container').addClass('current_icon');
				
			$.ajax({
			    beforeSend:FunRock.Loader.enableOnIcon,
				url:'/users/emailcheck_ajax?newemail=' + emailaddress,
				cache: false,
				success:function(html) {
					if(html == 'emailfound'){
						document.getElementById('errs_email_change').innerHTML = '<span>Email address already exist.</span>';
						document.getElementById('changeemail_err_msg').style.display = 'inline';					
					}
					else
					{
					    if(html == 'emailchangeok')
						{
							$('#changeemail_dialog').dialog('close');
							$('#changeemail_confirm').dialog('open');						
						}
					}
				},
				complete:FunRock.Loader.disableOnIcon
			});			   
		}
	}
}

function closePresentationDialog()
{
	$('#presentation_dialog').dialog('close');
}

function clearPresentationText()
{
	document.getElementById('presentation_text').value = '';
	document.getElementById('presentation_text').focus();
}

function setPresentationText()
{			
	if(document.getElementById('presentation_text').value == '')
	{
		document.getElementById('errs_presentation_change').innerHTML = '<span>Not found any presentation text to save.</span>';
		document.getElementById('presentation_err_msg').style.display = 'inline';	   
	}
	else
	{
    	var prs_text    = document.getElementById('presentation_text').value;
		var real_string = prs_text.ReplaceAllString("\n", "<br />");
					
		var $icon= $('.presentation_dialog_Container').addClass('current_icon');		

		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url:'/users/setpresentation_ajax?newtext=' + real_string,
			cache: false,
			success:function(html) {
			   $('#band_presentation').html(html);
			   $('#presentation_dialog').dialog('close');
			},
			complete:FunRock.Loader.disableOnIcon
		});			
	}
}

$(function() {
		$("#presentation_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});

function showPresentationDialog()
{
	var $icon= $('.presentation_text_Container').addClass('current_icon');		
				
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url:'/users/getpresentation_ajax',
		cache: false,
		success:function(html) {
    	   var prs_text    = html;
		   var real_string = prs_text.ReplaceAllString("<br />","\n");		
           document.getElementById('presentation_text').value = real_string; 
		   $('#presentation_dialog').dialog('open');
		},
		complete:FunRock.Loader.disableOnIcon
	});			   	
}

$(function() {
		$("#pm_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			buttons: {
				Ok: function() {
				    $('#pm_confirm').dialog('close');
				}	
			}
		});
});

$(function() {
		$(".privatemessage_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			buttons: {
				Cancel: function() {
				    $('.privatemessage_dialog').dialog('close');
					$(this).dialog('destroy');
				},				
				Save: function() {
					$.ajax({
						url:'/bands/setprivatemessage_ajax.json?newtext=' + document.getElementById('privatemessage_text').value + '&subject=' + document.getElementById('privatemessage_subject').value + '&UserBandMemId=' + document.getElementById('UserBandMemId').value,
						dataType:'json',
						success:function(resp) {
                            if(resp.status != '')
							{
								$('.privatemessage_dialog').dialog('close');
								$('#pm_confirm').dialog('open');
								$('.privatemessage_dialog').dialog('destroy');								
							}
							else{
								document.getElementById('subject_error').innerHTML = '<span>Please input subject.</span>';
								document.getElementById('subject_error').style.display = 'inline';		
								document.getElementById('text_error').innerHTML = '<span>Please input message.</span>';
								document.getElementById('text_error').style.display = 'inline';									
							}
						}
					});					
				},	
				Clear: function() {
				    document.getElementById('privatemessage_subject').value = '';
					document.getElementById('privatemessage_text').value = '';
				}				
			}
		});
});

function showPrivateMessageDialog()
{
   document.getElementById('subject_error').style.display = 'none';	
   document.getElementById('text_error').style.display = 'none';	
  
	$.ajax({
		url:'/bands/getprivatemessage_ajax.json',
		dataType:'json',
		success:function(resp) {
		   if(resp.status)
		   {
               document.getElementById('privatemessage_subject').value = resp.status;	
			   document.getElementById('privatemessage_text').value = resp.status;	
			   document.getElementById('UserBandMemId').value = resp.status;	
          
		   }
		}
	});	
					
   $('.privatemessage_dialog').dialog('open');
}

$(function() {
		$("#friend_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			buttons: {
				Ok: function() {
				    $('#friend_confirm').dialog('close');
				}	
			}
		});
});


$(function() {
		$("#createsong_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});

$(function() {
		$("#createsong_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function closeDialogCreateSong()
{
	$('#createsong_dialog').dialog('close');
}

$(function() {
		$("#create_error_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

$(function() {
		$("#membership_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});
$(function() {
		$("#membership_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});
function closeDialogMembercofirm()
{
	$('#membership_confirm').dialog('close');
	var y=self.location="/users/start/";	
}
function closeDialogMemberError()
{
	$('#create_membership_dialog').dialog('close');
}
function closeDialogMember()
{
	$('#membership_dialog').dialog('close');
}


$(function() {
		$("#create_membership_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function saveMembership()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    //var $icon= $('.createsong_container').addClass('current_icon'); 	
	 var $icon= $('.friend_loader_2').addClass('current_icon');	
	$.ajax({
	   beforeSend:FunRock.Loader.enableOnIcon,
		url:'/memberships/savemembership_ajax.json?membership_id=' + document.getElementById('membership_id').value,
		dataType:'json',
		success:function(resp) {
			if(resp.status == 'created')
			{
				$('#membership_dialog').dialog('close');
				$('#membership_confirm').dialog('open');
			}
			else
			{
			    //document.getElementById('errs_create_msg').innerHTML = '<div style="margin-left:10px; color:red;">' + resp.status + '</div>';
			    //document.getElementById('crt_err_msg').style.display = 'inline';
          		 //alert('Errors');		
			}
		},
		complete:FunRock.Loader.disableOnIcon
	});	
}

function closeCrtsongConfirmDialog()
{
	location.href = '/songs/bandStudio';
}

function saveCreateSong()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    var $icon= $('.createsong_container').addClass('current_icon'); 	
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url:'/songs/createsong_ajax.json?songname=' + document.getElementById('songname').value,
		dataType:'json',
		success:function(resp) {
			if(resp.status == 'created')
			{
				$('#createsong_dialog').dialog('close');
				$('#createsong_confirm').dialog('open');
			}
			else
			{
			    document.getElementById('errs_create_msg').innerHTML = '<div style="margin-left:10px; color:red;">' + resp.status + '</div>';
			    document.getElementById('crt_err_msg').style.display = 'inline';			
			}
		},
		complete:FunRock.Loader.disableOnIcon
	});	
}

function createSong(bandbooked, bookedfortoday, isvipuser, membermoresong, membersongsremaining, vipmoresong, vipsongsremaining)
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	if((bandbooked == 'yes') || ((bookedfortoday == 'yes')&& (membermoresong == 'no') && (vipmoresong == 'no')) || ((membermoresong == 'yes') && (membersongsremaining == 'no') && (isvipuser == 0)) || ((vipmoresong == 'yes') && (vipsongsremaining == 'no') && (isvipuser == 1)))
	{
	    document.getElementById('song_err_msg').style.display = 'inline';
	}
	else
	{
		document.getElementById('crt_err_msg').style.display = 'none';
	}	
	
	$('#createsong_dialog').dialog('open');
}

function vipMember(CurrentCredit,packageCredits,id,name,days)
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	document.getElementById('membership_id').value = id;
	document.getElementById('package_name').value  = name;
    document.getElementById('package_days').value  = days;
	
	if(CurrentCredit<packageCredits)
	{
	    
		document.getElementById('member_err_msg').innerHTML      =  '<b>You do not have sufficient credits to purchase '+document.getElementById('package_name').value+'</b>';
		document.getElementById('member_err_msg').style.display  = 'inline';
		$('#create_membership_dialog').dialog('open');	
	}
	else if(CurrentCredit>=packageCredits)
	{
	//var  document.getElementById('membership_id')=id;
	 document.getElementById('membership_id').innerHTML  = id;
	 document.getElementById('membership_message').innerHTML      =  '<b>Are you sure to purchase '+document.getElementById('package_name').value+' for '+ document.getElementById('package_days').value+ ' days?</b>';
	 document.getElementById('membership_message').style.display  = 'inline';
	 document.getElementById('membership_title').innerHTML      =  document.getElementById('package_name').value;
	 document.getElementById('membership_title').style.display  = 'inline';
	
	 $('#membership_dialog').dialog('open');	
	
	}	
	
}
$(function() {
		$("#recordsingle_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

$(function() {
		$("#recordsingle_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});

function closeRecSingleDialog()
{
	$('#recordsingle_dialog').dialog('close');
}

function saveRecordSong()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	var $icon= $('.record_song_container').addClass('current_icon');
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url:'/songs/saverecord_ajax.json?songid=' + document.getElementById('recsongid').value + '&reccompanyid=' + document.getElementById('reccompanyid').value,
		dataType:'json',
		success:function(resp) {
			if(resp.status == 'recorded')
			{
				$('#recordsingle_dialog').dialog('close');
				$('#recordsingle_confirm').dialog('open');	
			}
		},
		complete:FunRock.Loader.disableOnIcon
	});	    
}

function closeRecSingleConfirmDialog()
{
	$('#recordsingle_confirm').dialog('close');	
	location.href = '/songs/bandStudio';
}

function recordSingle(songId, songName, companyFlag)
{		
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	if(companyFlag == 'yes')
	{
		document.getElementById('recsingle_info').innerHTML      = '<span>' + '<b>Song:</b> ' + songName + '</span>';
		document.getElementById('recsingle_info').style.display  = 'inline';
		
		document.getElementById('recsongid').value               = songId;
	}
	else
	{
	    document.getElementById('recsingle_err_msg').style.display  = 'inline';
	}
	
	$('#recordsingle_dialog').dialog('open');
}

$(function() {
		$("#singbandbooked_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

$(function() {
		$("#singlebookedtoday_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

$(function() {
		$("#membersinglebookedtoday_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

$(function() {
		$("#vipsinglebookedtoday_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function closeBandBookedErrDialog()
{
	$('#singbandbooked_dialog').dialog('close');
}

function closeBookedTodayErrDialog()
{
	$('#singlebookedtoday_dialog').dialog('close');
}

function closeMemberBookedTodayErrDialog()
{
	$('#membersinglebookedtoday_dialog').dialog('close');
}

function closeVipBookedTodayErrDialog()
{
	$('#vipsinglebookedtoday_dialog').dialog('close');
}

function bandBookedDialog()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    $('#singbandbooked_dialog').dialog('open');
}

function bandBookedTodayDialog()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	$('#singlebookedtoday_dialog').dialog('open');
}

function memberDailySinglesDialog()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	$('#membersinglebookedtoday_dialog').dialog('open');
}

function vipDailySinglesDialog()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	$('#vipsinglebookedtoday_dialog').dialog('open');
}

function checkBoxes(flag)
{
   var inputs = document.forms['singlelist'].getElementsByTagName('input'); 
   
   for (i=0; i<inputs.length; ++i) { 
      if ('checkbox' == inputs[i].type.toLowerCase()) { 
	     if(flag)
		 {
			inputs[i].checked = true; 
		 }
		 else
		 {
		    inputs[i].checked = false; 
		 }
      } 
   }
 
}

$(function() {
		$("#money_error_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function closeMoneyErrorDlg()
{
	$('#money_error_dialog').dialog('close');
}

$(function() {
		$("#sure_buy_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function closeSureBuyDialog()
{
	$('#sure_buy_dialog').dialog('close');
}

function moneyDialog(studioId, cost, bandmoney)
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    document.getElementById('money_err_msg').innerHTML = '<b>Band money: $' + parseInt(bandmoney) + ' ' + 'Studio price: $' + parseInt(cost) + '</b>';
	
	$('#money_error_dialog').dialog('open');
}

function buyRehStudioAjax()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	var $icon= $('.sure_buy_container').addClass('current_icon');
					
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url:'/rehearsalstudios/buystudio_ajax?studioid=' + document.getElementById('studioid').value + '&cost=' + document.getElementById('studiocost').value,
		cache: false,
		success:function(html) {	
            $('#sure_buy_dialog').dialog('close');				
			$('#buystudio_confirm_dialog').dialog('open');				
		},
		complete:FunRock.Loader.disableOnIcon
	});				
}

$(function() {
		$("#buystudio_confirm_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function buyStudioCirmClose()
{
    location.href = '/rehearsalstudios/rehearsalStudio';
	$('#buystudio_confirm_dialog').dialog('close');
}

function buyStudio(studioId, cost)
{	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	document.getElementById('studioid').value = studioId;
	document.getElementById('studiocost').value = cost;
	
	$('#sure_buy_dialog').dialog('open');
}

function shareInput()
{
    if(document.getElementById('share_text').value == document.getElementById('hidden_value').value)
	{
		document.getElementById('share_text').value = "";
		document.getElementById('hidden_value').value = "";
	}
}

$(function() {
		$("#stat_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
			/*buttons: {
				Ok: function() {
				    $('#stat_dialog').dialog('close');
				}	
			}*/
		});
});

function closestatDialog()
{
	$('#stat_dialog').dialog('close'); 
}
function changeStat(statId, whatison)
{
    if((document.getElementById('share_text').value == '') || (document.getElementById('share_text').value == whatison))
	{
		$(".ui-dialog-titlebar").hide();
	    $(".ui-dialog").css("background",'transparent');
	    $(".ui-dialog").css("border",'none');
		
		$('#stat_dialog').dialog('open');
	}
	else
	{
	    var $icon= $('.band_stat_Container').addClass('current_icon');	
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url:'/users/changestat_ajax.json?statid=' + statId + '&statevalue=' + document.getElementById('share_text').value,
			dataType:'json',
			success:function(resp) {
				if(resp.status == 'done')
				{
					$('#header_text').html(document.getElementById('share_text').value);
					document.getElementById('share_text').value = whatison;
					document.getElementById('hidden_value').value = document.getElementById('share_text').value;
				}
			},
			complete:FunRock.Loader.disableOnIcon
		});				
	}
}

function btnClickedBuyStudio()
{
	location.href = '/rehearsalstudios/buyStudio';
}

function inCompleteSongs()
{
	document.getElementById('comsong').style.background = 'none';
	document.getElementById('comsong').style.color = 'black';
	
	document.getElementById('allsong').style.background = 'none';
	document.getElementById('allsong').style.color = 'black';
	
	document.getElementById('incomsong').style.background = 'black';
	document.getElementById('incomsong').style.color = 'white';	
	
    href = '/songs/incompleteSongs';
	
	var $icon= $('.songlist_container').addClass('current_icon');	
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url: href,
		cache: false,
		success: function(html)
		{
		    $('#song-list').replaceWith(html);
			initAsyncSongPagination();
		},
		complete:FunRock.Loader.disableOnIcon
	});
}

function completeSongs()
{
	document.getElementById('allsong').style.background = 'none';
	document.getElementById('allsong').style.color = 'black';
	
	document.getElementById('incomsong').style.background = 'none';
	document.getElementById('incomsong').style.color = 'black';	
	
	document.getElementById('comsong').style.background = 'black';
	document.getElementById('comsong').style.color = 'white';	
	
	var $icon= $('.songlist_container').addClass('current_icon');
		
    href = '/songs/completeSongs';
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url: href,
		cache: false,
		success: function(html)
		{
		    document.getElementById('loader_animation_songlist').style.display = 'none';
		    $('#song-list').replaceWith(html);
			initAsyncSongPagination();
		},
		complete:FunRock.Loader.disableOnIcon
	});
}

function showAllSongs()
{
	document.getElementById('incomsong').style.background = 'none';
	document.getElementById('incomsong').style.color = 'black';	
	
	document.getElementById('comsong').style.background = 'none';
	document.getElementById('comsong').style.color = 'black';		
	
	document.getElementById('allsong').style.background = 'black';
	document.getElementById('allsong').style.color = 'white';
	
	var $icon= $('.songlist_container').addClass('current_icon');	
			
    href = '/songs/allSongs';
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url: href,
		cache: false,
		success: function(html)
		{
		    document.getElementById('loader_animation_songlist').style.display = 'none';
		    $('#song-list').replaceWith(html);
			initAsyncSongPagination();
		},
		complete:FunRock.Loader.disableOnIcon
	});
}

$(function() {
		$("#gigs_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});



function gigsReportWindow(gigString, companyString, bandFans, songNotfound, xPosition, yPosition, bandbooked, isvipuser, bookedfortoday, membermoregig, membergigsremaining, vipmoregig, vipgigsremaining, song_giged_complete)
{	
 
    var giginfo = new Array();
    var companyinfo = new Array();
	   
    giginfo       = gigString.split(',');
		
	if(companyString != 'notfound')
	{
		companyinfo   = companyString.split(',');
    }
	
	document.getElementById('window_bandbooked_error_report').style.display  = 'none';
	document.getElementById('window_song_error_report').style.display        = 'none';
	document.getElementById('window_fan_error_report').style.display         = 'none';	
	document.getElementById('window_close_gig').style.display  		         = 'none';	
	document.getElementById('window_submit_gig').style.display  	         = 'none';
	document.getElementById('window_vip_error_report').style.display         = 'none';
	document.getElementById('window_booked_today_error').style.display       = 'none';
	document.getElementById('member_remaining_gigs_error').style.display     = 'none';
	document.getElementById('vip_remaining_gigs_error').style.display        = 'none';
	document.getElementById('window_song_giged_report').style.display        = 'none';
	
	if(giginfo[1].length > 8)
	{
		document.getElementById('lacation_name').innerHTML = '<span style="color:white; font-weight:bold; font-size:16px; ">' + 
	                                                           giginfo[1].substr(0,6) + '...' + '</span>';
	}
    else
    {
		document.getElementById('lacation_name').innerHTML = '<span style="color:white; font-weight:bold; font-size:16px; ">' + 
	                                                           giginfo[1] + '</span>';	
    }	
	
    document.getElementById('window_gig_report').innerHTML = '<div style="padding:6px;">' +
																 '<span><b>Area: </b>' + giginfo[1] + '</span>' + '<br>' +
																 '<span><b>Required Fans: </b>' + giginfo[2] + '</span>' + '<br>' +
																 '<span><b>Capacity: </b>' + giginfo[3] + '</span>' + '<br>' +
																 '<span><b>Commision: </b>' + giginfo[4] + '%</span>' + '<br>' +
																 '<span><b>Ticket Price: </b>$' + giginfo[5] + '</span>' + '<br>' +
																 '</div>';	 
    
	if(companyString == 'notfound')
	{
		document.getElementById('window_company_report').innerHTML = '<div style="padding:10px;">' +
																 '<span><b>Not Found Any Record Company</b></span>' + '<br>' +	
																 '</div>';																	 
	}
	else
	{
		document.getElementById('window_company_report').innerHTML = '<div style="padding:6px;">' +
																 '<span><b>Company Name: </b>' + companyinfo[0] + '</span>' + '<br>' +	
																 '<span><b>Commision: </b>' + companyinfo[1] + '%</span>' + '<br>' +
																 '</div>';	
	}
	
	document.getElementById('window_band_report').innerHTML = '<div style="padding:10px;">' +
																 '<span><b>Number Of Fans: </b>' + bandFans + '</span>' + '<br>' +	
																 '</div>';		
	
    if(bandbooked == 'yes')
    {
		document.getElementById('window_bandbooked_error_report').style.display  = 'inline';	
		document.getElementById('window_close_gig').style.display  = 'inline';		
    }
    else
    {	
		if((isvipuser == 0) && (giginfo[7] == 2))
		{
			document.getElementById('window_vip_error_report').style.display  = 'inline';	
			document.getElementById('window_close_gig').style.display  = 'inline';				
		}	    
		else
		{
			if(parseInt(bandFans) < parseInt(giginfo[2]))
			{
				document.getElementById('window_fan_error_report').style.display  = 'inline';	
				document.getElementById('window_close_gig').style.display  = 'inline';			
			}
            else
            {
				if(songNotfound == 'yes')
				{		
					document.getElementById('window_song_error_report').style.display  = 'inline';	
					document.getElementById('window_close_gig').style.display  = 'inline';		
				}
                else
                {
                    if(song_giged_complete == 'yes')
                    {
						document.getElementById('window_song_giged_report').style.display  = 'inline';	
						document.getElementById('window_close_gig').style.display  = 'inline';						
                    }
                    else
                    {					
						if((bookedfortoday == 'yes') && (membermoregig == 'no') && (vipmoregig == 'no'))
						{
							document.getElementById('window_booked_today_error').style.display  = 'inline';	
							document.getElementById('window_close_gig').style.display  = 'inline';		
						}
						else
						{
							if((membermoregig == 'yes') && (membergigsremaining == 'no') && (isvipuser == 0))
							{
								document.getElementById('member_remaining_gigs_error').style.display  = 'inline';	
								document.getElementById('window_close_gig').style.display  = 'inline';				
							}
							else
							{
								if((vipmoregig == 'yes') && (vipgigsremaining == 'no') && (isvipuser == 1))
								{
									document.getElementById('vip_remaining_gigs_error').style.display  = 'inline';	
									document.getElementById('window_close_gig').style.display  = 'inline';					
								}
								else
								{
									document.getElementById('window_gig_id_container').value         = giginfo[0];
									document.getElementById('window_gigString_container').value      = gigString;
									document.getElementById('window_companyString_container').value  = companyString;
									document.getElementById('window_bandFans_container').value       = bandFans;
									document.getElementById('window_songNotfound_container').value   = songNotfound;
									document.getElementById('window_submit_gig').style.display       = 'inline';		
								}
							}
						}
					}
				}
			}
        }		
	}	

	document.getElementById('report_window').style.left = 40 + 'px';
	document.getElementById('report_window').style.top = 14 + 'px';
	document.getElementById('report_window').style.display  = 'inline';	
    runEffect();
}

function closeGigReportWindow()
{
	$("#effect:visible").removeAttr('style').hide().fadeOut();
}


function showGigDialogBox()
{
	var gigString     = document.getElementById('window_gigString_container').value;
	var companyString = document.getElementById('window_companyString_container').value;
	var bandFans      = document.getElementById('window_bandFans_container').value;
	var songNotfound  = document.getElementById('window_songNotfound_container').value;
			
    var giginfo = new Array();
    var companyinfo = new Array();
   
    giginfo       = gigString.split(',');
	
	if(companyString != 'notfound')
	{
		companyinfo   = companyString.split(',');
    }
		
	document.getElementById('box_song_error_report').style.display  = 'none';
	document.getElementById('box_fan_error_report').style.display   = 'none';	
	document.getElementById('close_gig').style.display  			= 'none';	
	document.getElementById('submit_gig').style.display  			= 'none';
		
	document.getElementById('gigholderblock').style.background = 'url(/img/gigStage/' + giginfo[6] + ')';
	document.getElementById('gigholderblock').style.backgroundRepeat = 'no-repeat';
	
	document.getElementById('gigdlg_lacation_name').innerHTML = '<span style="color:white; font-weight:bold; font-size:16px; ">' + 
	                                                           giginfo[1] + '</span>';	
	
	
    document.getElementById('box_gig_report').innerHTML = '<div style="padding:6px;">'+
																 '<span><b>Area: </b>' + giginfo[1] + '</span>' + '<br>' +
																 '<span><b>Required Fans: </b>' + giginfo[2] + '</span>' + '<br>' +
																 '<span><b>Capacity: </b>' + giginfo[3] + '</span>' + '<br>' +
																 '<span><b>Commision: </b>' + giginfo[4] + '%</span>' + '<br>' +
																 '<span><b>Ticket Price: </b>$' + giginfo[5] + '</span>' + '<br>' +
																 '</div>';	 
    
	if(companyString == 'notfound')
	{
		document.getElementById('box_company_report').innerHTML = '<div style="padding:6px;">'+
																 '<span><b>Area: </b> Not Found Any Record Company</span>' + '<br>' +	
																 '</div>';																	 
	}
	else
	{
		document.getElementById('box_company_report').innerHTML = '<div style="padding:6px;">' +
																 '<span><b>Company: </b>' + companyinfo[0] + '</span>' + '<br>' +	
																 '<span><b>Commision: </b>' + companyinfo[1] + '%</span>' + '<br>' +
																 '</div>';	
	}
	
	document.getElementById('box_band_report').innerHTML = '<div style="padding:10px;">'+
																 '<span><b>Number Of Fans: </b>' + bandFans + '</span>' + '<br>' +	
																 '</div>';		
																 
    if(songNotfound == 'yes')
    {		
		document.getElementById('box_song_error_report').style.display  = 'inline';	
		document.getElementById('close_gig').style.display  = 'inline';		
	}	
	else
	{
	    if(parseInt(bandFans) < parseInt(giginfo[2]))
		{
			document.getElementById('box_fan_error_report').style.display  = 'inline';	
			document.getElementById('close_gig').style.display  = 'inline';			
		}
		else
		{
		    document.getElementById('gig_id_container').value    = giginfo[0];
			document.getElementById('submit_gig').style.display  = 'inline';		
		}
	}
	
	$("#effect:visible").removeAttr('style').hide().fadeOut();
	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
		
	$('#gigs_dialog').dialog('open');
   	
}

function closeGigDialog()
{
	$('#gigs_dialog').dialog('close'); 
}

$(function() {
		$("#gigs_submit_confirm").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function closeGigSubmitConfirm()
{
	location.href = '/gigs/currentGig';
	$('#gigs_submit_confirm').dialog('close');
}

function getGigSongsId()
{
   var inputs    = document.forms['gigdetailsform'].getElementsByTagName('input'); 
   var gigsongid = new Array();
   var index = 0;
   
   for (i=0; i<inputs.length; ++i) { 
      if ('checkbox' == inputs[i].type.toLowerCase()) { 
		if(inputs[i].checked)
        {
            gigsongid[index] = inputs[i].value;
			index++;
        }			
      } 
   }
   
   return gigsongid.join(',');
}

$(function() {
		$("#gig_error_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function gigSongCheckBoxes()
{
   var inputs = document.forms['gigdetailsform'].getElementsByTagName('input'); 
   var checked = false;
     
   for (i=0; i<inputs.length; ++i) { 
      if ('checkbox' == inputs[i].type.toLowerCase()) { 
		if(inputs[i].checked)
        {
		    checked = true;
			
        }			
      } 
   }
   
   return checked;
}

function runEffect(){

	var selectedEffect = 'blind';
	var options = {};

	if(selectedEffect == 'scale'){  options = {percent: 100}; }
	else if(selectedEffect == 'transfer'){ options = { to: "#star_button", className: 'ui-effects-transfer' }; }
	else if(selectedEffect == 'size'){ options = { to: {width: 280,height: 185} }; }

	$("#effect").show(selectedEffect,options,500);
};

function callback(){
	setTimeout(function(){
		$("#effect:visible").removeAttr('style').hide().fadeOut();
	}, 1000);
};

$(function() {
		$("#gigcountryreport_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});

$(function() {
		$("#loader_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width: 'auto'
		});
});

function gigCountryReport(countryId)
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	if(document.getElementById('refuserid'))
	{
	   if(document.getElementById('refuserid').value != '')
	   {
	      url_string = '/gigs/countryreport?countryid=' + countryId + '&refid=' + document.getElementById('refuserid').value;
	   }
	   else
	   {
	      url_string = '/gigs/countryreport?countryid=' + countryId;
	   }
	}
    else
    {
	   url_string = '/gigs/countryreport?countryid=' + countryId;
    }	
	
	var $icon= $('.travel_Country_Container').addClass('current_icon');		   
	$.ajax({
		beforeSend:FunRock.Loader.enableOnIcon,
		url:url_string,
		cache: false,
		success:function(html) {
			$('#country-report').replaceWith(html);
			document.getElementById('country-report').style.display = 'inline';
					
			$('#gigcountryreport_dialog').dialog('open');
			
			if(document.getElementById('refuserid'))
			{			
				if(document.getElementById('refuserid').value != '')
				{
				   initAsyncSingleRefGigPagination(countryId, document.getElementById('refuserid').value);
				}
				else
				{
				   initAsyncSingleGigPagination(countryId);
				}
            }
            else
            {
			    initAsyncSingleGigPagination(countryId);
            }			
		},
		complete:FunRock.Loader.disableOnIcon
	});
}

function closeCountryReportDialog()
{
	$('#gigcountryreport_dialog').dialog('close');
}

function closeGigErrDialog()
{
	$('#gig_error_dialog').dialog('close');
}

$(function() {
		$("#countryimg_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});

function travelCountryDialog(countryId){	
	$this=$(this);
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	var $icon= $('.NW4#'+countryId).addClass('current_icon');	
	$.ajax({
		beforeSend:FunRock.Loader.enableOnIcon,
		url:'/gigs/countrydetails?countryid=' + countryId,
		cache: false,
		success:function(html) {
			$('#show_country').replaceWith(html);
			document.getElementById('show_country').style.display = 'inline';
			$('#countryimg_dialog').dialog('open');
		},
		complete:FunRock.Loader.disableOnIcon	
	});		
}



/*$(function(){
		    $(".gig_map").colorbox({width:"50%", inline:true,href:"#gig_map"});});
*/
			/*$(function() {
		$("#giglocation_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});*/


function gigCountryLocation(countryId, xposition, yposition, name, requiredfans, capacity, commision, ticketprice)
{
	$this=$(this);
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	var $icon= $('.gig_report_details').addClass('current_icon');
	
	$.ajax({
		beforeSend:FunRock.Loader.enableOnIcon,
		url:'/gigs/gigLocation?countryid=' + countryId + '&xposition=' + xposition + '&yposition=' + yposition + '&name=' + name + '&requiredfans=' + requiredfans + '&capacity=' + capacity + '&commision=' + commision + '&ticketprice=' + ticketprice,
		cache: false,
		success:function(html) {
			$('#show_giglocation').replaceWith(html);
			document.getElementById('show_giglocation').style.display = 'inline';
			$('#giglocation_dialog').dialog('open');
		},
		complete:FunRock.Loader.disableOnIcon	
	});		    
}

$(function() {
		$("#giglocation_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width: 'auto'
		});
});

function closeGigLocationDialog()
{
	$('#giglocation_dialog').dialog('close');
}

function closeTravelDialog(imageFile)
{
	$('#countryimg_dialog').dialog('close');
}

function closeBandCreateWindow()
{
	$("#effect:visible").removeAttr('style').hide().fadeOut();
}

$(function() {
		$("#travel_error_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

$(function() {
		$("#travel_yesno_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});

function closeTravelYesnoDialog()
{
	$('#travel_yesno_dialog').dialog('close');
}

function closeTravelErrDialog()
{
	$('#travel_error_dialog').dialog('close');
}

function saveTravelCountry(trvlcountryId, bandbooked, bookedfortoday, tomorrow, bandmoney, cost, bandfans, fansrequired, timetofinish)
{
    if(bandbooked == 'yes')
	{
		$(".ui-dialog-titlebar").hide();
		$(".ui-dialog").css("background",'transparent');
		$(".ui-dialog").css("border",'none');	
		
		document.getElementById('dlgerr_travelerr_report').innerHTML = '<span style="margin-left:20px;">'+'<b>'+'Band Is Currently Booked.'+'</b>'+'</span><br>'+'<span style="margin-left:20px;">'+ timetofinish + '</span>';
		
	    $('#travel_error_dialog').dialog('open');
	}
	else
	{
	    if(bookedfortoday == 'yes')
		{
			$(".ui-dialog-titlebar").hide();
			$(".ui-dialog").css("background",'transparent');
			$(".ui-dialog").css("border",'none');	
			
			document.getElementById('dlgerr_travelerr_report').innerHTML = '<span style="margin-left:20px;">'+'<b>'+'Band Already Traveled Today. ' + '</b>'+'</span><br>' +'<span style="margin-left:20px;">'+ tomorrow + '</span>';
			
			$('#travel_error_dialog').dialog('open');		
		}
		else
		{
			if(parseInt(bandmoney) < parseInt(cost))
			{
				$(".ui-dialog-titlebar").hide();
				$(".ui-dialog").css("background",'transparent');
				$(".ui-dialog").css("border",'none');	
				
				document.getElementById('dlgerr_travelerr_report').innerHTML = '<div style="margin-left:20px;">'+'<b>'+'Oops!! You do NOT have sufficient Band Money to Travel here.'+'</b>'+'</div><br>';
				
				$('#travel_error_dialog').dialog('open');			
			}
			else
			{
				if(parseInt(bandfans) < parseInt(fansrequired))
				{
					$(".ui-dialog-titlebar").hide();
					$(".ui-dialog").css("background",'transparent');
					$(".ui-dialog").css("border",'none');	
					
					document.getElementById('dlgerr_travelerr_report').innerHTML = '<div style="margin-left:20px;">'+'<b>'+'Sorry!! You do NOT have the required number of Fans to Travel here.'+'</b>'+'</div>'+ '<span style="margin-left:20px;">'+ 'Band fans: ' + bandfans + ' ' + 'Required fans: ' + fansrequired + '</span>';
					
					$('#travel_error_dialog').dialog('open');				
				}
				else
				{
					$(".ui-dialog-titlebar").hide();
					$(".ui-dialog").css("background",'transparent');
					$(".ui-dialog").css("border",'none');	
					
					document.getElementById('dlg_yesno_travel').innerHTML = '<span style="margin-left:10px;">'+'<b>'+'Are You Sure? '+'</b>'+'</span><br>';
					document.getElementById('trvlcountryid').value = trvlcountryId;
					
					$('#travel_yesno_dialog').dialog('open');				

				}
			}
		}
	}
}

$(function() {
		$("#travel_confirm_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function travelCountryAjax()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	var $icon= $('.travel_Yesno_Container').addClass('current_icon');	
		
	$.ajax({
	    beforeSend:FunRock.Loader.enableOnIcon,
		url:'/gigs/savetravelcountry?countryid=' + document.getElementById('trvlcountryid').value,
		cache: false,
		success:function(html) {
			if(html == 1)
			{
				$(".ui-dialog-titlebar").hide();
				$(".ui-dialog").css("background",'transparent');
				$(".ui-dialog").css("border",'none');	
				
				document.getElementById('dlg_confirm_travel').innerHTML = '<span style="margin-left:10px;">'+'<b>'+'Successful '+'</b>'+'</span><br>';
				
				$('#travel_yesno_dialog').dialog('close');
				$('#travel_confirm_dialog').dialog('open');
			}			
		},
		complete:FunRock.Loader.disableOnIcon
	});		
}

function saveGigrepComment(id)
{
	$.ajax({
		url:'/gigs/addsinglecomment_ajax?gigreportid=' + id + '&commentbody=' + document.getElementById('comments_body').value,
		cache: false,
		success:function(html) {
			if(html == 1)
			{
               location.href = '/gigs/myGigreport/' + id;
			}			
		}
	});			      
}


function closeTravelConfirmDialog()
{
	location.href = '/gigs/currentGig';
	$('#travel_confirm_dialog').dialog('close');	
}


function performGigs()
{
	location.href = '/gigs/currentGig';
}

$(function() {		
		$("#uploadlogo_error_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: true,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});	
		
		$(".ui-dialog-titlebar").hide();
		$(".ui-dialog").css("background",'transparent');
		$(".ui-dialog").css("border",'none');		
});

function closeLogoErrorDialog()
{
	$('#uploadlogo_error_dialog').dialog('close');
}

function openErrorLoadDialog()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
}

$(function() {		
		$("#upload_logo_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: true,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});	
		
		$(".ui-dialog-titlebar").hide();
		$(".ui-dialog").css("background",'transparent');
		$(".ui-dialog").css("border",'none');	
});

function closeLogoUploadDialog()
{
	$('#upload_logo_dialog').dialog('close');
	document.getElementById('crp1').style.display = 'none';
	document.getElementById('crp2').style.display = 'none';
	document.getElementById('crp3').style.display = 'none';
}

function createCropedImages(file_ext)
{
	var img_x1 = document.getElementById('img_x1').value;
	var img_y1 = document.getElementById('img_y1').value;
	var img_x2 = document.getElementById('img_x2').value;
	var img_y2 = document.getElementById('img_y2').value;
	var img_w  = document.getElementById('img_w').value;
	var img_h  = document.getElementById('img_h').value;
	
	document.getElementById('loader_animation_uploadlogo').style.left = parseInt(document.getElementById('upload_logo_dialog').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_uploadlogo').style.top = parseInt(document.getElementById('upload_logo_dialog').clientHeight/2) - 42 + 'px';
	
	document.getElementById('loader_animation_uploadlogo').style.display = 'inline';		
	
	$.ajax({
		url:'/bands/savecropedimages_ajax?img_x1=' + img_x1 + '&img_y1=' + img_y1 + '&img_x2=' + img_x2 + '&img_y2=' + img_y2 + '&img_w=' + img_w + '&img_h=' + img_h + '&file_ext=' + file_ext,
		cache: false,
		success:function(html) {
			if(html == 1)
			{
			   document.getElementById('loader_animation_uploadlogo').style.display = 'none';			
               location.href = '/users/myband';  
			}			
		}
	});
}

$(function() {
		$("#privatemessage_search_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	
$(function() {
		$("#refer_friend_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});		

$(function() {
		$("#friend_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});
$(function() {
		$("#friend_accept_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});
$(function() {
		$("#friend_deny_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});
$(function() {
		$("#bandmember_background_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	

$(function() {
		$("#song_lyrics_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	

$(function() {
		$("#album_presentation_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	

function denyfriend(d_friendid,txtusername,d_pid)
{
	document.getElementById('d_friendid').value = d_friendid;
	document.getElementById('d_pid').value = d_pid;
	var d_friendid=this.d_friendid;	
	var d_pid=this.d_pid;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	document.getElementById('txtusername').innerHTML = txtusername;
    $('#friend_deny_dialog').dialog('open');	
}

function submitdenyRequest()
{
var $icon= $('.deny_loader').addClass('current_icon');	
$.ajax({
				beforeSend:FunRock.Loader.enableOnIcon,
				url:'/bands/setfriend_request_deny_ajax?d_friendid=' + document.getElementById('d_friendid').value + '&pid=' + document.getElementById('d_pid').value,
				cache: false,
				success:function(html) {
				  $('#friend_deny_dialog').dialog('close');
				  $('#d_'+document.getElementById('d_friendid').value).show();
				  $('#a_'+document.getElementById('d_friendid').value).hide();
				  $('#c_'+document.getElementById('d_friendid').value).hide();
					
				},
				complete:FunRock.Loader.disableOnIcon
			});		
}


function acceptfriend(id,username,pid)
{
	document.getElementById('friendid').value = id;
	document.getElementById('pid').value = pid;
	var id=this.id;	
	var pid=this.pid;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	document.getElementById('username').innerHTML =username;
    $('#friend_accept_dialog').dialog('open');	
}

function submitFriendRequest()
{
var $icon= $('.accept_loader').addClass('current_icon');
	
$.ajax({
				beforeSend:FunRock.Loader.enableOnIcon,
				url:'/bands/setfriend_request_accept_ajax?friendid=' + document.getElementById('friendid').value + '&pid=' + document.getElementById('pid').value,
				cache: false,
				success:function(html) {
				  $('#friend_accept_dialog').dialog('close');
				  $('#a_'+document.getElementById('friendid').value).hide();
				  $('#b_'+document.getElementById('friendid').value).show();
				  $('#a_'+document.getElementById('friendid').value).hide();
				  $('#c_'+document.getElementById('friendid').value).hide();
				},
				complete:FunRock.Loader.disableOnIcon
			});		
}


$(function() {
		$("#pressrelease_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	
$(function() {
		$("#privatemessage_mail_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	
$(function() {
		$("#album_cover_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			width:'auto'
		});
});	
function closeAlbumCoverDialog()
{
    $('#album_cover_dialog').dialog('close');	

}
function showAlbumCoverDialog()
{   $(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
    $('#album_cover_dialog').dialog('open');	
}


function PM_Mail_dialog(id)
{
	document.getElementById('loader_animation_presentation').style.left = parseInt(document.getElementById('PM').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_presentation').style.top  = parseInt(document.getElementById('PM').clientHeight/2) - 42 + 'px';
	document.getElementById('pmid').value = id;
	document.getElementById('loader_animation_presentation').style.display = 'inline';	
	var pm_id='pmid_'+id;
	var pm_from='pmfrom_'+id;
	var pm_message='pmmessage_'+id;
	var pm_message_from='pmmessagefrom_'+id;

	var id=this.id;	
			
	$.ajax({
		url:'/privatemessages/getprivatemessage_ajax?id='+document.getElementById('pmid').value,
		cache: false,
		success:function(html) {
		  var txt=html;
		  document.getElementById('loader_animation_presentation').style.display = 'none';	
          $(".ui-dialog-titlebar").hide();
	      $(".ui-dialog").css("background",'transparent');
	      $(".ui-dialog").css("border",'none');
		  document.getElementById('privatemessage_subject').value = txt;
		  $('textarea#privatemessage_text').val('new');
		  $('#privatemessage_mail_dialog').dialog('open');
		}
	});		
}

function submitPM_Mail_reply()
{
	$.ajax({
		url:'/privatemessages/reply_email?pmid=' + document.getElementById('myid').value + '&subval=' + document.getElementById('privatemessage_subject').value + '&msgval=' + document.getElementById('privatemessage_text').value,
		cache: false,
		success:function(html) {
		  document.getElementById('loader_animation_sendpm').style.display = 'none';	
		  $('#privatemessage_search_dialog').dialog('close');
		}
	});		   
}

function pressrelease()
{   $(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	document.getElementById('PR_err_msg').style.display = 'none';
	$('#pressrelease_dialog #title_text').val('');
	$('#pressrelease_dialog #description_text').val('');	
    $('#pressrelease_dialog').dialog('open');	
}

function submitPressrelease()
{
 if(document.getElementById('title_text').value == '')
   {
		document.getElementById('errs_sumbit_msg_PR').innerHTML = '<div style="margin-left:10px;">Title field should not be empty.</div>';
		document.getElementById('PR_err_msg').style.display = 'inline';	         
   }  else if(document.getElementById('description_text').value == '')
		{
			document.getElementById('errs_sumbit_msg_PR').innerHTML = '<div style="margin-left:10px;">Description field should not be empty.</div>';
			document.getElementById('PR_err_msg').style.display = 'inline';		
		}
		else
		{
			document.getElementById('PR_err_msg').style.display = 'none';	
		    var $icon = $('.pressrelease_dialog_loader').addClass('current_icon'); 
			var press_text    = document.getElementById('description_text').value;
		    var real_string = press_text.ReplaceAllString("\n", "<br />");
			
			$.ajax({
			       beforeSend:FunRock.Loader.enableOnIcon,
					url:'/users/save_mypressrelease?titleval='+document.getElementById('title_text').value+'&desval='+real_string,
					cache: false,
					success:function(html) {
                 	window.location.reload();
				 		$('#pressrelease_dialog').dialog('close');
				
					},
				  complete:FunRock.Loader.enableOnIcon
			});		
		}
   
}

function testfunc(id)
{
	document.getElementById('myid').value = id;
	
	var id=this.id;	
	var UserBandMemId=$('.test2').filter('#'+id).html();
	$('#UserBandMemId').val(UserBandMemId);
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    document.getElementById('pm_err_msg').style.display = 'none';	
	$('#privatemessage_search_dialog #privatemessage_subject').val('');
	$('#privatemessage_search_dialog #privatemessage_text').val('');
	$('#privatemessage_search_dialog #UserBandMemId').val('');
    $('#privatemessage_search_dialog').dialog('open');	
}

function submitPM()
{

   if(document.getElementById('privatemessage_subject').value == '')
   {
		document.getElementById('errs_sumbit_msg').innerHTML = '<div style="margin-left:10px;">Subject field should not be empty.</div>';
		document.getElementById('pm_err_msg').style.display = 'inline';	         
   }
   else if(document.getElementById('privatemessage_text').value == '')
		{
			document.getElementById('errs_sumbit_msg').innerHTML = '<div style="margin-left:10px;">Message field should not be empty.</div>';
			document.getElementById('pm_err_msg').style.display = 'inline';		
		}
		else
		{
		document.getElementById('pm_err_msg').style.display = 'none';	
		
		    var $icon= $('.pm_loader_new').addClass('current_icon');	
			var pm_text    = document.getElementById('privatemessage_text').value;
		    var pm_real_string = pm_text.ReplaceAllString("\n", "<br />");
			
			$.ajax({
			    beforeSend:FunRock.Loader.enableOnIcon,
				url:'/bands/send_pm?pmid=' + document.getElementById('myid').value + '&subval=' + document.getElementById('privatemessage_subject').value + '&msgval=' +pm_real_string,
			    cache: false,
				success:function(html) {
					$('#privatemessage_search_dialog').dialog('close');
				},
				complete:FunRock.Loader.disableOnIcon
			});		
		}
   
}
function closeDialogFriendAccept()
{
    $('#friend_accept_dialog').dialog('close');	

}
function closeDialogFriendDeny()
{
    $('#friend_deny_dialog').dialog('close');	

}

function closeDialogPressrelease()
{
    $('#pressrelease_dialog').dialog('close');	

}

function closeDialogPM()
{
    $('#privatemessage_search_dialog').dialog('close');	

}
function closeDialogPM_mail()
{
    $('#privatemessage_mail_dialog').dialog('close');	

}

 
function referFriend()
{
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
    document.getElementById('refer_err_msg').style.display = 'none';	
	$('#refer_friend_dialog #Name').val('');
	$('#refer_friend_dialog #E-mail').val('');
    $('#refer_friend_dialog').dialog('open');	
}

function submitReferFriend()
{
   
   var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if(document.getElementById('Name').value == '')
   {
		document.getElementById('errs_sumbit_msg_refer_friend').innerHTML = '<div style="margin-left:10px;">Name field should not be empty.</div>';
		document.getElementById('refer_err_msg').style.display = 'inline';	         
   }else if(document.getElementById('E-mail').value == ''){
			document.getElementById('errs_sumbit_msg_refer_friend').innerHTML = '<div style="margin-left:10px;">E-mail field should not be empty.</div>';
			document.getElementById('refer_err_msg').style.display = 'inline';		
	}else if(!emailRegEx.test(document.getElementById('E-mail').value)){
		document.getElementById('errs_sumbit_msg_refer_friend').innerHTML = '<span>Please input a correct email address.</span>';
		document.getElementById('refer_err_msg').style.display = 'inline';			   
	}else{ 
	    var $icon = $('.refer_loader').addClass('current_icon'); 
		$.ajax({
			    beforeSend:FunRock.Loader.enableOnIcon,
				url:'/bands/refer_friend?nameval=' + document.getElementById('Name').value + '&emailval=' + document.getElementById('E-mail').value,
				cache: false,
				success:function(html) {
					if(html == 'emailfound'){
						document.getElementById('errs_sumbit_msg_refer_friend').innerHTML = '<span>Email address already exist.</span>';
						document.getElementById('refer_err_msg').style.display = 'inline';					
					}
					else
					{
					    if(html == 'emailchangeok')
						{
							$('#refer_friend_dialog').dialog('close');
							//$('#changeemail_confirm').dialog('open');						
						}
					}
				},
				complete:FunRock.Loader.disableOnIcon
			});	
	}
}

function closeDialogReferFriend()
{
    $('#refer_friend_dialog').dialog('close');	

}
function closeBMBackground()
{
    $('#bandmember_background_dialog').dialog('close');	

}

function closeLyricsDialog()
{
    $('#song_lyrics_dialog').dialog('close');	

}
function closeAlbumDialog()
{
    $('#album_presentation_dialog').dialog('close');	

}
function showAlbumDialog(id)
{
	document.getElementById('albumid').value = id;
	var id=this.id;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	var LyricsText    = document.getElementById('Albumpresentation').value;
    var realLyricsText = LyricsText.ReplaceAllString("<br />", "\n");

	document.getElementById('lyrics_text').value = realLyricsText;//document.getElementById('songlyrics').value;
    document.getElementById('pm_err_msg').style.display = 'none';
	$('#album_presentation_dialog').dialog('open');	
}

function submitAlbumPresentation()
{
    if(document.getElementById('lyrics_text').value =='')
		{
			document.getElementById('errs_sumbit_msg').innerHTML = '<div style="margin-left:10px;">Presentation field should not be empty.</div>';
			document.getElementById('pm_err_msg').style.display = 'inline';		
		}
		else
		{
		    document.getElementById('pm_err_msg').style.display = 'none';	
			var LyricsText    = document.getElementById('lyrics_text').value;
		    var realLyricsText = LyricsText.ReplaceAllString("\n", "<br />");
			var $icon= $('.lyrics_loader').addClass('current_icon');
			$.ajax({
			  beforeSend:FunRock.Loader.enableOnIcon,  
				url:'/albums/savealbumpresentation&id=' + document.getElementById('albumid').value + '&presentation=' + realLyricsText,
				cache: false,
				success:function(html) {
				document.getElementById('Albumpresentation').value = realLyricsText;//document.getElementById('lyrics_text').value;
				document.getElementById('album_presentation').innerHTML = realLyricsText;//document.getElementById('lyrics_text').value;
				$('#album_presentation_dialog').dialog('close');
				},
			complete:FunRock.Loader.disableOnIcon
			});		
		}
}

function showLyricsDialog(id)
{
	document.getElementById('songid').value = id;
	var id=this.id;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	var LyricsText    = document.getElementById('songlyrics').value;
    var realLyricsText = LyricsText.ReplaceAllString("<br />", "\n");

	document.getElementById('lyrics_text').value = realLyricsText;//document.getElementById('songlyrics').value;
    document.getElementById('pm_err_msg').style.display = 'none';
	$('#song_lyrics_dialog').dialog('open');	
}

function submitLyrics()
{
    if(document.getElementById('lyrics_text').value == '')
		{
			document.getElementById('errs_sumbit_msg').innerHTML = '<div style="margin-left:10px;">Lyrics field should not be empty.</div>';
			document.getElementById('pm_err_msg').style.display = 'inline';		
		}
		else
		{
		    document.getElementById('pm_err_msg').style.display = 'none';	
			var LyricsText    = document.getElementById('lyrics_text').value;
		    var realLyricsText = LyricsText.ReplaceAllString("\n", "<br />");
			var $icon= $('.lyrics_loader').addClass('current_icon');
			$.ajax({
			    beforeSend:FunRock.Loader.enableOnIcon,  
				url:'/songs/savelyrics?id=' + document.getElementById('songid').value + '&lyricsval=' + realLyricsText,
				cache: false,
				success:function(html) {
			    //var newrealLyricsText = LyricsText.ReplaceAllString("\n", "<br />");
				
				document.getElementById('songlyrics').value = realLyricsText;//document.getElementById('lyrics_text').value;
				document.getElementById('song_presentation').innerHTML = realLyricsText;//document.getElementById('lyrics_text').value;
				$('#song_lyrics_dialog').dialog('close');
				},
				complete:FunRock.Loader.disableOnIcon
			});		
		}
   
}

function writeBMBackground(id)
{
	document.getElementById('bmid').value = id;
	var bm_id='bmid_'+id;
	var id=this.id;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	//document.getElementById('bmbackground_text').value = document.getElementById(bm_id).value;
	document.getElementById('pm_err_msg').style.display = 'none';
	
	var prs_text    = document.getElementById(bm_id).value;
    var real_string = prs_text.ReplaceAllString("<br />","\n");		
    document.getElementById('bmbackground_text').value = real_string; 
		  
	$('#bandmember_background_dialog').dialog('open');	
}



function submitBMBackground()
{
    if(document.getElementById('bmbackground_text').value == '')
		{
			document.getElementById('errs_sumbit_msg').innerHTML = '<div style="margin-left:10px;">Background field should not be empty.</div>';
			document.getElementById('pm_err_msg').style.display = 'inline';		
		}
		else
		{
		    document.getElementById('pm_err_msg').style.display = 'none';	
		
			var $icon= $('.bm_bg_loader').addClass('current_icon');
			var bm_text    = document.getElementById('bmbackground_text').value;
		    var real_string = bm_text.ReplaceAllString("\n", "<br />");
			
			$.ajax({
			    beforeSend:FunRock.Loader.enableOnIcon,
				url:'/users/myband_background?id=' + document.getElementById('bmid').value + '&bmbgval=' +real_string ,
				cache: false,
				success:function(html) {
				  $('#bandmember_background_dialog').dialog('close');
				},
				complete:FunRock.Loader.disableOnIcon
			});		
		}
   
}


function addfriendfunc(id,username)
{
	document.getElementById('friendid').value = id;
	var id=this.id;	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	document.getElementById('username').innerHTML =username;
    $('#friend_dialog').dialog('open');	
}
function addFriend()
{
 
 var $icon= $('.friend_loader_2').addClass('current_icon');	
 

 $.ajax({
				beforeSend:FunRock.Loader.enableOnIcon,
				url:'/bands/add_friend?friendid=' + document.getElementById('friendid').value,
				cache: false,
				success:function(html) {
				
				  $('#friend_dialog').dialog('close');
				  $('#a_'+document.getElementById('friendid').value).hide();
				},
				 complete:FunRock.Loader.disableOnIcon
			});		
}

function closeDialogfriend()
{
    $('#friend_dialog').dialog('close');	
}

function regFreeLink()
{
	location.href = '/users/registration/';
}

function sendMsg()
{
	document.getElementById('nameerror').style.display     = 'none';
	document.getElementById('emailerror').style.display    = 'none';
	document.getElementById('emailerror').style.display    = 'none';
	document.getElementById('categoryerror').style.display = 'none';
	
    var catvalue = document.getElementById('category').options[document.getElementById('category').selectedIndex].value;
    document.getElementById('cat_select').value = catvalue;

	var re = /^[a-z0-9\s]+$/i;
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(!re.test(document.getElementById('nameinput').value))
	{
		document.getElementById('nameerror').style.display = 'inline';
	}
	else
	{
		if(!emailRegEx.test(document.getElementById('emailinput').value))
		{
		   document.getElementById('emailerror').style.display = 'inline';
		}
		else
		{
		   if(document.getElementById('textinput').value == '')
		   {
			  document.getElementById('texterror').style.display = 'inline';
		   }
		   else
		   {
			  document.Bandtycoon.submit();
		   }
		}
	}	
}


$(function() {
		$("#confirm_trade_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});


$(function() {
		$("#trade_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});

function closeTradeDialog()
{
	$('#trade_dialog').dialog('close');	
}

function closeConfirmTradeDialog()
{
	$('#confirm_trade_dialog').dialog('close');	
}

function tradeItems()
{
	$('#confirm_trade_dialog').dialog('close');
	document.Tradeitems.submit();
}

function checkTrade(fromString, toString, fromItemsimage, toItemsimage, fromuserbandname, touserbandname)
{
   var fromuseritems = new Array();
   var touseritems = new Array();
   var fromimages = new Array();
   var toimages = new Array();
       
   fromuseritems  = fromString.split(',');
   touseritems    = toString.split(',');
   fromimages     = fromItemsimage.split(',');
   toimages       = toItemsimage.split(',');
         
   var fromselect = false;
   var toselect   = false;
   
   var fromnumberitems = 0;
   var tonumberitems   = 0;
   
   var frienditemsimage = new Array();
   var myitemsimage = new Array();
   
   var j = 0;
   
   for(i=0; i < fromuseritems.length; i++)
   {
      if(document.getElementById(fromuseritems[i]).checked)
	  {
	     fromselect = true;
		 fromnumberitems++;
		 frienditemsimage[j] = fromimages[i];
		 j++;
	  }
   }
   
   var j = 0;
   
   for(i=0; i < touseritems.length; i++)
   {
      if(document.getElementById(touseritems[i]).checked)
	  {
	     toselect = true;
		 tonumberitems++;
		 myitemsimage[j] = toimages[i];
		 j++;
	  }
   }

   $(".ui-dialog-titlebar").hide();
   $(".ui-dialog").css("background",'transparent');
   $(".ui-dialog").css("border",'none');    
    
   if((fromselect && toselect) && (fromnumberitems == tonumberitems) && (fromnumberitems <= 2) && (tonumberitems <= 2))
   {
		var strDialog = '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
							'<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + fromuserbandname +
							'</div>' +
						'</div>';
						
		strDialog = strDialog + '<div style="margin-left:8px;" >';		

		for(i=0; i < frienditemsimage.length; i++)
		{	
		   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
								   '<img src="/img/items/' + frienditemsimage[i] + '">' +
								   '</div></div></div>';				   
		}
		
		strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';	
		
		strDialog = strDialog + '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
								'<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + touserbandname +
								'</div>' +
								'</div>';
						
		strDialog = strDialog + '<div style="margin-left:8px;" >';		

		for(i=0; i < myitemsimage.length; i++)
		{	
		   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
								   '<img src="/img/items/' + myitemsimage[i] + '">' +
								   '</div></div></div>';				   
		}
		
		strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';

		document.getElementById('userItemsComponent').innerHTML = strDialog;		
   
        $('#confirm_trade_dialog').dialog('open');
   }
   else
   {
       $('#trade_dialog').dialog('open');
   }
   
   return false;
}

$(function() {
		$("#exchange_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:true,
			width:'auto'
		});
});

$(function() {
		$("#tradeconfirm_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

$(function() {
		$("#tradedeny_dialog").dialog({
			bgiframe: true,
			resizable: false,
			autoOpen: false,
			modal: true,
			closeOnEscape:false,
			width:'auto'
		});
});

function closeTradeConfirm()
{
	$('#tradeconfirm_dialog').dialog('close');
}

function showDenyDialog(itemrequestid)
{
	document.getElementById('loader_animation_reqtable').style.left = parseInt(document.getElementById('request_table').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_reqtable').style.top = parseInt(document.getElementById('request_table').clientHeight/2) - 42 + 'px';
	
	document.getElementById('loader_animation_reqtable').style.display = 'inline';	
	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');
	
	$.ajax({
			url:'/items/deny_ajax?requestid=' + itemrequestid,
			cache: false,
			success:function(html) {
				if(html){	       
				
					 document.getElementById('loader_animation_reqtable').style.display = 'none';	

					 if(html == '0')					 
					 {
						$('#totalnewreq').html('');
					 }
					 else
					 {
						$('#totalnewreq').html('(new ' + html + ')');
					 }					 
					 
					 document.getElementById('totaltrdreq').innerHTML = '<a href="/items/tradeRequest">'+html+' Trade Request' + '</a>';
					
					 var firstdivid = 'msg_' + itemrequestid;
					 document.getElementById(firstdivid).style.display = 'none';
					 
					 var seconddivid = 'deny_' + itemrequestid;
					 document.getElementById(seconddivid).style.color   = 'red';
					 document.getElementById(seconddivid).style.display = 'inline';
					 
					 var thirddivid = 'bandname_' + itemrequestid;
					 document.getElementById(thirddivid).style.display = 'none';		

					 var forthdivid = 'noexchange_' + itemrequestid;
					 document.getElementById(forthdivid).style.display = 'inline';								 
												 
					 $(this).dialog("close"); 

					$('#tradedeny_dialog').dialog('open');	
			}
		}
	});
}

function showAcceptDialog(itemrequestid, numberofrows)
{
	document.getElementById('loader_animation_reqtable').style.left = parseInt(document.getElementById('request_table').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_reqtable').style.top = parseInt(document.getElementById('request_table').clientHeight/2) - 42 + 'px';
	
	document.getElementById('loader_animation_reqtable').style.display = 'inline';	
	
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');	
	
	$.ajax({
			url:'/items/accept_ajax?requestid=' + itemrequestid + '&numofrows=' + numberofrows,
			cache: false,
			success:function(html) {
				if(html){	  
	
				     var returnedstringarray = new Array();					 
					 
					 returnedstringarray  = html.split(',');
					 
				     document.getElementById('loader_animation_reqtable').style.display = 'none';
									 
					 if(returnedstringarray[0] == 0)					 
					 {
						$('#totalnewreq').html('');
					 }
					 else
					 {
						$('#totalnewreq').html('(new ' + returnedstringarray[0] + ')');
					 }							 
					 
					 document.getElementById('totaltrdreq').innerHTML = '<a href="/items/tradeRequest">'+returnedstringarray[0]+' Trade Request' + '</a>';
					 
					 var firstdivid = 'msg_' + itemrequestid;
					 document.getElementById(firstdivid).style.display = 'none';
					 
					 var seconddivid = 'acpt_' + itemrequestid;
					 document.getElementById(seconddivid).style.display = 'inline';
					 
					 var thirddivid = 'bandname_' + itemrequestid;
					 document.getElementById(thirddivid).style.display = 'none';		

					 var forthdivid = 'noexchange_' + itemrequestid;
					 document.getElementById(forthdivid).style.display = 'inline';								 
					 
					 for(i=1; i < returnedstringarray.length; i++)
					 {
						 var firstdivid = 'msg_' + returnedstringarray[i];
						 
						 if(document.getElementById(firstdivid))
						 {
						    document.getElementById(firstdivid).style.display = 'none';
						 }
						 
						 var seconddivid = 'deny_' + returnedstringarray[i];
						 
						 if(document.getElementById(seconddivid))
						 {
							document.getElementById(seconddivid).style.color   = 'red';
							document.getElementById(seconddivid).style.display = 'inline';
						 }
						 
						 var thirddivid = 'bandname_' + returnedstringarray[i];
						 
						 if(document.getElementById(thirddivid))
						 {
							document.getElementById(thirddivid).style.display = 'none';		
                         }
						 
						 var forthdivid = 'noexchange_' + returnedstringarray[i];
						 
						 if(document.getElementById(forthdivid))
						 {
							document.getElementById(forthdivid).style.display = 'inline';						 
						 }	
					 }
												 
					 $(this).dialog("close"); 
							 								  
					 $('#tradeconfirm_dialog').dialog('open');
					
			}
		}
	});
}

function acceptRequest(numberofrows)
{
   
	var itemrequestid = document.getElementById('itemrequestid').value;
	
	document.getElementById('loader_animation_trade').style.left = parseInt(document.getElementById('exchange_dialog').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_trade').style.top = parseInt(document.getElementById('exchange_dialog').clientHeight/2) - 42 + 'px';
	
	document.getElementById('loader_animation_trade').style.display = 'inline';	
	
	$.ajax({
		url:'/items/accept_ajax?requestid=' + itemrequestid + '&numofrows=' + numberofrows,
		cache: false,
		success:function(html) {
			if(html){		 
				
				 var returnedstringarray = new Array();					 
				 
				 returnedstringarray  = html.split(',');
				 
				 document.getElementById('loader_animation_reqtable').style.display = 'none';
								 
				 if(returnedstringarray[0] == 0)					 
				 {
					$('#totalnewreq').html('');
				 }
				 else
				 {
					$('#totalnewreq').html('(new ' + returnedstringarray[0] + ')');
				 }							 
				 
				 document.getElementById('totaltrdreq').innerHTML = '<a href="/items/tradeRequest">'+returnedstringarray[0]+' Trade Request' + '</a>';
				 
				 var firstdivid = 'msg_' + itemrequestid;
				 document.getElementById(firstdivid).style.display = 'none';
				 
				 var seconddivid = 'acpt_' + itemrequestid;
				 document.getElementById(seconddivid).style.display = 'inline';
				 
				 var thirddivid = 'bandname_' + itemrequestid;
				 document.getElementById(thirddivid).style.display = 'none';		

				 var forthdivid = 'noexchange_' + itemrequestid;
				 document.getElementById(forthdivid).style.display = 'inline';								 
				 
				 for(i=1; i < returnedstringarray.length; i++)
				 {
					 var firstdivid = 'msg_' + returnedstringarray[i];
					 
					 if(document.getElementById(firstdivid))
					 {
						document.getElementById(firstdivid).style.display = 'none';
					 }
					 
					 var seconddivid = 'deny_' + returnedstringarray[i];
					 
					 if(document.getElementById(seconddivid))
					 {
						document.getElementById(seconddivid).style.color   = 'red';
						document.getElementById(seconddivid).style.display = 'inline';
					 }
					 
					 var thirddivid = 'bandname_' + returnedstringarray[i];
					 
					 if(document.getElementById(thirddivid))
					 {
						document.getElementById(thirddivid).style.display = 'none';		
					 }
					 
					 var forthdivid = 'noexchange_' + returnedstringarray[i];
					 
					 if(document.getElementById(forthdivid))
					 {
						document.getElementById(forthdivid).style.display = 'inline';						 
					 }	
				}							
																 
				$(this).dialog("close"); 
										 								  
				$('#tradeconfirm_dialog').dialog('open');	
				$('#exchange_dialog').dialog('close');

				document.getElementById('tradebuttons').style.display = 'none';
				document.getElementById('closebutton').style.display = 'none';				
			}
		}
	});				
}

function denyRequest()
{
	var itemrequestid = document.getElementById('itemrequestid').value;
	
	document.getElementById('loader_animation_trade').style.left = parseInt(document.getElementById('exchange_dialog').clientWidth/2) - 40 + 'px';
	document.getElementById('loader_animation_trade').style.top = parseInt(document.getElementById('exchange_dialog').clientHeight/2) - 42 + 'px';
	
	document.getElementById('loader_animation_trade').style.display = 'inline';		
	
	$.ajax({
		url:'/items/deny_ajax?requestid=' + itemrequestid,
		cache: false,
		success:function(html) {
			if(html){		
				document.getElementById('loader_animation_trade').style.display = 'none';
				
				if(html == '0')					 
				{
					$('#totalnewreq').html('');
				}
				else
				{
					$('#totalnewreq').html('(new ' + html + ')');
				}					 
				
				document.getElementById('totaltrdreq').innerHTML = '<a href="/items/tradeRequest">'+html+' Trade Request' + '</a>';
								 
				var firstdivid = 'msg_' + itemrequestid;
				document.getElementById(firstdivid).style.display = 'none';
								 
				var seconddivid = 'deny_' + itemrequestid;
				document.getElementById(seconddivid).style.color   = 'red';
				document.getElementById(seconddivid).style.display = 'inline';
				
				var thirddivid = 'bandname_' + itemrequestid;
				document.getElementById(thirddivid).style.display = 'none';		

				var forthdivid = 'noexchange_' + itemrequestid;
				document.getElementById(forthdivid).style.display = 'inline';									
																 
				$(this).dialog("close"); 										 
								  
				$('#tradedeny_dialog').dialog('open');	
				$('#exchange_dialog').dialog('close');
				
				document.getElementById('tradebuttons').style.display = 'none';
				document.getElementById('closebutton').style.display = 'none';
			}
		}
	});			
}

function closeDenyDialog()
{
	$('#tradedeny_dialog').dialog('close');	
}

function showItemChangeDialog(sugimageString, sugnameString, reqimageString, reqnameString, fromUser, toUser, itemrequestid)
{
    var sugitemimage = new Array();
    var sugitemname  = new Array();
    var reqitemimage = new Array();
    var reqitemname  = new Array();   
   
    sugitemimage  = sugimageString.split(',');
    sugitemname   = sugnameString.split(','); 
    reqitemimage  = reqimageString.split(',');
    reqitemname   = reqnameString.split(','); 
	
	document.getElementById('loader_animation_trade').style.display = 'none';
	
    var strDialog = '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
		                '<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + toUser +
		                '</div>' +
	                '</div>';
					
	strDialog = strDialog + '<div style="margin-left:8px;" >';		

    for(i=0; i < sugitemimage.length; i++)
    {	
	   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
	                           '<img src="/img/items/' + sugitemimage[i] + '">' +
	                           '</div></div></div>';				   
    }
	
	strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';	
	
    strDialog = strDialog + '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
		                    '<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + fromUser +
		                    '</div>' +
	                        '</div>';
					
	strDialog = strDialog + '<div style="margin-left:8px;" >';		

    for(i=0; i < reqitemimage.length; i++)
    {	
	   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
	                           '<img src="/img/items/' + reqitemimage[i] + '">' +
	                           '</div></div></div>';				   
    }
	
	strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';		
	
	document.getElementById('closebutton').style.display = 'none';
	document.getElementById('tradebuttons').style.display = 'inline';
    	
	document.getElementById('items_holder').innerHTML = strDialog;
	
	document.getElementById('itemrequestid').value = itemrequestid;
			
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');	
				  				   
    $('#exchange_dialog').dialog('open');
}

function showUserItemsDialog(sugimageString, sugnameString, reqimageString, reqnameString, fromUser, toUser, itemrequestid)
{
    var sugitemimage = new Array();
    var sugitemname  = new Array();
    var reqitemimage = new Array();
    var reqitemname  = new Array();   
   
    sugitemimage  = sugimageString.split(',');
    sugitemname   = sugnameString.split(','); 
    reqitemimage  = reqimageString.split(',');
    reqitemname   = reqnameString.split(','); 
	
	document.getElementById('loader_animation_trade').style.display = 'none';
	
    var strDialog = '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
		                '<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + toUser +
		                '</div>' +
	                '</div>';
					
	strDialog = strDialog + '<div style="margin-left:8px;" >';		

    for(i=0; i < sugitemimage.length; i++)
    {	
	   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
	                           '<img src="/img/items/' + sugitemimage[i] + '">' +
	                           '</div></div></div>';				   
    }
	
	strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';	
	
    strDialog = strDialog + '<div style="margin-left:10px; margin-right:10px; margin-bottom:10px; height:20px; border:2px solid; color:white;">' +
		                    '<div align="left" style="margin-left:10px; color:yellow; font-weight:bold;">' + fromUser +
		                    '</div>' +
	                        '</div>';
					
	strDialog = strDialog + '<div style="margin-left:8px;" >';		

    for(i=0; i < reqitemimage.length; i++)
    {	
	   strDialog = strDialog + '<div class="greenBorder" style="display: table; height: 160px;width:120px; float:left; margin-left:20px; margin-top:10px; #position: relative; overflow: hidden;"><div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; background-color:#F6F6F6"><div align="center"  style=" #position: relative; #top: -50%">' +
	                           '<img src="/img/items/' + reqitemimage[i] + '">' +
	                           '</div></div></div>';				   
    }
	
	strDialog = strDialog + '</div><div style="clear:both;"></div><div style="padding-top:14px;"></div>';		
          	
	document.getElementById('tradebuttons').style.display = 'none';
	document.getElementById('closebutton').style.display = 'inline';
    	
	document.getElementById('items_holder').innerHTML = strDialog;
		
	$(".ui-dialog-titlebar").hide();
	$(".ui-dialog").css("background",'transparent');
	$(".ui-dialog").css("border",'none');	
		
    $('#exchange_dialog').dialog('open');
}

function closeExchangeDialog()
{
   $('#exchange_dialog').dialog('close');
}

function userCommentsLink(commentid, classname, foreignid)
{
	$.ajax({
		url:'/users/usercomment_ajax?commentid=' + commentid,
		cache: false,
		success:function(html) {
			if(html){		
			   if(html == 1)
			   {
			      if(classname == 'Single')
				  {
					  location.href = '/bands/view/' + foreignid;				  
				  }
				  else
				  {
				      if(classname == 'Song')
					  {
					      location.href = '/songs/view/' + foreignid;
					  }
					  else
					  {
					      if(classname == 'Userstat')
						  {
						      location.href = '/users/view/' + foreignid;
						  }
						  else
						  {
						      if(classname == 'Album')
							  {
							     location.href = '/albums/view/' + foreignid;
							  }
							  else
							  {
							      if(classname == 'Gigreport')
								  {
								      location.href = '/gigs/view/' + foreignid;
								  }
								  else
								  {
								      if(classname == 'Pressrelease')
									  {
									     location.href = '/pressreleases/singlePressRelease/' + foreignid;
									  }
								  }
							  }
						  }
					  }
				  }
			   }
			}
		}
	});			  
}

$(function()
{
	stripeRows('#song-list tbody');
	stripeRows('#single-list tbody');
	stripeRows('#gig_songlist tbody');
	initAsyncSongPagination();
	initAsyncSinglePagination();
	initAsyncGigSongPagination();
	initAsyncBuyStudioPagination();	
	initAsyncUserItemsPagination();	
	initAsyncBuyItemsPagination();	
	initAsyncFromUserItemsPagination();	
	initAsyncTraveledPagination();
	initAsyncFromUserInstrumentPagination();
    initAsyncPressreleasePagination();		
	initAsyncFriendRequestPagination();	
	initAsyncGigReportsPagination();
	initAsyncSearchPagination();	
	initAsyncTradeListPagination();
	initAsyncPMPagination();
	initAsyncCommentListPagination();
	initAsyncUserDressPagination();
	initAsyncLogedUserPagination();	
	initAsyncRehearsalSongPagination();	
});

function initAsyncRehearsalSongPagination()
{
	$('#rehearsalsongs #pagerehersalsonglist a').click(function()
	{
	    var href = '';
	    href = $(this).attr('href');
	    var $icon= $('.rehearse_loader').addClass('current_icon');		
		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{   
				$('#rehearsalsongs').replaceWith(html);	
				 initAsyncRehearsalSongPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncLogedUserPagination()
{
	$('#loged_user_list #pagelogeduser a').click(function()
	{
		var href = '';
	    href = $(this).attr('href');
		var $icon= $('.users_list').addClass('current_icon');		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{    
				$('#loged_user_list').replaceWith(html);	
				initAsyncLogedUserPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncPMPagination()
{
	$('#PM #pagePMlist a').click(function()
	{
		var href = '';
	    href = $(this).attr('href');
		var $icon= $('.PM_loader').addClass('current_icon');		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{    
				$('#PM').replaceWith(html);	
				initAsyncPMPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncCommentListPagination()
{
	$('#user-comments #commentlist a').click(function()
	{
		var href = '';
		
	    href = $(this).attr('href');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{   
				$('#user-comments').replaceWith(html);	
				initAsyncCommentListPagination();
			},
				complete:FunRock.Loader.disable
		});
		return false;
	});	
}

function initAsyncTradeListPagination()
{
	$('#request_table #pagetradelist a').click(function()
	{
	
		document.getElementById('loader_animation_reqtable').style.left = parseInt(document.getElementById('request_table').clientWidth/2) - 40 + 'px';
		document.getElementById('loader_animation_reqtable').style.top = parseInt(document.getElementById('request_table').clientHeight/2) - 40 + 'px';
	    document.getElementById('loader_animation_reqtable').style.display = 'inline';			

		var href = '';
		
	    href = $(this).attr('href');
		
		$.ajax({
			url: href,
			cache: false,
			success: function(html)
			{   
			    document.getElementById('loader_animation_reqtable').style.display = 'none';
				$('#request_table').replaceWith(html);	
				initAsyncTradeListPagination();
			}
		});
		return false;
	});	
}

function initAsyncSearchPagination()
{
	$('#searchresult #pagesearchlist a').click(function()
	{
	
		var href = '';
		
	    href = $(this).attr('href');
	    var $icon= $('.searchresult_loader').addClass('current_icon');		
		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{   
				$('#searchresult').replaceWith(html);	
				 initAsyncSearchPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncPressreleasePagination()
{
	$('#rightpressrelease #pagepressreleaselist a').click(function()
	{
		var href = '';
		
	    href = $(this).attr('href');
		var $icon= $('.pressrelease_loader').addClass('current_icon');		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{   
				$('#rightpressrelease').replaceWith(html);	
				  initAsyncPressreleasePagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncGigReportsPagination()
{
	$('#gigreport_list #pagegigreports a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		var $icon= $('.country_Gigreport_Container').addClass('current_icon');			
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#gigreport_list').replaceWith(html);
				initAsyncGigReportsPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncSingleRefGigPagination(countryId, refId)
{
	$('#single-gig #pagesinglegig a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href') + "&countryid=" + countryId + "&refid=" + refId;
		
		var $icon= $('.country_Report_Container').addClass('current_icon');	
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#single-gig').replaceWith(html);				
				initAsyncSingleRefGigPagination(countryId, refId);
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncSingleGigPagination(countryId)
{
	$('#single-gig #pagesinglegig a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href') + "&countryid=" + countryId;
		
		var $icon= $('.country_Report_Container').addClass('current_icon');	
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#single-gig').replaceWith(html);				
				initAsyncSingleGigPagination(countryId);
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncTraveledPagination()
{
	$('#band_traveledlist #pagetravelist a').click(function()
	{		
		var $icon= $('.travellist_container').addClass('current_icon');

		var href = '';
		
		href = $(this).attr('href');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#band_traveledlist').replaceWith(html);
				initAsyncTraveledPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncFromUserItemsPagination()
{
	$('#fromuser-items #pageuseritemlist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		$.ajax({
		     beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#fromuser-items').replaceWith(html);	
				initAsyncFromUserItemsPagination();
			},
			 complete:FunRock.Loader.disable
		});
		return false;
	});	
}


function initAsyncFromUserInstrumentPagination()
{
	$('#fromuser-instruments #pageuserinstrumentlist a').click(function()
	{
		var href = '';
	    href = $(this).attr('href');
	
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#fromuser-instruments').replaceWith(html);	
				initAsyncFromUserInstrumentPagination();
			},
			complete:FunRock.Loader.disable
		});
		return false;
	});	
}

function initAsyncUserDressPagination()
{
	$('#fromuser-dresses #pageuserdresslist a').click(function()
	{
		var href = '';
	    href = $(this).attr('href');
	
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#fromuser-dresses').replaceWith(html);	
				initAsyncUserDressPagination();
			},
			complete:FunRock.Loader.disable
		});
		return false;
	});	
}
function initAsyncFriendRequestPagination()
{
	$('#friendrequest #pagefriendrequestlist a').click(function()
	{
	  
		var href = '';
	    href = $(this).attr('href');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
			  
				$('#friendrequest').replaceWith(html);	
				initAsyncFriendRequestPagination();
			},
			complete:FunRock.Loader.disable
		});
		return false;
	});	
}



function initAsyncBuyItemsPagination()
{
	$('#buy-items #pagesonglist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#buy-items').replaceWith(html);	
				initAsyncBuyItemsPagination();
			},
			    complete:FunRock.Loader.disable
		});
		return false;
	});	
}

function initAsyncUserItemsPagination()
{
	$('#user-items #pagesonglist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enable,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#user-items').replaceWith(html);	
				initAsyncUserItemsPagination();
			},
			  complete:FunRock.Loader.disable
		});
		return false;
	});	
}

function initAsyncBuyStudioPagination()
{
	$('#buy-studio #pagesonglist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		var $icon= $('.loader_animation_buystudio').addClass('current_icon');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#buy-studio').replaceWith(html);
				initAsyncBuyStudioPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}

function initAsyncGigSongPagination()
{
	$('#gig_songlist #pagesonglist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		var $icon= $('.gig_Songlist_Container').addClass('current_icon');
		
		$.ajax({
			beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{		
				$('#gig_songlist').replaceWith(html);
				
				stripeRows('#gig_songlist tbody');
				
				initAsyncGigSongPagination();
			},
			complete:FunRock.Loader.disableOnIcon	
		});
		return false;
		
	});	
}
	
function initAsyncSinglePagination()
{
	$('#single-list #pagesinglelist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		var $icon= $('.singlelist_container').addClass('current_icon');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
			    document.getElementById('loader_animation_singlelist').style.display = 'none';	
				$('#single-list').replaceWith(html);
				stripeRows('#single-list tbody');
				
				initAsyncSinglePagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});	
}


function initAsyncSongPagination()
{	
	$('#song-list #pagesonglist a').click(function()
	{
		var href = '';
		
		href = $(this).attr('href');
		
		var $icon= $('.songlist_container').addClass('current_icon');
		
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url: href,
			cache: false,
			success: function(html)
			{
				$('#song-list').replaceWith(html);
				stripeRows('#song-list tbody');
				
				initAsyncSongPagination();
			},
			complete:FunRock.Loader.disableOnIcon
		});
		return false;
	});		
}

function stripeRows(selector)
{
	$(selector + ' tr:nth-child(even)').addClass('Odd');	
}

function bookGig()
{
    if(gigSongCheckBoxes())
	{ 	
		$(".ui-dialog-titlebar").hide();
		$(".ui-dialog").css("background",'transparent');
		$(".ui-dialog").css("border",'none');
		
		var $icon= $('.gig_Dialog_Container').addClass('current_icon');
	
		$.ajax({
		    beforeSend:FunRock.Loader.enableOnIcon,
			url:'/gigs/submitgig_ajax?gigid=' + document.getElementById('gig_id_container').value + '&songsid=' +  getGigSongsId(),
			cache: false,
			success:function(resp) {
				if(resp){
					$('#gigs_dialog').dialog('close');	
					$('#gigs_submit_confirm').dialog('open');	
				}
			},
			complete:FunRock.Loader.disableOnIcon
		});		   
	}
	else
	{
	   $('#gig_error_dialog').dialog('open'); 
	}
}