var ActivePage='';
var BackColorButtonLine="#000000";
var baseTop = 0;
var LineButton=0;
var HeaderColorHeight = 0;
var FooterColorHeight = 0;

function NullOrMissing(obj)
{
	if (typeof obj == "undefined" || 
		obj == null || 
		obj == "")
		return true; 
	return false;
}
function LoadForm()
{
    
	baseTop = document.body.clientHeight;
    SetActivePages();
    if( document.getElementById("span_line_button") ) LineButton = document.getElementById("span_line_button").style.pixelHeight;
    if(!NullOrMissing(document.getElementById("DIV_HEADER_COLOR"))) HeaderColorHeight = document.getElementById("DIV_HEADER_COLOR").style.pixelHeight;
    if(!NullOrMissing(document.getElementById("DIV_FOOTER_COLOR"))) FooterColorHeight = document.getElementById("DIV_FOOTER_COLOR").style.pixelHeight;

    Line();
    Footer();
    Body();
    CenterZoomBG();
	AjaxLoad();
}

function hideLayer(layer)
{
    document.all[layer].style.visibility = "hidden";
}

function showLayer(layer)
{
    document.all[layer].style.visibility = "visible";
}

function SetActivePages()
{
	for(i=0;i<document.forms[0].length;i++){
		if(document.forms[0].elements[i].type=="hidden"){
			elemName = document.forms[0].elements[i].name
            len = elemName.length;
            if(elemName.substr(len-7,len)) document.forms[0].elements[i].click();
		}
	}
}

function ChangePage(thisPageTab,StoredField)
{
    hideLayer(document.all[StoredField].value);
    document.all[StoredField].value = thisPageTab;
    showLayer(document.all[StoredField].value);
}

function SetElementAction(ElementName)
{
    document.getElementById("FormElementAction").value = ElementName;
}

function BackGroundTop()
{
    document.all["bg_span"].style.posTop = document.body.scrollTop;
}

function HeaderTop()
{
   if( document.all["DIV_HEADER_COLOR"]==undefined ) return;
   document.all["DIV_HEADER_COLOR"].style.pixelTop = document.body.scrollTop;
   document.all["DIV_HEADER"].style.pixelTop = document.body.scrollTop;
}

function Footer()
{
    var obj =  document.getElementById("DIV_FOOTER_COLOR"); 
	var obj2 =  document.getElementById("DIV_FOOTER"); 
    if( !obj || !obj2) return;

    var posTop = (baseTop - obj.style.pixelHeight - LineButton);
	//alert();
	
	
	//alert(baseTop+"-baseTop "+obj.style.pixelHeight+"-pixelHeight "+LineButton+"-LineButton");
    
    document.getElementById("DIV_FOOTER_COLOR").style.pixelTop = posTop;
    document.getElementById("DIV_FOOTER").style.pixelTop = posTop;
	
	//alert(document.all["DIV_FOOTER_COLOR"].style.pixelTop+"-"+document.all["DIV_FOOTER"].style.pixelTop);
	
	//document.all["DIV_FOOTER_COLOR"].style.posTop;//-document.all["DIV_FOOTER_COLOR"].style.pixelHeight;
	
	//var obj = document.all["span_line_button"];
    //if( obj ) obj.style.pixelTop = baseTop-LineButton;
return ;

    
}

function MoveDivClip()
{
    var obj = document.getElementById("DIV_BODY");
    if( !obj ) return;

    var topClip = document.body.scrollTop;

    var bottomClip = document.getElementById("DIV_BODY_COLOR").style.pixelHeight+topClip;

    obj.style.clip  = 'rect('+topClip+'px,auto,'+bottomClip+'px,auto)';
}

function Body()
{
    var v = document.body.clientHeight - HeaderColorHeight - FooterColorHeight - LineButton;
    document.getElementById("DIV_BODY_COLOR").style.pixelHeight = v;

    var posTop = document.body.scrollTop;
    if(!NullOrMissing(document.getElementById("DIV_HEADER_COLOR"))) posTop = document.getElementById("DIV_HEADER_COLOR").style.posTop;
    document.getElementById("DIV_BODY_COLOR").style.posTop = posTop + HeaderColorHeight;

    MoveDivClip();
}

function Line()
{
    var obj = document.getElementById("span_line_button");
    if( obj ) obj.style.pixelTop = baseTop-LineButton;
}

function ScrollForm()
{
    baseTop = document.body.clientHeight + document.body.scrollTop;

    Line();

    HeaderTop();

    Footer();

    Body();

    var obj = document.all["DIV_BG_IMAGE"];
    if( !obj  ) return;
    obj.style.pixelHeight = document.body.clientHeight-LineButton;
    obj.style.pixelTop = document.body.scrollTop;
}

