//Needs Common.js

function GetContentDivSize(){            
    var container   = GetObj("contentPanel");            
    var posObj      = getContainerWindowPosition(container);
    
    return { width:container.scrollWidth, height:container.scrollHeight, x:posObj.x, y:posObj.y, left:container.style.left, top:container.style.top };
}

function ShowMainBusyDialog(){
    var container           = GetObj("busyDialog");
    var infoObj             = GetContentDivSize();
    //infoObj.height         += 100;
    
    container.className     = "busyDialogActive";
    container.style.left    = "268px";
    container.style.top     = "85px";
    container.style.width   = infoObj.width + "px";
    container.style.height  = infoObj.height + "px";
    container.width         = infoObj.width;
    container.height        = infoObj.height;
    return false;
}


function handleRollOver( styleClass, control ){
    control.className = styleClass;  
}

function OpenSearchSelect(page){
    var windowName  = "SearchSelect";
	var xloc        = (window.screen.availWidth-width)/2; 
	var yloc        = (window.screen.availHeight-height)/2; 
	var width       = 840;
	var height      = 800;
	var scrollable  = true;
	var resizeble   = false;
	
	var win = window.open( page , windowName, "height="+height+", width="+width+", top="+yloc+", left="+xloc+", scrollbars=" + ( scrollable ? 1 : 0 ) + ", menubar=0, location=0, resizable=" + (resizeble ? 1 : 0 ) + ", status=0");
    win.focus();
    return false;
}

function CloseSearchSelect(callback,selectedValue,selectedText){
    if(window.opener==null) return;
    if(window.opener[callback]==null){
        alert("Search Select Callback Function Undefined!");
        window.close();
        return;
    }
    
    window.opener[callback]( selectedValue, selectedText );     
 
    window.opener.focus();
    window.close();
    return false;
}

function OpenWindow(page){
    var windowName  = "Page";
	var xloc        = (window.screen.availWidth-width)/2; 
	var yloc        = (window.screen.availHeight-height)/2; 
	var width       = window.screen.availWidth;
	var height      = window.screen.availHeight;
	var scrollable  = true;
	var resizeble   = true;
	
	var win = window.open( page , windowName, "height="+height+", width="+width+", top="+yloc+", left="+xloc+", scrollbars=" + ( scrollable ? 1 : 0 ) + ", menubar=1, location=1, resizable=" + (resizeble ? 1 : 0 ) + ", status=1");
    win.focus();
    return false;
}

//makes sure that all regions are fit to the whole document.body width.
function AdjustRegions() { 
    var headerContainer = GetObj("headerContainer");
    var pageFooterWrapper = GetObj("pageFooterWrapper");
    if(headerContainer==null || pageFooterWrapper==null)return;
    
    var docWidth = window.screen.availWidth; //document.body.clientWidth;
        
    if(headerContainer.clientHeight<docWidth){
        headerContainer.width = docWidth;
        headerContainer.style.width = docWidth + "px";
    }
    
    if(pageFooterWrapper.clientHeight<docWidth){
        pageFooterWrapper.width = docWidth;
        pageFooterWrapper.style.width = docWidth+ "px";
    }
    
    //================================================    
    var pageContainer = GetObj("pageContainer");    
    var contentContainer = GetObj("contentContainer");    
    var headerContainer = GetObj("headerContainer");    
    var pageFooterWrapper = GetObj("pageFooterWrapper");    
    if(contentContainer==null || pageFooterWrapper==null || headerContainer==null )return;
    
    
    
    var defHeight = window.screen.availHeight - headerContainer.clientHeight - pageFooterWrapper.clientHeight;
   
    if(contentContainer.clientHeight==-1 || defHeight==null || defHeight<0) return;
    
    if(contentContainer.clientHeight<defHeight){        
        contentContainer.height = defHeight;
        contentContainer.style.height = defHeight + "px";
        
    }
}

function WaterMark_OnFocus(caller, defaultText, normalCssClass)
{ 
//alert("b");
   if (caller.value == defaultText)
   {
      caller.className = normalCssClass;
      caller.value = "";
   }
}

function WaterMark_OnBlur(caller, defaultText, normalCssClass, watermarkCssClass)
{
//alert("a");
   var textValue = caller.value;

   if (textValue == defaultText || textValue.length == 0)
   {
      caller.className = watermarkCssClass;
      caller.value = defaultText;
   }
   else
      caller.className = normalCssClass;
}


window.onresize=AdjustRegions;