var xmlHttp;
function GetXmlHttpObject() {
	var objXMLHttp=null
	if(window.XMLHttpRequest) {
  		objXMLHttp=new XMLHttpRequest();
  	} else if (window.ActiveXObject) {
  		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return objXMLHttp
}
function showPicture(picsurf) {
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null) {
  		alert ("Browser does not support HTTP Request");
  		return;
  	} 
  	var picnum = getPicnum(picsurf, 1, 7);
	var url="index.php?picnum="+picnum+
	"&sid="+Math.random();
	xmlHttp.onreadystatechange=displayPic ;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
} 

var NS4 = (document.layers);
var IE4 = (document.all);
var ver4 = (NS4 || IE4);
var IE5 = (IE4 && navigator.appVersion.indexOf("5.")!=-1);
var isMac = (navigator.appVersion.indexOf("Mac") != -1);
var isMenu = (NS4 || (IE4 && !isMac) || (IE5 && isMac));
var helpWindow;
var statusWindowList = "";
var statusWindowClosedList = "";

function strSearch(sub, str) {
  return str.toLowerCase().indexOf(sub.toLowerCase(), 0) + 1;
}
function isDOM() {
  if (document.getElementById) {
    return true;
  } else {
    return false;
  }
}
function isNS() {
  if (strSearch("netscape", navigator.userAgent)) {
    return true;
  } else {
    return false;
  }
}
function isNetscapeVersionAcceptable() {
  // Netscape UserAgent 6.0+ Format:
  // Netscapex/x.y or Netscape/x.y
  if (document.layers) {
    return false;
  }
  var x = strSearch("netscape", navigator.userAgent);
  if (!x) {
    return false;
  } else {
    return (navigator.userAgent.substring(x+7).split("/")[1].split(" ")[0] >= 7.01);
  }
}
function isMicrosoft() {
  if (strSearch("msie", navigator.userAgent) && !isOpera()) {
    return true;
  } else {
    return false;
  }
}
function isMicrosoftVersionAcceptable() {
  // Microsoft UserAgent 3.0+ Format:
  // Mozilla/version (compatible; MSIE version; Operating system; Extensions)
  return (navigator.userAgent.split(" ")[3].split(";")[0] >= 5.5);
}
function isFirefox() {
  if (strSearch("firefox", navigator.userAgent)) {
    return true;
  } else {
    return false;
  }
}
function isFirefoxVersionAcceptable() {
  // Firefox UserAgent 5.0+
  // Firefox/version
  var x = strSearch("firefox", navigator.userAgent);
  if (!x) {
    return false;
  } else {
    return (navigator.userAgent.substring(x+7).split(" ")[0] >= 1);
  }
}
function isOpera() {
  if (strSearch("opera", navigator.userAgent)) {
    return true;
  } else {
    return false;
  }
}
function checkBrowser() {
	if(isFirefox()) {
		alert("You are using Firefox.\nTuliKalom is best viewed using \"Internet Explorer 5.5\" onwards");
	} else if(isNS()) {
		alert("You are using Netscape.\nTuliKalom is best viewed using \"Internet Explorer 5.5\" onwards");
	} else if(isOpera()) {
		alert("You are using Opera.\nTuliKalom is best viewed using \"Internet Explorer 5.5\" onwards");
	} else if(!isMicrosoftVersionAcceptable()) {
		alert("You are using an older version of Internet Explorer.\nTuliKalom is best viewed using \"Internet Explorer 5.5\" onwards");
	} else if(!isMicrosoft()) {
		alert("You are using an unknown browser.\nTuliKalom is best viewed using \"Internet Explorer 5.5\" onwards");
	}
}
function adjustChildMenuPosition() {
	document.getElementById("contentArea").style.height = document.body.clientHeight - 188;
	var leftBoundary = 0;
	if(document.body.clientWidth > 860)
		leftBoundary = (document.body.clientWidth - 860) / 2;
	var childMenuLeft = leftBoundary + 129;
	childMenuLeft = childMenuLeft + 22;
	document.getElementById("childMenu4").style.left = childMenuLeft;
	document.getElementById("childMenu5").style.left = childMenuLeft;
	document.getElementById("childMenu6").style.left = childMenuLeft;
	document.getElementById("childMenu9").style.left = childMenuLeft;
	document.getElementById("childMenu10").style.left = childMenuLeft;
}


function getPicnum(picsurf, min, max) {
	var picnum = parseInt(document.getElementById("picnum").value);
	if(picsurf=="next") {
		if(picnum<max) {
			picnum = picnum + 1;
		} else {
			picnum = min;
		}
	} else {
		if(picnum>min) {
			picnum = picnum - 1;
		} else {
			picnum = max;
		}	
	}
	document.getElementById("picnum").value = picnum;
	return picnum;
	
}
function ltrim(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rtrim(sString)  {
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function trim(sString) {
	sString = ltrim(sString);
	sString = rtrim(sString);
	return sString;
}
function ismaxlength(obj) {
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength)
	}
}
function displayPic() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {  		
 		document.getElementById("pictureholder").innerHTML=xmlHttp.responseText;
 	} 
} 
function showPage(pagenum) {
	document.forms[0].pagenum.value = pagenum;
	document.forms[0].submit();
}
function movefocus(num) {
	document.getElementById("menuRow"+num).className='td_grey';
	document.getElementById("menuItem"+num).className='menu_blue';	
}
function losefocus(num) {
	document.getElementById("menuRow"+num).className='td_normal';
	document.getElementById("menuItem"+num).className='menu_normal';
}
function showChildMenu(num) {
	document.getElementById("childMenu"+num).style.visibility='visible';
}
function hideChildMenu(num) {
	document.getElementById("childMenu"+num).style.visibility='hidden';
}
function submitOpinion() {
	if(trim(document.getElementById("readerName").value) == "") {
		alert("Please Enter Your Name.");
		document.getElementById("readerName").focus();
		return;
	}
	if(trim(document.getElementById("opinionText").value) == "") {
		alert("Please Enter Your Opinion.");
		document.getElementById("opinionText").focus();
		return;
	}	
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null) {
  		alert ("Browser does not support HTTP Request");
  		return;
  	} 
  	//document.getElementById("opinionText").value = convertToEntities(trim(document.getElementById("opinionText").value));
  	//document.getElementById("readerName").value = convertToEntities(trim(document.getElementById("readerName").value))
	var url="index.php?opinionText="+convertToEntities(trim(document.getElementById("opinionText").value))+
	"&readerName="+convertToEntities(trim(document.getElementById("readerName").value))+
	"&sid="+Math.random();
	xmlHttp.onreadystatechange=displayOpinions ;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}
function displayOpinions() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("readerName").value = "";
		document.getElementById("opinionText").value = "";
		document.getElementById("opinionPane").innerHTML=xmlHttp.responseText;
	}
}
function convertToEntities(tstr) {
  var bstr = '';
  for(i=0; i<tstr.length; i++)
  {
    if(tstr.charCodeAt(i)>127)
    {
      bstr += '|' + tstr.charCodeAt(i) + ';';
    }
    else
    {
      bstr += tstr.charAt(i);
    }
  }
  return bstr;
}