﻿// JScript 文件


var __sto = setTimeout;    
window.setTimeout = function(callback,timeout,param){    
    var args = Array.prototype.slice.call(arguments,2);    
    var _cb = function(){    
        callback.apply(null,args);    
    }    
    __sto(_cb,timeout);    
}  

function getPageSize(){  
  var xScroll, yScroll;  
  if (window.innerHeight && window.scrollMaxY) {  
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {  // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }  
  
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }

  if(xScroll < windowWidth){  
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
return arrayPageSize;

}


//滚动条
function getPageScroll() {
  var yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll) 
  return arrayPageScroll;
}


function WinMessage(title, msg, w, h){ 
if($("dialog")) {document.body.removeChild($("dialog"))}
if($("dialogBg")) {document.body.removeChild($("dialogBg"))}

   var titleheight = "22px"; // 提示窗口标题高度 
        var bordercolor = "#dc7d00"; // 提示窗口的边框颜色 
        var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色 
        var titlebgcolor = "#dc7d00"; // 提示窗口的标题背景色
        var bgcolor = "#FFFFFF"; // 提示内容的背景色

		var arrPageSize=getPageSize();
		var arrPageScroll=getPageScroll();
		var pageWidth,pageHeight,windowWidth,windowHeight,xScroll, yScroll;
		pageWidth=arrPageSize[0];
		pageHeight=arrPageSize[1];
		windowWidth=arrPageSize[2];
		windowHeight=arrPageSize[3];
		xScroll=0;
		yScroll=arrPageScroll[1];
		
        
        var iWidth = windowWidth;
        var iHeight = windowHeight;       
        
        
                
        var bgObj = document.createElement("div"); 
        bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+pageWidth+"px;height:"+Math.max(document.body.clientHeight, pageHeight)+"px;filter:Alpha(Opacity=50);opacity:0.5;-moz-opacity:0.5;background-color:#666666;z-index:101;";
        bgObj.setAttribute('id','dialogBg');
        bgObj.innerHTML='<iframe src="javascript:false" style="position:absolute; visibility:inherit; top:0px; left:0px; width:'+pageWidth+'px; height:'+Math.max(document.body.clientHeight, pageHeight)+'px; z-index:-1; filter:Alpha(Opacity=10);opacity:0.1;-moz-opacity:0.1;background-color:#000000;"></iframe>'
        document.body.appendChild(bgObj); 
                
        var msgObj=document.createElement("div");
        msgObj.style.cssText = "position:absolute;top:"+(yScroll+(iHeight-h)/2)+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;min-height:"+h+"px;_height:"+h+"px; height:auto;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
        msgObj.setAttribute('id','dialog')
        document.body.appendChild(msgObj);
                                
        var table = document.createElement("table");
        msgObj.appendChild(table);
        table.style.cssText = "margin:0px;border:0px;padding:0px;";
        table.cellSpacing = 0;
        var tr = table.insertRow(-1);
        var titleBar = tr.insertCell(-1);
        titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
        titleBar.style.paddingLeft = "10px";
        titleBar.innerHTML = title;
        var moveX = 0;
        var moveY = 0;
        var moveTop = 0;
        var moveLeft = 0;
        var moveable = false;
        
        var docMouseMoveEvent = document.onmousemove;
        var docMouseUpEvent = document.onmouseup;
        titleBar.onmousedown = function() {
                var evt = getEvent();
                moveable = true; 
                moveX = evt.clientX;
                moveY = evt.clientY;
                moveTop = parseInt(msgObj.style.top);
		
                moveLeft = parseInt(msgObj.style.left);
                
                document.onmousemove = function() {
                        if (moveable) {
                                var evt = getEvent();
                                var x = moveLeft + evt.clientX - moveX;
                                var y = moveTop + evt.clientY - moveY;
                                if ( x > 0 &&( x + w < pageWidth) && y > 0 && (y + h < pageHeight) ) {
                                        msgObj.style.left = x + "px";
                                        msgObj.style.top = y + "px";
                                }
                        }        
                };
                document.onmouseup = function () { 
                        if (moveable) { 
                                document.onmousemove = docMouseMoveEvent;
                                document.onmouseup = docMouseUpEvent;
                                moveable = false; 
                                moveX = 0;
                                moveY = 0;
                                moveTop = 0;
                                moveLeft = 0;
                        } 
                };
        }
        
        var closeBtn = tr.insertCell(-1);
        closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
        closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
        closeBtn.onclick = function(){                
               
            if($("dialog")) {document.body.removeChild($("dialog"))}
            if($("dialogBg")) {document.body.removeChild($("dialogBg"))}
                 
        } 
        var msgBox = table.insertRow(-1).insertCell(-1);
        msgBox.style.cssText = "font:10pt '宋体';";
        msgBox.colSpan  = 2;
        msgBox.innerHTML = "<div id=\"dialogbody\">"+msg+"</div>";
        
  //获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
            return window.event || arguments.callee.caller.arguments[0];
    }
    } 
    
