
function CheckAllDataGridCheckBoxes(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;
				
			}
		}
	}	
}

function checkMail()
{
    var x = document.forms[0].spread_email.value;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(x))
    {
    return true;
    }
    else 
    {
    alert('Fill in a valid email.');
    return false;
    }
}

//myField accepts an object reference, myValue accepts the text strint to add
/*
function insertatcursor(myField, myValue) 
{
    //IE support
    if (document.selection) 
    {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //Mozilla/Firefox/Netscape 7+ support
    else if (myField.selectionStart || myField.selectionStart == '0') 
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
    } 
    else 
    {
        myField.value += myValue;
    }
}*/

function insertatcursor(myField, myValue) 
{
    //IE support
    if (document.selection) 
    {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //Mozilla/Firefox/Netscape 7+ support
    else if (myField.selectionStart || myField.selectionStart == '0') 
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
    } 
    else 
    {
        myField.value += myValue;
    }
}

function getElement(field, value)
{
    element = document.getElementById(field).value;
    insertatcursor(field, value);
}

// find focused element
function getIndex(what,which) 
{
    for (var i=0;i < what.elements.length;i++)
    {
        if (what.elements[i].name == which)
        {
            return what.elements[i].name
        }
    }
    return -1;
}

function ResetAllDataGridCheckBoxes(aspCheckBoxID) 
{
	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 = elm.defaultChecked;				
			}
		}
	}	
}

function ConfirmNoCheckBoxChecked(aspCheckBoxID,msg) 
{
    var chkboxExist = false;
	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)) 
			{
			    chkboxExist = true;
				if (elm.checked)
				{
				    return true;
				}
			}
		}
	}
	if (chkboxExist) return confirm(msg);	
	else return true;
}


