/* ******************************************************************************* */
/* Application : emyUtil.js Version 1.0                                            */
/* Author      : Wicky Poon	 August 20, 2002                                       */
/* Copyright   : Copyright (c) 2002 EMY Solutions                                  */
/* Description : Global module holding the utility methods for the Web site.       */
/*                                                                                 */
/* ******************************************************************************* */
// Define Primary Variables
var datLTime = new Date();
var scrWidth, scrHeight;
var value = 100;
var plus = 1;
var minus = 0;
pixid = 0;
loopCtr = 0;

// connect the onmousedown event of the document object to our function

// for Netscape Navigator 4.x
/*	if (document.layers) 
		noRightClick(window.captureEvents(Event.MOUSEDOWN));
	else	
		document.onmousedown = noRightClick;	
*/		
//	if (ns && appMajor < 5) window.onmousedown = noRightClick;

/*** Define primary functions ***/
function isEmailAddress(email_address) {

	// we can only check that the e-mail address is valid, not that it actually exists
	var goodAddress = false;
	// the following expression must be all on one line...	
	var goodEmail = email_address.match(/^\w(\.?[\w-])*@\w(\.?[\w-])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/gi);
	if (goodEmail) 
		goodAddress = true;
	return goodAddress;
}

function isDomain(domain) {
// we can only check that the website domain is valid, not that it actually exists
// the following expression must be all on one line...
	var bool = domain.match(/^http[s]?:\/\/[www\.]?\w(\.?[\w-])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/gi);
    if (bool) return (true);
    return (false);   
}

