//////////////// to change password from profile page
/////////////// reset passwordends here //////////////////////////
////////////////////// update portfolio page ///////////////
function payment_made(x,y){
    //// headers
    $('#'+x).toggleClass('done current');
    $('#'+x+'_number').css('background-color','#f74f75');
    $('#'+y).toggleClass('disabled current');
    // tabs
    $('#'+x+'_tab').toggleClass('current');
    $('#'+x+'_tab').css('display','none');
    $('#'+y+'_tab').toggleClass('current');
    $('#'+y+'_tab').css('display','block');
    /// buttons
    $('#'+x+'_btn').css('display','none');
    $('#'+y+'_btn').css('display','block');
    //////////////////
    $('#'+y+'_text').html('Your deposit transaction is being processed.');
}

function fund_value(x,y){
    $("#"+y).val(x);
}
////////////// update two fa

function switch_tabs(x){
    if(x == 1){
        $('#profile').css('display','block');
        $('#edit_profile').css('display','none');
        $('#settings').css('display','none');        
    }else if(x == 2){
        $('#profile').css('display','none');
        $('#edit_profile').css('display','block');
        $('#settings').css('display','none');        
    }
    else if(x == 3){
        $('#profile').css('display','none');
        $('#edit_profile').css('display','none');
        $('#settings').css('display','block');        
    }
}
function copy_text(x) {
    //    $("#"+x+"_btn").html('<i class="fas fa-spinner fa-spin"></i>');
    /* Get the text field */
    var copyText = document.getElementById(x);
    var btn = $("#"+x+"_btn");
	var btn_content = btn.html();
    btn.html('Copied');
    setTimeout(function () {
        btn.html(btn_content);
    }, 3000);
    /* Select the text field */
    copyText.select();
    copyText.setSelectionRange(0, 99999); /* For mobile devices */

    /* Copy the text inside the text field */
    navigator.clipboard.writeText(copyText.value);
}
function copy_text2(x) {
    //    $("#"+x+"_btn").html('<i class="fas fa-spinner fa-spin"></i>');
    /* Get the text field */
    var copyText = document.getElementById(x);
    /* Select the text field */
    copyText.select();
    copyText.setSelectionRange(0, 99999); /* For mobile devices */

    /* Copy the text inside the text field */
    navigator.clipboard.writeText(copyText.value);
}

/////// pay invoice
function pay_invoice(){
    var invoice_code = $("#invoice_number").html();
    var bar_code = $("#"+invoice_code).html();
    $("#invoice_qr_code").html(bar_code);
}
/////// generate invoice
function transfer_bonus(){
    var a  =$("#ref_amount").val();
    if(a.length != 0 && a > 0) {
	var data = {'amount':a}; 
        var btn = $("#ref_btn");
        btn.prop('disabled',false);
	$.ajax({
		type:'POST',
		url:'../controller/post.php?transfer_bonuses',
		data:data,
		beforeSend: function(){	
                    btn.html('<i class="fa fa-spinner fa-spin"></i>');
		},
		success: function(data){
			if(data == 1){
                            $("#ref_amount").val( $("#ref_amount2").val() - a);
                            $("#ref_amount2").val( $("#ref_amount").val());
                            Msg_custom("<strong><i class='fa fa-check-square'></i>&nbsp;</strong> Bonuses moved to wallet.","alert-success",1,"#msg_div",10000);
			} else if (data == 2){
                            Msg_custom("<strong><i class='fa fa-warning'></i>&nbsp;</strong> Invalid request","alert-danger",1,"#msg_div",12000);
			} else if(data == 3){
				Msg_custom("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong> Invalid amount","alert-danger",1,"#msg_div",12000);				
			}else{
                            Msg_custom("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong>"+data,"alert-danger",1,"#msg_div",12000);
			} 
                        btn.prop('disabled',false);
                        btn.html("Claim");
		}
	});
    }else{
        Msg_custom("<strong><i class='fa fa-warning'></i>&nbsp;</strong> amount must be greater than zero","alert-danger",1,"#msg_div",12000);
    }
}

////////////////////// in page support script ///////////////
////////////////////// support script ///////////////
function send_message(done){
        if($("#subject").val().length == 0 || $("#con_message").val().length == 0){
		Msg("<i class='fa fa-warning'></i>&nbsp; fill the form!!!","alert-danger",0,"#support_status",12000);
	} else if(done == 0) {
	var data = $("#support_form").serialize();
	$.ajax({
		type:'POST',
		url:'index.php',
		data:data,
		beforeSend: function(){	
			$("#support_btn").html('<i class="fa fa-spinner fa-spin"></i>');
		},
		success: function(data){
			if(data == 1){
                            $("#support_btn").html("Submit");
				Msg("<strong><i class='fa fa-check-square'></i>&nbsp;  Sent successfuly</strong>","alert-success",0,"#support_status",10000);
				setTimeout(function() {
					$("#support_form").trigger('reset');
				},12000);
			} else if (data == 2){
				Msg("<strong><i class='fa fa-warning'></i>&nbsp; fill the form!!!</strong>","alert-danger",0,"#support_status",12000);
				$("#support_btn").html("Submit");
			} else if(data == 3){
				Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; account does not exist</strong>","alert-danger",0,"#support_status",12000);				
				$("#support_btn").html("Submit");
			}else{
				Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; Unknown error. please try again</strong>","alert-danger",0,"#support_status",12000);				
				$("#support_btn").html("Submit");
			} 
                        done = 1;
		}
	});
    }
}

////////////////////// account select plan ///////////////

//// Update the last time they checked notification bar
function update_seen(x){
	var data = {'update_email_seen':x};
	$.ajax({
		type:'POST',
		url:'../controller/post.php?update_seen',
		data:data,		
		success: function(data){
//			if(data == 1){
//                            alert('good');
//			}else{
//                            alert('error');
//			} 
		}
	});
}
////////////////////// support script ///////////////
function invite_friend(done){
	var status = '#invite_status';
	if($("#referralEmail").val().length == 0 ){
		Msg("<i class='fa fa-warning'></i>&nbsp; Enter email...","alert-danger",0,status,12000);
	} else if( $("#ref_link").val().length == 0){
		Msg("<i class='fa fa-warning'></i>&nbsp; Reload page and try again...","alert-danger",0,status,12000);
	} else if(done == 0) {
		var btn = $('.invite_friend_btn');
		var btn_content = btn.html();
		btn.prop('disabled',true);
		var data = $("#invite_friend").serialize();
		$.ajax({
			type:'POST',
			url:'index.php',
			data:data,
			beforeSend: function(){	
				btn.html('<i class="fa fa-spinner fa-spin"></i>');
			},
			success: function(data){
				if(data == 1){
					Msg("<strong><i class='fa fa-check-square'></i>&nbsp;</strong> Sent...","alert-success",0,status,10000);
					setTimeout(function() {
						$("#support_form").trigger('reset');
					},6000);
				} else if (data == 2){
					Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> All fields required...","alert-danger",0,status,12000);
				} else if(data == 3){
					Msg("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong> Enter a valid email address...","alert-danger",0,status,12000);				
				}else{
					Msg("<strong><i class='fa fa-times-circle'></i>&nbsp;n</strong> "+data,"alert-danger",0,status,12000);				
				} 
				done = 1;
				btn.html(btn_content);
            	btn.prop('disabled',false);
			}
		});
	}
}
$(".invite_friend_btn").click(function(){    
    invite_friend(0);
});