﻿var isOpera = navigator.userAgent.indexOf("Opera") > -1; 
var isIE = navigator.userAgent.indexOf("MSIE") > 1 && !isOpera; 
var isMoz = navigator.userAgent.indexOf("Mozilla/5.") == 0 && !isOpera;


function Hreflnk(page)
{
    document.location = page;
}
function addToList(id)
{
    theForm.lid.value = id;
    if(theForm.pageAction)theForm.pageAction.value = "default";
    theForm.submit();
}
function PopWindow(width, height, url, name)
{
	popUp = parent.window.open(url,name, 'width=' + width + ',height=' + height + ',scrollbars=yes'); 
	popUp.moveTo(screen.width/2-(width/2),screen.height/2-(height/2));
	popUp.focus();
}
function Paging(str)
{
    theForm.pageAction.value = str;
    theForm.submit();
}
function viewDetails(id)
{
    theForm.id.value = id;
    theForm.action = "Details.aspx";
    theForm.submit();
}
function FlashSelect(x,y)
{
    var obj = theForm.ctl00$CntSearch1$dlCats;
    var obj2 = theForm.ctl00$CntSearch1$dlMain;
    var obj3 = theForm.ctl00$CntSearch1$txtSearch;
        
    if(obj){
        for(var i = 0; i < obj.length;i++){
            if(obj.options[i].value==x)
            {
                obj.selectedIndex = i;
                theForm.submit();
            }
        }
    }
    if(obj2 && y>0 && x==0){
        for(var i = 0; i < obj2.length;i++){
            if(obj2.options[i].value==y)
            {
                obj2.selectedIndex = i;
                theForm.submit();
            }
        }
    }
    if(y==0&&x==0)
    {
        obj3.value = ' ';
        theForm.submit();
    }
}
function ShowMap(objName1,objName2)
{
    var target1 = document.getElementById(objName1);
    var target2 = document.getElementById(objName2);
    
    target1.style.display = "inline"
    target2.style.display = "none"
    //target1.style.display = "block"
}
// Telephone  Masking
var oFin = Object("fin"); // Global
   function EventManager(oTextbox, oEvent)
   {
       if(oEvent != "39" && oEvent != "37" && oFin.value!=='true' ){
            RebuildMask(oTextbox);
            MaskActions(oTextbox, oEvent);
       }else if(oEvent != "8" && oEvent != "46" && oEvent != "39" && oEvent != "37" )
       {
            oFin.value!=='false';
            RebuildMask(oTextbox);
            MaskActions(oTextbox, oEvent);
       }
   }
   function MaskActions(oTextbox, oEvent)
   {
        if(setRanges(oTextbox,1,4,3)){return;}//Area Code
        else if(setRanges(oTextbox,5,8,3)){return;}//Exchange Code
        else if(setRanges(oTextbox,9,13,4)){return;}//Number
        else {oFin.value='true';} // completed
   }
   function RebuildMask(oTextbox)
   {
        var myMask = '(___)___-____';
        var container;
        var tmp = '';
        var output = '';
        var j = 0;
        var s = oTextbox.value;

        for (var i = 0; i < myMask.length;i++)
        {
            container = myMask.substring(i, i + 1);
            for (j; j < s.length; j++)
            {
               if(s.substring(j, j + 1)!=")"&&
                  s.substring(j, j + 1)!="("&&
                  s.substring(j, j + 1)!="-")
                  {
                     tmp = s.substring(j, j + 1);
                     j += 1;
                     break;
                  }
                  else
                  {
                    tmp = "_";
                    j += 1;
                    break;
                  }
            }                
            if (container == "_")
            {
                if(tmp.length==0)
                    tmp = "_";
                
                output += tmp;
                
                tmp = "_";
            }
            else
            {
                output += container;
            }
        }
        oTextbox.value = output;
   }
   function setRanges(oTextbox,iStart,iEnd,iLength)
   {
        var iSpaceChar = 0;
        if (isIE) { 
           var oRange = oTextbox.createTextRange();
           oRange.moveStart("character", iStart); 
           oRange.moveEnd("character",  iEnd - oTextbox.value.length);
           var sTxt = oRange.text;
           
           for(var i=0;i<sTxt.length;i++)
           {
                if(sTxt.substring(i,i+1)=='_')
                {
                    iSpaceChar = iSpaceChar + 1
                }
           }
           if(iSpaceChar!=sTxt.length&&iSpaceChar!=0)
           {
                oRange.moveStart("character", iLength - iSpaceChar);
           }
           
           if(replaceChars(sTxt)==""||replaceChars(sTxt).length<iLength)
           {
                oRange.select();
                return true;
           }
           
        }        
        return false;
   }
   function replaceChars(entry) {
        out = "_"; // replace this
        add = ""; // with this
        temp = "" + entry; // temporary holder

        while (temp.indexOf(out)>-1) {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
        }
        return temp;
    }
    function IsCellNo(sText)
    {
       var ValidChars = "0123456789()-";
       var IsNumber=true;
       var Char;
       
       for (i = 0; i < sText.length && IsNumber == true; i++) 
          { 
          Char = sText.charAt(i); 
          if (ValidChars.indexOf(Char) == -1) 
             {
             IsNumber = false;
             }
          }
       return IsNumber;
   }