$('document').ready(function() {
	if ($('#cart_content').length==0 && $('#Cart').length==0)
	{
		if ($('.content_title').length>0)
		{
			$('<form onsubmit="javascript:return false;" style="display:none;" name="Cart" id="Cart" action="" method="post" enctype="application/x-www-form-urlencoded"><div class="page_item" style="text-align:center;" id="cart_content">Se incarca lista....</div></form>').insertAfter('.content_title');
		}else if ($('h1').length >0)
		{
			$('<form onsubmit="javascript:return false;" style="display:none;" name="Cart" id="Cart" action="" method="post" enctype="application/x-www-form-urlencoded"><div class="page_item" style="text-align:center;" id="cart_content">Se incarca lista....</div></form>').insertAfter('h1');
		}else if ($('#pageheader').add('#pageheaderadmin').length>0)
		{
			$('<form onsubmit="javascript:return false;" style="display:none;" name="Cart" id="Cart" action="" method="post" enctype="application/x-www-form-urlencoded"><div class="page_item" style="text-align:center;" id="cart_content">Se incarca lista....</div></form>').insertAfter($('#pageheader').add('#pageheaderadmin'));
		}
		real_send_cart_update();
	}
});
function cart_plus(id)
{
	var nr = parseInt($('#cart_nr_'+id).val());
	if (!isNaN(nr)) nr++; else nr=1;
	$('#cart_nr_'+id).val(nr);
	$('#cart_'+id+'_text_q').html(nr);
	$('#cart_'+id+'_text_total').html('-----');
	$('#cart_total_price').html('-----');
	$('#cart_buttons').hide();
	$('#show_list_button').hide();
	send_cart_update();
}
function cart_minus(id)
{
	var nr = parseInt($('#cart_nr_'+id).val());
	if (!isNaN(nr)&&nr>0) nr--; else nr=0;
	$('#cart_nr_'+id).val(nr);
	$('#cart_'+id+'_text_q').html(nr+'');
	$('#cart_'+id+'_text_total').html('-----');
	$('#cart_total_price').html('-----');
	$('#cart_buttons').hide();
	$('#show_list_button').hide();
	send_cart_update();
}
function cart_del(id)
{
	//var nr = parseInt($('#cart_nr_'+id).val());
	//if (!isNaN(nr)&&nr>0) nr--; else nr=0;
	nr =0;
	$('#cart_nr_'+id).val(nr);
	$('#cart_'+id+'_text_q').html(nr+'');
	$('#cart_'+id+'_text_total').html('-----');
	$('#cart_total_price').html('-----');
	$('#cart_buttons').hide();
	$('#show_list_button').hide();
	send_cart_update();
}

var cart_update_timer = 0;
var cart_updating = 0;
var need_reupdate = false;
function send_cart_update()
{
	clearTimeout(cart_update_timer);
	cart_update_timer = setTimeout("real_send_cart_update();",1000);
}
function real_send_cart_update()
{
	if (cart_updating)
	{
		need_reupdate = true;
		return;
	}
	$('.cart_plus_minus').hide();
	$('#cart_buttons').hide();
	$('#show_list_button').hide();
	cart_updating = true;
	ajax_json(lang_url+'ajax/order',$('#Cart').serialize()+'&auto=1',true);
}
function end_cart_update()
{
	$('#cart_buttons').show();
	$('#show_list_button').show();
	if ($('#cart_page').length>0 || $('#Checkout_confirm').length>0 || $('#Checkout').length>0) 
	{
		$('#show_list_button').hide();
		$('#Cart').show();
	}else if ($('#cart_content').html().indexOf('images/delete_page.png')>-1) $('#Cart').show();
	cart_updating = false;
	if (need_reupdate)
	{
		real_send_cart_update();
	}
}
function cart_submit()
{
	$('#Cart').removeAttr('onsubmit');
	$('#Checkout').click();
	//$('#OrderP').submit();
//	ajax_json(base_url+'ajax/order',$('#Cart').serialize(),true);
	return true;
}
function cart_ajax()
{
	ajax_json(lang_url+'ajax/order',$('#Cart').serialize(),true);
	return false;
}
var req_started = 0;
var req_errors = [0,0,0,0,0,0,0,0,0,0,0,0];
function ajax_json(url,data,retry_on_error,retry_count)
{
	if (typeof retry_on_error == "undefined")
	{
		retry_on_error = false;
	}
	if (retry_on_error == true)
	{
		req_started ++;
		var timeout = 500;
		if (typeof retry_count == "undefined") retry_count = 0;
		timeout += Math.pow(2.2,retry_count);
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			timeout: timeout,
			async: true,
			dataType: "json",
			success: function(data){
				process(data);
			},
			error: function(obj,err,e){
				req_errors[retry_count]++;
				if (retry_count<10)
				{
					ajax_json(url,data,retry_on_error,retry_count+1)
				}
				else 
					alert('A aparut o eroare in timpul ultimei cereri. Cererea a fost incercata de 10 ori.');
			}
		});
	}else
	{
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			async: true,
			dataType: "json",
			success: function(data){
				process(data);
			},
			error: function(obj,err,e){
				alert('A aparut o eroare in timpul ultimei cereri. Te rog sa incerci mai tarziu.');
			}
		});
	}
}
function process(data)
{
	if (data.error)
	{
		alert(data.error_msg);
	}else if (typeof data.action != "undefined")
	{
		eval(data.action);
	}
}

