// JavaScript Document

function show_div(vector_divs,id_active_div)
{	
	var array = new Array(id_active_div);	    
	for(var i=0; i< vector_divs.length; i++ )
    {    	
    	if(vector_divs[i] != id_active_div)
    		document.getElementById(vector_divs[i]).style.display = 'none';
    	else if(vector_divs[i] == id_active_div)
    		document.getElementById(array[0]).style.display = 'block';
    }
}

//disable option in a select on IE
jQuery(document).ready(function() {
	  jQuery('option[disabled]').css({'color': '#999999'});
	  jQuery('select').change(function() {
	    if(this.options[this.selectedIndex].disabled) {
	      if(this.options.length == 0) {
	        this.selectedIndex =-1;
	      } else {
	        this.selectedIndex--;
	      }
	      jQuery(this).trigger('change');
	    }
	  });
	  jQuery('select').each(function(it) {
	    if(this.options[this.selectedIndex].disabled)
	      this.onchange();
	  });
	});



function add_to_cart(id)
{
	jQuery('#add_to_cart_output'+id).html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#add_to_cart_output'+id).load(''+base_url+'cart/ajax_add_to_cart/',{ 'id' : id, 'quantity' : jQuery('#buy_quantity'+id).val() },
			function(data){ 
		
				if(data=='') 
				{
					refresh_cart_div(); 
					jQuery('#add_to_cart_output'+id).html('<div class="cart_done">'+cart_successfully_added+'</div>');	
					
					
				}
	});
	
	/* jQuery('#sc_products').html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#sc_products').load(''+base_url+'/cart/ajax_load_shopping_cart_box/',{ },
	function(data){ 
		
				if(data=='') 
				{
					
					document.getElementById('sc_products').innerHTML=data;
					
					
				}
	}); */
	
}

function edit_cart(id, item_id)
{
	jQuery('#add_to_cart_output'+item_id).html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#add_to_cart_output'+item_id).load(''+base_url+'cart/ajax_add_to_cart/',{ 'item_id' : item_id, 'id' : id, 'quantity' : jQuery('#buy_quantity'+item_id).val() },
			function(data){ 
		
				if(data=='') 
				{
					refresh_cart_div(); 
				
					if(jQuery('#buy_quantity'+id).val() == '0')
						jQuery('#add_to_cart_output'+id).html('<div class="done">Scos din cos cu succes</div>');						
					else
						jQuery('#add_to_cart_output'+id).html('<div class="done">'+cart_successfully_added+'</div>');						
			
					
				}
	});
}

function remove_from_cart(id, item_id)
{	
	
	
	jQuery('#add_to_cart_output'+item_id).html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#add_to_cart_output'+item_id).load(''+base_url+'cart/ajax_add_to_cart/',{ 'item_id' : item_id, 'id' : id, 'quantity' : '0' },
			function(data){ if(data=='') refresh_cart_div(); });
}

function refresh_cart_div()
{
	jQuery('#cart_info_div').html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#cart_info_div').load(''+base_url+'cart/ajax_refresh_cart_div');
	
	
	refresh_full_cart_div();
}


function refresh_full_cart_div()
{
	//if(jQuery('#full_cart_info_div').text()!='')
	{
		jQuery('#full_cart_info_div').html('<img src="'+root_url+'images/loading.gif" />');
		jQuery('#full_cart_info_div').load(base_url+'cart/ajax_load_cart');
		
		// alert(base_url+'cart/ajax_load_cart');
	}
}


function empty_cart()
{
	jQuery('#cart_info_div').html('<img src="'+root_url+'images/loading.gif" />');
	jQuery('#cart_info_div').load(''+base_url+'cart/ajax_empty_cart/', false ,
			function(data){ refresh_cart_div(); jQuery('.buy_quantity').val('0') });
}



function submit_add_to_cart(myfield,e,id)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
		add_to_cart(id)
	   return false;
	   }
	else
	   return true;
}


function submit_edit_cart(myfield,e,id,item_id)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
		edit_cart(id,item_id)
	   return false;
	   }
	else
	   return true;
}


function bgcolor(row, event) 
{
	if(event == 2) {
		var object = 'check' + row;
		if(!document.getElementById(object).checked) {
			document.getElementById('row' + row).style.backgroundColor='';
			if(document.getElementById('img' + row)) document.getElementById('img' + row).style.border='1px solid #666666';
		}
	}
	else {
		document.getElementById('row' + row).style.backgroundColor='#EFEFEF';
		if(document.getElementById('img' + row)) document.getElementById('img' + row).style.border='1px solid #CCCCCC';
	}
}


function get_modele_select(id)
{ 
	//jQuery('#model_wrap').html('<img src="'+root_url+'images/loading.gif" />');
	jQuery.post(base_url+'configurator/get_models_select',{ 'id' : id},
		function(data){ 
	
			if(data !='') 
			{
				document.getElementById('model_wrap').innerHTML = data;
				jQuery('#models').sSelect({ddMaxHeight: '300px'});
				
				if(smodel !=null)
				{
					jQuery(function(){
						jQuery('#models').getSetSSValue(smodel);
					});
				}
			}
			else
				jQuery('#model_wrap').html  = "eroare";
	});
	
}