function WinDialog( w, h){ 
    if($("dialog")) {document.body.removeChild($("dialog"))}
     if($("dialogBg")) {document.body.removeChild($("dialogBg"))}
        var bordercolor = "#FFFFFF"; // 提示窗口的边框颜色 
        var bgcolor = "#FFFFFF"; // 提示内容的背景色

		var arrPageSize=getPageSize();
		var arrPageScroll=getPageScroll();
		var pageWidth,pageHeight,windowWidth,windowHeight,xScroll, yScroll;
		pageWidth=arrPageSize[0];
		pageHeight=arrPageSize[1];
		windowWidth=arrPageSize[2];
		windowHeight=arrPageSize[3];
		xScroll=0;
		yScroll=arrPageScroll[1];
		
        
        var iWidth = windowWidth;
        var iHeight = windowHeight; 

        var bgObj = document.createElement("div"); 
        bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+pageWidth+"px;height:"+Math.max(document.body.clientHeight, pageHeight)+"px;filter:Alpha(Opacity=50);opacity:0.5;-moz-opacity:0.5;background-color:#666666;z-index:101;";
        bgObj.setAttribute('id','dialogBg')
        bgObj.innerHTML='<iframe src="javascript:false" style="position:absolute; visibility:inherit; top:0px; left:0px; width:'+pageWidth+'px; height:'+Math.max(document.body.clientHeight, pageHeight)+'px; z-index:-1; filter:Alpha(Opacity=10);opacity:0.1;-moz-opacity:0.1;background-color:#000000;"></iframe>'
        document.body.appendChild(bgObj); 
        
        var msgObj=document.createElement("div");
        msgObj.style.cssText = "position:absolute;top:"+(yScroll+(iHeight-h)/2)+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;min-height:"+h+"px;_height:"+h+"px; height:auto;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
        msgObj.setAttribute('id','dialog')
        document.body.appendChild(msgObj);        
        var msgBox=document.createElement("div");
        msgBox.setAttribute('id','dialogbody')
        msgObj.appendChild(msgBox);
        
}

function CloseDialog(){
 if($("dialog")) {document.body.removeChild($("dialog"))}
  if($("dialogBg")) {document.body.removeChild($("dialogBg"))}
}


function stateChangeIE(loadId,_frame)
{ 
 if (_frame.readyState=="interactive")//state: loading ,interactive,   complete
 {
 var loader = document.getElementById(loadId); 
    loader.innerHTML = "";    
    loader.style.display = "none";  
    _frame.style.visibility = "visible";   
     _frame.style.display="";  

 }   
}
function stateChangeFirefox(loadId,_frame)
{ 
 var loader = document.getElementById(loadId); 
    loader.innerHTML = "";    
    loader.style.display = "none";  
    _frame.style.visibility = "visible"; 
    _frame.style.display="";  
}
    
    
//图片缩略
function imgResized(obj,width,height){
  window.setTimeout(imgResizeFun,1000,obj,width,height);

   //imgResizeFun(obj,width,height)
}

