﻿var MyWin = new Win();
var imgfile = "/static/images/popup/";
var imgname=new Array();
var img = new Array();
//预先加载图片
imgname[0] = imgfile+"clo.gif";
imgname[1] = imgfile+"b1.png";
imgname[2] = imgfile+"l1.png";
imgname[3] = imgfile+"l2.png";
imgname[4] = imgfile+"r1.png";
imgname[5] = imgfile+"r2.png";
imgname[6] = imgfile+"t1.png";
imgname[7] = imgfile+"t2.png";
imgname[8] = imgfile+"t3.png";
for (i=0;i<=imgname.length-1;i++)
{
   img[i] = new Image();
   img[i].src = imgname[i];
}
var zIndex = 0;
var Winid  = 0;
var Ie = /msie/i.test(navigator.userAgent);
function $(Id){return(document.getElementById(Id))}
function Win()
{
 this.Create = function(mask,title, wbody, w, h, l, t,o)
 {
  Winid++;
  mask = mask;
  title = title || "";
  wbody = wbody || " <p align='center'>正在载入…</p>";
  var winH=getPageSize();
  w = w || winH[2];
  h = h || winH[3];
  cw = document.documentElement.clientWidth;
  ch = document.documentElement.clientHeight;
  sw = document.documentElement.scrollWidth;
  sh = document.documentElement.scrollHeight;
	st = (document.documentElement.scrollTop || document.body.scrollTop);
  if (w > cw) ww = 0;
  else ww = (cw - w)/2;
  if (h > ch) hh = 0;
  else hh = (st + (ch - h)/2);
  l = l || ww;
  t = t || hh;
  o = o || 0.9;
  if (mask != "no"){
    var ndiv = document.createElement("DIV");
    ndiv.setAttribute("id", "ndiv"+ Winid);
    ndiv.style.cssText = "width:"+ sw +"px;height:"+ sh +"px;left:0px;top:0px;position:absolute;overflow:hidden;background:#000;filter:alpha(opacity="+o*100+");opacity:"+o+";-moz-opacity:"+o+";";
    document.body.appendChild(ndiv);
    if (Ie) {
      var niframe = document.createElement("iframe");
      niframe.style.width = sw;
      niframe.style.height = sh;
      niframe.style.top = "0px";
      niframe.style.left = "0px";
      niframe.style.visibility = "inherit";
      niframe.style.filter = "alpha(opacity=0)";
      niframe.style.position = "absolute";
      niframe.style.zIndex = -1;
      ndiv.insertAdjacentElement("afterBegin",niframe);
    }
  }
  var mywin = document.createElement("DIV");
  mywin.setAttribute("id", "win"+ Winid);
  mywin.style.cssText = "width:"+ w +"px;height:"+ h +"px;left:0px;top:0px;position:absolute;overflow:hidden;padding:0px;font-family:Arial, 宋体";
  mywin.style.zIndex = ++zIndex;
  document.body.appendChild(mywin);
  var mytie = document.createElement("DIV");
  var myboy = document.createElement("DIV");
  var mybom = document.createElement("DIV");
  mytie.style.cssText = "overflow:hidden;height:30px;font-weight:bold;font-size:14px;width:100%;vertical-align:top;";
  myboy.style.cssText = "overflow:hidden;width:100%";
  mybom.style.cssText = "overflow:hidden;height:30px;width:100%";
  mywin.appendChild(mytie);
  mywin.appendChild(myboy);
  mywin.appendChild(mybom);
  var wintag = [[mytie, 30, 15, "t1"], [mytie, 30, w-30, "t2"], [mytie, 30, 15, "t3"], [myboy, h-45, 15, "l1"], [myboy, h-47, w-32], [myboy, h-45, 15, "r1"], [mybom, 15, 15, "l2"], [mybom, 15, w-30, "b1"], [mybom, 15, 15, "r2"]];
  for (var i = 0; i < 9; i++) {
   var temp = document.createElement("DIV");
   temp.setAttribute("Fid", "win"+ Winid);
   wintag[i][0].appendChild(temp);
   if (wintag[i][3]) {
     temp.style.cssText = "float:left;height:"+ wintag[i][1] +"px;width:"+ wintag[i][2] +"px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgfile+""+wintag[i][3] +".png', sizingMethod='scale');background:url('"+imgfile+""+ wintag[i][3] +".png') !important;background:;";
   }
   else {
    temp.style.cssText = "float:left;filter:alpha(Opacity=95,style=0);opacity:0.95;-moz-opacity:0.95;height:"+ wintag[i][1] +"px;width:"+ wintag[i][2] +"px;background:#f7f7f7;border:1px solid #666;overflow:hidden;padding:0px";
   }
  }
  mytie.childNodes[1].innerHTML = "<div style=\"position:absolute;overflow:hidden;height:15px;top:12px;padding-left:4px;padding-right:4px;\"></div><div style=\"position:absolute;background:url('"+imgfile+"clo.gif');overflow:hidden;width:43px;height:17px;top:7px !important;right:15px\" title=\"关闭窗口\" onclick=\"MyWin.Close('win"+ Winid +"',10); MyWin.ndiv('ndiv"+ Winid +"',10);\"></div>";
  this.Title("win"+ Winid, title);
  this.Body("win"+ Winid, wbody);
  this.Move_e("win"+ Winid, l, t, 0, 0);
  return(mywin);
 }
 this.Title = function(Id, title)
 {
     if (Id == null) return;
     var o = $(Id);
     if (!o) return;
     o.childNodes[0].childNodes[1].childNodes[0].innerHTML = title;
 }
 this.Body = function(Id, wbody)
 {
     if (Id == null) return;
     var o = $(Id);
        if (!o) return;
        if (wbody.slice(0, 4) == "[pg]")
            o.childNodes[1].childNodes[1].innerHTML = "<iframe id=myframe name=myframe onfocus=\"MyWin.Show('"+ Id +"',this)\" src='"+ wbody.slice(4) +"' frameBorder='0' marginHeight='0' marginWidth='0' scrolling='no' width='100%' height='100%'></iframe>";
        else
            o.childNodes[1].childNodes[1].innerHTML = wbody;
 }
 this.Show = function(Id) {
      if (Id == null) return;
      var o = $(Id);
      if (!o) return;
      o.style.zIndex = ++zIndex;
    }
    this.Move_e = function(Id, l , t, ll, tt) {
      if (typeof(window["ct"+ Id]) != "undefined") clearTimeout(window["ct"+ Id]);
      var o = $(Id);
      if (!o) return;
      o.style.left = l +"px";
      o.style.top = t +"px";
      window["ct"+ Id] = window.setTimeout("MyWin.Move_e('"+ Id +"', "+ l +" , "+ t +", "+ ll +", "+ tt +")", 1);
    }
    this.Close = function(Id, Opacity) {
     if (typeof(window["et"+ Id]) != "undefined") clearTimeout(window["et"+ Id]);
     var o = $(Id);
     if (!o) return;
     //if (Opacity == 10) o.childNodes[0].childNodes[1].innerHTML = "";
     //if (Ie) o.style.filter = "alpha(opacity="+ Opacity +",style=0)";
     //else o.style.opacity = Opacity / 10;
     //if (Opacity > 20) Opacity -= 10;
     //else Opacity--;
     //if (Opacity <= 0) {
       if (o.getElementsByTagName("IFRAME").length != 0) o.getElementsByTagName("IFRAME").src = "about:blank";
       o.innerHTML = "";
       document.body.removeChild(o);
       return;
     //}
     window["et"+ Id] = window.setTimeout("MyWin.Close('"+ Id +"', "+ Opacity +")", 1);
    }
    this.ndiv = function(Id, Opacity) {
      var o = $(Id);
      if (!o) return;
      o.innerHTML = "";
      document.body.removeChild(o);
      return;
    }

}