function formatDomain(domain) {
    if (!(domain.match(/^http[s]?:\/\//gi)))
	domain = "http://" + domain;
	return domain;
}	

function Trim(trim_value){
	
	if(trim_value.length < 1) return '';
    
	trim_value = RTrim(trim_value);
	trim_value = LTrim(trim_value);
	
	if(trim_value == '') {
		return '';
	} else {
		return trim_value;
	}
	
} //End Function

function RTrim(value){

	var w_space = String.fromCharCode(32);
	var v_length = value.length;
	if (v_length < 1) return '';
	
	var strTemp = '';
	var iTemp = v_length - 1;

	while (iTemp > -1) {
		if (value.charAt(iTemp) == w_space) {
			doNothing();
		} else {
			strTemp = value.substring(0, iTemp + 1);
			break;
		}
		iTemp = iTemp - 1;

	} //End While
	
	return strTemp;

} //End Function

function LTrim(value){

	var w_space = String.fromCharCode(32);
	var v_length = value.length;
	if (v_length < 1) return '';
	
	var strTemp = '';
	var iTemp = 0;
	
	while (iTemp < v_length) {
		if (value.charAt(iTemp) == w_space) {
			doNothing();		 
		} else {
			strTemp = value.substring(iTemp, v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	
	return strTemp;

} //End Function

function doNothing() { }

function findObj(n, d) { //v3.0
  	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 = findObj(n, d.layers[i].document);
  	return x;
}

function preloadImages() { //v3.0
	var d = document;
 	if (d.images) {
 		if (!d.pix) d.pix = new Array();
   		var i, j = d.pix.length, a = preloadImages.arguments;
   		for (i = 0; i < a.length; i++) {
   			if (a[i].indexOf("#") != 0) {
   				d.pix[j] = new Image;
   				d.pix[j++].src = a[i];
   			}
   		}	
   	}
}

function reloadPage(init) { 
	// Environment: Netscape Navigator 4.x+
	if (init == true) with (navigator) {
		if ((appName.toLowerCase() == "netscape") && (parseInt(appVersion) >= 4)) {
			document.pgW = innerWidth;
			document.pgH = innerHeight;
			onresize = reloadPage;
		}
	}
	else if (innerWidth != document.pgW || innerHeight != document.pgH)
		location.reload();
}

function swapImage() { //v3.0
  	var i, j = 0, x, a = swapImage.arguments;
  	document.imgSrc = new Array();
  	for (i = 0; i < (a.length - 2); i += 3) {
	   if ((x = findObj(a[i])) != null) {
	       document.imgSrc[j++] = x;
	    	if (!x.oSrc) x.oSrc = x.src;
	    	x.src = a[i + 2];
	   }
    }
}

function swapImgRestore() { //v3.0
  	var i, x, a = document.imgSrc;
  	for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
  		x.src = x.oSrc;
}

function getCookieValue(cookieName) {
   var cookieValue = document.cookie;
   var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
   if (cookieStartsAt == -1) cookieStartsAt = cookieValue.indexOf(cookieName + "=");
   if (cookieStartsAt == -1) {
		cookieValue = null;
   } else {
      cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
      var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
      if (cookieEndsAt == -1) cookieEndsAt = cookieValue.length;
      cookieValue = unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt));
   }
   return cookieValue;
}

function getPlatform() {
	var myUserAgent = navigator.userAgent.toLowerCase();
	if ((myUserAgent.indexOf("win") != -1) || (myUserAgent.indexOf("16bit") != -1)) return "win";
	if (myUserAgent.indexOf("mac") != -1) return "mac";
	if (myUserAgent.indexOf("x11") != -1) return "unix";
	return "unknown";	
}

function noRightClick(e) {

    // Environment: IE 4.0+ and Nav4.x 	
	var strCRMsg = "All rights reserved by Mississauga Chiness Business Association!!";
	if ((document.layers) && (e.which > 1))	{	
		// for NN4.x 
		alert(strCRMsg);
	} 
	if ((document.all) && (event.button > 1)) {	
		// for IE4+
		alert(strCRMsg);		
	}
	if ((document.getElementById) && !(document.all) && (e.which == 3))	{	
		// for NN6+
		alert(strCRMsg);
		window.event.cancelBubble = false;
	}
	return;
}

function setCookie(cookieName, cookieValue, cookiePath, cookieExpires) {
   
  // cookieValue = escape(cookieValue);
   if (cookieExpires == "") {
      var nowDate = new Date();
      nowDate.setMonth(nowDate.getMonth() + 1);
      cookieExpires = nowDate.toGMTString();
   }
   if (cookiePath != "") cookiePath = ";Path=" + cookiePath;
   document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;

}

function setPointer(theRow, thePointerColor, theNormalBgColor) {

    var theCells = null;
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') return(false);
    if (typeof(document.getElementsByTagName) != 'undefined') theCells = theRow.getElementsByTagName('td');
    else if(typeof(theRow.cells) != 'undefined') theCells = theRow.cells;
    else return (false);
    var rowCellsCnt = theCells.length;
    var currentColor = null;
    var newColor = null;
// Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		newColor = (currentColor.toLowerCase() == thePointerColor.toLowerCase()) ? theNormalBgColor : thePointerColor;
		for (var c = 0; c < rowCellsCnt; c++)
            theCells[c].setAttribute('bgcolor', newColor, 0);		       
    } else {
		currentColor = theCells[0].style.backgroundColor;
		newColor = (currentColor.toLowerCase() == thePointerColor.toLowerCase()) ? theNormalBgColor : thePointerColor;
		for (var c = 0; c < rowCellsCnt; c++)
            theCells[c].style.backgroundColor = newColor;
    }
    return (true);
			
} // eof setPointer()

function submitform(theForm) { document.getElementById(theForm).submit(); }

function OpenWindow(SourceUrl, WndName, WndProp) {
	var newWnd = window.open(SourceUrl, WndName, WndProp);
	return false;
}

function getScreenResolution() {
	if (document.all) {
		scrWidth = window.screen.availWidth;
		scrHeight = window.screen.availHeight;
	} else {
		scrWidth = innerWidth;
		scrHeight = innerHeight;
	}	
}

function WndStatus() { window.status = 'Wyford Suites - Fully Furnished and Unfurnished Luxury Suites'; }
function AnimationImage(myID, myPix, myTitle, myTitleID, interval) { 
	setInterval("fadeImage('" + myID + "', '" + myPix + "', '" + myTitle + "', '" + myTitleID + "')", interval * 100); 
}

function fadeImage(myID, myPix, myTitle, myTitleID) {
	var myPixArray = myPix.split(",");
	var myTitleArray = myTitle.split(",");
	loopCtr += 1;
	if (value < 100 && plus == 1) {
		value += 10;
	} else {
		plus = 0;
		minus = 1;
	}

	if (value > 30 && minus == 1) {
		value -= 10;
	} else {
		plus = 1;
		minus = 0;
	}
	if (value <= 30 && plus == 1) {
		pixid += 1;
		if (pixid >= myPixArray.length) pixid = 0;
		document.getElementById(myID).src = myPixArray[pixid];	
	//	document.getElementById(myID).title = myTitleArray[pixid];			
		if (document.all) {
			document.getElementById(myTitleID).innerText = myTitleArray[pixid];
		} else if (document.getElementById) {
			document.getElementById(myTitleID).innerHTML = myTitleArray[pixid];	
		
		
		} else {
		
		
		
		
		}
	}
//	if (window.sidebar) document.getElementById(myID).style.MozOpacity = value + "%";
//	if (document.all) document.getElementById(myID).filters[0].opacity = value; 
}

getScreenResolution();