/**
 * This javascript is for the frontpage.
 * GUL Copyright Mediaman
 * This javascript effect use jQuery prototype
 * Author Billy Song <billy.song@mediaman.com.cn>
 */



/* 左边ts 走势图*/
function switchts(_this,t,tabbox,id){
	//alert(_this.parent.innerHTML);
	jQuery("#"+id + " ."+tabbox).addClass("none");
	jQuery("#"+id + " #"+tabbox+t).removeClass("none");
}

jQuery(function(){
	
	/** Selection percentage bar **/
	var strInitSBarWidth = 0;
	// Slider.			
	jQuery('select#speed').accessibleUISlider({width: 360, partNum: 3, partWidth: "131:131:98", sectionNum: "4:4:3", partClass: "lowStart:middleStart:highStart"});
	/** Selection end **/
	jQuery("#quick_search").autocompleteArray(
		arrDataSource,
		{
			delay:10,
			minChars:1,
			matchSubset:1,
			//onItemSelect:selectItem,
			//onFindValue:findValue,
			autoFill:true,
			maxItemsToShow:10,
			selectClick:true,
			hiddenObject:"con_fund_main"
		}
	);
	/** Selection end **/
		
	/** 右边teaser slider的效果 **/
	/* 左边 tab 趋势图的上方 */
	jQuery(".tabbar1").idTabs();

	/* input button */
	jQuery("input.btn").hover(
	  function () {
		jQuery(this).addClass("btn_h");
	  },
	  function () {
		jQuery(this).removeClass("btn_h");
	  }
	);

	
	/* ts  slider */
	jQuery("#slider").easySlider();
	/** end **/
	
	/** Clutip section **/
	// 所有 tips 的效果
	jQuery('.tips').cluetip({sticky: true, closePosition: 'bottom', arrows: true, width: '312px', cluetipClass: 'tips1' });
	/** Section end **/
	
	jQuery(".newstop dl").hover(
	  function () {
		jQuery(this).addClass("hover");
	  },
	  function () {
		jQuery(this).removeClass("hover");
	  }
	);
	
	
	
	

	
	// 货币型与非货币型基金的选择后相应的参数区域发生变化。
	jQuery("input[@name='fundtype.type']").each(function (){
		jQuery(this).click(function(){
			var optionHtml = "";
			var name_suffix = "";
			if (this.checked)
			{
				if (jQuery("input[@name='fundtype.type'][@checked]").val() == '05')
				{				
					jQuery(".coin_fund").hide();
					jQuery(".uncoin_fund").show();
					name_suffix = "coin";
				}
				else
				{
					jQuery(".coin_fund").show();
					jQuery(".uncoin_fund").hide();
					name_suffix = "uncoin";
				}
				
				optionHtml += "<option selected=\"selected\" value=\"\">请选择基金管理人</option>";
				var ab=jQuery.trim(jQuery("input[@name='fundtype.type'][@checked]").val());
				for (dataKey in arrDatatype)
				{
					//alert(jQuery.trim(arrDatatype[dataKey]["key"]));
					if ((arrDatatype[dataKey]["key"])==ab)
					{
							for (subDataKey in arrDatatype[dataKey]['subData']){
							if(arrDatatype[dataKey]['subData'][subDataKey]['key']!=null)
								optionHtml += '<option value="'+arrDatatype[dataKey]['subData'][subDataKey]['key']+'">'+arrDatatype[dataKey]['subData'][subDataKey]['name']+'</option>';
							}
							}
				}
			

				jQuery("select[@id='company_"+name_suffix+"']").html(optionHtml);
				
				}			
		});
	});
	/** end **/
});	


function fnCheckboxOnClick(data)
{
	if (data == undefined)
		return "";
	
	var dataChecked = false;
	var oppDataChecked = false;
	var oppositeData = (data == "0") ? "1" : "0";
	
	var arrDataType = getElementByClassName('checkbox_'+data, 'input');
	var arrOppDataType = getElementByClassName('checkbox_'+oppositeData, 'input');
	
	for (var key in arrDataType)
	{
		if (arrDataType[key].checked)
		{
			dataChecked = true;
			break;
		}					
	}
	
	if (dataChecked)
	{					
		for (var key in arrOppDataType)
		{
			arrOppDataType[key].setAttribute('disabled', 'disabled');
		}
		
		if (data == "0")
		{
			jQuery(".coin_fund").show();
			jQuery(".uncoin_fund").hide();
		}
		else
		{
			jQuery(".coin_fund").hide();
			jQuery(".uncoin_fund").show();
		}
	}
	else
	{
		for (var key in arrOppDataType)
		{
			arrOppDataType[key].removeAttribute('disabled');
		}
		
		jQuery(".coin_fund").show();
		jQuery(".uncoin_fund").hide();
	}
}

function getElementByClassName(cls,elm) 
{  
	var arrCls =[];  
	var seeElm = (elm != undefined) ? elm : '*';  
	var rexCls = new RegExp('(^|\\\\s)' + cls + '(\\\\s|$)','i');  
	var lisElm = document.getElementsByTagName(seeElm); 
	
	for (var i=0; i<lisElm.length; i++ ) 
	{  
		var evaCls = lisElm[i].className;  
		
		if(evaCls.length > 0 && (evaCls == cls || rexCls.test(evaCls))) 
		{  
			arrCls.push(lisElm[i]);  
		}  
	}  
	
	return arrCls;  
}