var sp = '[\\w/\\#~:.?+=%@!\\-;,]|(&(?!nbsp;))';
var sp2 = '\\w/\\#~:.?+=%@!\\-;,&';
var atext = '[a-zA-Z0-9]';
var letter = '[a-zA-Z]';
var letDig = '[a-zA-z0-9]';
var letDigHyp = '[a-zA-Z0-9-]';
var localPart = atext + '+([a-zA-Z0-9-_.]+)*';
var rfcLabel = letter + letDigHyp + '*' + letter;
var rfcLabel2 = letDig + letDigHyp + '*';
var domain = rfcLabel2 + '(\\.' + rfcLabel2 + ')*';
var emailUrl = localPart + '@' + domain;
var protocol = '((http|https):\/\/(www.)?|www.)';
var port = '(:\d+)?';
var wwwUrl = '(' + protocol + domain + port + '(' + sp + '*)*)(?=[,.:?\-]*(?:[^' + sp2 + ']|$))';
function Is()
{
	// initializing objects
	//jce102903 - created t varable to save on download time
	var t = true;
	var agt = navigator.userAgent.toLowerCase();
	
	//jce102903 - backwards compatible
	this.major = parseInt(navigator.appVersion);
	this.webTV = this.opera = this.nav = this.ie = this.safari = false;

	//Browser and version detection
	//Do least common browsers first because many browsers report "msie"
	//as a compatible engine
	var vInd = 0;
	if (agt.indexOf("webtv") != -1)
	{
		this.webTV = t;
		vInd = agt.indexOf("webtv/") + 6;
	}
	else if (agt.indexOf("safari") != -1)		//jad011304
	{
		this.safari = t;
		vInd = agt.lastIndexOf("safari") + 7;
	}
	else if (agt.indexOf("opera") != -1)
	{
		this.opera = t;
		vInd = agt.lastIndexOf("opera") + 6;
	}
	else if (navigator.appName == "Netscape")
	{
		this.nav = t;
		vInd = agt.lastIndexOf("/") + 1;
	}
	else if (agt.indexOf("msie") != -1)
	{
		this.ie = t;
		vInd = agt.indexOf("msie") + 4;
		if (agt.indexOf("america online") != -1)
		{
			this.aol = t;
		}
	}
	this.ver = parseInt(agt.substring(vInd));

	//Operating system detection
	this.win = (agt.indexOf("win") != -1);
	//jad081604 - Add XP detection
	this.winXP = (this.win && (agt.indexOf("windows nt 5.1;") != -1));
	this.mac = (agt.indexOf("mac") != -1);
	this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) || 
                           (agt.indexOf("powerpc")!=-1)));
	this.xpSp2 = (agt.indexOf("sv1") != -1);
	this.standard = document.mode == 'CSS1Compat';

	if ( this.safari || this.opera ) {
		this.getViewportHeight = function() {
			return self.innerHeight; // Safari, Opera
		}
	} else {
		this.getViewportHeight = function() {
			return (this.standard) ?
                        document.documentElement.clientHeight : // Standards
                        document.body.clientHeight; // Quirks
		}
	}

	if ( this.safari ) {
		this.getViewportWidth = function() {
			return  self.innerWidth;  // Safari
		}
	} else {
		this.getViewportWidth = function() {
			return (this.standard) ?
				document.documentElement.clientWidth : // Standards
                document.body.clientWidth; // Quirks
        }
	}

	this.getDocumentHeight = function() {
		var scrollHeight = (this.standard) ? document.documentElement.scrollHeight : document.body.scrollHeight;
		var h = Math.max(scrollHeight, this.getViewportHeight());
        return h;
    }
    this.getDocumentWidth = function() {
		var scrollWidth = (this.standard) ? document.documentElement.scrollWidth : document.body.scrollWidth;
        var w = Math.max(scrollWidth, this.getViewportWidth());
        return w;
    }
    
	this.getXY = function(elm) {
		return [elm.offsetLeft,elm.offsetTop];
	}

	this.getPageXY = function(elm,topId) {
		var pos = this.getXY(elm);
		var mOffsetParent = elm.offsetParent;
	
		while(mOffsetParent != null && mOffsetParent.id != topId) {
			pos[0] += mOffsetParent.offsetLeft;
			pos[1] += mOffsetParent.offsetTop;
			mOffsetParent = mOffsetParent.offsetParent;
		}
		return pos;
	}

    this.getScrollPos = function() {
    	var dd = document.documentElement, db = document.body;
        if (dd && (dd.scrollTop || dd.scrollLeft)) {
        	return [dd.scrollLeft, dd.scrollTop];
        } else if (db) {
            return [db.scrollLeft, db.scrollTop];
        } else {
           	return [0, 0];
        }
    }
    
    this.getMousePos = function(ev) {
 		var e = ev || window.event;
		if (e.pageX || e.pageY) { 
			return [e.pageX,e.pageY];
		} else if (e.clientX || e.clientY) { 
			var pos = this.getScrollPos();
			return [e.clientX + pos[0],e.clientY + pos[1]];
		} else {
			return [0,0];
		}
    }

    this.decendantOf = function (node,parent) {
		if (parent.contains && !this.safari) { // safari "contains" is broken
			return parent.contains(node);
        } else if ( parent.compareDocumentPosition ) {
			// DOCUMENT_POSITION_CONTAINED_BY = 16
			return !!(parent.compareDocumentPosition(node) & 16);
        } else { // loop up and test each parent
            var node = node.parentNode;
			while (node) {
				if (node == parent) {
					return true;
                } else if (!node.tagName || node.tagName.toUpperCase() == 'HTML') {
					return false;
				}
				node = node.parentNode;
            }
            return false;
		}
    }

 	this.getElementsBy = function(method, tag, root) {
        tag = tag || '*';
        root = root || document;
		var nodes = [];
        var elements = root.getElementsByTagName(tag);
		if ( !elements.length && (tag == '*' && root.all) ) {
        	elements = root.all; // IE < 6
        }
		for (var i = 0, len = elements.length; i < len; ++i) {
        	if ( method(elements[i]) ) { nodes[nodes.length] = elements[i]; }
        }
		return nodes;
	}

    this.getElementsByClassName = function(className, tag, root) {
    	var method = function(el) { return client.hasClass(el, className); };
        return this.getElementsBy(method, tag, root);
    }


    this.hasClass = function(el, className) {
 		var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
		return re.test(el['className']);
	}
 
    this.addClass = function(el, className) {
		var f = function(el) {
    		if (this.hasClass(el, className)) { return; } // already present
			el['className'] = [el['className'], className].join(' ');
		}
		this.applyMethod(el,f,this);
	}
  
    this.removeClass = function(el, className) {
 		var re1 = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
    	var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', 'g');
		var f = function(el) {
			while( re1.test(el['className']) ) {
        		var c = el['className'];
        		el['className'] = c.replace(re, ' ');
			}
		}
		this.applyMethod(el,f,this);
	}
	
    this.replaceClass = function(el, className,newClass) {
 		var re1 = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
    	var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', 'g');
		var f = function(el) {
			while( re1.test(el['className']) ) {
        		var c = el['className'];
        		el['className'] = c.replace(re, newClass);
			}
		}
		this.applyMethod(el,f,this);
	}

	this.isCollection = function(el) {
		return (el != null && el.length && !el.tagName);
	}

    this.applyMethod = function(el, method,scope) {
		if ( this.isCollection(el) ) {
			var collection = [];
			for (var i = 0, len = el.length; i < len; ++i) {
				collection[collection.length] = method.call(scope,el[i]);
        	}
			return collection;
		} else {
			return method.call(scope,el);
		}
	} 

    this.stopPropagation = function(ev) {
    	if (ev.stopPropagation) {
      		ev.stopPropagation();
        } else {
            ev.cancelBubble = true;
        }
    }
    
    this.preventDefault = function(ev) {
    	if (ev.preventDefault) {
        	ev.preventDefault();
        } else {
            ev.returnValue = false;
        }
    }

    this.stopEvent = function(ev) {
    	this.stopPropagation(ev);
        this.preventDefault(ev);
    }

    if (window.addEventListener) {
    	this.addSimpleEventListener = function(el, sType, fn, capture) {
        	el.addEventListener(sType, fn, (capture));
        }
    } else if (window.attachEvent) {
        this.addSimpleEventListener = function(el, sType, fn, capture) {
            el.attachEvent("on" + sType, fn);
        }
    } else {
        this.addSimpleEventListener = function(){};
    }
       
    if (window.removeEventListener) {
    	this.removeSimpleEventListener = function (el, sType, fn, capture) {
        	el.removeEventListener(sType, fn, (capture));
        }
    } else if (window.detachEvent) {
        this.removeSimpleEventListener = function (el, sType, fn) {
        	el.detachEvent("on" + sType, fn);
        }
    } else {
        this.removeSimpleEventListener = function(){};
    }

    this.getTarget = function(ev, resolveTextNode) {
    	var node = ev.target || ev.srcElement;
        if (node && 3 == node.nodeType) {
        	return node.parentNode;
		} else {
			return node;
		}
    }

	this.initAjax = function() {
		var http_request = null;
		if (window.XMLHttpRequest) { // Mozilla, Safari,... 
			return new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { // IE 
			try {
				return new ActiveXObject("Msxml2.XMLHTTP"); 
			} catch (e) { 
				try { 
					return new ActiveXObject("Microsoft.XMLHTTP"); 
 				} catch (e) {} 				
			} 
		} 
		return null;
	}
	
	this.isSupportAjax = function() {
 		return this.initAjax() != null;
	}

	this.makeAjaxCall = function(url, callback_function, return_xml) { 
		var http_request = this.initAjax();
		if ( http_request == null ) 
			return;
	
		if ( callback_function ) {
   			http_request.onreadystatechange = function() { 
				if (http_request.readyState == 4) { 
           			if (http_request.status == 200) { 
               			if (return_xml) { 
                   			eval(callback_function + '(http_request.responseXML)'); 
               			} else { 
                   			eval(callback_function + '(http_request.responseText)'); 
               			} 
           			} else { 
               			//alert('There was a problem with the request.(Code: ' + http_request.status + ')'); 
           			} 
       			} 
   			}
   		} 
		http_request.open('GET', url, true); 
		http_request.send(null); 
	}	 
         	  
}

