
function popWin(){
	
	//formatting the popup window
  var msgw,msgh,bordercolor;
  msgw=540;//pop window width
  msgh=410;//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;
  }
  sHeight=1.2*screen.height;
  window.scrollTo(sWidth/2, 0);

  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";
  bgObj.style.paddingLeft = "30px";
  document.body.appendChild(bgObj);//append the gray bg div to body

//the creation of the popup box
  var msgObj=document.createElement("div")//the pop div

  msgObj.setAttribute("id","msgDiv");
  msgObj.setAttribute("align","center");
  msgObj.className = "pop-form-dialog";
  msgObj.style.left = "35%";
  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/about_btn_3.jpg");
  button.style.border = "none";
  button.style.width = "259px";
  button.style.height = "22px";
  button.style.marginTop = "30px";
  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 = "90px";
  closeBtn.style.height = "20px";
  closeBtn.style.marginTop = "35px";
  closeBtn.style.marginLeft = "82px";
  closeBtn.onclick=closeWin;
//  
//  var calenderBtn=document.createElement("input");//the calender btn
//  calenderBtn.setAttribute("type","image");
//  calenderBtn.setAttribute("src","images/calendar.jpg");
//  calenderBtn.style.border = "none";
//  calenderBtn.className="calendar";
//  calenderBtn.style.float = "left";
 
  
  function closeWin(){
	document.body.removeChild(bgObj);//remove the gray bg
    document.body.removeChild(msgObj);//remove the pop window
  }
  
  //not sure what's happening here  
  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 lbFullName = createLabel("Full Name");
  var lbCity = createLabel("City");
  var lbState = createLabel("State");
  var lbAge = createLabel("Age of your child(ren)");
  var lbLanguage = createLabel("Language of interest");
  var lbEmailAddress = createLabel("Email Address");
  var lbPhoneNumber = createLabel("Phone number");
  var lbhearus = createLabel("How did you hear about us?");
  
//var internet = new Array("poodle","puli","greyhound");
//var inprint = new Array("trout", "mackerel", "bass");
//var anotherway = new Array("robin", "hummingbird", "crow");

  
  var tbFullName = createTextbox("fullName");
  var tbCity = createTextbox("city");
  var tbState = createTextbox("state");
  var tbAge = createTextbox("age");
  var tbLanguage = createDropdown("language");
  var tbEmailAddress = createTextbox("emailAddress");
  var tbPhoneNumber = createTextbox("phoneNumber");
  var tbhearus = createHearUsDropdown("hearus");
//  var tbhearus2 = createHearUs2Dropdown("hearus2");




  var msgDivEl = document.getElementById("msgDiv");
  
  formLeftDiv.appendChild(lbFullName);
  formLeftDiv.appendChild(tbFullName);
  formLeftDiv.appendChild(lbEmailAddress);
  formLeftDiv.appendChild(tbEmailAddress);
  formLeftDiv.appendChild(lbCity);
  formLeftDiv.appendChild(tbCity);
  formLeftDiv.appendChild(lbState);
  formLeftDiv.appendChild(tbState);
  
  formRightDiv.appendChild(lbPhoneNumber);
  formRightDiv.appendChild(tbPhoneNumber);
  formRightDiv.appendChild(lbAge);
  formRightDiv.appendChild(tbAge);
  formRightDiv.appendChild(lbLanguage);
  formRightDiv.appendChild(tbLanguage);
  formRightDiv.appendChild(lbhearus);
  formRightDiv.appendChild(tbhearus);
  
  formLeftDiv.appendChild(button);
  formRightDiv.appendChild(closeBtn);
  
  //checking for required fields (?)
  var req;
  function sendRequest(url,params,httpMethod){
	  if(!httpMethod){
		  httpMethod = "POST";
	  }
	  req = FactoryXMLHttpRequest();
	  
	  //sending the email
	  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);
	  }
  }
  
  //permission granted!
	function onReadyStateChange(){
		var ready = req.readyState;
		if(ready==4){
			//alert("Your email was sent. Thank you!");
			window.location = "download.php?file=ebrochure.pdf";
			//window.open('download.php?file=preschool_brochure.pdf','brochure','toolbar=no,location=no') 
		}
	}
  
  //checking validations
	function submitForm(){//the submit click event
		var url="mail.php";
		//validate
		var info;
		var fullNameValue = trim(tbFullName.value);
			if(fullNameValue.length==0){
				alert("Please enter the Full Name.");
			return ;
			}
 
		var phoneNumberValue = trim(tbPhoneNumber.value);
		info=IsValidPhoneNumber(phoneNumberValue);
		if(info.ReturnCode!=0){
			alert(info.ErrorDescription);
			return ;
		}
	 
		var emailaddressvalue=trim(tbEmailAddress.value);
	  	if( !checkEmail(emailaddressvalue) )
		{
			return;
		}
		//age
		var ageValue = trim(tbAge.value);
		if(ageValue.length==0){
			alert("Please enter the age of your child.");
			return ;
		}
		//city
		var cityValue = trim(tbCity.value);
		if(cityValue.length==0){
			alert("Please enter your city.");
			return ;
		}
		//state
		var stateValue = trim(tbState.value);
			if(stateValue.length==0){
				alert("Please enter your state.");
			return ;
		}
	    if(tbhearus.value.length == 0)
	    {
	        alert("Please let us know how you found out about us!");
	        return ;
	    }	    
		if(tbhearus2.value.length == 0)
	    {
	        alert("error- hearus 2 value not recorded!");
	        return ;
	    }
		//defining the data to be sent off in the email (?)
	 var params = "fullName="+fullNameValue+"&phoneNumber="+phoneNumberValue+"&emailAddress="+emailaddressvalue+"&age="+tbAge.value+"&city="+tbCity.value+"&state="+tbState.value+"&language="+tbLanguage.value+"&hearaboutus="+tbhearus.value;
		// alert("SDFSA");
		
		//sending the email, closing the window
	 sendRequest(url,params);
	 closeWin();

  }
}
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true)
	}
	alert("Invalid E-mail Address! Please re-enter.")
		return (false)
}