function imgResizeFun(obj,width,height){
   obj.style.display='';
   if(obj.width>width)
    {
    obj.resized=true; 
    obj.width=width;
    }
   else if(obj.height>height)
    {
    obj.resized=true; 
    obj.width=height;
    }
}


/*--------------Rand Image */
function ResetImg(){
    var _r = Math.random();
    $("RandPic").src="/tools/RandomCode.aspx?rnd=" + _r;
   
    
}

//取得cookies
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
   var aCrumb = aCookie[i].split("=");
   if (sName == aCrumb[0]) 
   {
    if (aCrumb.length > 1 )
     return unescape(aCrumb[1]);
    else
     return "";
   }
}
return null;

}

//写cookies函数
function SetCookie(name,value,expires)//两个参数，一个是cookie的名子，一个是值
{
//var Days = 30; //此 cookie 将被保存 30 天
var exp   = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + expires);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}



 var errobjs="";
function showError(objId,errMsg){
var newObj=document.createElement("span");
   newObj.setAttribute('id',objId+'_errorSpan')
   newObj.innerHTML=errMsg;
   newObj.className='error';
   $(objId).insertAdjacentElement('afterEnd',newObj);
   if(errobjs.indexOf(objId+'_errorSpan')<0)errobjs+=objId+'_errorSpan,';
}

function clearError(){
var errobjs_arr=errobjs.split(',');
var errobjs_len=errobjs_arr.length;
for(var i=0;i<errobjs_len;i++){
if(errobjs_arr[i]!=''){
if($(errobjs_arr[i]))$(errobjs_arr[i]).parentNode.removeChild($(errobjs_arr[i]));
}
}
errobjs="";
}

//要使该window.onerror生效，必须关闭IE的脚本调试功能
function debugScript(sMsg,sUrl,sLine)
{	
	return true;//禁止IE脚本调试
}


/*字符转换日期*/
function StrToDate(strDate){
var splitArray;
var str="";
str=strDate;
splitArray=str.split("-")

if(splitArray.length!=3)
  return new Date();
for(var i=0; i<splitArray.length; i++)
{

  if( isNaN(splitArray[i]) ){return new Date();}
}

return new Date(splitArray[0],splitArray[1]-1,splitArray[2]);
}
//日期比较
function compareDate(DateOne,DateTwo)
{

var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ("-"));
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ("-")+1);
var OneYear = DateOne.substring(0,DateOne.indexOf ("-"));

var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ("-"));
var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ("-")+1);
var TwoYear = DateTwo.substring(0,DateTwo.indexOf ("-"));

if (Date.parse(OneMonth+"/"+OneDay+"/"+OneYear) > Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear))
{
return true;
}
else
{
return false;
}
}
//日期相加
 function addDate(type,NumDay,dtDate){
   //var date = new Date(dtDate)
   var date=dtDate;
 type = parseInt(type) //类型 
 lIntval = parseInt(NumDay)//间隔
  switch(type){
   case 6 ://年
  date.setYear(date.getYear() + lIntval)
  break;
 case 7 ://季度
  date.setMonth(date.getMonth() + (lIntval * 3) )
  break;
 case 5 ://月
  date.setMonth(date.getMonth() + lIntval)
  break;
 case 4 ://天
  date.setDate(date.getDate() + lIntval)
  break
 case 3 ://时
  date.setHours(date.getHours() + lIntval)
  break
 case 2 ://分
  date.setMinutes(date.getMinutes() + lIntval)
  break
 case 1 ://秒
  date.setSeconds(date.getSeconds() + lIntval)
  break;
 default:
    
  } 
 return date.getYear() +'-' +  (date.getMonth()+1) + '-' +date.getDate()+ ' '+ date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()
  } 

