//var isIE = !!document.all;

//if(isIE())
//document.documentElement.addBehavior("#default#userdata");

function  saveUserData(key, value){
    var ex; 
    if(isIE()){
        with(document.documentElement)try {
            load(key);
            setAttribute("value", value);
            var overtime = new Date();
            overtime.setHours( overtime.getHours() + 24*30);
           // overtime.setMinutes(overtime.getMinutes() + 1);
            expires = overtime.toUTCString();
            save(key);
            return  getAttribute("value");
        }catch (ex){
            //alert(ex.message)
        }
    }else if(window.sessionStorage){//for firefox 2.0+
        try{
            sessionStorage.setItem(key,value)
        }catch (ex){
            //alert(ex);
        }
    }else{
       // alert("当前浏览器不支持userdata或者sessionStorage特性")
    }
}

function loadUserData(key){
    var ex; 
    if(isIE()){
        with(document.documentElement)try{
            load(key);
            return getAttribute("value");
        }catch (ex){
            //alert(ex.message);
            return null;
        }
    }else if(window.sessionStorage){//for firefox 2.0+
        try{
            return sessionStorage.getItem(key)
        }catch (ex){
           // alert(ex)
        }
    }else{
       // alert("当前浏览器不支持userdata或者sessionStorage特性")
    }
}
function  deleteUserData(key){
    var ex; 
    if(isIE){
        with(document.documentElement)try{
            load(key);
            expires = new Date(315532799000).toUTCString();
            save(key);
        }
        catch (ex){
            //alert(ex.message);
        }
    }else if(window.sessionStorage){//for firefox 2.0+
        try{
            sessionStorage.removeItem(key)
        }catch (ex){
            //alert(ex)
        }
    }else{
       // alert("当前浏览器不支持userdata或者sessionStorage特性")
    }
} 

//class helpdiv
var IsShow = true;
var help_Objects;
function addObj(divID, helpdiv)
{
	if (typeof(help_Objects) == "undefined")
		help_Objects=new Array();			
	help_Objects[divID]=helpdiv;
}
function getObj(divID)
{
	return help_Objects[divID];
}
function helpdiv()
{
	var div_left;
	var div_top;
	var width = 200;
	var div_id ="tiphelper" ;
	var title="";
	var content="";
	var div_visible = true;
	
	var div = document.createElement("div");
	div.id = this.div_id;
	div.style.position = "absolute";
	document.body.appendChild(div);
	//Class methods
	this.ShowDIV 	= ShowDIV;
	this.HiddenDIV  = HiddenDIV;
	this.HiddenHELP  = HiddenHELP;
	this.InitDIV	= InitDIV;
	this.GetInnerHTML = GetInnerHTML;
	addObj(div_id,this);
	function ShowDIV()
	{	
		if(IsShow)
		{	
			this.InitDIV();
			document.getElementById(this.div_id).style.display = "";
			document.getElementById(this.div_id).style.left = this.div_left;
			document.getElementById(this.div_id).style.top = this.div_top;
		}
		else
		{
			this.HiddenDIV();
		}
	}
	
	function HiddenDIV()
	{
		document.getElementById(this.div_id).style.display = "none";
	}
	function HiddenHELP()
	{
		document.getElementById(this.div_id).style.display = "none";
	}
	function InitDIV()
	{		
		document.getElementById(this.div_id).innerHTML = this.GetInnerHTML(this.width,this.title,this.content);	
	}
	
	function GetInnerHTML(width,title,content)
	{
		innertext = "<table width='"+width+"' border='0' cellspacing='0' cellpadding='0'><tr>  <td width='20'><img src='images/tooltipleft.gif' width='20' height='99' /></td>  <td style='border-top:2px solid #337283;border-right:2px solid #337283;border-bottom:2px solid #337283;' bgcolor='#ffffff'><table width='100%' border='0' cellpadding='0' cellspacing='0'> <tr><td height='20' align='right'><table width='100%' border='0' cellspacing='0' cellpadding='0'>  <tr> <td align='left'><div class='tipTitle'>"+title+"</div></td> <td width='24' align='right'><img src='images/tip_close.gif' onclick='ShowDivClose(\"tiphelper\");' alt='关闭提示'  style='cursor:pointer' width='11' height='10' />&nbsp;</td>  </tr></table>  </td> </tr> <tr><td height='50' valign='top'><div class='tipContent'>"+content+"</div></td> </tr></table></td></tr></table>";	
		return innertext;
	}
	
}



