function TimeNow(){
	var currentTime = new Date()
	var sec = "" + currentTime.getSeconds() + "";
	var min = currentTime.getMinutes();
	var hrs = currentTime.getHours();
	if(sec.length == 1){
		sec = "0"+sec;
	}
	var timenow = hrs + ':' + min + ':' + sec;
	return timenow;
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}

String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.ltrim=function(){
    return this.replace(/^\s*/g,'');
}

String.prototype.rtrim=function(){
    return this.replace(/\s*$/g,'');
}

function disableButton(formobj){
	document.getElementById('proceed').value = 'please wait...';
	document.getElementById('proceed').disabled = true;
	document.getElementById('submitted').value = 'TRUE';
	formobj.submit();
}
function writeConsole(title,content) {
		top.consoleRef=window.open('','myconsole',
		'width=350,height=250'
		+',menubar=0'
		+',toolbar=0'
		+',status=0'
		+',scrollbars=1'
		+',resizable=1')
		top.consoleRef.document.writeln(
		'<html>'
		+ '<head><title>'+title+'</title>'
		+ '<LINK REL=\'stylesheet\' TYPE=\'text/css\' HREF=\'../_style/css/style.css\'>'
		+ '</head>'
		+'<body bgcolor=white onLoad=\"self.focus()\">'
		+content
		+'</body></html>'
		)
		top.consoleRef.document.close()
}

function trim(str) {
    var stra = str.replace(/^\s+/, '');
    return stra.replace(/\s+$/, '');
}
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function ajaxLogin() {
	var status = arguments[0];
	if(status == 'successful. redirecting...'){
		location.href='./index.pl';
	}
	document.getElementById('message').innerHTML = status;
}

function checkAll(chk){
	for (i = 0; i < chk.length; i++){
		chk[i].checked = true ;
	}
}
function unCheckAll(chk){
	for (i = 0; i < chk.length; i++){
		chk[i].checked = false ;
	}
}
function load_photo(path,width,height,desc){
	//image = this.open("", "", "width="+ width +", height="+height+", toolbar=no,menubar=no,location=no,scrollbars=no,resize=yes");
	//image.document.write("<TITLE>"+desc+"</TITLE><IMG SRC=\"" + path + "\" WIDTH=" + width + " HEIGHT=" + height + ">");
	window.open(path, "", "width="+ width +", height="+height+", toolbar=no,menubar=no,location=no,scrollbars=no,resize=yes");
}
function load_win(path,width,height){
	var winW = width, winH = height;
	if(width != 0 && height != 0){
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
				winW = window.innerWidth;
				winH = window.innerHeight;
		 	}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			}
		}
	}
	win = window.open(path,"", "width="+ width +", height="+height
		+',menubar=0'
		+',toolbar=0'
		+',status=0'
		+',scrollbars=1'
		+',resizable=1');
	win.moveTo(0,0);
}

function loadpaper(paperid,from){
	alert('These papers are the personal collection of Wilson Wong for use by him and his co-authors for publication purposes. However, if you decide to read this paper here and now, you agree to adhere to whatever constraints invoked by the paper\'s copyright holder. You agree not to keep a local copy or distribute without the explicit permission of the copyright holder.');
	if(from == 'publication'){
		image = this.open("./load.php?id="+paperid, "", "");
	}
	else{
		image = this.open("http://publication.wilsonwong.me/load.php?id="+paperid, "", "");
	}
}

function switchMenu(objID) {
	var el = document.getElementById(objID);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
function switchMenuObj(obj) {
	if ( obj.style.display != "none" ) {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = '';
	}
}

function right(e) {
	var msg = "wilsonjoe.us";
	if (navigator.appName == 'Netscape' && e.which == 3) {
		alert(msg);
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
		return false;
	}
	else return true;
}

function trap(){
	if(document.images){
		for(i=0;i<document.images.length;i++){
			document.images[i].onmousedown = right;
			document.images[i].onmouseup = right;
		}
	}
}


