// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function menuScrollBg(index, i, flag) {
	var a=[0,71,142,213];
	var el='menu_'+index
	var position_y = (0-42*(index-1)) + 'px'
	if(flag == 0){
		$(el).setStyle({backgroundPosition: (0-a[i]) + 'px ' + position_y});
	} else {
		a.sort(function(b,c){return c-b;});
		$(el).setStyle({backgroundPosition: (0-a[i]) + 'px ' + position_y});
	}
}  

function menuEvent(index, flag) {
	for(var i=0; i<4; i++){
		setTimeout("menuScrollBg("+index+"," + i +","+flag+")",60 * i);
	}
}
function ajax_error() {
	alert('服务器连接失败，请稍候再试！');
	return false;
}
function chgSection(el, sum, index) {
	var mtab = 'mtab_'+el+'_tab';
	var mcon = 'mcon_'+el+'_con';
	for(var i=1; i<= sum; i++) {
		$(mtab+i).hide();
		$(mcon+i).hide();
	}
	$(mtab+index).show();
	$(mcon+index).show();
	return false;	
}
function doCopy(el) {
	$(el).focus();
	$(el).select();
	r = $(el).createTextRange();
	r.execCommand("Copy");
}
function chg1Section(el, sum, index) {
	var mtab = el + '_mtab_';
	var mcon = el + '_mcon_';
	for(var i=1; i<= sum; i++) {
		if (index == i) {
			$(mtab + i).addClassName('on');
			$(mcon + i).show();
		} else {
			$(mtab + i).removeClassName('on');
			$(mcon + i).hide();
		}
	}
	return false;	
}

function chg2Section(el, group, subtab) {
	var el_id = el.id
	var mcon = 'mtab2_'+ group + '_con';
	var mcon_curr = 'mtab2_'+el_id+'_con';
	$(el_id).up('div', 1).select('a.curr')[0].removeClassName('curr'); 
	$(el_id).className = 'curr';
	$(mcon).childElements().each(function(s) { if(s.id != "")s.hide();})
	$(mcon_curr).show();
	if(subtab != undefined) {
		var msubtab = 'mtab2_'+ group + '_subtab';
		var msubtab_curr = 'mtab2_'+el_id+'_subtab';
		$(msubtab).childElements().each(function(s) { s.hide();})
		$(msubtab_curr).show();
	}
	return false;	
}


function categoryToggle(el) {
	var prev_el = $(el).up('div', 0).select('span.open')[0];
	if (prev_el != undefined && prev_el != el) {
		$(prev_el).toggleClassName('open');
		$(prev_el).next('div').toggle();
	}
	$(el).toggleClassName('open');
	$(el).next('div').toggle();
	return false;
}

function doZoom(size){
	$('artibody').className = "text_" + size;
}

function mkt_search(stype, el, sum, index) {
	$('mkt_search_form')['type'].value = stype;
	$('mkt_search_form')['q'].focus();
	chg1Section(el, sum, index);
}

function count_num(el, val) {
	v = parseInt($(el).value);
	vv = v + val;
	$(el).value = vv > 1 ? vv : 1;
	return false;
}