﻿// JScript File

function countChar(str, ctlname){
    var o = document.getElementById(ctlname);
    o.innerHTML = str.length
}

function DisplayInLabel(str, ctlname, defaultvalue) {
    var o = document.getElementById(ctlname);
    if(str.length == 0) {
        o.innerHTML = defaultvalue;
    }
    else {
        o.innerHTML = str;
    }
}

function ToggleButtonState(btn, rdo) {
    var b = document.getElementById(btn);
    var n = document.getElementById(rdo);
    b.disabled = n.checked;
}

function confirmPopup(msg) {
    var result = confirm(msg);
    if (result) {
        return true;
    }
    else {
        return false;
    }
}

function setFocus(ctl) {
    alert(ctl);
    var o = document.getElementById(btn);
    o.setfocus();
}

//FAQs page
// function for the link that turns them all off
function toggleAllOff(){
     for (var i = 0; i < answers.length; i++) {
        answers[i].className = 'hide';
     }
}
        
// function for the link that turns them all on
function toggleAllOn(){
     for (var i = 0; i < answers.length; i++) {
        answers[i].className = 'show';
     }
}

function displayToggle(){
     // calls the toggle all off function 
     // to turn all the answers off when the page is loaded     
     toggleAllOff(); 

     for (i=0; i<questions.length; i++) {  // loops through the questions
         questions[i].onclick=function() {  // shows the answers onclick
             var next = this.nextSibling;
             // if it gets to a non-element node, go to the next one
             while(next.nodeType != 1) next=next.nextSibling; 
             next.className=((next.className=="hide") ? "show" : "hide");
          }
      }
}

function doBeforePaste(control)
{
   maxLength = control.attributes["maxLength"].value;
   if(maxLength)
   {
       event.returnValue = false;
   }
}
function doPaste(control)
{
   maxLength = control.attributes["maxLength"].value;
   value = control.value;
   if(maxLength){
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var o = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + o.text.length;
        var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
        o.text = sData;
    }
}
function LimitInput(control)
{
    if(control.value.length > control.attributes["maxLength"].value)
    {
        control.value = control.value.substring(0,control.attributes["maxLength"].value);
    }
}

function HideContent(d) {
    if(d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
    if(d.length < 1) { return; }
    var dd = document.getElementById(d);
    //AssignPosition(dd);
    dd.style.left = "225px";
    dd.style.top = "450px";
    dd.style.display = "block";
}

function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }

function AssignPosition(d) {
alert("rX:" + rX + " rY:" + rY + " cX:" + cX + " cY:" + cY);
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
alert("left: " + d.style.left + " top: " + d.style.top);
}
