// JavaScript Document
if (document.images) {
	/* Homepage */
    pbxdiy_over       = new Image();
    pbxdiy_over.src   = "images/price-diy-over.gif" ;
    pbxdiy     = new Image() ;
    pbxdiy.src = "images/price-diy.gif" ;

    pbxhome_over       = new Image();
    pbxhome_over.src   = "images/price-homeoffice-over.gif" ;
    pbxhome     = new Image() ;
    pbxhome.src = "images/price-homeoffice.gif" ;

    pbxsmallbiz_over       = new Image();
    pbxsmallbiz_over.src   = "images/price-smallbusiness-over.gif" ;
    pbxsmallbiz     = new Image() ;
    pbxsmallbiz.src = "images/price-smallbusiness.gif" ;

    pbxlargecorp_over       = new Image();
    pbxlargecorp_over.src   = "images/price-largecorp-over.gif" ;
    pbxlargecorp     = new Image() ;
    pbxlargecorp.src = "images/price-largecorp.gif" ;
	
	/* How it works */
	pbx_over = new Image();
	pbx_over.src = "images/icon-pbx-on.gif";
	pbx = new Image();
	pbx.src = "images/icon-pbx.gif";

	ivr_over = new Image();
	ivr_over.src = "images/icon-ivr-on.gif";
	ivr = new Image();
	ivr.src = "images/icon-ivr.gif";

	ext_over = new Image();
	ext_over.src = "images/icon-extension-on.gif";
	ext = new Image();
	ext.src = "images/icon-extension.gif";

	voicemail_over = new Image();
	voicemail_over.src = "images/icon-voicemail-on.gif";
	voicemail = new Image();
	voicemail.src = "images/icon-voicemail.gif";

	followme_over = new Image();
	followme_over.src = "images/icon-followme-on.gif";
	followme = new Image();
	followme.src = "images/icon-followme.gif";

	block_over = new Image();
	block_over.src = "images/icon-block-on.gif";
	block = new Image();
	block.src = "images/icon-block.gif";

	screening_over = new Image();
	screening_over.src = "images/icon-screening-on.gif";
	screening = new Image();
	screening.src = "images/icon-screening.gif";

	recording_over = new Image();
	recording_over.src = "images/icon-recording-on.gif";
	recording = new Image();
	recording.src = "images/icon-recording.gif";

	ringgroup_over = new Image();
	ringgroup_over.src = "images/icon-group-on.gif";
	ringgroup = new Image();
	ringgroup.src = "images/icon-group.gif";

	conference_over = new Image();
	conference_over.src = "images/icon-conference-on.gif";
	conference = new Image();
	conference.src = "images/icon-conference.gif";

}
function buttondown( imgname )
{
    if (document.images) {
      document[ imgname ].src = eval( imgname + ".src" );
    }
}
function buttonup ( imgname )
{
    if (document.images) {
      document[ imgname ].src = eval( imgname + "_over.src" );
    }
}

function show(layerName) { 
	document.getElementById(layerName).style.display = '';
} 

function hide(layerName) { 
	document.getElementById(layerName).style.display = 'none';
}

function toggleTab( ID ) {
	if (document.getElementById && document.getElementsByTagName){
	  var objstyle = document.getElementById(ID);
	  if(objstyle.className == "menutab-item" || objstyle.className == "") {
        objstyle.className = "menutab-selected"; 
	  } else {
        objstyle.className = "menutab-item"; 
      }
    }
}

function toggleDisplay( ID ) {
	if (document.getElementById && document.getElementsByTagName){
	  var objstyle = document.getElementById(ID);
	  if(objstyle.className == "hide" || objstyle.className == "") {
        objstyle.className = "show"; 
	  } else {
        objstyle.className = "hide"; 
      }
    }
}

