function validEmail(email) {
invalidChars = " /:,;"
if (email == "") {
    return false
}

for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i)
    if (email.indexOf (badChar,0) != -1) {
        return false
    }
}  // for (i=o.. 

atPos = email.indexOf ("@",1)

if (atPos == -1) {
    return false
}

if ( email.indexOf ("@", atPos+1) != -1) {
    return false
}
periodPos = email.indexOf (".", atPos)

if ( periodPos == -1) {
    return false
}

if ( periodPos+3 > email.length)    {
    return false
}
return true
}  // validEmail 

function calculate() {
price = 0;
rates = new Array();
for(i=0;i<document.booking.elements.length;i++) {
	if(document.booking.elements[i].name.indexOf("rates_type_") != -1) {
		rates.push(document.booking.elements[i].value);
	}
}

periods 		= document.booking.dates.value.split(":");
arrivalarray 	= document.booking.arrival.value.split("-");
departurearray 	= document.booking.departure.value.split("-");

arrivaldate 	= new Date(arrivalarray[0],parseInt(arrivalarray[1])-1,parseInt(arrivalarray[2]));
departuredate 	= new Date(departurearray[0],parseInt(departurearray[1])-1,parseInt(departurearray[2]));


today			= new Date();
holidays 		= (departuredate-arrivaldate)/86400000;
// Find the value of the room
if(holidays > 0 || arrivaldate > today) {
	price = 0;
	for(i=0;i<holidays;i++) {
		antaldage = new Date(i*86400000);
		daytocalculate = (arrivaldate-0)+(antaldage-0);
		for(j=0;j<periods.length;j++) {
			period_dates 	= periods[j].split("-");
			startdate 		= new Date(period_dates[0]);
			enddate 		= new Date(period_dates[1]);
			accommodation	= parseInt(document.booking.accommodation.value);
			if(daytocalculate >= (startdate-0) && daytocalculate <= (enddate-0)) { // within period
				periodrates = rates[accommodation-1].split(",");
				price += Number(periodrates[j]);
			}
		}
	}
}
document.booking.fullamount.value = price;
document.booking.amount.value = Math.floor(price*0.3);
document.booking.balance.value = document.booking.fullamount.value-document.booking.amount.value;
}

function validatebookform() {
	
	errors = ""
	if (document.booking.cust_fname.value == "")
		errors += "You need to put in your first name\n"
	if (document.booking.cust_lname.value == "")
		errors += "You need to put in your last name\n"
	if (document.booking.cust_address1.value == "")
		errors += "You need to put in an address\n"
	if (document.booking.cust_city.value == "")
		errors += "You need to put in a city\n"
	if (document.booking.cust_province.value == "")
		errors += "You need to put in a province\n"
	if (document.booking.cust_zip.value == "")
		errors += "You need to put in a zip code\n"
	if (document.booking.cust_country.value == "")
		errors += "You need to put in a country\n"
	if(!validEmail(document.booking.cust_email.value))
		errors += "Your email address is not valid\n"
	
	
	arrivalarray 	= document.booking.arrival.value.split("-");
	departurearray 	= document.booking.departure.value.split("-");
	arrivaldate 	= new Date(arrivalarray[0],parseInt(arrivalarray[1])-1,parseInt(arrivalarray[2]));
	departuredate 	= new Date(departurearray[0],parseInt(departurearray[1])-1,parseInt(departurearray[2]));
	
	today 			= new Date();
	holidays 		= (departuredate-arrivaldate)/86400000;
	
	if(holidays <= 0 || arrivaldate < today || arrivaldate > departuredate) 
		errors += "Your arrival date and departure date are not valid\n"
		
	if (errors != "") {
		alert(errors)
		return false;
	}
}



function CurrencyPopup(QueryString) {
    CurrencyWindow = window.open ('', 'CurrencyWindow', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=170,width=600')
    CurrencyWindow.focus()
    CurrencyWindow.location.href = 'http://www.xe.net/ecc/input.cgi?Template=sw&AmountSet='+document.booking.fullamount.value+'&'+QueryString
}


function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';
  document.write(str);
}
function NoBorder(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function copypaste() {
	document.forms[0].linkoutput.focus();
	document.forms[0].linkoutput.select();
	therange=document.forms[0].linkoutput.createTextRange();
	therange.execCommand("Copy");
}  

startList = function() {
	// only MSIE supports document.all
	if (document.all) {
		// Get all the list items within the menu
		navRoot = document.getElementById("menulist");
		/*
			if there is more than one ITEM in the mainMenu Unordered List,
			loop through the List to see if there is any List Item.
		*/
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			/*
				if there is more List Item (LI) when on mouseover action,
				use CSS style "#menulist li.over ul" to display for IE browser.
			*/
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+="over";
				}
				//else use CSS style "#mainMenu li:hover ul" to display for other browsers.
				node.onmouseout=function() {
					this.className=this.className.replace("over", "");
				}
			}
		}
	}
}
//when the page is loaded on to the browser, if it is Internet Explorer, the javascript is runned and starts processing the webpage.
window.onload=startList;