﻿// JScript 文件
function isIE(){ //ie? 
    if (window.navigator.userAgent.indexOf("MSIE")>=1) 
        return true; 
    else 
        return false; 
}

function $(id) {
 if (document.getElementById != null) {
 return document.getElementById(id);
 }
 else if (document.all != null) {
 return document.all[id];
 }
 else {
 return null;
 }
}

function create_xmlhttp() {
var req=null;
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
}else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}   

return req;
} 

function ajax_post(url,data){

var xmlhttp = create_xmlhttp();
xmlhttp.open("POST", url, false);
xmlhttp.setrequestheader("cache-control","no-cache"); 
xmlhttp.setrequestheader("content-length",data.length); 
xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); 
xmlhttp.send(data);
    if(xmlhttp.readyState == 4) {
        if(xmlhttp.status == 200){      
            if(xmlhttp.responseText == "True") {
             return true;
            } 
            else 
            {
              return false;
            } 
        } 
    }  
}


function hideElementAll(){
	HideElement("SELECT");		
	HideElement("OBJECT");	
}

function showElementAll(){
	ShowElement("SELECT");
	ShowElement("OBJECT");
}

function CreateDialog(content,subject,msgw,msgh)
{
var sWidth,sHeight;
sWidth  = document.body.scrollWidth;
//sHeight = document.body.scrollHeight;
var ch = document.body.clientHeight, sh = document.body.scrollHeight;
sHeight = (sh > ch ? sh : ch);
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.left="0";
bgObj.style.background="#777";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);";
bgObj.style.opacity="0.3";
bgObj.style.width= sWidth + "px";
bgObj.style.height= sHeight + "px"; 
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);

var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.style.position = "absolute";
//msgObj.className = "lightbox";
msgObj.className = "helpbox";
msgObj.style.left = "50%";
msgObj.style.top = "45%";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75 + document.documentElement.scrollTop +"px";
msgObj.style.width = msgw + "px";
msgObj.style.height = msgh + "px";
msgObj.style.zIndex = "10001";

var title=document.createElement("div");
title.setAttribute("id","msgTitle");
title.className = "title";
title.innerHTML='<img src="/images/ico_close_3.gif" alt="Close this Dialog" onclick="RemoveDialog()"  style="cursor:pointer;" id="close" > ' + subject;
if(isIE()) hideElementAll();
document.body.appendChild(msgObj);
$("msgDiv").appendChild(title);
var txt = document.createElement("div");
txt.setAttribute("id","msgTxt");
txt.className ="content";
txt.style.height = msgh  - 65;
txt.innerHTML = content;
$("msgDiv").appendChild(txt);

}

function RemoveDialog()
{
if($("bgDiv")){
document.body.removeChild($("bgDiv"));
$("msgDiv").removeChild($("msgTitle"));
document.body.removeChild($("msgDiv"));
if(isIE()) showElementAll();
}
}

function test(){
var reg=/^[0-9]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}  

function test2(){
var reg=/^[0-9.]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}

function test3(){
var reg=/^[0-9-]/.test(String.fromCharCode(event.keyCode));
if(!reg) event.keyCode=0;
}

//可折叠式滑动显示
var colContentHeight=0;
var colImgPath="http://192.168.1.103:50/images/";
function displayIt(contentID,imgID,maxHeight){
	var h = $(contentID).offsetHeight;
	var max_h = maxHeight;
	var anim = function(){
		h += 15;
		if(h >= max_h){
			$(contentID).style.height = maxHeight + "px";
			$(imgID).src=colImgPath+"collapse_up.gif";
			if(tt){
				window.clearInterval(tt);
			}
		}else{
			$(contentID).style.display="block";
			$(contentID).style.height = h + "px";
		}
	}
	var tt = window.setInterval(anim,2);
}

function hiddenIt(contentID,imgID,maxHeight){
	var h = $(contentID).offsetHeight;
	var anim = function(){
		h -= 15;
		if(h <= 5){
			$(contentID).style.display="none";
			$(imgID).src=colImgPath+"collapse_down.gif";
			if(tt){
				window.clearInterval(tt);
			}
		}else{
			$(contentID).style.height = h + "px";
		}
	}
	var tt = window.setInterval(anim,2);
}

function collapseIt(contentID,imgID){
	if(colContentHeight==0) colContentHeight = $(contentID).offsetHeight;
	colImgPath = $(imgID).src.split("collapse_")[0];
	if($(contentID).style.display == "block"){
		hiddenIt(contentID,imgID,colContentHeight);
	}else{
		displayIt(contentID,imgID,colContentHeight);
	}
}

//不间断横向向左滚动
function initSlide(wrapper,content1,content2){
var slideSpeed=30;
var sct=$(wrapper);
var sct1=$(content1);
var sct2=$(content2);
if(sct1.offsetWidth > sct.offsetWidth ) {
sct2.innerHTML=sct1.innerHTML;
function Marquee(){
if(sct2.offsetWidth - sct.scrollLeft <= 0){
sct.scrollLeft -= sct1.offsetWidth;
}else{
sct.scrollLeft++;
}
}
var MyMar=setInterval(Marquee,slideSpeed);
sct.onmouseover=function() {clearInterval(MyMar);};
sct.onmouseout=function() {MyMar=setInterval(Marquee,slideSpeed);};
}
}

function DisplayAndHiddenObj(arg,titleobj,bodyobj){
    if(arg == true){
      titleobj.style.display="none";
      bodyobj.style.display="block";
    }  
    else{
      titleobj.style.display="block";
      bodyobj.style.display="none";
    }
        return false;
}

function HideElement(strElementTagName){

	try{

		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){

			var objTemp = window.document.all.tags(strElementTagName)[i];

			objTemp.style.visibility = "hidden";

		}

	}catch(e){

		//alert(e.message);
	}

}


function ShowElement(strElementTagName){

	try{

		for(i=0;i<document.getElementsByTagName(strElementTagName).length; i++){

			var objTemp = document.getElementsByTagName(strElementTagName)[i];

			objTemp.style.visibility = "visible";

		}

	}catch(e){
		//alert(e.message);
	}
}

function getCookie(objName){
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
   var aCrumb = aCookie[i].split("=");
   if (objName == aCrumb[0])
   {
    if (aCrumb.length > 1 )
     return unescape(aCrumb[1]);
    else
     return "";
   }
}
return "";
}