function createUT(document,cid)
{
        var ut=new Cookie(document, "ut", 360*30);
        if (cid != "" && (cid == "000000010000000100000000" || 
                          cid == "000000010000000100000000" || 
                          cid == "000000010000001000000001" ||
                          cid == "000000010000001100000000")) {
                ut.lvp="lp";
        } else {
                ut.lvp="cons";
        }
        ut.createCookie();
}

function readUT(document)
{
    var ut=new Cookie(document, "ut", 360*30);
    var isUT=ut.readCookie();

    if (isUT) {
        return ut.lvp;
    }

    var vp=new Cookie(document, "VIEW_PREFS", 360);

    vp.readOldCookie();

    var vpvalue = vp.attr;

    if (vpvalue != "" && (vpvalue == "000000010000000100000000" ||
                          vpvalue == "000000010000000100000000" ||
                          vpvalue == "000000010000001000000001" ||
                          vpvalue == "000000010000001100000000")) {
        return "lp";
    } else {
        return "cons";
    }
}

function readUP(document)
{
    var up=new Cookie(document, "up", 360);
    var isUP=up.readCookie();
    if (isUP) {
        return up;
    }
}

function readUR(document)
{
    var ur=new Cookie(document, "ur", 360);
    var isUR=ur.readURCookie();
    if (isUR) {
		if (ur.urv){
       		return ur;
		}else{
			//Remove Cookie
			ur.removeCookie();
		}
    }
}

function Cookie(document, name, days)
{
        this.$document=document;
        this.$name=name;
        if (days)
                this.$expiration=new Date((new Date()).getTime() + days *3600000*24);
        else this.$expiration=null;
        this.$path="/";
        this.$domain=".findlaw.com";
}

Cookie.prototype.createCookie=function() {
        var cookieval="";
        for(var prop in this) {
                if ((prop.charAt(0)=='$') || ((typeof this[prop])=='function'))
                        continue;
                if (cookieval !="") cookieval += '&';
                cookieval += prop + '&' + escape(this[prop]);
        }

        var cookie=this.$name+ '=' + cookieval;
        if (this.$expiration)
                cookie += '; expires=' + this.$expiration.toGMTString();
        cookie += '; path=' + this.$path;
        cookie += '; domain=' + this.$domain;
        this.$document.cookie=cookie;
}

Cookie.prototype.readCookie=function() {
        var allcookies = this.$document.cookie;
        if (allcookies=="") return false;
        var start = allcookies.indexOf(this.$name+'=');
        if (start== -1) return false;
        start += this.$name.length+1;
        var end = allcookies.indexOf(';',start);
        if (end == -1) end = allcookies.length;
        var cookieval = allcookies.substring(start,end);
        var a = cookieval.split('&');
        for (var i=0;i<a.length-1;i=i+2) {
                this[a[i]]=unescape(a[i+1]);
        }
        return true;
}

Cookie.prototype.readURCookie=function() {
        var allcookies = this.$document.cookie;
        if (allcookies=="") return false;

        var start = allcookies.indexOf(this.$name+'=');
        if (start== -1) return false;
        start += this.$name.length+1;

        var end = allcookies.indexOf(';',start);
        if (end == -1) end = allcookies.length;

		var items;
        var cookieval = unescape(allcookies.substring(start,end));
        var a = cookieval.split('&');
        for (var i=0;i<a.length-1;i++) {
			items = a[i].split(':');
            this[items[0]]=unescape(items[1]);
        }
        return true;
}

//read old cookie 

Cookie.prototype.readOldCookie=function() {
        var allcookies = this.$document.cookie;
        if (allcookies=="") return false;

        var start = allcookies.indexOf(this.$name+'=');
    	if (start== -1) return false;
    	start += this.$name.length+1;

    	var end = allcookies.indexOf(';',start);
    	if (end == -1) end = allcookies.length;

    	var cookieval = allcookies.substring(start,end);
    	this.attr=unescape(cookieval);
        this.$document.write("<br>OLDcookieval" + cookieval);
        return true;
}

//remove cookie
Cookie.prototype.removeCookie=function() {
        var cookie;
        cookie=this.$name+'=';
        cookie += '; path='+this.$path;
        cookie += '; domain='+this.$domain;
        cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
        this.$document.cookie=cookie;
}

function parseCookie(name){
    var sentence;
    var decmaker = "";

    if (name == "up"){
        sentence = "zip="+ up.zip +
                    ";msa=" + up.msa +
                    ";expl=" + up.expl +
                    ";state=" + up.state + ";";
    }else if (name == "ur"){
        var s_decmaker = ur.dm;
			
        for(var i=0;i < 4;i++){
			if ((s_decmaker>>i)%2 == 1){
        		if (i == 0){
                    decmaker = "dm=tp";
                }else if (i == 1){
                    if (decmaker != ""){
                        decmaker = decmaker + ";";
                    }
                    decmaker = decmaker + "dm=lm";
                }else if (i == 2){
                    if (decmaker != ""){
                        decmaker = decmaker + ";";
                    }
                    decmaker = decmaker + "dm=lr";
                }else if (i == 3){
                    if (decmaker != ""){
                        decmaker = decmaker + ";";
                    }
                    decmaker = decmaker + "dm=ah";
                }
            }
        }

        //Create line for decmaker
        sentence = decmaker +
                    ";wl=" + ur.wl+
                    ";in=" + ur.iy+
                    ";em=" + ur.em+
                    ";pf=" + ur.pf+
                    ";pr=" + ur.pr;
    }
    return (sentence);
}
