window.onerror=new Function("return true");
window.onload = function(){
 	CheckNews();
	resizeimg();
	}
var step=0;
var HasNew=0;	
function $(ID){
    if(document.getElementById&&document.getElementById(ID)){
		return document.getElementById(ID);
	}else if (document.all&&document.all(ID)) {
		return document.all(ID);
	}else if (document.layers&&document.layers[ID]){
		return document.layers[ID];
	}else{
		return false;
	}
}
var Loading="<div style='text-align:center;font:bold 12px arial;line-height:50px;color:#ccc'>";
	Loading+="Please wait...";
	Loading+="<br \/><img src='images/loading.gif' alt='' /><br \/><br \/><\/div>";
//显示时间
function ShowDate(){
setInterval("time.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
}
//##########################################
//#AJAX类
//##########################################
function AJAX(){
	var $HTTP=false;var $Me=this;
	try{$HTTP=new XMLHttpRequest;}
		catch(e){
	try{$HTTP=new ActiveXObject("MSXML2.XMLHTTP");}
		catch(e2){
	try{$HTTP=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(e3){$HTTP=false;}}}
	if (!$HTTP){return false;}
	this.method="POST";
	this.URL;
	this.ASYNC=true;
	this.content="";
	this.callback=function(obj) {return obj;}
	this.send=function(){
	if(!this.method||!this.URL||!this.ASYNC){return false;}
	//$HTTP.open (this.method,this.URL+"&Time="+new Date().getTime(), this.ASYNC);
	$HTTP.open (this.method,this.URL,this.ASYNC);   
	if(this.method=="POST"){$HTTP.setRequestHeader("Content-Type","application/x-www-form-URLencoded");}
	$HTTP.onreadystatechange=function(){$Me.callback($HTTP);}
	if(this.method=="POST"){$HTTP.send(this.content);}else{$HTTP.send(null);}
	}
}

function flash_title(){
if(HasNew==1){
 //   step++
//	
//    if (step==3) {step=1}
//    if (step==1) {document.title="【你有新的消息】";}
//    if (step==2) {document.title="【　　　　　　】"}	
//setTimeout("flash_title()",380);
}
}

function CheckNews() {   
var Ajax=new AJAX();	
	Ajax.method="get";
	Ajax.URL="Ajax.asp?Action=showlog";
	Ajax.callback=function($HTTP){
	if($HTTP.readyState == 4){
	if($HTTP.status == 200){  
	var ss=unescape($HTTP.responseText);
	theerr=ss.split('|')[0];	
	themsg=ss.split('|')[1];
	if(theerr=="yes"){
	document.getElementById('winpop').style.height='0px';//我不知道为什么要初始化这个高度,CSS里不是已经初始化了吗,知道的告诉我一下
	//setTimeout("tips_pop()",800);     //3秒后调用tips_pop()这个函数
	tips_pop()
	document.getElementById('wincontent').innerHTML = themsg;
		HasNew=1;
		//tidck = setTimeout('CheckNews()',8000); 
	}
	//返回打开层
	}else{alert("您所请求的页面有异常。");} 
	}
}
	Ajax.send(null);	
    flash_title()

}
function showMenu (baseID, divID) {
    baseID = $(baseID);
    divID  = $(divID);
    if (showMenu.timer) clearTimeout(showMenu.timer);
	hideCur();
    divID.style.display = 'block';
	showMenu.cur = divID;
    if (! divID.isCreate) {
        divID.isCreate = true;
        divID.timer = 0;
        divID.onmouseover = function () {
            if (showMenu.timer) clearTimeout(showMenu.timer);
			hideCur();
            divID.style.display = 'block';
        };

        function hide () {
           showMenu.timer = setTimeout(function () {divID.style.display = 'none';}, 1000);
        }

        divID.onmouseout = hide;
        baseID.onmouseout = hide;
    }
	function hideCur () {
		showMenu.cur && (showMenu.cur.style.display = 'none');
	}
}

//设为首页
function homepage(e,NAME){
	e.style.behavior='url(#default#homepage)';e.setHomePage(NAME);
}
//加入收藏
function Favorite(URL,NAME){
	window.external.AddFavorite(URL,NAME)
}
//图片按比例缩放,可输入参数设定初始大小
function resizeimg() {
	var picTarget=document.getElementById("content").getElementsByTagName("img");
	for (var i=0;i<picTarget.length;i++){
	var image=new Image();
    image.src=picTarget[i].src;
	var iheight = 500;var iwidth= 600; 
	if(image.width>0 && image.height>0){
        if(image.width/image.height>= iwidth/iheight){
           if(image.width>iwidth){
               picTarget[i].width=iwidth;
               picTarget[i].height=(image.height*iwidth)/image.width;
           }else{
                  picTarget[i].width=image.width;
                  picTarget[i].height=image.height;
                }
               picTarget[i].alt=image.width+"×"+image.height;
        }
        else{
                if(image.height>iheight){
                       picTarget[i].height=iheight;
                       picTarget[i].width=(image.width*iheight)/image.height;
                }else{
                        picTarget[i].width=image.width;
                        picTarget[i].height=image.height;
                     }
                picTarget[i].alt=image.width+"×"+image.height;
            }
　　　　　picTarget[i].style.cursor= "pointer"; //改变鼠标指针
　　　　　picTarget[i].onclick = function() { window.open(this.src);} //点击打开大图片
　　　　if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器，如果是IE
　　　　　　picTarget[i].title = "请使用鼠标滚轮缩放图片，点击图片可在新窗口打开";
　　　　　　picTarget[i].onmousewheel = function img_zoom() //滚轮缩放
　　　　　 {
　　　　　　　　　　var zoom = parseInt(this.style.zoom, 10) || 100;
　　　　　　　　　　zoom += event.wheelDelta / 12;
　　　　　　　　　　if (zoom> 0)　this.style.zoom = zoom + "%";
　　　　　　　　　　return false;
　　　　　 }
　　　  } else { //如果不是IE
　　　　　　　     picTarget[i].title = "点击图片可在新窗口打开";
　　　　　　   }
    }	
	}
}
//弹出层
function showdiv(action,title,id,oo,channelid,IsRefresh){
if(oo == 1){
	if($("open").value=="yes"){
	alert("已经有用户查看该配货信息")
	return false
	}
}
var o=$("thediv");
var m=$("backdiv");
o.innerHTML = Loading;
o.style.display="block";
o.style.top ="75px";
o.style.left=((document.body.scrollWidth-document.getElementById("thediv").offsetWidth) /2)+"px";
m.style.display='block';
m.style.height = window.screen.availHeight  + "px";
ajaxinnerdiv(action,title,id,oo,channelid,IsRefresh);
}


function ajaxinnerdiv(action,title,id,oo,channelid,IsRefresh){
	var o=$("thediv");
	var Ajax=new AJAX();
    Ajax.method="GET";
    Ajax.URL="Ajax.asp?Action="+escape(action)+"&title="+escape(title)+"&oo="+escape(oo)+"&ChannelID="+ escape(channelid)+"&id="+ id+"&IsRefresh="+ escape(IsRefresh);
    Ajax.callback=function($HTTP){
		if ($HTTP.readyState==4 && $HTTP.status == 200){
		//var o=parent.Main.$("thediv");
		
		var content=unescape($HTTP.responseText);
		o.innerHTML="<div class=\"container\"><div class=\"itemtitle\"><h3>"+title+"</h3><em class=\"icon_close\" onClick=\"hiddendiv("+IsRefresh+","+id+")\" title=\"关闭\">&nbsp;</em></div><div id=\"divcontent\">"+content+"</div></div>";
		
		}
	}
	Ajax.send(null);
}
function hiddendiv(IsRefresh,id){
var o=$("thediv");
var m=$("backdiv");
if(IsRefresh==3 && $("isshow").value == 1){
	if(confirm("您现在点开没有配货成功,关闭是要扣除3元金币,确定吗？")){
	top.location.href="Ajax.Asp?Action=showkoufen&id="+id+"";
}else{
	return false
}
var reurl=location.toString();
var gourl=reurl.split('?')[0];
if (IsRefresh==3){location=reurl;}
}
o.style.display="none";
m.style.display="none";
}
//提示层
function msgbox(err,obj){
var o=$("errbox");
var m=$("backdiv");
o.style.display="block";
o.style.top =((document.body.scrollHeight-document.getElementById("errbox").offsetHeight) /2)+"px";
o.style.left=((document.body.scrollWidth-document.getElementById("errbox").offsetWidth) /2)+"px";
o.innerHTML = obj + "!";
m.style.display='block';
if(err=="yes"){
	o.className = "yes";
}else{
	o.className = "no";
}
m.style.height = window.screen.availHeight  + "px";
window.setTimeout('msgbox_close()',  3000 );  
}
function msgbox_close(){
	document.getElementById("errbox").style.display="none";	
	document.getElementById("backdiv").style.display="none";	
}
//显示列表
function Load_list(action,div){
var Ajax=new AJAX();
    Ajax.method="GET";
    Ajax.URL="Ajax.asp?To="+action+"";
    Ajax.callback=function($HTTP){if ($HTTP.readyState==4){$(div).innerHTML=$HTTP.responseText;}else{$(div).innerHTML=Loading;}}
    Ajax.send(null);	
	}
	
//显示内容
function Load_show(action,div,id){
var Ajax=new AJAX();
    Ajax.method="GET";
    Ajax.URL="Ajax.asp?To="+action+"&ID="+id+"";
    Ajax.callback=function($HTTP){if ($HTTP.readyState==4){$(div).innerHTML=$HTTP.responseText;}else{$(div).innerHTML=Loading;}}
    Ajax.send(null);	
	}	
//分页
function GetPage(URL,Page){
var Ajax=new AJAX();
    Ajax.method="GET";
    Ajax.URL=""+URL+"&Page="+Page+"";
    Ajax.callback=function($HTTP){if ($HTTP.readyState==4){$("center").innerHTML=$HTTP.responseText;}else{$("center").innerHTML=Loading;}}
    Ajax.send(null);
}﻿

//显示FLASH
window.onerror=new Function("return true");

function Flash(Path,Width,Height)
{
var Tmp
	Tmp='<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="FlashH" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="'+Width+'" height="'+Height+'">'
	Tmp+='<param name="movie" value="'+Path+'"/>'
	Tmp+='<param name="quality" value="High"/>'
	Tmp+='<param name="scale" value="ExactFit"/>'
	Tmp+=' <param name="wmode" value="transparent"/>';
	Tmp+='<embed wmode="transparent" src="'+Path+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="FlashH" width="'+Width+'" height="'+Height+'" scale="ExactFit"/>'
	Tmp+='</object>'
document.write(Tmp);
}
//分页
function showPageLink(sUrl,iPage,iCount){
	var i;
	i=Math.max(1,iPage-1);
	document.write("<a href=\"" + sUrl + "1\" title='第 1 页'>|&lsaquo;</a> ");
	document.write("<a href=\"" + sUrl + i + "\" title='上一页(第 " + i + " 页)'>&lsaquo;&lsaquo;</a> ");
	for(i=Math.max(1,iPage-5);i<iPage;i++){
		document.write("<a href=\""+sUrl + i + "\" title='第 " + i + " 页'><b>" + i + "</b></a> ");
	}
	document.write("<span class=\"current\">" + iPage + "</span> ");
	for(i=iPage+1;i<=Math.min(iCount,iPage+5);i++){
		document.write("<a href=\""+sUrl + i + "\" title='第 " + i + " 页'><b>" + i + "</b></a> ");
	}
	i=Math.min(iCount,iPage+1);
	//if(iCount>iPage+5) document.write("<span style='font-size:8px'>···</span> ");
	document.write("<a href=\"" + sUrl + i + "\" title='下一页(第 " + i + " 页)'>&rsaquo;&rsaquo;</a> ");
	document.write("<a href=\"" + sUrl + iCount + "\" title='最后一页(第 " + iCount + " 页)'>&rsaquo;|</a> ");
}
//消息提示层样式表
function tips_pop(){
var MsgPop=document.getElementById("winpop");//获取窗口这个对象,即ID为winpop的对象
var popH=parseInt(MsgPop.style.height);//用parseInt将对象的高度转化为数字,以方便下面比较
if (popH==0){         //如果窗口的高度是0
MsgPop.style.display="block";//那么将隐藏的窗口显示出来
show=setInterval("changeH('up')",2);//开始以每0.002秒调用函数changeH("up"),即每0.002秒向上移动一次
}
else {         //否则
hide=setInterval("changeH('down')",2);//开始以每0.002秒调用函数changeH("down"),即每0.002秒向下移动一次
}
}
function changeH(str) {
var MsgPop=document.getElementById("winpop");
var popH=parseInt(MsgPop.style.height);
if(str=="up"){     //如果这个参数是UP
if (popH<=100){    //如果转化为数值的高度小于等于100
MsgPop.style.height=(popH+4).toString()+"px";//高度增加4个象素
}
else{
clearInterval(show);//否则就取消这个函数调用,意思就是如果高度超过100象度了,就不再增长了
}
}
if(str=="down"){
if (popH>=4){       //如果这个参数是down
MsgPop.style.height=(popH-4).toString()+"px";//那么窗口的高度减少4个象素
}
else{        //否则
clearInterval(hide);    //否则就取消这个函数调用,意思就是如果高度小于4个象度的时候,就不再减了
MsgPop.style.display="none";  //因为窗口有边框,所以还是可以看见1~2象素没缩进去,这时候就把DIV隐藏掉
}
}
}
function GetString(form){
var param =[];var cname = [];var oEditorName = [];var oEditor = [];
for   (var   i=0;i<document.forms[form.name].elements.length;i++){ 
	var e = document.forms[form.name].elements[i] ;
	switch (e.type){		
	//编辑器
	case "textarea" :
	if($(e.name).style.display=="none"){
		oEditor = new Array(FCKeditorAPI.GetInstance(e.name).GetXHTML(true)); 	
		param.push(e.name+ "=" +escape(oEditor))
	}else{
		param.push(e.name + "=" + escape(e.value))
	}
	break;	
	//单选
	case "radio":
	if(e.checked){param.push(e.name + "=" + escape(e.value));};break;
	//多选框
	case "checkbox":
	if(e.checked == false){param.push(escape(e.name) +"=0");}
	if(e.checked){param.push(escape(e.name)+"="+escape(e.value));};break;
	//
	case "select-one":
	for(var j=0;j<e.options.length;j++){
	if(e.options[j].selected){
	param.push(e.name + "=" + escape(e.options[j].value));
	}
	}
	break;
	case "select-multiple":
	for(var j=0;j<e.options.length;j++){
		param.push(e.name + "=" +escape(e.options[j].value))
		};break;
	
	default:
	param.push(e.name + "=" + escape(e.value));
	}
}
return param.join("&");
}
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;
          }
        }
      /*else{
        ImgD.src="";
        ImgD.alt=""
        }*/
      } 
