/* 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 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;
	}
}

/*
* These next 2 javascript functions work together to disable a button
* and change its text to "Please Wait..." while the system is processing
* the Click Event. Preventing a Double Submit of an impatient user 
*
* EXAMPLE IMPLENENTATION
* In Page Load --> btnSubmit.Attributes.Add("onclick", "PleaseWaitButton();");
*/
function PleaseWaitButton() {
    document.forms[0].submit();
    window.setTimeout("DisableButton('" + window.event.srcElement.id + "')", 0);
}
function DisableButton(buttonID) {
    document.getElementById(buttonID).disabled=true;
    document.getElementById(buttonID).value = "Please Wait...";
}

function PleaseWaitButtonFr() {
    document.forms[0].submit();
    window.setTimeout("DisableButtonFr('" + window.event.srcElement.id + "')", 0);
}
function DisableButtonFr(buttonID) {
    document.getElementById(buttonID).disabled=true;
    document.getElementById(buttonID).value = "Veuillez patienter...";
}


	
