/* Base Website Library
   Villa Castellamonte 
   Copyright (c) 2001-09 Exodus Enterprise Systems, LLC
*/

// Globals
ES_Domain = 'villacastellamonte.com';
ES_CONTACT = false;
_ecSiteNewbie = true;

// Empty initialization and termination functions
function initPage()	{}
function exitPage()	{}
function _ecSiteRetain() {}

ApacheRemoteAddr = '<!--#echo var="REMOTE_ADDR"-->';
ApacheServerAddr = '<!--#echo var="SERVER_ADDR"-->';
ApacheUserAgent = '<!--#echo var="HTTP_USER_AGENT"-->';
ApacheSoftware = '<!--#echo var="SERVER_SOFTWARE"-->';
ApacheName = '<!--#echo var="SERVER_NAME"-->';
ApacheHost = '<!--#echo var="REMOTE_HOST"-->';
ApacheLocal = '<!--#echo var="DATE_LOCAL"-->';
ApacheGMT = '<!--#echo var="DATE_GMT"-->';

function hasPopupBlocker() {
    /*  Function:      hasPopUpBlocker
        Creation Date: April 5, 2004
        Programmer:    Edmond Woychowsky
        Purpose:       The purpose of this function is to attempt to open
                       a popup window to determine if a popup blocker is
                       enabled.
        Update Date:            Programmer:         Description:
	*/
	var objChild;                           // Window
	var reWork = new RegExp('object','gi');	// Regular expression
	try {
		objChild = window.open('','child','width=50,height=50,status=no,resizable=yes'); 

		objChild.close();
	}
	catch(e) { }
	if(!reWork.test(String(objChild)))
		return true;
		// alert('Warning: A pop-up blocker is enabled for this site!');
	else
		return false;
		// alert('No pop-up blocker or pop-up blocker is disabled!');
}

// Get the arguments from either the active or passed location URL
function getURLArgs(theURL)	{
	var theArgs = new Object();						// Create a new object to hold the args
	var argv = getURLArgs.arguments;				// Get the function arguments
	if(argv.length == 0) {
		query = location.search.substring(1);		// Assume we are parsing the active location string
	} else {
		var queryLoc = theURL.indexOf('?');			// Or check to see if we have been passed one to parse
		if(queryLoc == -1) return;
		query = theURL.substr(queryLoc+1);
	}
	var arguments = query.split("&")				// Split into array arguments at the & symbol
	for(var i = 0; i < arguments.length; i++)	{
		var argLoc = arguments[i].indexOf('=');		// Look for name=value pair
		if (argLoc == -1) continue;					// Nothing found, go to next one
		var argName = arguments[i].substring(0,argLoc);		// Extract the name
		var argValue = arguments[i].substring(argLoc+1);	// Extract the value
		theArgs[argName] = unescape(argValue);				// Store in object as full string
		}
	return theArgs;
}
var ES_RELOAD = false;
var ES_URLARGS = getURLArgs();
if(ES_URLARGS["reload"])	{ ES_RELOAD = true; }

// Parse the URL elements from the string of data
function parseURL(theURL) {
    var e=/((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?/;
	
    if (theURL.match(e)) {
        return  {url: RegExp['$&'],
                protocol: RegExp.$2,
                host:RegExp.$3,
                path:RegExp.$4,
                file:RegExp.$6,
                hash:RegExp.$7};
    }
    else {
        return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
    }
}

// Create Bookmark in Popular Browsers
function bookmarkUs(aURL, aTitle)	{
	var aStr = "" + aTitle;
	if (document.all)	{
		window.external.AddFavorite(aUrl, aStr);
	}
}

// Reasonable attempt to get the basics about this session
function WhoIsIt() {
    this.platform  = navigator.platform.toLowerCase();
	this.agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
	this.ie = (agent.indexOf("msie") != -1);
	this.op3 = (agent.indexOf("opera") != -1);
	this.pc  = (agent.indexOf("win") != -1);
	this.mac = (agent.indexOf("mac")!=-1); // Mac detect
	this.client = ( (navigator.userAgent.indexOf('AOL')!=-1) || (navigator.userAgent.indexOf('CS 2000')!=-1) )? 1 : 0;
	this.moz = ( this.ns && (agent.indexOf("netscape/") == -1) );
	if (this.moz) this.ns = 0;
	this.HIDDEN = (this.ns) ? 'hide' : 'hidden';
	this.VISIBLE = (this.ns) ? 'show' : 'visible';
}
var ES_BROWSERINFO = WhoIsIt();


// Disable the right click button - Copyright © 2001-2005 Exodus Island Ventures
function disableRightClick(e)
{
	if(!document.rightClickDisabled) {	// Initialize event grabber
		if(document.layers) {
			document.captureEvents(Event.MOUSEDOWN); // NS
			document.onmousedown = disableRightClick;
		} else document.oncontextmenu = disableRightClick;  //IE
		return document.rightClickDisabled = true;
	}
	// Caught, generate message and abort
	var message = "The contents, images and underlying implementation of this website\n"+
				  "are all Copyright (c) 2001 - Present by Exodus Island Ventures.\n"+
				  "All Rights Reserved Worldwide.";

	if(document.layers || (document.getElementById && !document.all)) {
		if (e.which==2||e.which==3||e.eventPhase==2) {
			message += ("Code=" + e.which + "/" + e.eventPhase);
			alert(message);
			return false;
		}
	} else {
		alert(message);
		return false;
	}
}
//disableRightClick();

// Show or Hide BLOCK elements ('blockid','show|hide',...)
function ES_showHideBlocks() { //v1.0
	var i,p,v,obj,args=ES_showHideBlocks.arguments;
	for (i=0; i<(args.length-1); i+=2) 
  		if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+1];
			if (obj.style) { 
				obj=obj.style; 
				v=(v=='show')?'block':(v=='hide')?'none':v; 
			}
		obj.display=v; }
}

