// EVENTS

function addEvent(o,t,fn){
	if( o.attachEvent ){
   	o['e'+t+fn] = fn;
   	o[t+fn] = function(){o['e'+t+fn](window.event);};
   	o.attachEvent('on'+t, o[t+fn]);
   }else{
   	o.addEventListener(t,fn,false);
   }
}

function removeEvent(o,t,fn){
  if( o.detachEvent ){
    o.detachEvent('on'+t,o[t+fn]);
    o[t+fn] = null;
  }else{
     o.removeEventListener(t,fn,false);
  }
}

// STYLE

function findPosX(o){
	var curleft = 0;
	if(o.offsetParent){
		while(o.offsetParent){
			curleft += o.offsetLeft;
			o = o.offsetParent;
		}
	}else if(o.x){
		curleft += o.x;
	}
	return curleft;
}

function findPosY(o){
	var curtop = 0;
	if(o.offsetParent){
		while(o.offsetParent){
			curtop += o.offsetTop;
			o = o.offsetParent;
		}
	}else if(o.y){
		curtop += o.y;
	}
	return curtop;
}


// PROTOTYPES

if( ! Array.push ){
	Array.prototype.push = function(){
		for( var i = 0 ; i < arguments.length ; i++ ){
			this[this.length] = arguments[i];
		}
		return this.length;
	};
}

if( ! String.trim ){
	String.prototype.trim = function(){
		return this.replace(/^\s+|\s+$/g,"");
	};
}

if( ! String.paddLeft ){
	String.prototype.paddLeft = function(c,l){
		var ret = this;
		while( ret.length < l ){
			ret = c + ret;
		}
		return ret;
	};
}

// DOM

function insertAfter(parent,node,referenceNode) {
  	parent.insertBefore(node,referenceNode.nextSibling);
}

function getElementsByClassName(el,tag,c){
	var elements = el.getElementsByTagName(tag);
	var ret = [];
	for( var i = 0 ; i < elements.length ; i++ ){
		if( elements[i].className && elements[i].className.toString().indexOf(c) >= 0 ){
			ret.push( elements[i] );
		}
	}
	return ret;
}


/*
if( ! Document.getElementsByClassName ||
	 ! Element.getElementsByClassName ){
	Document.prototype.getElementsByClassName = 
	Element.prototype.getElementsByClassName = function(s){
		// mmm change the attribute selector here!!!
		return this.selectNodes(".//*[@class='"+ s +"']");
	};
}

Node.prototype.selectNodes = function(xpath){
	var doc = ( this.nodeType == 9 ) ? this : this.ownerDocument;
	var oNSResolver = this.createNSResolver(this.documentElement);
	var nodes = this.evaluate(xpath,this,oNSResolver,0,null);
	var nodelist = [];
	var node = nodes.iterateNext();
	while( node ){
		nodelist.push( node );
		node = nodes.iterateNext();
	}
	return nodelist;
}

Element.prototype.selectNodes = function(xpath){
	return this.ownerDocument.selectNodes(xpath,this);
}

Element.prototype.selectSingleNode = function(xpath){
	return this.ownerDocument.selectSingleNode(xpath,this);
}

Node.prototype.__defineGetter__('xml',function(){return (new XMLSerializer()).serializeToString(this);});
Node.prototype.__defineGetter__('outerHTML',function(){return this.xml;});
*/
/* An extra function */


// popup
var win;

function getWindowCenter(_iX,_iY){
	var iWinX=(screen.width - _iX)/2;
	var iWinY=(screen.height - _iY)/2;
	return('top='+iWinY+',left='+iWinX);
}

function createWindowName(_sUrl){
	var _iLastSlash=_sUrl.lastIndexOf('/');
	var _iLastSlashMin=_sUrl.substring(0,(_iLastSlash-1)).lastIndexOf('/');
	return(_sUrl.substr(_iLastSlash,_sUrl.length).indexOf('.')>0)?('file_'+escape(_sUrl.substring(_iLastSlash+1,_sUrl.lastIndexOf('.')))):('file_'+ escape(_sUrl.substring((_iLastSlashMin+1),_iLastSlash)));
}

function createWindow(_sUrl,_sName,_sParams){
	win=window.open(_sUrl,_sName,_sParams);
	if(win){win.focus();}
	return(win);
}

function w(_sUrl,_sType){
	var _sParams,_sName,_sWinPos,_iX,_iY;
	switch(_sType){
		case'popup_reservation':
		case'popup_rates':
		   	_iX=560;
		   	_iY=580;
   			_sParams='height='+_iY+',width='+_iX+',scrollbars=1,location=0;toolbars=0,resizable=1,status=1';
		   	_sName='form';
	   		break;
		case'popup_rooms':
		   	_iX=600;
		   	_iY=350;
   			_sParams='height='+_iY+',width='+_iX+',scrollbars=1,location=0;toolbars=0,resizable=1,status=1';
		   	_sName='p_room';
   			break;
		case'popup_image':
		   	_iX=600;
		   	_iY=450;
   			_sParams='height='+_iY+',width='+_iX+',scrollbars=1,location=0;toolbars=0,resizable=1,status=1';
		   	_sName='p_image';
   			break;
	};
	_sWinPos=getWindowCenter(_iX,_iY);
	_sParams+=','+_sWinPos;
	return(createWindow(_sUrl,_sName,_sParams));
}

function parentNav(_sUrl){
	if(window.opener != null){
		window.opener.location=_sUrl;
		window.opener.focus();
	}
}