var client = new Is();

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  	return height;
}


function GetViewportRight() {
	if ( client.ie ) {
    	if ( document.compatMode && document.compatMode!="BackCompat") {
			var viewport = document.documentElement;
			return viewport.scrollLeft + viewport.clientWidth-15;
    	} else {
			var viewport = document.body;
			return viewport.scrollLeft + viewport.clientWidth-15;
		}
	} else {
		return window.pageXOffset+window.innerWidth-15;
	}
}

function GetViewportBottom() {
	if ( client.ie ) {
    	if ( document.compatMode && document.compatMode!="BackCompat") {
			var viewport = document.documentElement;
			return viewport.scrollTop + viewport.clientHeight-15;
    	} else {
			var viewport = document.body;
			return viewport.scrollTop + viewport.clientHeight-15;
    	}
	} else {
		return window.pageYOffset+window.innerHeight-15;
	}
}
function GetViewportLeft() {
	if ( client.ie ) {
    	if ( document.compatMode && document.compatMode!="BackCompat") {
			var viewport = document.documentElement;
			return viewport.scrollLeft;
    	} else {
			var viewport = document.body;
			return viewport.scrollLeft;
		}
	} else {
		return window.pageXOffset;
	}
}

function GetViewportTop() {
	if ( client.ie ) {
    	if ( document.compatMode && document.compatMode!="BackCompat") {
			var viewport = document.documentElement;
			return viewport.scrollTop;
    	} else {
			var viewport = document.body;
			return viewport.scrollTop;
    	}
	} else {
		return window.pageYOffset;
	}
}
function $(id)
{
	return document.getElementById(id);
}

