//浏览器辨别
var browser;
function InitBrower(){
	   if(navigator.userAgent.indexOf("MSIE")>0) browser = 1;//IE,myIE,Maxthon
	   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0) browser = 2;
	   if(isSafari=navigator.userAgent.indexOf("Safari")>0) browser = 3;  
	   if(isCamino=navigator.userAgent.indexOf("Camino")>0) browser = 4;
	   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0) browser = 5;//火狐
	   return browser;
}	

//滤镜初始化
function buildGlobalLayer() {
       //定义记住BODY滚动高度的全局变量
       window.bdscrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
       if ( browser==1 ) {//IE 7.0以下版本需加iframe
               var gIfr                        = document.createElement( 'iframe' );
               gIfr.id                                ='globalIfr';
               gIfr.style.display        = 'none';
               gIfr.style.position        = 'absolute';
               gIfr.style.clear        = 'both';
               gIfr.style.zIndex        = '90';
               gIfr.style.left                = '0px';
               gIfr.style.top                = '0px';
               gIfr.style.width        = '100%';
               gIfr.style.height        = '100%';
               gIfr.style.border        = '0px #ffffff solid';
               gIfr.onselectstart        = function() { return false;};
               gIfr.style.filter        = 'alpha(opacity=0)';
               document.body.appendChild( gIfr );
       }
       var gDiv                                = document.createElement( 'div' );
       gDiv.id                                        = 'globalDiv';
       gDiv.style.display                = 'none';
       gDiv.style.position                = 'absolute';
       gDiv.style.clear                = 'both';
       gDiv.style.zIndex                = '91';
       gDiv.style.left                        = '0px';
       gDiv.style.top                        = '0px';
       gDiv.style.width                = '100%';
       gDiv.style.height                = '100%';
       gDiv.style.border                = '0px #ffffff solid';
       gDiv.style.background        = 'darkgray';
       gDiv.onselectstart                = function() { return false;};
       if ( browser==1 ) {
               gDiv.style.filter        = 'alpha(opacity=30)';
       }
       else {
               gDiv.style.opacity        = 30/100;
       }
       document.body.appendChild( gDiv );
}	

//打开滤镜层
function openGlobalLayer() {
	window.bdscrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
	var bw = ( document.body.scrollWidth || document.documentElement.scrollWidth ) + 'px';
	var bh = ( document.body.scrollHeight || document.documentElement.scrollHeight ) + 'px';
	if ( $_( 'globalIfr' ) ) {
		$_( 'globalIfr' ).style.width	= bw;
		$_( 'globalIfr' ).style.height	= bh;
		$_( 'globalIfr' ).style.display = 'block';
	}
	$_( 'globalDiv' ).style.width		= bw;
	$_( 'globalDiv' ).style.height		= bh;
	$_( 'globalDiv' ).style.display		= 'block';
}

//关闭滤镜层
function closeGlobalLayer() {
	if ( $_("globalIfr") ) {
		$_( 'globalIfr' ).style.width	= '0px';
		$_( 'globalIfr' ).style.height	= '0px';
		$_("globalIfr").style.display	= 'none';
	}
	$_( 'globalDiv' ).style.width		= '0px';
	$_( 'globalDiv' ).style.height		= '0px';
	$_( 'globalDiv' ).style.display		= 'none';
}