// Show or Hide LAYER elements ('layerid','show|hide',...)
function ES_showHideLayers()	{	//v1.0 - Lots of assumptions here!
	if(!document.layers) return;
	var i,args=ES_showHideLayers.arguments;
	for(i=0;i<(args.length-2);i+=3)	{
		v=(args[i+2]=='show')?'visible':'hidden';
		document.layers.args[i].style.visibility=v;
   }
}

// Loads images in the 'background'
function EA_lazypreloadImages()	{	//v1.0
	var x,args=EA_lazypreloadImages.arguments
	var d=document;
	if(args.length>0)	{
		if(!d.EA_lazyFiles)	{
			d.EA_lazyFiles = new Array();
			d.EA_lazyImgs = new Array();
			d.EA_lazyStart = new Date();
		}
		for(x=0;x<args.length+1;x++)	{
			d.EA_lazyFiles.push(args[x]);
		}
	}
	if(!d.EA_preloader)	{
		d.EA_preloader = setInterval("EA_lazypreloadImages()", 250);
	}
	var i=new Image();
	i.src=d.EA_lazyFiles.pop();
	d.EA_lazyImgs.push(i);
	if(d.EA_lazyFiles.length==0)	{
		clearInterval(d.EA_preloader);
		d.EA_lazyFiles=new Array();
//		alert('Done in ' + (new Date()- d.EA_lazyStart)/1000 + " secs");
	}
}

// Generate a random number between 0 and num
function getRand(num)	{
	return (Math.floor(Math.random()*num)+1);
}

// Set the receipient element to the parameter provided
function setRecipient(aVal)	{
	if((s = MM_findObj('recipient')) != null)	{
		s.value = aVal + '@' + ES_Domain;
	}
}

// Locate all elements with a specified class name
// Format: getElementsByClassName(document, 'TD', 'required')
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
	    oElement = arrElements[i];
	    if(oRegExp.test(oElement.className)){
	        arrReturnElements.push(oElement);
	    }
	}
	return (arrReturnElements)
}

function num2Currency(num)	{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

// Pad the string on the left
function padleft(val, ch, num) {
    var re = RegExp(".{" + num + "}$");
    var pad = "";

    do {
        pad += ch;
    }
    while (pad.length < num)

    return re.exec(pad + val);
}

// Pad the string on the right
function padright(val, ch, num) {
    var re = RegExp("^.{" + num + "}");
    var pad = "";

    do {
        pad += ch;
    }
    while (pad.length < num)

    return re.exec(val + pad);
}

function ltrim(str) {
    return str.replace(/^\s+/, '');
}

function rtrim(str) {
    return str.replace(/\s+$/, '');
}

function alltrim(str) {
    return str.replace(/^\s+|\s+$/g, '');
}

// Set the value of an INPUT
function ES_setInputValue(e,v)	{
	var obj;
	if((obj=MM_findObj(e))!=null) {
		obj.value=v;
	}
}

// Get the value of an INPUT
function ES_getInputValue(e)	{
	var obj;
	if((obj=MM_findObj(e))!=null) {
		return obj.value;
	}
}

// Delay for a specific number of milleseconds
function ES_delay(ms)	{
	ms += new Date().getTime();
	while (new Date() < ms){}
}


/* Create a Fade Effect */
var ES_fader=function(){
    return{
        init:function(id, flag, target){
            this.elem = document.getElementById(id);
            clearInterval(this.elem.si);
            this.target = target ? target : flag ? 100 : 0;
            this.flag = flag || -1;
            this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
            this.si = setInterval(function(){ES_fader.tween()}, 20);
        },
        tween:function(){
            if(this.alpha == this.target){
                clearInterval(this.elem.si);
            }else{
                var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag);
                this.elem.style.opacity = value / 100;
                this.elem.style.filter = 'alpha(opacity=' + value + ')';
                this.alpha = value
            }
        }
    }
}();

/* ------------- */
/* 
	The following code is generated by Macromedia Dreamweaver, copied here for convenience
*/

// Restore an image that was previously swapped.
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// Preload images for this page.
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Locate an object in the document.
function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Swap an image
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Write a message to the status area.
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


