
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 - 17 ;
  }
  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 = "30%";
  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_friend_btn.gif");
  button.style.border = "none";
  button.style.width = "166px";
  button.style.height = "28px";
  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 = "66px";
  closeBtn.style.height = "28px";
  closeBtn.style.marginTop = "-28px";
  closeBtn.style.marginLeft = "180px";
  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="thank_you.aspx";
    //reset error display
    lbYourName.style.color = "#987e5c";
    lbFriendName.style.color = "#987e5c";
    lbYourEmail.style.color = "#987e5c";
    lbFriendEmail.style.color = "#987e5c";
    tbYourName.style.background = "#ffffff";
    tbFriendName.style.background = "#ffffff";
    tbYourEmail.style.background = "#ffffff";
    tbFriendEmail.style.background = "#ffffff";
	 
    //validate
    var info;
    var yourNameValue = trim(tbYourName.value);
    if(yourNameValue.length==0){
     alert("Please enter Your Name.");
     tbYourName.focus();
     tbYourName.style.background = "#ffa2a2";
     lbYourName.style.color = "#ff0000";
     return ;
    }
    var friendNameValue = trim(tbFriendName.value);
    if(friendNameValue.length==0){
     alert("Please enter Friend's Name.");
     tbFriendName.focus();
     tbFriendName.style.background = "ffa2a2";
     lbFriendName.style.color = "#ff0000";
     return ;
    }

    var yourEmailValue=trim(tbYourEmail.value);
    info = IsValidEMailAddress(yourEmailValue)
    if(info.ReturnCode!=0){
      alert(info.ErrorDescription);
      tbYourEmail.focus();
      tbYourEmail.style.background = "ffa2a2";
      lbYourEmail.style.color = "#ff0000";
      return ;
    }
    var friendEmailValue=trim(tbFriendEmail.value);
    info = IsValidEMailAddress(friendEmailValue)
    if(info.ReturnCode!=0){
      alert(info.ErrorDescription);
      tbFriendEmail.focus();
      tbFriendEmail.style.background = "ffa2a2";
      lbFriendEmail.style.color = "#ff0000";
    return ;
    }
    
    var params = "yourName="+yourNameValue+"&friendName="+friendNameValue+"&yourEmail="+yourEmailValue+"&friendEmail="+friendEmailValue+"&comments="+taComments.value+"&form=taf";
    
    sendRequest(url,params);
    
    closeWin();

  }
}