function formatDate(timestamp){var date=new Date(timestamp); 
var hours=date.getHours(); 
var mins=date.getMinutes(); 
if(mins<10){mins="0"+mins; 
}
if(hours>=12){a_p=" p.m.";  
}else{a_p=" a.m."; 
}
if(hours>12){hours-=12; 
}
if(hours===0){hours=12; 
}
return hours+":"+mins+a_p; 
}
function formatLink(url){
    if(url.indexOf('?mod=')>-1){
        //var url=url.replace(/\?mod=.*?\&|\?mod=.*?$/,'?mod=igoogle_wsj_gadgv1&'); 
        var url=url+'&mod=igoogle_wsj_gadgv1';
        return url; 
    }
    else if(url.indexOf('&mod=')>-1){
        //var url=url.replace(/\&mod=.*?\&|\&mod=.*?$/,'&mod=igoogle_wsj_gadgv1&'); 
        var url=url+'&mod=igoogle_wsj_gadgv1';
        return url; 
    }
    if(url.indexOf('?')>-1)
        return url.replace(/^\s+|\s+$/g,'')+'&mod=igoogle_wsj_gadgv1'; 
    return url.replace(/^\s+|\s+$/g,'')+'?mod=igoogle_wsj_gadgv1'; 
}
function makeCachedUrl(url,refreshInterval){
  
var td=new Date(); 
var ts = td.getTime() + td.getTimezoneOffset() * 60;

var sep="?"; 
if(refreshInterval&&refreshInterval>0){ts=Math.floor(ts/(refreshInterval*1000)); 
}
if(url.indexOf("?")>-1){sep="&"; 
}
url=[url,sep,"nocache=",ts].join(""); 
return url; 
}
function search(){var item=document.getElementById('hat_input'); 
window.open('http://online.wsj.com/public/search/page/3_0466.html?KEYWORDS='+item.value); 
}
function inputfocus(){document.getElementById('hat_input').value=''; 
}

function xgetBctId(url){var i=url.indexOf('.html'); 
if(i==-1)
return null; 
var j=url.indexOf('/',29); 
var idStr=url.substring(j+1,i); 
return '{'+idStr+'}'; 
}

function getBctId(url){var i = url.lastIndexOf('/'); if(i==-1)return null; var idStr = url.substr(i+1); return idStr; }

function setPlayer(bctid,autoStart){if(autoStart == true){document.getElementById("videoFrame").src='http://online.wsj.com/static_html_files/MPLinkVideoPlayer.html?autoStart=yes&guid='+bctid; 
}else {document.getElementById("videoFrame").src='http://online.wsj.com/static_html_files/MPLinkVideoPlayer.html?autoStart=no&guid='+bctid; 
}}
function isWideHome(){var width=0; 
if(window.innerWidth)width=window.innerWidth; 
if(document.documentElement)width=document.documentElement.clientWidth; 
if(document.body)width=document.body.clientWidth; 
if(width>320)
return true; 
return false; 
}
function isWideCanvas(){var width=0; 
if(window.innerWidth)width=window.innerWidth; 
if(document.documentElement)width=document.documentElement.clientWidth; 
if(document.body)width=document.body.clientWidth; 
if(width>1024)
return true; 
return false; 
}
function choptrailingChars(str){var lastIndex=str.lastIndexOf(' '); 
return(str.substring(0,lastIndex)+' ...'); 
}

