// JavaScript Document

function removeByElement(arrayName,arrayElement)
 {
    for(var i=0; i<arrayName.length;i++ )
     { 
        if(i == arrayElement)
            arrayName.splice(i,1); 
      } 
  }
  
function getCaret(el) { 
  if (el.selectionStart) { 
    return el.selectionStart; 
  } else if (document.selection) { 
    el.focus(); 

    var r = document.selection.createRange(); 
    if (r == null) { 
      return 0; 
    } 

    var re = el.createTextRange(), 
        rc = re.duplicate(); 
    re.moveToBookmark(r.getBookmark()); 
    rc.setEndPoint('EndToStart', re); 

    return rc.text.length; 
  }  
  return 0; 
}



function addTextString(destid,newVal)
{   
  var txtObj = document.getElementById(destid); 
  var curPos = getCaret(txtObj);
  
  txtObj.value = txtObj.value.substring(0,curPos) + newVal + txtObj.value.substring(curPos);    
  txtObj.scrollTop = txtObj.scrollHeight;
  
  setSelRange(txtObj,curPos + newVal.length,curPos + newVal.length);
}

function addTextItem(que,itemstring,desttag,defaultval,destid,hidesuffix,single)
{
  var target = document.getElementById(destid);
  
  var curPos = getCaret(target);
  
  if(target != null)
  {
   var slorig = (target.value).substring(target.selectionStart,target.selectionEnd); 
      
   if(hidesuffix)
    var rtnUrl = prompt(que,'');
   else
    var rtnUrl = prompt(que,defaultval);
   
   if(rtnUrl != null && rtnUrl != defaultval)
   { 
     if(desttag.length == 0)
     {
       if(hidesuffix)
        var itemadd = '[' + itemstring + '' + desttag + '="' + defaultval + rtnUrl + '"]';
       else
        var itemadd = '[' + itemstring + '' + desttag + '="' + rtnUrl + '"]';
     }
     else
     {
       if(hidesuffix)
        var itemadd = '[' + itemstring + ' ' + desttag + '="' + defaultval + rtnUrl + '"]';
       else
        var itemadd = '[' + itemstring + ' ' + desttag + '="' + rtnUrl + '"]';     
     }
         
    if(slorig.length == 0 && !single)
     var sl = prompt("Enter " + itemstring + " text",rtnUrl);
    else
     var sl = slorig;
      
     if(!single)
      itemadd += sl + '[/' + itemstring + ']';
     else
      itemadd += '[/' + itemstring + ']';
    
    //TAKE CARE OF WIDTH REPLACES FOR YOUTUBE VIDEOS
    if(itemstring == 'YOUTUBE')
    {
    //var regex =  new RegExp(strA,"g");     
    //return text.replace(regex , strB );
    
      var regex =  new RegExp("width=\"[0-9]+\"","g");     
      itemadd =  itemadd.replace(regex , "width=\"640\"");
      
      var regex =  new RegExp("WIDTH=\"[0-9]+\"","g");     
      itemadd =  itemadd.replace(regex , "WIDTH=\"640\"");
      
      var regex =  new RegExp("height=\"[0-9]+\"","g");     
      itemadd =  itemadd.replace(regex , "height=\"385\"");
      
      var regex =  new RegExp("HEIGHT=\"[0-9]+\"","g");     
      itemadd =  itemadd.replace(regex , "HEIGHT=\"385\"");                        
    }
    
    if(slorig.length == 0)
    {
     target.value = target.value.substring(0,curPos) + itemadd + target.value.substring(curPos);
    }
    else
     target.value = target.value.substring(0,curPos) + itemadd + (target.value.substring(curPos + slorig.length));

     var lengthIn = 3 + itemstring.length + desttag.length;
     
     if(hidesuffix)
      setSelRange(target,curPos + lengthIn,curPos + lengthIn + rtnUrl.length + defaultval.length);          
     else
      setSelRange(target,curPos + lengthIn,curPos + lengthIn + rtnUrl.length);
   }
  }
}

function doUrlEncode(valuein)
{
 try
 {
    var re = new RegExp('\\&','g');
    valuein = valuein.replace(re,'%26');
  
    re = new RegExp('\\#','g');
    valuein = valuein.replace(re,'%23');
  
    re = new RegExp('\\$','g');
    valuein = valuein.replace(re,'%24');
  
    re = new RegExp('\\+','g');
    valuein = valuein.replace(re,'%2B');
  
    re = new RegExp('\\,','g');
    valuein = valuein.replace(re,'%2C');
  
    re = new RegExp('\\:','g');
    valuein = valuein.replace(re,'%3A');
  
    re = new RegExp('\\=','g');
    valuein = valuein.replace(re,'%3D');
  
    re = new RegExp('\\?','g');
    valuein = valuein.replace(re,'%3F');
    
    re = new RegExp('\\@','g');
    valuein = valuein.replace(re,'%40');
  
    re = new RegExp('\\<','g');
    valuein = valuein.replace(re,'%3C');
  
    re = new RegExp('\\>','g');
    valuein = valuein.replace(re,'%3E');
 }
 catch(err) { }
  
  return valuein; 
}

