// JavaScript Document

function update_enquiryform(tstatus){
$.ajax({
  url: "/includes/dev-view-ajax/enquiryform.php" + tstatus,
  cache: false,
  success: function(html){
    $("#enquiry-form").replaceWith(html);
  }
 });
}

function update_obform(tstatus){
$.ajax({
  url: "/includes/dev-view-ajax/onlinebrochureform.php" + tstatus,
  cache: false,
  success: function(html){
    $("#obform").replaceWith(html);
  }
 });
}


function update_viewingform(tstatus){
$.ajax({
  url: "/includes/dev-view-ajax/viewingrequest.php" + tstatus,
  cache: false,
  success: function(html){
    $("#viewingform").replaceWith(html);
		
	$(function() {$('#visiting_date').datepicker({
	  skin : "dmxCalendar",
	  dateFormat : "M d, yy",
	  showStatus : false,
	  numberOfMonths : [1,1],
	  showAnim : "slide",
	  showOptions : 
	  {
		easing : "easeOutBounce",
		direction : "up",
		mode : "show"
	  },
	  duration : "fast",
	  showOn : "both",
	  buttonImage : "/Styles/dmxCalendar/calendar_icon.gif",
	  buttonImageOnly : true,
	  prompt : "",
	  closeAtTop : false
	});})


  }
 });
}

var newimagepath='';
var thetimeout;

function doimage(){
	var thumb=document.getElementById('thumb');
	thumb.src=newimagepath;
}

function loadthumb(newpath, delay){
	newimagepath=newpath;
	if(thetimeout) clearTimeout(thetimeout);
	thetimeout=setTimeout('doimage()',delay);
}
var isvis=0;

function makevis(){
	document.getElementById('hiddentable').className='vis';
//	isvis=1;
}

function check_obform(theform) {

//alert("temporary overide");
//return true;

	missinginfo = "";
	if (theform.cust_name.value == "")
		missinginfo += "\n     :  Name";

	if(checkPhone(theform.cust_phone.value)=='') 
		missinginfo += "\n     :  Valid Telephone number";

	if(ajaxcheckemail(theform.cust_email.value)==false)
		missinginfo += "\n     :  Valid E-mail address";

	if (missinginfo != ""){
		missinginfo ="_____________________________\n" + "The following fields have not been entered correctly:\n" + missinginfo  + "\n_____________________________" + "\nPlease click the OK button and re-enter details";

		alert(missinginfo);
		return false;
	}else{
		return true;
	}
}

function check_viewingform(theform) {

//alert("temporary overide");
//return true;

	missinginfo = "";
	
	if (theform.visiting_date.value == "")
		missinginfo += "\n     :  Visiting date";

	if (theform.cust_firstname.value == "" || theform.cust_name.value == "")
		missinginfo += "\n     :  First and last names";

	if(checkPhone(theform.cust_phone.value) == "") 
		missinginfo += "\n     :  Valid Telephone number";

	if(ajaxcheckemail(theform.cust_email.value)==false)
		missinginfo += "\n     :  Valid E-mail address";

	if (missinginfo != ""){
		missinginfo ="_____________________________\n" + "The following fields have not been entered correctly:\n" + missinginfo  + "\n_____________________________" + "\nPlease click the OK button and re-enter details";

		alert(missinginfo);
		return false;
	}else{
		return true;
	}
}

function check_enquiryform(theform) {

// alert("temporary overide");
//return true;

	missinginfo = "";

	if(theform.preferred_contact_method.value=='') 
			missinginfo += "\n     :  Preferred contact method";

	if (theform.cust_firstname.value == "" || theform.cust_name.value == "")
		missinginfo += "\n     :  First and last names";

	if((theform.preferred_contact_method.value=='Post' || theform.et_brochure.checked) && (theform.cust_address.value == "" || theform.cust_postcode.value == "")) 
		missinginfo += "\n     :  Address and postcode";
	
	if(checkPhone(theform.cust_phone.value) == "") 
		missinginfo += "\n     :  Valid Telephone number";

	if(ajaxcheckemail(theform.cust_email.value)==false)
		missinginfo += "\n     :  Valid E-mail address";

	if (missinginfo != ""){
		missinginfo ="_____________________________\n" + "The following fields have not been entered correctly:\n" + missinginfo  + "\n_____________________________" + "\nPlease click the OK button and re-enter details";

		alert(missinginfo);
		return false;
	}else{
		return true;
	}
}


/*	// go through form elements if class="checkbox" / name=enq[] / id starts "enquirytype_" then one should be ticked.
	var enqtypechecked=false;
	for(i=0; i<theform.elements.length; i++){
		if(theform.elements[i].type == "checkbox"){
			if(theform.elements[i].name=='enquirytype[]' && theform.elements[i].checked){
				enqtypechecked=true;
//				alert(theform.elements[i].name + " | " + theform.elements[i].id + " | " + theform.elements[i].value);
			}
		}
	}	
	// if none ticked and no viewing request date
	if(!enqtypechecked && theform.visiting_date.value == "") 
		missinginfo += "\n     :  Please select an enquiry type or enter a viewing date";
*/

