/* Copyright (c) 2007 eSolutions Group Ltd 
*
* Author:	Matt Ridley <mridley@esolutionsgroup.ca>
*/

/**
 * This public function handles the auto tab.
 *
 * Example Implementation
 *		// init auto tabbing for home phone
 *		txtPhoneArea.Attributes.Add("onKeyUp", "AutoTab('" + txtPhoneArea.ClientID + "', '" + txtPhonePrefix.ClientID + "');");
 *		txtPhonePrefix.Attributes.Add("onKeyUp", "AutoTab('" + txtPhonePrefix.ClientID + "', '" + txtPhoneSuffix.ClientID + "');");
 *		txtPhoneSuffix.Attributes.Add("onKeyUp", "AutoTab('" + txtPhoneSuffix.ClientID + "', '" + txtPhoneExt.ClientID + "');");
 *
 *
 */
function AutoTab(controlId, controlId2) {
	var control = document.getElementById(controlId);
	var control2 = document.getElementById(controlId2);
	if (control.value.length >= control.getAttribute("maxlength")){
		control2.focus();
	}
}

/**
* This function  clears a checkbox
*
* -EXAMPLE IMPLEMENTATION (in Page Load)
*
*		q7.Attributes.Add("onKeyPress","AutoUnCheck('" + chkQ7.ClientID + "');");
 */
function AutoUnCheck(controlId) 
{
	var control = document.getElementById(controlId);
	control.checked = false;
}

/**
* This function  checks a checkbox
*
* -EXAMPLE IMPLEMENTATION (in Page Load)
*
*		q7.Attributes.Add("onKeyPress","AutoCheck('" + chkQ7.ClientID + "');");
 */
function AutoCheck(controlId) 
{
	var control = document.getElementById(controlId);
	control.checked = true;
}

/**
* This function performs a max charecter countdown for multiline textboxes
*
* -EXAMPLE IMPLEMENTATION
*			<asp:TextBox id="q7" runat="server" textmode="multiline" style="width:100%; height:75px;" 
*				onkeyup="TextCounter(q7, this.form.remLen1, 3000);" 
*				onkeydown="TextCounter(q7, this.form.remLen1, 3000);">
*			</asp:TextBox>
*			<table cellpadding="0" cellspacing="0" border="0" width="100%">
*				<tr>
*					<td align="right">
*						Characters Remaining: <input readonly="readonly" type="text" name="remLen1" size="4" maxlength="4" value="3000" /> 
*					</td>
*				</tr>
*			</table>
*/
function TextCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit){
		 field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function AutoCheckNAForNo(chkControlId,rbYesId) 
{
	var control = document.getElementById(chkControlId)	
	var radioButton = document.getElementById(rbYesId)
	
	radioButton.checked = false;
	control.checked = true
}

function AutoUnCheckNAForYes(chkControlId,rbNoId) 
{
	var control = document.getElementById(chkControlId)	
	var radioButton = document.getElementById(rbNoId)

	radioButton.checked = false;
	control.checked = false
}


	
