var return_url = "";

function readLC(document)
{

	var check = 0;
	var flag = 0;
	var o_urlstring = document.URL;
	var lc = "";
	o_urlstring = pathIntr(o_urlstring);
	section = section(o_urlstring);

	if (o_urlstring.indexOf("intromercial.html") > -1){
		check = 1;
		flag = 1;
	}else if ((o_urlstring.indexOf("technology.") > -1)
			||(o_urlstring.indexOf("practice.") > -1)
			||(o_urlstring.indexOf("marketcenter.") > -1)
			||(o_urlstring.indexOf("vendor.") > -1)
			||(o_urlstring.indexOf("vendors.") > -1)
			||(o_urlstring.indexOf("corporate.") > -1)
			||(o_urlstring.indexOf("supreme.") > -1)
			||(o_urlstring.indexOf("careers.") > -1)
			||(o_urlstring.indexOf("stu.") > -1)){

		// Only check the current page whether it is index page
		// if it is the index page and in these 8 sections,
		// break up o_urlstring into chunks according to "/"
		var urlArray = new Array();
		urlArray=o_urlstring.split('/');
		var length = urlArray.length;
	
		if (length > 1){
			if ((urlArray[1].indexOf("index") == 0)
			|| (urlArray[1].length == 0)){
				check = 1;
			}
		}else{
			check = 1;
		}
	}

	if (check){
		//If we are in the index page then try to display the landing page.
		if (o_urlstring.indexOf("technology.") > -1){
    		lc=new IntrCookie(document, "techintr640480", 1);
		}else if (o_urlstring.indexOf("practice.") > -1){
    		lc=new IntrCookie(document, "pracintr640480", 1);
		}else if ((o_urlstring.indexOf("marketcenter.") > -1)
			||(o_urlstring.indexOf("vendor.") > -1)
			||(o_urlstring.indexOf("vendors.") > -1)){
    		lc=new IntrCookie(document, "vendintr640480", 1);
		}else if (o_urlstring.indexOf("corporate.") > -1){
    		lc=new IntrCookie(document, "cccintr640480", 1);
		}else if (o_urlstring.indexOf("supreme.") > -1){
    		lc=new IntrCookie(document, "suprintr640480", 1);
		}else if (o_urlstring.indexOf("careers.") > -1){
    		lc=new IntrCookie(document, "carintr640480", 1);
		}else if (o_urlstring.indexOf("stu.") > -1){
    		lc=new IntrCookie(document, "stuintr640480", 1);
		}
    	var isLC=lc.readIntrCookie();
    	if (!isLC) {
			//No Landing Cookie 
			//Set the Landing Cookie
			lc.createIntrCookie();

			//Check the intr640480 cookie to see if cookie is disabled.
			var enabled = lc.readIntrCookie();
			if (enabled){
				//Display the Landing Page
				window.location="http://" + section + "/intromercial.html";
			}
		}else{
			//There is landing cookie.
			//returning true so we won't call the DART javascript.
			if (flag){
				return false;
			}else{
				return true;
			}
		}
	}
	return true;
}

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

IntrCookie.prototype.createIntrCookie=function() {
        var cookieval=document.URL;
        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;
}

IntrCookie.prototype.readIntrCookie=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;
        return_url= allcookies.substring(start,end);
		var o_urlstring = document.URL;
		if (o_urlstring.indexOf("intromercial.html") != -1){
			//We are in Landing page
			//Redirect to the correct path after 8 seconds.
			setTimeout("getGoing()", 8000);
		}
        return true;
}

function getGoing(){
		window.location=return_url;
}

function openAdWindow() {
		window.open("http://www.findlaw.com/ad.html", "alert", "height=140,width=510,toolbars=false,status=false");
}

function pathIntr(urlstring)
{
   urlstring = urlstring.toLowerCase();
   var start = urlstring.indexOf('//');
   if (start != -1) {
      start = start+2;
      //delete the "http://"
      urlstring = urlstring.substring(start, urlstring.length);
   }
   return urlstring;
}

function section(urlstring)
{
   var end = urlstring.indexOf('/');
   if (end != -1) {
      //grab all string until the first /
      urlstring = urlstring.substring(0, end);
   }
   return urlstring;
}
