/////////////////////////////////////////////////////////////////
//
// Web Beget Framework & Application under
// Copyright © 2007 Robb Garrioch, robb@datamenus.com
// All rights reserved
//
/////////////////////////////////////////////////////////////////


function clear_alert_sel(selobj, selclass, alertclass, imgclass, selspanid)
{
    if(selobj.options[selobj.selectedIndex].value!='')
    {
        selobj.className = selclass;
        document.getElementById(selspanid).className = '';
    }
    else
    {
        selobj.className = alertclass;
        document.getElementById(selspanid).className = imgclass;
    }
}

function clear_alert_rad(container_obj)
{
    var ids = getElementsByTagNames('span', document.getElementById(container_obj));
    for(var i = 0; i < ids.length; i++)
    {
        if(document.getElementById(ids[i]).className != "widgettxt") // widgettxt, default class for radio button text 
        {
             document.getElementById(ids[i]).className = '';
        }
    }
}


function buildquerystring(frm)
{
    frm.onsubmit = function() {
        for(var i = 0; i < this.elements.length; i++)
        {
            if((this.elements[i].value != "") && (this.elements[i].type != "submit"))
            {
                qs += this.elements[i].name;
                qs += "=";
                qs += encodeURIComponent(this.elements[i].value);
                qs += "&";
            }
        }
        return qs;
    }
}


function set_opacity(obj, value)
{
    obj.style.opacity = value/10;
    obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}


function writeresponse(elem, content)
{
    elem.innerHTML = content;
}

// Alerted from original to suite Background Alert alert type
function getElementsByTagNames(list, obj)
{
    if(!obj) var obj = document;
    var tagNames = list.split(',');
    var resultArray = new Array();
    var id;
    for(var i = 0; i < tagNames.length; i++)
    {
        var tags = obj.getElementsByTagName(tagNames[i]);
        for (var j = 0; j < tags.length; j++)
        {
            id = tags[j].getAttribute('id');
            if(id.indexOf("radspanid") != -1) // Only admit span ids that are to hold the alert image 
            {
                resultArray.push(id);
            }
        }
    }
/*
    var testNode = resultArray[0];
    if(testNode.sourceIndex)
    {
        resultArray.sort(function (a,b) {
                return a.sourceIndex - b.sourceIndex;
        });
    }
    else if(testNode.compareDocumentPosition)
    {
        resultArray.sort(function (a,b) {
                return 3 - (a.compareDocumentPosition(b) & 6);
        });
    } 
*/
    return resultArray;
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autotab(input,len, e)
{
    var keyCode = (isNN) ? e.which : e.keyCode; 
    if(input.value.length >= len)
    {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
    function getIndex(input)
    {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
        return index;
    }
    return true;
}




function isnum(val)
{
   var validchars = "0123456789";
   var isnum = true;
   var c;

   for(i = 0; i < val.length && isnum == true; i++) 
   { 
      c = val.charAt(i); 
      if(validchars.indexOf(c) == -1) 
      {
         isnum = false;
      }
   }
   return isnum;
}


function isvalidateemail(email)
{
    if (email.length < 7 ||
    email.indexOf(" ") != -1 ||
    email.indexOf("@.") != -1 ||
    email.indexOf("-.") != -1 ||
    email.indexOf("_.") != -1 ||
    email.indexOf("..") != -1 ||
    email.indexOf("._") != -1 ||
    email.indexOf(".-") != -1 ||
    email.indexOf(".@") != -1 ||
    email.indexOf("@-") != -1 ||
    email.indexOf("@_") != -1 ||
    email.indexOf("@") != email.lastIndexOf("@") ||
    email.indexOf("@") == -1 ||
    email.indexOf(".") == -1 ||
    (email.length - (email.lastIndexOf(".") + 1)) < 2)
        return false;
    else
        return true;
}



/* SILON RELATED CODE */
var pid;
var bplft = 0;
var direction = "lft";
function dynamic_styles_silon(tag)
{
    if(direction == "lft")
    {
        bplft++;
        if(bplft == 72)        // increase this integer for longer button text
            direction = "rht";
    }
    else if(direction == "rht")
    {
        bplft--;
        if(bplft == -50)
            direction = "lft";
    }

    var h = "";
    var c = 0;

    if(document.getElementsByTagName)
    {
        var nodes = document.getElementsByTagName(tag);   // nodes here is a Collection not an array 
        for(var i = 0; i < nodes.length; i++)
        {
            var nodeObj = nodes.item(i);
            for(var j = 0; j < nodeObj.attributes.length; j++)
            {
                if((nodeObj.attributes.item(j).nodeName == 'class') && (nodeObj.attributes.item(j).nodeValue == 'btn_silon'))
                {
                     if(direction == "lft")
                     {
                         nodeObj.style.backgroundImage = "url(images/lft_c00_000_silon.jpg)";
                         nodeObj.style.backgroundPosition = bplft + "px -10px";
                     }
                     else if(direction == "rht")
                     {
                         nodeObj.style.backgroundImage = "url(images/rht_000_c00_silon.jpg)";
                         nodeObj.style.backgroundPosition = bplft + "px -10px";
                     }
                }
            }
        }
    }
}