function getDateDiff(date1,date2){
   
   var   re   =   /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;   
   var   dt1,dt2;   
   if   (re.test(date1))   
   {   
    dt1   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);   
   } 
    
   if   (re.test(date2))   
   {   
    dt2   =   new   Date(RegExp.$1,RegExp.$2   -   1,RegExp.$3);   
   }  
    
   return Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24))
   
  }
  
  function Request(strName)
{
    var strHref = window.document.location.href;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);

    var arrTmp = strRight.split("&");
    for(var i = 0; i < arrTmp.length; i++)
    {
        var arrTemp = arrTmp[i].split("=");

        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
    }
    return "";
}

function SetKeyWordColor(key){
//var str=$(objId).innerHTML;
//$(objId).innerHTML=str.replace(key,'<span style="color:red;background-color:#ffff80;font-weight:bold;padding:2px;"' >'+key+'</span>');
if(document.createRange)
var range = document.createRange(); 
else 
var range = document.body.createTextRange();      

if(range.findText){ 
    while(range.findText(key)){ 
        //range.pasteHTML(range.text.fontcolor("#ff0000")); 
        range.pasteHTML('<span style="color:red;background-color:#ffff80;padding:2px;" >'+key+'</span>'); 
        range.collapse(true); 
    } 
}

}

//下拉框可输入事件
function selectInput_onkeypress(obj){
obj.options[2]=new Option(ok=(obj.options[2])?obj.options[2].innerText+String.fromCharCode(event.keyCode):String.fromCharCode(event.keyCode),"client")
obj.selectedIndex=2;
}


////下拉框可输入事件
function selectInput_onkeyup(obj){
if(obj.options[2]){
    if(event.keyCode==8){
    var str=obj.options[2].innerText;
    var len=str.length;
    obj.options[2].innerText=str.substring(0,len-1);
        if(obj.options[2].innerText=="")obj.remove(2);
        }
        if(event.keyCode==13)return false;
        if(event.keyCode==32){
        obj.options[2].innerText+=" ";

        }
    }
}
//收藏
function bookmarkit(url,title){
window.external.addFavorite(url,title)
}

//显示地图
function ShowMap(nid){


var mapUrl="http://www.newhy.cn/map/showbizmap.php?width=400&height=300&bizid="+nid;

if(nid!=""){
  var htmlStr='';
   htmlStr+='<div style="width:100%;padding:150px 0px;text-align:center;color:red" id="IframeLoad"><img src="/images/loading.gif" />&nbsp;地图正在加载中...</div>';
   htmlStr+='<iframe style="visibility:hidden" onreadystatechange=stateChangeIE("IframeLoad",this) onload=stateChangeFirefox("IframeLoad",this) name="callframe" id="callframe" style="height:300px;width:400px;display:none;margin-top:5px;" frameborder="0" scrolling="no" marginheight="0"></iframe>';
   WinMessage('显示地图',htmlStr,440,340);
  callframe.location.href=mapUrl; 
}
else{
alert("暂未提供地图");
}
	
}

//图片按比例缩放
//var flag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
   // flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        ImgD.alt=image.width+"×"+image.height;
        }
    }
} 

function tabSelect(showId,idpre) {
	for(i=1; i<=10; i++) {
        var tab = $("#"+idpre+i);
        if(!tab[0]) break;
		if (i==showId) { 
			$("#btn_"+idpre+i).attr("className","selected");
			$("#"+idpre+i).toggleClass("none");
			$("#"+idpre+i).css("display","");
		 } else {
			$("#btn_"+idpre+i).attr("className","unselected");
			$("#"+idpre+i).addClass("none");
			$("#"+idpre+i).css("display","none");
		}
	}
}

function ShowUserStatus(companyId){
$("user_status").innerHTML='';
var url = 'http://www.newhy.cn/ajax/ajax.php';
var obj = $('user_status');
var postStr = '&act=user_status&pid=' +companyId;


runAjax(url, postStr, "POST", obj);

/*
TestAjax('user_status','user_status','&pid='+companyId,CallBack);

function CallBack(){


}
*/
}
