function getElementsByClassName(oElm, strTagName, strClassName)
{
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function getCookie(c_name)
{
    if (document.cookie.length > 0) {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1) {
            c_start = c_start + c_name.length + 1;
            c_end   = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end=document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

var views_max = views_max ? views_max : false;

function myfunction(num, area)
{
    //
    var views = getCookie('idx-views');
    views++;
    setCookie('idx-views', views);
    //
    	num = num.replace(/vdi\-/,"");
    	num = num.replace(/vd\-/,"");
    	
    if (views > views_max) {


        if (area != undefined && area != '') {
            document.location.href="/idx/" + area  + "/register.html?pid=" + num;
        } else {
            document.location.href = "/idx/register.html?pid=" + num;
    	}

    }else{
        //http://www.texaspropertyinformation.com/idx/residential/7248790/details.html
         document.location.href = "/idx/" + area  + "/"+ num + "/details.html";
    }

}

function registration(area)
{
    var cookie = getCookie('registered');
    if (cookie == '' || cookie == null){
        var objLinks = getElementsByClassName(document, "a", "info-links");
        for (var iCounter = 0; iCounter < objLinks.length; iCounter++){
            var mlsnum = objLinks[iCounter].getAttribute('id');
            objLinks[iCounter].onclick = function() { myfunction(this.id, area); return false; };
        }
    }
}
