var SITE_URL = 'http://www.business-add.com/';

function delete_product(id) {
  var r = confirm('Are you sure you want to delete this product?');

  if ( r == true ) {
    window.location = 'delete_product-delete-' + id;
  }
}

function loadPhone(id, div, link) {
  var ajaxres = $.ajax( { type: "GET", url: "ajax_load_phone.php?id=" + id, async: false } ).responseText;

  if(typeof(ajaxres) != null) {
    $("#" + link).hide();
    $("#" + div).html(ajaxres);
  }
}

function loadFax(id, div, link) {
  var ajaxres = $.ajax( { type: "GET", url: "ajax_load_fax.php?id=" + id, async: false } ).responseText;

  if(typeof(ajaxres) != null) {
    $("#" + link).hide();
    $("#" + div).html(ajaxres);
  }
}

function loadEmail(id, div, link) {
  var ajaxres = $.ajax( { type: "GET", url: "ajax_load_email.php?id=" + id, async: false } ).responseText;

  if(typeof(ajaxres) != null) {
    $("#" + link).hide();
    $("#" + div).html(ajaxres);
  }
}

function loadWebUrl(id, div, link) {
  var ajaxres = $.ajax( { type: "GET", url: "ajax_load_web_url.php?id=" + id, async: false } ).responseText;

  if(typeof(ajaxres) != null) {
    $("#" + link).hide();
    $("#" + div).html(ajaxres);
  }
}

function image_preview() {
  if ( $('#imag_preview').css('display') == 'none' ) {
    $('#imag_preview').show(1000);
  } else {
    $('#imag_preview').hide(1000);
  }
}

function delete_company(company_id) {
  var r = confirm('Are you sure you want to remove your company?');

  if ( r == true ) {
    window.location = 'edit_company.php?action=delete&delete_id=' + company_id;
  }
}

function delete_user() {
  var r = confirm('Are you sure you want to remove your account with our website?');

  if ( r == true ) {
    window.location = 'edit_account.php?action=delete&aaa=sure';
  }
}

function load_category(type) {
  $('#subcategory_place_' + type).html('<div align="center"><img src="images/load1.gif" /></div>');

  $.ajax({
    type: "POST",
    url: "ajax_populate_subcategories.php",
    data: "parent=" + $('#category_place_' + type).val() + "&type=" + type,
    success: function(msg){
      //alert( "Data Saved: " + msg );
      $('#subcategory_place_' + type).html(msg);

      set_values(type, $('#category_place_' + type).val());
    }
  });
}

function select_subcategory(type) {
  $('#headingcategory_place_' + type).html('<div align="center"><img src="images/load1.gif" /></div>');

  $.ajax({
    type: "POST",
    url: "ajax_populate_headingcategories.php",
    data: "parent=" + $('#subcategory_div_' + type).val() + "&type=" + type,
    success: function(msg){
      //alert( "Data Saved: " + msg );
      $('#headingcategory_place_' + type).html(msg);

      set_values(type, $('#subcategory_div_' + type).val());

      $("#subcategory" + type).val($('#subcategory_div_' + type).val());
    }
  });
}

function select_headingcategory(type) {
  if ( type == 1 ) {
    $("#category").val($('#headingcategory_div_' + type).val());
  } else {
    $("#category" + type).val($('#headingcategory_div_' + type).val());
  }
}

function set_values(type, value) {
  if ( type == 1 ) {
    $("#category").val(value);
  } else {
    $("#category" + type).val(value);
  }
}

function preload_category(type, parent, child) {
  $('#subcategory_place_' + type).html('<div align="center"><img src="images/load1.gif" /></div>');

  $.ajax({
    type: "POST",
    url: "ajax_populate_subcategories.php",
    data: "parent=" + parent + "&child=" + child + "&type=" + type,
    success: function(msg){
      //alert( "Data Saved: " + msg );
      $('#subcategory_place_' + type).html(msg);

      set_values(type, $('#category_place_' + type).val());
    }
  });
}

function preselect_subcategory(type, parent, child) {
  $('#headingcategory_place_' + type).html('<div align="center"><img src="images/load1.gif" /></div>');

  $.ajax({
    type: "POST",
    url: "ajax_populate_headingcategories.php",
    data: "parent=" + parent + "&child=" + child + "&type=" + type,
    success: function(msg){
      //alert( "Data Saved: " + msg );
      $('#headingcategory_place_' + type).html(msg);

      set_values(type, $('#subcategory_div_' + type).val());

      $("#subcategory" + type).val($('#subcategory_div_' + type).val());
    }
  });
}

function load_preloaded_categories(cat1, cat2, cat3, type) {
  if ( cat1 != '' && cat2 != '' && cat3 != '' && type != '' ) {
    preload_category(type, cat1, cat2);
    preselect_subcategory(type, cat2, cat3);
  }
}

function make() {
  var c = setInterval("change_add()", 1000);
}

function change_add() {
  var default_var = 'url(' + SITE_URL + 'images/menu_special.jpg)';
  var default_var2 = 'url("' + SITE_URL + 'images/menu_special.jpg")';

  if ( $('#add_bussiness').css('background-image') == default_var || $('#add_bussiness').css('background-image') == default_var2 ) {
    $('#add_bussiness').css('background-image', 'url(' + SITE_URL + 'images/menu_hover_add2.jpg)');
  } else {
    $('#add_bussiness').css('background-image', 'url(' + SITE_URL + 'images/menu_special.jpg)');
  }
}