function matchRegEx(pattern,value)
{
//[0-9]+[-][0-9]+
  var re = new RegExp(pattern);
    
  var rtn = value.match(re);  
  return rtn;
}

function getElementInDiv(parentid,childid)
{
 var parent = document.getElementById(parentid);
 
 if(parent != null)
 {
  var elements = parent.childNodes;
  
   for(var ii = 0; ii < elements.length; ii++)
   { 
    var varid = elements[ii].id;
    varid = replaceAll(varid, '\\\\"', '');
    varid = replaceAll(varid, '\\', '');                
    
    //alert(varid);
    
    if(elements[ii] != null && elements[ii].id != null && (varid == childid || '\\' + varid + '\\' == childid))
      return elements[ii];
   }    
 }
 
 return null; 
}

//Takes an HTML color and converts ot RGB 
function getRGB(colorcode)
{
 var R = colorcode.substring(0,2);
 var G = colorcode.substring(2,4);
 var B = colorcode.substring(4,7);
 
 var Ri = parseInt(R,16);
 var Gi = parseInt(G,16);
 var Bi = parseInt(B,16);
 
 var rtnArray = [Ri,Gi,Bi];
 
 return rtnArray;
}

function ascii_value (c)
{
	// restrict input to a single character
	c = c . charAt (0);

	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i)
	{
		// convert i into a 2-digit hex string
		var h = i . toString (16);
		if (h . length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape (h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}

//Checks for valid characters for passwords,usernames,etc
function checkvalidchars(value)
{
 for(var ii = 0; ii < value.length; ii++)
 {
  var thischar = value.substring(ii,ii+1);  
  
  if(ascii_value(thischar) < 48 ||
     (ascii_value(thischar) > 57 && ascii_value(thischar) < 65) ||
     (ascii_value(thischar) > 90 && ascii_value(thischar) < 97 && ascii_value(thischar) != 95) || 
     (ascii_value(thischar) > 122))
  {
   return false;
  }
  
 }
 
 return true;
}


//Convert all form elements into a parameter string
function getparamstr(formname)
{
 var formobj = document.getElementById(formname);
 
 var params = "";
 
 for(ii = 0; ii < formobj.elements.length; ii++)
 {
  if(formobj.elements[ii].name.length == 0)
   continue;
   
  if(ii > 0)
    params += '&';
  
  var theValue = doUrlEncode(formobj.elements[ii].value);  
  params += formobj.elements[ii].name + "=" + theValue;
 }
 
 return params;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  //alert('IN cookie (' + name + ': ' + value);
  //delete_cookie(name);
  document.cookie = "";
  
  var cookie_string = name + "=" + escape ( value );
  
  //alert(cookie_string);
  
  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}



function setSelRange(inputEl, selStart, selEnd) 
{ 
 if (inputEl.setSelectionRange) 
 { 
  inputEl.focus(); 
  inputEl.setSelectionRange(selStart, selEnd); 
 } 
 else if (inputEl.createTextRange) 
 { 
  var range = inputEl.createTextRange(); 
  range.collapse(true); 
  range.moveEnd('character', selEnd); 
  range.moveStart('character', selStart); 
  range.select(); 
 } 
}

function removearrayelement(array,element)
{
 var newarray = new Array();
 
 for(var ii = 0; ii < array.length; ii++)
 {
  if(ii != element)
   newarray.push(array[ii]);
 }
 
 return newarray;
}

function isnull(elementname)
{
 return ((document.getElementById(elementname)) == null);
}


//Verifies fields are field in properly
function verifyfieldsinner(idlist,labellist,number)
{
 if(number == null)
  number = false;
  
 var idarray = idlist.split(",");
 var lblarray = labellist.split(",");
 
 var pass = true;
 var errlist = "";
 
 for(var ii = 0; ii < idarray.length; ii++)
 {
  var thisobj = document.getElementById(idarray[ii]);
  
  if(!number && thisobj.innerHTML == '' || thisobj.innerHTML == null)
  {
   errlist += lblarray[ii] + ",";
   pass = false;
  }
  else if(number && (isNaN(thisobj.innerHTML) || thisobj.innerHTML == null))
  {   
   errlist += lblarray[ii] + ",";
   pass = false;
  }
  
 } 
 
 if(!pass)
 {  
  var errsplit = errlist.split(',');
  var strtotal = "";
  for(var jj = 0; jj < errsplit.length; jj++)
  {
   strtotal += errsplit[jj] + ",";
  }
  
  strtotal = strtotal.substring(0,strtotal.length - 2);    
  
  if(!number)
   var msg = "Please fill in the following fields: <br />" + strtotal;
  else
   var msg = "The following fields have missing or invalid values:<br />" + strtotal;
   
   displayPopupDiv('Alert','ajax/getpopup.php?message=' + msg + '&okcode=closePopupDiv(6);',450,165,6);    
      
 }
 
 return pass;
}

//Verifies fields are field in properly
function verifyfields(idlist,labellist,number,numbernotblank)
{
 if(number == null)
  number = false;

 if(numbernotblank == null)
  numbernotblank = false;
  
 var idarray = idlist.split(",");
 var lblarray = labellist.split(",");
 
 var pass = true;
 var errlist = "";
 var erridlist = "";
 
 for(var ii = 0; ii < idarray.length; ii++)
 {
  var thisobj = document.getElementById(idarray[ii]);
  
  if(!number && thisobj.value == '' || thisobj.value == null)
  {   
   errlist += lblarray[ii] + ",";
   erridlist += idarray[ii] + ",";
   pass = false;
  }
  else if(number && (isNaN(thisobj.value) || (numbernotblank && thisobj.value == '') || thisobj.value == null))
  {      
   errlist += lblarray[ii] + ",";
   erridlist += idarray[ii] + ",";
   pass = false;
  }
  
 } 
 
 if(!pass)
 {  
  //erridlist = erridlist.substring(erridlist,0,erridlist.length - 1);
  
  var errsplit = errlist.split(',');
  var erridsplit = erridlist.split(',');
  
  var strtotal = "";
  for(var jj = 0; jj < errsplit.length; jj++)
  {
   strtotal += errsplit[jj] + ",";
  }
  
  strtotal = strtotal.substring(0,strtotal.length - 2);    
  
  if(!number)
   var msg = "Please fill in the following fields: <br />" + strtotal;
  else
   var msg = "The following fields have missing or invalid values:<br />" + strtotal;
  
   var afterClose = "document.getElementById('" + erridsplit[0] + "').focus();document.getElementById('" + erridsplit[0] + "').select();";
   
   displayPopupDiv('Alert','ajax/getpopup.php?message=' + msg + '&okcode=closePopupDiv(6);' + afterClose,450,175,6);          
 }
 
 return pass;
}

//Verifies fields are field in properly
function verifyfieldslength(idlist,labellist,lengthval)
{
 var idarray = idlist.split(",");
 var lblarray = labellist.split(",");
 
 var pass = true;
 var errlist = "";
 
 for(var ii = 0; ii < idarray.length; ii++)
 {
  var thisobj = document.getElementById(idarray[ii]);
  
  if(thisobj.value == '' || thisobj.value == null || thisobj.value.length < lengthval)
  {
   errlist += lblarray[ii] + ",";
   pass = false;
  }
 } 
 
 if(!pass)
 {  
  var errsplit = errlist.split(',');
  var strtotal = "";
  for(var jj = 0; jj < errsplit.length; jj++)
  {
   strtotal += errsplit[jj] + ",";
  }
  
  strtotal = strtotal.substring(0,strtotal.length - 2);    
  
   var msg = "The following fields have missing or invalid values:<br />" + strtotal;
   
   displayPopupDiv('Alert','ajax/getpopup.php?message=' + msg + '&okcode=closePopupDiv(6);',450,165,6);    
      
 }
 
 return pass;
}


//Gets the selected value from a list
function getselectindex(elementname)
{
 if(elementname == null)
  return null;                        
  
 var measunit = document.getElementById(elementname);
 
 if(measunit == null)
  return null;
                                   
    for (var i=0; i < measunit.length; i++)
       {
        if (measunit[i].selected)
          {
           //alert(elementname + "=" + measunit[i].value);
           
           return i;
          }
       }      
}

//Gets the selected value from a list
function getselectvalue(elementname)
{
 if(elementname == null)
  return null;                        
  
 var measunit = document.getElementById(elementname);
 
 if(measunit == null)
  return null;
                                   
    for (var i=0; i < measunit.length; i++)
       {
        if (measunit[i].selected)
          {
           //alert(elementname + "=" + measunit[i].value);
           
           return measunit[i].value;
          }
       }      
}

//Remove a row from a table, clean and simple...
function removetablerow(tableid,rownum)
{
 try
 {
    var exTbl = document.getElementById(tableid);              
    exTbl.deleteRow(rownum);
 }
 catch(err) { } 
}

function setclickcolor(id,bgcolor,fcolor)
{
 element = document.getElementById(id);           
 element.style.backgroundColor = bgcolor;
 element.style.color = fcolor;
}

function replaceAll(text, strA, strB)
{
  try
  {
    var regex =  new RegExp(strA,"g");
     
    return text.replace(regex , strB );
  }
  catch(err)
  {
   return text;
  }    
}

function escRegularExpression(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}


function replaceSmilySymbolics(msg)
{      
 //TAKE CARE OF SMILEYS
 var smileyarray = new Array(
                      ':)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/smile.png',
                      ':D' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/laugh.png',
                      ':S' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/worried.png',
                      ':(' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/sad.png',
                      ':P' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/silly.png',
                      ':O' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/surprised.png',
                      ';)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/wink.png',
                      '8)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/geek.png',
                      '8|' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/cool.png',
                      '>:(' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/angry.png',
                      ':\\' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/shock.png',
                      ':\'(' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/cry1.png',
                      '3:)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/devilsmile.png',
                      '3:D' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/devillaugh.png',
                      'O:)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/angel.png',
                      '<3' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/love.png',
                      'I-)' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/sleep.png',
                      '*^^*' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/blush.png',
                      ':-#' + String.fromCharCode(18) +  './images/emoticon/mazes_mini2/zip.png'                            
                      );                    
 var smid=1;
 
 for(var ii = 0; ii < smileyarray.length; ii++)
 {      
  var smItem = smileyarray[ii];
  smsplit = smItem.split(String.fromCharCode(18));      
  
  var replItem = escRegularExpression(smsplit[0].toUpperCase());
  var replWith = "[img src='" + escRegularExpression(smsplit[1]) + "' /img]";
  
  //alert("|" + smsplit[0] + "|");
  msg = replaceAll(msg,replItem,replWith);
  
  replItem = escRegularExpression(smsplit[0].toLowerCase());
  replWith = "[img src='" + escRegularExpression(smsplit[1]) + "' /img]";
  
  //alert("|" + smsplit[0] + "|");
  msg = replaceAll(msg,replItem,replWith);
  
  smid++;
 }
 
 return msg;
}


function showProgressDialog(text)
{
    centerObject('loadingdiv',200,50);
    document.getElementById('loadingtext').innerHTML = text;
    setelementvisibilitys('loadingdiv',true);
    fadeitem('loadingdiv',0,80,10,0);
}
          
function getBrowserType()
{
 return navigator.appName; 
}

function pausecomp(millis)
{
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); }
  while(curDate-date < millis);
} 

