// Front end ajax functions

// Call the python function get alert string and del the session
function AjaxDeleteSession(id){
	$.post('/ajax/delete-session/'+id+'/', function(data){
		if(data != 'none'){
			alert(data);
		}
	});
}

function ajaxDelImg(id, img, mode){
    num =1
	if(confirm('Are you sure you want to delete this image?')){
		$.post('/ajax/delimg/' +  id + '/' + img + '/' , function(data){
			$(".imgdel_hide").hide();
			$(".imgdel_show").show();
		});
	}
}

function validate_username(username, id) {
    if (id) {
        url = '/ajax-validate-username/' + username + '/' + id + '/';
    } else {
        url = '/ajax-validate-username/' + username + '/';
    }
    if (username != '') {
         $.post(url, function(data){
			if (data == "True") {
                alert("The username entered is already in use")
                $('#id_username').val('');
                $('#id_username').focus();
            }
		});
    }
   
}

function validate_member_email(email, id) {
    if (id) {
        url = '/ajax-validate-email/' + email + '/' + id + '/';
    } else {
        url = '/ajax-validate-email/' + email + '/';
    }
    if (email != '') {
         $.post(url, function(data){
			if (data == "True") {
                alert("The primary email for this member is already in use");
                $('#id_email1').val('');
                $('#id_email1').focus();
            }
		});
    }
   
}

function validate_url(url, id) {
    if (id != '' && url != '') {
         $.post('/ajax-validate-url/' + url  + '/' + id + '/', function(data){
			if (data == "True") {
                alert("The Headwear Direct URL entered  is already in use");
                $('#id_direct_url').val('');
                $('#id_direct_url').focus();
            }
		});
    
    }
    else if (url != '') {
        $.post('/ajax-validate-url/' + url  + '/' , function(data){
			if (data == "True") {
                alert("The Headwear Direct URL entered  is already in use");
                $('#id_direct_url').val('');
                $('#id_direct_url').focus();
            }
		});
    }
    
        
   
}

function AjaxVerifyImageCode(enteredcode,imghash) {
  var verified = "False";
  if(enteredcode!="" && imghash!=""){
	$.ajax({
		  url: "/ajax/check_verification/"+enteredcode+"/"+imghash+"/",
		  async: false,
		  success: function(msg){
			verified = msg;
		  }
	});

  }
  return verified;
}
