//create the gbook div..
var messa=document.createElement("div");
messa.id='messa';
messa.style.width="209px";
messa.style.height="27px";
messa.style.overflow="hidden";
messa.style.position="absolute";
//the head of the gbook
var fltitle=document.createElement("div");
fltitle.style.width="209px"; 
fltitle.style.height="30px";
fltitle.style.background="url(/images/messa/hbg.gif)";
fltitle.style.cursor="pointer";
fltitle.onclick=chsize;
fltitle.id='fltitle';
messa.appendChild(fltitle);
//create the form..
var theb=document.createElement("b");
theb.style.cssFloat="left";
theb.style.styleFloat="left";
theb.style.margin="3px 10px";
theb.style.color="#fff";
theb.innerHTML="欢迎给我们留言";
fltitle.appendChild(theb);
var flsign=document.createElement("img");
flsign.src='/images/messa/off.gif';
flsign.style.styleFloat="right";
flsign.style.cssFloat="right";
flsign.style.margin="3px 10px";
flsign.id='flsign';
fltitle.appendChild(flsign);
var mscontent=document.createElement("form");
mscontent.id="mscontent";
mscontent.style.color="#754641";
var msdiv=document.createElement("div");
msdiv.style.width="209px";
msdiv.style.background="url(/images/messa/bg1.gif)";
msdiv.innerHTML="<p class='project_select'>咨询项目:</p><p class='projects'><input type='radio' name='projectId' value='0' />进口食品<input type='radio' name='projectId' value='1' />冰淇淋<input type='radio' name='projectId' value='2' />奶茶<input type='radio' name='projectId' value='3' />全部</p><p style='margin-left:10px;'>留言内容：</p><textarea name='content'>请在此留言,我们会及时联系你</textarea><div id='contacts'><p><img src='/images/messa/name.gif' /><input type='text' name='name' value='请输入姓名'/></p><p><img src='/images/messa/name.gif' /><input type='text' name='media' value='请输入从哪个媒体了解到我们'/></p><p><img src='/images/messa/mobile.gif' /><input type='text' name='mobile' value='请输入您的手机或电话号码'/></p></div>";
var pp=document.createElement("p");
pp.style.width="209px";
pp.style.height="46px";
pp.style.background="url(/images/messa/bbg.gif)";
pp.innerHTML="<input type='button' value='发送' onclick='ajsend()' style='width:66px; height:19px;background:url(/images/messa/send.gif); border:0px; margin:8px 10px;'/> 电话:020-86243488";
mscontent.appendChild(msdiv);
mscontent.appendChild(pp);
messa.appendChild(mscontent);
//set the style for the gbook
var mstyle=document.createElement("style");
mstyle.type="text/css";
var css="#messa textarea {background:#FFFFFF;\
border:1px solid #C57954;\
color:#A39890;\
font-size:12px;\
height:78px;\
overflow:hidden;\
width:185px;\
margin-left:10px;\
}\n\
.project_select{margin-left:10px;}\n\
.projects{margin-left:6px;}\n\
.projects input{margin:0px; width:12px;}\n\
#contacts input {\
border:1px solid #C57954;\
color:#A39890;\
font-size:12px;\
height:17px;\
margin:2px 0px;\
padding:0;\
width:154px;\
}\n\
#messa form p{clear:both;}\n\
#messa form p img{float:left; border:0px; margin-left:10px;}";
if(mstyle.styleSheet){mstyle.styleSheet.cssText=css;}
else{mstyle.innerHTML=css;}
document.body.appendChild(mstyle);
document.body.appendChild(messa);

//initial the size and location..
divheight=parseInt(messa.style.height);
divwidth=parseInt(messa.style.width);
docs=document.documentElement?document.documentElement:document.body;
divtop=parseInt(docs.clientHeight)-divheight;
divleft=parseInt(docs.clientWidth)-divwidth;
//div float right down..
function fldiv(){
divtop=parseInt(docs.clientHeight)-divheight;
divleft=parseInt(docs.clientWidth)-divwidth;
if(document.documentElement)
{
    messa.style.top=divtop+docs.scrollTop+document.body.scrollTop+"px";
}
else
{
    messa.style.top=divtop+docs.scrollTop+"px";
}
messa.style.left=divleft+docs.scrollLeft+"px";
}
fls=window.setInterval("fldiv()",1);
//set the div maximum
function maxdiv(){
if(divheight<252){
divheight+=4;
divtop=parseInt(docs.clientHeight)-divheight;
messa.style.height=divheight+"px";
}
else{
 ismax=true;
 flsign.src="/images/messa/off.gif";
 clearInterval(maxing);
 }
}
//set the div mini
function mindiv(){
if(divheight>27){
divheight-=4;
divtop=parseInt(docs.clientHeight)-divheight;
messa.style.height=divheight+"px";
}
else{
 ismax=false;
 flsign.src="/images/messa/on.gif";
 clearInterval(mining);
 }
}
function chsize(){
if(!ismax){
maxing=window.setInterval("maxdiv()",10);
}else{
mining=window.setInterval("mindiv()",10);
}
}
ismax=false;
fltitle.onclick();

xmlhttp=initajax();
xmlhttp.onreadystatechange=messahand;
function messahand(){
	if(xmlhttp.readyState==4){
		alert(xmlhttp.responseText);
		mscontent.content.value="请在此留言,我们会及时联系你";
		mscontent.name.value="请输入姓名";
		mscontent.media.value="请输入从哪个媒体了解到我们";
		mscontent.mobile.value="请输入您的手机或电话号码";
	}
}
mscontent.content.onfocus=function (){if(this.value=="请在此留言,我们会及时联系你")this.value="";}
mscontent.name.onfocus=function (){if(this.value=="请输入姓名")this.value="";}
mscontent.mobile.onfocus=function (){if(this.value=="请输入您的手机或电话号码")this.value="";}
mscontent.media.onfocus=function (){if(this.value=="请输入从哪个媒体了解到我们")this.value="";}
mscontent.content.onblur=function (){if(this.value=="")this.value="请在此留言,我们会及时联系你";}
mscontent.name.onblur=function (){if(this.value=="")this.value="请输入姓名";}
mscontent.mobile.onblur=function (){if(this.value=="")this.value="请输入您的手机或电话号码";}
mscontent.media.onblur=function (){if(this.value=="")this.value="请输入从哪个媒体了解到我们";}
function ajsend(){
	if(mscontent.content.value==""||mscontent.content.value=="请在此留言,我们会及时联系你"){
		alert("请输入留言");
	}else if(mscontent.name.value==""||mscontent.name.value=="请输入姓名"){
		alert("请输入姓名");
	}else if(/[^0-9]/.test(mscontent.mobile.value)){
		alert("请正确输入您的手机或电话号码");
	}else{
        //alert(mscontent.projectId.length);
        var isChecked = false;
        for(i=0; i<mscontent.projectId.length; i++)
        {
            if(mscontent.projectId[i].checked)
            {
                isChecked=true;
                projectVale = mscontent.projectId[i].value;
            }
        }
        if(isChecked) {
            sendata();
        }else{
            alert("请选择要咨询的项目");
        }
}
}
function sendata(){
	sendstr="content="+mscontent.content.value+"&name="+mscontent.name.value+"&mobile="+mscontent.mobile.value+"&media="+mscontent.media.value+"&projectId="+projectVale;
	xmlhttp.open("post","../../showso.php?fre="+Math.random(),true);
	xmlhttp.setRequestHeader("Content-Type","Application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Cache-Control","no-cache");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(sendstr);
	xmlhttp.onreadystatechange=messahand;
}
