//////////////////////////////////
// form validation methods library

// string is valid email
function isEmail(s) {
  var apos = s.indexOf('@');
  var dpos = s.indexOf('.');
  if (apos<=0 || dpos<=0) {
	return false; 
  }
  if (dpos+1>=s.length) {
	return false; 
  }
  return true;
}				

// string contains only whitespace
function isBlank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c!=' ') && (c!='\n') && (c!='\t')) return false;
	}
	return true;
}		

// string is empty or only whitespace
function isEmpty(s) {
	if (!(s.value==null || s.value=="" || isBlank(s.value)))return false;
	return true;	
}	

// string is numeric
function isNumber(s) {
 if (isEmpty(s)) {
  return false;
 }	
 for (var i = 0; i < s.value.length; i++) {
   var ch = s.value.substring(i, i + 1);
   if((ch!=' ') && (ch!='\n') && (ch!='\t')) 
     if (ch < "0" || "9" < ch)return false;
 }
 return true;
}		

// string is numeric
function isFloat(s) {
 if (isEmpty(s)) {
  return false;
 }
 if (isNaN(parseFloat(s))) {
  return false;
 }
 for (var i = 0; i < s.value.length; i++) {
   var ch = s.value.substring(i, i + 1);
   if((ch!=' ') && (ch!='\n') && (ch!='\t') && (ch!='.')) 
     if (ch < "0" || "9" < ch)return false;
 }
 return true;
}


function ContactFormVerify() {
	var msg;
	var empty_fields = "";
	var err = "";

  if (isEmpty(document.contactform.username))
    empty_fields += "\n  - your Name";
  if (isEmpty(document.contactform.company))
    empty_fields += "\n  - your Company";
  if (isEmpty(document.contactform.address))
    empty_fields += "\n  - your Address";
  if (isEmpty(document.contactform.tel))
    empty_fields += "\n  - your Telephone Number";
  if (isEmpty(document.contactform.fax))
    empty_fields += "\n  - your Fax Number";
  if (isEmpty(document.contactform.enquiry))
    empty_fields += "\n  - your Enquiry";
  if (!isEmail(document.contactform.email.value))
    err += "\n  - your Email";
	if (!empty_fields && !err) return true;

	msg = "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "\n\n";

	if ( (empty_fields.length > 1) || (err.length > 1) )
	{
		msg += "The following required field(s) are incomplete or incorrectly formatted:" + empty_fields + err + "\n";
		msg += "\n";
	}

	alert(msg);

  return false;
}

function EnquiryFormVerify() {
	var msg;
	var empty_fields = "";
	var err = "";

  if (isEmpty(document.contactform.username))
    empty_fields += "\n  - your Name";
  if (isEmpty(document.contactform.company))
    empty_fields += "\n  - your Company";
  if (isEmpty(document.contactform.address))
    empty_fields += "\n  - your Address";
  if (isEmpty(document.contactform.tel))
    empty_fields += "\n  - your Telephone Number";
  if (isEmpty(document.contactform.dates))
    empty_fields += "\n  - the Date(s) Required";
  if (!isEmail(document.contactform.email.value))
    err += "\n  - your Email";
	if (!empty_fields && !err) return true;

	msg = "The form was not submitted because of the following error(s).\n";
	msg += "Please correct these error(s) and re-submit.\n";
	msg += "\n\n";

	if ( (empty_fields.length > 1) || (err.length > 1) )
	{
		msg += "The following required field(s) are incomplete or incorrectly formatted:" + empty_fields + err + "\n";
		msg += "\n";
	}

	alert(msg);

  return false;
}

var i,y;
function loadImageSet(i) {
if (document.images)  {
 this.name = i;
 this.onImage = new Image();
 this.onImage.src = '../imgs/l-' + i + '-on.gif';
 this.offImage = new Image();
 this.offImage.src = '../imgs/l-' + i + '-off.gif';
 this.pickedImage = new Image();
 this.pickedImage.src = '../imgs/l-' + i + '-on.gif';
	}
}

var pick = -1;
var imageSets = new Array();

function doClick(i) {
if (document.images) {
 if (pick != -1) {
   self.document.images[imageSets[pick].name].src = imageSets[pick].offImage.src;
 }
 pick = i;
 self.document.images[imageSets[pick].name].src = imageSets[pick].pickedImage.src;
	}
}

function doMouseOver(i) {
 if (document.images) {
 if (i != pick) {
  self.document.images[imageSets[i].name].src = imageSets[i].onImage.src;
  }
 }
}

function doMouseOut(i) {
 if (document.images) {
 if (i != pick) {
  self.document.images[imageSets[i].name].src = imageSets[i].offImage.src;
  }
 }
}


// EMAIN NAVIGATION BAR
imageSets[0] = new loadImageSet('home');
imageSets[1] = new loadImageSet('rooms');
imageSets[2] = new loadImageSet('services');
imageSets[3] = new loadImageSet('events');
imageSets[4] = new loadImageSet('business');
imageSets[5] = new loadImageSet('visitor');
imageSets[6] = new loadImageSet('historical');
imageSets[7] = new loadImageSet('catering');
imageSets[8] = new loadImageSet('hotel');
imageSets[9] = new loadImageSet('chinese');
imageSets[10] = new loadImageSet('china');
imageSets[11] = new loadImageSet('virtual');
imageSets[12] = new loadImageSet('dometours');

var win;

function OpWin(i,x,y) {
win = open(i, '', 'width='+x+',height='+y+',resizable=0,toolbar=0,scrollbars=0,location=0,menubar=0,status=0,titlebar=0,top=0,left=0');
}

function goDate(m,y) {
	with (self.document.eventsform) {
		MONTH.value = m;
		YEAR.value = y;
		action = '/cgi-bin/events_list.pl';
    	submit();	
	}
}

function goDateChurch(m,y) {
	with (self.document.eventsform) {
		MONTH.value = m;
		YEAR.value = y;
		action = '/cgi-bin/events_list_church.pl';
    	submit();	
	}
}


var delay = 4000;
var imgNumber = 0;
var anim = new Array();

var totalimgNumber = 2;

for (var i = 0; i < totalimgNumber; i++) {
anim[i] = new Image (138, 80);
anim[i].src = '../imgs/pt-sign' + (i + 1) + '.jpg';
} 

function Switch() {                
document.images.picture.src = anim[imgNumber].src;
imgNumber++;
        if(imgNumber >= totalimgNumber) imgNumber = 0;
}
                
function animate() {
Switch();
setTimeout("animate()", delay);
}

function slow() {
delay+=10;
if(delay > 4000) delay = 4000;
}
        
function fast() {
delay-=10;
if(delay < 0) delay = 0;
}


document.write("<link REL='STYLESHEET' TYPE='text/css' HREF='../remotes/screen2.css' media='screen'>");