function TilingBG()
{
    var obj = document.getElementById("IMG_BG_IMAGE");
    var BaseObj = document.getElementById("DIV_BG_IMAGE");
    var idNom =1;
    var id = "IMG_BG_IMAGE_";
    var newImg;
    while(true)
    {
        newImg = document.getElementById((id + idNom));
        if( newImg == null ) break;
        BaseObj.removeChild(newImg);
        idNom +=1;        
    }

    idNom =1;
    var offset = 0;
    if(obj.style.height=="100%"){
        obj.style.pixelLeft = 0;
        delta = document.body.clientWidth - obj.clientWidth;
        offset = obj.clientWidth;
    }
    else{
        obj.style.pixelTop = 0;
        delta = document.body.clientHeight - obj.clientHeight;
        offset = obj.clientHeight;
    }

    while( delta > 0 )
    {
        newImg = obj.cloneNode(); 
        newImg.id = id + idNom;
        newImg.style.position = "absolute";

        if(obj.style.height=="100%")
        {
            newImg.style.left = offset;
            offset += obj.clientWidth;
            delta -= obj.clientWidth;
        }
        else
        {
            newImg.style.top = offset;
            offset += obj.clientHeight;
            delta -= obj.clientHeight;
        }

        BaseObj.appendChild(newImg);
        idNom++;
    }
}

function CenterZoomBG()
{
    var obj = document.getElementById("DIV_BG_IMAGE");
    if( !obj ) return;

    obj.style.pixelHeight = baseTop-LineButton;

    obj = document.getElementById("DIV_BG_IMAGE_POS");
    if( !obj ) return;

    if( obj.value == "center" )
    {
        obj = document.getElementById("IMG_BG_IMAGE");
        if( obj.style.height=="100%" ) obj.style.left = (document.body.clientWidth - obj.clientWidth)/2;
        else obj.style.top = (document.body.clientHeight - obj.clientHeight)/2;
    }

    if( obj.value == "tiling" ) TilingBG();
}

function ResizeForm()
{
	ScrollForm();
    CenterZoomBG();
}
/**
 * @author Lexx
 */
function SetActiveTab(TabName, TabStr)
{
	var tabs_arr = TabStr.split(", ");
	var i = 0;
	while(i < tabs_arr.length)
	{
		//alert(tabs_arr[i] + " " + TabName);
		if(tabs_arr[i] != TabName)
		{
		var tab = document.getElementById(tabs_arr[i]);
		var div = document.getElementById(tabs_arr[i]+"_div");
		div.style.visibility = "hidden";
		tab.setAttribute("class", "tab");
		tab.className = "tab";
		}
		i++;
	}
	tab = document.getElementById(TabName);
	div = document.getElementById(TabName+"_div");
	tab.className = "tab_active";
	div.style.visibility = "visible";
}
function UnhideR(TabStr)
{
	var tabs_arr = TabStr.split(", ");
	var i = 0;
	var vset = 0;
	var vunset = 0;
	var last_tab = document.getElementById(tabs_arr[tabs_arr.length-1]).style.display;
	while(i < tabs_arr.length)
	{
		var tab = document.getElementById(tabs_arr[i]).style;
		if(tab.display == "inline" && vunset == 0 &&  last_tab == "none")
		{
			if((i+1) < tabs_arr.length)
			{
				tab.display = "none";
				vunset = 1;	
			}		
		}
		i++;
	}
	i = tabs_arr.length-1;
	while(i > -1)
	{
		tab = document.getElementById(tabs_arr[i]).style;
		if(tab.display == "inline" && vset == 0)
		{
			if((i+1) < tabs_arr.length)
			{
				document.getElementById(tabs_arr[i+1]).style.display = "inline";
				vset = 1;
			}
			
		}
		i--;
	}
}
function UnhideL(TabStr)
{
	var tabs_arr = TabStr.split(", ");
	var i = 0;
	var vset = 0;
	var vunset = 0;
	var first_tab = document.getElementById(tabs_arr[0]).style.display;
	while(i < tabs_arr.length)
	{
		var tab = document.getElementById(tabs_arr[i]).style;
		if(tab.display == "inline" && vset == 0 && first_tab == "none")
		{
			document.getElementById(tabs_arr[i-1]).style.display = "inline";
			vset = 1;
		}
		i++;
	}
	i = tabs_arr.length-1;
	while(i > -1)
	{
		tab = document.getElementById(tabs_arr[i]).style;
		if(tab.display == "inline" && vunset == 0 && first_tab != "inline")
		{
			tab.display = "none";
			vunset = 1;
		}
		i--;
	}
}
