
//Start TalkAhead Comment Agent Code

var TH_test = function() {
  return dcPath != null && (! dcPath.match("^4003.Lifestyle")) && (! dcPath.match("^2.News"));
}

if (TH_test()) {

// load TalkAhead/Ynet integration script
TH_load = function(jsfile) {
  	headID = document.getElementsByTagName("head")[0];
  	newScript = document.createElement('script');
  	newScript.type = 'text/javascript';
  	newScript.src = jsfile;
  	headID.appendChild(newScript);
};
TH_load('http://server.talkahead.com/custom/ynet/comment_merger.js');

if (window.stlkbc.util.ajax2 == null){
    window.stlkbc.util.ajax2 = window.stlkbc.util.ajax;
}
window.stlkbc.util.ajax = function(url, callback, isjson) {
	if (url.indexOf("ShowTalkBacksAjax")>=0 && (url.indexOf("-asc-")>0 || url.indexOf("-desc-")>0)){
		var isAsc = url.indexOf("-asc-")>0;
        return this.ajax2(url, function(obj) { TH_showTalkbacks(callback, obj, isAsc, 0); }, isjson);
	} else {
		return this.ajax2(url, callback, isjson);
	}
};

TH_showTalkbacks = function(callback, customer_obj, isAsc, counter)  {
    if(typeof(TH_showTalkbacksTimeout) !== 'undefined' && TH_showTalkbacksTimeout!=null)
        clearTimeout(TH_showTalkbacksTimeout);
    if (counter == null)
        counter = 0;

    if ((typeof(TH_json)== 'undefined' || TH_json == null) && counter < 20) {
        TH_showTalkbacksTimeout = setTimeout(function() { TH_showTalkbacks(callback, customer_obj, isAsc, counter + 1) }, 100);
        return;
    }
    var mergerExists = typeof(TH_mergeTalkbacks) != 'undefined' && TH_mergeTalkbacks != null;
    var merged_obj  = mergerExists ? TH_mergeTalkbacks(customer_obj, isAsc) : customer_obj;
//      alert("called the callback mergerExists="+mergerExists);
    callback(merged_obj);
    if (window.TH_opentalkbacks !=null){
        window.TH_opentalkbacks(merged_obj);
    }
}

}
//End TalkAhead Comment Agent Code