function checkradio() {
		var submitButton = $('signIn');
		submitButton.disabled = true;
		
		var username = $('username').value.replace(/\s/g,'');
		if(username.length == 0){
			alert("请填写会员名或注册邮箱");
			submitButton.disabled = false;
			return false;
		}
			
		var password = $('password').value.replace(/\s/g,'');
		if(password.length == 0){
			alert("请填写密码");
			submitButton.disabled = false;
			return false;
		}
		
		var theradio = document.registerform.opinion;
		for (var i = 0; i < theradio.length; i++) {
			if (theradio[i].checked == true) {
				return true;
			}
		}
		alert("请选择后市看法");
		submitButton.disabled = false;
		return false;
}

function addCookie( event){
	if( window.event ){
		event = window.event;
	}
    if (document.all){
		window.external.addFavorite('http://www.v6.com.cn','价值人生');
    }
    else if (window.sidebar){
        window.sidebar.addPanel('价值人生', 'http://www.v6.com.cn', "");
    }
	
	event.returnValue = false;
	return false;
}

function setHome( event ){
	if( window.event ){
		event = window.event;
	}
	
	if (document.all){
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://www.v6.com.cn');
    }
    else if (window.sidebar){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e){
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage','http://www.v6.com.cn');
	}
	
	event.returnValue = false;
	return false;
}

 
//滚动
function startMarquee(h, speed, delay, sid, sumPage) {
	var t = null;
	var p = false;
	var o = $(sid);
	//o.innerHTML += o.innerHTML;
	o.onmouseover = function() {p = true}
	o.onmouseout = function() {p = false}
	o.scrollTop = 0;
	function start() {
	    t = setInterval(scrolling, speed);
	    if(!p) {
			o.scrollTop += h;
		}
		
	}
	function scrolling() {
	    if(p) return;
		if(o.scrollTop / h < (sumPage - 1)) {
	        o.scrollTop += h;
	    } else {
			o.scrollTop = 0;
	        clearInterval(t);
	        setTimeout(start, delay);
	    }
	}
	setTimeout(start, delay);
}

//获取股票观点
function getstockview() {
	new v6Lib.Ajax(v6Lib.twitterurl + 'twitter.php?action=amt&num=12',{				   
				onSuccess: function(transport){
							var resultstr = '';	
							var degree = '';
							var jsonobj = (transport.responseText).evalJSON();
							if (parseInt(jsonobj.status) != 0) {
								$('scrollbody').innerHTML = jsonobj.message;
							}
							else {								
								var	nodearray = jsonobj.data.details;
								for (var j = 0; j < nodearray.length; j++) {
									degree = getViewClass(nodearray[j].profit);
									resultstr += '<div class="login_view_cell">\
									<div class="view_cell_top">\
										<div class="' + degree + ' l"></div>\
										<span class="l"> &nbsp;\
											<font class="bfont"><a href="' + v6Lib.v6url + 'profile.php?uid=' + nodearray[j].profile.uid + '" target="_blank" title="' 
											+ nodearray[j].profile.name + '">' + v6Lib.countCharacters(nodearray[j].profile.name, 9) + '</a></font> 在价格为<font style="color:#d80e30;">' 
											+ nodearray[j].buy_price + '</font>元时关注\
											<font class="bfont"><a href="' + v6Lib.bbsurl + 'jumpboard.php?stockid=' + nodearray[j].stock_id + '" target="_blank"><font title="'+nodearray[j].stock_name+'">' + nodearray[j].stock_name + '</font></a></font>&nbsp;目标价位：<font style="color:#d80e30;">' + nodearray[j].recommended_price + '</font>元\
										</span>\
										<span class="r" title="' + v6Lib.formatTime(nodearray[j].created_time)+'">' + v6Lib.formatTime(nodearray[j].created_time).substring(0,10) + '</span>\
									</div>\
									<div class="c"></div>\
									<div class="view_cell_bottom">\
										<div class="l"><img src="'+ nodearray[j].profile.avatarurl +'" width="36" height="36"/></div>\
										<div class="view_cell_bottom_text" title="' + nodearray[j].reason + '"><a href="' + v6Lib.twitterurl + 'stockview.php?action=all&uid=' + nodearray[j].profile.uid + '&tid=' + nodearray[j].tid + '#' + nodearray[j].tid + '" title="' + nodearray[j].reason + '" target="_blank">' + nodearray[j].reason + '</a>\
										</div>\
										<div class="c"></div>\
									</div>\
									</div>';
											
								}
								$('scrollbody').innerHTML = resultstr;
							}																					
				},
				onFailure:function(transport){
							$('scrollbody').innerHTML = '没有获取到股票观点数据，请稍候再试';
						}
				}				
	);	
}

