//<SCRIPT language="JavaScript">
//<!--
//--- Script by Philippe SERVAIS 20070709
function switchdomain(VariableId, color_on, color_off)
{
	if (color_off == ""){var color_off="#003366";}
	if (color_on == ""){var color_on="#808080";}
	if (document.login.checkdomainonoff.value == "") 
	{
		document.getElementById(VariableId).style.color=color_on;
		document.login.checkdomainonoff.value = "on";
		document.login.checkdomainonoff.checked = true;
	} 
	else if (document.login.checkdomainonoff.value == "on")
	{ 
		document.getElementById(VariableId).style.color=color_off;
		document.login.checkdomainonoff.value = "";
		document.login.checkdomainonoff.checked = false;
	}
}

function addomainuser()
{
var UserName = document.login.RCuser.value;
	if (UserName != "")
	{
	if (document.login.checkdomainonoff.value == "on")
	{
		if (GetCookie("CUser") == "") {
			if (document.login.RCuser.value.indexOf('@') == -1) {
			document.login.RCuser.value = UserName+domainuser;
			}
		}else{
			if (document.login.RCuser.value.indexOf('@') == -1) {
				if (UserName != GetCookie("CUser"))
				{ document.login.RCuser.value = UserName+domainuser; }
			}
		}
	}
	}
	return Login(1)
}

//--- Script by TOD SAMBAR
function loadFocus()
{
    var username = GetCookie("CUser");
    if (username != "")
    {
        document.login.RCuser.value = username;
        document.login.RCpwd.focus();
    }
    else
    {
        document.login.RCuser.focus();
    }
}

// cookie functions
function getCookieVal (offset)
{

    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;

    return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }

    return "";
}

function SetCookie (name, value)
{
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function Login(action)
{
    if (document.login.RCuser.value == "")
    {
        alert("User name not provided.");
        document.login.RCuser.focus();
        return false;
    }

    if (document.login.saveuser.checked)
        SetCookie("CUser", document.login.RCuser.value);
    else
        DeleteCookie("CUser");

    var user = document.login.RCuser.value;

    // Standard login
    if (action == 1)
    {
        document.login.RCpage.value = "/sysuser/index.asp";
    }
    else
    {
        document.login.RCpage.value = "/sysuser/wfolder.asp";
    }

    document.login.submit();

    return true;
}
//-->
//</SCRIPT>

