// JavaScript Document




function fullImage(sPicURL) { 
 window.open( "image.htm?"+sPicURL, "","resizable=1,HEIGHT=200,WIDTH=200"); 
} 


function MM_openBrWindow(theURL,winName,features) { //v2.0
	tWindow = window.open(theURL,winName,features);
	tWindow.focus()
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function state_jumpMenu(selObj){ //v3.0
  eval("window.location='"+selObj.options[selObj.selectedIndex].value+"'");
 
}



function slot_full(){
	alert('Sorry all appointments are full for that time.')
}

function price_full(){
	alert('Sorry all appointments are full for that price range.')
}

function salon(aId){
	MM_openBrWindow('salon.php?id=' + aId,'salon','width=710,height=510')
	
}

function voucher_check_value(){
	document.booking_form.booking_submitted.value = "voucher_check";
	document.booking_form.submit();

}

function handle_voucher_use(){
	if(document.booking_form.voucher_use.checked == false){
		document.booking_form.voucher_secret_key.value = ""
		document.booking_form.voucher_remaining_value.value = ""
		document.booking_form.voucher_day.value = 1
		document.booking_form.voucher_month.value = 1
		document.booking_form.voucher_year.value = 2007
		
		obj_remaining_value_text = document.getElementById("remaining_value_text")
		obj_remaining_value_text.innerHTML = "";
	}
}

function validate_booking(){
	tForm = document.booking_form;
	tVoucherOK = true;
	voucher_remaining_value = 0;
	total_amount = tForm.total_amount.value;
	
	
	if(tForm.voucher_use.checked == true){
		if(tForm.voucher_secret_key.value == ''){
			tVoucherOK = false;
			alert("Please enter your Gift Voucher Code.");
		} else {
		    if (tForm.voucher_type.value == 'global_discount') {
		       tVoucherOK = true;
		    } else if(isNaN(tForm.voucher_remaining_value.value) || tForm.voucher_remaining_value.value == 0 ){
				tVoucherOK = false;
				
				if(tForm.voucher_remaining_value.value == ''){
						alert("Please check your vouchers validity by clicking on the 'Check Voucher' button");
				} else {
					if(tForm.voucher_remaining_value.value == 0 ){
						alert("Your voucher has $0 remaining value.\nPlease use a different voucher or deselect the voucher payment option.");
					} else {
						alert("Please check your vouchers validity by clicking on the 'Check Voucher' button");
					}
				}
				
			} else {
				voucher_remaining_value = tForm.voucher_remaining_value.value;
			}
		}
	}
	
	
	
	if(tVoucherOK){
		var tValidatedOK = true;
		var tMessage = "The following field(s) are required:\n";
		
		if (tForm.firstname.value  == ""){
			tMessage += "          Your First Name\n";
			tValidatedOK = false
		}
		
		if (tForm.lastname.value  == ""){
			tMessage += "          Your Last Name\n";
			tValidatedOK = false;
		}
		
		if (tForm.email.value  == ""){
			tMessage += "          Your Email Address\n";
			tValidatedOK = false;
		}
		
		if (tForm.phone.value  == ""){
			tMessage += "          Your Phone Number\n";
			tValidatedOK = false;
		}
		
		if(parseFloat(voucher_remaining_value) < parseFloat(total_amount)){
			if (tForm.cardtype.value  == ""){
				tMessage += "          The Credit Card Type\n";
				tValidatedOK = false;
			}
			if (tForm.cardnumber.value  == ""){
				tMessage += "          Your Credit Card Number\n";
				tValidatedOK = false;
			}
			if (tForm.cardname.value  == ""){
				tMessage += "          The Name on your Credit Card\n";
				tValidatedOK = false;
			}
			if (tForm.cvn.value  == ""){
				tMessage += "          Your CVN Number of your Credit Card\n";
				tValidatedOK = false;
			}
		}
		
		if (tForm.tc.checked  == false){
			tMessage += "          You must accept the terms and conditions\n";
			tValidatedOK = false;
		}
		
		if(tValidatedOK == false){
			alert(tMessage);
		} else {
			tForm.submit();
		}
	}
	
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}


function validate_gift_fitmein(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	if (document.gift_form.firstname.value  == ""){
		tMessage += "          Your First Name\n"
		tValidatedOK = false
	}
	
	if (document.gift_form.lastname.value  == ""){
		tMessage += "          Your Last Name\n"
		tValidatedOK = false
	}
	
	
	if (document.gift_form.email.value  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	}
	
	if (document.gift_form.phone.value  == ""){
		tMessage += "          Your Phone Number\n"
		tValidatedOK = false
	}
	
	if (document.gift_form.cardtype.value  == ""){
		tMessage += "          The Credit Card Type\n"
		tValidatedOK = false
	}
	if (document.gift_form.cardnumber.value  == ""){
		tMessage += "          Your Credit Card Number\n"
		tValidatedOK = false
	}
	if (document.gift_form.cardname.value  == ""){
		tMessage += "          The Name on your Credit Card\n"
		tValidatedOK = false
	}
	if (document.gift_form.cvn.value  == ""){
		tMessage += "          Your CVN Number of your Credit Card\n"
		tValidatedOK = false
	}
	if (document.gift_form.recipient_name.value  == ""){
		tMessage += "          The Name of the Recipient\n"
		tValidatedOK = false
	}
	
	if (getSelectedRadioValue(document.gift_form.send_certificate)  == "recipient" || getSelectedRadioValue(document.gift_form.send_certificate)  == "both"  ){
		if (document.gift_form.recipient_email.value  == ""){
			tMessage += "          The Recipients Email Address\n"
			tValidatedOK = false
		}
	}
   
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		document.gift_form.submit()
	}
	
}


function validate_gift_salon(){
	document.gift_form.submit();
}




function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function showhide(id){ 
	if (document.getElementById){ 
		obj = document.getElementById(id); 
		if (obj.style.display == "none"){ 
			obj.style.display = ""; 
		} else { 
			obj.style.display = "none"; 
		} 
	} 
} 

function isValidDate(day,month,year){
	var dteDate;
	dteDate=new Date(year,month,day);
	
	isValid = true;
	
	if(day != dteDate.getDate()){
		isValid = false;
	}
	if(month != dteDate.getMonth()){
		isValid = false;
	}
	if(year != dteDate.getFullYear()){
		isValid = false;
	}
	if(!isValid){
		alert("The date you have chosen is not valid");
	}
	return isValid;
}

function trim(aString) {
	return aString.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function getFieldValue(aFormName, aFieldName) {
	var strValue = null;
	var str = 'strValue = document.' + aFormName + '.' + aFieldName + '.value;';
	eval(str);
	return trim(strValue);
}

function setFieldValue(strFormName, strFieldName, strValue) {
	var str = 'document.forms["' + strFormName + '"].' + strFieldName + '.value="' + strValue + '";';
	eval(str);
}

function getFieldValueInt(aFormName, aFieldName) {
	var strValue = null;
	var str = 'strValue = document.' + aFormName + '.' + aFieldName + '.value;';
	eval(str);
	return parseInt(trim(strValue));
}

function setFocus(aFormName, aFieldName) {
	var obj = null;
	var str = 'obj = document.' + aFormName + '.' + aFieldName;
	eval(str);
	obj.focus();
}
