var tabs;
function joocart_get_tab_key(href) {
  return href.replace('#', '');
}
function joocart_hide_all_tabs() {
    tabs.each(function(){
        var href = joocart_get_tab_key(jQuery(this).attr('href'));
        jQuery('#' + href).hide();
    });
}
function joocart_activate_tab(tab) {
    tab = jQuery(tab);
    if (!tab || tab.length === 0) {
        return;
    }
    var href = joocart_get_tab_key(tab.attr('href'));
    tabs.removeClass('nav-tab-active');
    tab.addClass('nav-tab-active');
    jQuery('#' + href).show();
}
jQuery(document).ready(function($){
    var activeTab, firstTab;
    firstTab = false;
    activeTab = false;
    tabs = $('a.nav-tab');
    if (!tabs.length) {
        return;
    }
    joocart_hide_all_tabs();
    tabs.each(function(){
        var href = $(this).attr('href').replace('#', '');
        if (!firstTab) {
            firstTab = $(this);
        }
        if ($(this).hasClass('nav-tab-active')) {
            activeTab = $(this);
        }
    });
    if (!activeTab) {
        activeTab = firstTab;
    }
    joocart_activate_tab(activeTab);
    tabs.click(function(e) {
        e.preventDefault();
        joocart_hide_all_tabs();
        joocart_activate_tab($(this));
    });
});
elment_focused = false;
joocart_validate_form();
function joocart_validate_field (field_id) {
	element_field = document.querySelector(field_id);
	if(element_field.value=="") {
		if(!elment_focused) {
			element_field.focus();
			elment_focused = true;
		}
		element_field.style.border = "1px solid red";
	} else {
		element_field.style.border = "";
	}
}

function joocart_validate_form() {
	if(document.querySelector("#joocart_upgrade_download_id").value=="" || document.querySelector("#joocart_order_email").value=="" || document.querySelector("#joocart_opencart_dir_path").value=="" || document.querySelector("#joocart_opencart_dir_url").value=="") {  
		elment_focused = false;
		joocart_validate_field('#joocart_upgrade_download_id');
		joocart_validate_field('#joocart_order_email');
		joocart_validate_field('#joocart_opencart_dir_path');
		joocart_validate_field('#joocart_opencart_dir_url');
		return false;
     }	
}