$(document).ready(function() { 

	if ($("#home_builds ul li").length > 0){
		$("#home_builds ul li").hover(function() { //On hover...
			
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		
		//Set a background image(thumbOver) on the &lt;a&gt; tag 
		$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		//Animate the image to 0 opacity (fade it out)
		$(this).find("img").stop().animate({opacity: 0}, 300);
		} , function() { //on hover out...
			//Animate the image back to 100% opacity (fade it back in)
			$(this).find("img").stop().animate({opacity: 1}, 300);
		});
	}
	
	if ($("#home_jq").length > 0){
		$("#home_jq").easySlider({
			auto: true,
			continuous: true 
		});
	} 
	
});


$(function(){
	
	//Do what we need to when form is submitted.	
	$('#form_submit').click(function(){
	
	//Setup any needed variables.
	var input_name = $('#contact_name').val(),
		input_email = $('#contact_email').val(),
		input_number = $('#contact_number').val(),
		input_message = $('#contact_message').val(),
		response_text = $('#response');
		//Hide any previous response text 
		response_text.hide();
		
		//Change response text to 'loading...'
		response_text.html('Sending...').show();
		
		//Make AJAX request 
		$.post('/sendmail.php', {name: input_name, email: input_email, number: input_number, message: input_message}, 
			   function(data){
				   response_text.removeClass();
					response_text.addClass(data.error);
					response_text.html(data.name);
		}, "json");
		
		//Cancel default action
		return false;
	});

});


function initialize1() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
		map.removeMapType(G_SATELLITE_MAP);
        map.setCenter(new GLatLng(51.293146,-0.735941), 13);
		map.setMapType(G_NORMAL_MAP);
		
		window.setTimeout(function() {
          map.setMapType(G_NORMAL_MAP);
        }, 1000);

		var center = new GLatLng(51.293146,-0.735941);
		var marker = new GMarker(center, {draggable: true});
        map.addOverlay(marker);
		
		
      }
}




if (document.images){	
	//home
	btn_home_on= new Image();
	btn_home_on.src="/images/btn_home_on.gif";  
	
	btn_home= new Image();
	btn_home.src="/images/btn_home.gif"; 
	
	//about
	btn_treatments_on= new Image();
	btn_treatments_on.src="/images/btn_treatments_on.gif";  
	
	btn_treatments= new Image();
	btn_treatments.src="/images/btn_treatments.gif"; 
	 
	//salons
	btn_products_on= new Image();
	btn_products_on.src="/images/btn_products_on.gif";  
	
	btn_products= new Image();
	btn_products.src="/images/btn_products.gif"; 	 
	
		//salons
	btn_studio_on= new Image();
	btn_studio_on.src="/images/btn_studio_on.gif";  
	
	btn_studio= new Image();
	btn_studio.src="/images/btn_studio.gif"; 	
	
		//salons
	btn_testimonials_on= new Image();
	btn_testimonials_on.src="/images/btn_testimonials_on.gif";  
	
	btn_testimonials= new Image();
	btn_testimonials.src="/images/btn_testimonials.gif"; 	
	 
		//salons
	btn_newsletter_on= new Image();
	btn_newsletter_on.src="/images/btn_newsletter_on.gif";  
	
	btn_newsletter= new Image();
	btn_newsletter.src="/images/btn_newsletter.gif"; 	
	 
	//services
	btn_contact_on= new Image();
	btn_contact_on.src="/images/btn_contact_on.gif";  
	
	btn_contact= new Image();
	btn_contact.src="/images/btn_contact.gif";
	
	
		//services
	btn_yoga_on= new Image();
	btn_yoga_on.src="/images/british_school_of_yoga_on.gif";  
	
	btn_yoga= new Image();
	btn_yoga.src="/images/british_school_of_yoga.gif";
	
	
	
			//services
	btn_guild_on= new Image();
	btn_guild_on.src="/images/guild_beauty_on.gif";  
	
	btn_guild= new Image();
	btn_guild.src="/images/guild_beauty.gif";
	
	
				//services
	btn_tropez_on= new Image();
	btn_tropez_on.src="/images/st_tropez_on.gif";  
	
	btn_tropez= new Image();
	btn_tropez.src="/images/st_tropez.gif";
	
					//services
	btn_zahra_on= new Image();
	btn_zahra_on.src="/images/zahra_on.gif";  
	
	btn_zahra= new Image();
	btn_zahra.src="/images/zahra.gif";
	
		btn_aussie_on= new Image();
	btn_aussie_on.src="/images/australian_on.gif";  
	
	btn_aussie= new Image();
	btn_aussie.src="/images/australian.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;
    }
 }
 
 var newwindow;
function product_large(url)
{
	newwindow=window.open(url,'name','resizable=1, width=400, height=500');
	if (window.focus) {newwindow.focus()}
}




///-------------------------------------------------------------------------------------------------------


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();
			}
			
			//var xvar = (x+1) + "";
			//checkTime(xvar, now.getHours());
			
			document.getElementById(xxxx).value  = now.getHours();
			document.getElementById(xxxy).value = yy;
			var xvar = 's'+(x+1);
			checkTime(xvar, now.getHours());
		}
	}
}
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);
}







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 += "Treatment "+ x + ": -- Please select a valid treatment\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 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. Allergies or disabilities"){
		xx.value = "";	
	}
	
}

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

if (xx.value == ""){
		xx.style.fontSize = "12px";
	xx.style.color = "#666666";
	xx.value = "e.g. 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;
}




