// JavaScript Document
var isIe=(document.all)?true:false;
var FF = (navigator.userAgent.indexOf("Firefox")>0) ? 1 : 0;
var b_version=navigator.appVersion;
var version=b_version.split(";");
var trim_Version=version[1].replace(/[ ]/g,"");
var IE7 = (trim_Version=="MSIE7.0") ? 1 : 0;
var IE6 = (trim_Version=="MSIE6.0") ? 1 : 0;
//设置select的可见状态
function setSelectState(state){
    var objl=document.getElementsByTagName('select');
    for(var i=0;i<objl.length;i++){
        objl[i].style.visibility=state;
    }
}

//弹出方法
function showMessageBox(wTitle,content,wWidth,wHeight){
    closeWindow();
    var bWidth=parseInt(document.documentElement.scrollWidth);
    var bHeight=parseInt(document.documentElement.scrollHeight);
    //var ctop = parseInt(document.documentElement.clientHeight);
    var sTop = parseInt(document.documentElement.scrollTop);
    var sLeft = parseInt(document.documentElement.scrollLeft);
    var bTop = 0;

    if (FF == 0 && IE7 == 0){       
        bTop =(( parseInt(screen.availHeight)-wHeight) / 2 ) + sTop;
        bLeft = (( parseInt(screen.availWidth)-wWidth) / 2 ) + sLeft;
    }
    else{
        bTop =(window.screen.availHeight-wHeight)/2;
        bLeft = (window.screen.availWidth-wWidth)/2;
    }
    
    if(isIe){
        setSelectState('hidden');
    }
  
    var back=document.createElement("div");
    back.id="back";
    var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
    styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
    back.style.cssText=styleStr;
    document.body.appendChild(back);
    showBackground(back,40);
  
    var mesW=document.createElement("div");
    mesW.id="mesWindow";
    mesW.className="mesWindow";
    mesW.innerHTML="<div  class='mesWindowTop'><table width='100%' height='100%'><tr><td>&nbsp;</td><td style='width:1px;'><input id='btn_mesw_close' name='btn_mesw_close' type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /><input id='btn_mesw_close2' name='btn_mesw_close2' type='button' onclick='closeWindow2();' title='关闭窗口' class='close' value='关闭' style='display: none;' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
    styleStr="left:"+(bLeft)+"px;top:"+(bTop)+"px ;width:"+wWidth+"px;";
    mesW.style.cssText=styleStr;
    document.body.appendChild(mesW);
}

//修改：把关闭文字改成图形
function showMessageBox1(wTitle,content,wWidth,wHeight){
    closeWindow();
    var bWidth=parseInt(document.documentElement.scrollWidth);
    var bHeight=parseInt(document.documentElement.scrollHeight);
    //var ctop = parseInt(document.documentElement.clientHeight);
    var sTop = parseInt(document.documentElement.scrollTop);
    var sLeft = parseInt(document.documentElement.scrollLeft);
    var bTop = 0;

    if (FF == 0 && IE7 == 0){
        bTop =(( parseInt(screen.availHeight)-wHeight) / 2 ) + sTop;
        bLeft = (( parseInt(bWidth)-wWidth) / 2 ) + sLeft;
    }
    else{
        bTop =(screen.availHeight-wHeight)/2;
        bLeft = (bWidth-wWidth)/2;
    }

    if(isIe){
        setSelectState('hidden');
    }

    var back=document.createElement("div");
    back.id="back";
    var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
    styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
    back.style.cssText=styleStr;
    document.body.appendChild(back);
    showBackground(back,40);

    var mesW=document.createElement("div");
    mesW.id="mesWindow";
    mesW.className="mesWindow";
    mesW.innerHTML="<div  class='mesWindowTop'><table width='100%' height='100%'><tr><td>&nbsp;</td><td style='width:1px;'> <img id='btn_mesw_close' name='btn_mesw_close' src='/img/2duauction/main_pic/icon_close.gif' alt='关闭' width='15' height='13' style='cursor:pointer;' onclick='closeWindow();'><img id='btn_mesw_close2' name='btn_mesw_close2' src='/img/2duauction/main_pic/icon_close.gif' alt='关闭' width='15' height='13' style='cursor:pointer; display: none;' onclick='closeWindow2();'></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
    styleStr="left:"+(bLeft)+"px;top:"+(bTop)+"px ;width:"+wWidth+"px;";
    mesW.style.cssText=styleStr;
    document.body.appendChild(mesW);
}

//让背景渐渐变暗
function showBackground(obj,endInt){
    if(isIe){
        obj.filters.alpha.opacity+=1;
        if(obj.filters.alpha.opacity<endInt){
            setTimeout(function(){
                showBackground(obj,endInt)
            },5);
        }
    }else{
        var al=parseFloat(obj.style.opacity);al+=0.01;
        obj.style.opacity=al;
        if(al<(endInt/100)){
            setTimeout(function(){
                showBackground(obj,endInt)
            },5);
        }
    }
}

//关闭窗口
function closeWindow(){
    if(document.getElementById('back')!=null){
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if(document.getElementById('mesWindow')!=null){
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if(isIe){
        setSelectState('');
    }
}

//关闭窗口 自动刷新
function closeWindow2(){
    if(document.getElementById('back')!=null){
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if(document.getElementById('mesWindow')!=null){
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }
    if(isIe){
        setSelectState('');
    }
    document.location.href = document.location.href.replace("#","");    
}

//弹出浮动窗口
function showSimplewindow(ev,url,width,height){
    var dwidth = '';
    var dheight = '';
    if (width == '')
        dwidth = '600'
    else  dwidth = width;

    if (height == '')
        dheight = '400px'
    else  dheight = height;
    messContent="<iframe frameborder=0 width='98%' height='"+dheight+"' src='"+url+"'></iframe>";
    showMessageBox(1,messContent,dwidth,dheight);
}

function showSimplewindow1(ev,url,width,height){
    var dwidth = '';
    var dheight = '';
    if (width == '')
        dwidth = '600'
    else  dwidth = width;

    if (height == '')
        dheight = '400px'
    else  dheight = height;
    messContent="<iframe frameborder=0 width='98%' height='"+dheight+"' src='"+url+"'></iframe>";
    showMessageBox1(1,messContent,dwidth,dheight);
}

function setCookie( name, value, expiredays ){ 
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
} 

function getCookie(name) {
    var Found = false;
    var start, end;
    var i = 0;
    while(i <= document.cookie.length){
        start = i;
        end = start + name.length;
        if(document.cookie.substring(start, end) == name) {
            Found = true;
            break;
        }
        i++;
    }
	
    if(Found == true) {
        start = end + 1;
        end = document.cookie.indexOf(";", start);
        if(end < start)
            end = document.cookie.length;
        return document.cookie.substring(start, end);
    }
	
    return "";
}

function loadWin(){
    var eventCookie=getCookie("noWin");
    if (eventCookie != "done") {
        testMessageBox(event);
    }
}

function closeWin(){ 
    setCookie("noWin", "done" , 1);
}

