// JavaScript Document	
function GetGroupbuyQuestion(){
	var url = '/WebService/tg/TgService.asmx/GroupbuyQuestionService';
	new Ajax.Request(url,{method: 'get',onComplete: function(request){
	var strReturn = request.responseXML.documentElement.text;
	if(!strReturn){
		strReturn = request.responseXML.documentElement.textContent;}
		$('question_list').innerHTML = strReturn;}});
	}
function load_cars_brands(){
	if ($('tg_cars_area').value!= ''){
		var url = '/WebService/tg/TgService.asmx/GetGroupbuyBrands';
		var pars = 'area='+ $('tg_cars_area').value;
		new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(re){
		var xmldoc=re.responseXML.documentElement;
		var nodes=xmldoc.getElementsByTagName('Table');
		while($('tg_cars_brand').options.length){
			$('tg_cars_brand').options.remove(0);
			}
		$('tg_cars_brand').options[0] = new Option('请选择团购地区','');
		for(var i=0;i<nodes.length;i++){
    		var opn=new Option;
   			opn.text = getValue(nodes[i],'brand_name');
    		opn.value = getValue(nodes[i],'gc_id');
    		$('tg_cars_brand').options.add(opn);}}});
			}
	else{
		$('tg_cars_brand').length = 1;
		$('tg_cars_brand').options[0] = new Option('请先选团购地区','');
	}
}
function load_cars_series(){
	if ($('tg_cars_brand').value != ''){
		var url = '/WebService/tg/TgService.asmx/GetGroupbuySeries';
		var pars = 'gc_id='+ $('tg_cars_brand').value;
		new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(re){
		var xmldoc=re.responseXML.documentElement;
		var nodes=xmldoc.getElementsByTagName('Table');
		while($('tg_cars_series').options.length){
			$('tg_cars_series').options.remove(0);
			}
		$('tg_cars_series').options[0] = new Option('请选择汽车系列','');
		for(var i=0;i<nodes.length;i++){
    		var opn=new Option;
   			opn.text = getValue(nodes[i],'series_name');
    		opn.value = getValue(nodes[i],'g_id');
    		$('tg_cars_series').options.add(opn);}}});
			}
	else{
		$('tg_cars_series').length = 1;
		$('tg_cars_series').options[0] = new Option('请先选择汽车品牌','');
		}
	}

function turn_tg(){
	if($("tg_cars_series").value==""){
		alert("请选择汽车系列！");
		}
	else{
  		window.open("/tgbm.aspx?g_id="+$('tg_cars_series').value);
		}
}



function load_cars_id(){
	$('H_cars_id').value = '';
	$('selSeries').options.length = 0;
	if ($('drp_g_id').options[$('drp_g_id').selectedIndex].value!= '0'){
		var url = '/WebService/tg/TgService.asmx/GetGroupbuyCars';
		var pars = 'g_id='+ $('drp_g_id').value;
		new Ajax.Request(url,{method: 'get',parameters: pars,onComplete: function(re){
		var xmldoc=re.responseXML.documentElement;
		var nodes=xmldoc.getElementsByTagName('Table');

		while($('drp_gi_id').options.length){
			$('drp_gi_id').options.remove(0);
			}
		$('drp_gi_id').options[0] = new Option('请选择车型','');
		for(var i=0;i<nodes.length;i++){
    		var opn=new Option;
   			opn.text = getValue(nodes[i],'cars_nick'); 
    		opn.value = getValue(nodes[i],'gi_id');
    		$('drp_gi_id').options.add(opn);
			
			var opn2=new Option;
			opn2.value = getValue(nodes[i],'cars_id');
			$('selSeries').options.add(opn2);
		}
		$('hidSeries').value = getValue(nodes[0],'series_code');	
			}});
			
			}
		
	else{
		$('drp_gi_id').length = 1;
		$('drp_gi_id').options[0] = new Option('请选择系列','');
		$('hidSeries').value = '';
		}
	}

function load_series(){
  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  var xml_file = "/xml/cars/series/"+document.all.brand.value+".xml";
  if(document.all.brand.value != ""){
  document.all.series.length = 1;
  document.all.series.options[0] = new Option('------请选择系列------','');
  
  xmlDoc.async="false";
  xmlDoc.load(xml_file);
  
  nodes=xmlDoc.documentElement.childNodes;
   for(var i=0;i<nodes.length;i++){
    var opn=new Option;
    opn.text = getValue(nodes[i],'series_name');
    opn.value = getValue(nodes[i],'series_code');
    document.all.series.options.add(opn);
   }
  }
  else{
	  document.all.series.length = 1;
      document.all.series.options[0] = new Option('------请选择系列------','');
  }
}

function turn_cars(){
	window.open("http://www.yescar.cn/cars/"+document.all.series.value.substring(0,7)+"/"+document.all.series.value,"_blank");
	}

function getValue(newsItem,id){
	if(document.uniqueID)
	{
		if(newsItem.getElementsByTagName(id)[0]==null)
			return '';
		return newsItem.getElementsByTagName(id)[0].text;
	}
	else
	{
		if(newsItem.getElementsByTagName(id)[0]==null)
			return '';
		return newsItem.getElementsByTagName(id)[0].textContent;
	}
	/*var str;
	if(xmlNode.getElementsByTagName(id)[0]==null)
		return '';
	
    return Try.these(
        function() {
			str=xmlNode.getElementsByTagName(id)[0].text;
			if(str==null || str=='')
				return '';
			return str;
			},
        function() {
			str=xmlNode.getElementsByTagName(id)[0].textContent;
			if(str==null || str=='')
				return '';
			return str;
			}
        );*/
	}
	
