//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 ToggleDisplay(objId){
    if(objId==null)return false;
    var htmlObj = GetObj(objId);
    
    if(htmlObj==null)return false;
    
    htmlObj.style.display = htmlObj.style.display=="block" ? "none" : "block";
    return false;
}

var lastPhoneInfoObj;
function TogglePhoneInfo(objId){
    if(objId==null)return false;
    var htmlObj = GetObj(objId);
    
    if(htmlObj==null)return false;
    
    if(lastPhoneInfoObj!=null ){
        lastPhoneInfoObj.style.display="none";
        
        if(lastPhoneInfoObj.id==htmlObj.id){
            lastPhoneInfoObj = null;
            return false;
        }
        
        lastPhoneInfoObj = null;
     }
    
    htmlObj.style.display = htmlObj.style.display=="block" ? "none" : "block";
    
    if(htmlObj.style.display=="block") lastPhoneInfoObj = htmlObj;
    else lastPhoneInfoObj = null;
    
    return false;
}


function OpenUploader(page,windowName){ //alert("upload: " +page);
    var width       = 523;
	var height      = 216;
	
	   
	var xloc        = (window.screen.availWidth-width)/2; 
	var yloc        = (window.screen.availHeight-height)/2; 
	
	var scrollable  = false;
	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 OpenRadio(page){ //alert("upload: " +page);
    var width       = 400;
	var height      = 190;
	
	   
	var xloc        = (window.screen.availWidth-width)/2; 
	var yloc        = (window.screen.availHeight-height)/2; 
	
	var scrollable  = false;
	var resizeble   = false;
	
	var win = window.open( page , "radioplayer", "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 DownloadFile( divId, src ){//alert("src: " +src);
    var divObj = GetObj( divId );
    
    if( divObj==null ){
        alert("Invalid Print Container");
        return false;
    }
    
    if( divObj.innerHTML==null ){
        alert("Invalid Print Container");
        return false;
    }
    
    divObj.style.visibility = "hidden";
    divObj.innerHTML = "<iframe runat=\"server\" id=\"ifr_download\" width=\"0\" height=\"0\" src=\"" + src + "\"></iframe>";
   
    //alert("divObj.innerHTML: " +  divObj.innerHTML ); 
    return false;
}


//=========================================================================================================//

 function DisplayTime( labelId, hoursDiff, doSubstract ){
    if(hoursDiff==null)hoursDiff = 0;
    if(doSubstract==null)doSubstract = false;
    
    var months = ["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"];
    
    var currentDate = new Date();
    
    if(hoursDiff!=0){      
        currentDate = new Date( 
            currentDate.getYear(),
            currentDate.getMonth(),
            currentDate.getDate(),
            doSubstract ? (currentDate.getHours() - hoursDiff) : (currentDate.getHours() + hoursDiff),
            currentDate.getMinutes(),
            currentDate.getSeconds()
        );
    }
    
    var dateStr = "";
    
    
    dateStr += "" + currentDate.getDate();
    dateStr += " " + months[currentDate.getMonth()];
    dateStr += " " + currentDate.getFullYear(); 
    
    dateStr += " " + Get2DigitNumber( currentDate.getHours() );
    dateStr += ":" + Get2DigitNumber( currentDate.getMinutes() );
    dateStr += ":" + Get2DigitNumber( currentDate.getSeconds() );
    
    
    
    //alert("value: "+ GetObj(labelId).value + ", innerText: "+ GetObj(labelId).innerText + ", innerHTML: "+GetObj(labelId).innerHTML);
    GetObj(labelId).innerText = dateStr;
}

function Get2DigitNumber( number ){            
    if( number<10 ) return ( "0" + number );
    return number.toString();
}

//=========================================================================================================//

 function InsertEditorSmily(editorId, smilyUrl){
    //alert("InsertEditorSmily: " + editorId +", smilyUrl: "+smilyUrl);
    var editor1 = GetObj(editorId);
    //alert("editor1: "+editor1);
    if(editor1==null)return;
    
    var smilyImageTag = '<img src="' + smilyUrl + '" align="absMiddle" border="0"  alt="" />';
    //alert("smilyImageTag: "+smilyImageTag);
    editor1.PasteHTML(smilyImageTag);
 }


function OpenSmily(page){
    var windowName  = "SelectSmily";
	var xloc        = (window.screen.availWidth-width)/2; 
	var yloc        = (window.screen.availHeight-height)/2; 
	var width       = 320;
	var height      = 400;
	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;
}

//=========================================================================================================//

//onmouseover="showtrail('http://www1.istockphoto.com/file_thumbview_approve/5484255/2/istockphoto_5484255_bet_on_the_future.jpg','Bet on the future','Bet on the future','5.0000','1','1',253,1);" onmouseout="hidetrail();"
window.onresize=AdjustRegions;