function openLayer(divname){
     //alert("openLayer");
     //创建一个div元素做上面显示的层
// JavaScript Documentfunction openLayer(navi){
     //alert("openLayer");
     //创建一个div元素做上面显示的层
     var popupDiv=createPopupDiv(divname);
     //创建背景层，就是遮罩层，半透明，以使页面失效
     var bodyBack=createBackgroundDiv();
     
     //收工插入到目标元素之后，body下面
     var mybody = document.getElementById("flow");
     insertAfter(popupDiv,mybody);//控制层的顺序
     insertAfter(bodyBack,mybody);
     //弹出层内容
     // if()
}

function createPopupDiv(divname){
 /*   switch (divname)
	{
		case "termOFuse":
			document.write('<!--Term of Use Start--><div id="termOFuse" name="termOFuse" style="float:left;display:none;background-color: #C90;width:600px;height:550px;"> <a onclick="closeLayer(\'termOFuse\');"style="cursor:pointer;text-decoration:none;color:red;float:right;font-size:12px;margin-top:10px;margin-right:20px;">X</a><h2>TERMS OF USE</h2><p style="font-size:14px;">You are free to use the SupaTuna guitar tuner on your own website or blog.</p><p style="font-size:14px;">The only restriction we place upon its use is that you provide a link back to the SupaTuna website on the same page, an example link is shown below.</p><p style="font-size:14px;">Guitar tuner from &lt;a href=&quot;http://www.supatuna.com&quot;&gt;SupaTuna&lt;/a&gt;.</p><p style="font-size:14px;">Copyright (c) 2009 SupaTuna Guitar Tuner</p><div style="margin-top:390px;"><a onclick="closeLayer(\'termOFuse\');" style="cursor:pointer;text-decoration:underline;color:#FFF; font-size:10px;margin-left:250px;">Click here to close</a></div></div><!--Term of Use End-->');
			break;
		case "signUp":
			document.write('<!--Privacy Policy Start--><div id="Privacy_Policy" name="Privacy_Policy" style="float:left;display:none;background-color:#C90;width:600px;height:550px;OVERFLOW-Y:auto;"> <a onclick="closeLayer(\'Privacy_Policy\');" style="cursor:pointer;text-decoration:none;color:red;float:right;font-size:12px;margin-top:10px;margin-right:20px;">X</a><h2>PRIVACY POLICY</h2>    <p>This privacy policy applies to the use of www.supatuna.com</p>    <p>We highly value your privacy and make this policy easily available throughout our site to assist you in understanding the handling of information in the course of using this site. </p>    <h2>Log Files and Cookies</h2>    <p>This website utilizes industry standard analytics packages which gathers limited information on visitors to our website automatically, and stores this anonymous information in server log files. This information may include IP addresses, browser type, basic IP information, referring pages, operating system used and date/time stamps. This information does not identify individual users; it is used only for site administration, as well as for analysis of website usage and trends.</p>    <p>Additionally, cookies may be used to provide easier and faster access to website features such as logins and/or repeat visits.&nbsp; Cookies are very small text files that are stored on personal computers for reference purposes. We do not link the information we store in cookies to any personally indentifiable information you have submitted while on our site.</p>    <p>We use both session ID cookies and persistent cookies. A session cookie expires when your browser is closed, and a persistent cookie may stay on your hard drive for an extended period. Session cookies make it easier for you to navigate our site; persistent cookies can perform such activities as storing your password for forums or blogs so you do not have to sign in every time you visit those areas, and/or may be used to enable us to track and target the interests of our users so as to enhance the overall experience of using our site.</p>    <p>We have no access to or administration abilities over any cookies that are used by any advertisers on our site.&nbsp;&nbsp;&nbsp; </p>    <h2>Links to Other Websites</h2>    <p>This website may contain links to other sites that are not controlled in any way by us. Please be aware of this when you click on any such links; we are not responsible for the privacy practices and/or policies of any website other than our own. Consequently, we strongly suggest that you review the privacy policy of every website you visit, whether or not they are linked to by our own site.</p>    <h2>Registration and Use of Personal Information</h2>    <p>Registration is not required in order to use or access this website. However, this site may make forums, blogs, message boards or similar available to its users. You may be required to register for these features, particularly if you wish to leave comments or provide articles. </p>    <p>If you do register, and in the process provide us with personally identifiable information, rest assured that any such information you provide will not be shared with any third-party organization except with your express consent. </p>    <p>Please note that if you post comments or articles to any forum, blog or message board on this site, any personally identifiable information you provide in those comments or articles may be read, collated and used by anyone viewing them. As such, we are not responsible for personally identifiable information you may choose to make available through these channels.</p>    <p>We also provide visitors to our website the opportunity to opt-in to receive communications from us.&nbsp; In this case, we ask the visitor for his or her email address and name. These communications will include our regular newsletter, product promotions and any other information that we feel may be pertinent to the visitor. You may opt out of receiving any, or all, of these communications by emailing us at <a href="mailto:newsletter@supatuna.com">newsletter@supatuna.com</a>, or clicking on the ‘unsubscribe’ link in any email we send to you, by replying to any email we send you and entering the word UNSUBSCRIBE in the subject line.</p>    <p>Again, if you provide us with your email address and/or name for the purposes of receiving communications from us, this information will not be shared with any third-party organization except with your express consent.</p> <h2>Access to Personally Identifiable Information</h2>    <p>If your personally identifiable information changes, or if you no longer wish us to possess your information, you may request correction, updating, or deletion of your information by emailing us at <a href="mailto:newsletter@supatuna.com">newsletter@supatuna.com</a>; you also may make your request by phone or postal mail at the address/phone number indicated at the end of this privacy policy.</p>    <h2>Security</h2>    <p>We follow accepted industry standards to protect any personal information you have provided to us. However, please be aware that no method of electronic storage can ever be 100% secure. Therefore as is the case with any organization - we are not in a position to guarantee the absolute security of your information. </p>    <p>You may submit any questions you may have about our security procedures by emailing us at newsletter@supatuna.com </p>    <h2>Links to Other Websites</h2>    <p>This website may contain links to other sites that are not controlled in any way by us. Please be aware of this when you click on any such links; we are not responsible for the privacy practices and/or policies of any website other than our own. Consequently, we strongly suggest that you review the privacy policy of every website you visit, whether or not they are linked to by our own site.</p>    <h2>Legal Disclaimer</h2>    <p>We reserve the right to disclose your personally identifiable information as required by law and when we believe that disclosure is necessary to protect our rights and/or to comply with a judicial proceeding, court order or legal process served on our website.</p>    <h2>Contact Details</h2>    <p>If you have any questions or concerns regarding this privacy policy, or you wish to contact us by phone or postal mail, our contact information is as follows:</p>    <p><a href="mailto:newsletter@supatuna.com">newsletter@supatuna.com</a></p>    <p>SupaTuna c/o Clear Brand Essence Limited<br />      90 Long Acre<br />      London<br />      WC2E 9RZ</p>    <p>+44 (0)1455 844 827</p>    <p>This privacy policy was last updated on April 6th 2009.</p>    <div style="margin-top:20px;margin-bottom:10px;"><a onclick="closeLayer(\'Privacy_Policy\');" style="cursor:pointer;text-decoration:underline;color:#FFF; font-size:10px;margin-left:250px;">Click here to close</a></div>  </div>  <!--Privacy Policy End-->');
			break;
	}
 	*/
	var popupDiv = document.getElementById(divname);
   // var popupDiv = document.createElement("div");
     //给这个元素设置属性与样式

     //popupDiv.setAttribute("id","maskdiv")
     popupDiv.style.display="block";
     popupDiv.style.border = "1px solid #ccc";
     popupDiv.style.width = "600px";
     popupDiv.style.height = "550px";
     popupDiv.style.background = "#e14407";
     popupDiv.style.zIndex =2;
     popupDiv.style.position = "absolute";
 	 //popupDiv.style.filter = "alpha(opacity=80)";
     //popupDiv.style.opacity = 0.8;

     //让弹出层在页面中垂直左右居中
     var arrayPageSize = getPageSize();
     var arrayPageScroll = getPageScroll();
     //alert(arrayPageScroll);
     //alert(arrayPageSize);

     popupDiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 400) / 2) + 'px') ;
     popupDiv.style.left = (((arrayPageSize[0] - 20 - 600) / 2) + 'px');
     return popupDiv;
    }
