Array.max = function(array){
    return Math.max.apply(Math, array);
};

Array.min = function(array){
    return Math.min.apply(Math, array);
};

Array.shuffle = function(array)
{
	var temp = new Array();
	while(array.length > 0)
	{
		temp.push(array.splice(Math.round((array.length - 1) * Math.random()), 1));
	}
	return temp;
}

function emoticon ( emoticon ) {
	document.n6form.commentText.value += emoticon;
	document.n6form.commentText.focus();	
}
function maxlength(obj){
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength) {
        obj.value=obj.value.substring(0,mlength);
        alert('The maximum length for the comment is '+ mlength + ' characters.');
    }
    var target = document.getElementById('commentText');
    if (target.clientHeight < target.scrollHeight) {
        target.style.height = target.scrollHeight + "px";
    }
}
function setFocus(area) {
    var x =document.getElementById(area);
    x.scrollIntoView();
}
function show(id) {
  if (document.getElementById) {
	  document.getElementById(id).style.display="block";
	} else if (document.all) {
	  document.all[id].style.display="block";
	} else if (document.layers) {
	  document.layers[id].display="block";
	}
	
}
function hide(id) {
  if (document.getElementById) {
	  document.getElementById(id).style.display="none";
	} else if (document.all) {
	  document.all[id].style.display="none";
	} else if (document.layers) {
	  document.layers[id].display="none";
	}
}
var isShown = false;
function toggle(id)
{
	if(isShown){
		hide(id);
		isShown = false;		
	}
	else
	{
		show(id);
		isShown = true;		
	}
}
function menu_selected (id)  {
  document.cookie="MenuID="+id + ";path=/;domain=.harnesslink.com";
}
///track back
function getUrl() {
    if (document.getElementById('checkbox').checked) {
        document.getElementById('trackbackcondition').style.display='none';
        document.getElementById('trackbackurl').style.display='block';
    }
    else {
        alert('You have to read and agree to the trackback guidelines.');
    }
}
function showCondition() {
    if (!document.getElementById('checkbox').checked) {
        document.getElementById('trackbackcondition').style.display='block';
    }
}
function bookmark()
{
	var title = document.title;
	var href = location.href;
	if(window.sidebar)
	{
		window.sidebar.addPanel('Harnesslink - ' + title, href, '');	
	}
	else if(window.opera && window.print)
	{
		var tem = document.createElement('a');
		tem.setAttribute('rel', 'sidebar');
		tem.setAttribute('href', href);
		tem.setAttribute('title', title);
		tem.click();
	}
	else if(document.all)
	{
		window.external.AddFavorite(href, 'Harnesslink - ' + title);
	}
}

function resizeItem(id, width)
{
	var ele = document.getElementById(id);
	var tag = ele.getElementsByTagName('img');
	var tol = tag.length;
	var img = new Image();	
	var ws = new Array();
	if(tol>0)
	{		
		for(var i=0; i<tol; i++)
		{
			img.src = tag.item(i).src;
			if(img.src.indexOf("/images/thumbnails/") == -1)
			{
				ws.push(img.width);
			}
		}
	}
	else
	{
		alert('no images found inside' + id);
	}
	
	var w = Array.max(ws); 
	if(w < width)
	{
		ele.style.width = w + 'px';
	}	 
	else
	{
		ele.style.width = width + 'px';
	}
}
function shareThis(type) {
    title = encodeURIComponent( $('#articleTitle').text() );
    summary = encodeURIComponent( $('.articleSummary').text() );
    url = encodeURIComponent ( location.href );
    if (type == 'google') target = 'http://www.google.com/bookmarks/mark?op=add&bkmk=' + url + '&title=' + title;
    else if (type == 'live') target = 'http://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url='+url+'&title='+title+'&top=1';
    else if (type == 'digg') target = 'http://digg.com/submit?url='+ url + '&title=' + title+ '&bodytext=' + summary +'&media=news&topic=other_sports';
    else if (type == 'newsvine') target = 'http://www.newsvine.com/_tools/seed&save?u='+url+'&h='+title + '&s=' + summary;
    else if (type == 'furl') target = 'http://www.furl.net/savedialog.jsp?p=1&u=' + url + '&t=' + title + '&r=&v=1&c=';
    else if (type == 'yahoo') target = 'http://myweb.yahoo.com/myresults/bookmarklet?ei=UTF-8&u=' + url + '&t=' + title;
    else if (type == 'del') target = 'http://del.icio.us/post?v=3&url=' + url + '&title=' + title;
    else if (type == 'ask') target ='http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&url=' + url + '&title= ' + title + '&abstext=' + summary;
    else if (type == 'facebook') target = 'http://www.facebook.com/sharer.php?u='+url+'&t='+title;
    else if (type == 'stumbleupon') target ='http://www.stumbleupon.com/submit?url='+url+'&title='+title;
    window.open(target, 'ShareThis', 'width=600,height=420,scrollbars=yes,menubar=no,location=no,status=no');
    return false;
}

function setHomeDropBox()
{
	if (document.all)
	{
		var ele = document.getElementById('setHomeOnIE');
		ele.addBehavior("#default#homepage");
		ele.setHomePage(location.href);
	}
	else
	{
		var dropBox = document.getElementById('setHomeDropBox');
		dropBox.style.display = 'block';
	}
}
function disposeDropBox()
{
	var dropBox = document.getElementById('setHomeDropBox');
	dropBox.style.display = 'none';
}