function getElementContent(id) {
	var element; 
	if ( typeof(id) == "string" )
		element = $(id);
	else
		element = id;	
	return element == null ? "" : element.innerHTML;
}

function setElementContent(id,value) {
	var element; 
	if ( typeof(id) == "string" )
		element = $(id);
	else
		element = id;	
	if ( element != null ) element.innerHTML = value;
}

function setLastVisitedAreaInCookie(areaId)
{
   var today = new Date();
   var expiry = new Date(today.getTime() + 90 * 24 * 60 * 60 * 1000); // plus 90 days
   var urlDomain = document.domain;
   var indexOfFirstDot = urlDomain.indexOf('.');
   var cookieDomain = urlDomain.substring(indexOfFirstDot, urlDomain.length);
   var cookieName = "site_preference";
   var cookiePath = "/";
   var cookieDecoderChar = "V"; //void/no encoding
   var value = "default_area="+escape(areaId);//forming cookielets
   value = cookieDecoderChar + value;
   
   setCookie(cookieName, value, expiry, cookiePath, cookieDomain,null);
 }
 
function setCookie(name, value, expires, path, domain, secure)
{
    var temp = name + "=" + value + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == null) ? "" : ("; secure=" + secure)) ;
    document.cookie = temp;
}

function Popup() {
	document.write("<iframe id='popupIframe' src='javascript:false;' frameborder='0' scrolling='no'></iframe>");
	document.write("<div id='modalBackground'></div>");

	this.div = null;
	this.refObj = null;
	this.modal = false;
	this.modalBackground = $('modalBackground');
	this.menu = false;
	this.timer = null;
	this.displayed = false;
	this.isTooltip = false;
	this.eventListener = [];
	this.timerDelay=100;  //menu disappear speed onMouseout (in miliseconds)
	this.needsSelectHack =  ( client.ie && client.ver < 7 );
	if ( client.ie ) {
		this.modalBackground.style.position = "absolute";
		this.iframe = $('popupIframe');
	}
	this.selects = [];
    var divs = client.getElementsByClassName("popupWindow", "div");
	for (var i = 0; i < divs.length; i++){
		var div = divs[i];
		div.onmouseover= function() {_popup.mouseOver();};
		div.onmouseout= function() {_popup.mouseOut();};
	}
    var as = client.getElementsByClassName("popupMenu", "*");
	for (var i = 0; i < as.length; i++){
		var clsNames = as[i].className;
		clsNames = clsNames.split(" ");
		var contentName = null;
		for(var j = 0; j < clsNames.length; j++ ) {
			if ( clsNames[j].indexOf('content-') == 0 )
				contentName = clsNames[j].substring(8);
		}
		if ( contentName == null )
			contentName = as[i].id + 'Menu';
		as[i].onclick= function(event) { return _popup.showMenu($(contentName),this, event)};
	}
	
    as = client.getElementsByClassName("tooltip", "*");
	for (var i = 0; i < as.length; i++){
		var clsNames = as[i].className;
		clsNames = clsNames.split(" ");
		var contentName = null;
		for(var j = 0; j < clsNames.length; j++ ) {
			if ( clsNames[j].indexOf('content-') == 0 )
				contentName = clsNames[j].substring(8);
		}
		if ( contentName != null ) {
			as[i].onmouseover= function(event) { return _popup.startTooltip($(contentName),this, event)};
			as[i].onmouseout= function(event) { _popup.hide();};
		}
	}
}
Popup.prototype.showMenu = function(div,refObj,e) {
        if ( this.displayed )
		this.hide();
	client.stopEvent(e || window.event);
	div.style.display = 'block';
	var w = div.offsetWidth;
	var h = div.offsetHeight;
	div.style.display = 'none';
	this.timer = null;
	var pos = client.getPageXY(refObj);
	var x= pos[0] + refObj.offsetWidth;
	var y = pos[1] + refObj.offsetHeight;
	var right = GetViewportRight();
    if (x > right)
		x = right;
	x -= w;
	var left = GetViewportLeft();
	if ( x < left )
		x = left;
	var bottom = GetViewportBottom();
    if (y > (bottom- h))
		y = (bottom - h);
	if ( y < 0 )
		y = 0;
	this._show(div,false,w,h,true);
	if ( this.needsSelectHack ) {
		this.iframe.style.top = y;
		this.iframe.style.left = x;
	}
	div.style.top = y;
	div.style.left = x;
	this.refObj = refObj;
	refObj.onmouseover= function() {_popup.mouseOver();};
	refObj.onmouseout= function() {_popup.mouseOut();};
	return false;
}
Popup.prototype.showMenu2 = function(div,refObj,e) {
    //Show menu code for onMouseOver dorpdown Menus. Changed the horizontal positioning and removed 'onmouseover' event over writing.
	if ( this.displayed )
		this.hide();
	client.stopEvent(e || window.event);
	div.style.display = 'block';
	var w = div.offsetWidth;
	var h = div.offsetHeight;
	div.style.display = 'none';
	this.timer = null;
	var pos = client.getPageXY(refObj);
	x= pos[0];
	var y = pos[1] + refObj.offsetHeight;
	var right = GetViewportRight();
	if (x > right)
		x = right;
	var left = GetViewportLeft();
	if ( x < left )
		x = left;
	var bottom = GetViewportBottom();
    if (y > (bottom- h))
		y = (bottom - h);
	if ( y < 0 )
		y = 0;
	
	this._show(div,false,w,h,true);
	if ( this.needsSelectHack ) {
		this.iframe.style.top = y;
		this.iframe.style.left = x;
	}
	div.style.top = y;
	div.style.left = x;
	refObj.onmouseout= function() {_popup.mouseOut();};
	return false;
}

