// Browser sniffer
var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

function checkSearch(formName) {
	if(parseInt(formName.minprice.value) >= parseInt(formName.maxprice.value)) {
		alert('Maximum price has to be greater than Lowest price');
		return false;
	}else{
		return true;
	}
}

function viewImage(image) {
document.getElementById('imgLarge').src = image;
}

function validateNews(form) {var e = form.elements, m = '';
if(!e['name'].value) {m += '- Name is required.\n';}
if(!/.+@[^.]+(\.[^.]+)+/.test(e['email'].value)) {
m += '- Email requires a valid email address.\n';
}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function validateAdd(form) {var e = form.elements, m = '';
if(!e['tbHotelname'].value) {m += '- Property name is required.\n';}
if(!e['tbDescription'].value) {m += '- Description is required.\n';}
if(!e['tbHoteladdress'].value) {m += '- Address is required.\n';}
if(!e['tbHotelprice'].value) {m += '- Price is required.\n';}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function validateEnq(form) {var e = form.elements, m = '';
if(!e['firstname'].value) {m += '- First name is required.\n';}
if(!e['surname'].value) {m += '- Surname is required.\n';}
if(!/.+@[^.]+(\.[^.]+)+/.test(e['email'].value)) {
m += '- Email requires a valid email address.\n';
}
if(!e['telephone'].value) {m += '- Telephone is required.\n';}
if(!e['enquiry'].value) {m += '- Enquiry is required.\n';}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function validateReg(form) {var e = form.elements, m = '';
if(!e['firstname'].value) {m += '- First name is required.\n';}
if(!e['surname'].value) {m += '- Surname is required.\n';}
if(!e['address1'].value) {m += '- Address Line 1 is required.\n';}
if(!e['postcode'].value) {m += '- Post Code is required.\n';}
if(!e['favouritelocation'].value) {m += '- Favourite location is required.\n';}
if(!e['telephone'].value) {m += '- Telephone number is required.\n';}
if(!/.+@[^.]+(\.[^.]+)+/.test(e['username'].value)) {
m += '- username requires a valid email address.\n';
}
if(!e['password'].value) {m += '- Password is required.\n';}
if(e['password'].value != e['confirmpassword'].value) {
m += '- Your password and confirmation password do not match.\n';
}
if(!e['privacy'].checked) {m += '\n\n- Please read and agree to the booking terms and conditions before continuing to checkout!.\n';}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function validateRegBuyer(form) {var e = form.elements, m = '';
if(!/.+@[^.]+(\.[^.]+)+/.test(e['username'].value)) {
m += '- username requires a valid email address.\n';
}
if(!e['password'].value) {m += '- Password is required.\n';}
if(e['password'].value != e['confirmpassword'].value) {
m += '- Your password and confirmation password do not match.\n';
}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function validateUpdUser(form) {var e = form.elements, m = '';
if(!e['firstname'].value) {m += '- First name is required.\n';}
if(!e['surname'].value) {m += '- Surname is required.\n';}
if(!/.+@[^.]+(\.[^.]+)+/.test(e['email'].value)) {
m += '- Email requires a valid email address.\n';
}
if(!e['address1'].value) {m += '- Address Line 1 is required.\n';}
if(!e['postcode'].value) {m += '- Post Code is required.\n';}
if(!e['favouritelocation'].value) {m += '- Favourite location is required.\n';}
if(!e['telephone'].value) {m += '- Telephone number is required.\n';}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}

function logout() {
if(confirm('Are you sure you want to log out?')) {
location.href='/login/logoff.asp';	
}
}


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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

// Cross-browser function to change the contents inside a DIV tag
function writeInDiv(text, id)
{
	if (document.getElementById)
	{ x = document.getElementById(id); x.innerHTML = ''; x.innerHTML = text; }
	else if (document.all)
	{ x = document.all[id]; x.innerHTML = text; }
	else if (document.layers)
	{ x = document.layers[id]; text2 = '<p>' + text + '</p>'; x.document.open(); x.document.write(text2); x.document.close(); }
}

// Attaches objects dependent on browser
function object_attach(id)
{
	var obj;
	if(ns4) obj = document.layers[id];
	else if(ie4) obj = document.all[id];
	else if(ie5 || ns6) obj = document.getElementById(id);
	return obj;
}

//Div switch function
function div_switch(id, bShow, bBlock)
{
	temp_Obj = object_attach(id);
	if(ns4)
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.display = "block"; }
			else { temp_Obj.visibility = "show"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.display = "none"; }
			else { temp_Obj.visibility = "hide"; }
		}
	}
	else
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.style.display = "block"; }
			else { temp_Obj.style.visibility = "visible"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.style.display = "none"; }
			else { temp_Obj.style.visibility = "hidden"; }
		}
	}
}

// Opens a popup window
function openPopupWin(popUrl, popWid, popHgt, popScroll, popResize)
{
	popupWin=window.open(popUrl,"popupWin","width=" + popWid + ",height=" + popHgt + ",left=" + ((screen.width-popWid)/2) + ",top=" + ((screen.height-popHgt)/2) + ",status=yes,toolbar=no,menubar=no,scrollbars=" + popScroll + ",resizable=" + popResize);
	if(!popupWin.opener) popupWin.opener=self;
	if (window.focus) {popupWin.focus()}
}