
function toggle_div(id)
{
    if(document.getElementById(id).style.display=='none')
    {
         document.getElementById(id).style.display = "inline";
    }else{
         document.getElementById(id).style.display = "none";
    }
}

function ShowHide(dvTab, dvContent)
{
    var c = document.getElementById(dvContent);
    if (c != null && c.style.display == "inline") {
        // already showing, don't do anything
        //document.getElementById(myDiv).style.display = "none";
    } else {
        var ck = null;
        // show and hide the rest
        var ck = document.getElementById('tb1xx')
        if (ck)
            ck.style.display = "none";
        ck = document.getElementById('tb2xx');
        if (ck)
            ck.style.display = "none";
        ck = document.getElementById('tb3xx');
        if (ck)
            ck.style.display = "none";
        ck = document.getElementById('tb4xx');
        if (ck)
            ck.style.display = "none";
        ck = document.getElementById('tb5xx');
        if (ck)
            ck.style.display = "none";
        ck = document.getElementById('tb6xx');
        if (ck)
            ck.style.display = "none";

        ck = document.getElementById('FeatureTab1');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";
        ck = document.getElementById('FeatureTab2');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";
        ck = document.getElementById('FeatureTab3');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";
        ck = document.getElementById('FeatureTab4');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";
        ck = document.getElementById('FeatureTab5');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";
        ck = document.getElementById('FeatureTab6');
        if (ck)
            ck.style.backgroundColor = "#ebebeb";

        ck = document.getElementById(dvContent);
        if (ck)
            ck.style.display = "inline";
        ck = document.getElementById(dvTab);
        if (ck)
            ck.style.backgroundColor = "#adadad";

        var fv = document.getElementById('feature_view');
        if (fv)
            fv.value=dvTab;
        var tiv = document.getElementById('tab_in_view');
        if (tiv)
            tiv.value=dvContent;
    }
}

// below is very portable

function getRefToDiv(divID,oDoc) {
  if( document.getElementById ) {
    return document.getElementById(divID); }
  if( document.all ) {
    return document.all[divID]; }
  if( !oDoc ) { oDoc = document; }
  if( document.layers ) {
    if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
      //repeatedly run through all child layers
      for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
        //on success, return that layer, else return nothing
        y = getRefToDiv(divID,oDoc.layers[x].document); }
    return y; } }
  return false;
}

function set_cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
    /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function xy()
{
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
}

}



var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
phonevalue2 = ParseChar(object.value, zChar);
}

function valid_format_ku(object,e,etype)
{
    switch(etype){
        case 'phone':
        backspacerUP(object,e);
        break;
    }
}

function valid_format_kd(object,e,etype)
{
    switch(etype){
        case 'phone':
        backspacerDOWN(object,e);
        break;
    }
}


function backspacerUP(object,e) {
        if(e){
                e = e
        } else {
                e = window.event
        }
        if(e.which){
                var keycode = e.which
        } else {
                var keycode = e.keyCode
        }

        ParseForNumber1(object)

        if(keycode >= 48){
                ValidatePhone(object)
        }
}

function backspacerDOWN(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}
ParseForNumber2(object)
}

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp;

} else if(p.length >= 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
    if (sChar.length == null)
    {
        zChar = new Array(sChar);
    }
    else zChar = sChar;

    for (i=0; i<zChar.length; i++)
    {
        sNewStr = "";

        var iStart = 0;
        var iEnd = sStr.indexOf(sChar[i]);

        while (iEnd != -1)
        {
            sNewStr += sStr.substring(iStart, iEnd);
            iStart = iEnd + 1;
            iEnd = sStr.indexOf(sChar[i], iStart);
        }

        sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
        sStr = sNewStr;
    }

return sNewStr;
}



function visable_height()
{

 var viewportwidth;
 var viewportheight;

 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }else{ // old ie
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

    return viewportheight;
}

function float_footer_div()
{
        /*
         * float the bottom footer, this might not be that portable.
         */
         var noPx = document.childNodes ? 'px' : 0;
         var bdy = document.getElementById('bdy_id');
         var hdr = document.getElementById('hdr_id');
         var footer = document.getElementById('ftr_id');
         var height = visable_height();
         var body_height = bdy.offsetHeight;
         var hdr_height = hdr.offsetHeight;
         var ftr_height = footer.offsetHeight;
         var tot_height = body_height + hdr_height + ftr_height;
         //alert('body_height: '+body_height+' height: '+height);
         if(tot_height < height - 10){
                footer.style.top = height - 25;
                footer.style.position='absolute';
         }
        // alert('Height: '+height+' body: ' + body_height);
        // bdy.style.height = -80-221;

}

function div_cpy(a,b)
{
    parent.document.all(b).innerHTML = document.all(a).innerHTML;
}

function open_pop_win(page,width,height)
{
     var ourl;
     ourl = page;
     var winl = (screen.width - width) / 2;
     var wint = (screen.height - height) / 2;
     winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+'resizable=0'
    //'Details', 'iframe',ourl,'Dialog Box','width='+width+',height='+height+',center=1,resize=0,scrolling=0'
    window.open(ourl,'details',winprops);
}

function  write_help_icon(val)
{

     w=500;
     h=400;
     var winl = (screen.width - w) / 2;
     var wint = (screen.height - h) / 2;
     winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+'resizable=0'
     window.open("index.php?mod=help&hid="+val, "Window2",winprops);

}
