

function doWork(xx, yy, xxx){
	var sz = xx.substr(xx.length-1);
	var xy = 'book_service'+sz;
	//var xz = new String("arr"+yy);
	var combo = document.getElementById(xy);
	combo.disabled = false;
	combo.options.length = 0;
	var response = window[xxx];
	//alert(response);
	var items = response.split(";");
	var count = items.length-1;
	for (var i=0;i<count;i++){
		var options = items[i].split("#");
		combo.options[i] =	new Option(options[0],options[1]);
	}
	
	addTime(xx);
}

function addTime(row) {
	if (row == 'x1'){
		var rowx = parseInt(1);
	}else{
		var rowx = parseInt(row.substr(row.length-1));
	}
	iteration = document.booking_form.norows.value;
	if(iteration > 1){
		for (x=rowx; x< iteration; x++){
			var prevTime = document.getElementById('book_service' +x).value;
			
			var currHo	= document.getElementById('book_hours'+x).value;
			
			var currMo = document.getElementById('book_minutes'+x).value;
			var xxxx  = 'book_hours'+(x+1);
			var currH	= document.getElementById(xxxx).value;
			var xxxy =  'book_minutes'+(x+1);
			var currM = document.getElementById(xxxy).value;
	
			var xxx  = Math.ceil(array2[prevTime]/15)*15;
	
			var now =	new Date();
			var hour =	now.setHours(currHo);
			var mins =	now.setMinutes(parseInt(currMo)+xxx);
			
			if (now.getMinutes() == 0){
				var yy = "00";
			}else{
				var yy = now.getMinutes();
			}
			
			document.getElementById(xxxx).value  = now.getHours();
			document.getElementById(xxxy).value = yy;
		}
	}
}
function checkTime2(xx){
	var x = parseInt(xx.substr(xx.length-1))-1;
	if (x >= 1){
	var prevTime = document.booking_form['book_service' + (x)].value;
	var xxx  = Math.ceil(array2[prevTime]/15)*15;
	
	var currHo	= document.booking_form['book_hours'+(x)].value;
	var currMo = document.booking_form['book_minutes'+(x)].value;
	
	var currH	= document.booking_form['book_hours'+ parseInt(x+1)].value;
	var currM = document.booking_form['book_minutes'+ parseInt(x+1)].value;

	var xxx  = Math.ceil(array2[prevTime]/15)*15;

	var old = new Date();
	var hour =	old.setHours(currH);
	var mins =	old.setMinutes(parseInt(currM));

	var now =	new Date();
	var hour =	now.setHours(currHo);
	var mins =	now.setMinutes(parseInt(currMo)+xxx);
	
	var newh = now.getHours();
	var newm = now.getMinutes();
	
	if (old < now){
		alert("Current Time must be greater than - "+newh+":"+newm);
		document.booking_form['book_hours'+(x+1)].value  = now.getHours();
	document.booking_form['book_minutes'+(x+1)].value = now.getMinutes();
	}else{
		addTime('it'+(x+1));
	//document.booking_form['book_hours'+(x+1)].value  = now.getHours();
	//document.booking_form['book_minutes'+(x+1)].value = now.getMinutes();
	}
	}
	
}



function checkTime(xxx, yy){
	//alert(xxx);
	var sz = 'time_am'+xxx.substr(xxx.length-1);
	if (yy >=12){
		document.getElementById(sz).innerHTML = '&nbsp;PM';
	}else{
		document.getElementById(sz).innerHTML = '&nbsp;AM';
	}
	
	addTime(xxx);
}