function createBackgroundDiv(){
     var bodyBack = document.createElement("div");
     bodyBack.setAttribute("id","bodybg")
     bodyBack.style.width = "100%";
     bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
     bodyBack.style.zIndex = 1;
     bodyBack.style.position = "absolute";
     bodyBack.style.top = 0;
     bodyBack.style.left = 0;

     bodyBack.style.filter = "alpha(opacity=50)";
     bodyBack.style.opacity = 0.5;
     bodyBack.style.background = "#000";
     //bodyBack.style.background = "#ccc";
     return bodyBack;
}   
   

//元素插入另一个元素之后
function insertAfter(newElement, targetElement){
      var parent = targetElement.parentNode;
      if(parent.lastChild == targetElement){
         parent.appendChild(newElement);
      }else{
         parent.insertBefore(newElement, targetElement.nextSibling);
    }
}
//获取滚动条的高度
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 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;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}
//关闭弹出层
function closeLayer(divname){//----------------------need edit！
     document.getElementById(divname).style.display = "none";
     document.getElementById("bodybg").style.display = "none";
     return false;
}
//拖动函数
function mousedown(e){
    var obj = document.getElementById("popupAddr");
    var e = window.event ? window.event : e;

    obj.startX = e.clientX - obj.offsetLeft;
    obj.startY = e.clientY - obj.offsetTop;


    document.onmousemove = mousemove;
    var temp = document.attachEvent ? document.attachEvent("onmouseup",mouseup) : document.addEventListener("mouseup",mouseup,"");
}
function mousemove(e){
    var obj = document.getElementById("popupAddr");
    var e = window.event ? window.event : e;

    with(obj.style){
    left = (e.clientX - obj.startX)<10 ? 10 : (e.clientX - obj.startX) + "px";
    top = (e.clientY - obj.startY)<10?10:(e.clientY - obj.startY) + "px";
}
}
function mouseup(e){
    var e = window.event ? window.event : e;
    var obj = document.getElementById("popupAddr");
    var currentX=e.clientX - obj.startX;
    var currentY=e.clientY - obj.startY;
    //让弹出层在页面中垂直左右居中
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
    //alert(arrayPageScroll);
    //alert(arrayPageSize);

    //popupDiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 400) / 2) + 'px') ;
    //popupDiv.style.left = (((arrayPageSize[0] - 20 - 600) / 2) + 'px');
    //alert(arrayPageSize[1]);
    var maxX=arrayPageSize[0]-600-24;
    var maxY=arrayPageScroll[1] +((arrayPageSize[3] - 400));

    if(currentX>maxX){
    obj.style.left=maxX-10 + "px";
    }
    if(currentY>maxY){
    obj.style.top=maxY-10 + "px";
    }
    document.onmousemove = "";
    var temp = document.detachEvent ? document.detachEvent("onmouseup",mouseup) : document.addEventListener("mouseup",mouseup,"");
    }