// JavaScript Document
/*
	called from dynamic blog entries
	Usage within blog admin:
	...
	...
	...
	<a href=javascript:_show_('test')>ViewNow</a>
	<div id='test' style='display:none;'>
		Some content for 'x'
	</div>
	...
	...
	...
	The HTML source above will set the <div> to be visible 
*/
function _show_(eid) {
	document.getElementById(eid).style.display = "block";
}
function _hide_(eid){
	document.getElementById(eid).style.display = "none";
}
//
//
//
function formatStringAsImage( str ){
	if (str == null || str == undefined) {
		str = '-';
	}
	var strArray = str.toLowerCase().split('');
	var imageStr = "";
	for ( var i = 0 ; i < strArray.length ; i++ ) {
		if (strArray[i] == ' '){
			imageStr += "&nbsp;&nbsp;&nbsp;";
		}else if ( strArray[i].match(/[0-z,&?]/) == null ){
			imageStr += strArray[i];
		}else{
			imageStr += "<img border='0' alt='"+strArray[i]+"'";
			imageStr += "src='img/alphabets/"+ strArray[i]+".gif" +"'";
			imageStr += "</img>";
		}
	}
	return imageStr;
}
var lh;
function loadHistory(){
	clearTimeout(lh);
	try{
		top.frames["historytracker"].location.href = "unloader.php";
	}catch(e){
		alert(e);
	}
}
function reloadHistory(){
	lh = setTimeout(loadHistory,100);
}
//
//	Need to resolve this issue
//
function removeJPEGError(str){
	var idiot = "Not a JPEG file: starts with 0x47 0x49";
	while(str.match(idiot) != null){
		str = str.replace(idiot, "");
	}
	return str;
}
//
//	History Stack Implementation
//
function ajaxGoBack(){
	//alert("Items in history (bef): "+historyStack.toString());
	try{
		var dumdum = historyStack.pop();
		//alert("Items in history (aft this action): "+historyStack.toString());
		//var lastVisited = historyStack.pop();
		var vIndex = historyStack.length;
		var lastVisited = historyStack[vIndex-1];
		if (vIndex>0) {
			var arr = lastVisited.split("|");
			//alert(arr[0] + ", page " + arr[1]);
			isHistory = true;
			historyPage = arr[1];
			//alert("Category: "+arr[0]+", page: "+arr[1]);
			if (arr[0] == "*") {
				viewAllEntries();
			}else{
				viewByCategories(arr[0]);
			}
		} else {
			//alert("No more pages left in the history stack!");
		}
	}catch(e){
		//
	}
}
function ajaxStoreNav(category_id, page_no){
	try{
		historyStack.push(category_id + "|" + page_no );
	}catch(e){
		//
	}
}