Popup.prototype.startTooltip = function (div,refObj,e) {
	if ( !this.displayed || this.isTooltip ) {
		if ( this.isTooltip ) {
			if ( refObj != this.refObj ) {
				// clear old tooltip
				this.endTooltip();
			}
		} else {
			this.div = div;
    		this.timer=setTimeout("_popup.showTooltip()",200);
    	}
		this.refObj = refObj;
		this.isTooltip = true;
		this.mousePos = client.getMousePos(e);
    }
}
Popup.prototype.showTooltip = function() {
	if ( this.displayed )
		this.hide();
	this.timer = null;
	var pos = this.mousePos;
	var x= pos[0];
	var y = pos[1] + 10;
	var right = GetViewportRight();
	var left = GetViewportLeft();
	var bottom = GetViewportBottom();
	this.div.style.display = 'block';
	var w = this.div.offsetWidth;
	var h = this.div.offsetHeight;
    if (x > (right - w) )
		x = right - w;
	if ( x < left )
		x = left;
    if (y > (bottom- h))
		y = (bottom - h);
	if ( y < 0 )
		y = 0;
	this.div.style.top = y;
	this.div.style.left = x;
	this.div.style.display = 'none';
	this._show(this.div,false,w,h,true);
	if ( this.needsSelectHack ) {
		this.iframe.style.top = y;
		this.iframe.style.left = x;
	}
	this.div.style.top = y;
	this.div.style.left = x;
	return false;
}
Popup.prototype.endTooltip = function () {
	if ( this.isTooltip ) {
		this.hide();
	}
}

