﻿function changCity ()		//1 关闭关闭层. 2. 没有关闭按钮
{
	closebut = "";
		closebut = "<a href=\"javascript:void(0);\" class=\"closeW\" onclick=\"closeWindow('SHOW_DIV,bgDiv');\"   >关闭</a>" ;

		strBuf = "		<div class=\"dlBox\"> "+
							"	<div style='height:200px;'>"+closebut+
							//"		<a href=\"javascript:void(0);\" class=\"closeW\"  >关闭</a>"+
							"		<h1 style=\"cursor:move;\" onmousedown=\"move_init('SHOW_DIV');\"><img src=\"/images/arrow_4.gif\" align=\"absmiddle\" />&nbsp;&nbsp;切换城市</h1> "+
							"		<h2  id=\"USER_MSG\" style=\"display:none ;\" ></h2>"+
							"		<iframe src=\"/selectcity.jsp\" frameborder=0 scrolling=yes width=\"500\" height=\"400\"></iframe>"+

							"	</div>"+
							"</div>";
	Mask ();
	CreateWindow(500,400,strBuf) ;
}

function closeWindow( _value) {
	//_value 可能是以,分隔的多个对像.
	var ary = _value.split(",");
	for(i = 0 ; i < ary.length; i++) {
		 var obj = document.getElementById(ary[i]);
		if(obj != null)
			document.body.removeChild(obj);
	}
	document.documentElement.style.overflow="auto";
	for(var j=0;j<document.forms.length;j++){
      for (var i=0;i<document.forms(j).elements.length;i++){
          var e = document.forms(j).elements[i];
          if (e.tagName == "SELECT")e.style.display = "";
      }
	 }
}

//焦点
function _focus(obj) {  	obj.focus();  }
function _select(butStr , type) {
	var ary  = butStr.split(",");
	for(i = 0 ; i < ary.length; i++) {
		var obj = document.getElementById(ary[i]);
		if(obj != null)
			if(type == 1)
				obj.style.display = 'none';
				 else
					obj.style.display = '';	
	}
}

//遮挡层实现
function Mask ( ) 
{
	//attr1,newold, num , price , gender , degree,house_type , bedroom , house_type , degree1,degree2,gender2,stature2,age2,newold
	//上面是统计出来的SELECT框,由于创建遮挡层时SELECT无法完全遮挡,用IFRAM 颜色不理想,所以我们用隐藏的方来来实现
	//var select_but = "attr1,newold,num,price,gender,degree,house_type,bedroom,house_type,degree1,degree2,gender2,stature2,age2,newold,ticket_type,huji1,huji2,attr3_show_select";
	//_select( select_but , 1 );
   var sWidth,sHeight;
   		sHeight = screen.height;
   		sWidth = screen.width;
  document.documentElement.style.overflow="hidden";
  
  var bgObj = document.createElement("div");
	   bgObj.setAttribute('id','bgDiv');
	   bgObj.style.position="absolute";
	   bgObj.style.top=0;
	   bgObj.style.background="#000000";
	   bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=30,finishOpacity=100)";
	   bgObj.style.opacity="0.6";
	   bgObj.style.left=0;
	   bgObj.style.width=sWidth+"px";
	   bgObj.style.height=sHeight+"px";
	   bgObj.style.zIndex = 100;
	   //bgObj.innerHTML = "<iframe style=\"width:"+sWidth+"PX;height:"+sHeight+"PX;top:0;left:0;\"></iframe>" ;
	   document.body.appendChild(bgObj);
	   
 if(navigator.userAgent.indexOf("MSIE")>0){ 
     for(var j=0;j<document.forms.length;j++){
      for (var i=0;i<document.forms(j).elements.length;i++){
          var e = document.forms(j).elements[i];
          if (e.tagName == "SELECT")e.style.display = "none";
      }
	 }
 }
 
}


function CreateWindow ( w , h , title ) 
{
	  var  sWidth,sHeight;
		mLeft = document.documentElement.scrollLeft + (document.documentElement.clientWidth -  500 ) / 2
		mTop = 	document.documentElement.scrollTop + (document.documentElement.clientHeight -400) / 2 
		var oDiv = document.createElement("div");
			 oDiv.setAttribute('id','SHOW_DIV');
			 oDiv.style.position   =   'absolute';
			 oDiv.style.left= parseInt(mLeft)+"px" ;
	  		 oDiv.style.top=  parseInt(mTop)+"px";
			 oDiv.style.width =parseInt( w )+"px";;
			 oDiv.style.height = parseInt( h )+"px";;
			 oDiv.style.background = '#FFFFFF';
			 oDiv.style.borderBottom="#999999 1px solid";
			 oDiv.style.borderLeft="#999999 1px solid";
			 oDiv.style.borderRight="#999999 1px solid";
			 oDiv.style.borderTop ="#999999 1px solid";
			 //oDiv.style.visibility = 'visible';
			 oDiv.style.zIndex = 1100;
		 	 oDiv.innerHTML=title;
			 document.body.appendChild(oDiv);
			 //#########
			//$("login_name_cw").focus();
}

//定位(居中)
function SHOW_DIV_CENTER()
{
	if( document.getElementById("SHOW_DIV") == null ) return ;
	document.getElementById("SHOW_DIV").style.top=( document.documentElement.scrollTop + (document.documentElement.clientHeight - document.getElementById("SHOW_DIV").offsetHeight) / 2 ) +"px";
	document.getElementById("SHOW_DIV").style.left=(document.documentElement.scrollLeft + (document.documentElement.clientWidth - document.getElementById("SHOW_DIV").offsetWidth) / 2 ) +"px";
}

//为了ONLOAD, ONRESIZE ONSCROLL	函数调用
function DIV_CENTER_FUNCTION() {
	SHOW_DIV_CENTER();
}

window.onscroll=DIV_CENTER_FUNCTION;
window.onresize=DIV_CENTER_FUNCTION;
window.onload=DIV_CENTER_FUNCTION;

//#######窗口拖动
var MOVE_TYPE = 0;
function move_init ( move_obj ) 
{
	MOVE_TYPE = 1;
	drag( document.getElementById(move_obj) );
}

function drag( d )
{	
	d.onmousedown=function( a )	
	{
		if(!a) a=window.event;
		var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
		if(d.setCapture)
			d.setCapture();

		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

		if(MOVE_TYPE) {
			d.onmousemove=function( a )	
			{
				if(!a)	a=window.event;
				if(!a.pageX)	a.pageX=a.clientX;
				if(!a.pageY)	a.pageY=a.clientY;
				var tx=a.pageX-x,ty=a.pageY-y;
				d.style.left=tx+"px";
				d.style.top=ty+"px";
			};
		}

		d.onmouseup=function()	
		{
			if(d.releaseCapture)
				d.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			d.onmousemove=null;
			d.onmouseup=null;
			MOVE_TYPE = 0;
		};
	};

}

/* JS 写入Cookie的例子*/
function setCookie(objName,objValue,objHours) //添加cookie
{
		var str = objName + "=" + escape(objValue);
		if(objHours > 0) //为0时不设定过期时间，浏览器关闭时cookie自动消失
		{
			var date = new Date();
			var ms = objHours*3600*1000;
			date.setTime(date.getTime() + ms);
			str += ";expires=" + date.toGMTString();
		}
		document.cookie = str;
}