if (document.images)
   {
	//home
	btn_home_on= new Image();
	btn_home_on.src="/images/btn_home_on.png";  
	
	btn_home= new Image();
	btn_home.src="/images/btn_home.png"; 
	
	//about
	btn_about_on= new Image();
	btn_about_on.src="/images/btn_about_on.png";  
	
	btn_about= new Image();
	btn_about.src="/images/btn_about.png"; 
	 
	//salons
	btn_salons_on= new Image();
	btn_salons_on.src="/images/btn_salons_on.png";  
	
	btn_salons= new Image();
	btn_salons.src="/images/btn_salons.png"; 	 
	 
	//services
	btn_services_on= new Image();
	btn_services_on.src="/images/btn_services_on.png";  
	
	btn_services= new Image();
	btn_services.src="/images/btn_services.png";
	
	//testimonials
	btn_testimonials_on= new Image();
	btn_testimonials_on.src="/images/btn_testimonials_on.png";  
	
	btn_testimonials= new Image();
	btn_testimonials.src="/images/btn_testimonials.png";
	
	//contact
	btn_contact_on= new Image();
	btn_contact_on.src="/images/btn_contact_on.png";  
	
	btn_contact= new Image();
	btn_contact.src="/images/btn_contact.png";
	
	btn_page_1_on= new Image();
	btn_page_1_on.src="/images/pagination_1_on.gif";
	
	btn_page_1= new Image();
	btn_page_1.src="/images/pagination_1.gif";
	
	btn_page_2_on= new Image();
	btn_page_2_on.src="/images/pagination_2_on.gif";
	
	btn_page_2= new Image();
	btn_page_2.src="/images/pagination_2.gif";
	
	btn_page_3_on= new Image();
	btn_page_3_on.src="/images/pagination_3_on.gif";
	
	btn_page_3= new Image();
	btn_page_3.src="/images/pagination_3.gif";
	
	btn_page_n_on= new Image();
	btn_page_n_on.src="/images/pagination_next_on.gif";
	
	btn_page_n= new Image();
	btn_page_n.src="/images/pagination_next.gif";
	
	btn_page_p_on= new Image();
	btn_page_p_on.src="/images/pagination_prev_on.gif";
	
	btn_page_p= new Image();
	btn_page_p.src="/images/pagination_prev.gif";
	
   }


function turnoff(imgName)
 {
   if (document.images)
    {
      imgOff=eval(imgName + ".src");
      document[imgName].src= imgOff;
    }
 }


function turnon(imgName)
 {
   if (document.images)
    {
      imgOn=eval(imgName + "_on.src");
      document[imgName].src= imgOn;
    }
 }
 
 
 function changeRequest(myForm, valx){
	var checkedx = valx;
	//alert(checkedx);
	
	if (checkedx == "send1"){
						myForm.brochure_house.disabled = true;
		myForm.brochure_street.disabled = true;
		myForm.brochure_town.disabled = true;
		myForm.brochure_postcode.disabled = true;
		
		myForm.brochure_house.style.backgroundColor = '#cccccc';
		myForm.brochure_street.style.backgroundColor = '#cccccc';
		myForm.brochure_town.style.backgroundColor = '#cccccc';
		myForm.brochure_postcode.style.backgroundColor = '#cccccc';
	}
	
		if (checkedx == "send2"){
					myForm.brochure_house.disabled = false;
		myForm.brochure_street.disabled = false;
		myForm.brochure_town.disabled = false;
		myForm.brochure_postcode.disabled = false;
		
		myForm.brochure_house.style.backgroundColor = '#ffffff';
		myForm.brochure_street.style.backgroundColor = '#ffffff';
		myForm.brochure_town.style.backgroundColor = '#ffffff';
		myForm.brochure_postcode.style.backgroundColor = '#ffffff';
		
		
	}
	
	
	
	 
	 
 }
 
 
 
 
 
 
 function validateRequest(myForm){
	
	
	var checkedx = myForm.brochure_eb;
	var fValue = myForm.brochure_postcode.value;
	  
	  
  var msg = "";
  var msgTop = "The field(s) listed below still need to be entered correctly\n\n"
	if(myForm.contact_name.value == ""){
	msg += "Name:  -- Please enter your name\n"
	}
	
	if(!checkedx[0].checked  &&  !checkedx[1].checked){
	msg += "Brochure:  -- Please select your brochure delivery method\n"
	}
	 

	 
	 if (checkedx[0].checked){
		 
		  var field = myForm.brochure_email; // email field
		  var str = myForm.brochure_email.value; // email string
		  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		  

		  
		    if (!reg2.test(str)) { 
			  msg += "E-mail:  -- Please enter your e-mail, \"" + str + "\" is an invalid e-mail\n"; 
			  }
  
	 }
	 
	 
	if (checkedx[1].checked){
		if(myForm.brochure_house.value == ""){
			msg += "House Name/Number:  -- Please enter a valid House Name/Number\n"
		}
	
		if(myForm.brochure_street.value == ""){
			msg += "Street:  -- Please enter your Stree address\n"
		}
	
		if(myForm.brochure_town.value == ""){
			msg += "Town:  -- Please enter your Town\n"
		}
	
	
		pcode1a = /^[a-z,A-Z]{1,1}\d\s\d([a-zA-Z]{2,2})/;
		pcode1b = /^[a-z,A-Z]{1,1}\d\d([a-zA-Z]{2,2})/;
		pcode2a = /^[a-z,A-Z]{2,2}\d\s\d[a-zA-Z]{2,2}/;
		pcode2b = /^[a-z,A-Z]{2,2}\d\d[a-zA-Z]{2,2}/;
		pcode3a = /^[a-z,A-Z]{2,2}\d\d\s\d[a-zA-Z]{2,2}/;
		pcode3b = /^[a-z,A-Z]{2,2}\d\d\d[a-zA-Z]{2,2}/;
	
		if (pcode1a.test(fValue) || pcode1b.test(fValue)){
			//alert("type1");
		//	document.forms["homePcode"].submit();
		}else if (pcode2a.test(fValue) || pcode2b.test(fValue)){
			//alert("type2");
			//document.forms["homePcode"].submit();
		}else if (pcode3a.test(fValue) || pcode3b.test(fValue)){
			//alert("type3");
			//document.forms["homePcode"].submit();
		}else{
			msg += "Postcode:  -- Please enter a valid postcode\n"
			//return false;
		}
	 }
  
		if (msg != ""){
			alert(msgTop + msg);
		//return false;
		}else{
			myForm.submit();
		}
}






