

function DSCookie(name)
{
    this.getExpDate = function()
    {
        var expDate = new Date();
        expDate.setMonth(expDate.getMonth() + 1);
        return expDate.toGMTString();
    }
    this.getCookie = function()
    {
		var res = new RegExp(this.name + "=([^;]+)", "i").exec(document.cookie);
		return res ? unescape(res[1]) : null;
    }  
    this.setCookie = function(value)
    {
        document.cookie = this.name + "=" + escape (value) + "; expires=" + this.getExpDate() + ";path=/";
    }
    this.setTempCookie = function(value)
    {
        document.cookie = this.name + "=" + escape (value);
    }
    this.deleteCookie = function()
    {
        if (this.getCookie()) document.cookie = this.name + "=; expires=" + new Date(0).toGMTString();
    }
    this.getCookieInt = function()
    {
    	var res = this.getCookie();
	    return res == null ? 0 : parseInt(res, 10);
    }
    this.getCookieBool = function()
    {
	    var res = this.getCookie();
	    return res ? res == "true" : null;
    }
    this.getCookieStr = function()
    {
        var res = this.getCookie();
        return res ? res : "";
    }
	this.name = name;
}
function DSForm()
{
	this.init = function(){
		this.cLogin = new DSCookie('Login');
		//this.cPassword = new DSCookie('Password');
		this.cSecure = new DSCookie('Secure');
		this.secure.onclick = function(){me.checkSSL();};
		this.loginForm.onsubmit = function(){return me.onLogin();};
	}
	this.onLogin = function(){
		if (this.login.value.length > 0 && this.password.value.length > 0){
			if (!this.remember.checked){
				this.cLogin.deleteCookie();
//				this.cPassword.deleteCookie();
				this.cSecure.deleteCookie();
			}else{
				this.cLogin.setCookie(this.login.value);
				//GDA this.cPassword.setCookie(this.password.value);
				this.cSecure.setCookie(this.secure.checked);
			}
			this.loginForm.action = this.action;
			return true;
		}else{
			return false;
		}
	}
	this.checkSSL = function(){
		this.action = ((this.secure.checked==true)?"https":"http")+this.action.substring(this.action.indexOf(":"));
	}
	this.onPageLoad = function(){
		var username = this.cLogin.getCookieStr();
		if (username.length > 0){
			this.login.value = username;
			//GDA this.password.value = this.cPassword.getCookieStr();
			this.remember.checked = true;
		}
		if (this.cSecure.getCookieBool()){
			this.secure.checked = true;
		}
		else 
		{
			this.secure.checked = false;
		}
		this.login.focus();
	}
	var me = this;
	this.loginForm = document.getElementById('loginForm');
	this.login = document.getElementById('login');
	this.password = document.getElementById('password');
	this.remember = document.getElementById('checkRemember');
	this.secure = document.getElementById('checkSecure');
	this.action = 'http://app1.docusync.com/web/login.aspx';
	this.init();
}