function ToggleDLopen(){  //we open all of them
	if (document.getElementById('pbx-forwarding')) {
  	  var pbxDD=document.getElementById('pbx-forwarding').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-forwarding').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	if (document.getElementById('pbx-caller')) {
  	  var pbxDD=document.getElementById('pbx-caller').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-caller').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	if (document.getElementById('pbx-ivr')) {
  	  var pbxDD=document.getElementById('pbx-ivr').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-ivr').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	if (document.getElementById('pbx-voicefax')) {
  	  var pbxDD=document.getElementById('pbx-voicefax').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-voicefax').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	if (document.getElementById('pbx-advanced')) {
  	  var pbxDD=document.getElementById('pbx-advanced').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-advanced').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	if (document.getElementById('pbx-others')) {
  	  var pbxDD=document.getElementById('pbx-others').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-others').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'show';
	  }
	}
	return false;
}
function ToggleDLclose(){//we close all of them	
	if (document.getElementById('pbx-forwarding')) {
  	  var pbxDD=document.getElementById('pbx-forwarding').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-forwarding').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	if (document.getElementById('pbx-caller')) {
  	  var pbxDD=document.getElementById('pbx-caller').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-caller').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	if (document.getElementById('pbx-ivr')) {
  	  var pbxDD=document.getElementById('pbx-ivr').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-ivr').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	if (document.getElementById('pbx-voicefax')) {
  	  var pbxDD=document.getElementById('pbx-voicefax').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-voicefax').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	if (document.getElementById('pbx-advanced')) {
  	  var pbxDD=document.getElementById('pbx-advanced').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-advanced').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	if (document.getElementById('pbx-others')) {
  	  var pbxDD=document.getElementById('pbx-others').getElementsByTagName('dd');
  	  var pbxDT=document.getElementById('pbx-others').getElementsByTagName('dt');
	  for(var i=0;i<pbxDT.length;i++){
        pbxDD[i].className = 'hide';
	  }
	}
	return false;
}

function toggleInit() {
	if (document.getElementById && document.getElementsByTagName){			
	  var ToggleON = document.getElementById('toggleOn');
	  var ToggleOFF = document.getElementById('toggleOff');	
	  if (ToggleON && ToggleOFF){ // Show All - Hide All "links"
	    ToggleON.onclick = ToggleDLopen;
	    ToggleON.title = "Show All Details";
	    ToggleON.href = "#";		
	    ToggleOFF.onclick = ToggleDLclose;	
	    ToggleOFF.title = "Hide All Details";
	    ToggleOFF.href = "#";
	  }
	  ToggleDLclose();
	}
}

function fetchnumber(prefix) {
	var prefix = (prefix == null) ? 888 : prefix;
	var params = 'prefix='+prefix;
	new Ajax.Updater('numberpool', 'numpool.php', {method: 'post', parameters: params}); 
}

var numbertype;

function numcheck(ID) {
	
	numbertype = ID;

	var numberpool = document.getElementById('numberpool');

	var numtype_888 = document.getElementById('typeblock-888');
	var numtype_877 = document.getElementById('typeblock-877');
	var numtype_866 = document.getElementById('typeblock-866');
	var numtype_800 = document.getElementById('typeblock-800');
	var numtype_vanity = document.getElementById('typeblock-vanity');
	var numtype_local = document.getElementById('typeblock-local');

	var numtype = document.getElementById(ID);
	var numtype_classname = document.getElementById('typeblock-'+ID);

	if (numtype.checked != true) {
	  numtype.checked = true;
	  numtype_888.className = 'typeblock';
	  numtype_877.className = 'typeblock';
	  numtype_866.className = 'typeblock';
	  numtype_800.className = 'typeblock';
	  numtype_vanity.className = 'typeblock';
	  numtype_local.className = 'typeblock';
	  numtype_classname.className = 'typeblock-selected';
	}

	var vanitysearch = document.getElementById('vanitysearch');
	var vanitynumber = document.getElementById('vanitynumber');
	var localnumbers = document.getElementById('localnumbers');

	if (ID == 'vanity') {
	  vanitysearch.className = 'show';
	  localnumbers.className = 'hide';
	  numberpool.innerHTML = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><center><strong>Real-time Search in the National Database...</strong></p></center>';
	  
	  vanitynumber.focus();

	} else if (ID == 'local')	{
	  localnumbers.className = 'show';
	  vanitysearch.className = 'hide';
	  numberpool.innerHTML = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><center><strong>Please Select State &amp; City on the left side!</strong></p></center>';
	} else {
	  vanitysearch.className = 'hide';
	  localnumbers.className = 'hide';

	  var numberpool = document.getElementById('numberpool');
	  numberpool.innerHTML = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><center><strong>Fetching 1-(' + ID + ') Toll Free Numbers</strong><br /><img src="images/pending.gif" alt="Pending..." width="161" height="12" /><p><a onclick="javascript: fetchnumber(\''+ID+'\');">Please click here to re-fetch toll free numbers if timeout</a></p></center>';
	
	  fetchnumber(ID);
	}
}

function fetchlocalnumber(state, areacode, city) {
	var params = 'prefix=local&state='+state+'&areacode='+areacode+'&city='+city;
	new Ajax.Updater('numberpool', 'numpool.php', {method: 'post', parameters: params}); 
}

