﻿// purpose: Show inline help on mouse hover
// Author: MR
// Creation Date: 12/04/2009
 /* --------------
 * CHANGE HISTORY
 * --------------
 * 
 * 
 * VERSION          AUTHOR              DATE            REASON (TASK ID) 
 * ---------------------------------------------------------------------
 * 1.0              MR                  12/04/09        Add functionality to display inline help message next the control
 

 --------------------------------------------------------------------------------*/




/* Rollover help text constants. Ends*/




var global_control_id = '';
var global_control;
var global_help_text = '';
var global_help_header_text = '';

/*this function is used for showing rollover help.
arguments: 
1. control_id = This is the id of the control for which the rollover text will be shown.
2. help_text = This is the text which will be shown on the rollover help div.
3. help_header_text = This is the header text of the rollover help div.
*/
function ShowRollOverHelp(control_id, help_text, help_header_text)
{   
    global_control_id = control_id;
    global_help_text = help_text ;
    global_help_header_text  = help_header_text ;
    
    //this function executes using the globally saved values.
    GlobalShowRollOverHelp();
}

function ShowRollOverHelp1(control, help_text, help_header_text)
{   
    global_control = control;
    global_help_text = help_text ;
    global_help_header_text  = help_header_text ;
    
    //this function executes using the globally saved values.
    GlobalShowRollOverHelp1();
}

function ShowRollOverHelpFilter(control_id, help_text, help_header_text)
{       
    global_control_id = control_id;
    global_help_text = help_text ;
    global_help_header_text  = help_header_text ;
    
    //this function executes using the globally saved values.
    GlobalShowRollOverHelpFilter();
}

function GlobalShowRollOverHelpFilter()
{
    //remove previous rollover help div.
    HideRollOverHelp();
    
    //getting the absolute position of the control.
    GetAbsolutePositionOfAControlFilter( global_control_id );
    
    //set the contents of roll over help div.  
    if ( document.getElementById('roll_over_help_div_inner_info') == null )
        return;  
    document.getElementById('roll_over_help_div_inner_info').innerHTML = global_help_text;
    
    if ( global_help_header_text == null )
        global_help_header_text = "Help";
    //setting the roll over help header info.
    document.getElementById('roll_over_help_div_header_info').innerHTML = global_help_header_text;
    
    var fleft=0;
    var width_roll_over_help_div= document.getElementById('roll_over_help_div').offsetWidth;
    //fixing for location and image. Assigning the left coordinate of the rollover help div.
    if ( global_control_id.match('fileOpportunityImage') != null || global_control_id.match('txtAddress') != null || global_control_id.match('txtCity') != null )
    {
        final_left = parseInt(control_absolute_left)-100 ;
        fleft=final_left ;
        //alert('hp2');
    }
    else
    {
        fleft = control_absolute_left ;
        //alert('hp3');
    }
    
    //show the rollover div.
    //document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    
    final_top = parseFloat(control_absolute_top)+1;
    document.getElementById('roll_over_help_div').style.top = ""+final_top+"px" ;
    document.getElementById('roll_over_help_div').style.display = 'block' ;    
    
    var IE = document.all?true:false //checking the IE browser.
    var deduct=110;
    if( global_control_id.match('search_name') )
        deduct=10;
    if (global_control_id.match('div_academic_discipline'))
        deduct=150;     
    if ( IE )
    {
        deduct=deduct+10;
    }
    fleft=fleft-deduct-document.getElementById('roll_over_help_div').offsetWidth;
    document.getElementById('roll_over_help_div').style.left=""+fleft+"px";
}