Popup.prototype.show = function(div,modal,w,h) {
	if ( this.displayed )
		this.hide();
	this._show(div,modal,w,h,false);
}

Popup.prototype.addListener = function(n,f,s,p){
	this.eventListener[this.eventListener.length] = {name:n,method:f,scope:s,parameter:p};
}

Popup.prototype.dispatchEvent = function(e,elm) {
	if ( e == "close" ) {
		this.hide();
	} else {
		for( var i = 0; i < this.eventListener.length; i++ ) {
			var listener = this.eventListener[i];
			if ( e == listener.name ) {
				listener.method.call(listener.scope,listener.parameter,elm);	
			}
		}
	}
}

Popup.prototype._show = function(div,modal,w,h,isMenu) {
	this.displayed = true;
	this.div = div;
	this.modal = modal;
	this.menu = isMenu;
	if ( !isMenu ) {
		if ( w )
			div.style.width = w;
		//div.style.height = h;
		if ( client.ie ) 
			div.style.position = "absolute";
	}
	div.style.display = 'block';

	// special IE-only processing for windowed elements, like select	
	if ( this.needsSelectHack ){
		this.iframe.style.display = 'block';
		this.iframe.style.width = this.div.offsetWidth;
		this.iframe.style.height = this.div.offsetHeight;
		if ( modal) {
			this.modalBackground.style.left = 0;
			this.modalBackground.style.top = 0;
			
			var selects = document.getElementsByTagName('select');
			this.selects = [];
			for (var i = 0; i < selects.length; i++){
				var select = selects[i];
				if (select.clientWidth == 0 || select.clientHeight == 0  ||  client.decendantOf(select,this.div) ||
					select.disabled ) {
					continue;
				}
				this.selects[this.selects.length] = select;
				select.disabled = true;
			}
			client.addClass(this.selects,"modalDisable");
		}
	}
	
	
	if ( modal ) {
		this.modalBackground.style.display = 'block';
		// call once to center everything
		this.resize();
	
		client.addSimpleEventListener(window, "resize", OnWindowResize, false);
		if (client.ie)
			client.addSimpleEventListener(window, "scroll", OnWindowResize, false);
	}
};

