﻿$( document ).ready( function( ){
							  
	if(document.location.protocol == "http:"){
		var ssl_or_not_to_ssl = "http://";
	} else {
		var ssl_or_not_to_ssl = "https://";
	}
	
	// get array of article-numbers from product list
	all_rows_in_table = $( '.artiklar:first .odd,.even' );
	second_rows_in_table = $( '.artiklar:eq(1) .odd' );
	//all_rows_in_table.splice(0,2);
	array_length = all_rows_in_table.length;
	second_array_length = second_rows_in_table.length;
		
	var sku = [];
	for( i=0; i < array_length; i++ ){
		sku.push( $( all_rows_in_table[i] ).children(':first').next().text() );
	}
	for( i=0; i < second_array_length; i++ ){
		sku.push( $( second_rows_in_table[i] ).find( 'td' ).find( 'a:first' ).text() );
	}	
	
	xxx = [];
	$( '.artiklar .odd,.even' ).each( function( i ){
	
		if( $( this ).find( 'td:last' ).prev().prev().children( 'span' ).hasClass( 'solar' ) ){
			$( this ).find( 'td:last' ).prev().prev().empty();
			$( this ).find( 'td:last' ).prev().prev().append( "<img class='ajax_loader' src='stock_level_function/ajax_loader.gif' />" );
			xxx[i] = $( this ).find( 'td:last' ).prev().prev();
			
		    $.ajax({
			   type: "GET",
			   url: ssl_or_not_to_ssl+"www.elot.se/stock_level_function/get_stockdata_from_support_server.html?sku="+sku[i],
			   dataType: "html",
			   success: function( response ){
					if( response ){
						$( xxx[i] ).empty();
						var core_response = $( response+', #response' ).html();
						$( xxx[i] ).append( core_response );
					}
			   }
			 });
			 
		}
		
	});

});
