﻿var chatLayer
var divstate=true
var cssob=document.createElement("link")
cssob.setAttribute("href","chat/media/css.css")
cssob.setAttribute("rel","stylesheet")
cssob.setAttribute("type","text/css")
var myhead=document.getElementsByTagName("head")
myhead[0].appendChild(cssob)

var bodybox=document.getElementsByTagName("body")
var chatbox=document.createElement("div")
chatbox.setAttribute("id","chatbox")
bodybox[0].appendChild(chatbox)
function showchatbox()
{
chatbox.innerHTML="<div id='chatboxtop'><a href='#' onclick='openwindow()'>Inquire form</a><a href='#' onclick='closewindow()'>Close</a></div><div id='chatmessage'><a href='#' onclick='openwindow()' style='color:red'>Click here to contact us</a></div>"
}
showchatbox()
function hiddenchatbox()
{
	chatbox.innerHTML="<div id='chatboxtop'><a href='#'>Inquire form</a><a href='#' >Close</a></div><div id='chatmessage'><a href='#' style='color:red'>Click here to contact us</a></div>"
	}
//关闭窗口
function closewindow()
{
chatbox.innerHTML=""
chatbox.style.cssText="background:none;border:none;height:0px;width:0px;"
divstate=false
}
var scrollPos
var nowheight
var xScroll
xScroll=window.screen.width-300
yScroll=window.screen.availHeight-300
chatbox.style.cssText="position:absolute; top:"+yScroll+"px; left:"+xScroll+"px;"
window.onscroll = function()
{
	if(divstate==true)
	{

		if (typeof window.pageYOffset != 'undefined') {
	   scrollPos = window.pageYOffset;
		}
		else if (typeof document.compatMode != 'undefined' &&
					 document.compatMode != 'BackCompat') {
		   scrollPos = document.documentElement.scrollTop;
		}
		else if (typeof document.body != 'undefined') {
				   scrollPos = document.body.scrollTop;
		}
		nowheight=scrollPos+yScroll
		chatbox.style.cssText="position:absolute; top:"+nowheight+"px; left:"+xScroll+"px;"
	}
}

function closechatbox()
{
chatLayer.innerHTML=""
chatLayer.style.cssText="width:0px;height:0px;"
showchatbox()
}

function openwindow()
{
openwindow_x=(xScroll/2)-100
chatLayer=document.createElement("div")
chatLayer.style.cssText="height:520px;width:500px;position:absolute; top:"+nowheight+"px;left:"+openwindow_x+"px; background:#fff;text-align:center;border:2px solid #999;"
var getframe=document.createElement("iframe")
getframe.setAttribute("width","460")
getframe.setAttribute("height","500")
getframe.setAttribute("scrolling","no")
getframe.setAttribute("frameBorder","0")
getframe.setAttribute("src","feedback/index.html")
var closewindow=document.createElement("div")
closewindow.innerHTML="<a href='#' id='closewindow' onclick='closechatbox()'>Close&nbsp;&nbsp;&nbsp;&nbsp;</a>"
chatLayer.appendChild(closewindow)
chatLayer.appendChild(getframe)
document.body.appendChild(chatLayer)
hiddenchatbox()
}