Popup.prototype.hide = function () {
	this.displayed = false;
	this.eventListener = [];
	if ( this.refObj != null ) {
		if ( !this.isTooltip ) {
			this.refObj.onmouseover= "";
			this.refObj.onmouseout= "";
		}
		this.refObj = null;
	}
 	this.isTooltip = false;
	if ( this.timer != null)	{
    	clearTimeout(this.timer);
		this.timer = null;
	}
	if ( this.div )
		this.div.style.display  = "none";
	if ( this.needsSelectHack ){
		this.iframe.style.display  = "none";
	}
	
	if ( this.modal ) {
		this.modalBackground.style.display = "none";
	
		// special IE-only processing for windowed elements, like select	
		if ( this.needsSelectHack ) {
			for (var i = 0; i < this.selects.length; i++){
				this.selects[i].disabled = false;
			}
			client.removeClass(this.selects,"modalDisable");
			this.selects = [];
		}
	
		client.removeSimpleEventListener(window,'resize', OnWindowResize, false);
		if (client.ie)
			client.removeSimpleEventListener(window, "scroll", OnWindowResize, false);
	}
};

Popup.prototype.resize = function () {
	// we only need to move the dialog based on scroll position if
	// we're using a browser that doesn't support position: fixed, like IE
	var pos = client.getScrollPos();
	var left = client.ie ? pos[0] : 0;
	var top = client.ie ? pos[1] : 0;
	
	if ( this.modal ) {
		this.modalBackground.style.width = client.getDocumentWidth();
		this.modalBackground.style.height = client.getDocumentHeight();
	}

	left = left + Math.max((client.getViewportWidth() - this.div.offsetWidth) / 2, 0) + "px";
    top = top + Math.max((client.getViewportHeight() - this.div.offsetHeight) / 2, 0) + "px";

	if ( this.needsSelectHack )	{	
		this.iframe.style.left = left;
    	this.iframe.style.top = top;
	}

	this.div.style.left = left;
	this.div.style.top = top;
	if ( this.needsSelectHack )	{	
		this.iframe.style.width = this.div.offsetWidth;
		this.iframe.style.height = this.div.offsetHeight;
	}
};

Popup.prototype.mouseOver = function() {
    if ( this.timer != null)	{
    	clearTimeout(this.timer);
		this.timer = null;
	}
}

Popup.prototype.mouseOut = function () {
    if (this.div)
    	this.timer=setTimeout("_popup.hide()",this.timerDelay);
}

function OnWindowResize()
{
	_popup.resize();

}

function openPopupWindow(url,name,style) {
	window.open(url,name,style);
}

var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
function GetDaysCountForMonth(SomeYear, SomeMonth) {
   return ((SomeMonth == 1) && ((SomeYear % 400 == 0) || ((SomeYear % 4 == 0) && (SomeYear % 100 != 0)))) ? 29 : MonthDays[SomeMonth];
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
/*
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
    //return this.replace(/\s+$/,"");
    return this;
}
*/

function readCookie(name) {
	var toRet = null
	if(!name) return null;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0){
			toRet =  c.substring(nameEQ.length,c.length);
			if(toRet.length >= 1) toRet =  toRet.substring(1,toRet.length); //remove version info
		}			
	}
	return toRet;
}

function readCookielet(cookieName, cookieletName){
var toRet = null;
if(!(cookieName && cookieletName)) return;
var cookieValue = readCookie(cookieName);
if(cookieValue == null) return null;
var cookieletNameEQ = cookieletName + "=";
var ca = cookieValue.split('^');
for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	if (c.indexOf(cookieletNameEQ) == 0){
		 toRet = c.substring(cookieletNameEQ.length,c.length);
		 break;
	}				
}
return toRet;
}
		
		
function decodeBase64(rv){
	var len=rv.length,ret="",i=0;var chr1,chr2,chr3="";
	var enc1,enc2,enc3,enc4="";
	var aChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=*";
	var test=new RegExp("[^A-Za-z0-9+/=*]");
	if(test.exec(rv)){return;}
	do{
		enc1=aChar.indexOf(rv.charAt(i++));
		enc2=aChar.indexOf(rv.charAt(i++));
		enc3=aChar.indexOf(rv.charAt(i++));
		enc4=aChar.indexOf(rv.charAt(i++));
		chr1=(enc1<<2)|(enc2>>4);
		chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;ret+=String.fromCharCode(chr1);
		if(!(enc3>=64)) ret+=String.fromCharCode(chr2);
		if(!(enc4>=64)) ret+=String.fromCharCode(chr3);
		chr1=chr2=chr3=enc1=enc2=enc3=enc4="";}while(i<len);return ret;
	}


