/***********************************************************************************
*																				   *
*	Copyrights (c) Rackup, LLC. (2008-2010)										   *
*   ALL RIGHTS RESERVED										                       *
*																				   *
***********************************************************************************/

var RAP = {

	ELEMENT_NODE: 1,
	ATTRIBUTE_NODE: 2,
	TEXT_NODE: 3,
	CDATA_SECTION_NODE: 4,
	ENTITY_REFERENCE_NODE: 5,
	ENTITY_NODE: 6,
	PROCESSING_INSTRUCTION_NODE: 7,
	COMMENT_NODE: 8,
	DOCUMENT_NODE: 9,
	DOCUMENT_TYPE_NODE: 10,
	DOCUMENT_FRAGMENT_NODE: 11,
	NOTATION_NODE: 12,
	
	msie: /MSIE/.test(navigator.userAgent),
	firefox: /Firefox/.test(navigator.userAgent),
	chrome: /chrome/.test(navigator.userAgent),
	safari: /webkit/.test(navigator.userAgent) && !/chrome/.test(navigator.userAgent),
	opera: /Opera/.test(navigator.userAgent),
	
	supportedBrowsers:
	[
		{
			test: /MSIE/.test(navigator.userAgent),
			key: "MSIE ",
			minVersion: [ 7, 0 ]
		},
		{
			test: /Firefox/.test(navigator.userAgent),
			key: "Firefox/",
			minVersion: [ 3, 5 ]
		},
		{
			test: /Chrome/.test(navigator.userAgent),
			key: "Chrome/",
			minVersion: [ 4 , 1 ]
		},
		{
			test: /WebKit/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent),
			key: "Version/",
			minVersion: [ 4 , 0 ]
		},
		{
			test: /Opera/.test(navigator.userAgent),
			key: "Version/",
			minVersion: [ 10 , 0]
		}
	],
	
	supportedBrowser:
	function(){
		var supported = false;
		for(i=0; i<this.supportedBrowsers.length; i++){
			if (this.supportedBrowsers[i].test){
				var version = '';
				var pos = navigator.userAgent.indexOf(this.supportedBrowsers[i].key);
				if (pos>=0){
					for(c=pos+this.supportedBrowsers[i].key.length;c<navigator.userAgent.length;c++){
						ch = navigator.userAgent.charAt(c);
						if((ch=='.') || (("0"<=ch) && (ch<="9"))){
							version += ch;
						} else {
							break;
						}
					
					}
				}
				var currentVersion = version.split(".");
				if (currentVersion.length>=2){
					if(parseInt(currentVersion[0])>this.supportedBrowsers[i].minVersion[0]){
						supported = true;
						break;
					} else {
						if(parseInt(currentVersion[0])==this.supportedBrowsers[i].minVersion[0]){
							if(parseInt(currentVersion[1])>=this.supportedBrowsers[i].minVersion[1]){
								supported = true;
								break;
							}
						}
					}
				} else {
					if (currentVersion.length>=1){
						if(currentVersion[0]>this.supportedBrowsers[i].minVersion[0]){
							supported = true;
							break;
						}
					}
				}
			}
		}
		return supported;
	},
	
	byID:
	function(name){
		return document.getElementById(name);
	},

	getSize:
	function(elem){
		return {w:elem.offsetWidth,h:elem.offsetHeight};
	},

	getWindowCenter:
	function(){
		var _x = 0;
		var _y = 0;

		if(!window.innerWidth){
			if(!(document.documentElement.clientWidth==0))
			{
				_x = document.documentElement.clientWidth;
				_y = document.documentElement.clientHeight;
			} else {
				_x = document.body.clientWidth;
				_y = document.body.clientHeight;
			}
		} else {
			_x = window.innerWidth;
			_y = window.innerHeight;
		}
		
		_x=_x/2;
		_y=_y/2;
		return {x: _x,y: _y};
	},

	centerElement:
	function(name){
		var elem = this.byID(name);
		if(elem){
			if(this.msie){
				elem.style.position = 'absolute';
			}
			elem.style.left = (this.getWindowCenter().x - (this.getSize(elem).w/2)) + "px";
		}
	},

	stickToBottom:
		function(name,dv){
		var elem = this.byID(name);
		if(elem){
			if(!dv){
				dv = 0;
			}
			if(this.IE){
				elem.style.position = 'absolute';
			}
			elem.style.top = ((this.getWindowCenter().y) * 2 - elem.offsetHeight -dv) + "px";
		}
	},

	stickToRight:
	function(name,dh){
		var elem = this.byID(name);
		if(elem){
			if(!dh){
				dh = 0;
			}
			if(this.msie){
				elem.style.position = 'absolute';
			}
			elem.style.left = ((this.getWindowCenter().x) * 2 - elem.offsetWidth - dh -40) + "px";
		}
	},

	topLinks:
	function(){
		var html='';
		html += '<table width="100%"><tr><td align="center" style="text-align: center;">\n';
		html += '<p class="topLinks" align="center" style="text-align: center;" >\n';
		html += '		&nbsp;\n';
		html += '		<a href="index.html" class="topLinks">Home</a>\n';
		html += '		&nbsp;|&nbsp;\n';
		html += '		<a href="contact-information.html" class="topLinks">Contact Information</a>\n';
		html += '		&nbsp;|&nbsp;\n';
		html += '		<a href="about-us.html" class="topLinks">About us</a>\n';
		html += '		&nbsp;\n';
		html += '	</p>\n';
		html += '</td></tr></table>\n';
		document.writeln(html);
	},

	pageHeader:
	function(){
		var html='';
		html += '<a href="index.html"><img id="rackup-logo" src="../images/rackup_logo_header.png" alt="Rackup.com" border="0" /></a>';
		html += '<div class="grayLine"></div>';
		document.writeln(html);
	},

	pageFooter:
	function(){
		var html='';
		html += '<div class="grayLine"></div>';
		document.writeln(html);
		this.topLinks();
		html='';
		html += '<p align="center" width="100%">&copy;2010 Rackup LLC.</p>';
		document.writeln(html);
	},

	gotoPage:
	function(page){
		var url = window.location.protocol + "//" + window.location.host + "/" + page;
		window.location.assign(url);
	},
	
	baseURL:
	function(){
		var url = window.location.protocol+"//"+window.location.host;
		var ar_path = window.location.pathname.split("/");
		if(ar_path.length>2){
			for($i=1;$i<(ar_path.length-1);$i++){
				url += "/" + ar_path[$i];
			}
		}
		return url;
	},
	
	currentURL:
	function(){
		return window.location.protocol+"//"+window.location.host+window.location.pathname;
	},
	
	areCookiesEnabled: function (){
		var result = false; 
		if (typeof document.cookie == "string") { 
			if (document.cookie.length == 0) { 
				document.cookie = "test"; 
				result = (document.cookie == "test"); 
				document.cookie = ""; 
			} else { 
				result = true; 
			} 
		} 
		return result;
	},

	
	
	
	
	setStyle:
	function (elem,cssText){
		if(RAP.msie){
			elem.style.setAttribute("cssText",cssText);
		} else {
			elem.setAttribute("style",cssText);
		}
	},
	
	setClass:
	function(elem,className){
		if(RAP.msie){
			elem.className = className;
		} else {
			elem.setAttribute("class",className);
		}
	},
	
	getUniqueNodeValue:
	function (xml,tagName){
		return xml.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
	},
	
	reflectObject:
	function (obj,filter){
		var s=null;
		if(obj){
			s="";
			for(prop in obj){
				if((filter!=undefined) && (filter!='')){
					if (filter.indexOf(prop)!=-1){
						s += prop + ":" + obj[prop] + "\n";
					}
				} else {
					try{
						s += prop + ":" + obj[prop] + "\n";
					} catch (e){
					}
				}
			}
		}
		return s;
	}
	
}