//this function actually shows the rollover help at the actual position.
function GlobalShowRollOverHelp()
{
    //remove previous rollover help div.
    HideRollOverHelp();
    
    //getting the absolute position of the control.
    GetAbsolutePositionOfAControl( global_control_id );
    
    //set the contents of roll over help div.    
    if ( document.getElementById('roll_over_help_div_inner_info') == null )
        return;
    document.getElementById('roll_over_help_div_inner_info').innerHTML = global_help_text;
    
    if ( global_help_header_text == null )
        global_help_header_text = "Help";
    //setting the roll over help header info.
    document.getElementById('roll_over_help_div_header_info').innerHTML = global_help_header_text;
    
    
    //fixing for location and image. Assigning the left coordinate of the rollover help div.
    /*if ( global_control_id.match('fileOpportunityImage') != null || global_control_id.match('txtAddress') != null || global_control_id.match('txtCity') != null )
    {
        final_left = parseInt(control_absolute_left)+ 55;
        document.getElementById('roll_over_help_div').style.left = ""+final_left + "px" ;
    }
    else
    {
        document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    }*/
    document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    
    //show the rollover div.
    //document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    
    final_top = parseFloat(control_absolute_top)+1;
    document.getElementById('roll_over_help_div').style.top = ""+final_top+"px" ;
    document.getElementById('roll_over_help_div').style.display = 'block' ;    
}


//this function actually shows the rollover help at the actual position.
function GlobalShowRollOverHelp1()
{
    //remove previous rollover help div.
    HideRollOverHelp();
    
    //getting the absolute position of the control.
    GetAbsolutePositionOfAControl1( global_control );
    
    //set the contents of roll over help div.    
    if ( document.getElementById('roll_over_help_div_inner_info') == null )
        return;
    document.getElementById('roll_over_help_div_inner_info').innerHTML = global_help_text;
    
    if ( global_help_header_text == null )
        global_help_header_text = "Help";
    //setting the roll over help header info.
    document.getElementById('roll_over_help_div_header_info').innerHTML = global_help_header_text;
    
    
    //fixing for location and image. Assigning the left coordinate of the rollover help div.
    if ( global_control_id.match('fileOpportunityImage') != null || global_control_id.match('txtAddress') != null || global_control_id.match('txtCity') != null )
    {
        final_left = parseInt(control_absolute_left)+ 55;
        document.getElementById('roll_over_help_div').style.left = ""+final_left + "px" ;
    }
    else
    {
        document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    }
    
    //show the rollover div.
    //document.getElementById('roll_over_help_div').style.left = ""+control_absolute_left + "px" ;
    
    final_top = parseFloat(control_absolute_top)+1;
    document.getElementById('roll_over_help_div').style.top = ""+final_top+"px" ;
    document.getElementById('roll_over_help_div').style.display = 'block' ;    
}


function HideRollOverHelp()
{
    if ( document.getElementById('roll_over_help_div') == null )
        return;
    document.getElementById('roll_over_help_div').style.display = 'none' ;
}


//this is for removing the previously shown rollover text.
function RemoveRollOverHelp()
{
    if ( document.getElementById('roll_over_help_div') == null )
        return;
    var roll_over_div = document.getElementById('roll_over_help_div') ;
    if (roll_over_div != null)
    {
        document.getElementById('roll_over_help_div').parentNode.removeChild(roll_over_div) ;
    }
}

//this function prohibits user to submit forms on pressing enter.
function DoNotSubmitOnEnter(eventWhich,eventKeyCode)
{
    if(eventWhich && eventWhich == 13) //enter is pressed. this is for Mozila.
    { 
        //document.getElementById('aspnetForm').onSubmit=" return false;";
        return false;
    }
    else if(eventKeyCode && eventKeyCode == 13) //this is for IE.
    { 
        //document.getElementById('aspnetForm').onSubmit=" return false;";
        return false;
    }
}

//********************************************************************
//This portion is necessary for Roll Over Help Text.   Ends.
//********************************************************************



//********************************************************************
//This portion for getting absolute position of a control. Begins
//********************************************************************


var control_absolute_left = 0;
var control_absolute_top  = 0;