function changeFocusImgTg(id){
	var objFocusImg = $('tghd');
	try{
	objFocusImg.style.filter="blendTrans(Duration=0.3)";
	objFocusImg.filters[0].Apply();
	}catch(e){}
	for(var i=1; i<=3; i++){
		if(i=='3'){
			$('tghd' + i).className = 'weektj divHide';
			}
		else{
			$('tghd' + i).className = 'weektg divHide';	
			}
		$('tghd_head' + i).className = '';
	}
	if(id=='3'){
		$('tghd' + id).className = 'weektj';
		}
	else{
		$('tghd' + id).className = 'weektg';
	}
	$('tghd_head' + id).className = 'ch';
	try{
	objFocusImg.filters[0].play();
	}catch(e){}
}
/////////////////////////地区团购/////////////////////////////
function changeAreaEvent(id){
	if(id=="1"){
		$("head1").className="s";
		$("head2").className="";
		$("head3").className="";
		$("head4").className="";
		$("head5").className="";
		
		$("tgbox").style.display = 'block';
		$("tgbox2").style.display="none";
		$("tgbox3").style.display="none";
		$("tgbox4").style.display="none";
		$("tgbox5").style.display="none";
	}else if(id=="2"){
		$("head1").className="";
		$("head2").className="s";
		$("head3").className="";
		$("head4").className="";
		$("head5").className="";

		$("tgbox").style.display="none";
		$("tgbox2").style.display = 'block';
		$("tgbox3").style.display="none";
		$("tgbox4").style.display="none";
		$("tgbox5").style.display="none";
	}else if(id=="3"){
		$("head1").className="";
		$("head2").className="";
		$("head3").className="s";
		$("head4").className="";
		$("head5").className="";
		
		$("tgbox").style.display="none";
		$("tgbox2").style.display="none";
		$("tgbox3").style.display = 'block';
		$("tgbox4").style.display="none";
		$("tgbox5").style.display="none";
	}else if(id=="4"){
		$("head1").className="";
		$("head2").className="";
		$("head3").className="";
		$("head4").className="s";
		$("head5").className="";
		
		$("tgbox").style.display="none";
		$("tgbox2").style.display="none";
		$("tgbox3").style.display="none";
		$("tgbox4").style.display = 'block';
		$("tgbox5").style.display="none";
	}else{
		$("head1").className="";
		$("head2").className="";
		$("head3").className="";
		$("head4").className="";
		$("head5").className="s";
		
		$("tgbox").style.display="none";
		$("tgbox2").style.display="none";
		$("tgbox3").style.display="none";
		$("tgbox4").style.display="none";
		$("tgbox5").style.display = 'block';
	}
}
function clickFocusImgNews(i){
  clearInterval(timer);
  Divshow(i);
  ntt = i;
  timer = setTimeout('change_div()',5000);
}

function change_div(){
	ntt = ntt + 1;
	if( ntt>3 ){ ntt=1; }
	Divshow(ntt);
	timer = setTimeout('change_div()',5000);
}
function Divshow(i){
	if(i!=0){
		selectDiv(i);
	}
	else{
		 clearInterval(timer);
	}
}
function selectDiv(i){
	switch(i){
		case 1: changeFocusImgTg('1'); break;
		case 2: changeFocusImgTg('2'); break;
		case 3: changeFocusImgTg('3'); break;
		default : changeFocusImgTg('1'); break;
	}
}

function change_divTg(){
	ntt = ntt + 1;
	if( ntt>turn_photo_num){ ntt=1;}
	selectDivTg(ntt);
	timer = setTimeout('change_divTg()',5000);
}

function selectDivTg(i){
	switch(i){
		case 1: changeFocusImgTgc('1'); break;
		case 2: changeFocusImgTgc('2'); break;
		case 3: changeFocusImgTgc('3'); break;
		case 4: changeFocusImgTgc('4'); break;
		case 5: changeFocusImgTgc('5'); break;
		case 6: changeFocusImgTgc('6'); break;
		case 7: changeFocusImgTgc('7'); break;
		case 8: changeFocusImgTgc('8'); break;
		case 9: changeFocusImgTgc('9'); break;
		case 10: changeFocusImgTgc('10'); break;
		case 11: changeFocusImgTgc('11'); break;
		case 12: changeFocusImgTgc('12'); break;
		case 13: changeFocusImgTgc('13'); break;
		case 14: changeFocusImgTgc('14'); break;
		case 15: changeFocusImgTgc('15'); break;
		default : changeFocusImgTg('1'); break;
	}
}

function changeFocusImgTgc(id){
	var objFocusImg = $('tghd');
	try{
	objFocusImg.style.filter="blendTrans(Duration=0.3)";
	objFocusImg.filters[0].Apply();
	}catch(e){}
	for(var i=1; i<=turn_photo_num; i++){
		$('tghd' + i).className = 'divHide';
	}
	$('tghd' + id).className = '';
	try{
	objFocusImg.filters[0].play();
	}catch(e){}
}

var ntt=1;
var timer;
function startChange(){
	timer = setTimeout('change_div()',5000);
}

function startChangeTg(){
	var url=top.location.href;
	if(url.indexOf("gc_id")!=-1){
		timer = setTimeout('change_divTg()',5000);}
	}
	
function a()
{
	var code = $('hidSeries').value;
	if(code)
	{
		var index = $('drp_gi_id').selectedIndex-1;	
		if(index>=0)
		{
			window.open('http://www.yescar.cn/cars/'+code.substring(0,7)+"/"+code+'/'+$('selSeries').options[index].value+'.htm');
		}
		else
		{
			window.open('http://www.yescar.cn/cars/'+code.substring(0,7)+"/"+code);
		}
	}
	else
	{
		alert('请选择汽车系列');
	}
}