var xmlhttp=false;
var Path;

try
    {    // Firefox, Opera 8.0+, Safari ;   
			xmlhttp=new XMLHttpRequest();
	}
  catch (e)
    {    // Internet Explorer   
		try
      {      xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");      }
    catch (e)
      {      try
        {        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");        }
      catch (e)
        {        alert("Your browser does not support AJAX!");
		}
	  }
	}

/*if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
if(!xmlhttp && typeof XMLHttpRequest!='underfiend'){
	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
if(!xmlhttp && typeof XMLHttpRequest!='underfiend'){
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");	
}
*/
function GetLocation(ObjVal,Objval1)
{
	
	if(ObjVal!="")
	{
		params="Location=" + ObjVal + "&act=" + Objval1;
		Path="../booking/Workshopdata.php?" + params;
		xmlhttp.open("POST",Path,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");			
	
		xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("Location").innerHTML=xmlhttp.responseText;
			document.getElementById("StartDate").innerHTML="Select Location to display Dates";	
			}
		}
		xmlhttp.send(params);
	}
	else
	{
		document.getElementById("Location").innerHTML="Select WorkShop to display Location";	
		document.getElementById("StartDate").innerHTML="Select Location to display Dates";	
	}
	return false;
}

function GetDates(frmObj,Objval1)
{

	WorkShop=frmObj.coursename.value;
	Loc=frmObj.location.value;
	if(Loc!="")
	{
		params="Course=" + WorkShop + "&Location=" + Loc + "&act=StartDate";
		Path="../booking/Workshopdata.php?" + params;
		
		xmlhttp.open("POST",Path,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");			
		
		xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById("StartDate").innerHTML=xmlhttp.responseText;
			document.getElementById("hfocus").value="location";
			
			}
		}
		xmlhttp.send(params);
	}
	else {
		document.getElementById("StartDate").innerHTML="Select Location to display Dates";	
	}
	return false;	
}

/*function GetFormData()
{

}*/

/*function GetDelegates(frmObj)
{
	query="../booking/Workshopdata.php?";
	CountVal=frmObj.countVal.value;
	query=query + "Count=" + CountVal +"&";
	for(i=1;i<=CountVal;i++)
	{
		fname="fname" + i;
		lname="lname" + i;
		job="job" + i;
		email="email" + i;
		phno="phno" + i;
		
		query = query + "fname" + i + "=" + document.getElementById(fname).value + "&";
		query = query + "lname" + i + "=" + document.getElementById(lname).value + "&";
		query = query + "job" + i + "=" + document.getElementById(job).value + "&";
		query = query + "email" + i + "=" + document.getElementById(email).value + "&";
		query = query + "phno" + i + "=" + document.getElementById(phno).value + "&";						
	}
}*/

function addDelegate(ObjVal)
{
	DivID="Delegate" + ObjVal;
	params="Delegate=" + ObjVal + "&act=Add";
	Path="../booking/Delegates.php?" + params;
	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");		
	
	document.getElementById("hfocus").value="fname" + ObjVal;
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		document.getElementById(DivID).innerHTML=xmlhttp.responseText;
			}
	}
	xmlhttp.send(params);	
	
}

function DeleteDelegate(ObjVal)
{
	
//	document.getElementById(DivID).innerHTML="";
	DivID="Delegate" + ObjVal;
	
	params="Delegate=" + ObjVal + "&act=Delete";
	Path="../booking/Delegates.php?";
	document.getElementById("hfocus").value="fname" + ObjVal-1;
	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");		
	
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		document.getElementById(DivID).innerHTML=xmlhttp.responseText;
			}
	}
	
	xmlhttp.send(params);	
}

function GetDietart(ObjVal1,ObjVal2)
{
	DivID="spdietary" + ObjVal2;
	
	params="Dietart=" + ObjVal1 + "&DID=" + ObjVal2 + "&act=Hide";
	Path="../booking/Delegates.php?" + params;
	if(ObjVal1=="0"){
		document.getElementById("hfocus").value="dcname";	
	}
	else {
		document.getElementById("hfocus").value="dessdn" +  ObjVal2;			
	}
	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");	
	
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {

		document.getElementById(DivID).innerHTML=xmlhttp.responseText;
			}
	}
	xmlhttp.send(params);		

}

function ContactInfo(frmObj,OptVal)
{
	if(OptVal=="Yes")
	{
/*		ContactFName=escape(frmObj.fname1.value);
		ContactLName=escape(frmObj.lname1.value);
		ContactJob=escape(frmObj.job1.value);
		Contactemail=escape(frmObj.email1.value);
		ContactPhno=escape(frmObj.phno1.value);*/
		
		ContactFName=urlEncode(frmObj.fname1.value);
		ContactLName=urlEncode(frmObj.lname1.value);
		ContactJob=urlEncode(frmObj.job1.value);
		Contactemail=urlEncode(frmObj.email1.value);
		ContactPhno=urlEncode(frmObj.phno1.value);		
		
		
	}
	else {

		ContactFName="";
		ContactLName="";
		ContactJob="";
		Contactemail="";
		ContactPhno="";
		
	}
//	alert(ContactPhno);
	params="CFName=" + ContactFName + "&CLName=" + ContactLName + "&CJob=" + ContactJob + "&CEmail=" + Contactemail + "&CPhone=" + ContactPhno + "&act=Contact";
	Path="../booking/Delegates.php?" + params;
	
//		alert(Path);
	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");	
	
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		document.getElementById("ContactDetails").innerHTML=xmlhttp.responseText;
			}
	}
	
	xmlhttp.send(params);	
