var basePath;
var city_group = new Array();     //单组分站
var totalCityGroup=new Array();//全部单组分站的总集合
var warnNum=0;                       //每行分站的字数总结，大于40则加入下一组中
var current_cityinfo = 0;           //当前展示第几行
var	FGDemo1_1;
//生成分站组合list begin------------------------
function getCityList(){
	for (var j=0;j<cmhead.length;j++){
		var cityGroup=cmhead[j].value;
		for(var i=0;i<cityGroup.length;i++){
			while(cityGroup[i].sn.length<5){
				cityGroup[i].sn=cityGroup[i].sn+" ";
			}
			warnNum=warnNum+cityGroup[i].sn.length;
			if(warnNum<=40){
				city_group.push(cityGroup[i]);
			}else{
				totalCityGroup.push(city_group);
				city_group=new Array();
				city_group.push(cityGroup[i]);
				warnNum=cityGroup[i].sn.length;
			}
		}
		if(j==cmhead.length-1){
				totalCityGroup.push(city_group);
			}
	}
}
//生成分站组合list end------------------------
//滚动方法begin------------------   -号为向左切换
function scroll_cityinfo(forward){
    if( forward == '-'){
    	if(current_cityinfo>0) current_cityinfo--;
    	else current_cityinfo=totalCityGroup.length-1;
    }else{
    	if(current_cityinfo<totalCityGroup.length-1) current_cityinfo++;
    	else current_cityinfo=0;
    }
    var htmlText = '';
    var cityGroups=totalCityGroup[current_cityinfo];
    for(var i=0;i<cityGroups.length;i++){
    	htmlText = htmlText + '<a target="_blank" href="'+basePath+'/web/forepageProducts/CitySiteIndex.html?cityId='+cityGroups[i].cId+'"'+' title="'+cityGroups[i].n+'"'+'>'+cityGroups[i].sn+'</a>';
    }
    jQuery("#cityinfo_area").html(htmlText);
}	
//滚动方法end------------------
//自动滚动begin-----------------
jQuery(function(){
	getCityList();
	//给头部分站按钮绑定点击切换事件
	$("#scrollCity .click-left").bind("click",function(){ scroll_cityinfo('-'); });
    $("#scrollCity .click-right").bind("click",function(){ scroll_cityinfo(); });
	FGDemo1_1=document.getElementById('scrollCity');
	scroll_cityinfo();
    var speed=7000;
    var MyMar1=setInterval(scroll_cityinfo,speed);
	FGDemo1_1.onmouseover=function(){clearInterval(MyMar1)};
	FGDemo1_1.onmouseout=function(){MyMar1=setInterval(scroll_cityinfo,speed)};		
 });