function $_(str) {
     if (typeof str == 'string' && document.getElementById(str) != null ) {
             return document.getElementById(str);
     }
     return false;
}var mousePos_x;var mousePos_y;
/*
//鼠标位置判断
var mousePos_x;
var mousePos_y;
function mouseMove(ev){ 	ev= ev || window.event; 
	var mousePos = mouseCoords(ev); 
	//alert(ev.pageX); 
	mousePos_x = mousePos.x; //TZZ
	mousePos_y = mousePos.y; //TZZ
	//mousePos_x = ev.clientX+document.body.scrollLeft; 
	//mousePos_y = ev.clientY+document.body.scrollTop; 
	
		//alert("x:"+ev.x+"  y:"+ev.y+" screenx:"+ev.screenX+"  screeny:"+ev.screenY+" clientx:"+ev.clientX+"  clienty:"+ev.clientY+" scrollWidth:"+document.body.scrollWidth+" scrollHeight:"+document.body.scrollHeight);
}

function mouseCoords(ev) { 	//alert("mouse: X-"+ev.clientX+" Y-"+ev.clientY);	//alert("scroll: X-"+document.body.scrollLeft+" Y-"+document.body.scrollTop);
	if(ev.pageX || ev.pageY){ 
	return {x:ev.pageX, y:ev.pageY}; 
	} 
	return { 
			    //var x = dragObjectEvent.clientX+d.body.scrollLeft-dragObject.offsetLeft;
			    //var y = dragObjectEvent.clientY+d.body.scrollTop-dragObject.offsetTop;
	//x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, //TZZ原来值
	//y:ev.clientY + document.body.scrollTop - document.body.clientTop    //TZZ原来值		x:ev.clientX , //TZZ原来值	y:ev.clientY    //TZZ原来值
	//x:ev.clientX + document.body.scrollLeft - ev.offsetLeft, 
	//y:ev.clientY + document.body.scrollTop - ev.offsetTop 
	}; 
	//alert(" x:"+x+" y:"+y);
}

document.onmousemove = mouseMove; 
*/
//date[objS对象集] -- to -- html
function dateToHtml(objS, type){
	var tableTop = "";
	if(type==1){
		tableTop = '<h5>选择省市<span onclick="closDiv(1);closeSubDiv()">关闭</span></h5>';
	}else if(type==2){
		tableTop = '<h5>选择行业<span onclick="closDiv(2);closeSubDiv()">关闭</span></h5>';
	}
	var tableInner = "";
	var tableStart = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	var tableButton = "";
	if(type==1||type==2){
		tableButton = '<tr><td colspan="2" align="center"><input name="" type="button" value="确定/修改" class="input_normal2_bt" onclick="closDiv(\''+type+'\')" /></td></tr>';
	}
	var tableEnd = '</table>';
	for(var i=0; i<objS.length; i++){
		if(type==3||type==4){
			if(objS[i].level==0){
				if(tableInner==""){
					tableInner += '<tr><td class="list_tit_one" valign="top">'+objS[i].name+'</td><td class="list_tit_two">';
				}else{
					tableInner += '<-><tr><td class="list_tit_one" valign="top">'+objS[i].name+'</td><td class="list_tit_two">';
				}
			}else{
				if(type==3){
					tableInner += '<span onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)" onclick="sortSearch(\'ProvinceCityCode\',\''+objS[i].code+'\',\''+objS[i].name+'\')">'+objS[i].name+'</span>';
				}else if(type==4){
					tableInner += '<span onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)" onclick="sortSearch(\'IndustryCode\',\''+objS[i].code+'\',\''+objS[i].name+'\')">'+objS[i].name+'</span>';
				}
			}
		}else if(type==1||type==2){
			if(objS[i].level==0){
				if(type==1){
					if(tableInner==""){
						tableInner += '<tr><td style="width:100px" class="list_tit_one" valign="top"><input name="box_City" type="checkbox" style="display:none"/>'+objS[i].name+'</td><td class="list_tit_two">';
					}else{
						tableInner += '<-><tr><td style="width:100px" class="list_tit_one" valign="top"><input name="box_City" type="checkbox" style="display:none"/>'+objS[i].name+'</td><td class="list_tit_two">';
					}
				}else if(type==2){
					if(tableInner==""){
						tableInner += '<tr><td style="width:140px" class="list_tit_one" valign="top"><input name="box_Ind" type="checkbox" style="display:none"/>'+objS[i].name+'</td><td class="list_tit_two">';
					}else{
						tableInner += '<-><tr><td style="width:140px" class="list_tit_one" valign="top"><input name="box_Ind" type="checkbox" style="display:none"/>'+objS[i].name+'</td><td class="list_tit_two">';
					}
				}
			}else{
				if(type==1){
					tableInner += '<span style="width:140px" onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)"><input name="box_City" type="checkbox" value="'+objS[i].code+'" onclick="choiceBoxCity(document.forms[0][\'box_City\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')" /><a style="color:#000;" onclick="getAllChildCity_div(\''+objS[i].code+'\')">'+objS[i].name+'</a></span>';
				}else if(type==2){
					tableInner += '<span style="width:170px" onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)"><input name="box_Ind" type="checkbox" value="'+objS[i].code+'" onclick="choiceBoxIndustry(document.forms[0][\'box_Ind\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')"/><a style="color:#000;" onclick="getAllChildIndustry_div(\''+objS[i].code+'\')">'+objS[i].name+'</a></span>';
				}
			}
		}
	}
	re = /<->/g; 
	tableInner = tableInner.replace(re, '</td></tr>');
	tableInner += '</td></tr>';
	//alert(tableInner);
	//alert(tableStart+tableInner+tableButton+tableEnd);
	return tableTop+tableStart+tableInner+tableButton+tableEnd;
}