function validateGift(myForm){
	var fValue = myForm.brochure_postcode.value;
	  
	  
	var msg = "";
	var msgTop = "The field(s) listed below still need to be entered correctly\n\n"
	if(myForm.contact_name.value == ""){
		msg += "Name:  -- Please enter your name\n"
	}

	var field = myForm.brochure_email; // email field
	var str = myForm.brochure_email.value; // email string
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	
	var str2 = myForm.brochure_number.value; // email string
	var reg11 = /^\+?0?\d{2,4}[\d -]{6,9}$/;

	if (!reg11.test(str2)) { 
		msg += "Phone Number:  -- Please enter a valid  contact number, \"" + str + "\" is an invalid number\n"; 
	}
		  

		  
	if (!reg2.test(str)) { 
		msg += "E-mail:  -- Please enter your e-mail, \"" + str + "\" is an invalid e-mail\n"; 
	}
	
	
	if(myForm.brochure_house.value == ""){
		msg += "House Name/Number:  -- Please enter a valid House Name/Number\n"
	}
	
	if(myForm.brochure_street.value == ""){
		msg += "Street:  -- Please enter your Street address\n"
	}

	if(myForm.brochure_town.value == ""){
		msg += "Town:  -- Please enter your Town\n"
	}
	
	pcode1a = /^[a-z,A-Z]{1,1}\d\s\d([a-zA-Z]{2,2})/;
	pcode1b = /^[a-z,A-Z]{1,1}\d\d([a-zA-Z]{2,2})/;
	pcode2a = /^[a-z,A-Z]{2,2}\d\s\d[a-zA-Z]{2,2}/;
	pcode2b = /^[a-z,A-Z]{2,2}\d\d[a-zA-Z]{2,2}/;
	pcode3a = /^[a-z,A-Z]{2,2}\d\d\s\d[a-zA-Z]{2,2}/;
	pcode3b = /^[a-z,A-Z]{2,2}\d\d\d[a-zA-Z]{2,2}/;
	
	if (pcode1a.test(fValue) || pcode1b.test(fValue)){

	}else if (pcode2a.test(fValue) || pcode2b.test(fValue)){

	}else if (pcode3a.test(fValue) || pcode3b.test(fValue)){

	}else{
		msg += "Postcode:  -- Please enter a valid postcode\n"

	}

  
	if (msg != ""){
		alert(msgTop + msg);
		//return false;
	}else{
		myForm.submit();
	}
}









