var root = "http://www.indianbytes.com/"
var summarydiv
function getsummary(id)
{
summarydiv = 'summarydiv-'+id;
$('summarydiv-'+ id).style.display = "";
$('summaryshowa-'+ id).style.display = "none";
$('summaryhidea-'+ id).style.display = "";
var url = root + "getstory.php";
var params = "id=" + id;
$('summarydiv-'+ id).innerHTML = "<p style='text-align:center;'><img src='" + root + "/images/AjaxRefresh.gif' /></p>";
 var myAjax = new Ajax.Updater(
 {success: 'summarydiv-'+ id},
 url,
 {
 method: 'post',
 parameters: params,
 onFailure: showError,
 onComplete:showSuccess
 });

}
function hidesummary(id)
{
	$('summarydiv-'+ id).style.display = "none";
	$('summaryshowa-'+ id).style.display = "";
	$('summaryhidea-'+ id).style.display = "none";
}
function showError(request)
{
 alert('An Error was encountered. Please try again');
}
function showSuccess()
{
	checkimagesize();
}
function getsidebar(type,target,nameofpage,categoryname)
{

var url = root + "getcomments.php";
var params = "type=" + type + "&nameofpage=" + nameofpage + "&categoryname=" + categoryname;
$(target).innerHTML = "<p style='text-align:center;'><img src='" + root + "/images/AjaxRefresh.gif' /></p>";
 var myAjax = new Ajax.Updater(
 {success: target},
 url,
 {
 method: 'get',
 parameters: params,
 onFailure: showError
 });
}
function ChooseCategory(categoryElement,categoryId)
{
	chosenCategory = categoryElement;
	//alert(chosenCategory.parentNode.id);
	$('category').value =  categoryId;
	f = $$('li.selected');
	for(var i=0; i<f.length; i++)
	{
		f[i].className = '';
	}
	chosenCategory.parentNode.className='selected';
	return false;
}

/*$$('categorycheck').each(function(item)
	{
      Event.observe(item, 'click', function(event){ alert('clicked!');});
    }
	)
*/
function checkimagesize(sumcontainer)
{
	var imageNodeList = $(summarydiv).getElementsByTagName('img');

	for (i = 0; i < imageNodeList.length; i++)
	{
		
		width = imageNodeList[i].width;
		height = imageNodeList[i].height;

		 maxWidth = 600;
		 maxHeight = 800;
		 
		 if ( width > maxWidth )
		 {
			height = height * (maxWidth/imageNodeList[i].width)
			width = maxWidth;
			
		 }
		 if ( height > maxHeight )
		 {
			width = width * (maxHeight/imageNodeList[i].height)
			height = maxHeight;
			
		 }

		 imageNodeList[i].width = width;
		 imageNodeList[i].height = height;
		 
	}
}

function checkimages()
{

 for (i = 0; i < document.images.length; i++)
 {
	 while ( !document.images[i].complete )
	 {
		break;
	 }

	 if(!document.images[i].parentNode.id  || (document.images[i].parentNode.id.indexOf('ls_contents') < 0 && document.images[i].parentNode.id.indexOf('comment_content') < 0))
	 continue;

	 width = document.images[i].width;
	 height = document.images[i].height;

 maxWidth = 500;
 maxHeight = 200;
 isStoryPage = (location.href.indexOf("\/story.php?") > 0);

 if(isStoryPage)
 {
	maxWidth = 640;
	maxHeight = 800;
	
 }

 if ( width > maxWidth )
 {
	height = height * (maxWidth/document.images[i].width)
	width = maxWidth;
	
 }
 if ( height > maxHeight )
 {
	width = width * (maxHeight/document.images[i].height)
	height = maxHeight;
	
 }

 document.images[i].width = width;
 document.images[i].height = height;
 }
}
function marksc(scid,sctype,target)
{
	alert(scid);
	var url = root + "mark_as.php";
	var params = "sid=" + scid + "&sctype=" + sctype;
	//$('summarydiv-'+ id).innerHTML = "<p style='text-align:center;'><img src='" + root + "/images/AjaxRefresh.gif' /></p>";
	 var myAjax = new Ajax.Updater(
	 {success: target},
	 url,
	 {
	 method: 'get',
	 parameters: params,
	 onFailure: showError
	 });
}