

// ##############################
// SlideShow    slideshow(1,preCount[1],8000);
//###############################

function slideshow(start,last,interval) {
  var frame = start;
  var nextframe = start+1;
  Effect.Appear('img1',{duration:.5,from:0.0,to:1.0});
    setInterval(function() {
    Effect.Fade('img'+frame,{duration:.5,from:1.0,to:0.0,afterFinish:function(){
    $('img'+frame).hide();
    Effect.Appear('img'+nextframe,{duration:.5,from:0.0,to:1.0});
    frame = nextframe;
    nextframe = (frame == last) ? start : nextframe+1;
    }});
 },interval);
 return;
};
// check that AJAX is possible and define an AJAX object. 
function GetXmlHttpObject() {
	var MyAjax=null;
	try {
  		// Firefox, Opera 8.0+, Safari
  		MyAjax=new XMLHttpRequest();
  	}
	catch (e) {
  		// Internet Explorer
  		try { MyAjax=new ActiveXObject("Msxml2.XMLHTTP"); }
  		catch (e) { MyAjax=new ActiveXObject("Microsoft.XMLHTTP"); }
  	}
	return MyAjax;
} 


// ##############################
// Google Maps
//###############################

var map;
var kobehtml = "<img src='images/kobe_small.gif' width='222' height='71' alt='Kobe Japanese Restaurant'>";
var suttonhtml = "<b>Sutton Place Hotel</b><br>845 Burrard Street<br>Vancouver, BC";
var hyatthtml = "<b>Hyatt Regency</b><br>655 Burrard Street<br>Vancouver, BC";
var fairmonthtml = "<b>Fairmont Hotel Vancouver</b><br>900 West Georgia Street<br>Vancouver, BC";
var fourSeasonhtml = "<b>Four Seasons Hotel Vancouver</b><br>791 West Georgia Street<br>Vancouver, BC";
var markKobe = new GMarker(new GPoint(-123.122567,49.284526));
var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
	blueOption = { icon:blueIcon };		
var markBlueA = new GMarker(new GPoint(-123.123530,49.282929),blueOption); // Sutton Place
var markBlueB = new GMarker(new GPoint(-123.120325,49.285016),blueOption); // Hyatt
var markBlueC = new GMarker(new GPoint(-123.120116,49.283683),blueOption); // Fairmont Hotel Vancouver
var markBlueD = new GMarker(new GPoint(-123.118815,49.283149),blueOption); // Four Seasons Vancouver
function loadMap() {
	// clearTimeout(flaTime);
	// vidStatus = 1;
	if (GBrowserIsCompatible()) {
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		// document.getElementById("topMask").style.zIndex = 8;	
		map = new GMap(document.getElementById("mapBox"));
		map.addControl(new GSmallMapControl(), topRight);	
		map.centerAndZoom(new GPoint(-123.122567,49.284526), 2);
		map.addOverlay(markKobe);
		map.addOverlay(markBlueA);
		map.addOverlay(markBlueB);
		map.addOverlay(markBlueC);
		map.addOverlay(markBlueD);
		GEvent.addListener(markKobe, 'click', function() { bubbleKobe(); });
		GEvent.addListener(markBlueA, 'click', function() { bubbleSutton(); });
		GEvent.addListener(markBlueB, 'click', function() { bubbleHyatt(); });
		GEvent.addListener(markBlueC, 'click', function() { bubbleFairmont(); });
		GEvent.addListener(markBlueD, 'click', function() { bubbleFourSeasons(); });
	      bubbleKobe();
	}
}
function bubbleKobe(){
	// map.centerAndZoom(new GPoint(-123.122567,49.284526), 2);
	markKobe.openInfoWindowHtml(kobehtml);
}
function bubbleSutton(){
	// map.centerAndZoom(new GPoint(-123.123530,49.282929), 2);
	markBlueA.openInfoWindowHtml(suttonhtml);	
}
function bubbleHyatt(){
	// map.centerAndZoom(new GPoint(-123.120325,49.285016), 2);
	markBlueB.openInfoWindowHtml(hyatthtml);	
}
function bubbleFairmont(){
	// map.centerAndZoom(new GPoint(-123.120116,49.283683), 2);
	markBlueC.openInfoWindowHtml(fairmonthtml);	
}
function bubbleFourSeasons(){
	// map.centerAndZoom(new GPoint(-123.118815,49.283149), 2);
	markBlueD.openInfoWindowHtml(fourSeasonhtml);	
}
	
	
   
