if (typeof SilverTech == 'undefined') {
  // defines the global SilverTech namespace
  SilverTech = {};
}



SilverTech.PopupHtmlBox = function ( popId ) {
	this.popupBoxId = popId;
}

SilverTech.PopupHtmlBox.prototype.setHtml = function ( html ) {
	this.html = html;
}

SilverTech.PopupHtmlBox.prototype.DisplayAtElement = function ( elementId ) {
	this.Close();
	
	var sPop = document.createElement('div');
	sPop.setAttribute('id', this.popupBoxId );
	var s = sPop.style;
	s.position = "absolute";
	s.display = "block";
	s.padding = "5px";
	
	var p = getPos(document.getElementById(elementId));
	var x = p.x + 25;
	var y = p.y + 25;
	s.left = x + "px";
	s.top = y + "px";
	
	s.border = "1px solid #292929";
	s.backgroundColor = "#FFFFFE";
	sPop.innerHTML= this.html;
			
	document.body.appendChild(sPop);
}
	
SilverTech.PopupHtmlBox.prototype.Close = function () {
	var sPop = document.getElementById( this.popupBoxId );
	if( sPop )
		document.body.removeChild(sPop);
}

function ClosePopup( popId ) {
	var sPop = document.getElementById( popId );
	if( sPop )
		document.body.removeChild(sPop);
}


SilverTech.Forms = {};
// defines the Forms namespace

SilverTech.Forms.PopupBox = function (params) {

	function setParamDefault(param, pDefault) {
		 if (typeof params[param] == "undefined")
		 	params[param] = pDefault;
	};
	
	setParamDefault("popupBoxId", "popupBox");
	setParamDefault("dataFieldType", "selectBox");
	setParamDefault("dataFieldId", "dataField");
	
	this.popupBoxId = params.popupBoxId;
	this.dataFieldType = params.dataFieldType;
	this.dataFieldId = params.dataFieldId;
	this.jsName = params.jsName;
}

SilverTech.Forms.PopupBox.prototype.DisplayAtElement = function ( elementId ) {
		this.Close();
	
		var sPop = document.createElement('div');
		sPop.setAttribute('id', this.popupBoxId );
		var s = sPop.style;
		s.position = "absolute";
		s.display = "block";
	
		var p = getPos(document.getElementById(elementId));
		var x = p.x;
		var y = p.y;
		s.left = x + "px";
		s.top = y + "px";
	
		s.border = "2px solid #180E5A";
		s.backgroundColor = "#FFFFFE";
		sPop.innerHTML="<table border='0' cellspacing='10px' width='200px' height='150px'><tr><td class='blue' align='left' colspan='2'><strong>Sponsor Information</strong></td></tr><tr><td class='copy' valign='top'>Name</td><td><input id='sponsorName' type='text' size='30' /></td></tr><tr><td class='copy' valign='top'>Link</td><td><input id='sponsorLink' type='text' value='http://' size='30' /></td></tr><tr><td><input type='button' value='Add' onclick='javascript: addSponsor();' class='btn2' /></td><td><input type='button' value='Cancel' onclick='javascript: " + this.jsName + ".Close();' class='btn2' /></td></tr></table>";
			
		document.body.appendChild(sPop);
	}
	
SilverTech.Forms.PopupBox.prototype.Close = function () {
		var sPop = document.getElementById( this.popupBoxId );
		if( sPop )
			document.body.removeChild(sPop);
	}


function getPos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getPos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
		return r;
}
