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

createCookie = function (name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

readCookie = function(name) {
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

eraseCookie = function(name) {
	createCookie(name,"",-1);
}

not_null_name = function (id) {
    t = document.getElementById(id);
    str = t.value
    if (str == null || str == "") {
        t.className = 'textbox_incomplete';
        return false;       
    } else {
        t.className = 'textbox';
        return true;
    }
}

numericmask = function(t) {
    var patt = /(-?\d*)\.{1}(\d{0,3})/;
    var donepatt = /^(-?\d*)\.{1}(\d{3})$/;
    var str = t.value;
    var result;
    
    if (!str.match(donepatt)) {
        result = str.match(patt);
    if (result!= null) {
        t.value = t.value.replace(/[^-?\d]/gi,'');
        str = result[1] + '.' + result[2] ;
        t.value = str;
        } else {
            if (t.value.match(/[^-?\d]/gi))
            t.value = t.value.replace(/[^-?\d]/gi,'');
        }
    }
}

not_null = function(id) {
    t = document.getElementById(id);
    str = t.value
    if (str == null || str == "") {
        //alert("hello");        
        t.focus();
        t.select();
        t.className = 'textbox_incomplete';
        return false;       
    } else {
        t.className = 'textbox';
        return true;
    }
}

currencymask = function(t) {
    var patt = /(\d*)\.{1}(\d{0,2})/;
    var donepatt = /^(\d*)\.{1}(\d{2})$/;
    var str = t.value;
    var result;
    
    if (!str.match(donepatt)) {
        result = str.match(patt);
    if (result!= null) {
        t.value = t.value.replace(/[^\d]/gi,'');
        str = result[1] + '.' + result[2] ;
        t.value = str;
        } else {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
        }
    }
}

datemask = function(t) {
    var donepatt = /^(\d{2})\/(\d{2})\/(\d{4})$/;
    var patt = /(\d{2}).*(\d{2}).*(\d{4})/;
    var str = t.value;
    if (!str.match(donepatt)) {
    result = str.match(patt);
        if (result!= null) {
            t.value = t.value.replace(/[^\d]/gi,'');
            str = result[1] + '/' + result[2] + '/' + result[3];
            t.value = str;
        } else {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
        }
    }
}

phonemask = function(t) {
    var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
    var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
    var str = t.value;
    var result;
    
    if (!str.match(patt2)) {
        result = str.match(patt1);
        if (result!= null) {
            t.value = t.value.replace(/[^\d]/gi,'');
            str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
            t.value = str;
        } else {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
        }
    }
}

ssnmask = function(t) {
    var patt = /(\d{3}).*(\d{2}).*(\d{4})/;
    var donepatt = /^(\d{3})-(\d{2})-(\d{4})$/;
    var str = t.value;
    var result;
    if (!str.match(donepatt)) {
        result = str.match(patt);
        if (result!= null) {
            t.value = t.value.replace(/[^\d]/gi,'');
            str = result[1] + '-' + result[2] + '-' + result[3];
            t.value = str;
        } else {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
            }
    }
}

addListener = function(element, event, listener) {
	try {
		if (element.addEventListener) {
			element.addEventListener(event,listener,false);
		} else if (element.attachEvent) {
			element.attachEvent('on'+event, function(){listener.call(element)});
		}
	} catch(ex) {
		log(ex);
	}	
}

removeListener = function(element, event, listener) {
	if (element.removeEventListener) {
		element.removeEventListener(event,listener,false);
	} else if (element.detachEventEvent) {
		element.detachEventEvent('on'+event, function(){listener.call(element)});
	}
}

noenter = function() {
  return !(window.event && window.event.keyCode == 13); 
}

disableContextMenu = function() {
	document.oncontextmenu = function(){return false;};
}

enableContextMenu = function() {
	document.oncontextmenu = function(){return true;};
}

objectSize = function(object) {
	size = 0;
	for (i in object) {
		size++;
	}
	return size;
}

lastElement = function(object) {
	element = false;
	for (i in object) {
		//fast forward to the last one
	}	
	return object[i];
}

disableSelections =  function(node) {
	if (node) {
		// CSS3 draft way
		if (typeof node.style.userSelect == "string")
			node.style.userSelect = "none";
		
		// mozilla extension
		if (typeof node.style.MozUserSelect == "string")
			node.style.MozUserSelect = "none";
			
		// msie/safari extension
		if(typeof node.onselectstart != "undefined")
			node.onselectstart = function() {return false;};
			
		node.style.cursor = "default";
	}
	return true;
}

progressVeil = function(state,element) {
	
		var veilDiv = document.getElementById(element.getAttribute('id') + "_progress_veil");
		
		if(state == "start" && !veilDiv) {
			//create the 2 divs to be used
			veilDiv = document.createElement("DIV");
			progressDiv = document.createElement("DIV");
			
			veilDiv.id = element.id+"_progress_veil";
			
			//veilDiv.style.background = 'url(_css/images/veil_background.gif)';
			veilDiv.className = "veil";
			veilDiv.style.top = findPos(element).y+"px";
			veilDiv.style.left = findPos(element).x+"px";
			veilDiv.style.width = element.style.width;
			if (element.style.height) {
				veilDiv.style.height = element.style.height;
			} else {
				veilDiv.style.height = parseInt(element.offsetHeight);
			}
			
			veilDiv.style.zIndex = "100";
			veilDiv.style.position = 'absolute';
						
			(element.parentNode).appendChild(veilDiv);
						
			progressDiv.className = "progress";
			progressDiv.style.visibility = "hidden";
			
			veilDiv.appendChild(progressDiv);
			
			progressDiv.style.marginTop = (((parseInt(veilDiv.style.height))/2) - 10) + "px";
			progressDiv.style.marginLeft = (((parseInt(veilDiv.style.width))/2) - 10) + "px";
			progressDiv.style.zIndex = "100";
			//progressDiv.innerHTML = "loading...";
			progressDiv.style.position = 'relative';
			
			setTimeout(function(){progressDiv.style.visibility = "visible"},20);
			
			//add a "watchdog" to keep veilDiv the same size as it's parent.
			veilDiv.interval = setInterval(function(){veilDiv.style.top = findPos(element).y  + "px";
										veilDiv.style.width = element.style.width;
										if (element.style.height) {
											veilDiv.style.height = element.style.height;
										} else {
											veilDiv.style.height = parseInt(element.offsetHeight) + "px";
										}
										progressDiv.style.marginTop = (((parseInt(veilDiv.style.height))/2) - 20) + "px";
										progressDiv.style.marginLeft = (((parseInt(veilDiv.style.width))/2) - 10) + "px";}
										,20);
			
			return true;
	
		} else if (state == "finish"  && veilDiv) {
			clearInterval(veilDiv.interval);
			/*if (element.parentNode) {
				log("hello");				
				//kill the watchdog
				(element.parentNode).removeChild(veilDiv);
			} else {*/
			(veilDiv.parentNode).removeChild(veilDiv);
			//}
			return true;
		} 
		
}

getElementsByClassName = function(oElm, strTagName, oClassNames) {
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

getParentByTag =  function(element, tagName) {
	var parent = null;
	parent = element.parentNode;
	if (parent) {
		//log(parent.tagName.toUpperCase() + " : " + tagName.toUpperCase() + "\n");
		if (parent.tagName.toUpperCase() != tagName.toUpperCase()) {
			return getParentByTag(parent, tagName);
		} 
	}	
	return parent;
}

getChildById = function(element,tagName,id) {
	children = element.getElementsByTagName(tagName);
	for (var i=0; i<children.length; i++){
     		var child = children[i];
     		if(child && child.nodeType != 1) continue;
     		if (child.id == id) {
     			break;
     		}
     	}
     return child;
}

getPreviousSibling = function(element) {
	do {
		element = element.previousSibling;
	} while (element && element.nodeType != 1);			
	return element;
}

//parse contents of a HTML table into a rowsArray
parseHTMLTable = function(tblID) {
	var ELEMENT_NODE = 1;
	var rowsArray = new Object();
    var tbody = document.getElementById(tblID);
     
     if (tbody) {
     	for (var i=0; i<tbody.childNodes.length; i++){
     		var row = tbody.childNodes[i];
     		if (row.nodeType != ELEMENT_NODE) continue;
			row_id = row.id;
			var rowArray = new Object();
			for (var j=0; j<row.childNodes.length; j++) {
				var cell = row.childNodes[j];
				if (cell.nodeType != ELEMENT_NODE) continue;
					cell_id = cell.id;
					rowArray[cell_id] = cell;									
			}
     		rowsArray[row_id] = rowArray;
     	}
     	    
     }   
    return rowsArray;
}

log = function(message) {
    if (!this.window_ || this.window_.closed) {
        var win = window.open("", null, "width=400,height=200," +
                              "scrollbars=yes,resizable=yes,status=no," +
                              "location=no,menubar=no,toolbar=no");
        if (!win) return;
        var doc = win.document;
        doc.write("<html><head><title>Debug Log</title></head>" +
                  "<body></body></html>");
        doc.close();
        window_ = win;
    }
    var logLine = window_.document.createElement("div");
    logLine.appendChild(window_.document.createTextNode(message));
    window_.document.body.appendChild(logLine);
}

removeAllChildren = function(element) {
	while (element.hasChildNodes())
	{
	  element.removeChild(element.firstChild);
	}
}

findPos =  function(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {	
			if(obj.style.position != 'relative') {		
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		} while (obj = obj.offsetParent);		
	}
	return {x:curleft,y:curtop};
}

addHoverBehavior = function(element,style,styleHover) {
	if (element) {
		addListener(element,"mouseover",function(){if(element.className){element.origClassName = element.className;} element.className = styleHover;});
		addListener(element,"mouseout",function(){if(element.origClassName){element.className = element.origClassName;} else {element.className = style;}});
	}
	return true;
}

var animatedResize = new Object;

animatedResize = function(divObj,time,height) {
	
	this.divObj = divObj;
	this.time = time;
	this.height = height;
	this.heightDiff = height - parseInt(divObj.style.height);
	
	//log("height idff = " + this.heightDiff);
	
	this.startTime = new Date().getTime();
	this.increment = Math.ceil(Math.abs(this.heightDiff/(this.time))); //number of pixels we will move at once
	this.increment = (this.increment<2?2:this.increment);	//set default to 2 px of the calculated increment is less than 2
	this.iterations = Math.ceil(Math.abs(this.heightDiff/this.increment)); //number of times the setTimeout will be called
	//log("iterations = " + this.iterations);
	this.delay = Math.round(this.time/this.iterations);  //number of milliseconds between each increment
	//log("delay = " + this.delay);
	this.stopSlide = false;
	this.animationId = new Object; //create an array that will hold refeneces to animation ids
	
	this.animate(this.divObj);
}

animatedResize.prototype = {
	
	slide: function(divObj) { //slide id the function that slides the element up of down by manipulatin syle.height
		if(!this.stopSlide) {
			elapsedTime = new Date().getTime() - this.startTime;
			if (this.heightDiff > 0) {
				divObj.style.height = (parseInt(divObj.style.height) + this.increment) + "px";
				//log(" timeout = " + timeout + " elapsed = " + elapsedTime + " sliding " + this.direction + " " + this.increment);
				if ((parseInt(divObj.style.height) >= parseInt(this.height)) || (elapsedTime >= this.time)) {
					//log("elapased = " + elapsedTime + " time = " + this.time + " timeout = " + timeout);
					this.stopSlide = true;
					//log("---- timeout ----");
					divObj.style.height = this.height + 'px';
					this.clearTimeouts(this.animationId);
					return true;
				} 
			} else {
				divObj.style.height = (parseInt(divObj.style.height) - this.increment) + "px";
				//log(" sliding " + this.direction + i);
				if ((parseInt(divObj.style.height) <= parseInt(this.height)) || (elapsedTime >= this.time)) {
					this.stopSlide = true;
					//log("---- timeout ----");
					divObj.style.height = this.height + 'px';
					this.clearTimeouts(this.animationId);
					return true;				
				}
			}
		}
	},
	
	clearTimeouts: function(animationId) {
		for (i in this.animationId) {
			clearTimeout(animationId[i]);
			delete animationId[i];
			//log(this.direction + " killing timer = " + this.animationId[i]);
		}
	},
	
	animate: function(divObj) {
		//var timeout = 0;
		for (var i=0; i<this.iterations; i++) {
			timeout = this.delay*i;
			
			var animation = this;			 
			this.animationId[i] = setTimeout(function(){animation.slide(divObj)},timeout);
			//log(this.direction + " animation id = " + this.animationId[i] + " timeout = " + timeout);		
		}	
		return true;
	}
	
}

function stopBubble(e) {
	if (!e) {
		e = window.event
		e.cancelBubble = true;
	} else {
		 e.stopPropagation();
	}
}

function disableDefault(e) {
	if(!e) {
		e = window.event
		e.returnValue = false;
	} else {
		e.preventDefault();	
	}	
}

function Calendar(elementId,event) {
	
	
	if (!event) {
		event = window.event;
		
	}
	
	if (!document.getElementById(elementId+"_calendar_selector")) {
	
		var element = document.getElementById(elementId);
		var elementValue = element.value;
		
		var calendarContainer = document.createElement('DIV');
		calendarContainer.className = 'calendar_container';
		calendarContainer.id = elementId+"_calendar_selector";
		
		var calendarHeader = document.createElement('DIV');
		calendarHeader.className = 'calendar_header';
		
		var weekHeaderDiv = document.createElement('DIV');
		weekHeaderDiv.className = 'week_row';
		
		var monthDiv = document.createElement('DIV');
		monthDiv.className = 'month_container';
		
		var prevMonth = document.createElement('DIV');
		prevMonth.className = 'prev_month';
		var nextMonth = document.createElement('DIV');
		nextMonth.className = 'next_month';
		var monthCaption = document.createElement('DIV');
		monthCaption.className = 'month_caption';
		var daysOfWeekArray = ['Su','Mo','Tu','We','Th','Fr','Sa'];
		var montsOfYearArray = ['January','February','March','April','May','June','July','August','September','October','November','December'];
		var monthDateArray = new Object;
		
		var buildHeader = function() {	
			updateHeader();		
			addListener(prevMonth,'mousedown',moveCalendarBack);
			addListener(nextMonth,'mousedown',moveCalendarFwd);
			addHoverBehavior(prevMonth,'prev_month','prev_month_hover');		
			addHoverBehavior(nextMonth,'next_month','next_month_hover');		
			calendarHeader.appendChild(prevMonth);
			calendarHeader.appendChild(monthCaption);
			calendarHeader.appendChild(nextMonth);		
			calendarContainer.appendChild(calendarHeader);	
		
		}
		
		 IsValidDate = function(date){
		    var DateVal = date.split("/");
		    var Mn = DateVal[0];
		    var Day = DateVal[1];
		    var Yr = DateVal[2];
		    var dt = new Date(date);
		
		    if(dt.getDate()!=Day){
		        return(false);
		        }
		    else if(dt.getMonth()!=Mn-1){
		    //this is for the purpose JavaScript starts the month from 0
		        return(false);
		        }
		    else if(dt.getFullYear()!=Yr){
		        return(false);
		        }		        
		    return(true);
		 }
		
		var moveCalendarBack = function(e) {
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
			buildMonthDateArray(date.setMonth(date.getMonth()-1));
			updateHeader();
			buildMonth();
		}
		
		var moveCalendarFwd = function(e) {
			if (!e) var e = window.event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
			buildMonthDateArray(date.setMonth(date.getMonth()+1));
			updateHeader();
			buildMonth();
		}
		
		var updateHeader = function() {
			var year = monthDateArray[0].year;
			var month = montsOfYearArray[monthDateArray[0].month];		
			monthCaption.innerHTML = month+", "+year;
		}
		
		
		var buildWeekDayHeader = function () {
					
			var weekNumberDiv = document.createElement('DIV');
			weekNumberDiv.style.backgroundColor = '#CCCCFF';
			weekNumberDiv.style.cursor = 'default';
			weekNumberDiv.innerHTML = '#';
			weekNumberDiv.className = 'date_cell';
			weekHeaderDiv.appendChild(weekNumberDiv);
			
			for(day in daysOfWeekArray) {
				var dayOfWeek = daysOfWeekArray[day];
				var dayDiv = document.createElement('DIV');
				dayDiv.style.backgroundColor = '#CCCCFF';
				dayDiv.style.fontWeight = 'bold';
				dayDiv.style.cursor = 'default';
				dayDiv.style.fontFamily = 'Arial';
				dayDiv.style.fontSize = '10';
				dayDiv.className = 'date_cell';
				dayDiv.innerHTML = dayOfWeek;
				weekHeaderDiv.appendChild(dayDiv);		
			}
			calendarContainer.appendChild(weekHeaderDiv);
		
		}
		
		var buildMonth = function() {
			
			//clear out the month div first
			removeAllChildren(monthDiv);
			
			
			var weeks = Math.ceil(objectSize(monthDateArray)/7);
			/*log(" length = " + objectSize(monthDateArray));
			for(i in monthDateArray) {
				log("day: " + monthDateArray[i].day + " month: " + monthDateArray[i].month + " date: " + monthDateArray[i].date + " year: "+ monthDateArray[i].year);
			}*/
			
			var i = 0;
		
			for(var week=1; week<=weeks+1; week++) {
				var weekDiv = document.createElement('DIV');
				weekDiv.className = 'week_row';
				var weekNumberDiv = document.createElement('DIV');
				weekNumberDiv.className = 'date_cell';
				weekNumberDiv.style.backgroundColor = '#CCCCFF';
				weekNumberDiv.style.fontFamily = 'Arial';
				weekNumberDiv.style.fontSize = '10';
				weekNumberDiv.style.cursor = 'default';
				weekNumberDiv.innerHTML = week;
				weekDiv.appendChild(weekNumberDiv);
				for(var weekDay=0; weekDay<=6; weekDay++) {
					var dateDiv = document.createElement('DIV');
					dateDiv.style.fontFamily = 'Arial';
					dateDiv.style.fontSize = '10';
					dateDiv.className = 'date_cell';
					if (monthDateArray[i]) {
						var dateObject = monthDateArray[i];
						if (dateObject.day == weekDay) {
							dateDiv.innerHTML = dateObject.date;
							dateDiv.date=dateObject.month+1+"/"+dateObject.date+"/"+dateObject.year;
							addListener(dateDiv,'mousedown',function(){element.value = this.date;});
							if(date.getDate() == dateObject.date) {
								dateDiv.className = 'date_cell_selected';
							} else {
								addHoverBehavior(dateDiv,'date_cell','date_cell_hover');
							}															
							i++;
						} else {
							dateDiv.innerHTML = '';
							dateDiv.style.backgroundColor = 'silver';
							dateDiv.style.cursor = 'default';
						}
					} else {
						dateDiv.innerHTML = '';
						dateDiv.style.backgroundColor = 'silver';
						dateDiv.style.cursor = 'default'
					}					
					weekDiv.appendChild(dateDiv);
				}
				monthDiv.appendChild(weekDiv);
				if (i >= objectSize(monthDateArray)) {
					break;
				}
			}
			calendarContainer.appendChild(monthDiv);
		}
		
		var buildMonthDateArray = function(date) {
			if (monthDateArray != null) {
				monthDateArray = new Object();
			}
			
			var d = new Date(date);		
			var month = d.getMonth();
			var i = 0;
			d.setDate(1);
			
			
			while (month == d.getMonth()) {
							
				var dateEntry = new Object();				
				dateEntry.date = d.getDate();
				dateEntry.month = d.getMonth();
				dateEntry.day = d.getDay();
				dateEntry.year = d.getFullYear();
				monthDateArray[i] = dateEntry;
				
				d.setDate(d.getDate()+1);
				i++;
			}
			
			return true;
		}
		
		var removeCalendar = function() {
			if(document.getElementById(elementId+"_calendar_selector")) {
				document.body.removeChild(document.getElementById(elementId+"_calendar_selector"));
				removeListener(document.body,'mousedown',removeCalendar);	
			}		
		}
		
		//make sure the date entered is a valid date, if not, default to today's date
		if (elementValue != '' && IsValidDate(elementValue)) {
			var date = new Date(elementValue);
		} else {
			var date = new Date();
			element.value = (date.getMonth()+1+"/"+date.getDate()+"/"+date.getFullYear());
		}
		
		buildMonthDateArray(date);
		buildHeader();
		buildWeekDayHeader();
		buildMonth();
			
		document.body.appendChild(calendarContainer);
		
		//element.parentNode.appendChild(calendarContainer);
		//element.parentNode.insertBefore(calendarContainer,element);
		
		/*alert("window scroll = " + window.scrollY + " parent scroll = " + 
								element.parentNode.scrollY + 
								" event Y = " + event.clientY);*/
		calendarContainer.style.left = findPos(element).x;
		calendarContainer.style.top = event.clientY + parseInt(document.body.scrollTop) -
										parseInt(calendarContainer.offsetHeight) - 
										parseInt(element.offsetHeight);  
		
		//alert(calendarContainer.parentNode);
		addListener(document.body,'mousedown',removeCalendar);
		addListener(document.body,'scroll',removeCalendar);
	}
}

function popUp(parentID,height,width,URL,extVars,closeCallback) {	
	
	var popupID = parentID + '_popup';
	var parentContainer = document.getElementById(parentID);
	var popUpContainer = null;
	var closeButton = null;
	var contentDiv = null;
	var headerDiv = null;
	var closeButtonCallback = null;
	
	if (!height) {
		var height = '100px';
	} else {
		var height = height + 'px';
	}
	if (!width) {
		var width = '160px';
	} else {
		var width = width + 'px';
	}
	
	if (URL && extVars) {
		//log(URL);
		for(i in extVars) {
			URL +='&'+i+'='+extVars[i];
		}
	}
	
	if (closeCallback && (typeof closeCallback == 'function')) {
		closeButtonCallback = closeCallback;
	} else {
		closeButtonCallback = function(){return true;}
	}
	
	var closePopup = function() {
		//log(parentContainer);
		parentContainer.removeChild(popUpContainer);
		//log(parentContainer);
	}
	
	var showPopup = function() {
		
		leftOffset = 0;
		topOffset = 0;
		
		//log('left offset = ' + leftOffset);
		//log('top offset = ' + topOffset);
		
		popUpContainer = document.createElement('DIV');
		popUpContainer.id = popupID;
		
		leftOffset = (parseInt(findPos(parentContainer).x)+(parseInt(parentContainer.offsetWidth)/2) - (parseInt(width) / 2));
		topOffset = (parseInt(findPos(parentContainer).y)+(parseInt(parentContainer.offsetHeight)/2) - (parseInt(height) / 2));
		
		
		//log('left offset = ' + leftOffset);
		//log('top offset = ' + topOffset);
	
		
		popUpContainer.style.visibility = 'hidden';
		
		popUpContainer.style.width = width;
		popUpContainer.style.height = height;
		popUpContainer.style.left = leftOffset + 'px';
		popUpContainer.style.top = topOffset + 'px';
		popUpContainer.className = 'popup_box';
		parentContainer.appendChild(popUpContainer);
		
		headerDiv = closeButton = document.createElement('DIV');
		headerDiv.className = "popup_header_div";
		
		closeButton = document.createElement('DIV');
		closeButton.className = "popup_close_button";
		headerDiv.appendChild(closeButton);
		popUpContainer.appendChild(headerDiv);
		addListener(closeButton,"click",function(){closePopup();closeButtonCallback();});
		
		contentDiv = document.createElement('DIV');
		contentDiv.id = popupID + "_content";
		contentDiv.className = 'content';	
		popUpContainer.appendChild(contentDiv);
		contentDiv.style.height = (parseInt(popUpContainer.offsetHeight) - parseInt(headerDiv.offsetHeight)) + 'px';
		contentDiv.style.width = width;	
				
		popUpContainer.style.visibility = 'visible';
		progressVeil('start',popUpContainer);
		
		new net.ContentLoader(URL,loadPopupContent);		
	
	}
	
	var loadPopupContent = function() {
		var htmlDoc = this.req.responseText;
		
		if (htmlDoc) {
			contentDiv.innerHTML = htmlDoc;
		}
		
		var scripts = contentDiv.getElementsByTagName('SCRIPT');
		if (scripts) {
			for (i in scripts) {
				var script = scripts[i];
				if(script.nodeType != 1) continue;
				eval(script.innerHTML);
			}
		}
		
			var containers = getElementsByClassName(contentDiv,'DIV','content');
			for (i in containers) {
				var container = containers[i];
				if (container) {
					container.style.height = (parseInt(contentDiv.offsetHeight)) + 'px';
				}
			}
		
		progressVeil('finish',popUpContainer);		
		return true;
	}
	
	
	if (!document.getElementById(popupID)) {
		showPopup();
	}

}