function validateContact(myForm){
  var field = myForm.contact_email; // email field
  var str = myForm.contact_email.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  
  var str2 = myForm.contact_tel.value; // email string
  var reg11 = /^\+?0?\d{2,4}[\d -]{6,9}$/;
  var msg = "";
  var msgTop = "The field(s) listed below still need to be entered correctly\n\n"

	if(myForm.contact_name.value == ""){
	msg += "Name:  -- Please enter your name\n"
	}


  if (!reg2.test(str)) { 
  msg += "E-mail:  -- Please enter your e-mail, \"" + str + "\" is an invalid e-mail\n"; 
  }
  
  

	if(myForm.contact_comment.value == ""){
	msg += "Message:  -- Please enter a message you would like to send to us\n";
	}
	
	if (msg != ""){
	alert(msgTop + msg);
	//return false;
	}else{
		myForm.submit();
	}
}

function validateBooking(myForm){
  var field = myForm.book_email; // email field
  var str = myForm.book_email.value; // email string
  var str2 = myForm.book_number.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  var xxx = myForm.norows.value;
  var msg = "";
  var msgTop = "The field(s) listed below still need to be entered correctly\n\n"
	
	if(myForm.book_first.value == ""){
	msg += "First Name:  -- Please enter your First Name\n"
	}
	
	if(myForm.book_last.value == "" || myForm.book_last.length < 2){
	msg += "Last Name:  -- Please enter your Last Name\n"
	}


  if (!reg2.test(str)) { 
  msg += "E-mail:  -- Please enter your e-mail, \"" + str + "\" is an invalid e-mail\n"; 
  }
  
  	var reg11 = /^\+?0?\d{2,4}[\d -]{6,9}$/;

	if (!reg11.test(str2)) { 
		msg += "Phone Number:  -- Please enter a valid  contact number, \"" + str + "\" is an invalid number\n"; 
	}
  var currd = new Date;
var mydate = new Date;
mydate.setDate(myForm.book_d.value);
mydate.setMonth(myForm.book_m.value - 1);
mydate.setFullYear(myForm.book_y.value);
//alert(mydate + ' - ' + currd);
	if(mydate <= currd){
	msg += "Date: -- Please select a date which is after todays date\n";
	}
	
	for(x=1; x<=xxx;x++){
		//alert(myForm['book_service'+x].length);
		if (myForm['book_service'+x].length <= 1){
			msg += "Service "+ x + ": -- Please select a valid service\n";	
		}
		
	}
	
	if (msg != ""){
	alert(msgTop + msg);
	//return false;
	}else{
		//return true;
		myForm.submit();
	}
}


function confirmDelete(varx){
	vary = confirm('Are you sure you want to cancel this appointment from the system?\nThe customer will be sent an email notifying them this appointment has been cancelled ONLY IF this appointment was not booked before today.');
	if (vary == true){
		document.location.href = "book_delete.php?id="+ varx;
	}
}
	
function confirmApproval(varx){
	vary = confirm('Are you sure you want to confirm this appointment from the system?\nThe customer will be sent an email notifying them this appointment has been approved.');
	if (vary == true){
		document.location.href = "book_approve.php?id="+ varx;
	}
	
}
function termsWindow(){

 newwindow = window.open('terms.html','terms', 'left=20,top=20,width=500,height=600,toolbar=0,resizable=1,scrollbars=1');
 if (window.focus) {
 newwindow.focus();
 }
}


function requestWindow(){

 newwindow = window.open('request_brochure.php','request', 'left=20,top=20,width=500,height=600,toolbar=0,resizable=1,scrollbars=1');
 if (window.focus) {
 newwindow.focus();
 }
} 