//----------------------------------------------
// FORM VALIDATION - intelliForms v1.0 by rudy@digifx.tv aka: Intelligent Live Forms or ILF
// vType Legend (validationType~MinChars~maxChars~mustMatchID
// IF you use this script, please leave my credit intact. 
//----------------------------------------------
function mustMatch(me,you){
	if (me.value != document.getElementById(you).value){
	me.value="";
	borderThis(me,1);
	borderThis(document.getElementById(you),1);
	document.getElementById(you).value="";
	document.getElementById(you).focus();
	}

}
function borderThis(theObj,mode){
	if (mode == 0) { 
		theObj.style.border = "1px #000000 solid";
	//	theObj.style.background = "#FFFFFF";
	} else if (mode == 1){ 
		theObj.style.border = "1px #ff0033 solid";
	//	theObj.style.background = "#fee9e9";
	} else if (mode == 2){ 
		theObj.style.border = "1px #33cc33 solid";
	//	theObj.style.background = "#eeffd9";
		//theObj.style.background = "#eeffd9";
		//setTimeout("theObj.style.background = '#FFFFFF'",2000);
	} //repeat as required.
	
}
function getIndex(theObj) {
	var index = -1, i = 0, found = false;
	while (i < theObj.form.length && index == -1) {
		if (theObj.form[i] == theObj) { index = i; } else { i++; }
	}
	return index;
}
function checkField(theObj) {
//	var reAlpha = /!|@|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|\.|>|\\|\?|\||\/|\d/;  // my regular expression - in the works.     reAlpha.exec(elemVal)
//	var reNumba = /!|@|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|\.|>|\\|\?|\||\/|\D/
//	var reEmail = /!|#|\$|%|`|~|\^|&|\*|\(|\)|_|\-|=|\+|'|"|:|;|\]|\[|\{|\}|,|<|>|\\|\?|\||\//; // same as Alpha but . @ and numbers are permitted
	var reAlpha = /[^A-Za-z]/;
	var reEmail = /[^A-Za-z@._0-9\-]/;
	var reNumba = /[^0-9]/;
	var reAlphaNum = /[^A-Za-z0-9]/;
	var reAlphaNumS = /[^A-Za-z\ 0-9]/;
	var rePostalA = /[^A-Za-z]/;
	var rePostal1 = /[^0-9]/;
	//var reSelect = /[^A-Za-z0-9 ]/;	
	var preChkStr = theObj.className.split(" ");
	var chkStr = preChkStr[1].split("~"); 	
	var elemVal = theObj.value;
	var q = 0, f = 0;
	if(elemVal.length >= chkStr[2]) { theObj.value = elemVal.slice(0, chkStr[2]); theObj.form[(getIndex(theObj)+1) % theObj.form.length].focus(); } // TOO LONG
	if (elemVal.length < chkStr[1]){ borderThis(theObj,1);  q=q+1;} // TOO SHORT 
	if (chkStr[0] == 'numba') { if ( reNumba.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reNumba.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'email') { 
			if ( reEmail.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reEmail.exec(elemVal))); q=q+1;}
			if ((elemVal.indexOf('.') == -1) || (elemVal.indexOf('@') == -1)) { q=q+1;
			} else if (elemVal.split("@").length > 2){ theObj.value = elemVal.slice(0, elemVal.indexOf("@")); q=q+1;
			} else { if (elemVal.split("@").length == 2) { tVarA=elemVal.split("@");
							if (tVarA[1].split(".").length != -1) { tVarB=tVarA[1].split(".");
								if ((tVarB[1].length < 2) || (tVarB[1].length > 6)) { q=q+1; }
							} else { q=q+1;}
					} else { q=q+1;}
			}
	} else if (chkStr[0] == 'alpha') { if ( reAlpha.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlpha.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'alphaNum') { if ( reAlphaNum.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlphaNum.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'alphaNumS') { if ( reAlphaNumS.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reAlphaNumS.exec(elemVal))); q=q+1;}
	} else if (chkStr[0] == 'postalA') { if (elemVal.split("").length == 3) { tVarA=elemVal.split(""); if ( rePostalA.exec(tVarA[0])+rePostal1.exec(tVarA[1])+rePostalA.exec(tVarA[2]) != 0){q=q+1;}}
	} else if (chkStr[0] == 'postalB') { if (elemVal.split("").length == 3) { tVarA=elemVal.split(""); if ( rePostal1.exec(tVarA[0])+rePostalA.exec(tVarA[1])+rePostal1.exec(tVarA[2]) != 0){q=q+1;}}
	} else if (chkStr[0] == 'select') { /* if ( reSelect.exec(elemVal) != null) { theObj.value = elemVal.slice(0, elemVal.indexOf(reSelect.exec(elemVal))); q=q+1;} */
	} else { // borderThis(theObj,0); alert("did nothing");		alert("q="+q+"f="+f+"objName="+theObj.id);
	} 
	if (q > 0){ borderThis(theObj,1); if (f < 0){ alert("f was 0");	document.getElementById(theObjid).focus(); f=1;} return 'no'; } else { borderThis(theObj,2); return 'ok';}
}
function formCheck(obj,goesTo,showsIn) {
	var getstr = "";
	var myOkStr = "";
	for (i=0; i<obj.form.length; i++) {
		if (obj.form[i].tagName == "INPUT") {
			if (obj.form[i].type == "text") {  //ok
				myOkStr = myOkStr+checkField(obj.form[i])+",";
				getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
			}	
			if (obj.form[i].type == "password") { //ok
				myOkStr = myOkStr+checkField(obj.form[i])+",";
				getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
			}			
			if (obj.form[i].type == "checkbox") {
				if (obj.form[i].checked) {
					getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
				} else {
					getstr += obj.form[i].id + "=&"; // could possibly omit`
				}
			}
			if (obj.form[i].type == "radio") {
				if (obj.form[i].checked) {
					getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
				}
			}
		}  
		if (obj.form[i].tagName == "SELECT") {
			myOkStr = myOkStr+checkField(obj.form[i])+",";
			var sel = obj.form[i];
			getstr += sel.id + "=" + sel.options[sel.selectedIndex].value + "&";
		}   
		if (obj.form[i].tagName == "textarea") {
			myOkStr = myOkStr+checkField(obj.form[i])+",";
			getstr += obj.form[i].id + "=" + obj.form[i].value + "&";
		}         
	}//     alert(chkStr); 	alert(myOkStr);
	//alert(getstr);
	if (myOkStr.indexOf('no') == -1){ 
	//	postRequest(goesTo, getstr); 
	getData(goesTo, showsIn, getstr); // this calls the form submission method
	} else {
		document.getElementById('myspan').innerHTML = "An error occured with your request. Please ensure that no fields are highlighted red"; //document.getElementById('myspan').innerHTML + 
		reBox();
	}
	return false
}