function getStandardDate(inVal, longformat)
{  
 if(longformat == null)
  longformat = false;
  
 if(!longformat)
 { 
   var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
   var days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
 }
 else
 {
   var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'); 
 }
   
 var vYear = inVal.substring(0,4);
 var vMonth = inVal.substring(5,7);
 var vDay = inVal.substring(8);

 if(vMonth < 10)
  vMonth = vMonth.substring(1);
 
 vMonth = parseInt(vMonth) - 1;
 //alert(inVal);
 //alert(vYear);
 //alert("***" + parseInt(inVal.substring(5,7) + "***");
 //alert(vMonth);
 //alert(vDay);
 
 if(vDay < 10)
  vDay = vDay.substring(1);
     
 //alert(inVal.substring(5,7));
 
 var dateStr = months[vMonth] + " " + vDay + ", " + vYear;
 newDate = new Date(dateStr);
 
 return days[newDate.getDay()] + " " + dateStr;
}

function getDateTime()
{
 var d = new Date();
 var day = d.getDate();
 var year = d.getYear();
 var month = d.getMonth();
 var hours = d.getHours();
 var mins = d.getMinutes();
 var secs = d.getSeconds();

 month += 1;
 
 if(day < 10)
  day = "0" + day;

 if(month < 10)
  month = "0" + month;  

 if(mins < 10)
  mins = "0" + mins; 
 
 if(secs < 10)
  secs = "0" + secs; 
      
 return year + "-" + month + "-" + day + " " + hours + ":" + mins + ":" + secs;
}