function menu_toggle(arrow,id)
{
	if ($(arrow).hasClass('nav_arrow_expand'))
	{
		$(arrow).removeClass('nav_arrow_expand').addClass('nav_arrow_collapsed');
		$('.submenu_'+id).hide(500);
	}else
	{
		$(arrow).addClass('nav_arrow_expand').removeClass('nav_arrow_collapsed');
		$('.submenu_'+id).show(500);
	}
}
function add_to_list(product_id)
{
	var cnt = $('#nr_'+product_id).val();
	data = {product_id:product_id,product_count:cnt};
	var backup = $('#col_add_'+product_id).html();
	$('#col_add_'+product_id).html('<div class="loader"></div>');
	$.ajax({
		type: "POST",
		url: lang_url+'ajax/add_to_list/',
		data: data,
		async: true,
		dataType: "json",
		success: function(data){
			$('#col_add_'+product_id).html(backup);
			if (data.error)
			{
				//var tmp_height_buttons = $('.product_buttons').css('height');
				//$('.rating_working').css('display','none');
				//$('.rating_container').css('display','block');
				alert(data.error_msg);
				//setTimeout("$('.rating_container').css('height','30px');",100);
				//$('.product_buttons').css('height',tmp_height_buttons);
			}else if (typeof data.action != "undefined")
			{
				//var tmp_height_buttons = $('.product_buttons').css('height');
				eval(data.action);
				//$('.rating_working').css('display','none');
				//$('.rating_container').css('display','block');
				//setTimeout("$('.rating_container').css('height','30px');",100);
				//$('.product_buttons').css('height',tmp_height_buttons);
			}
		},
		error: function(obj,err,e){
			$('#col_add_'+product_id).html(backup);
			//var tmp_height_buttons = $('.product_buttons').css('height');
			//$('.rating_working').css('display','none');
			//$('.rating_container').css('display','block');
			alert('An error occured during request. Please try again.');
			//setTimeout("$('.rating_container').css('height','30px');",100);
			//$('.product_buttons').css('height',tmp_height_buttons);
		}
	});
}
function dreambox_more_emails()
{
	x = $('.email_to_duplicate').eq($('.email_to_duplicate').length-1).clone();
	$('.email_to_duplicate').eq($('.email_to_duplicate').length-1).after(x);
	$('.email_to_duplicate').eq($('.email_to_duplicate').length-1).children('input').val('');
}
function dreambox_hide_prices()
{
	if ($('#hide_prices').attr('checked')==true)
	{
		$('.cart_product_price').hide();
		$('.cart_total_price').hide();
	}
	else
	{
		$('.cart_product_price').show();
		$('.cart_total_price').show();
	}
}
if (typeof console == "undefined")
{
console = {};
console.log = function() {};
}
var current_rating_backup = 0;
function rating_init()
{
	current_rating_backup = $('.rating_current').css('width');
	if ($('.rating_main').length>0)
	{
		$('.rating_cell').bind('mouseenter',function(){
			var cell_id = $(this).attr('id').substring(5);
			$('.rating_over').css('width',(30*cell_id)+'px');
			$('.rating_current').css('width','0px')
		}).bind('mouseleave',function(){
			var cell_id = $(this).attr('id').substring(5);
			$('.rating_over').css('width','0px');
			$('.rating_current').css('width',current_rating_backup)
		}).bind('click',function(){
			var cell_id = $(this).attr('id').substring(5);
			rate_product($('.rating_container').attr('id').substring(7),cell_id);
		});
		
	}
}
function rate_product(product_id,rating)
{
	$('.rating_container').hide();
	$('.rating_working').show();
	data = {rating:rating,product_id:product_id};
	$.ajax({
		type: "POST",
		url: lang_url+'ajax/rate_product/',
		data: data,
		async: true,
		dataType: "json",
		success: function(data){
			if (data.error)
			{
				var tmp_height_buttons = $('.product_buttons').css('height');
				$('.rating_working').css('display','none');
				$('.rating_container').css('display','block');
				alert(data.error_msg);
				setTimeout("$('.rating_container').css('height','30px');",100);
				$('.product_buttons').css('height',tmp_height_buttons);
			}else if (typeof data.action != "undefined")
			{
				var tmp_height_buttons = $('.product_buttons').css('height');
				eval(data.action);
				$('.rating_working').css('display','none');
				$('.rating_container').css('display','block');
				setTimeout("$('.rating_container').css('height','30px');",100);
				$('.product_buttons').css('height',tmp_height_buttons);
			}
		},
		error: function(obj,err,e){
			var tmp_height_buttons = $('.product_buttons').css('height');
			$('.rating_working').css('display','none');
			$('.rating_container').css('display','block');
			alert('An error occured during request. Please try again.');
			setTimeout("$('.rating_container').css('height','30px');",100);
			$('.product_buttons').css('height',tmp_height_buttons);
		}
	});
}
function add_to_cart(type,id)
{
	$('#AddToCart').attr('action',lang_url+'/'+type+'/add/'+id);
	$('#AddToCart').submit();
}
var scroller_direction = 1; //1=up,-1=down
var scroller_saved_direction = 1;
var scroller_step = 4;//px at a time
var scroller_period = 20;// ms between scrolls
var scroller_wait = 5000;//ms wait between sec
var scroller_steps = Math.round(160/scroller_step);
scroller_step *= 174/400;
var scroller_start_pos = -160;
var scroller_end_pos = 0;
var scroller_times_scrolled = 0;
var scroller_auto = true;
var scroller_marquee = false;
var scroller_marquee_obj = null;
var scroller_top = 0;
var scroller_busy = false;
var scroller_manual = false;
var scroller_timer = null;

