﻿/* ----------------------------------------------------------- */
// Browser Sniff
/* ----------------------------------------------------------- */

var UserAgent = navigator.userAgent.toLowerCase();
var Opera = (UserAgent.indexOf('opera') != -1); // is opera
var Opera8 = ((UserAgent.indexOf('opera 8') != -1 || UserAgent.indexOf('opera/8') != -1) ? 1 : 0); // is opera8
var NS4 = (document.layers) ? true : false; // is netscape 4
var IE4 = (document.all && !document.getElementById) ? true : false; // is IE 4
var IE5 = (document.all && document.getElementById) ? true : false;  // is IE 5+
var NS6 = (!document.all && document.getElementById) ? true : false; // is netscape 6
var FireFox = (UserAgent.indexOf("firefox/") != -1); // is firefox
var Transitions = (IE5 || IE4) ? true : false // do we support transitions
          
/* ----------------------------------------------------------- */
// Get a reference to an object on the client-side                   
/* ----------------------------------------------------------- */

function FindControl(strControlName) {
    
    var objReturn = '';
        if (IE5 || NS6 || Opera || Opera8 || FireFox)
        {
	        objReturn = document.getElementById(strControlName);
        }
        else if (IE4)
        {
	        objReturn = document.all[strControlName];
        }
        else if (NS4)
        {
	        objReturn = document.layers[strControlName];
        }

    return objReturn

}

// Global form post handler
function animateLogo()
{
    if(IE5 || IE4)
    {
        var sAppend = getControlNameBeginning();
        FindControl(sAppend + 'Header1_headerleftlogo').style.display = "none";
        FindControl(sAppend + 'Header1_headerleftlogoanimated').style.display = "block";  
                    
        document.body.style.cursor = "wait";
    }
}

function stopAnimation()
{
    var sAppend = getControlNameBeginning();

    FindControl(sAppend + 'Header1_headerleftlogo').style.display = "block";
    FindControl(sAppend + 'Header1_headerleftlogoanimated').style.display = "none";  
        
    document.body.style.cursor = "default";
}

window.onload = function()
{
   stopAnimation();
}

function openContentWindow(url)
{
    //alert('openContentWindow called');
    var newWin = window.open(url, 'ConnectContent', 'width=500px,height=300px,menubar=0,toolbar=0,resize=1');    
    //var newWin = window.open(url, 'ConnectContent');    
}


function downloadContent(url)
{
    var newWin = window.open(url, 'download', 'height=150px,width=450px,address=1,status=1');
    //var newWin = window.open(url);
}


function search(page)
{
    var ctl = FindControl('searchTerm');
    var trimmed = ctl.value.replace(/^\s+|\s+$/g, '') ;
    if(trimmed.length==0)
    {
        if(page=='Search')
        {
            //show the validation message
            var valMess = FindControl('divValidation');
            valMess.style.display = "";
        }
        else
        {
            //show the message in the search box
            ctl.value = 'Please enter a value';
        }
    }
    else
    {
        window.location.href = 'Search/Search.aspx?q=' + ctl.value;
    }
}

var lastInputBoxUsed = ''; 
function keyPressed(input)
{
    lastInputBoxUsed = input.id;           
}

function doLogin()
{
    if(lastInputBoxUsed.indexOf('txtUser')>0 || lastInputBoxUsed.indexOf('txtPassword')>0)
    {
        login();
        return true;
    }
    else
        return false;
}

function expandCollapseFolderList(scoID) {
    var ctl_img = $("#control_image_" + scoID);
    if(ctl_img[0])
        ctl_img = ctl_img[0];
    if(ctl_img) {        
        if(ctl_img.src.indexOf('closed')>0) {
			ctl_img.src = ctl_img.src.replace(/closed/,"open");
		} else {
			ctl_img.src = ctl_img.src.replace(/open/,"closed");
		}
    }
    
    showHideItem(scoID);
}

function expandCollapseMeetingList(scoID) {
    var ctl_img1 = FindControl(scoID + '_control_image1');
    var ctl_img2 = FindControl(scoID + '_control_image2');
    
    if(ctl_img1) {
        if(ctl_img1.src.indexOf('collapsed')>0) {
			ctl_img1.src = ctl_img1.src.replace(/collapsed/,"expanded");
		} else {
			ctl_img1.src = ctl_img1.src.replace(/expanded/,"collapsed");
		}
    }
   
    if(ctl_img2) {
        if(ctl_img2.src.indexOf('closed')>0) {
			ctl_img2.src = ctl_img2.src.replace(/closed/,"open");
		} else {
			ctl_img2.src = ctl_img2.src.replace(/open/,"closed");
		}
    }
    
    showHideItem(scoID);
}


function showHideItem(id) {

    //jQuery
    $("#" + id).toggle('fast');

    //prototype + scripalicious
	//new Effect.toggle(id, 'slide', {duration: 0.2});
}


function login()
{
    Fade_Login(true);
    var sAppend = getControlNameBeginning();    
    FindControl(sAppend + 'Header1_btnLogin').style.visibility = 'hidden';
    
    FindControl('LogonMessage').innerHTML = '';
    setTimeout('validateAndSubmitLogin()', 1000);
}

function getControlNameBeginning()
{
    var sAppend = '_ctl0_';
    if(!FindControl('_ctl0_Header1_btnLogin')) sAppend = sAppend + '_ctl0_';
    return sAppend;
}
        		
function validateAndSubmitLogin()
{   
    //set the values
    var sAppend = getControlNameBeginning();    
        
    FindControl('hidUser').value = FindControl(sAppend + 'Header1_txtUser').value;
    FindControl('hidPassword').value = FindControl(sAppend + 'Header1_txtPassword').value;

    //submit the form
    document.forms['frmSubmit'].submit();
}

function Fade_Login(e)
{
    FindControl('spLightboxText').innerHTML = "Logging in ...";
    FindControl('light_login').style.display=(e?'block':'none');
    FindControl('fade').style.display=(e?'block':'none');
}  

function Fade_Search(e)
{
    FindControl('spLightboxText').innerHTML = "Searching ...";
    FindControl('light_login').style.display=(e?'block':'none');
    FindControl('fade').style.display=(e?'block':'none');
}  

function closeFader()
{
    FindControl('light_login').style.display='none';
    FindControl('fade').style.display='none';
}

/*
document.oncontextmenu = doThings;

function doThings()
{	
    return false;
}

document.onkeydown = function ()
{
    var key_f5	= 116;	// 116 = F5
    var alt		= 18;	// Alt Key
    var clrl	= 17; 

    var keyPressed =((event.which)||(event.keyCode));
    
    if (key_f5 == keyPressed)
    {
        event.keyCode = 27;
        return false;
    }
}
*/