<!--
/************************************************************
 * Countdown Characters
 ************************************************************/
function countdown_chars2(field, limit) {
  content_length = $F(field).length;
  remaining = limit - content_length;
  if (remaining < 1) {
    $(field).value = $F(field).substring(0,limit);
  }
  $('char_count').innerHTML = remaining;
}

function countdown_chars(field, limit) {
  content_length = document.getElementById(field).value.length;
  remaining = limit - content_length;
  
  if (remaining < 1) {
    document.getElementById(field).value = document.getElementById(field).value.substring(0,limit);
  }
  document.getElementById('char_count').innerHTML = remaining + ' characters left';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ToggleControlVisible(controlName)
{   
    if (document.getElementById(controlName).style.visibility == 'visible')
    {
        document.getElementById(controlName).style.visibility = 'hidden';
    }
    else if (document.getElementById(controlName).style.visibility == 'hidden')
    {
        document.getElementById(controlName).style.visibility = 'visible';
    }
    return false;
}

function ToggleControlDisplay(controlName)
{   
    if (document.getElementById(controlName).style.display == 'block')
    {
        document.getElementById(controlName).style.display = 'none';
    }
    else if (document.getElementById(controlName).style.display == 'none')
    {
        document.getElementById(controlName).style.display = 'block';
    }
    return false;
}
function DisableControlPrePostBack(controlID, validationGroup)
{
    var v = false;
    alert('Function DisableControlPrePostBack() called by: ' + controlID);
    if(controlID)
    {
        var c = document.getElementById(controlID);
        
        if(c)
        {
            if(validationGroup != '') 
            { 
                Page_ClientValidate(validationGroup); 
            }
            
            else 
            { 
                Page_ClientValidate(); 
            }
            
            v = ValidatorCommonOnSubmit();
            alert('Validation for group: ' + validationGroup + ' is ' + v);
            if(v)
            {
                c.disabled = true;
            }
        }
    }
}
function maxChar(txtControl, lblControl, maxChrs)
{
    
    var txt = document.getElementById(txtControl);
    var lbl = document.getElementById(lblControl);
    var max = parseInt(maxChrs)

    if(txt && lbl)
    {
        var inp = txt.value;
        var l = parseInt(inp.length)
        
        if (l > max)
        {
            alert("You have reached the maximum number of allowed characters!")
            inp = inp.substr(0,max)
            txt.value = inp
            return;
        }
        
        lbl.innerHTML = max-inp.length;
    }
}
function GetControlValue(c)
{
    return document.getElementById(c).value;
}
function GetControlOption(c)
{
    return document.getElementById(c).options[GetControl(c).selectedIndex].text;
}
function GetControl(c)
{
    var d = document.getElementById(c);                                        
    return d;
}
function GetTextLength(c)
{
    return parseInt(GetControlValue(c).length);
}
function ToggleControlVisibility(txtCntrl, lblCntrl)
{
    GetTextLength(txtCntrl) > 0 ? GetControl(lblCntrl).style.display = 'block' : GetControl(lblCntrl).style.display = 'none';
}
function ResolveFriendlyUrl(c)
{
    if(c)
    {
        return GetControlValue(c).search(/http:/) == -1 ? "http://" + GetControlValue(c) : GetControlValue(c);
    }
}

function popup(url,title,width,height,left,top)
{

	link = window.open(url,title,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=" + width +",height=" + height + ",left="+left+",top="+top +"");
}

function popupnoscroll(url,title,width,height,left,top)
{

	link = window.open(url,title,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,width=" + width +",height=" + height + ",left="+left+",top="+top +"");
}


 function isAlphaNumericKey(keyCode)
 {
      if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91))
      {
          return true;
      }
      return false;
 }

 function LimitCharacters(editor)
 {
     if(editor.GetText().length < 1)
     {
        editor.SetHtml("");
     }
     
     var messageText = 'The amount of characters may not exceed ';
     var args = editor.GetDialogParameters("CharacterCount");
     var textLength = parseInt(editor.GetText().length);
     var maxTextLength = 0;
     var elementCharCount = null;
     
     if(args)
     {
        maxTextLength = args["CharMax"];
        elementCharCount = args["UpdateControl"];
     }
     
     editor.AttachEventHandler ("onkeyup", function (e)
     {
         e = (e == null)? window.event : e;

         textLength = parseInt(editor.GetText().length);
         
         if(maxTextLength && elementCharCount)
         {
             if (textLength > maxTextLength)
             {
                  alert(messageText + maxTextLength);
                  e.returnValue = false;
                  editor.SetHtml(editor.GetText().substr(0,maxTextLength));
                  
                  return false;
             }
             GetControl(elementCharCount).innerHTML = (maxTextLength - textLength);
         }
      });
     editor.AttachEventHandler ("onpaste", function (e)
     {
         textLength = CalculateLength (editor);
         if(maxTextLength && elementCharCount)
         {
             if (textLength > maxTextLength)
             {
                 alert(messageText + maxTextLength);
                 
                 e.returnValue = false;
                 e.cancelBubble = true;
                 editor.SetHtml(editor.GetText().substr(0,maxTextLength));
                 
                 return false;
             }
             GetControl(elementCharCount).innerHTML = maxTextLength - textLength;
         }
     });
 }

 function CalculateLength(editor)
 {
     var textLength = editor.GetText().length;
     var clipboardLength = window.clipboardData.getData("Text").length;
     textLength += clipboardLength;
     return textLength;
 }

 function OnClientCommandExecuting(editor, commandName, oTool)
 {
    var maxTextLength = 0;
    var elementCharCount = null;
    var args = editor.GetDialogParameters("CharacterCount");
    if(args)
    {
        maxTextLength = args["CharMax"];
        elementCharCount = args["UpdateControl"];
    }
    if (commandName == "PasteFromWord"
        || commandName == "PasteFromWordNoFontsNoSizes"
        || commandName == "PastePlainText"
        || commandName == "PasteAsHtml"
        || commandName == "Paste" )
    {     
    if (document.all)
    {
        var textLength = CalculateLength (editor);
        if(maxTextLength && elementCharCount)
        {
            if (textLength >= maxTextLength)
            {
              alert(messageText + maxTextLength);
              return false;
            }
            GetControl(elementCharCount).innerHTML = maxTextLength - textLength;
        }
    }
  }
}

//-->