/* Copyright (c) 2007 eSolutions Group Ltd 
*
* Author:	Matt Ridley <mridley@esolutionsgroup.ca>
*/

/**
 * This public function handles the auto tab.
 */
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  checks a checkbox and unchecks it 
* depending on if there is text in a textbox
*
* -EXAMPLE IMPLEMENTATION (in Page Load)
*
*	txtName.Attributes.Add("onKeyUp","AutoCheckOrUncheck('" + chkA2.ClientID + "', '" + txtName.ClientID + "');");
 */
function AutoCheckOrUncheck(chkcontrolId, txtcontrolId) 
{
	var chkcontrol = document.getElementById(chkcontrolId);
	var txtcontrol = document.getElementById(txtcontrolId);
	
	if(txtcontrol.value.length > 0){
		chkcontrol.checked = true;
	}
	else{
	chkcontrol.checked = false;
	}
}

/**
* 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;
	}
}


	