function getViewClass(profit) {
	var degree = 'viewhold';
	switch(profit) {
  		case '-2':
  			degree = 'viewsellout';
  			break;
  		case '-1':
  			degree = 'viewsell';
  			break;
  		case '0':
  			degree = 'viewhold';
  			break;
  		case '1':
  			degree = 'viewbuy';
  			break;
  		case '2':
  			degree = 'viewbuyall';
  			break;
  	}
	return degree;
}

/*-------------------------------------------------------------------------------------------------------------------*/
//切换行情数据
		function quotation_switch(index,type) {
			if(type == 'A'){
				var tag = 'quotation_tab_' + index;
				var tab_content = 'quotation_' + index;
				$('quotation_1').style.display = 'none';
				$('quotation_2').style.display = 'none';
				$('quotation_3').style.display = 'none';
				$('quotation_tab_1').className = 'quotation_left_cell';
				$('quotation_tab_2').className = 'quotation_left_cell';
				$('quotation_tab_3').className = 'quotation_left_cell';
				$(tab_content).style.display = 'block';
				$(tag).className = 'quotation_left_cell_sel';
				switch(index){
					case 1:quotation_switch(1,'B');getMarketInfo('shgs');break;
					case 2:getMarketInfo('hl');break;
					case 3:getMarketInfo('yyqh');quotation_switch(3,'D');break;
				}
			}
			else if(type == 'B'){
				var tag = 'market_gs_' + index;
				$('market_gs_1').className = 'market_cell';
				$('market_gs_2').className = 'market_cell';
				$('market_gs_3').className = 'market_cell';
				$(tag).className = 'market_cell_sel';
				switch(index){
					case 1:getMarketInfo('shgs');break;
					case 2:getMarketInfo('szgs');break;
					case 3:getMarketInfo('qqgz');break;
				}
			}
			else if(type == 'C'){
				var tag = 'market_hl_' + index;
				$('market_hl_1').className = 'market_cell';
				$('market_hl_2').className = 'market_cell';
				$('market_hl_3').className = 'market_cell';
				$(tag).className = 'market_cell_sel';
				switch(index){
					case 1:break;
					case 2:break;
					case 3:break;
				}
			}
			else if(type == 'D'){
				var tag = 'market_qh_' + index;
				$('market_qh_1').className = 'market_cell';
				$('market_qh_2').className = 'market_cell';
				$('market_qh_3').className = 'market_cell';
				$(tag).className = 'market_cell_sel';
				switch(index){
					case 1:getMarketInfo('ncpqh');break;
					case 2:getMarketInfo('jsqh');break;
					case 3:getMarketInfo('yyqh');break;
				}
			}
		}
		
		//获取对应的行情数据
		function getMarketInfo(type){
			if(type == 'shgs' || type == 'szgs'){
				switch(type){
					case 'shgs':
						resultstr = '<iframe src="http://h1.v6.com.cn/minutehqmini.php?stockid=sh000001" width="190" height="150" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes" id="iframe_shgs"></iframe>';
						$('quotation_1_c').innerHTML = resultstr;
						$('iframe_shgs').src = 'http://h1.v6.com.cn/minutehqmini.php?stockid=sh000001';
						break;
					case 'szgs':
						resultstr = '<iframe src="http://h1.v6.com.cn/minutehqmini.php?stockid=sz399001" width="190" height="150" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes" id="iframe_szgs"></iframe>';
						$('quotation_1_c').innerHTML = resultstr;
						$('iframe_szgs').src = 'http://h1.v6.com.cn/minutehqmini.php?stockid=sz399001';
						break;
				}
			}
			else{
				var url = '';
				
				switch(type) {
					//原油期货
					case 'yyqh': url = 'http://h1.v6.com.cn/indexmap/getep_json.php';break;
					//农产品期货
					case 'ncpqh':url = 'http://h1.v6.com.cn/indexmap/getap_json.php';break;
					//金属期货
					case 'jsqh':url = 'http://h1.v6.com.cn/indexmap/getmp_json.php';break;
					//全球股指
					case 'qqgz':url = 'http://h1.v6.com.cn/indexmap/getr_json.php';break;
					//汇率
					case 'hl':url = 'http://h1.v6.com.cn/indexmap/getxrate_json.php';break;
					//
					default:url = '';break;
				}
				
				new v6Lib.Ajax(url,{				   
					onSuccess: function(transport){
								var resultstr = '';	
								var jsonobj = (transport.responseText).evalJSON();
								
								if (parseInt(jsonobj.status) != 0) {
									$('quotation_1_c').innerHTML = jsonobj.message;
								}
								else {								
									var	nodearray = jsonobj.data.details;
									var dataLength = nodearray.length > 7 ? 7 : nodearray.length;
									
									if(type == 'yyqh'||type == 'ncpqh'||type == 'jsqh'){
										resultstr += '<dl><dt><li style="width:70px;">名称</li><li style="width:49px; *width:51px;">最新</li><li style="width:50px;">涨跌</li></dt>';
										for (var j = 0; j < dataLength; j++) {
											
											resultstr += '<dd><li style="width:70px;">' + nodearray[j].name + '</li><li style="width:49px;*width:51px;">' 
											+ nodearray[j].price + '</li><li style="width:50px;">';
											if(nodearray[j].change.indexOf('-') != -1){
												resultstr += ' <font style="color:#029a6a;">';
											}
											else{
												resultstr += ' <font style="color:#d80e30;">';
											}
											
											resultstr += nodearray[j].change + '</font></li></dd>';
										}
										
										resultstr += '</dl>';
										
										$('quotation_3_c').innerHTML = resultstr;
										
									}
									else if(type == 'hl'){
										resultstr += '<dl><dt><li style="width:85px;">币种</li><li style="width:85px;*width:86px;">现价</li></dt>';
										for (var j = 0; j < dataLength; j++) {
											resultstr += '<dl><dd><li style="width:85px;">' + nodearray[j].base + '/' 
												+ nodearray[j].target + '</li><li style="width:85px;*width:86px;">' + nodearray[j].value + '</li></dd>';
										}
										resultstr += '</dl>';
										$('quotation_2_c').innerHTML = resultstr;
									}
									else if(type == 'qqgz'){
										resultstr += '<dl><dt><li style="width:70px;">名称</li><li style="width:49px;*width:51px;">最新</li><li style="width:50px;">涨跌</li></dt>';
										for (var j = 0; j < dataLength; j++) {
											resultstr += '<dd><li style="width:70px;">' + nodearray[j].name + '</li><li style="width:49px;*width:51px;">' 
											+ nodearray[j].value + '</li><li style="width:50px;">';
											if(nodearray[j].ratio.indexOf('-') != -1){
												resultstr +=' <font style="color:#029a6a;">';
											}
											else{
												resultstr +=' <font style="color:#d80e30;">';
											}
											resultstr += nodearray[j].ratio + '</font></li></dd>';
										}
										resultstr += '</dl>';
										$('quotation_1_c').innerHTML = resultstr;
									}
																	
									
									
								}																					
					},
					onFailure:function(transport){
								$('quotation_1_c').innerHTML = '没有获取相关信息，请稍候再试';
								$('quotation_2_c').innerHTML = '没有获取相关信息，请稍候再试';
								$('quotation_3_c').innerHTML = '没有获取相关信息，请稍候再试';
							}
					}				
				);
			}
			
		}
		
		
//首页搜索框股票自动提示
function homesrchdc(){
    $('v6search').value = "";
 	if(typeof s != 'undefined' ){
		var dc1 = new dhCombobox();
		dc1.callbackName = "v6search";
		dc1.datasource = s;
		dc1.targetObj = $("v6search");
		dc1.setup();
	}
}

function goSearch() {
	var stock = $('v6search').value;
	if(stock.length > 0 && stock != "请输入股票代码/拼音/名称"){
		document.v6srchfrm.submit();
	}
	else{
		alert("请输入搜索条件");
	}
}
		
/*-------------------------------------------------------------------------------------------------------------------*/



document.observe('dom:loaded', function() {
	$('sethome').observe('click',setHome);
	$('addcookie').observe('click',addCookie);
	$('v6search').observe('click',homesrchdc);
	getMarketInfo('shgs');
	getstockview();
	startMarquee(258, 4000, 4000, 'scrollbody', 4);
	
} );



