﻿var timerID = 0;

//Allows you to hide a control after a period of time (status messages, etc).
function HideControlTimer(controlid, time){
    document.getElementById(controlid).style.display = '';
    timerID  = setTimeout("HideControl('"+controlid+"')", time);
}

//hides the target control.
function HideControl(id){
    document.getElementById(id).style.display = 'none';
}

//hides the target control.
function ControlState(id, state){
    document.getElementById(id).style.display = state;
}


//confirm something (usually a delete action).
function ConfirmDelete(text)
{
  if (confirm(text)==true)  
    return true;    
  else  
    return false;
}

//Gets the current window Width (Cross browser compatible)
function getWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

//Gets the current window Height (Cross browser compatible)
function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight  ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function SetStatus(text, mode){

    var divelement = document.getElementById('divStatusMessage'); 
    divelement.style.display = '';
    if (mode==1){
        divelement.className = 'divStatusMessage divStatusMessage_Failed';  
    }
    else{
        divelement.className = 'divStatusMessage divStatusMessage_Success';    
    }
    divelement.innerHTML = text;
    
    HideControlTimer(divelement.id,2000);
}

function SwapButtonCSS(controlIds, className, surroundClassName, disable){
    
    controlIds = controlIds.split(",");
    
    for(var i = 0; i < controlIds.length; i++){
        // change the css on the control
        var control = document.getElementById(controlIds[i]);
        control.className = className;
        
        //change the css on the surrounding control (button padding).
        control.parentNode.className = surroundClassName;
        
        //if required disable the control.
        if (disable){
            control.onClick = function() {return false;}
        }        
    }
    
}

//Passes focus onto the next field once it's max length is reached.
function nextbox(fldobj, nbox) {
	if (fldobj.value.length==fldobj.maxLength && nbox != '') {
		document.getElementById(nbox).focus();
	}
}

//clears a default value.
function cleardefault(fldobj, defaultvalue){
    if (fldobj.value == defaultvalue)
        fldobj.value = '';
}

//restores a default value.
function restoredefault(fldobj, defaultvalue){
    if (fldobj.value == '')
        fldobj.value = defaultvalue;
}

//Limits data entry in a field to numberic values only.
function numberonly(evt, allowdecimals){
    
    var returnValue = false;
    
    //Get the keycode.
    var keyCode = event.which || event.keyCode;
    
    //If the user has pressed shift, tab, delete or backspace.
	if (keyCode == 16 || keyCode == 8 || keyCode == 46 || keyCode == 9){
		returnValue = true;
	}
	else if ((keyCode >= 48 && keyCode <= 57) || (allowDecimals && (keyCode == 190 || keyCode == 110)) || (keyCode >= 96 && keyCode <= 105))
	{
		returnValue = true;
	}

	return returnValue;
}

function GetRDBValue(id)
{
    var returnValue = null;
    var radio = document.getElementsByName(id);
    for (var i = 0; i < radio.length; i++)
    {
        if (radio[i].checked)
        {
            returnValue = radio[i].value;
            break;
         }
    }
    
    return returnValue;
}