/*function asd() {console.log($('#scroller_scroll').css('top')); setTimeout("asd();",400);} asd();*/

function scroller_manual_scroll(direction)
{
	if (scroller_busy || scroller_manual) return;
	scroller_manual = true;
	if (scroller_marquee) direction = -1 * direction;
	scroller_saved_direction = scroller_direction;
	scroller_direction = direction;
	scroller_manual = true;

	var scroller_items = $('.scroller_product').length;
	if ((direction == -1 && scroller_marquee == false || direction == 1 && scroller_marquee==true))
	{
		clearTimeout(scroller_timer);
		scroller_run_down(true);
	}else
	{
		clearTimeout(scroller_timer);
		scroller_run(true);
	}
}
function scroller_init()
{
	if ($('#scroller').length == 0) return;
	if (scroller_times_scrolled == 0)
	{//only first time!!!
		if ($.browser.msie)
		{
			if ($.browser.version<8.0)
			{
				scroller_direction = -1 * scroller_direction;
				scroller_saved_direction = scroller_direction;
				scroller_marquee = true;
				var marquee = document.createElement("marquee")
				$(marquee).attr('id','marquee');
				$(marquee).attr('direction','up');
				$(marquee).attr('scrolldelay','1');
				$(marquee).attr('scrollamount','0');
				$(marquee).attr('behavior','scroll');
				$(marquee).attr('width','170px');
				$(marquee).attr('height','478px');
				$(marquee).css('width','170px');
				$(marquee).css('height','478px');
				$("#scroller_scroll").wrapInner(marquee);
				scroller_marquee_obj = document.getElementById('marquee');
				scroller_marquee_obj.stop();
				scroller_marquee_obj.scrollTop=478;
			}
		}
	}
	scroller_start_pos = 160*scroller_direction
	$('.scroller_product').bind('click',function(){
		parent.location=$(this).children('.scroller_url').html();
	}).bind('mouseenter',function(){
		$(this).addClass('scroller_product_over');
		$(this).removeClass('scroller_product');
	}).bind('mouseleave',function(){
		$(this).addClass('scroller_product');
		$(this).removeClass('scroller_product_over');
	});
	$('#scroller').bind('mouseenter',function(){
		scroller_auto = false;
	}).bind('mouseleave',function(){
		scroller_auto = true;
	});
	$('#scroller_up_arrow').bind('mouseenter',function(){ $(this).addClass('over'); }).bind('mouseleave',function(){$(this).removeClass('over');});
	$('#scroller_down_arrow').bind('mouseenter',function(){ $(this).addClass('over'); }).bind('mouseleave',function(){$(this).removeClass('over');});
	scroller_timer = setTimeout("scroller_run(false);",scroller_wait);
}
function scroller_run_down(auto)
{
	if (scroller_busy) return;
	var scroller_items = $('.scroller_product').length;
	if (scroller_items<4) return;
	if (scroller_times_scrolled==0)
	{
		scroller_times_scrolled = scroller_items-3;
		scroller_start_pos = 160*scroller_direction*(scroller_times_scrolled);
		scroller_top = 160*scroller_direction*(scroller_times_scrolled);
		//console.log('manual: '+scroller_start_pos+' - '+scroller_top+' - '+(-160*scroller_direction*scroller_times_scrolled));
		if (scroller_marquee)
		{
			//console.log('marquee reset to 478');
			scroller_marquee_obj.scrollTop=478+160*scroller_direction*scroller_times_scrolled;
		}else
			$('#scroller_scroll').css('top',160*scroller_direction*scroller_times_scrolled)
			scroller_times_scrolled = scroller_items-3;
	}
	scroller_start_pos=160*scroller_direction*scroller_times_scrolled;//160*scroller_direction;// = scroller_end_pos;
	scroller_end_pos = scroller_start_pos+(-1)*160*scroller_direction;
	//console.log('scroller_initialized 5down '+scroller_start_pos+' -> '+scroller_end_pos);

	if (scroller_manual)
	{
		scroller_times_scrolled--; scroller_scroll(scroller_steps);
	}else if (scroller_auto)
	{
		scroller_times_scrolled--; scroller_scroll(scroller_steps);
	}else
	{
		scroller_timer = setTimeout("scroller_run(false);",500);
		return;
	}
}