//	xmlhttp.send(null);	
	
}
function GetOrganization(OrgValue)
{
	params="Organization=" + urlEncode(OrgValue) + "&act=Organization";
	Path="../booking/Delegates.php?" + params;
	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");		
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		document.getElementById("Organisation").innerHTML=xmlhttp.responseText;
			}
	}
	
	xmlhttp.send(params);		
	
}

function GetBilling(frmObj,BillingValue)
{
	if(BillingValue=="Yes")
	{
		
		BillingFName=urlEncode(frmObj.dcname.value);
//		alert(BillingFName);
		BillingLName=urlEncode(frmObj.dclname.value);
		BillingJob=urlEncode(frmObj.djob.value);
		
		Billingemail=urlEncode(frmObj.demail.value);
		BillingPhno=urlEncode(frmObj.dphno.value);
		if(frmObj.booking[0].checked){
			Billingorgname=urlEncode(frmObj.orgname.value);
			booking="No";
		}
		else{
			Billingorgname="";			
			booking="Yes";
		}
		
		Billingaddr1=urlEncode(frmObj.addr1.value);
		Billingaddr2=urlEncode(frmObj.addr2.value);
		Billingaddr3=urlEncode(frmObj.addr3.value);
		Billingtown=urlEncode(frmObj.town.value);
		Billingcounty=urlEncode(frmObj.county.value);
		Billingcountry=urlEncode(frmObj.country.value);
		Billingpcode=urlEncode(frmObj.pcode.value);
	}
	else {

		BillingFName="";
		BillingLName="";
		BillingJob="";
		Billingemail="";
		BillingPhno="";
		Billingorgname="";			
		Billingaddr1="";
		Billingaddr2="";
		Billingaddr3="";
		Billingtown="";
		Billingcounty="";
		Billingcountry="";
		Billingpcode="";
	}
	
	params="act=Billing&FName=" + BillingFName + "&LName=" + BillingLName + "&Job=" + BillingJob + "&Email=" + Billingemail + "&Phone=" + BillingPhno + "&OrgName=" + Billingorgname + "&Add1=" + Billingaddr1 + "&Add2=" + Billingaddr2 + "&Add3=" + Billingaddr3 + "&Town=" + Billingtown  + "&Country1=" + Billingcounty + "&Country2=" + Billingcountry + "&PCode=" + Billingpcode + "&booking=" + booking;
	Path="../booking/Delegates.php?" + params;

	xmlhttp.open("POST",Path,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");		
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		document.getElementById("Billing").innerHTML=xmlhttp.responseText;
			}
	}
	
	xmlhttp.send(params);		

}


function GetAboutUs(ObjValue)
{
	var AboutData="";
	if(ObjValue!=""){
			if(ObjValue=="Other" || ObjValue=="Internet - Other" || ObjValue=="Colleague or friend" || ObjValue=="Mailshot"){
				
				AboutData='&nbsp;&nbsp;please specify&nbsp;&nbsp;&nbsp;<input type="text" name="specify" value="" class=boxtextpurch>';
			}
				AboutData=AboutData + '<input type="hidden" name="hinet" value="' + ObjValue + '" style="width:100px;">';
			document.getElementById("AboutUs").innerHTML=AboutData;
	}
				
/*			Path="../booking/Delegates.php?act=AboutUs&About=" + ObjValue;
			xmlhttp.open("POST",Path,true);
			xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById("AboutUs").innerHTML=xmlhttp.responseText;
					}
			}
			
			xmlhttp.send(null);			
	}*/
}

function GetPayment(PaymentValue)
{
	
	
	var PaymentData="";
	if(PaymentValue!=""){
			
			if(PaymentValue=="VISA Card" ||	PaymentValue=="Master Card" ||PaymentValue=="AMEX Card" ||	PaymentValue=="Switch / Maestro Card" ||	PaymentValue=="Solo Card"){
				
				PaymentData="<p>We will contact you shortly to take your credit card details over the telephone.</p>";
				
			} else if(PaymentValue=="Cheque"){
				
				PaymentData="<p>Once you receive an invoice from us, please send a cheque made payable to Skillstudio Limited.  Please remember to include the invoice number on the back of your cheque.</p>";
				
			} else if(PaymentValue=="Bank Transfer"){
				
				PaymentData="<p>Once you receive an invoice for us, please arrange for a bank transfer using the invoice number as part of the reference for your payment.  Our Bank Account is HSBC Bank PLC, 249 High Street Orpington, Kent, England, BR6 0NR.  Sort code:- 40-35-30, Account:- 91405543, Name:- Skillstudio Limited .</p>";
			}
			document.getElementById("Cards").innerHTML=PaymentData;

	}
}

function urlEncode(str){
	str=str.replace(new RegExp('\\£','g'),'&pound;');
	str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');

	
    return str.replace(new RegExp('%20','g'),'+');
}
