function BackGround(color)
{
    $("#imageBack").remove();
	$("<div id=\"imageBack\" style=\"position:absolute;display:none\"></div>").appendTo("body");
	$("#imageBack").css("top","0px");
	$("#imageBack").css("left","0px");
	$("#imageBack").css("height",$(document).height());
	$("#imageBack").css("width",$(document).width());
	$("#imageBack").css("backgroundColor",color);
	$("#imageBack").css('opacity',0.8);
	$("#imageBack").fadeIn("slow");
	$loader = $("<img src=\"/images/loading_"+color+".gif\" />");
	$("#imageBack").html($loader);
	$loader.center();
	$("#imageBack").click(function(){ $("#placeHolder").remove();$(this).fadeOut("fast")})	
}
var finishedText;
var title;
function DoHoverItem(type,value,factoryID,finishedT,titleT)
{
    finishedText = finishedT;
    title = titleT;
    var options;
    switch(type)
    {
        case "view":
            BackGround("black");
            options = {
                cache: false,
                data: {Screen:'api',Method:'domainClassViewPreview',call:'domainClassViewPreview',ID:factoryID,type:value,mode:'undefined'},
                dataType: 'xml',
                error: function(XMLHttpRequest, textStatus, errorThrown){alert("Sorry there was an error getting the view " + XMLHttpRequest.statusText)},
                success: function(data, textStatus){DrawItem(data)},
                url: '/default.aspx'
            }
            break;
        case "uniForm":
            Loading();
            options = {
                cache: false,
                data: {Screen:'api',Method:'getDomainClassForm',call:'getDomainClassForm',ID:'0',type:value,mode:'undefined',pageID:factoryID},
                dataType: 'xml',
                error: function(XMLHttpRequest, textStatus, errorThrown){alert("Sorry there was an error getting the form")},
                success: function(data, textStatus){Loaded();DrawForm(data,true,factoryID)},
                url: '/default.aspx'
            }
            break;
       case "uniFormWithPage":
            Loading();
            options = {
                cache: false,
                data: {Screen:'api',Method:'getDomainClassForm',call:'getDomainClassForm',ID:'0',type:value,mode:'undefined',pageID:factoryID},
                dataType: 'xml',
                error: function(XMLHttpRequest, textStatus, errorThrown){alert("Sorry there was an error getting the form")},
                success: function(data, textStatus){Loaded();DrawForm(data,true,factoryID)},
                url: '/default.aspx'
            }
            break;
    }
    $.ajax(options);
}	   

function Loading()
{

    BackGround("white");

}
function Loaded()
{}
 

function DrawForm(data,isForm,pageID)
{
    $("#imageBack").remove();
    if($(data).find("data").text().length == 0)
    {
        alert(finishedText);
        $("#imageBack").click();
    }
    $("#placeHolder").remove();
    $placeHolder = $("<div id=\"placeHolder\" style=\"display:none\"><h1>"+title+"</h1><br style=\"clear:both\"/></div>");
    $($(data).find("data").text()).appendTo($placeHolder);
    $placeHolder.insertAfter($(".menu").parent("div").next("div"));
    $(".menu").parent("div").next("div").fadeOut("slow",function()
    {
        $("#placeHolder").fadeIn("slow");
    });
    var options = { 
        success:       function(responseXML){DrawForm(responseXML,true)},
        dataType:  'xml',
        url: "/api_form_handlers/DomainClass.aspx?pageID="+pageID    
        };	
    $placeHolder.find("form").append("<input type=hidden name=page value='"+pageID+"'>");
	$placeHolder.find("form").ajaxForm(options); 
  
}

function DrawItem(data,isForm,pageID)
{
    if($(data).find("data").text().length == 0)
    {
        alert(finishedText);
        $("#imageBack").click();
    }
    $("#placeHolder").remove();
    $placeHolder = $("<div id=\"placeHolder\"><h1>"+title+"</h1><br style=\"clear:both\"/></div>");
    $($(data).find("data").text()).appendTo($placeHolder);
    $placeHolder.appendTo("body");
    $placeHolder.center();
    if(isForm)
    {
        var options = { 
            success:       function(responseXML){DrawItem(responseXML,true)},
            dataType:  'xml',
            url: "/api_form_handlers/DomainClass.aspx?pageID="+pageID
            
        };	
		$placeHolder.find("form").ajaxForm(options); 
    }
} 
