/* /####################################################################
# Work : BuildAdelaide - Business Email Send
# Copyright : Vmedia Pty Ltd
# Licensee : Building Industry Network Pty Ltd
# DateCreated : January 2008
# LastModified : January 2008
# ----------------------------------------------------------------------
# Author : Robin Goodfellow Programmer in HTML Perl PHP MySQL JavaScript
# Contact : 08 8232 0099 Vmedia 2nd Floor 187 Rundle St Adelaide SA 5000
######################################################################*/

var closepause, busid ;

function jsSendEmail() {
	
	var httpmethod = "POST" ;
	var url = "../scripts/business_email.php" ;
	var console = document.getElementById("emailform") ;
	
	busid = document.getElementById("toid").value ;
	var fromemail = document.getElementById("fromemail").value ;
	var message = document.getElementById("message").value ;
	
	var params = "toid=" + busid + "&fromemail=" + fromemail + "&message=" + message ;
	var preview = ajaxpreview(httpmethod, url, params, console) ;
	
	closepause = window.setTimeout("jsCloseForm()", 10000) ;
	
}

function jsCloseForm() {
	
	window.clearTimeout(closepause) ;
	
	var theNewForm ;
	theNewForm = document.getElementById("emailform") ;
	theNewForm.style.display = "none" ;
	
	buildpause = window.setTimeout("jsBuildEmailForm()", 500) ;
}

function jsBuildEmailForm() {
	
	window.clearTimeout(buildpause) ;
	
	var theNewForm, InputFirst, DivFirst, LabelFirst, theTextOfLabelFirst, InputSecond, DivSecond, LabelSecond, theTextOfLabelSecond, TextAreaFirst, DivThird, InputThird ;
	
	theNewForm = document.getElementById("emailform") ;
	theNewForm.style.display = "none" ;
	if (theNewForm.hasChildNodes()) {
		while (theNewForm.childNodes.length >= 1) {
			theNewForm.removeChild(theNewForm.firstChild) ;       
		}
	}
	
	InputFirst = document.createElement('input') ;
	InputFirst.setAttribute('type', 'hidden') ;
	InputFirst.setAttribute('name', 'toid') ;
	InputFirst.setAttribute('id', 'toid') ;
	InputFirst.setAttribute('value', busid) ;
	theNewForm.appendChild(InputFirst) ;
	
	DivFirst = document.createElement('div') ;
	
	LabelFirst = document.createElement('label') ;
	LabelFirst.setAttribute('for', 'fromemail') ;
	theTextOfLabelFirst = document.createTextNode('Insert your Email Address here') ;
	LabelFirst.appendChild(theTextOfLabelFirst) ;
	DivFirst.appendChild(LabelFirst) ;
	
	InputSecond = document.createElement('input') ;
	InputSecond.setAttribute('type', 'text') ;
	InputSecond.setAttribute('name', 'fromemail') ;
	InputSecond.setAttribute('id', 'fromemail') ;
	DivFirst.appendChild(InputSecond) ;
	theNewForm.appendChild(DivFirst) ;
	
	DivSecond = document.createElement('div') ;
	
	LabelSecond = document.createElement('label') ;
	LabelSecond.setAttribute('for', 'message') ;
	theTextOfLabelSecond = document.createTextNode('Type your Message here') ;
	LabelSecond.appendChild(theTextOfLabelSecond) ;
	DivSecond.appendChild(LabelSecond) ;
	
	TextAreaFirst = document.createElement('textarea') ;
	TextAreaFirst.setAttribute('name', 'message') ;
	TextAreaFirst.setAttribute('id', 'message') ;
	DivSecond.appendChild(TextAreaFirst) ;
	theNewForm.appendChild(DivSecond) ;
	
	DivThird = document.createElement('div') ;
	
	InputThird = document.createElement('input') ;
	InputThird.setAttribute('type', 'button') ;
	InputThird.setAttribute('value', 'Send') ;
	InputThird.setAttribute('onclick', 'jsSendEmail();') ;
	InputThird.setAttribute('onkeypress', 'jsSendEmail();') ;
	DivThird.appendChild(InputThird) ;
	theNewForm.appendChild(DivThird) ;
	
}