function localnumcheck (params) {
  if (params != null) {
	var numberpool = document.getElementById('numberpool');
	numberpool.innerHTML = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><center><strong>Fetching Local Numbers</strong><br /><img src="images/pending.gif" alt="Pending..." width="161" height="12" /><p><a onclick="javascript: localnumcheck();">Please click here to re-fetch local numbers if timeout</a></p></center>';
	
	var params_arr = params.split('*');
	var state = params_arr[0];
	var areacode = params_arr[1];
	var city = params_arr[2];
	
	fetchlocalnumber(state, areacode, city);
  }
}

function numlist(ID) {

	var numlist = document.getElementById(ID);
	var numlist_classname = document.getElementById('numlist-'+ID);

	var numlist_one = document.getElementById('numlist-num1');
	var numlist_two = document.getElementById('numlist-num2');
	var numlist_three = document.getElementById('numlist-num3');
	var numlist_four = document.getElementById('numlist-num4');
	var numlist_five = document.getElementById('numlist-num5');
	var numlist_six = document.getElementById('numlist-num6');
	var numlist_seven = document.getElementById('numlist-num7');
	var numlist_eight = document.getElementById('numlist-num8');
	var numlist_nine = document.getElementById('numlist-num9');
	var numlist_ten = document.getElementById('numlist-num10');
  
	if (numlist.checked != true) {
	  numlist.checked = true;
	  numlist_one.className = 'numblock';
	  numlist_two.className = 'numblock';
	  numlist_three.className = 'numblock';
	  numlist_four.className = 'numblock';
	  numlist_five.className = 'numblock';
	  numlist_six.className = 'numblock';
	  numlist_seven.className = 'numblock';
	  numlist_eight.className = 'numblock';
	  numlist_nine.className = 'numblock';
	  numlist_ten.className = 'numblock';
	  numlist_classname.className = 'numblock-selected';
	}
}

/***** toll free vanity number search *****/
function getCursorPosition(textField) 
{
    // Initialize
    var cursortPos = 0;
    // IE Support
    if (document.selection) {
        // Set focus on the element
        textField.focus();
        // To get cursor position, get empty selection range
        var selRange = document.selection.createRange();
        // Move selection start to 0 position
        selRange.moveStart('character', -textField.value.length);
        // The caret position is selection length
        cursorPos = selRange.text.length;
    }  
    // Firefox support
    else if (textField.selectionStart || textField.selectionStart == '0') {
        cursorPos = textField.selectionStart;
    }   
    // Return results
    return (cursorPos);
}
function setCursorPosition(textField, cursorPos) 
{
    // IE Support
    if (document.selection) {
        // Create empty selection range
        var selRange = document.selection.createRange();
        // Move selection start to 0 position
        selRange.moveStart('character', -textField.value.length);
        // Move selection to desired position
        selRange.move('character', cursorPos);
        selRange.select();
    }
    // Firefox support
    else if (textField.selectionStart || textField.selectionStart == '0') { 
        textField.selectionStart = cursorPos;
        textField.selectionEnd = cursorPos;
        textField.focus();
    }
}

//add vanity number when using phone key pad
function addkey(key, vanityinput) {

	var vanitynumber = document.getElementById(vanityinput);

	//clear field
	if (vanitynumber.value=='pbx****') {
	    vanitynumber.value='';
	}
	var position = 0;
	if (vanitynumber.value.length < vanitynumber.maxLength) {
	    //get the cursor position
	    position = getCursorPosition(vanitynumber);
	    var currentText = vanitynumber.value;
	    var preCursorText = currentText.substr(0, position);
	    var postCursorText = currentText.substr(position);
		vanitynumber.value = preCursorText + key + postCursorText;
		//set cursor position
		setCursorPosition(vanitynumber, position + 1);
	}
}