//date[objS对象集] -- to -- html  (弹出窗口)
function dateToHtml_Sub(objS, type){
	var tableInner = "";
	var tableTop = '<h5><span onclick="closeSubDiv();closeGlobalLayer();">[关闭]</span></h5>';
	var tableStart = '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	//var bottonV = '<tr><td colspan="2" align="center"><input type="button" value="确定" class="input_normal2_bt" onclick="closeSubDiv()" /></td></tr>'
	var tableEnd = '</table>';
	for(var i=0; i<objS.length; i++){
		if(objS[i].level==2){
			if(type==1){
				if(tableInner==""){
					tableInner += '<tr><td class="list_tit_one" valign="top"><input name="box2_City" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2City(document.forms[0][\'box2_City\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')" />'+objS[i].name+'</td><td class="list_tit_two">';
				}else{
					tableInner += '<-><tr><td class="list_tit_one" valign="top"><input name="box2_City" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2City(document.forms[0][\'box2_City\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')"/>'+objS[i].name+'</td><td class="list_tit_two">';
				}
			}else if(type==2){
				if(tableInner==""){
					tableInner += '<tr><td style="width:140px" class="list_tit_one" valign="top"><input name="box2_Ind" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2Industry(document.forms[0][\'box2_Ind\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')" />'+objS[i].name+'</td><td class="list_tit_two">';
				}else{
					tableInner += '<-><tr><td style="width:140px" class="list_tit_one" valign="top"><input name="box2_Ind" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2Industry(document.forms[0][\'box2_Ind\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')"/>'+objS[i].name+'</td><td class="list_tit_two">';
				}
			}
		}else{
			if(type==1){
				tableInner += '<span style="width:90px" onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)"><input name="box2_City" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2City(document.forms[0][\'box2_City\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')"/><a style="color:#000;">'+objS[i].name+'</a></span>';
			}else if(type==2){
				tableInner += '<span style="width:110px" onmouseover="chBgColor(this, 1)" onmouseout="chBgColor(this, 0)"><input name="box2_Ind" type="checkbox" value="'+objS[i].code+'" onclick="choiceBox2Industry(document.forms[0][\'box2_Ind\']['+i+'].checked ,\''+objS[i].code+'\',\''+objS[i].name+'\')"/><a style="color:#000;">'+objS[i].name+'</a></span>';
			}
		}
	}
	re = /<->/g; 
	tableInner = tableInner.replace(re, '</td></tr>');
	tableInner += '</td></tr>';
	//alert(tableTop+tableStart+tableInner+tableEnd);
	return tableTop+tableStart+tableInner+tableEnd;
}


	function chBgColor(obj, type) {
		if (type) {
			obj.className = 'mouseon';			//alert(obj.className);
		} else {
			obj.className = '';
		}
	}
	
	function callbackCity(date){
		//alert("callback");
		var objS = eval(date);
		var result = dateToHtml_Sub(objS,1);
		buildSubLayer(result);		//closeGlobalLayer();
		initSubDivBoxCity();
	}
	function callbackInd(date){
		//alert("callback");
		var objS = eval(date);
		var result = dateToHtml_Sub(objS,2);
		buildSubLayer(result);		//closeGlobalLayer();
		initSubDivBoxIndustry();
	}
	
	function closeSubDiv(){
		document.getElementById('SubDiv').style.display="none";
	}
	
	//----------------------
	function getAllChildCity_div(code){		$.get("ProvinceCityServer?code="+code, null, callbackCity);
	}
	function getAllChildIndustry_div(code){
		$.get("IndustryServer?code="+code, null, callbackInd);
	}
	
function buildSubLayer( result ) {
	var divSTableDom = document.getElementById('SubDiv');
	divSTableDom.style.zIndex = '98';
	divSTableDom.style.position = 'absolute';
	//divSTableDom.style.visibility = 'hidden';
	divSTableDom.style.backgroundColor = '#FFEDE0';
	//divSTableDom.style.width = '500px';
	//divSTableDom.style.height = '500px';
	//alert("x:"+mousePos_x+" y:"+mousePos_y);		//alert(" scrollTop:"+document.body.scrollTop+" scrollLeft:"+document.body.scrollLeft);
	divSTableDom.style.top = (mousePos_y +document.documentElement.scrollTop)+ 'px';//tzz
	divSTableDom.style.left = (mousePos_x+document.body.scrollLeft) + 'px';//tzz
	//alert("top:"+divSTableDom.style.top+"  left:"+divSTableDom.style.left+" scrollWidth:"+document.body.scrollWidth+" scrollHeight:"+document.body.scrollHeight+" scrollTop:"+document.body.scrollTop+" scrollLeft:"+document.body.scrollLeft);
	//divSTableDom.style.top = (mousePos_y-dragObject.offsetTop) + 'px';
	//divSTableDom.style.left = (mousePos_x-dragObject.offsetLeft) + 'px';
	divSTableDom.style.display = 'block';
	divSTableDom.innerHTML = result;	//alert(divSTableDom.innerHTML);	dragDiv(divSTableDom, 1);
}