//////////////////
// send enquiry //
//////////////////

function sendEnquiry()
{
	var name,email,phone,query;
	
	try
	{
		frm=document.forms["formEnquiry"];
		
		name=frm["myName"].value;
		email=frm["myEmail"].value;
		phone=frm["contactPhone"].value;
		query=frm["enquiry"].value;

		query=query.replace(/\n/g," ");

		checkValid(name,"Name and email address are both required.");
		checkValid(email,"Name and email address are both required.");
		checkEmail(email);

		setPrompt("enquiryPrompt","Contacting server, please wait...");	
		document.getElementById("ifrmSendEnquiry").src="cgi-bin/sendEnquiry.cgi?name="+name+"&email="+email+"&phone="+phone+"&query="+query;
	}
	catch(e)
	{
		setPrompt("enquiryPrompt",e);
	}
}


///////////////////////////
// send enquiry complete //
///////////////////////////

function onSendEnquiry(e)
{
	setPrompt("enquiryPrompt",e.firstChild.nodeValue);
	document.getElementById("ifrmSendEnquiry").src=null;
}


/////////////////////////
// clear subscriptions //
/////////////////////////

function clearSubs()
{
	var email;
	
	try
	{
		frm=document.forms["formSubs"];
	
		email=frm["editEmail"].value;

		checkValid(email,"Name and email address are both required.");
		checkEmail(email);

		setPrompt("subsPrompt","Contacting server, please wait...");	
		document.getElementById("ifrmSetSubs").src="cgi-bin/setSubs.cgi?name="+name+"&email="+email;
	}
	catch(e)
	{
		setPrompt("subsPrompt",e);
	}
}


///////////////////////
// set subscriptions //
///////////////////////

function setSubs()
{
	var name,email,subs,frm;
	
	try
	{
		frm=document.forms["formSubs"];
		
		name=frm["editName"].value;
		email=frm["editEmail"].value;

		subs="";

		if(frm["btnCoachingWomen"].checked)
			subs+="0|";
		if(frm["btnNewsletter"].checked)
			subs+="2|";
		if(frm["btnCareerManagement"].checked)
			subs+="5|";
		if(frm["btnCoachingForChange"].checked)
			subs+="6|";
		if(frm["btnProcesses"].checked)
			subs+="7|";
		if(frm["btnEbook"].checked)
			subs+="8|";

		if(subs=="")
			throw "You must select at least one publication";

		checkValid(name,"Name and email address are both required.");
		checkValid(email,"Name and email address are both required.");
		checkEmail(email);

		setPrompt("subsPrompt","Contacting server, please wait...");	
		document.getElementById("ifrmSetSubs").src="cgi-bin/setSubs.cgi?name="+name+"&email="+email+"&subs="+subs;
	}
	catch(e)
	{
		setPrompt("subsPrompt",e);
	}
}


///////////////////////////////
// set subscription complete //
///////////////////////////////

function onSetSubscription(e)
{
	setPrompt("subsPrompt",e.firstChild.nodeValue);
	document.getElementById("ifrmSetSubs").src=null;
}


///////////////////////
// set a text prompt //
///////////////////////

function setPrompt(ctrl,text)
{
	var e;
	
	e=document.getElementById(ctrl);
	e.style.display="inline";
	e.firstChild.nodeValue=text;
}


//////////////////////////
// validation functions //
//////////////////////////

var banned="<>|&";

function checkValid(str,err)
{
	var i;

	if(str==null || str.length==0)
		throw err;

	for(i=0;i<banned.length;i++)
  	if(str.indexOf(banned.charAt(i),0)!=-1)
    	throw "Please don't use these characters: "+banned;
}


function checkEmail(str)
{
	if(str.indexOf(".")==-1 || str.indexOf("@")==-1 || str.indexOf(" ")!=-1)
		throw "Please enter a valid email address.";
}