function chktousu(form){
var title = document.form2.title;
var content = document.form2.content;
if(title.value=="" || title.value.length>20){
	alert("请输入标题,不能大于20个字");
	title.focus();
	return false
}
if(content.value==""){
	alert("请输入内容,不能大于200个字");
	content.focus();
	return false
}
return true
}
//##########################################
//#发送数据
//##########################################
function AjaxSave(form,action,isfunction,IsParam,IsRefresh){	
	if(isfunction==false){return false}
   	var Ajax=new AJAX();	
	Ajax.method="POST";
	Ajax.URL="Ajax.asp?Action="+action+"";
	Ajax.content=GetString(form);
	Ajax.callback=function($HTTP){
	if($HTTP.readyState == 4){
	if($HTTP.status == 200){  
	var ss=unescape($HTTP.responseText);
	theerr=ss.split('|')[0];	
	themsg=ss.split('|')[1];

	if(theerr=="no"){alert("错误")}
	if(theerr=="yes"){

	alert(themsg)	
		
	}else{alert("您所请求的页面有异常。");} 
	}
}
	}
	Ajax.send(null);	
}	  
//##########################################
//#打开上传盒子
//##########################################
function OpenUpload(theid){
if ($(theid).style.display == "none") {
$(theid).style.display = "";
var o=$(theid);
o.style.display="block";
o.style.top =(((document.body.scrollHeight-$(theid).offsetHeight) /2)-50)+"px";
o.style.left=((document.body.scrollWidth-$(theid).offsetWidth) /2)+"px";
}else{$(theid).style.display = "none";}
}



function display(ID){
	if ($(ID).style.display == "none"){
		$(ID).style.display="";
	}else{
	    $(ID).style.display="none";
	}
}
