var register_clicked;
var show_updates_clicked = false;
var show_licenses_clicked = false;
var show_update_clicked = false; 

function productsandupdates(form) {
  try {	
	if (register_clicked==true){
		$("#register_product_form").load("/userportal/ajax/your-products/product_register/", $("#product_registration_form").serializeArray(), function(data){						
			if ($('#messagePartner').length != 1) {
				$('#messageProduct').show();
				$('#product_registration_form input:first').val('');
				$('#commercial_products_list').load("/userportal/ajax/your-products/products/");
			}
			else {
				$('#messages_container').hide();				
				$('#messageProduct').show();
				if ($('select#id_product').length != 1) {
					$('#product_registration_form input:first').val('');
					$('#commercial_products_list').load("/userportal/ajax/your-products/products/");
				}
			}
		});
		
		return false;
	}
  } catch (e) {alert(e)};
}

function list_updates(id, forloopcounter){
	elem = $('#id_updates_product_'+id+'_i');
	if (elem.is(':visible')){
		elem.hide();
	}
	else{
		var data =  {product_id:id};
		elem.html('Loading...');
		elem.show()
		elem.load("/userportal/ajax/your-products/updates/", data);
	}
}

function list_updates2(id){
	elem = $('#id_update_list');
	var data =  {product_id:id};
	elem.html('Loading...');
	elem.load("/userportal/ajax/your-products/updates/", data);
}

function show_files_all(){
	elem = $('span.id_file_list')
	$('span.add_sign_all').html('<img src="/site_media/theme_images/minus.gif" style="margin-top:2px;" width="9px" align="left">');		
	elem.show();
	
}

function hide_files_all(){
	elem = $('span.id_file_list')	
	if (elem.is(':visible')) {
		$('span.add_sign_all').html('<img src="/site_media/theme_images/plus.gif" style="margin-top:2px;" width="9px" align="left">');
		elem.hide();		
	}	
	
}

function list_source_files(trial_id){
	elem = $('div#download_source_files_'+trial_id)
	if (elem.is(':visible')) {
		elem.hide();
		$('span#sign_source_files_'+trial_id).html('<img width="9" style="margin-top: 2px;" src="/site_media/theme_images/plus.gif"/>&nbsp;sources<br />');		
	}
	else{
		$('span#sign_source_files_'+trial_id).html('<img width="9" style="margin-top: 2px;" src="/site_media/theme_images/minus.gif"/>&nbsp;sources<br />');
		elem.show();
	}		
}

function list_files(grupa){
	elem = $('span#id_list_files_'+grupa);	
	if (elem.is(':visible')){
		elem.hide();
		$('span#add_sign_'+grupa).html('<img src="/site_media/theme_images/plus.gif" style="margin-top:2px;" width="9px" align="left">');
	}
	else{
		var data =  {grupa:grupa};
		$('span#add_sign_'+grupa).html('<img src="/site_media/theme_images/minus.gif" style="margin-top:2px;" width="9px" align="left">');		
		elem.css({
			'display': 'block'
		});
	}
}

function list_licenses(id, type, ssn){
	elem = $('#id_licenses_'+type+'_'+id+'_ssn'+ssn);
	if (elem.is(':visible')){
		elem.hide();
	}
	else{
		var data =  {product_id:id};
		elem.html('Loading...');
		elem.show()
		elem.load("/userportal/ajax/your-products/licenses/", {ssn:ssn});
	}
}

function show_update_info(slug_name, product_slug_name){
	var reqDone = function(req){   
        document.getElementById('id_update_info2').style.display = 'block';
        document.getElementById('panelLeft_details').style.display = 'none';
    };
	
	if (show_update_clicked == false){
        show_update_clicked = true;
		$('#id_update_info2').load("/userportal/ajax/your-products/" + product_slug_name + "/" + slug_name + "/", {post_it:1}, reqDone);
    } else {
        show_update_clicked = false;
        document.getElementById('panelLeft_details').style.display = 'block';
		document.getElementById('id_update_info2').style.display = 'none';
    };
}

function login(form) { 
    $('#id_panel_register_new_product').load("/userportal/ajax/your-products/product_register/", $(form).formToArray());
    $(form).resetForm();
}

jQuery.fn.extend({ 
        disableSelection : function() { 
                return this.each(function() { 
                        this.onselectstart = function() { return false; }; 
                        this.unselectable = "on"; 
                        jQuery(this).css('user-select', 'none'); 
                        jQuery(this).css('-o-user-select', 'none'); 
                        jQuery(this).css('-moz-user-select', 'none'); 
                        jQuery(this).css('-khtml-user-select', 'none'); 
                        jQuery(this).css('-webkit-user-select', 'none'); 
                }); 
        } 
});
function add_product_on_stock(form) {
  try {	
	if (register_clicked==true){
		$("#add_product_on_stock").load("/userportal/partner-area/warehouse/add-on-stock/", $("#product_registration_form").serializeArray(), function(data){									
			      $('#product_registration_form input#id_key').val('');
			      $('#warehouse_products_list').load("/userportal/partner-area/warehouse/on-stock/");
		});
		
		return false;
	}
  } catch (e) {alert(e)};
}

