/** AjaxConn*/
function AjaxConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
	  else if(sMethod=="IFRAME") {
		document.domain="intosz.com";
		function getIFrameDoc(id) {
			 var iframe = document.getElementById(id);
			 iframe.style.display='block';
			 var doc = (iframe.contentWindow || iframe.contentDocument);
			 if (doc.document) {
				 doc = doc.document;
			 }
			 return doc;
		}
		function init(frame) {
			var d=getIFrameDoc("iframeProxy").body;
			//var txt=d.body.innerHTML;
			fnDone(d);
			//alert(d.body.innerHTML);
			frame.document.execCommand('stop');
			document.body.removeChild(frame);
		}			
		var f=document.createElement("iframe");
		f.src=sURL+"?"+sVars;
		f.id="iframeProxy";
		f.style.border="0px";
		f.style.width="0px";
		f.style.height="0px";
		f.onload = function(){ init(f);};
		if ( f.attachEvent != null )
			f.attachEvent( 'onload', function() { init(f); });
		document.body.appendChild(f);
	  }
	  else {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}


/*例子
var myConn = new AjaxConn();
if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
var fnWhenDone = function (oXML) { alert(oXML.responseText); };
myConn.connect("test.do", "POST", "sn=test", fnWhenDone);
*/

function $(id) 
{
	if(document.getElementById) 
	{
		return document.getElementById(id);
	}
	else if(document.all)
	{
		return document.all[id];
	}
	else if(document.layers)
	{
		return document.layers[id];
	}
}


function getlogininfo(){
	var myConn = new AjaxConn();
	var fnWhenDone = function (oXML) { $("logininfo").innerHTML=oXML.responseText; };
	myConn.connect("/manage/getlogininfo.do", "GET", "saction=getlogininfo", fnWhenDone);
}

function dologin(stype)
{
if (stype=="1")
{
$("slogan_info").style.display  = "none";
$("login_box").style.display  = "";
}
else
{
	
$("slogan_info").style.display  = "";
$("login_box").style.display  = "none";
}


}

function dologout(servername,returnurl)
{
	var myConn = new AjaxConn();
	var fnWhenDone = function (oXML) {if(  returnurl!="") window.location.href=returnurl; else window.location.href= window.location.href; };
	myConn.connect(servername+"/manage/logout.do", "GET", "", fnWhenDone);

}


function checklogin(servername,returnurl)
{
		if(document.loginform.userid.value=="")
		
		{
			alert("对不起,用户名不能为空!");
			document.loginform.userid.focus();
			return false;
		}
		if(document.loginform.password.value=="")
		
		{
			alert("对不起,登录密码不能为空!");
			document.loginform.password.focus();
			return false;
		}
var url=servername+"/manage/checklogin.do"
var parameterstr="saction=login&userid="+escape(document.loginform.userid.value)+"&password="+document.loginform.password.value
	var myConn = new AjaxConn();
	var fnWhenDone = function (oXML) { body=oXML.responseText;alert(oXML.responseText);if(  body.indexOf('登录成功') >= 0 ) window.location.href= window.location.href; };
	myConn.connect(url, "POST", parameterstr, fnWhenDone);
		
return false;

}

function isEmpty (str) {
    if ((str==null)||(str.length==0)) return true;
    else return(false);
}
function isInt (theStr) {
	var flag = true;
	if (isEmpty(theStr)) { flag=false; }
	else
	{	for (var i=0; i<theStr.length; i++) {
			if (isDigit(theStr.substring(i,i+1)) == false) {
				flag = false; break;
			}
		}
	}
	return(flag);
}
//校验数字：0-9数字的组合
function isDigit(s)
{
	var patrn=/^[0-9]{1,20}$/;
	if (!patrn.exec(s)) return false
	return true
}
function isBetween (val, lo, hi) {
	if ((val < lo) || (val > hi)) { return(false); }
	else { return(true); }
}
function IsDate (theStr) {
	var the1st = theStr.indexOf('-');
	var the2nd = theStr.lastIndexOf('-');
	
	if (the1st == the2nd) { return(false); }
	else {
		var y = theStr.substring(0,the1st);
		var m = theStr.substring(the1st+1,the2nd);
		var d = theStr.substring(the2nd+1,theStr.length);
		var maxDays = 31;
		
		if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
			return(false); }
		else if (y.length < 4) { return(false); }
		else if (!isBetween (m, 1, 12)) { return(false); }
		else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
		else if (m==2) {
			if (y % 4 > 0) maxDays = 28;
			else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
           	else maxDays = 29;
		}
		if (isBetween(d, 1, maxDays) == false) { return(false); }
		else { return(true); }
	}
}

function setCopy(_sTxt){

	if(document.uniqueID) {
		clipboardData.setData('Text',_sTxt);
		alert (""+_sTxt+" 已成功复制\n请使用ctrl + V粘贴到您要发布的地方");
	} else {
		prompt("请复制以下网址：",_sTxt); 
	}
}
function bbimg(o){
	var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
	return false;
}


//获取浏览器类型
function getExplorer(){
       var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        if (window.ActiveXObject)
            Sys.ie = ua.match(/msie ([\d.]+)/)[1]
        else if (document.getBoxObjectFor)
            Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
        else if (window.MessageEvent && !document.getBoxObjectFor)
            Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]
        else if (window.opera)
            Sys.opera = ua.match(/opera.([\d.]+)/)[1]
        else if (window.openDatabase)
            Sys.safari = ua.match(/version\/([\d.]+)/)[1];

		if(Sys.ie) return('IE');
        if(Sys.firefox) return('Firefox: '+Sys.firefox);
        if(Sys.chrome) return('Chrome: '+Sys.chrome);
        if(Sys.opera) return('Opera: '+Sys.opera);
        if(Sys.safari) return('Safari: '+Sys.safari);
}



//图片自动缩放，垂直居中
function picCheck (obj, maxWidth, maxHeight)
{
	obj.style.width = "auto";
	if (obj.width > maxWidth)
	{
		obj.style.width = maxWidth + 'px';
	}
	if (obj.height > maxHeight)
	{
		obj.style.width = (obj.width * maxHeight / obj.height + 1) + 'px';
	}
	parentHeight = obj.parentNode.clientHeight == 0?obj.parentNode.parentNode.clientHeight : obj.parentNode.clientHeight;
	obj.style.marginTop = (parentHeight - obj.clientHeight) / 2 + 'px';
}
function picPosition (obj)
{
	parentHeight = obj.parentNode.clientHeight == 0?obj.parentNode.parentNode.clientHeight : obj.parentNode.clientHeight;
	obj.style.marginTop = (parentHeight - obj.clientHeight) / 2 + 'px';
}