//this function gets the absolute position of a control in a page.
//control_id is the id of the control of which we want to get the absolute position.
function GetAbsolutePositionOfAControl( control_id )
{        
    var obj = document.getElementById(control_id) ;
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft-obj.scrollLeft;
            curtop += obj.offsetTop-obj.scrollTop;
            var position='';
            if (obj.style&&obj.style.position) position=obj.style.position.toLowerCase();
            if ((position=='absolute')||(position=='relative')) break;
            while (obj.parentNode!=obj.offsetParent) 
            {
                obj=obj.parentNode;
                curleft -= obj.scrollLeft;
                curtop -= obj.scrollTop;
            }
            obj = obj.offsetParent;
        }
    }
    else 
    {
        if (obj.x)
        curleft += obj.x;
        if (obj.y)
        curtop += obj.y;
    }
                            
    //Maintainance for Internet Explorer.
    var IE = document.all?true:false //checking the IE browser.
    if ( IE ){ curleft += 10 ; curtop += 1 ; } //position maintainance for IE.
    
    //assigning the global variables.
    control_absolute_left = curleft + document.getElementById(control_id).offsetWidth;
    control_absolute_top = curtop ;
    
}      

//this function gets the absolute position of a control in a page.
//control_id is the id of the control of which we want to get the absolute position.
function GetAbsolutePositionOfAControl1( obj )
{    
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft-obj.scrollLeft;
            curtop += obj.offsetTop-obj.scrollTop;
            var position='';
            if (obj.style&&obj.style.position) position=obj.style.position.toLowerCase();
            if ((position=='absolute')||(position=='relative')) break;
            while (obj.parentNode!=obj.offsetParent) 
            {
                obj=obj.parentNode;
                curleft -= obj.scrollLeft;
                curtop -= obj.scrollTop;
            }
            obj = obj.offsetParent;
        }
    }
    else 
    {
        if (obj.x)
        curleft += obj.x;
        if (obj.y)
        curtop += obj.y;
    }
                            
    //Maintainance for Internet Explorer.
    var IE = document.all?true:false //checking the IE browser.
    if ( IE ){ curleft += 10 ; curtop += 1 ; } //position maintainance for IE.
    
    //assigning the global variables.    
    control_absolute_left = "450";
    control_absolute_top = curtop ;
    
}  

function GetAbsolutePositionOfAControlFilter( control_id )
{        
    var obj = document.getElementById(control_id) ;
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft-obj.scrollLeft;
            curtop += obj.offsetTop-obj.scrollTop;
            var position='';
            if (obj.style&&obj.style.position) position=obj.style.position.toLowerCase();
            if ((position=='absolute')||(position=='relative')) break;
            while (obj.parentNode!=obj.offsetParent) 
            {
                obj=obj.parentNode;
                curleft -= obj.scrollLeft;
                curtop -= obj.scrollTop;
            }
            obj = obj.offsetParent;
        }
    }
    else 
    {
        if (obj.x)
        curleft += obj.x;
        if (obj.y)
        curtop += obj.y;
    }
                            
    //Maintainance for Internet Explorer.
    var IE = document.all?true:false //checking the IE browser.
    if ( IE ){ curleft += 10 ; curtop += 1 ; } //position maintainance for IE.
    
    //assigning the global variables.
    control_absolute_left = curleft;
    control_absolute_top = curtop ;
    
}    
function clearOpportunityDates(chkNoDates,txtDeadlineDate,txtStartDate,txtEndDate)
{
    if(chkNoDates.checked==true)
    {
        //alert(txtDeadlineDate);
        txtDeadlineDate.value='';
        txtStartDate.value='';
        txtEndDate.value='';
    }
}

//********************************************************************
//This portion for getting absolute position of a control. Ends
//********************************************************************
function handleCommentTextarea(event)
        {
            try
            {
                key = event.which;            
                if(key == 13)
                {
                    event.stopPropagation();
                    return false;                
                }
            }
            catch(e)
            {
            }
        }
        
           
///Disabled Enter Key for global site
function disableEnterKey(eventWhich,eventKeyCode,e)
{
   if(eventWhich && eventWhich == 13)
   { 
      e.stopPropagation();
      return false;       
   }
  else if(eventKeyCode && eventKeyCode == 13)
  { 
    e.stopPropagation();
    return false;
    
  }else
  {
    return true;
  }
                  
}
