
//-----------------------------------------------------------------------------
var Win, newWin;
function displayWindow(url,name,width,height) {
	opt = 'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes,toolbar=yes,menubar=yes,top=0,left=0,status=yes,location=yes'
  Win = window.open(url, name, opt);
	if (Win) {
		Win.focus();
	}
}

//-----------------------------------------------------------------------------
function displayWin(url,name,width,height) {
	var _left = (screen.width - width)/2;
	var _top = (screen.height - height)/2;
	opt = 'width=' + width + ',height=' + height + ',left=' + _left + ',top=' + _top + ',location=no,menubar=no,resizable=0,scrollbars=yes,status=no,toolbar=no'
	newWin = window.open(url, name, opt);
	if (newWin) {
		newWin.focus();
	}
}

function redirectTo(url)
{
	window.location.href=url
}
function GetCheckedRadioValue(radioObj) 
{ 
    if(!radioObj) return ""; 
    var radioLength =radioObj.length; 
    if(radioLength == undefined) 
    {
        if(radioObj.checked) 
            return radioObj.value;
        else 
            return ""; 
    }
    for(var i = 0; i < radioLength; i++) 
    { 
        if(radioObj[i].checked) 
        {
            return radioObj[i].value; 
        } 
    } 
    return ""; 
}


// ****************************************************************************************
// Begin Validate Email Address
// ****************************************************************************************
function Validate_String(string, return_invalid_chars)
{
    valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    invalid_chars = '';

    if(string == null || string == '')
        return(true);

    for(index = 0; index < string.length; index++)
    {
        char = string.substr(index, 1);                        

        if(valid_chars.indexOf(char) == -1)
        {
            if(invalid_chars.indexOf(char) == -1)
            {
                if(invalid_chars == '')
                    invalid_chars += char;
                else
                    invalid_chars += ', ' + char;
            }
        }
    }                     

    if(return_invalid_chars == true && invalid_chars != '')
    {
        last_comma = invalid_chars.lastIndexOf(',');

        if(last_comma != -1)
            invalid_chars = invalid_chars.substr(0, $last_comma) + ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);

        return(invalid_chars);
    }
    else
        return(invalid_chars == ''); 
}

function Validate_Email_Address(email_address)
{
    at = email_address.indexOf('@');
    dot = email_address.indexOf('.');

    if(at == -1 || dot == -1 || dot <= at + 1 || dot == 0 || dot == email_address.length - 1)
        return(false);

    user_name = email_address.substr(0, at);
    domain_name = email_address.substr(at + 1, email_address.length);                  

    if(Validate_String(user_name) == false || Validate_String(domain_name) == false)
        return(false);                     

    return(true);
}
function OpenInNewWindow(url) 
{
// Change "_blank" to something like "newWindow" to load all links in the same new window
    var newWindow = window.open(url, '_blank');
    newWindow.focus();
    return true;
}

 function SelectAllCheckboxesInTheList(chkControl)
 {

   var oItem  = chkControl.children;
   var theBox = (chkControl.type=="checkbox") ? chkControl : chkControl.children.item[0];
   xState     = theBox.checked;
   elm        = theBox.form.elements;

   for(i=0; i<elm.length; i++)
     if(elm[i].type == "checkbox" && elm[i].id != theBox.id)
     {
       if(elm[i].checked != xState)
         elm[i].click();
     }
 }
// ****************************************************************************************
// End Validate Email Address
// ****************************************************************************************