function getMouseXY(e) {
  if(getBrowserType() == 'Microsoft Internet Explorer') { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  
  try
  {  
  document.Show.MouseX.value = tempX
  document.Show.MouseY.value = tempY
  }
  catch(err) { }
  
  return true
}

function centerObject(id,width,height)
{    
  document.getElementById(id).style.left = (document.body.clientWidth/2)-(width/2);
  
  var variance = 100;  
  
  if(height > document.body.clientHeight)
  {    
   height = document.body.clientHeight - 50;
   document.getElementById(id).style.height = height;
   
   if(id.indexOf('popupdiv') > -1)
   {
    if(id == 'popupdiv')
      var contentname = 'popupdivcontents';
    else
      var contentname = 'popupdivcontents' + id.substring(id.length - 1);
      
    //alert(contentname);
    //if(document.getElementById(contentname) != null)
    
    if(getBrowserType() == 'Microsoft Internet Explorer')
     document.getElementById(contentname).style.height = height - 30;
    else
     document.getElementById(contentname).style.height = height - 20;
   }
  }
   
  document.getElementById(id).style.top = document.body.scrollTop + (document.body.clientHeight/2) - (height / 2);
}

function closePopupDiv(divtype)
{
   if(divtype == null)
    divtype = '';
              
        
            
   var bodyitem = 'bodydiv';
   
   if(getBrowserType() == 'Microsoft Internet Explorer')   
    bodyitem = 'bodytable';    
        
   var height = document.getElementById('popupdiv' + divtype).style.height;      
   height = height.substring(0,height.lastIndexOf('px'));   
   
   //if(getBrowserType() != 'Microsoft Internet Explorer')
    //fadeitem('popupdiv' + divtype,100,0,-20,0);
  //else
    setelementvisibilitys('popupdiv' + divtype,false);
   
   if(divtype != '')
   {
      var divnum = parseInt(divtype);
      //alert(divnum);
      
      var ok = true;
      for(var stdivnum = divnum - 1; stdivnum >= 1; stdivnum--)
      {
       var divit = stdivnum;
       
       if(divit == 1)
        divit = '';
       
       if(document.getElementById('popupdiv' + divit).style.display == '')
       {
         if (window.getComputedStyle)                       
           var thisZIndex = document.defaultView.getComputedStyle(document.getElementById('popupdiv' + divit),null).getPropertyValue('z-index');   
         else
           var thisZIndex = document.getElementById('popupdiv' + divit).currentStyle['zIndex'];    
      
         var newZIndex = thisZIndex;
                
        ok = false;
        break;
       }
      }
      
      //alert('ok');
            
      
      if(ok)
      {
       //if(getBrowserType() != 'Microsoft Internet Explorer')
        //fadeitem('backgroundfilter',60,0,-10,0);
        
       disableBackgroundShield();          
      }
      else
       enableBackgroundShield(null,newZIndex);
   }
   else
   {
    //if(getBrowserType() != 'Microsoft Internet Explorer')
     //fadeitem('backgroundfilter',60,0,-10,0);
     
     disableBackgroundShield();   
   }
   
   /**
    if((document.getElementById('popupdiv2').style.display != '' &&
        document.getElementById('popupdiv3').style.display != '' &&
        document.getElementById('popupdiv4').style.display != '' && 
        document.getElementById('popupdiv5').style.display != '' &&
        document.getElementById('popupdiv6').style.display != '') ||
        divtype == '')
    { 
     fadeitem('backgroundfilter',60,0,-10,0);
     disableBackgroundShield();
    }
   **/
}

function displayPopupDivContent(title,contents,onclose,vwidth,vheight,divtype)
{
   if(divtype == null)
    divtype = '';
    
   //scroll(0,0);
   
   document.getElementById('closecode' + divtype).innerHTML = onclose;
   
   document.getElementById('contentsource' + divtype).innerHTML = contents.id;
   document.getElementById('popuptitle' + divtype).innerHTML = title;
   document.getElementById('popupdiv' + divtype).style.width = vwidth;
   document.getElementById('popupdiv' + divtype).style.height = vheight;
   
   if(getBrowserType() == 'Microsoft Internet Explorer')
    document.getElementById('popupdivcontents' + divtype).style.width = vwidth-4;
   else
    document.getElementById('popupdivcontents' + divtype).style.width = vwidth-0;
   
   document.getElementById('popupdivcontents' + divtype).style.height = vheight-35;
   
   //document.getElementById('popupdivcontents').style.width = vwidth;
         
   setelementvisibilitys('popupdiv' + divtype,true); 
   
   /*
   if(getBrowserType() == 'Microsoft Internet Explorer')                          
    rollItemVerticallyS('popupdiv',0,vheight,10,0);
   else
    rollItemVerticallyS('popupdiv',0,vheight,10,5);
    */

    
  //fadeitem('popupdiv' + divtype,0,100,20,0);    
   
   //if(getBrowserType() == 'Microsoft Internet Explorer')
   // fadeitem('bodytable',100,20,-10,0);

   var thisZIndex = document.getElementById('popupdiv' + divtype).style.zIndex;
   var newZIndex = thisZIndex - 1;
   
   enableBackgroundShield(null);
   //fadeitem('backgroundfilter',0,60,10,0);
   
   //document.getElementById('popupdivcontents' + divtype).innerHTML = contents;
   
   var node = document.getElementById('popupdivcontents' + divtype);
   
    while (node.hasChildNodes()) {
        node.removeChild(node.lastChild);
    }
   
   var helperobj = document.getElementById(contents.id + "_help");
   
   if(helperobj != null)
   {
    contents.innerHTML = helperobj.innerHTML + contents.innerHTML; 
   }
    
   node.appendChild(contents);
   
   centerObject('popupdiv' + divtype,vwidth,vheight);  
   //setTimeout("getAjaxValue('" + contents + "','popupdivcontents')",1000);
}

function displayPopupDiv(title,contents,vwidth,vheight,divtype,afterload)
{
  var contobj = document.getElementById('popupdivcontents' + divtype);

  if(contobj != null)
   contobj.innerHTML = "";
   
   if(divtype == null)
    divtype = '';
    
   //scroll(0,0);
   
   document.getElementById('contentsource' + divtype).innerHTML = contents;
   document.getElementById('popuptitle' + divtype).innerHTML = title;
   document.getElementById('popupdiv' + divtype).style.width = vwidth;
   document.getElementById('popupdiv' + divtype).style.height = vheight;

   if(getBrowserType() == 'Microsoft Internet Explorer')
    document.getElementById('popupdivcontents' + divtype).style.width = vwidth-4;
   else
    document.getElementById('popupdivcontents' + divtype).style.width = vwidth-0;
   
   document.getElementById('popupdivcontents' + divtype).style.height = vheight-35;

   //document.getElementById('popupdivcontents').style.width = vwidth;
   
   centerObject('popupdiv' + divtype,vwidth,vheight);
   
   setelementvisibilitys('popupdiv' + divtype,true); 
   
   /*
   if(getBrowserType() == 'Microsoft Internet Explorer')                          
    rollItemVerticallyS('popupdiv',0,vheight,10,0);
   else
    rollItemVerticallyS('popupdiv',0,vheight,10,5);
    */
   
   //if(getBrowserType() != 'Microsoft Internet Explorer') 
   // fadeitem('popupdiv' + divtype,0,100,15,0);    

   if (window.getComputedStyle)                       
     var thisZIndex = document.defaultView.getComputedStyle(document.getElementById('popupdiv' + divtype),null).getPropertyValue('z-index');   
   else
     var thisZIndex = document.getElementById('popupdiv' + divtype).currentStyle['zIndex'];    
   
   var newZIndex = thisZIndex;
          
   enableBackgroundShield(null,newZIndex);
   
   //if(getBrowserType() != 'Microsoft Internet Explorer')
   // fadeitem('backgroundfilter',0,60,10,0);
   
   //document.getElementById('popupdivcontents' + divtype).height = vheight-100 + "px";   
   
   if(afterload != null)
    var vGetAjaxVal = new getAjaxValue(contents,'popupdivcontents' + divtype,afterload);
   else
    var vGetAjaxVal = new getAjaxValue(contents,'popupdivcontents' + divtype);      
   
   //setTimeout("getAjaxValue('" + contents + "','popupdivcontents')",1000);
}

function enableBackgroundShield(suffix,zIndex)
{
 if(suffix == null)
  suffix = "";
 else
  suffix = "_" + suffix;
  
if(zIndex == null || zIndex < 0)
 zIndex = 1;
 
  setelementvisibilitys('backgroundfilter' + suffix,true);
  
  var bgelement = document.getElementById('backgroundfilter' + suffix);
  
  bgelement.style.width = screen.width+200;
  bgelement.style.height = document.body.scrollHeight+document.body.scrollTop+100; 
  bgelement.style.backgroundColor='#000000';
  setItemOpacity('backgroundfilter' + suffix,60);
  bgelement.style.zIndex = zIndex;
  
  document.body.style.overflow='hidden';
  
  var objHeadLink = document.getElementById('headerlink');
  objHeadLink.style.display = 'none';
}

function disableBackgroundShield(suffix)
{
 if(suffix == null)
  suffix = "";
 else
  suffix = "_" + suffix;


  var bgelement = document.getElementById('backgroundfilter' + suffix);
    
  setelementvisibilitys('backgroundfilter' + suffix,false);
  document.body.style.overflow='scroll';
  
  var objHeadLink = document.getElementById('headerlink');
  objHeadLink.style.display = '';
}

function rollItemVerticallyS(id,from,to,increment,speed)
{
  setItemHeightS(id,from,from,to,increment,speed);
}

function rollItemVertically(id,idp,from,to,increment,speed)
{
  setItemHeight(id,idp,from,from,to,increment,speed);
}

function setHeight(id,value)
{
 if(document.getElementById(id) != null)
  document.getElementById(id).style.height = value;
}

function setItemHeightS(id,value,from,to,increment,speed)
{    
    document.getElementById(id).style.height = value;                 
    
    if(value < 0)
      value = 0;
    
    if( (from < to && value < to) || (from > to && value > to))
      setTimeout("setItemHeightS('" + id + "'," + (value+increment) + "," + from + "," + to + "," + increment + "," + speed + ")",speed);
      
    if(to < from && value == 0)
    {
     //setelementvisibilitys(id,false);
    }
}

function setItemHeight(id,idp,value,from,to,increment,speed)
{    
    document.getElementById(id).style.height = value;                 
    
    if( (from < to && value < to) || (from > to && value > to) )
      setTimeout("setItemHeight('" + id + "','" + idp + "'," + (value+increment) + "," + from + "," + to + "," + increment + "," + speed + ")",speed);
    else
     setelementvisibilitys(idp,true);
       
    if(to < from && value <= 0)
    {    
     setelementvisibilitys(id,false);
     setelementvisibilitys(idp,false);
    }         
}

function rollItemHorizontally(id,from,to,increment,speed)
{
  setItemWidth(id,from,from,to,increment,speed);
}

function RGBtoHex(R,G,B) 
{
 return toHex(R)+toHex(G)+toHex(B)
}

function toHex(N) 
{
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}

function setMenuColors(r, g, b)
{
 var fact = 12;
 
 for(ii = 1; ii < 30; ii++)
 {
    var itemname = 'menuitem_' + ii;
    var menuobj = document.getElementById(itemname);
    
    if(menuobj == null)
     break;
    
    var redval = r+(fact*ii);
    var greenval = g+(fact*ii);     
    var blueval = b+(fact*ii);
    
    var nowclr = RGBtoHex(r,g,b);  
    menuobj.style.backgroundColor=nowclr;//"#0066DD";
 }
}

function menuSet(item,mode,round)
{   
  if(round == null)
   round = 1;
   
  var itemname = 'menuitem_' + item;
  var menuobj = document.getElementById(itemname);
  
  var fadespeed=75;
  var delay=75;
  
  //First time around go quick
  if(round > 1)
  {
   delay += 100;
  }
  else //slow down and smooth out now
  {
   delay = 0;
   fadespeed = 0;
  }
   
  var stdelay = delay;
  
  var fact = 12;
  
  var startblue = 100;
  
  var inmode = mode;
  
  if(menuobj != null)
  {
    itemcount = item + 1;
    var blueval = startblue+(fact*itemcount);
      
    var nowclr = RGBtoHex(0,0,blueval);
    
    //if(menuobj != null)     
    // menuobj.style.backgroundColor=nowclr;//"#0066DD";
        
    if(mode == 'DOWN')
      fadeitem(itemname,110,100,-5,fadespeed);
    else
      fadeitem(itemname,100,110,5,fadespeed);
    
     inmode = mode;          
   }
   else
   {

     if(inmode == 'UP')
      inmode = 'DOWN';
     else
      inmode = 'UP';
     
     itemcount = 1;     
     stdelay = 0;
     
     round++;
   }
   
   setTimeout("menuSet(" + itemcount + ",'" + inmode + "'," + round + ")",stdelay);          
}

function menuFade(item,mode,round)
{   
   
  if(round == null)
   round = 1;
   
  var itemname = 'menuitem_' + item;
  var menuobj = document.getElementById(itemname);
  
  var fadespeed=75;
  var delay=75;
  
  //First time around go quick
  if(round > 1)
  {
   delay += 100;
  }
  else //slow down and smooth out now
  {
   delay = 0;
   fadespeed = 0;
  }
   
  var stdelay = delay;
  
  var fact = 12;
  
  var startblue = 100;
  
  var inmode = mode;
  
  if(menuobj != null)
  {
    itemcount = item + 1;
    var blueval = startblue+(fact*itemcount);
      
    var nowclr = RGBtoHex(0,0,blueval);
    
    //if(menuobj != null)     
    // menuobj.style.backgroundColor=nowclr;//"#0066DD";
        
    if(mode == 'DOWN')
      fadeitem(itemname,100,20,-5,fadespeed);
    else
      fadeitem(itemname,20,100,5,fadespeed);
    
     inmode = mode;          
   }
   else
   {

     if(inmode == 'UP')
      inmode = 'DOWN';
     else
      inmode = 'UP';
     
     itemcount = 1;     
     stdelay = 0;
     
     round++;
   }
         
    setTimeout("menuFade(" + itemcount + ",'" + inmode + "'," + round + ")",stdelay);
}


function setItemWidth(id,value,from,to,increment,speed)
{    
    if(getBrowserType() != 'Microsoft Internet Explorer')
      speed += 10;
      
    document.getElementById(id).style.width = value;            
 
    centerObject(id);
    
    if( (from < to && value < to) || (from > to && value > to) )
      setTimeout("setItemWidth('" + id + "'," + (value+increment) + "," + from + "," + to + "," + increment + "," + speed + ")",speed);
      
    if(to < from && value == 0)
     setelementvisibilitys(id,false);
}

function setItemOpacity(id,value)
{
    document.getElementById('id').style.opacity = value;
    document.getElementById('id').style.filter  = "alpha(opacity=" + value + ")";
}

//Fade the body opacity
function fadebody(from,to,increment,speed)
{
  setBodyOpacity(from,from,to,increment,speed);  
}

function setBodyOpacity(value,from,to,increment,speed)
{
    document.body.style.opacity = value;
    document.body.style.filter  = "alpha(opacity=" + value + ")";
    
    if( (from < to && value < to) || (from > to && value > to) )
      setTimeout("setBodyOpacity(" + (value+increment) + "," + from + "," + to + "," + increment + "," + speed + ")",speed);     
}

//Fade an item opacity
function fadeitem(id,from,to,increment,speed,hide)
{
 if(hide == null)
  hide = true;
  
  setItemOpacity(id,from,from,to,increment,speed,hide);  
}

function setItemOpacity(id,value,from,to,increment,speed,hide)
{
    //if(getBrowserType() != 'Microsoft Internet Explorer')
      //speed += 8;
      
    document.getElementById(id).style.opacity = value/100;    
    document.getElementById(id).style.filter  = "alpha(opacity=" + value + ");";        
    
    if( (from < to && value < to) || (from > to && value > to) )
      setTimeout("setItemOpacity('" + id + "'," + (value+increment) + "," + from + "," + to + "," + increment + "," + speed + "," + hide + ")",speed);
      
    if(to < from && value == 0)
    {     
     
     if(id == 'backgroundfilter')          
      disableBackgroundShield();
     
     if(hide)
      setelementvisibilitys(id,false);
    }           
}


function setInnerText(id,text)
{
 if(document.getElementById(id) != null)
  document.getElementById(id).innerHTML = text;
}
     
function setelementvisibilitys(id,visible)
{
 element = document.getElementById(id);
 
 if(element == null)
  return;
  
 if(!visible)
  element.style.display = "none";
 else
 {
  element.style.display = "";
  
  //document.getElementById('searchtxt').focus();            
 }
}
                  
function setelementvisibility(id)
{
 element = document.getElementById(id);
 
 if(element.style.display == "")
  element.style.display = "none";
 else
 {
  element.style.display = "";
  
  if(document.getElementById('searchtxt') != null)
    document.getElementById('searchtxt').focus();
 }
}

function isFieldNumber(id)
{
 return !isNaN(id.value); 
}

//Gets the value inside value attribute
function getValue(innerHTML)
{

 if(getBrowserType() == 'Microsoft Internet Explorer')
 {
   var fIdx = innerHTML.lastIndexOf("value=");
   var lIdx = innerHTML.lastIndexOf("name=");
 }
 else
 {
   var fIdx = innerHTML.indexOf("value=")+1;
   var lIdx = innerHTML.indexOf("onkeyup=")-1; 
 }
 
 var rtnStr = innerHTML;
 
 if(fIdx > -1)
  rtnStr = rtnStr.substring(fIdx + 6,lIdx - 1);
 
 return rtnStr;
}

//Gets the value inside value attribute
function getID(innerHTML)
{
 if(getBrowserType() == 'Microsoft Internet Explorer')
 {
   var fIdx = innerHTML.lastIndexOf("id=");
   var lIdx = innerHTML.lastIndexOf("onkeyup=");
 }
 else  
 {
   var fIdx = innerHTML.lastIndexOf("id=")+1;
   var lIdx = innerHTML.lastIndexOf("name=")-1; 
 }
 
 
 var rtnStr = innerHTML;
 
 if(fIdx > -1)
  rtnStr = rtnStr.substring(fIdx + 3,lIdx - 1);
 
 return rtnStr.substring(1);
}


