// These javascript functions are common to all contents pages //

//---------------------------/
// Menu reselection function /
//---------------------------/
// When a page is loaded into the contentframe it calls defn(page).
// The value of 'page' is placed in parent.re and the menu is reloaded
// (unless it was the entry page loaded by default.asp)

function defn(page) {
 if (this.name=="contentframe") {
   if (parent.entry>0) {
     parent.entry=0;
     }
   else {
	parent.re = page;
	parent.trace = parent.trace+","+page;
	parent.menuframe.location = "zmenu.asp";
	}
   } 
 else {
   document.write('<p class=boldred>Please <a href="http://www.bycar.com/?re='+page+'">click here</a> to view this page in context.</p>');
   }
}

//-------------------------------/
// Display of clickable pictures /
//-------------------------------/
function lpic(nom) {
  document.write('<a href=javascript:popUp("../images/f'+nom+'.jpg")><img src=../images/t'+nom+'.jpg align=left hspace=12alt="click to view larger image"></a>');
}
function rpic(nom) {
  document.write('<a href=javascript:popUp("../images/f'+nom+'.jpg")><img src=../images/t'+nom+'.jpg align=right hspace=12 alt="click to view larger image"></a>');
}
function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,width=600,height=450');");
}

//---------------------------------------------/
// Display of gallery pictures used in pic.htm /
//---------------------------------------------/
pics=0;
picr=4;
function show(nom) {
  if (pics++==0) document.write("<tr>");
  document.write("<td>");
  plink(nom);
  document.write("</td>");
  if (pics==picr) {
    pics=0;
    document.write("</tr>");
  }
}
function plink(nom) {
  document.write("<a target=photo href=/gallery/f"+nom+".jpg><img src=/gallery/t"+nom+".jpg></a>");
}
function gallery(capt,nums) {
  pics=0;
  document.write("<p>"+capt+"</p>");
  document.write("<table>");
  numbers=nums.split(" ");
  for (j=0;j<numbers.length;j++) show(numbers[j]);
  if (pics>0) document.write("</tr>");
  document.write("</table>");
}

//--------------------/
// Data Bus Functions /
//--------------------/
function options(op1st,oplast,selected) {
for (i=op1st; i<oplast+1; i++) {
 document.write ("<OPTION value="+i);
 if (i==selected) document.write (" selected");
 if (i<0) document.write (">");
 if (i>=0) document.write (">"+i);
 }
}
function go(d) { 
 for (i=0; i<d.length; i++) {
  if (d.options[i].selected) {
   return d.options[i].value;
   }
  }
 }
function parentvalues() {
 s = parent.season;
 s+="," +parent.apt;
 s+="," +parent.start;
 s+="," +parent.weeks;
 s+="," +parent.folk;
 s+="," +parent.kids;
 s+="," +parent.towels;
 return s;
 }
function goseason(sees) {
  parent.season = sees;
  document.sched.transaction.value = parentvalues();
  document.sched.submit();
  }
function gokids() {
  parent.kids = go(document.detail.kids);
  document.detail.transaction.value  = parentvalues();
 }
function gotowels() {
  parent.towels = go(document.detail.towels);
  document.detail.transaction.value  = parentvalues();
  document.detail.submit();
 }
function goweeks() {
  parent.weeks = go(document.detail.weeks);
  document.detail.transaction.value  = parentvalues();
  document.detail.submit();
 }
function gofolk() {
  parent.folk = go(document.detail.folk);
  document.detail.transaction.value  = parentvalues();
  document.detail.submit();
  }
function plug(vApt,vPage) {
 parent.apt = vApt;
 document.showform.transaction.value  = parentvalues();
 document.showform.action = vPage;
 document.showform.submit();
 }


//------------------------------------------/
// To check format of a user supplied email /
//------------------------------------------/
function validemail(str) {

/* check for invalid characters */
var goodchar=/^[\w\-\.\@]*$/;
var matchArray=str.match(goodchar);
if (matchArray==null) {
	alert("Email address contains illegal characters.");
	return false;
	}

/* allow username@domain */
var emailPat=/^(.+)@(.+)$/;
matchArray=str.match(emailPat);
if (matchArray==null) {
	alert("Email address must contain @");
	return false;
	}

var user=matchArray[1];
var domain=matchArray[2];

/* check username does not contain an @ */
if (user.indexOf("@")>0) {
	alert("Only one @ may be included.");
	return false;
	}

domainels=domain.split(".");

lastel=domainels[domainels.length-1];

if ((domainels.length>1) && (lastel.length>1) && (lastel.length<5)) return true;

alert("Email format seems invalid");

return false;
}