function scroller_run(auto)
{
	if (scroller_busy) return;
	var scroller_items = $('.scroller_product').length;
	if (scroller_items<4) return;
	if (scroller_times_scrolled>=scroller_items-3)
	{
		if (scroller_marquee)
		{
			//console.log('marquee reset to 478');
			scroller_marquee_obj.scrollTop=478;
		}else
			$('#scroller_scroll').css('top',0)
		scroller_times_scrolled = 0;
		scroller_start_pos = 160*scroller_direction;
		scroller_top = 0;
	}
	scroller_start_pos=-160*scroller_direction*scroller_times_scrolled;//160*scroller_direction;// = scroller_end_pos;
	scroller_end_pos = scroller_start_pos-160*scroller_direction;

	if (scroller_manual)
	{
		scroller_times_scrolled++; scroller_scroll(scroller_steps);
	}else if (scroller_auto)
	{
		scroller_times_scrolled++; scroller_scroll(scroller_steps);
	}else
	{
		scroller_timer = setTimeout("scroller_run(false);",500);
		return;
	}
}
function scroller_function(step)
{
	//scroller_steps......step
	//2 ....... x
	step = /*(scroller_direction==1?2:0)*/2+(2.0*step)/scroller_steps;
	var result = step*step-4*step;
//	console.log('x='+step+', result='+result);
	return result;	
}
function scroller_scroll(times)
{
	scroller_busy = true;
	scroller_top = scroller_top + (scroller_direction*scroller_step*scroller_function(scroller_steps-times+1));
	//var new_pos = parseInt($('#scroller_scroll').css('top'))+(scroller_direction*scroller_step*scroller_function(scroller_steps-times+1));
	if (scroller_direction==1 && scroller_top<scroller_end_pos)
		scroller_top = scroller_end_pos;
	else if (scroller_direction==-1 && scroller_top>scroller_end_pos)
		scroller_top = scroller_end_pos;
	//console.log('scroller_scroll '+times+' new_pos='+scroller_top+' '+scroller_start_pos+' -> '+scroller_end_pos);
	if (scroller_marquee)
	{
		scroller_marquee_obj.scrollTop=scroller_top+478;
	}
	else
		$('#scroller_scroll').css('top',scroller_top+'px');
	if (times>1)
	{
		setTimeout("scroller_scroll("+(times-1)+");",scroller_period);
	}
	else
	{
		scroller_manual = false;
		scroller_busy = false;
		scroller_direction = scroller_saved_direction;
		scroller_timer = setTimeout("scroller_run(false);",scroller_wait);
	}
}
function menu_init()
{
	//first line
	$('.menu_ul > li').bind('mouseenter',function(){
		setTimeout("menu_select('"+menu_get_id($(this))+"');",10);
	}).bind('mouseleave',function(){
		setTimeout("menu_deselect('"+menu_get_id($(this))+"');",10);
	}).bind('click',function(e){
		if (e.target.tagName!='A')
		{
			parent.location = $('#menu_li_2_'+menu_get_id(e.target)).children('a').attr('href');
		}
	});
	//border under first line
	if ($('.menu_selected').length>0)
	{
		var id = menu_get_id($('.menu_selected'));
		var offset_1 = $('#menu_li_1_'+id).offset();
		var offset_2 = $('#menu_li_1_'+id).parent().offset();
		var width_1 = offset_1.left-offset_2.left+25+1;
		var width_2 = $('#menu_li_2_'+id).width();
		//set width
		$('#under_menu_no_border').css('width','0px');//reset width to not break on multiple lines
		$('#under_menu_border_1').css('width',width_1+'px');
		$('#under_menu_no_border').css('width',width_2+'px');
		$('#under_menu_border_2').css('width',(980-width_1-width_2)+'px');
	}else
	{
		$('#under_menu_border_1').css('width','0px');
		$('#under_menu_no_border').css('width','0px');
		$('#under_menu_border_2').css('width','980px');
	}
	//2nd line
	$('.menu2_ul > li').bind('mouseenter',function(){
		setTimeout("menu2_select('"+menu2_get_id($(this))+"');",10);
	}).bind('mouseleave',function(){
		setTimeout("menu2_deselect('"+menu2_get_id($(this))+"');",10);
	});
	//pop menu
	$('.menu3_ul > li').bind('mouseenter',function(){
		setTimeout("menu3_select('"+menu3_get_id($(this))+"');",10);
	}).bind('mouseleave',function(){
		setTimeout("menu3_deselect('"+menu3_get_id($(this))+"');",10);
	}).bind('click',function(e){
		if (e.target.tagName!='A')
		{
			parent.location = $(this).children('a').attr('href');
		}
	});
}
function browse_init()
{
	$('.browse_product').bind('click',function(){
		parent.location=$(this).children('.browse_url').html();
	}).bind('mouseenter',function(){
		$(this).addClass('browse_product_over');
		$(this).removeClass('browse_product');
	}).bind('mouseleave',function(){
		$(this).addClass('browse_product');
		$(this).removeClass('browse_product_over');
	});
}
$(document).ready(function() {
	menu_init();
	scroller_init();
	rating_init();
	browse_init();
	if ($.browser.msie && $.browser.version <=6.0)
	{
		$('#dreambox_nori').css('position','absolute');
		$('#dreambox_nori').css('left',(parseInt($('#right_content').offset().left)-19));
	}
});