var formJax
   function getData(goesTo, showsIn, postStr) {
 		formJax=GetXmlHttpObject();
		var postStr  = postStr+"randy="+Math.random();
		// alert("going to send:"+postStr);
		formJax.open("POST",goesTo,true);
		formJax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		formJax.onreadystatechange = function() {
			if (formJax.readyState == 4 && formJax.status == 200) { //	alert("i changed state");
			// document.getElementById(showsIn).innerHTML = formJax.responseText;
				if (formJax.responseText.indexOf('<!-- ok -->') != -1){  document.getElementById(showsIn).innerHTML = formJax.responseText; 
				} else { document.getElementById('myspan').innerHTML = formJax.responseText;
				} reBox();
			} else if( formJax.readyState == 4 && formJax.status != 200){
			// alert(formJax.responseText);
				document.getElementById('myspan').innerHTML = "an internal error has occured, please retry your request.<br>If this problem persists, please contact a system administrator."; 
				alert(formJax.responseText);
			}
         }
       formJax.send(postStr);
     }

	 
function placeTaggy(){
	taggy = document.getElementById('tagga_tagg').style;
	taggy.position ="absolute";
	taggy.top = "200px";
	taggy.left = "200px";
	taggy.zIndex = 20000;
	taggy.backgroundColor = "#FFFFFF";
}	 
