//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 style='margin-left:10px;'>留言内容：</p><input type='hidden' name='projectId' value='0' /><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<239){
        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(!mscontent.mobile.value.isMobile() && !mscontent.mobile.value.isTel()){
	//	alert("请正确输入您的手机或电话号码");
	//}else{
	}else if(mscontent.mobile.value==""){
		alert("请正确输入您的手机或电话号码");
	}else{
        sendata();
    }
}
function sendata(){
    sendstr="content="+mscontent.content.value+"&name="+mscontent.name.value+"&mobile="+mscontent.mobile.value+"&media="+mscontent.media.value+"&projectId="+mscontent.projectId.value;
    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;
}
//判断固话手机号码
String.prototype.Trim = function() { 
var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/); 
return (m == null) ? "" : m[1]; 
}

String.prototype.isMobile = function() { 
return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(this.Trim())); 
}

String.prototype.isTel = function()
{
    //"兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3位)"
    //return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
    return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(this.Trim()));
}