function menu_select(id)
{
	if ($('#menu_li_1_'+id).hasClass('menu_border_right'))
	{
		$('#menu_li_1_'+id).addClass('menu_border_right_over');
		$('#menu_li_1_'+id).removeClass('menu_border_right');
	}
	if ($('#menu_li_2_'+id).hasClass('menu'))
	{
		$('#menu_li_2_'+id).addClass('menu_over');
		$('#menu_li_2_'+id).removeClass('menu');
	}
	if ($('#menu_li_3_'+id).hasClass('menu_border_right'))
	{
		$('#menu_li_3_'+id).addClass('menu_border_right_over');
		$('#menu_li_3_'+id).removeClass('menu_border_right');
	}
}
function menu2_select(id)
{
	if ($('#menu2_li_'+id).hasClass('menu2'))
	{
		$('#menu2_li_'+id).addClass('menu2_over');
		$('#menu2_li_'+id).removeClass('menu2');
	}
	$('#menu2_li_'+id+' > .menu3_ul').css('display','block');
	$('#menu2_li_'+id+' > .menu3_ul').css('left',$('#menu2_li_'+id).offset().left+($.browser.mozilla?1:0));
	$('#menu2_li_'+id+' > .menu3_ul').css('top',$('#menu2_li_'+id).offset().top+30);
}
function menu3_select(id)
{
	if ($('#menu3_li_'+id).hasClass('menu3'))
	{
		$('#menu3_li_'+id).addClass('menu3_over');
		$('#menu3_li_'+id).removeClass('menu3');
	}
}
function menu_deselect(id)
{
	if ($('#menu_li_1_'+id).hasClass('menu_border_right_over'))
	{
		$('#menu_li_1_'+id).addClass('menu_border_right');
		$('#menu_li_1_'+id).removeClass('menu_border_right_over');
	}
	if ($('#menu_li_2_'+id).hasClass('menu_over'))
	{
		$('#menu_li_2_'+id).addClass('menu');
		$('#menu_li_2_'+id).removeClass('menu_over');
	}
	if ($('#menu_li_3_'+id).hasClass('menu_border_right_over'))
	{
		$('#menu_li_3_'+id).addClass('menu_border_right');
		$('#menu_li_3_'+id).removeClass('menu_border_right_over');
	}
}
function menu2_deselect(id)
{
	if ($('#menu2_li_'+id).hasClass('menu2_over'))
	{
		$('#menu2_li_'+id).addClass('menu2');
		$('#menu2_li_'+id).removeClass('menu2_over');
	}
	$('#menu2_li_'+id+' > .menu3_ul').css('display','none');
}