function decodeUTF8(s){
	var len=s.length;
	var rs="";
	var i=0;
	var c=c1=c2=0;
	while(i<len){
		c=s.charCodeAt(i);
		if(c<128){
			rs+=String.fromCharCode(c);
			i++;
		}
		else if((c>191)&&(c<224)){
			c2=s.charCodeAt(i+1);
			rs+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;
		}
		else{
			c2=s.charCodeAt(i+1);
			c3=s.charCodeAt(i+2);
			rs+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}
		}
	return rs;
}


function showHeaderWithGreetings(){
	var elementb = document.getElementById('withGreetings');
	var elementa = document.getElementById('withoutGreetings');
	var encodedUserGreeting = readCookielet('na', 'ug');
	if(encodedUserGreeting !=null)
	{
		withGreetings.innerHTML = 					withGreetings.innerHTML.replace('replacewithusergreetings',decodeUTF8(decodeBase64(encodedUserGreeting)));
		withoutGreetings.innerHTML = withGreetings.innerHTML;
	}

}

function DoNav(xRowId){
	var row = document.getElementById(xRowId);
	row.className='highlight';
	row.onmouseout = new Function("this.className=''");
/*	var link = row.getElementsByTagName("a");
	if(link[0].onclick){
		row.onclick = eval(link[0].onclick);
	}
	else{
		row.onclick = new Function("document.location.href='" + link[0].href + "'");
	}*/
}

function SortResults(frm){
  	var list = frm.sortBy;
  	var sortOption = list.options[list.selectedIndex].value;
	document.location = sortOption;
}

if(typeof cachableUrl != 'undefined' && cachableUrl){
	showHeaderWithGreetings();
}

function show(w,h) {
	var popupTable = $("mainSec");
	var tableContent = $("reloadMain");
	popupTable.innerHTML = tableContent.innerHTML;
	_popup.show($('subform'),true,w,h);
}
function showHide(show){               
        var currentCountryDiv = document.getElementById("currentCountryDiv");
        var otherCountriesDiv = document.getElementById("otherCountriesDiv");

        if(show == "currentCountry"){
           currentCountryDiv.style.display = "block";

           otherCountriesDiv.style.display = "none";
        }

        else{
            currentCountryDiv.style.display = "none";

            otherCountriesDiv.style.display = "block";
        }
	_popup.resize();
}

function imageLayer(index, count){
		SetImagesToDefault(count);
		
		var largeImg = document.getElementById("largeImg"+index);
		largeImg.style.display= "block";
		var spanIndex = "span"+index;
		var imgIndex = "link"+index;
		var spanLay = document.getElementById(spanIndex);
		var imgLay = document.getElementById(imgIndex);
		imgLay.className = "aImgOn";
		spanLay.className = "spanImgOn";
		document.all.imageRow.style.display = "block";
		
		_popup.show($('supersizeRow'),true,825,600);
		
		return false;
	}
	
	function SetImagesToDefault(count){
		for(var i=0;i<=count;i++){
			var bigImg = document.getElementById("largeImg"+[i]);
			bigImg.style.display = "none";			
			var spanImg = document.getElementById("span"+[i]);
			spanImg.className = "spanImgOff";
			var linkImg = document.getElementById("link"+[i]);
			linkImg.className = "aImgOff";
		}
	}
	
	function SwapImage(index, count){
		if(count == 0){
			return false;
		}
		
		SetAllImagesBordersOff(count);
		SetOneImageBorderOn(index, count);
		UnSetOtherImagesBorderOff(index, count);
		
		var divId = "largeImg"+index;
		var imgDivId = document.getElementById(divId);
		imgDivId.style.display = "block";
	}
	function SetAllImagesBordersOff(count){
		for(var i=0;i<=count;i++){
			var span = document.getElementById("span"+[i]);
			span.className = "spanImgOff";
			var linkImg = document.getElementById("link"+[i]);
			linkImg.className = "aImgOff";
		}
	}
	function SetOneImageBorderOn(index, count){
		var spanDiv = document.getElementById("span"+index);
		var linkDiv = document.getElementById("link"+index);
		spanDiv.className = "spanImgOn";
		linkDiv.className = "aImgOn";
	}
	function UnSetOtherImagesBorderOff(index, count){
		for(var i=0;i<=count;i++){
			if(index != [i]){
				var imgIndex = document.getElementById("largeImg"+[i]);
				imgIndex.style.display = "none";
			}
		}
	}

