
function popfriend(){
  var msgw,msgh,bordercolor;
  msgw=540;//pop window width
  msgh=310;//pop window height

  var sWidth,sHeight; //body width and height
  if(document.all){ //for IE
  	sWidth=document.body.scrollWidth;
  }else{
  	sWidth=window.document.documentElement.scrollWidth - 18;
  }
  sHeight=screen.height;


  var bgObj=document.createElement("div");//the gray background
  bgObj.setAttribute('id','bgDiv');
  bgObj.style.position="absolute";
  bgObj.style.top="0";
  bgObj.style.background="#777";
  bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  bgObj.style.opacity="0.6";
  bgObj.style.left="0";
  bgObj.style.width=sWidth + "px";
  bgObj.style.height=sHeight + "px";
  bgObj.style.zIndex = "10000";
  document.body.appendChild(bgObj);//append the gray bg div to body


  var msgObj=document.createElement("div")//the pop div

  msgObj.setAttribute("id","msgDiv");
  msgObj.setAttribute("align","center");
  msgObj.className = "pop-form-dialog";
  msgObj.style.left = "25%";
  msgObj.style.top = "30%";
  msgObj.style.width = msgw + "px";
  msgObj.style.height =msgh + "px";

  var button=document.createElement("input");//the sumbit btn
  button.setAttribute("type","image");
  button.setAttribute("src","images/send_frined_btn.gif");
  button.style.border = "none";
  button.style.width = "152px";
  button.style.height = "29px";
  button.style.marginTop = "128px";
  button.style.marginLeft = "0px";
  button.onclick=submitForm;
  
  var closeBtn=document.createElement("input");//the close btn
  closeBtn.setAttribute("type","image");
  closeBtn.setAttribute("src","images/close.jpg");
  closeBtn.style.border = "none";
  closeBtn.style.width = "95px";
  closeBtn.style.height = "27px";
  closeBtn.style.marginTop = "128px";
  closeBtn.style.marginLeft = "0px";
  closeBtn.onclick=closeWin;
  

 
  
  function closeWin(){

	document.body.removeChild(bgObj);//remove the gray bg
    document.body.removeChild(msgObj);//remove the pop window
  }
  




  document.body.appendChild(msgObj);//append the pop window
  
  var formDiv = document.createElement("DIV");
  formDiv.className="pop-form-div";
  var formLeftDiv = document.createElement("DIV");
  formLeftDiv.className="pop-form-left";
  var formRightDiv = document.createElement("DIV");
  formRightDiv.className = "pop-form-right";
  formDiv.appendChild(formLeftDiv);
  formDiv.appendChild(formRightDiv);
  msgObj.appendChild(formDiv);

  var lbYourName = createLabel("Your Name");
  var lbFriendName = createLabel("Friend's Name");
  var lbYourEmail = createLabel("Your Email");
  var lbFriendEmail = createLabel("Friend's Email");
  
  
  var lbComments = createLabel("Comments");
  
  var tbYourName = createTextbox("yourName");
  var tbFriendName = createTextbox("friendName");
  var tbYourEmail = createTextbox("yourEmail");
  var tbFriendEmail = createTextbox("friendEmail");
  
  
  var taComments = createTextarea("comments");
  
  var msgDivEl = document.getElementById("msgDiv");
  
  formLeftDiv.appendChild(lbYourName);
  formLeftDiv.appendChild(tbYourName);
  formLeftDiv.appendChild(lbYourEmail);
  formLeftDiv.appendChild(tbYourEmail);
  formLeftDiv.appendChild(lbComments);
  formLeftDiv.appendChild(taComments);
  
  formRightDiv.appendChild(lbFriendName);
  formRightDiv.appendChild(tbFriendName);
  formRightDiv.appendChild(lbFriendEmail);
  formRightDiv.appendChild(tbFriendEmail);
  
  formRightDiv.appendChild(button);
  formRightDiv.appendChild(closeBtn);
 

  var req;
  function sendRequest(url,params,httpMethod){
	  if(!httpMethod){
		  httpMethod = "POST";
	  }
	  req = FactoryXMLHttpRequest();
	  if(req){
		  req.onreadystatechange = onReadyStateChange;
		  req.open(httpMethod,url,true);
		  if(httpMethod=="POST"){
		  	//Send the proper header information along with the request, add by tony
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			req.setRequestHeader("Content-length", params.length);
			req.setRequestHeader("Connection", "close");
		  }
		  req.send(params);
	  }
  }
  
  function onReadyStateChange(){
	  var ready = req.readyState;
	  if(ready==4){
		  alert("Your email was sent. Thank you!");
	  }
  }
  
  function submitForm(){//the submit click event
     var url="mail.php";
	 //validate
	 var info;
	 var yourNameValue = trim(tbYourName.value);
	 if(yourNameValue.length==0){
		lbYourName.className = "error";
		tbYourName.className = "error";
		 return ;
	 }else{
		 lbYourName.className = "";
		tbYourName.className = "";
	 }
	 var friendNameValue = trim(tbFriendName.value);
	 if(friendNameValue.length==0){
		 lbFriendName.className = "error";
		tbFriendName.className = "error";
		 return ;
	 }else{
		  lbFriendName.className = "";
		tbFriendName.className = "";
	 }
	 
	 var yourEmailValue=trim(tbYourEmail.value);
	 info = IsValidEMailAddress(yourEmailValue)
	 if(info.ReturnCode!=0){
		 lbYourEmail.className = "error";
		 tbYourEmail.className = "error";
		 return ;
	 }else{
		  lbYourEmail.className = "";
		 tbYourEmail.className = "";
	 }
	 var friendEmailValue=trim(tbFriendEmail.value);
	 info = IsValidEMailAddress(friendEmailValue)
	 if(info.ReturnCode!=0){
		 lbFriendEmail.className = "error";
		 tbFriendEmail.className = "error";
		 return ;
	 }else{
		  lbFriendEmail.className = "";
		 tbFriendEmail.className = "";
	 }
	 
	 
	 
	 var params = "yourName="+yourNameValue+"&friendName="+friendNameValue+"&yourEmail="+yourEmailValue+"&friendEmail="+friendEmailValue+"&comments="+taComments.value+"&form=taf";
	 sendRequest(url,params);
	 closeWin();

  }
}