function menu3_deselect(id)
{
	if ($('#menu3_li_'+id).hasClass('menu3_over'))
	{
		$('#menu3_li_'+id).addClass('menu3');
		$('#menu3_li_'+id).removeClass('menu3_over');
	}
}
function menu_get_id(el)
{
	var id = $(el).attr('id').substring(10);
	if (id.length==0) return '0';
	return id;
}
function menu2_get_id(el)
{
	var id = $(el).attr('id').substring(9);
	if (id.length==0) return '0';
	return id;
}
function menu3_get_id(el)
{
	var id = $(el).attr('id').substring(9);
	if (id.length==0) return '0';
	return id;
}
function fix_header_position()
{
	if ($.browser.msie == true)
	{
		if ($.browser.version <=6.0)
			$('#dreambox_nori').css('left',(parseInt($('#right_content').offset().left)-19));
		if ($('body').width() % 2 == 1 && $('body').width()>1280)
			$('#main').css('margin-left','2px');
		else
			$('#main').css('margin-left','1px');
	}
	if ($.browser.mozilla == true)
	{
		if ($('body').width() % 2 == 0 || $('body').width()<980)
			$('#main').css('margin-left','1px');
		else
			$('#main').css('margin-left','0px');
	}else if (navigator.appVersion.indexOf('Chrome')!= -1)
	{
		if ($('body').width() % 2 == 0 || $('body').width()>1280)		
			$('#main').css('margin-left','1px');
		else
			$('#main').css('margin-left','2px');
	}
}
function category_click(id){
	var t = $('#subcat_'+id).css("display");
	//$('#arrow_'+id).removeClass();
	$('#main_cat_'+id).removeClass();
	if (t=='none')
		$('#main_cat_'+id).addClass('cat_open');
	else
		$('#main_cat_'+id).addClass('cat');
//		$('#arrow_'+id).addClass('arrow_down');
//	}else{
//		$('#arrow_'+id).addClass('arrow_right');
//	}
	$('#subcat_'+id).toggle(1000);
}
function go_to_page(nr) {
	$('input#page').val(nr);
	setTimeout("$('form#filterfrm').submit()",100);
}
var checkout_step = 2;
var what = 1;//What would you like to do? (1-online,2-offline,3-quote)
var new_sa = 0;//new shipping address
var new_ba = 0;//new billing address
function checkout_first_option()
{
 what = 1;
}
function checkout_so()
{
	var so = 0;
	var po = 0;
	$('input[name="shipping_options"]').each(function(){
		if ($(this).attr('checked')==true) so = $(this).attr('id').substring(17);
	});
	$('input[name="payment_options"]').each(function(){
		if ($(this).attr('checked')==true) po = $(this).attr('id').substring(16);
	});
	if (so==17)
	{
		$('#po_2').hide();
		if (po==2) $('#payment_options_1').attr('checked','checked');
	}else
	{
		$('#po_2').show();
	}
}
function checkout_bo()
{
	
}
function checkout_next()
{
	$('form#Checkout').submit();
	return true;

	/*
	checkout_first_option();
	if (checkout_step==2 && new_sa==true){//new shipping address
		if ($('#s_street_address').val().length<2){
			alert('Please fill in the street address.');
			$('#s_street_address').focus(); return;
		}
		if ($('#s_zip_code').val().length<2){
			alert('Please fill in the zip code.');
			$('#s_zip_code').focus(); return;
		}
		if ($('#s_city').val().length<2){
			alert('Please fill in the city.');
			$('#s_city').focus(); return;
		}
		if ($('#s_state').val()==0){
			alert('Please select the state.');
			$('#s_state').focus(); return;
		}
	}
	if (checkout_step==2 && new_ba==true){//new billing address
		if ($('#street_address').val().length<2){
			alert('Please fill in the street address.');
			$('#street_address').focus(); return;
		}
		if ($('#zip_code').val().length<2){
			alert('Please fill in the zip code.');
			$('#zip_code').focus(); return;
		}
		if ($('#city').val().length<2){
			alert('Please fill in the city.');
			$('#city').focus(); return;
		}
		if ($('#state').val()==0){
			alert('Please select the state.');
			$('#state').focus(); return;
		}
	}
	if (checkout_step==2)
	{
		$('form#Checkout').submit();
		return true;		
	}else//1
	{
		checkout_step = 2;
		$('#step_1').hide();
		$('#step_6').show();//comment
		if (what!=3)
		{
			$('#step_2').show();
			$('#step_3').show();
			$('#step_4').show();
			if (what!=2)
				$('#step_5').show();//payment options
		}
	}
	$('#back_btn').show();
	*/
}
function checkout_back(){
//	checkout_first_option();
	$('#step_6').hide();
	$('#step_5').hide();
	$('#step_4').hide();
	$('#step_3').hide();
	$('#step_2').hide();
	$('#step_1').show();
	$('#back_btn').hide();
	checkout_step = 1;
}
function checkout_sa()
{
	if ($('#shipping_address_0').attr("checked")==true){
		$('#shipping_address_new').show(); new_sa = true;
	}else{
		$('#shipping_address_new').hide(); new_sa = false;
	}
}
function checkout_ba()
{
	if ($('#billing_address_0').attr("checked")==true){
		$('#billing_address_new').show(); new_ba = true;
	}else{
		$('#billing_address_new').hide(); new_ba = false;
	}
}
function check_contact()
{
	if ($('#name').val().length<2){
		alert('Please fill in the name.');
		$('#name').focus(); return false;
	}
	if ($('#phone').val().length<2){
		alert('Please fill in the phone.');
		$('#phone').focus(); return false;
	}
	if ($('#email_c').val().length<2){
		alert('Please fill in the e-mail.');
		$('#email_c').focus(); return false;
	}
	if ($('#message').val().length<2){
		alert('Please fill in the message.');
		$('#message').focus(); return false;
	}
	return true;
}
function fire_thickbox(obj){
	var t = obj.title || obj.name || null;
	var a = obj.href || obj.alt;
	var g = obj.rel || false;
	tb_show(t,a,g);
	obj.blur();
	return false;
}
function js_cancel(url)
{
	if (confirm('All changes will be lost. Are you sure?')) document.location=url;	
}

//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["suckertree0","suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++)
if (document.getElementById(menuids[i]) != null)
{
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.display="none"
		ultags[t].style.visibility="visible"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)

function over_tab(id)
{
	$("#limenu_"+id).removeClass('limenu');
	$("#limenu_"+id).addClass('limenuover');
	$("#limenu_"+id).children().blur();
}
function notover_tab(id)
{
	$("#limenu_"+id).removeClass('limenuover');
	$("#limenu_"+id).addClass('limenu');
	$("#limenu_"+id).children().blur();
}