function giftWindow(){

 newwindow = window.open('gift_voucher.php','request', 'left=20,top=20,width=500,height=600,toolbar=0,resizable=1,scrollbars=1');
 if (window.focus) {
 newwindow.focus();
 }
} 






function addRowToTable(){
  var tbl = document.getElementById('booking_form_service');
  var norows = document.booking_form.norows.value;
  var lastRow = tbl.rows.length;


  var iteration = lastRow+1;
  var row = tbl.insertRow(lastRow);
  
 
  // right cell
  var cellLeft = row.insertCell(0);

  // select cell
  var cellLeftSel = row.insertCell(1);
  var sel = document.getElementById('book_service_main1').cloneNode(true);
  var selx = document.getElementById('book_service1').cloneNode(true);
  sel.name = 'book_service_main' + iteration;
  sel.id = 'book_service_main' + iteration;
  
  selx.name = 'book_service' + iteration;
  selx.id = 'book_service' + iteration;
  selx.disabled = true;
  var spanx = document.createElement("span");
  spanx.innerHTML = '&nbsp;&nbsp;';
  cellLeftSel.appendChild(sel);
  cellLeftSel.appendChild(spanx);
  cellLeftSel.appendChild(selx);

  
   // right cell
  var cellRight2 = row.insertCell(2);
  var sel2 = document.getElementById('book_hours1').cloneNode(true);
  sel2.name = 'book_hours' + iteration;
  sel2.id = 'book_hours'+iteration;
  var sel3 = document.getElementById('book_minutes1').cloneNode(true);
  sel3.name = 'book_minutes' + iteration;
  sel3.id = 'book_minutes' + iteration;
  
  
  var span = document.createElement("span");
  span.innerHTML = '<strong>Time: </strong>'; 
   
 var span2 = document.createElement("span");
  span2.innerHTML = '&nbsp;:&nbsp;';
  
  var span3 = document.getElementById('time_am1').cloneNode(true);
  span3.id = 'time_am'+iteration;
  span3.innerHTML = '&nbsp;AM';
  
  
  cellRight2.appendChild(span);
  cellRight2.appendChild(sel2);
  cellRight2.appendChild(span2);
  cellRight2.appendChild(sel3);
  cellRight2.appendChild(span3);
  
    
	document.booking_form.norows.value = iteration;
addTime('x1');
  

  }


function removeRowFromTable(){
//	alert(x);
  var tbl = document.getElementById('booking_form_service');
  var norows = document.getElementById('norows').value;

 var lastRow = tbl.rows.length;
  if (lastRow > 1){ 
  	tbl.deleteRow(lastRow-1); 
	norows = lastRow-1;
	
  }else{
  
  }
}

function changeText(){
	var xx = document.getElementById('book_comments');
	xx.style.fontSize = "12px";
	xx.style.color = "#000000";
	xx.style.fontStyle = 'normal';
	if (xx.value == "e.g. Preferred therapist, allergies or disabilities"){
		xx.value = "";	
	}
	
}

function changeTextOut(){
var xx = document.getElementById('book_comments');

if (xx.value == ""){
		xx.style.fontSize = "11px";
	xx.style.color = "#666666";
	xx.style.fontStyle = 'italic';
	xx.value = "e.g. Preferred therapist, allergies or disabilities";	
	}
}

function changeEnable(xx, yy){
	if (yy.checked == true){
	document.myForm['book_hours'+xx].disabled = false;
	document.myForm['book_minutes'+xx].disabled = false;
	
	document.myForm['book_d'+xx].disabled = false;
	document.myForm['book_m'+xx].disabled = false;
	document.myForm['book_y'+xx].disabled = false;
		
	}else{
	document.myForm['book_hours'+xx].disabled = true;
	document.myForm['book_minutes'+xx].disabled = true;
	
	document.myForm['book_d'+xx].disabled = true;
	document.myForm['book_m'+xx].disabled = true;
	document.myForm['book_y'+xx].disabled = true;
	}
	
}



function popitup(url) {
	newwindow=window.open(url,'name','height=500,width=425');
	if (window.focus) {newwindow.focus()}
	return false;
}