function isNumberKey(evt) {
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function vanitysearch() {
	
	vanityupdate(null, true);
	
	var prefix = document.getElementById('prefix');
	var vanitynumber = document.getElementById('vanitynumber');
	var searchnumber = prefix.value + vanitynumber.value;
	
	if (searchnumber.length < 10) {
	  alert('Please enter at least 7 numbers for your vanity number!');
	  return false;
	}

	var params = 'tollfree=' + searchnumber;
	new Ajax.Updater('checkstatus', 'vanitysearch.php', {method: 'post', parameters: params}); 
	
	vanitycheck();
}

var vanitycount = 0;

function vanitycheck() {

	var checkstatus = document.getElementById('checkstatus');
	if (checkstatus.innerHTML == '01-Success' || checkstatus.innerHTML == ' 01-Success') {
	  clearTimeout(timer);
	  
	  var prefix = document.getElementById('prefix');
	  var vanitynumber = document.getElementById('vanitynumber');
	  var searchnumber = prefix.value + vanitynumber.value;

	  var params = 'tollfree=' + searchnumber;
	  new Ajax.Updater('checkstatus', 'numcheck.php', {method: 'post', parameters: params}); 
	  
	  vanitycount = 0;
	  vanityupdate(searchnumber);
	} else if (numbertype == 'vanity') {
	  var numberpool = document.getElementById('numberpool');
	  numberpool.innerHTML = '<center><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><strong>Processing...</strong></center>';

	  timer = setTimeout("vanitycheck()",1000);  // hold on 1 sec.
	}
}

function vanityupdate(searchnumber, cleanup) {

  if (cleanup != null) {
	if (window.timer) clearTimeout(timer);
  } else {

	vanitycount++;

	var params = 'tollfree=' + searchnumber;
	new Ajax.Updater('checkstatus', 'numcheck.php', {method: 'post', parameters: params}); 

	var numberpool = document.getElementById('numberpool');
	var checkstatus = document.getElementById('checkstatus');
	checkstatus.innerHTML = 'NEW';

	if (checkstatus.innerHTML == 'Done' || checkstatus.innerHTML == ' Done') {
	  clearTimeout(timer);
	  numberpool.innerHTML = '<div id="numlist-num" class="numblock-selected"><a onclick="numlist(\'num\');"><div class="number"><input type="radio" checked="checked" name="chosennum" id="num" value="'+searchnumber+'" onfocus="numlist(\'num\');" />'+searchnumber+'</div><div class="pickme">Pick me</div></a></div>';
	} else if (checkstatus.innerHTML == 'NEW') {
	  if (numbertype == 'vanity') numberpool.innerHTML = '<center><div id="counter">'+vanitycount+'</div><strong>Pending in queue</strong><br /><img src="images/pending.gif" alt="Pending..." width="161" height="12" /><br /><br />(Note: This is a real-time search in the national database. The estimate searching time ranges from 10 sec. to a couple of mins. If the number is available, we will reserve it for you!)</center>';
	  timer = setTimeout("vanityupdate('"+searchnumber+"')",2000);  // hold on 2 sec.
	} else if (checkstatus.innerHTML == 'Running') {
	  if (numbertype == 'vanity') numberpool.innerHTML = '<center><div id="counter">'+vanitycount+'</div><strong>Searching in the National Database</strong><br /><img src="images/pending.gif" alt="Pending..." width="161" height="12" /><br /><br />(Note: This is a real-time search in the national database. The estimate searching time ranges from 10 sec. to a couple of mins. If the number is available, we will reserve it for you!)</center>';
	  timer = setTimeout("vanityupdate('"+searchnumber+"')",2000);  // hold on 2 sec.
	} else {
	  timer = setTimeout("vanityupdate('"+searchnumber+"')",2000);  // hold on 2 sec.
	}
  }
}

/***** end of vanity search *****/

/***** dropdown functions *****/
function filter(pattern, list)
{
	if (!list.bak)
	{
		list.bak = new Array();
		for (n=0;n<list.length;n++)
		{
			if (list[n].value != "")
			{
				//No need to save the top empty string.
				list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
			}
		}
	}
	
	match = new Array();
	nomatch = new Array();
	for (n=0;n<list.bak.length;n++)
	{
		if(list.bak[n][0].toLowerCase().indexOf(pattern.toLowerCase())!=-1)
		{
			match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
		}
	}
	
	list.options.length = match.length + 1;	
	list[0].value = "";	
	list[0].text = "Select Area Code or City";
			  
	var lastCityName = "";
	for (n=0;n<match.length;n++)
	{
			var cityText = match[n][1];
			if(cityText != lastCityName)
			{
				list[n+1].value = match[n][0];
				list[n+1].text = cityText;
			}
			lastCityName = cityText;
	}
	  
	list.selectedIndex=0;
}

function updateCity(stateSelectName, citySelectName)
{
	var stateSelect = document.getElementById(stateSelectName);
	var citySelect = document.getElementById(citySelectName);

	filter(stateSelect.value, citySelect);
}
/***** end of dropdown functions *****/

function totalupdate (planfee) {
	var reservefee = document.getElementById('reservefee');
	var discount = document.getElementById('discount');
	var totalcharge = document.getElementById('totalcharge');
	
	totalcharge.innerHTML = '$'+Math.round((parseFloat(planfee)+parseFloat(reservefee.value)-parseFloat(discount.value))*100.0)/100.0;
}

/************* audio player **************/
var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
			
			// click action
			toggleTDDisplay(theRowNum);
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;

			// click action
			toggleTDDisplay(theRowNum);
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


function toggleTDDisplay( ID ) {
	if (document.getElementById && document.getElementsByTagName){
	  var objstyle = document.getElementById('tdblock'+ID);
	  if(objstyle.className == "tdblock-hide" || objstyle.className == "") {
        objstyle.className = "tdblock"; 

	    var msgbox = document.getElementById('contact-msgbox'+ID);
	    msgbox.innerHTML = '';

	  } else {
        objstyle.className = "tdblock-hide"; 
      }
    }
}


function tabswitch(ID, tab) {
	
	var div_contact = document.getElementById('mnu-contact'+ID);
	// var div_forwarding = document.getElementById('mnu-forwarding'+ID);
	var div_notes = document.getElementById('mnu-notes'+ID);

	div_contact.className = 'menutab-item';
	// div_forwarding.className = 'menutab-item';
	div_notes.className = 'menutab-item';

	var tab_contact = document.getElementById('tab-contact'+ID);
	// var tab_forwarding = document.getElementById('tab-forwarding'+ID);
	var tab_notes = document.getElementById('tab-notes'+ID);

	tab_contact.className = 'messagebody hide';
	// tab_forwarding.className = 'messagebody hide';
	tab_notes.className = 'messagebody hide';
	
	if (tab == 'contact') {
		div_contact.className = 'menutab-selected';
		tab_contact.className = 'messagebody';
		
		var fullname = document.getElementById('fullname'+ID);
		fullname.focus();
		
	} else if (tab == 'forwarding') {
		div_forwarding.className = 'menutab-selected';
		tab_forwarding.className = 'messagebody';
	} else if (tab == 'notes') {
		div_notes.className = 'menutab-selected';
		tab_notes.className = 'messagebody';
		
		var notes = document.getElementById('notes'+ID);
		notes.focus();
	}
	
	var msgbox = document.getElementById('contact-msgbox'+ID);
	msgbox.innerHTML = '';
}

function updatecontact(ID, num, msgid) {
	var displayflag = document.getElementById('displayflag'+ID);
	var displayname = document.getElementById('displayname'+ID);
	
	var fullname = document.getElementById('fullname'+ID);
	var phonetype = document.getElementById('phonetype'+ID);
	var groupid = document.getElementById('groupid'+ID);
	
	var flag = 0;
	var flagmessage = document.getElementById('flag'+ID);
	if (flagmessage.checked == true) var flag = 1;
	
	var status = 1;
	var deletemessage = document.getElementById('delete'+ID);
	if (deletemessage.checked == true) var status = 0;
	
	var blockstatus = 0;
	var block = document.getElementById('block'+ID);
	if (block.checked == true) var blockstatus = 1;

	var params = 'msgid='+msgid+'&num='+num+'&fullname='+fullname.value+'&phonetype='+phonetype.value+'&groupid='+groupid.value+'&flag='+flag+'&status='+status+'&block='+blockstatus;
	new Ajax.Updater('contact-msgbox'+ID, '/messages/process_contact.php', {method: 'post', parameters: params}); 
	
	// update flag/name display
	if (flag == 1) displayflag.innerHTML = '<center><strong>&sect;</strong></center>'; else displayflag.innerHTML = '&nbsp;';
	if (fullname.value != '') displayname.innerHTML = fullname.value;

	var blockindex = document.getElementById('blockindex'+ID);
	var tdblock = document.getElementById('tdblock'+ID);
	if (status == 0) {
	  blockindex.className = 'hide';
	  tdblock.className = 'hide';
	}
}

function updatenotes(ID, msgid) {
	var displaynote = document.getElementById('displaynote'+ID);
	
	var notes = document.getElementById('notes'+ID);
	
	var params = 'msgid='+msgid+'&notes='+notes.value;
	new Ajax.Updater('notes-msgbox'+ID, '/messages/process_notes.php', {method: 'post', parameters: params}); 
	
	// update notes display
	displaynote.innerHTML = notes.value;
}

