function loadfiles()
{
	jQuery("body").append(jQuery("#addpopup").html());
	jQuery("#addpopup").remove();
	
	var csslink = document.createElement("link");	
	csslink.setAttribute("type", "text/css");
	csslink.setAttribute("href", "/css/smoothness/jquery-ui-1.7.1.custom.css");
	csslink.setAttribute("media", "screen, tv, projection");
	csslink.setAttribute("rel", "stylesheet");
	document.getElementsByTagName("head")[0].appendChild(csslink);
	
	var csslink = document.createElement("link");	
	csslink.setAttribute("type", "text/css");
	csslink.setAttribute("href", "/css/admin.css");
	csslink.setAttribute("media", "screen, tv, projection");
	csslink.setAttribute("rel", "stylesheet");
	document.getElementsByTagName("head")[0].appendChild(csslink);
	
	var jsscript = document.createElement("script");	
	jsscript.setAttribute("type", "text/javascript");
	jsscript.setAttribute("src", "/js/jquery-ui-1.7.1.custom.min.js");
	document.getElementsByTagName("head")[0].appendChild(jsscript);
	
	jsscript.onload = adminjs;
  	jsscript.onreadystatechange = function()
  	{
    	if(this.readyState == "complete"){
            adminjs();
        }
    }
}

function adminjs(){

	jQuery("#popupcontent").draggable({handle: 'span.header'});

	if(jQuery("#wrap").html() == null)
	{
		jQuery("body").attr("id", "admtask");
	}

	var updivs = jQuery("#updivs").html();

	var updiv = updivs.split(";");
	
	for(var i=0; i<updiv.length; i++)
	{
		if(updiv[i] != "")
		{
			jQuery("#" + updiv[i]).addClass("adm");
			jQuery("#" + updiv[i]).prepend("<img  alt=\"edit\" class=\"admimg\" src=\"/images/icon/Edit.gif\" />");
		}
	}
	
	jQuery(".admimg").bind("click", function(){
		jQuery(this).parent().css({
			"border": "3px solid #ff0000"
		});
		
		showdiv(jQuery(this).parent().attr("id"), jQuery("#pgmnam").html());
	});
	
	jQuery(".closediv").click(function(){
		closediv("close");
	});
	
}

function showdiv(div, pgm)
{
	jQuery("#popupcontent iframe").attr("src", "admcontent.pgm?task=admform&div=" + div + "&pgm=" + pgm + "&rnd=" + Math.random());
	jQuery("#popupcontent").css("display", "block");
	jQuery("#popupcontent .header").html("Change Content for " + div);
}

function closediv(type, pgm)
{
	if(typeof type == "undefined")
	{
		type = "";
	}
	
	jQuery(".admimg").parent().css({
		"border": "1px solid #ff9813"});
	
	jQuery("#popupcontent iframe").attr("src", "");
	jQuery("#popupcontent").css("display", "none");
	
	if(type == "")
	{
		location.href = pgm + ".pgm?edit=Y";
		return false;
	}
}

function divwidth(div, type)
{
	if(type == "rw")
	{
		return jQuery("#" + div).css("width");
	}
}

function frameheight(height)
{
	jQuery("#popupcontent iframe").css("height", height + "px");
	jQuery("#popupcontent").css("height", height + 50 + "px");
}