//close_tips

function StrCode(str){if(encodeURIComponent) return encodeURIComponent(str);if(escape) return escape(str);}
function UnStrCode(str){if(decodeURIComponent ) return decodeURIComponent (str);if(unescape) return unescape(str);}

function gid(id){return document.getElementById?document.getElementById(id):null;}

function gname(name){return document.getElementsByTagName?document.getElementsByTagName(name):new Array()}

function Browser()
{
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.isOP = false;
	this.isSF = false;
	ua = navigator.userAgent.toLowerCase();
	s = "opera";
	if ((i = ua.indexOf(s)) >= 0)
	{this.isOP = true;return;}
	s = "msie";
	if ((i = ua.indexOf(s)) >= 0) 
	{this.isIE = true;return;}
	s = "netscape6/";
	if ((i = ua.indexOf(s)) >= 0) 
	{this.isNS = true;return;}
	s = "gecko";if ((i = ua.indexOf(s)) >= 0) 
	{this.isNS = true;return;}
	s = "safari";if ((i = ua.indexOf(s)) >= 0)
	{this.isSF = true;return;}
}

function ScreenConvert(){

	var browser = new Browser();
	var objScreen = gid("ScreenOver");
	if(!objScreen) 
	var objScreen = document.createElement("div");
	var oS = objScreen.style;objScreen.id = "ScreenOver";
	oS.display = "block";
	oS.top = oS.left = oS.margin = oS.padding = "0px";
	if (document.body.clientHeight)	
	{
	var wh = document.body.clientHeight + "px";
	}
	else if (window.innerHeight)
	{
	var wh = window.innerHeight + "px";
	}
	else{var wh = "100%";}
	if(document.body.scrollHeight)
	{
		var wh = document.body.scrollHeight + "px";
	}
	oS.width = "100%";
	oS.height = wh;
	oS.position = "absolute";
	oS.zIndex = "3";
	if ((!browser.isSF) && (!browser.isOP))
	{oS.background = "#cccccc";}
	else{oS.background = "#cccccc";}
	oS.filter = "alpha(opacity=40)";
	oS.opacity = 40/100;oS.MozOpacity = 40/100;
	document.body.appendChild(objScreen);
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++)
	allselect[i].style.visibility = "hidden";
}

function ScreenClean()
{
	var objScreen = document.getElementById("ScreenOver");
	if (objScreen) objScreen.style.display = "none";
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++) 
	allselect[i].style.visibility = "visible";
}

function DialogLoc()
{
	var dde = document.documentElement;
	if (window.innerWidth)
	{
		var ww = window.innerWidth;
		var wh = window.innerHeight;
		var bgX = window.pageXOffset;
		var bgY = window.pageYOffset;}
	else
	{
		var ww = dde.offsetWidth;
		var wh = dde.offsetHeight;
		var bgX = dde.scrollLeft;
		var bgY = dde.scrollTop;
	}
	t_DiglogX = (bgX + ((ww - t_DiglogW)/2));
	t_DiglogY = (bgY + ((wh - t_DiglogH)/2));
}
function getWindowSize() 
{ 
	var e = new Object(); 
	if(window.self && self.innerWidth) 
	{ 
		e.width = self.innerWidth; 
		e.height = self.innerHeight; 
	} 
	else if(document.documentElement && document.documentElement.clientHeight) 
	{ 
		e.width = document.documentElement.clientWidth; 
		e.height = document.documentElement.clientHeight; 
	}else 
	{ 
		e.width = document.body.clientWidth; 
		e.height = document.body.clientHeight; 
	} 
	return e 
}
function DialogShow(showdata,ow,oh,w,h)
{
	var objDialog = document.getElementById("DialogMove");
	if (!objDialog) objDialog = document.createElement("div");
	t_DiglogW = ow;
	t_DiglogH = oh;
	DialogLoc();
	objDialog.id = "DialogMove";
	var oS = objDialog.style;
	oS.display = "block";
	oS.top = t_DiglogY + "px";
	oS.left = t_DiglogX + "px";
	oS.margin = "0px";
	oS.padding = "0px";
	oS.width = w + "px";
	oS.height = h + "px";
	oS.position = "absolute";
	oS.zIndex = "5";
	oS.background = "#FFF";
	oS.border = "solid #000 2px";
	objDialog.innerHTML = showdata;
	document.body.appendChild(objDialog);
}

