
// setRow is used to save the currently selected row
var topSetRow;
var setRow;

function hideResponseAndWait(responseId, waitId)
{
	if(document.getElementById(responseId) != null)
	{
		document.getElementById(responseId).innerHTML = "";
	}
	hide(responseId);
	hide(waitId);
}

function display(id) 
{
	if (document.getElementById(id) != null)
	{
		document.getElementById(id).style.display = '';
	}
}

function hide(id)
{
	if (document.getElementById(id) != null)
	{
    	document.getElementById(id).style.display = 'none';
   	}
}

function mouseOut(row, type)
{
	if(type == "top")
	{
		if(row != topSetRow)
		{
			row.className = "";
		}
	}
	else
	{
		if(row != setRow)
		{
			row.className = "";
		}
	}
}

function mouseOver(row, type)
{
	row.className = 'alt_row';
}

function stickRowStripe(row, type)
{
	if(type == "top")
	{
		if(topSetRow != null)
		{
			topSetRow.className = "";
		}
		
		row.className = "alt_row";
		topSetRow = row;
	}
	else
	{	
		// 1. Un set old alt row
		if(setRow != null)
		{
			empty('commissionDetailsBreakdownResponse');
			setRow.className = "";
		}
		
		// 2. Set new alt row
		row.className = "alt_row";
		setRow = row;
	}
}

function stickRowStripeParent(row, type)
{
	if(type == "top")
	{
		// 1. Unset old alt row
		if(setRow != null)
		{
			topSetRow.className = "";
		}
		
		// 2. Set new alt row
		row.parentNode.className = "alt_row";
		topSetRow = row.parentNode;
	}
	else
	{
		// 1. Unset old alt row
		if(setRow != null)
		{
			setRow.className = "";
		}
		
		// 2. Set new alt row
		row.parentNode.className = "alt_row";
		setRow = row.parentNode;
	}
}

function unStickRowStripe()
{
	if(setRow != null)
	{
		setRow.className = "";
		empty('commissionDetailsBreakdownResponse');
		setRow = null;
	}
}

function selectRow(row)
{
	// 1. Un set old alt row
	if(setRow != null)
	{
		setRow.className = "";
	}
	
	// 2. Set new alt row
	row.className = "alt_row";
	setRow = row;
}

// Used in commissionDetails.jsp to prevent the page jumping when breakdown details are displayed
function empty(id)
{
	if (document.getElementById(id) != null)
	{
    	document.getElementById(id).innerHTML = '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>';
   	}
}

function getRadioCheckedValue(name)
{
	var val;
	var btns = document.getElementsByName(name);
	
	for(var i = 0; i < btns.length; i++)
	{
		if(btns[i].checked === true)
		{
			val = btns[i].value;
		}
	}
	
	return val;
}

function disableButton(button)
{
	if (document.getElementById(button) != null)
	{
		if( (document.getElementById(button).disabled === false) && (button != null) )
		{
			document.getElementById(button).disabled = true;
		}
	}			
}

function enableButton(button)
{
	if (document.getElementById(button) != null)
	{
		if(document.getElementById(button).disabled === true)
		{
			document.getElementById(button).disabled = false;
		}
	}
	
	ajaxButton = "";
}

// Press enter to submit
function checkKeySearchForm(event)
{
	var keynum;

	if(window.event) // IE
	{
		keynum = event.keyCode;
	}
	else if(event.which) // netscape/Firefox/opera
	{
		keynum = event.which;
	}
	
	// 14 = enter key
	if(keynum == 13)
	{
		submitNameSearch();
	}
}

function focusOn(id)
{
	if (document.getElementById(id) != null)
	{
		try
		{
			document.getElementById(id).focus();
		}
		catch(err)
		{
			// The button is closed, so IE can't focus on it
		}
	}
}

function clearInput(id)
{
	if (document.getElementById(id) != null)
	{
		document.getElementById(id).value = "";
	}
}
function setTopSetRow(planRow)
{
	topSetRow = document.getElementById(planRow);
}

function getPlanId()
{
	if(document.getElementById('planId') != null)
	{
		return document.getElementById('planId').value;
	}
	return "";
}

function clearForm(theForm)
{
       for(i=0; i<theForm.elements.length; i++)
       {
           var field = theForm.elements[i];

           if (field.type=="text" || field.type=="textarea" || field.type=="password" )
           {
               field.value = "";
           }
           else if (field.type=="radio" || field.type=="checkbox")
           {
               field.checked = false;
           }
           else if (field.type=="select")
           {
               field.selectedIndex = -1;
           }
       }
}

function correctDecimalPlaces(fieldValue)
{
	decallowed = 2;  // how many decimals are allowed?
	isTwoOrLess = true;
	if (fieldValue.indexOf('.') == -1) 
	{
		fieldValue += ".";
	}
	
	dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

	if (dectext.length > decallowed)
	{
			isTwoOrLess = false;
    }
	else 
	{
			isTwoOrless = true;
    }
   return isTwoOrLess;
}

function cookiesDisabled() {
  var result=true;
  // some browser versions support this - use it if possible
  if (navigator.cookiesEnabled)
    return false;

  // else try to set and read a cookie
  document.cookie = "testcookie=yes;";
  var cookieSet = document.cookie;
  if (cookieSet.indexOf("testcookie=yes") > -1) {
    result=false;
  }
  document.cookie = "testcookie=;expires=;";
  
  if (result)
  {
  	alert('Cookies are required to use this site. Please enable cookies on your Web Browser');
  }
  return result;
}

function openPDF(URL) {
	newWindow = window.open(URL, 'image', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,left = 100,top = 100',true);
}

function loadPlan(planId)
{
	document.getElementById('mainContent').innerHTML=
	'<br /><br /><br /><p><img alt="Retrieveing plan summary ..." class="loadingImage" src="/myonlineservices/public/images/loader.gif"/> Retrieving Plan Summary, please wait ...</p><br /><br /><br />';
	
	window.location.href= '/myonlineservices/planSummary.do?planId='+planId;	
}

function clearPwBox()
{
	if (document.getElementById)
	{
		var pw = document.getElementById('password');
		if (pw != null)
		{
			pw.value = '';
		}
	}
}
function showDetail(id)
{
	var $visibleSiblings = $("#"+id).siblings('div:visible');
	if ($visibleSiblings.length ) 
	{
		$visibleSiblings.slideUp(170, function() 
		{
			$("#"+id).slideToggle(170);
		});
	} 
	else 
	{
		$("#"+id).slideToggle(170);
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//Tabs
//

function changeTab(tabSection, id)
{
for(i = 0; ; i++)
{	
	if($('#'+tabSection+'-tab-link' + i).length != 0)
	{
		if(i == id)
		{
			$('#'+tabSection+'-tab-link' + i).addClass('on'); 
			$('#'+tabSection+'-tab-content' + i).removeClass('hidden'); 
		}
		else
		{
			$('#'+tabSection+'-tab-link' + i).removeClass('on'); 
			$('#'+tabSection+'-tab-content' + i).addClass('hidden');
		}
	}
	else
	{
		break;
	}
}
}

