﻿// JScript File

//function to calculate Star Treatment quote and then submit quote via email
function calcQuote(){
    var T=0; //total cost
    var bandNo=0; //number of band members
    var Q=0; //travel cost
    
    var a1=0;
    var a2="";
    var a3=0;
    var a4=0;
    var a5=0;
    var a6=0;
    var a7=0; 
    var a8="";
    var a9="";
    var a10="";
    var a11="";
    var a12="";   

    //validate
    var F = document.getElementById("quoteForm");

	if (( F.q1.value=="-1" ) || ( F.q3.value=="-1" ) || ( F.q4.value=="-1" ) || ( F.q5.value=="-1" ) || ( F.q6.value=="-1" ) || ( F.q7.value=="-1" ))
	{
		alert ("To get an accurate quote please answer all questions fully.");
		return false;
	}	

	if (( F.q2.value=="" ))
	{
		alert ("To get an accurate quote please fill in the location of the event.");
		return false;
	}	
	
    //now for quote building, let get the values
    
    //workout how many band members we're using    
    switch(F.q1.value){
        case "2 Vocalists [BUDGET BAND]":
            a1=675;
            bandNo=6;
            break;
       case "2 Vocalists, Trumpet & Sax [FULL BAND]":
            a1=900;
            bandNo=8;
            break;
    }
   
    
   switch(F.q3.value){
        case "10 miles away":
            a3=5;
            break;
        case "25 miles away":
            a3=10;
            break;
        case "40 miles away":
            a3=15;
            break;
        case "60 miles away":
            a3=25;
            break;
        case "80 miles away":
            a3=35;
            break;
        case "100 miles away":
            a3=50;
            break;
        case "125 miles away":
            a3=75;
            break;
        case "150 miles away":
            a3=90;
            break;
        case "175 miles away":
            a3=110;
            break;
        case "200 miles away":
            a3=125;
            break;
        case "250 miles away":
            a3=150;
            break;
        case "Over 250 miles away":
            a3=200;
            break;
    }

     switch(F.q4.value){
        case "Up to 80 guests":
            a4=50;
            break;
        case "Up to 150 guests":
            a4=125;
            break;
        case "Over 150 guests":
            a4=180;
            break;
        case "Over 300 guests":
            a4=250;
            break;
    }
   
    switch(F.q5.value){
        case "Not sure what finish time":
            a5=0;
            break;
        case "Daytime performance":
            a5=0;
            break;
        case "11pm finish":
            a5=0;
            break;
        case "12pm finish":
            a5=0;
            break;
        case "1am finish":
            a5=10;
            break;
        case "2am finish":
            a5=25;
            break;
        case "Up to 3am finish":
            a5=50;
            break;
    }


    switch (F.q6.value) {
        case "5pm arrive":
            a6=10;
            break;
        case "4pm arrive":
            a6=15;
            break;
        case "3pm arrive":
            a6=20;
            break;
        case "12-2pm arrive":
            a6=30;
        case "Before Midday arrive":
            a6=50;
            break;
    }
    
    switch(F.q7.value){
        case "No Music":
            a7=0;
            break;
        case "DJ Booked":
            a7=0;
            break;
        case "Use PA":
            a7=25;
            break;
        case "Use Star DJ":
            a7=150;
            break;
    }
                             
    bandNo = parseFloat(bandNo);  
    //q1
    T=(parseFloat(a1));
   // alert(T);
    //q3
    G=(bandNo*parseFloat(a3)); //now have the travel cost
    T=(T+G);
  
    //q4
    if (a4 > 0){
     T=(T+((G/bandNo)+parseFloat(a4)));
    }
       
    //q5
    T=(T+(bandNo*parseFloat(a5)));
    
    //q6
    T=(T+(bandNo*parseFloat(a6)));
    
    //q7  
    if (a7> 10){
     T=(T+((G/bandNo)+parseFloat(a7)));
    } else{
     T=(T+parseFloat(a7));   
    }
      
    F.q10.value = F.q2.value;  
    var now = new Date;
    var randomnumber=Math.floor(Math.random()*100);
    var quoteNumber=now.getDate() + '' + now.getMonth()+1 + '' + now.getYear() + '-' + randomnumber;
    
    //display quote and quote number to the user
   //document.quoteForm.quoteNumber.value = 'Your full quote price is £' + T + ', your quote number is ' + quoteNumber;
    F.quoteNumber.value = 'Your full quote price is £' + T + ', your quote number is ' + quoteNumber;
   //document.getElementById('quoteNumber').innerHTML = 'Your full quote price is £' + T + ', your quote number is ' + quoteNumber;
        
   if (confirm('Your full quote price is £' + T + ', your quote number is ' + quoteNumber + '\n\nDo you want to check availability?')){ 
         showdiv('DIVAvail1');}
         else {
            F.submit();}
        
        
        //document.getElementById("lblQuoteDetail").innerHTML = '<br/>The full quote price is <strong><font color="white">£'+ T + '</font></strong><br/>your quote number is ' + quoteNumber + '<br/><br/>';
} 

function SubmitFormNoAvail(go){
    var F = document.getElementById("quoteForm");

    if (go=="GO"){
        if ((F.qDate.value == "dd/mm/yy"))
	   {
		alert ("A date is required so we can check its availabiility.");
		return false;
	   }	
	   if (( F.q13.value=="Prefer Telephone" ) && ( F.q11.value=="" ))
	   {
		alert ("Telephone preferred but no number entered, please complete.");
		return false;
	   } 
	   if (( F.q13.value=="Prefer Email" ) && ( F.q12.value=="" ))
	   {
		alert ("Email preferred but no address entered, please complete.");
		return false;
	   } 	 
    }
    F.submit();
}

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
var ids=new Array('DIVq6','DIVq3','DIVq5');
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


