﻿//Javascript functions used in this site

function LimitFieldLength(text,long) 
{
    //Limits the length of textfields
    //Usage: In Page_Load event, type: 
    //      TextBox1.Attributes.Add("onkeydown", "LimitFieldLength(this, " + TextBox1.MaxLength + ");");
    //      TextBox1.Attributes.Add("onkeyup", "LimitFieldLength(this, " + TextBox1.MaxLength + ");");
    //where MaxLength is the MaxLength property of TextBox1
	var maxlength = new Number(long); // Change number to your max length.
	if (text.value.length > maxlength)
	{
		text.value = text.value.substring(0,maxlength);
		//alert(" Only " + long + " chars");
	}
}

//THIS FUNCTION IS NOT USED ANYMORE
//function formValidator() 
//{
//	if (confirm("If you delete this record, all data associated with it will also be deleted!\n\nARE YOU SURE YOU WANT TO DELETE THIS RECORD?\n\nIf you are unsure, click CANCEL.")) {
//		if (!confirm("WARNING: This record and all its dependent information will be DELETED PERMANENTLY!\n\nClick CANCEL if you don't want to delete it or if you are unsure.")) {
//			return false;
//		}
//	} else {
//		return false;
//	}
//	return true;
//}

//Prompts for a double confirmation before deleting record - based on two input strings.
//Usage:
//<asp:Button ID="btnDeleteSelected" Text="Delete Selected" OnClick="btnDeleteSelected_Click"
//OnClientClick="return DeleteValidator('Msg1', 'Msg2');" runat="server" />
//Uses default message if msg1 or msg2 are empty strings ('')
function DeleteValidator(msg1, msg2) 
{
    if (msg1 == "")
    {
        msg1 = "If you delete this record, all data associated with it will also be deleted!\n\nARE YOU SURE YOU WANT TO DELETE THIS RECORD?\n\nIf you are unsure, click CANCEL.";
    }
    if (msg2 == "")
    {
        msg2 = "WARNING: This record and all its dependent information will be DELETED PERMANENTLY!\n\nClick CANCEL if you don't want to delete it or if you are unsure.";
    }
    if (confirm(msg1)) 
	{
		if (!confirm(msg2)) 
		{
			return false;
		}
	} 
	else 
	{
		return false;
	}
	return true;
}

//checks all GridView CheckBoxes with the given name with the given value
function CheckAllGridViewCheckBoxes (aspCheckBoxID, checkVal)
{
    re = new RegExp(aspCheckBoxID + '$');
    
    for (i = 0; i < document.forms[0].elements.length; i++)
    {
        elm = document.forms[0].elements[i];
        
        if (elm.type == 'checkbox')
        {
            if (re.test(elm.name))
            {
                elm.checked = checkVal;
            }
        }
    }
}