function DialogHide()
{
	ScreenClean();
	var objDialog = document.getElementById("DialogMove");
	if (objDialog) objDialog.style.display = "none";
}

function ShowDivClose(div_id)
{
	ScreenConvert();
	var html="<div id=\"DialogTitle\"><div id=\"DialogTitleBtn\" onclick=\"return DialogHide();\" onmouseover=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #000000';\" onmouseout=\"var objShut = document.getElementById('DialogTitleBtn');objShut.style.border='solid 1px #EEE';\"></div></div><div style='font-size:12px;padding-left:8px;padding-top:20px;padding-bottom:16px;'>下次是否继续显示该提示？</div><div style='text-align:center;'><button  class='SubmitButton' onclick=\"return closeThisDiv('"+div_id+"',true);\">继续提示</button>&nbsp;&nbsp;<button class='SubmitButton' onclick=\"return closeThisDiv('"+div_id+"',false);\">不再提示</button></div>";
	DialogShow(html,240,80,240,80);	
}
function closeThisDiv(id,b)
{
	IsShow = b;
	getObj(id).HiddenDIV();
	DialogHide();
}

var maptable = null;
function ShowMap()
{
	maptable = document.getElementById("maptable");
	ScreenConvert();
	var objDialog = document.getElementById("mapdlg");
	if (!objDialog) objDialog = document.createElement("div");
	var mapdiv = document.getElementById("viewport");
	var e = getWindowSize();
	t_DiglogW = e.width/2;
	t_DiglogH = e.height/2;
	maptable.style.display = "";
	maptable.style.width = t_DiglogW + "px";
	maptable.style.height = t_DiglogH + "px";
	mapdiv.style.width = t_DiglogW + "px";
	mapdiv.style.height = (t_DiglogH - 32)+ "px";

	DialogLoc();
	objDialog.id = "mapdlg";
	var oS = objDialog.style;
	oS.display = "block";
	oS.top = t_DiglogY + "px";
	oS.left = t_DiglogX + "px";
	oS.margin = "0px";
	oS.padding = "0px";
	oS.width = t_DiglogW + "px";
	oS.height = t_DiglogH + "px";
	oS.position = "absolute";
	oS.zIndex = "5";
	oS.background = "#FFF";
	oS.border = "solid #000 2px";
	if(!objDialog.init)
	{
		objDialog.appendChild(maptable);
		objDialog.init=true;
		//SWMap.resize();
	}	
	document.body.appendChild(objDialog);
	mapInit();	
}
function CloseMap()
{
	maptable = document.getElementById("maptable");
	maptable.style.display = "none";
	ScreenClean();
	var objDialog = document.getElementById("mapdlg");
	if (objDialog) objDialog.style.display = "none";
}
function DoSelectRect()
{
	//do
	getBound();
	maptable = document.getElementById("maptable");
	maptable.style.display = "none";
	ScreenClean();
	var objDialog = document.getElementById("mapdlg");
	if (objDialog) objDialog.style.display = "none";
}
function hiddenall(e)
{
	e = (e)?e:((event)?event:null);
    if(e)
    {
        var charCode=(e.charCode)?e.charCode:e.keyCode;
        if(charCode == 27)
        {
			DialogHide();
			CloseMap();
		}
	}
}
document.onkeydown = hiddenall;
document.onkeypress = hiddenall;