//自动滚动end-----------------
//展示省或直辖市下分站begin----------
function create_level_0(upId){
	var count = 1 ;
	var flag = false;   //ul标签换行标识
	var htmlText = '';
	var data;
	for (var j=0;j<cmhead.length;j++){
		if (upId == cmhead[j].key ) {
			data = cmhead[j].value;
			break;
		}
	}
	if(data.length==0){
		//表示该省级下暂无分站
		htmlText = '<h1><span></span></h1><ul style="width:155px; margin-right:25px; display:inline;">' + '<li class="jiameng-wu">暂无分站，<a class="c2" href="javascript:void(0);">点击加盟</a></li></ul>';
		count=1.8;
	}else{
		//表示该省级下已有分站
		htmlText = '<h1><span></span></h1><h2><a class="c2" href="javascript:void(0);">点击加盟</a></h2><ul>';
	}
	for (var i = 0;i<data.length;i++){
		if( i%10 == 0 && i != 0 ) {
			htmlText = htmlText + '</ul><ul>';
			count++;
		}
		if (i%10 != 0) {
			flag = true;
		}
		if(data[i].n!="") htmlText = htmlText + '<li class="c1"><a target="_blank" href="'+basePath+'/web/forepageProducts/CitySiteIndex.html?cityId='+data[i].cId+'" style="color:#ff6600">'+data[i].n.substring(0,7)+'</a></li>'
	}
	if( flag ) {
		htmlText = htmlText + '</ul>';
	}
	var width = count*100;
	jQuery(".jing-cl").removeClass("jing-cl");
	jQuery("#level_0_"+upId).addClass("jing-cl");
	jQuery("#level_1").css("width",width+"px");
	jQuery("#level_1").html(htmlText);
	$("a.c2").click(function(){
		var d=document.getElementById('coverdiv');
		if(!d){d=document.createElement("div");d.id="coverdiv";jQuery(d).css({"filter":"alpha(opacity=30)","top":"0px","left":"0px","opacity":"0.3","background-color":"black","z-index":"10000","height":document.documentElement.scrollHeight+"px","width":document.documentElement.scrollWidth+"px","position":"absolute"});jQuery("body").append(d); } jQuery(d).show();
		jQuery('#company').val("");jQuery('#remark').val("");
		jQuery('#man').val("");jQuery('#tel').val("");jQuery('#text').val("");
		addSiteDivShow();
		$("#area_zone").hide();
		$("#area_level_1").hide();
	});
	if ( data.length>0 )
		jQuery("#area_level_1").show();
}
//展示省或直辖市下分站end----------
//include
function setDialogBig(id){
	var tiwen=document.getElementById(id);
	tiwen.style.position ="absolute";
	tiwen.style.left = document.body.clientWidth/2-160+"px";
	tiwen.style.top = document.documentElement.scrollTop+document.documentElement.clientHeight/2-200+"px";
	tiwen.style.zIndex="10001";
}
function setDialog(id){
	var tiwen=document.getElementById(id);
	tiwen.style.position ="absolute";
	tiwen.style.left = document.body.clientWidth/2-140+"px";
	tiwen.style.top = document.documentElement.scrollTop+document.documentElement.clientHeight/2+"px";
	tiwen.style.zIndex="10001";
}
function addSiteDivShow(params){
	//$("#company").val(params);
	setDialogBig("siteAddDivJH");
	loadvalidatecodejh();
	jQuery(window).scroll(function(){setDialogBig("siteAddDivJH");})
	document.getElementById('thisunlook').innerHTML=="";
	$("#siteAddDivJH").show();
}
function loadvalidatecodejh(){	
	document.getElementById("codepicjh").src=basePath+"/validatecode/validatecode.html?temp=" + (new Date().getTime().toString(36));            
}
function checkcityvalidatecode(){
		$.ajax({
				type : "post",
				url : basePath+"/validatecode/checkvalidatecode.html",
				async:false,
				data:{c:$("#text").val()},
				success : function(data){
				var i=parseInt(data);
				if(i==1){
					$('#v_codell').attr('value',1);
				}else if(i==2){
					$('#v_codell').attr('value',2);
				}
				}
			});
}
function addSite(){
		if($.trim($("#company").val())==""){
			document.getElementById('thiscompanyem').innerHTML="不能为空";
			$("#company").val('');
			$('#company').focus();
			return false;
		}else if($.trim($("#man").val())==""){
			document.getElementById('thisnoempty').innerHTML="不能为空";
			$("#man").val('');
			$('#man').focus();
			return false;
		}else if($.trim($("#tel").val())==""){
			document.getElementById('thistelem').innerHTML="不能为空";
			$("#tel").val('');
			$('#tel').focus();
			return false;
		}
		checkcityvalidatecode();
		if($("#v_codell").val()==2){
			document.getElementById('thisunlook').innerHTML="验证码错误";
			$("#text").val('');
			$('#text').focus();
			return false;
		}else{
			$.ajax({
		          type:"post",
		          url:basePath+"/headJqueryAjax/addSiteJquery.html",
		          data:{company:$("#company").val(),man:$("#man").val(),tel:$("#tel").val(),remark:$("#remark").val(),type:1},
		          success:function(){
		          	$('#siteAddDivJH').hide();
					setDialogBig('layer2JH');
					$('#layer2JH').show();
		          },
		          error:function(){$('#siteAddDivJH').hide();
					setDialogBig('layer2JH');
					$('#layer2JH').show();}
		    });      
		}
}