getPageSize = function (){
  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;

	if(windowHeight>720) windowHeight=720;
	if(windowHeight*1.6>windowWidth){windowHeight=windowWidth/1.6;}
	else if(windowWidth/1.6>windowHeight){windowWidth=windowHeight*1.6}
	else{windowWidth=1152;windowHeight=windowWidth/1.6;}
	//if(windowWidth>1152) windowWidth=1152;
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}

//获取参数
function GetQuery(name) {
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r!=null) return unescape(r[2]); return null;
}

//选择模板类别
function mbType(num,type,d){
	if(!d) getlist(num,type);
	for(var id = 0;id<=9;id++)
	{
		if(id==num)
		{
			document.getElementById("qh_con"+id).style.display="block";
			document.getElementById("mynav"+id).className="nav_on";
		}
		else
		{
			if(!document.getElementById("mynav"+id))continue;
			document.getElementById("qh_con"+id).style.display="none";
			document.getElementById("mynav"+id).className="nav_off";
		}
	}
}

//下拉选择
function tp(a,n){
	var d = document.getElementById(a);
	if(n==1)d.style.display='block';
	else d.style.display='none';
}

//*获取模板列表开始*//
var xmlHttp;
var loadtxt = "<br/>";
loadtxt += "<div class=lay-main>";
loadtxt += "<div class=mod-box-a>";
loadtxt += "<b class=r-t><b></b></b>";
loadtxt += "<div class=bc-a>";
loadtxt += "<div class=mbb></div>";
loadtxt += "<div class=con-mb style=\"height:800px;text-align:center;\"><br/><br/><br/><img src=static/images/loading.gif></div>";
loadtxt += "<b class=r-b><b></b></b>";
loadtxt += "</div>";
loadtxt += "</div>";
loadtxt += "<br/>";
function getlist(num,type){
	document.getElementById("mblist").innerHTML=loadtxt;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("浏览器不支持AJAX!");
 		return;
	}
	var url="mb";
	url=url+"?n="+num;  //模板类别
	url=url+"&t="+type;  //是否收费
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById("mblist").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	  // Firefox, Opera 8.0+, Safari
  	xmlHttp=new XMLHttpRequest();
  }catch (e){
  	// Internet Explorer
  	try {
    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
	return xmlHttp;
}
//*获取模板列表结束*//

//企业QQ
function tencent_wpa(uuu,gh,g_corp,useqq,newpop){
	if(parseInt(newpop) == 1){
		var sURL = "http://"+"b3.qq.com"+"/webc.htm?new=0&sid=" + uuu + "&o=" + g_corp + "&q=" + useqq ;
		window.open(sURL,"","height=502px,width=644px,toolbar=no,scrollbars=no,status=no,menubar=no");
		return false;
	}
	if(parseInt(uuu) > 10000 ){
		g_kfuin = parseInt(uuu);
		if(parseInt(useqq) == 7){
			var URL = 'tencent://message/?uin='+ g_kfuin + '&Site=' +g_corp+'&Menu=yes&crm=1';
			this.location.href=URL;
		}
	} else { 
 		alert("您输入的参数有误！");
 		return fase;
	}
}

