PageRenderTime 1159ms CodeModel.GetById 372ms app.highlight 540ms RepoModel.GetById 172ms app.codeStats 2ms

/design/theme/base-responsive-v2/ec-store-js.js

https://github.com/EmranAhmed/wp-easycart
JavaScript | 3178 lines | 2306 code | 585 blank | 287 comment | 755 complexity | 45ac621478fa42803509cf497dec41e3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1function ec_product_show_quick_view_link( modelnum ){
   2	jQuery('#ec_product_quick_view_' + modelnum).fadeIn(100);	
   3}
   4
   5function ec_product_hide_quick_view_link( modelnum ){
   6	jQuery('#ec_product_quick_view_' + modelnum).fadeOut(100);	
   7}
   8
   9function ec_product_show_quick_view( modelnum ){
  10	jQuery('#ec_product_quick_view_box_' + modelnum).fadeIn(100);
  11}
  12
  13function ec_product_hide_quick_view( modelnum ){
  14	jQuery('#ec_product_quick_view_box_' + modelnum).fadeOut(100);
  15}
  16
  17function ec_thumb_quick_view_click( modelnum, level, imgnum ){
  18	
  19	if( document.getElementById( 'ec_image_quick_view_' + modelnum + "_" + 1 + "_" + level ) ){
  20		jQuery('#ec_image_quick_view_' + modelnum + "_" + 1 + "_" + level ).hide();
  21	}
  22		
  23		
  24	if( document.getElementById( 'ec_image_quick_view_' + modelnum + "_" + 2 + "_" + level ) )
  25		jQuery('#ec_image_quick_view_' + modelnum + "_" + 2 + "_" + level ).hide();
  26		
  27		
  28	if( document.getElementById( 'ec_image_quick_view_' + modelnum + "_" + 3 + "_" + level ) )
  29		jQuery('#ec_image_quick_view_' + modelnum + "_" + 3 + "_" + level ).hide();
  30		
  31		
  32	if( document.getElementById( 'ec_image_quick_view_' + modelnum + "_" + 4 + "_" + level ) )
  33		jQuery('#ec_image_quick_view_' + modelnum + "_" + 4 + "_" + level ).hide();
  34		
  35		
  36	if( document.getElementById( 'ec_image_quick_view_' + modelnum + "_" + 5 + "_" + level ) )
  37		jQuery('#ec_image_quick_view_' + modelnum + "_" + 5 + "_" + level ).hide();
  38	
  39	jQuery('#ec_image_quick_view_' + modelnum + "_" + imgnum + "_" + level ).show();
  40	
  41}
  42
  43function ec_image_quick_view_click( modelnum, level, imgnum ){
  44	return false;
  45}
  46
  47function product_quantity_change( ){
  48	// Possibly do something on quantity change
  49}
  50
  51function ec_swatch_quick_view_click( modelnum, level, imgnum ){
  52	
  53	if( level == 1 && document.getElementById( 'use_optionitem_images_' + modelnum ).value == 1 ){
  54		ec_image_quick_view_update( modelnum, level, imgnum );
  55	}
  56	
  57	if(document.getElementById( 'ec_swatch_quick_view_' + modelnum + "_" + level + "_" + imgnum ).className != "ec_product_swatch_out_of_stock"){
  58		
  59		var i=0;
  60		while( document.getElementById( 'ec_swatch_quick_view_' + modelnum + "_" + level + "_" + i ) ){
  61					
  62			if( document.getElementById( 'ec_swatch_quick_view_' + modelnum + "_" + level + "_" + i ).className != "ec_product_swatch_out_of_stock"){
  63				document.getElementById( 'ec_swatch_quick_view_' + modelnum + "_" + level + "_" + i ).className = "ec_product_swatch";
  64			}
  65			
  66			i++;
  67		}
  68				
  69		document.getElementById( 'ec_swatch_quick_view_' + modelnum + "_" + level + "_" + imgnum ).className = "ec_product_swatch_selected";	
  70	}
  71	
  72}
  73
  74function ec_image_quick_view_update( modelnum, level, imgnum ){
  75	if(this.document.getElementById( 'ec_swatch_' + modelnum + "_" + level + "_" + imgnum ).className != "ec_product_swatch_out_of_stock"){
  76		
  77		var i=0;
  78		while( this.document.getElementById( 'ec_swatch_' + modelnum + "_" + level + "_" + i ) ){
  79			
  80			if(this.document.getElementById( 'ec_image_quick_view_'  + modelnum + "_" + 1 + "_" + i ))
  81				jQuery('#ec_image_quick_view_'  + modelnum + "_" + 1 + "_" + i ).hide();
  82			
  83			if(this.document.getElementById( 'ec_image_quick_view_'  + modelnum + "_" + 2 + "_" + i ))
  84				jQuery('#ec_image_quick_view_'  + modelnum + "_" + 2 + "_" + i ).hide();
  85			
  86			if(this.document.getElementById( 'ec_image_quick_view_'  + modelnum + "_" + 3 + "_" + i ))
  87				jQuery('#ec_image_quick_view_'  + modelnum + "_" + 3 + "_" + i ).hide();
  88			
  89			if(this.document.getElementById( 'ec_image_quick_view_'  + modelnum + "_" + 4 + "_" + i ))
  90				jQuery('#ec_image_quick_view_'  + modelnum + "_" + 4 + "_" + i ).hide();
  91			
  92			if(this.document.getElementById( 'ec_image_quick_view_'  + modelnum + "_" + 5 + "_" + i ))
  93				jQuery('#ec_image_quick_view_'  + modelnum + "_" + 5 + "_" + i ).hide();
  94			
  95			if(this.document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 1 + "_" + i ))
  96				jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 1 + "_" + i ).hide();
  97			
  98			if(this.document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 2 + "_" + i ))
  99				jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 2 + "_" + i ).hide();
 100			
 101			if(this.document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 3 + "_" + i ))
 102				jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 3 + "_" + i ).hide();
 103			
 104			if(this.document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 4 + "_" + i ))
 105				jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 4 + "_" + i ).hide();
 106			
 107			if(this.document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 5 + "_" + i ))
 108				jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 5 + "_" + i ).hide();
 109			
 110			i++;
 111				
 112		}
 113		
 114		jQuery('#ec_image_quick_view_'  + modelnum + "_" + 1 + "_" + imgnum ).show();
 115			
 116		if( document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 1 + "_" + imgnum ) )
 117			jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 1 + "_" + imgnum ).show();
 118		
 119		if( document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 2 + "_" + imgnum ) )
 120			jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 2 + "_" + imgnum ).show();
 121		
 122		if( document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 3 + "_" + imgnum ) )
 123			jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 3 + "_" + imgnum ).show();
 124		
 125		if( document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 4 + "_" + imgnum ) )
 126			jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 4 + "_" + imgnum ).show();
 127		
 128		if( document.getElementById( 'ec_thumb_quick_view_'  + modelnum + "_" + 5 + "_" + imgnum ) )
 129			jQuery('#ec_thumb_quick_view_'  + modelnum + "_" + 5 + "_" + imgnum ).show();
 130		
 131	}
 132	
 133}
 134
 135function ec_product_image_click( model, level, num ){
 136	return true;
 137}
 138
 139function ec_image_click( model, level, num ){
 140	return true; // just go to the link
 141}
 142
 143function ec_product_details_swap_image( modelnum, level, imgnum ){
 144	
 145	var i=1;
 146	while(	document.getElementById( 'ec_image_quick_view_' + modelnum + '_' + i + '_' + level ) ){
 147		document.getElementById( 'ec_image_quick_view_' + modelnum + '_' + i + '_' + level ).className = 'ec_product_image_inactive';
 148		i++;
 149	}
 150	
 151	document.getElementById( 'ec_image_quick_view_' + modelnum + '_' + imgnum + '_' + level ).className = 'ec_product_image';
 152}
 153
 154var content_width = 1000;
 155
 156jQuery( document ).ready( function( ){
 157	content_width = jQuery( "#ec_product_page" ).width( );
 158	resize_product_layout( );
 159	if( jQuery( '.ec_product_details_page' ).width( ) < 550 ){
 160		jQuery( '.ec_product_details_right_side' ).css( 'width', '100%' );
 161		jQuery( '.ec_product_details_right_side' ).css( 'float', 'left' );
 162		jQuery( '.ec_product_details_right_side' ).css( 'margin-left', '0px' );
 163		jQuery( '.ec_product_details_left_side' ).css( 'width', '100%' );
 164	}
 165});
 166
 167jQuery( window ).resize( function( ){
 168	if( content_width != jQuery( "#ec_product_page" ).width( ) ){
 169		content_width = jQuery( "#ec_product_page" ).width( );
 170		resize_product_layout( );
 171	}
 172});
 173
 174function resize_product_layout( ){
 175	if( document.getElementById( 'ec_product_details_mag_viewer' ) ){
 176		var position_top = jQuery( '.ec_product_details_left_side' ).offset().top;
 177		var margin_bottom = parseInt( jQuery( '.ec_product_details_top_bar' ).css( "margin-bottom" ) );
 178		jQuery( '#ec_product_details_mag_viewer' ).css( "top", position_top + margin_bottom + 2 );	
 179	}
 180	
 181	var product_width = jQuery( "#ec_product_item1" ).width( );
 182	var num_products_per_row = Math.floor( content_width / product_width );
 183	var remaining_space = content_width - ( num_products_per_row * product_width );
 184	var margin_between_product = remaining_space / ( ( ( num_products_per_row - 1 ) * 2 ) );
 185	
 186	if( Number(margin_between_product) < 1 )
 187		margin_between_product = 0;
 188	
 189	
 190	var i = 0;
 191	while( document.getElementById( "ec_product_item" + (i+1) ) ){
 192		if( i%num_products_per_row == 0 ){ //This is left product
 193			document.getElementById( "ec_product_item" + (i+1) ).setAttribute("class", "ec_product left"); 
 194		}else if( i%num_products_per_row == num_products_per_row-1 ){ // This is the right product
 195			document.getElementById( "ec_product_item" + (i+1) ).setAttribute("class", "ec_product right");
 196		}else{ // This is a middle product
 197			document.getElementById( "ec_product_item" + (i+1) ).setAttribute("class", "ec_product middle");
 198		}
 199		i++;
 200	}
 201	
 202	// Change class for left products so margins are correct
 203	jQuery( ".ec_product.left" ).css( "margin-left", "0px" );
 204	jQuery( ".ec_product.left" ).css( "margin-right", margin_between_product + "px" );
 205	
 206	// Change class for middle products so margins are correct
 207	jQuery( ".ec_product.middle" ).css( "margin-left", margin_between_product + "px" );
 208	jQuery( ".ec_product.middle" ).css( "margin-right", margin_between_product + "px" );
 209	
 210	// Change class for right products so margins are correct
 211	jQuery( ".ec_product.right" ).css( "margin-left", "0px" );
 212	jQuery( ".ec_product.right" ).css( "margin-right", "0px" );
 213	
 214}// Base Theme - Product Filter Bar Javascript Document// JavaScript Document// EC Product Page JavaScript Document
 215function change_product_sort(menu_id, menu_name, submenu_id, submenu_name, subsubmenu_id, subsubmenu_name, manufacturer_id, pricepoint_id, currentpage_selected, perpage, URL, divider){
 216	
 217	var url_string = URL + divider + "filternum=" + document.getElementById('sortfield').value;
 218	
 219	if( subsubmenu_id != 0 ){
 220		url_string = url_string + "&subsubmenuid=" + subsubmenu_id;
 221		
 222		if( subsubmenu_name != 0 )
 223			url_string = url_string + "&subsubmenu=" + subsubmenu_name;
 224	
 225	}else if( submenu_id != 0 ){
 226		url_string = url_string + "&submenuid=" + submenu_id;
 227		
 228		if( submenu_name != 0 )
 229			url_string = url_string + "&submenu=" + submenu_name;
 230			
 231	}else if( menu_id != 0 ){
 232		url_string = url_string + "&menuid=" + menu_id;
 233		
 234		if( menu_name != 0 )
 235			url_string = url_string + "&menu=" + menu_name;
 236		
 237	}
 238	
 239	if( manufacturer_id > 0 )
 240		url_string = url_string + "&manufacturer=" + manufacturer_id;
 241		
 242	if( pricepoint_id > 0 )
 243		url_string = url_string + "&pricepoint=" + pricepoint_id;
 244	
 245	if( currentpage_selected )
 246		url_string = url_string + "&pagenum=" + currentpage_selected;
 247	
 248	if( perpage )
 249		url_string = url_string + "&perpage=" + perpage; 
 250	
 251	window.location = url_string;
 252}jQuery(document).ready(
 253	function() {
 254		// In case a theme over-rides images, we need to make sure all inactive images get hidden on load
 255		jQuery( ".ec_product_image_inactive" ).hide( );
 256		
 257		// Initialize the available quick view boxes
 258		jQuery(".ec_product_quick_view_box_holder").each( function( ){
 259			var temp_split = jQuery( this ).attr( "id" ).split( "ec_product_quick_view_box_" );
 260			ec_initialize_options_product( temp_split[1] );
 261		});
 262		
 263		if( document.getElementById( 'ec_product_details_magbox' ) ){
 264			
 265			if( document.getElementById( 'ec_product_details_description_tab' ) ){
 266				if( document.getElementById( 'ec_product_details_specifications' ) )
 267					jQuery( '#ec_product_details_specifications' ).hide( );
 268					
 269				if( document.getElementById( 'ec_product_details_customer_reviews' ) )
 270					jQuery( '#ec_product_details_customer_reviews' ).hide( );
 271			}
 272				
 273			
 274			jQuery('.ec_product_details_images img').hover( 
 275				function (){
 276					if( jQuery(window).width() > 960 ){
 277						if( !jQuery.browser.msie ){
 278							//jQuery('#ec_product_details_magbox').fadeIn(100); 
 279						}
 280						var hasTouch = ("ontouchstart" in window);
 281						if( !hasTouch ){
 282							jQuery('#ec_product_details_mag_viewer').fadeIn(100); 
 283							jQuery("#ec_product_details_mag_viewer").html('<img src="' + this.src + '" class="ec_product_details_mag_viewer_image" style="width:800px; height:800px;" width="800" height="800">');
 284						}
 285					}
 286				}, 
 287				
 288				function (){ 
 289					if( !jQuery.browser.msie ){
 290						//jQuery('#ec_product_details_magbox').fadeOut(100); 
 291					}
 292					jQuery('#ec_product_details_mag_viewer').fadeOut(100); 
 293				} 
 294			);
 295			
 296			var position_top = jQuery( '.ec_product_details_left_side' ).offset().top;
 297			var margin_bottom = parseInt( jQuery( '.ec_product_details_top_bar' ).css( "margin-bottom" ) );
 298			jQuery( '#ec_product_details_mag_viewer' ).css( "top", position_top + margin_bottom + 2 );
 299			
 300			jQuery(document).bind('mousemove', function( e ){
 301					
 302				jQuery('#ec_product_details_magbox').css({ 'left': e.pageX - jQuery(e.target).offset().left - 20, 'top': e.pageY - jQuery(e.target).offset().top + 225});
 303				
 304				// top left position, image should be 0,0
 305				// top right position, image should be at -550, 0
 306				// bottom left position, image should be at 0, -550
 307				// bottom right position, image should be at -550, -550
 308				var mag_box_size = 350;
 309				
 310				var small_img_width = 350;
 311				var small_img_height = 350;
 312				
 313				var large_img_width = 800;
 314				var large_img_height = 800;
 315				
 316				var move_width = large_img_width - mag_box_size;
 317				var move_height = large_img_height - mag_box_size;
 318				
 319				var left_pos = e.pageX - jQuery( e.target ).offset( ).left;
 320				var top_pos = e.pageY - jQuery( e.target).offset( ).top;
 321				
 322				// %accross * amount to move * negative move distance
 323				var left = ( left_pos / small_img_width ) * move_width * -1; 
 324				var top = ( top_pos / small_img_height ) * move_height * -1; 
 325				
 326				jQuery('#ec_product_details_mag_viewer img').css({ 'left': left, 'top': top});
 327			});
 328		}
 329	}
 330);
 331
 332// tab listener
 333function update_content_areas( item_num ){
 334	
 335	if( item_num == 1 ){
 336		jQuery( '#ec_product_details_description' ).show( );
 337		document.getElementById( 'ec_product_details_description_tab' ).className = "ec_product_details_tab_selected";
 338	}else{
 339		jQuery( '#ec_product_details_description' ).hide( );
 340		document.getElementById( 'ec_product_details_description_tab' ).className = "ec_product_details_tab";
 341	}
 342	
 343	if( document.getElementById( 'ec_product_details_specifications' ) ){
 344		if( item_num == 2 ){
 345			jQuery( '#ec_product_details_specifications' ).show( );
 346			document.getElementById( 'ec_product_details_specifications_tab' ).className = "ec_product_details_tab_selected";
 347		}else{
 348			jQuery( '#ec_product_details_specifications' ).hide( );
 349			document.getElementById( 'ec_product_details_specifications_tab' ).className = "ec_product_details_tab";
 350		}
 351	}
 352		
 353	if( document.getElementById( 'ec_product_details_customer_reviews' ) ){
 354		if( item_num == 3 ){
 355			jQuery( '#ec_product_details_customer_reviews' ).show( );
 356			document.getElementById( 'ec_product_details_customer_reviews_tab' ).className = "ec_product_details_tab_selected";
 357		}else{
 358			jQuery( '#ec_product_details_customer_reviews' ).hide( );
 359			document.getElementById( 'ec_product_details_customer_reviews_tab' ).className = "ec_product_details_tab";
 360		}
 361	}
 362	
 363}
 364
 365
 366// Set initial variables
 367var model_number = "";
 368var product_id = "";
 369var current_rating = -1;
 370var selected_option_quantity = 0;
 371
 372/////////////// OPTION FUNCTIONS ///////////////////////////////
 373
 374// Once the page has loaded we can initialize the commonly used variables.
 375function ec_update_product_details_variables( ){
 376	
 377	model_number = document.getElementById( 'model_number' ).value;
 378	product_id = document.getElementById('product_id').value;
 379
 380}
 381
 382// Initialize the product details page for option sets
 383function ec_initialize_options( ){
 384	ec_update_product_details_variables( );
 385	
 386	if( ec_uses_stock_quantities( model_number ) ){
 387		
 388		if( ec_is_swatch_set( 1 ) )									ec_set_swatches_by_stock_quantities( 1 );
 389		else if( ec_is_combo_box( 1 ) )								ec_set_combo_by_stock_quantities( 1 );
 390		
 391		if( ec_is_swatch_set( 1 ) && ec_is_swatch_set( 2 ))			ec_set_swatches_by_stock_quantities( 2 );
 392		else if( ec_is_swatch_set( 1 ) && ec_is_combo_box( 2 ))		ec_set_combo_by_stock_quantities( 2 );
 393		else if( ec_is_swatch_set( 2 ) )							ec_clear_swatch_set( 2 );
 394		else if( ec_is_combo_box( 2 ) )								ec_clear_combo_box( 2 );
 395		
 396		if( ec_is_swatch_set( 3 ) )									ec_clear_swatch_set( 3 );
 397		else if( ec_is_combo_box( 3 ) )								ec_clear_combo_box( 3 );
 398		
 399		if( ec_is_swatch_set( 4 ) )									ec_clear_swatch_set( 4 );
 400		else if( ec_is_combo_box( 4 ) )								ec_clear_combo_box( 4 );
 401		
 402		if( ec_is_swatch_set( 5 ) )									ec_clear_swatch_set( 5 );
 403		else if( ec_is_combo_box( 5 ) )								ec_clear_combo_box( 5 );
 404		
 405	}
 406}
 407
 408function ec_initialize_options_product( modnum ){
 409	
 410	model_number = modnum;
 411	if( ec_uses_stock_quantities( modnum ) ){
 412		
 413		if( ec_is_swatch_set( 1 ) )									ec_set_swatches_by_stock_quantities( 1 );
 414		else if( ec_is_combo_box( 1 ) )								ec_set_combo_by_stock_quantities( 1 );
 415		
 416		if( ec_is_swatch_set( 1 ) && ec_is_swatch_set( 2 ))			ec_set_swatches_by_stock_quantities( 2 );
 417		else if( ec_is_swatch_set( 1 ) && ec_is_combo_box( 2 ))		ec_set_combo_by_stock_quantities( 2 );
 418		else if( ec_is_swatch_set( 2 ) )							ec_clear_swatch_set( 2 );
 419		else if( ec_is_combo_box( 2 ) )								ec_clear_combo_box( 2 );
 420		
 421		if( ec_is_swatch_set( 3 ) )									ec_clear_swatch_set( 3 );
 422		else if( ec_is_combo_box( 3 ) )								ec_clear_combo_box( 3 );
 423		
 424		if( ec_is_swatch_set( 4 ) )									ec_clear_swatch_set( 4 );
 425		else if( ec_is_combo_box( 4 ) )								ec_clear_combo_box( 4 );
 426		
 427		if( ec_is_swatch_set( 5 ) )									ec_clear_swatch_set( 5 );
 428		else if( ec_is_combo_box( 5 ) )								ec_clear_combo_box( 5 );
 429		
 430	}
 431
 432}
 433
 434// When a swatch changes, update the state of the page
 435function ec_swatch_click( modelnum, level, num ){
 436	
 437	model_number = modelnum;
 438	
 439	if( document.getElementById( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + num ) )
 440		element_name = 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + num;
 441	
 442	else
 443		element_name = 'ec_swatch_' + model_number + "_" + level + "_" + num;
 444	
 445	if( document.getElementById( element_name ).className != "ec_product_swatch_out_of_stock" ){
 446		
 447		// Update the selected optionitem_id
 448		document.getElementById( 'ec_option' + level + "_" + model_number ).value = document.getElementById( element_name ).getAttribute( "data-optionitemid" );
 449		// If first level, AND uses option item images, swap out the product image
 450		if( ec_uses_optionitem_images( ) && level == 1 ){
 451			ec_update_product_details_images( num, level );
 452		}
 453		// Update the swatches to reflect the new selection
 454		ec_update_swatch_images( level, num );
 455		
 456		// If we use stock quantities, update the next box to reflect the correct stock count
 457		if( ec_uses_stock_quantities( ) ){
 458			ec_update_next_option_level( level, num );
 459		}//close if uses stock quantities
 460	}//close check for out of stock
 461}//close ec_product_details_swatch_change
 462
 463// Run when the combo box changes
 464function ec_product_details_combo_change( level, modelnum ){
 465	model_number = modelnum;
 466	
 467	// Only update stock stuff if this product uses that option.
 468	if( ec_uses_stock_quantities( model_number ) ){
 469		
 470		// If the user selected a value (not index 0!)
 471		if( document.getElementById( 'ec_option' + level + "_" + model_number ).selectedIndex > 0 ){
 472			
 473			ec_update_next_option_level( level, document.getElementById( 'ec_option' + level + "_" + model_number ).selectedIndex );	
 474		
 475		// Otherwise reset to the previous level or reset all if level 1
 476		}else{
 477			if( level == 1 ){
 478				if( ec_uses_optionitem_images( ) ){
 479					ec_update_product_details_images( level, 0 );
 480				}
 481				ec_update_next_option_level( level, document.getElementById( 'ec_option' + level + "_" + model_number ).selectedIndex - 1 );	
 482			}else{
 483				ec_update_next_option_level( level-1, get_selected_option_index( level - 1) );
 484			}//close if/else for level 1
 485		}//close if/else for 0 index check
 486	}//close check if uses stock quantities
 487
 488	if( ec_uses_optionitem_images( ) && level == 1 && document.getElementById( 'ec_option' + level + "_" + model_number ).selectedIndex > 0 ){
 489		ec_update_product_details_images( document.getElementById( 'ec_option' + level + "_" + model_number ).selectedIndex - 1, level );
 490	}
 491}// close ec_option_combo_change
 492
 493// Swap the product image
 494function ec_thumb_click( modelnum, image_index, image_number ){
 495	
 496	var model_number = modelnum;
 497	var i=1;
 498	
 499	while( document.getElementById( 'ec_image_' + model_number + "_" + i + "_" + image_index ) ){
 500		jQuery('#ec_image_' + model_number + "_" + i + "_" + image_index ).hide();
 501		jQuery('#ec_image_quick_view_' + model_number + "_" + i + "_" + image_index ).hide();
 502		i++;
 503	}
 504	
 505	jQuery('#ec_image_' + model_number + "_" + image_number + "_" + image_index ).show();
 506	jQuery('#ec_image_quick_view_' + model_number + "_" + image_number + "_" + image_index ).show();
 507	
 508}
 509
 510// Update the swatch image classes
 511function ec_update_swatch_images( level, num ){
 512	
 513	// Only change the swatch if someone clicked a swatch that is in stock
 514	if( document.getElementById( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + num ) )
 515		element_name = 'ec_swatch_quick_view_' + model_number + "_" + level + "_";
 516	else
 517		element_name = 'ec_swatch_' + model_number + "_" + level + "_";
 518	
 519	// Only update a swatch image if it isn't out of stock!
 520	if(this.document.getElementById( element_name + num ).className != "ec_product_swatch_out_of_stock" ){
 521		
 522		var i=0;
 523		element_name_temp = element_name + i;
 524		while( document.getElementById( element_name_temp ) ){
 525			
 526			//Don't touch out of stock swatches
 527			if( document.getElementById( 'ec_swatch_' + model_number + "_" + level + "_" + i ) && 
 528				document.getElementById( 'ec_swatch_' + model_number + "_" + level + "_" + i ).className != "ec_product_swatch_out_of_stock" ){
 529				
 530				ec_set_element_class_name( 'ec_swatch_' + model_number + "_" + level + "_" + i, "ec_product_swatch" );
 531			}
 532			
 533			if( document.getElementById( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + i ) && 
 534				document.getElementById( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + i ).className != "ec_product_swatch_out_of_stock" ){ 
 535				
 536				ec_set_element_class_name( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + i, "ec_product_swatch" );
 537				
 538			}
 539			i++;
 540			element_name_temp = element_name + i;	
 541		}
 542		
 543		ec_set_element_class_name( 'ec_swatch_' + model_number + "_" + level + "_" + num, "ec_product_swatch_selected" );
 544		ec_set_element_class_name( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + num, "ec_product_swatch_selected" );
 545		
 546	}
 547}
 548
 549// Update the next option level
 550function ec_update_next_option_level( level, num ){
 551	
 552	if( ec_uses_stock_quantities( model_number ) ){
 553		
 554		// Check for a resetting combo box, manage the quantity values different for this.
 555		if( ec_is_combo_box( level ) && num == 0 ){
 556			// Reset this combo box, lets revert the quantities
 557			selected_option_quantity = get_stock_amount( level-1, get_selected_option_index( level-1 ) );
 558			
 559			if( document.getElementById( 'in_stock_amount_text_' + model_number ) )
 560				document.getElementById( 'in_stock_amount_text_' + model_number ).innerHTML = selected_option_quantity;
 561			else if( document.getElementById( 'in_stock_amount_text' ) )
 562				document.getElementById( 'in_stock_amount_text' ).innerHTML = selected_option_quantity;
 563			
 564			if( document.getElementById( 'quantity_' + model_number ) )
 565				document.getElementById( 'quantity_' + model_number ).value = selected_option_quantity;
 566		}else{
 567			// We are moving forward, update quantities and options
 568			selected_option_quantity = get_stock_amount( level, num );
 569			
 570			if( document.getElementById( 'in_stock_amount_text_' + model_number ) )
 571				document.getElementById( 'in_stock_amount_text_' + model_number ).innerHTML = selected_option_quantity;
 572			else if( document.getElementById( 'in_stock_amount_text' ) )
 573				document.getElementById( 'in_stock_amount_text' ).innerHTML = selected_option_quantity;
 574
 575			if( document.getElementById( 'quantity_' + model_number ) )
 576				document.getElementById( 'quantity_' + model_number ).value = selected_option_quantity;
 577		}
 578	
 579		if( Number(level) < 5 ){
 580			level = Number(level)+1;
 581			if( ec_is_swatch_set( level ) )										ec_set_swatches_by_stock_quantities( level );
 582			else if( ec_is_combo_box( level ) )									ec_set_combo_by_stock_quantities( level );
 583		}
 584		
 585		while( level < 5 ){
 586			
 587			level++;
 588			
 589			if( ec_is_swatch_set( level ) )										ec_clear_swatch_set( level );
 590			else if( ec_is_combo_box( level ) )									ec_clear_combo_box( level );
 591		}
 592	}
 593}
 594
 595// Update swatches in the NEXT level based on quantities
 596function ec_set_swatches_by_stock_quantities( level ){
 597	//If this level has swatches, update the swatches to match stock quantities
 598	if( document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_0' ) ){
 599		
 600		var i=0;
 601		while( document.getElementById('ec_swatch_' + model_number + '_' + level + '_' + i ) ){
 602			if( level != 1 )
 603				document.getElementById('ec_option' + level + "_" + model_number).value = 0;
 604			
 605			if( level == 1 && i == document.getElementById( 'initial_swatch_selected_' + model_number ).value ){	
 606				if( document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i  ) )
 607					document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch_selected";
 608				
 609				selected_option_quantity = get_stock_amount(level, i);
 610				
 611				if( document.getElementById('in_stock_amount_text') )
 612					document.getElementById('in_stock_amount_text').innerHTML = selected_option_quantity;
 613			}else if( ec_is_in_stock( level, i ) ){
 614				if( document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i ) )
 615					document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch";
 616				
 617			}else{
 618				if( document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i ) )
 619					document.getElementById( 'ec_swatch_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch_out_of_stock";
 620				
 621			}
 622			
 623			i++;
 624		}
 625		
 626	}else if( document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_0' ) ){
 627		
 628		var i=0;
 629		while( document.getElementById('ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ) ){
 630			
 631			if( level == 1 && i == document.getElementById( 'initial_swatch_selected_' + model_number ).value ){	
 632				if( document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ) )
 633					document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch_selected";
 634				
 635				selected_option_quantity = get_stock_amount(level, i);
 636				
 637				if( document.getElementById('in_stock_amount_text') )
 638					document.getElementById('in_stock_amount_text').innerHTML = selected_option_quantity;
 639			}else if( ec_is_in_stock( level, i ) ){
 640				if( document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ) )
 641					document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch";
 642			}else{
 643				if( document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ) )
 644					document.getElementById( 'ec_swatch_quick_view_' + model_number + '_' + level + '_' + i ).className = "ec_product_swatch_out_of_stock";
 645			}
 646			
 647			i++;
 648		}
 649		
 650	}
 651	
 652}
 653
 654// Update combo in the NEXT level based on quantities
 655function ec_set_combo_by_stock_quantities( level ){
 656	//If this level has swatches, update the swatches to match stock quantities
 657	if(level > 1 && get_selected_option_index(level-1) == -1){
 658		document.getElementById('ec_option' + level + "_" + model_number).disabled = "disabled";
 659		document.getElementById('ec_option' + level + "_" + model_number).selectedIndex = 0;
 660	}else{
 661		document.getElementById('ec_option' + level + "_" + model_number).disabled = "";
 662		document.getElementById('ec_option' + level + "_" + model_number).selectedIndex = 0;
 663		//Hide or show items
 664		for(var i=1; i<document.getElementById('ec_option'+level+"_"+model_number).options.length; i++){
 665			if(get_stock_amount(level, i) > 0){
 666				jQuery("#ec_option"+level+"_"+model_number+" option[value=" + document.getElementById('ec_option'+level+"_"+model_number).options[i].value + "]").show();
 667			}else{
 668				jQuery("#ec_option"+level+"_"+model_number+" option[value=" + document.getElementById('ec_option'+level+"_"+model_number).options[i].value + "]").hide();
 669			}
 670		}
 671	}
 672}
 673
 674// Clear a swatch set
 675function ec_clear_swatch_set( set_num ){
 676	
 677	if(document.getElementById( 'ec_swatch_' + model_number + '_' + set_num + '_0' ) ){
 678		var i=0;
 679		while( document.getElementById('ec_swatch_' + model_number + '_' + set_num + '_' + i ) ){
 680			document.getElementById( 'ec_swatch_' + model_number + '_' + set_num + '_' + i ).className = "ec_product_swatch_out_of_stock";
 681			document.getElementById( 'ec_swatch_quick_view' + model_number + '_' + set_num + '_' + i ).className = "ec_product_swatch_out_of_stock";
 682			i++;
 683		}
 684		document.getElementById( 'ec_option' + set_num + "_" + model_number ).value = 0;
 685	}	
 686}
 687
 688// Get an option's specific stock quantity
 689function get_stock_amount( level, num ){
 690	
 691	if( num == -1 )
 692	num = 0;
 693	// Get the quantity string off of the element
 694	var quantity_string = "";
 695	if( ec_is_swatch_set( level ) && document.getElementById( 'ec_swatch_' + model_number + "_" + level + "_" + num ) )		
 696										quantity_string = document.getElementById( 'ec_swatch_' + model_number + "_" + level + "_" + num ).getAttribute("data-quantitystring");
 697	
 698	else if( ec_is_swatch_set( level ) && document.getElementById( 'ec_swatch_quick_view_' + model_number + "_" + level + "_" + num ) )		
 699