	function lookup(inputString) {
		if(inputString.length == 0) {
			$('#suggestions').hide();
		} else {
			$.post("../ajax/upac.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} 
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}
	
	function lookup_search(inputString) {
		if(inputString.length == 0) {
			$('#srchsuggestions').hide();
		} else {
			$.post("../ajax/ac.php?op=srch", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#srchsuggestions').show();
					$('#srchautoSuggestionsList').html(data);
				}
			});
		}
	} 
	
	function fill_search(thisValue) {
		$('#srchinputString').val(thisValue);
		setTimeout("$('#srchsuggestions').hide();", 200);
	}
	
	function fill_taglink(thisValue) {
		$('#taginputString').val(thisValue);
		setTimeout("$('#tagsuggestions').hide();", 200);
	}
	
	function lookup_taglink(inputString) {
		if(inputString.length == 0) {
			$('#tagsuggestions').hide();
		} else {
			$.post("../ajax/tag.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#tagsuggestions').show();
					$('#tagautoSuggestionsList').html(data);
				}
			});
		}
	} 
	
	function search(){
		var content = document.getElementById('srchinputString').value;
		if(content!="search" && content!=""){
			if(content.search(/exact:/i)>=0){
			content = content.replace(/exact:/i,"");
			window.location = "../../search2/"+ content.replace(/ /g,'+');
			}else{
			window.location = "../../search/"+ content.replace(/ /g,'+');
			}
		}else{
			//alert("Search error.");
			$.blockUI({
				theme:	true,
				title:	'Error Occured',
				message:	'<p>Search error.</p>',
				timeout: 3000
			});
		}
	}
	
	function enterpressed(e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;

		if (keycode == 13){search();}
	}
	
	function editabout(){
		$.post("../ajax/editabout.php", {queryString: ""}, function(data){
				if(data.length >0) {
					document.getElementById('prof_editabout').innerHTML = '<textarea id="aboutmeinput" cols="65" rows="5">' + data.replace(/<br>/g, "") + '</textarea><br/><input type="button" onclick="saveabout();" value="Save"/>';	
				}else{
					document.getElementById('prof_editabout').innerHTML = '<textarea id="aboutmeinput" cols="65" rows="5">Enter here.</textarea><br/><input type="button" onclick="saveabout();" value="Save"/>';	
				}
			});
	}
	
	function editprofic(){
	
	}
	
	function saveabout(){
		var content = document.getElementById('aboutmeinput').value;
		$.post("../ajax/editabout.php?op=edit", {queryString: "" + content + ""}, function(data){
				if(data.length >0) {
					document.getElementById('prof_editabout').innerHTML = '<p>' + data + '<a href="#edit" onclick="editabout(); return false;"><img src="../../style/default/images/edit.png"></a></p>';	
				}
			});
	}
	
	function voteup(imgid,type){
		$.post("../../ajax/vote.php?do=voteup&imgid=" + imgid, {queryString: ""}, function(data){
					if(data.length>0){
						if(data.search("already")<0){
						document.getElementById('vote').innerHTML = data;
						}else{
							$.blockUI({
							theme:	true,
							title:	'Error Occured',
							message:	'<p>' + data + '</p>',
							timeout: 3000
							});
						}
					}else{
						$.blockUI({
							theme:	true,
							title:	'Error Occured',
							message:	'<p>Unknown Error occured when submitting vote.</p>',
							timeout: 3000
						});
						
					}
				});
	}
	
	function votedown(imgid,type){
		$.post("../../ajax/vote.php?do=votedown&imgid=" + imgid, {queryString: ""}, function(data){
					if(data.length>0){
						if(data.search("already")<0){
						document.getElementById('vote').innerHTML = data;
						}else{
							$.blockUI({
							theme:	true,
							title:	'Error Occured',
							message:	'<p>' + data + '</p>',
							timeout: 3000
							});
						}
					}else{
						$.blockUI({
							theme:	true,
							title:	'Error Occured',
							message:	'<p>Unknown Error occured when submitting vote.</p>',
							timeout: 3000
						});
					}
				});
	}
	
	function forgetpass(){
		$.blockUI({
			theme:	true,
			title:	'Email Address',
			message:	'<input type="text" name="forgot_email" id="forgot_email" class="smallfont" value="" size="33">&nbsp;<input class="smallfont" type="button" value="Recover" onclick="sendemail();"/>&nbsp;<input class="smallfont" type="button" value="Close" onclick="$.unblockUI();">',
		});
	}
	
	function sendemail(){
		email = document.getElementById('forgot_email').value;
		$.post("../../ajax/forgotpass.php", {queryString: ""+email+""}, function(data){
			if(data.length>0){
					$.blockUI({
					theme:	true,
					title:	'Information',
					message:	'<p>' + data + '</p>',
					timeout: 3000
					});
			}
		});
	}
	
	function replycomment(cmntid,userid){
		$.blockUI({
			theme:	true,
			title:	'Reply to Comment',
			message:	'<input id="reply" size="48" class="smallfont"><input class="smallfont" type="button" onclick="sendreply(' + cmntid + ',' + userid + ');" value="Reply"/>&nbsp;<input class="smallfont" type="button" value="Close" onclick="$.unblockUI();">',
		});
	}
	
	function redirect(urlc) {
	window.location = urlc;
	}
	
	function sendreply(cmntid,userid){
		reply = document.getElementById('reply').value;
		imageid = document.getElementById('imgid').value;
		if(userid!=0){
			$.post("../../ajax/replycomment.php", {queryString: ""+reply+"",cmntid: ""+cmntid+"",imgid: ""+imageid+""}, function(data){
				if(data.length>0){
						$.blockUI({
						theme:	true,
						title:	'Information',
						message:	'<p>' + data + '</p>',
						});
						setTimeout(redirect("../../image/"+ imageid), 3000);
				}
			});
		}else{
			$.blockUI({
			theme:	true,
			title:	'Login Required',
			message:	'<p>Please Login to reply this comment.</p>',
			timeout: 3000
			});
		}
	}
	
	function imgmod(){
		$.post("../ajax/ajaxmod.php", {queryString: ""}, function(data){
			if(data.length >0) {
					$.blockUI({
					theme:	true,
					title:	'Modpanel',
					message:	data,
					css: { width: 'auto', height: 'auto'}
					});
			}
		});
	}
	
	function closedialog(){
		setTimeout($.unblockUI, 0); 
	}

	function cnext(){
		pstopid = document.getElementById('pstop').value;
			$.blockUI({
						theme:	true,
						title:	'Loading',
						message:	'<p>Please wait....</p>',
						timeout: 5000
						});
		var tmp;
		$.post("../ajax/catajax.php", {pstop: ""+pstopid+""}, function(data){
			if(data.length >0) {
					tmp = data.split("|::|");
					$(".browse_box").append(tmp[0]);
					document.getElementById('pstop').value = tmp[1]*1 + pstopid*1;
					setTimeout($.unblockUI, 0); 
			}
		});
	}
	
	function bnext(){
		pstopid = document.getElementById('pstop').value;
			$.blockUI({
						theme:	true,
						title:	'Loading',
						message:	'<p>Please wait....</p>',
						timeout: 5000
						});
		var tmp;
		$.post("../ajax/browseajax.php", {pstop: ""+pstopid+""}, function(data){
			if(data.length >0) {
					tmp = data.split("|::|");
					$(".browse_box").append(tmp[0]);
					document.getElementById('pstop').value = tmp[1]*1 + pstopid*1;
					setTimeout($.unblockUI, 0); 
			}
		});
	}
	
	function alnext(){
		pstopid = document.getElementById('pstop').value;
		palbumid = document.getElementById('albumid').value;
			$.blockUI({
						theme:	true,
						title:	'Loading',
						message:	'<p>Please wait....</p>',
						timeout: 5000
						});
		var tmp;
		$.post("../ajax/viewalbumajax.php", {pstop: ""+pstopid+"",albumid: ""+palbumid+""}, function(data){
			if(data.length >0) {
					tmp = data.split("|::|");
					$(".browse_box").append(tmp[0]);
					document.getElementById('pstop').value = tmp[1]*1 + pstopid*1;
					setTimeout($.unblockUI, 0); 
			}
		});
	}
	
	function snext(){
		pstopid = document.getElementById('pstop').value;
		srchidid = document.getElementById('srchid').value;
		stypeid = document.getElementById('stype').value;
			$.blockUI({
						theme:	true,
						title:	'Loading',
						message:	'<p>Please wait....</p>',
						timeout: 5000
						});
		var tmp;
		$.post("../ajax/srchajax.php", {pstop: ""+pstopid+"",srchid: ""+srchidid+"",stype: ""+stypeid+""}, function(data){
			if(data.length >0) {
					tmp = data.split("|::|");
					$("#imgbox").append(tmp[0]);
					document.getElementById('pstop').value = tmp[1]*1 + pstopid*1;
					setTimeout($.unblockUI, 0); 
			}
		});
	}
	
	
	function checkupdates(){
		uptime = document.getElementById('updatetime').value;
		$.post("../ajax/mainreload.php", {updatetime: ""+uptime+""}, function(data){
			if(data.length >0) {
					tmp = data.split("|::|");
					document.getElementById('imgboxes').innerHTML = tmp[0];
					document.getElementById('updatetime').value = tmp[1];
			}
		});
		setTimeout("checkupdates()", 60000); 
	}
	
	function addtag(){
		imgid = document.getElementById('imgid').value;
		$.blockUI({
						theme:	true,
						title:	'Add tag for image # '+ imgid,
						message:	'<p><input type="text" id="newtag" size="51" />&nbsp;<input type="button" value="Add" onclick="save_addtag()"/>&nbsp;<input type="button" value="Close" onclick="closedialog()"/><br/><span class="smallfont required">(Separated by comma.)</span></p>',
						});
	}
	
	function cfl(string)
	{
		return string.charAt(0).toUpperCase() + string.slice(1);
	}
	
	function save_addtag(){
		pimgid = document.getElementById('imgid').value;
		ptag = document.getElementById('newtag').value;
		curtags = document.getElementById('curtags').innerHTML;
			$.post("../ajax/tag_ajax_add.php", {imgid: ""+pimgid+"",tag: ""+ptag+""}, function(data){
				if(data.length >0) {
						$.blockUI({
						theme:	true,
						title:	'Add tag for image # '+ imgid,
						message:	'<p>'+os_msgstring(data)+'</p>',
						});
						if(chkrep==101) document.getElementById('curtags').innerHTML = curtags + ', <a href="../search/' + cfl(ptag) + '">' + cfl(ptag) + ' </a>';
						setTimeout($.unblockUI, 3000); 
				}
				});
	}
	
	var reverttag;
	
	function edittag(){
		var tmp;
		reverttag = document.getElementById('curtags').innerHTML;
		pimgid = document.getElementById('imgid').value;
		$.post("../ajax/tag_ajax_edit.php?do=edit", {imgid: ""+pimgid+""}, function(data){
				if(data.length >0) {
					tmp = data.split(" ");
					if(tmp[1]>0){
						$.blockUI({
						theme:	true,
						title:	'Edit Tag',
						message:	'<p>'+os_msgstring(data)+'</p>',
						timeout: 3000
						});
					}else{
					document.getElementById('curtags').innerHTML = 'tags : <span class="required smallfont">(separated by comma)</span><textarea id="edittags" cols="50" rows="3">'+data+'</textarea><br/></span>&nbsp;<input type="button" value="Save" onclick="savetag()"/>&nbsp;<input type="button" value="Close" onclick="revert()">';
					}
				}
				});
	}
	
	function savetag(){
		pimgid = document.getElementById('imgid').value;
		pedittags = document.getElementById('edittags').value;
		$.post("../ajax/tag_ajax_edit.php?do=save", {tag: ""+pedittags+"",imgid: ""+pimgid+""}, function(data){
				if(data.length >0) {
					tmp = data.split(" ");
					if(tmp[1]>0){
						$.blockUI({
						theme:	true,
						title:	'Edit Tag for image # '+ pimgid,
						message:	'<p>'+os_msgstring(data)+'</p>',
						timeout: 3000
						});
					}else{
					document.getElementById('curtags').innerHTML = 'tags : '+data;
					}
				}
				});
	}
	
	
	
	function revert(){
		document.getElementById('curtags').innerHTML = reverttag;
	}
	
	function showalbums(){
		$.post("../ajax/ajaxshowalbum.php?do=show", {aid: ""}, function(data){
				if(data.length >0) {
						tmp = data.split(" ");
						if(tmp[1]>0){
							$.blockUI({
							theme:	true,
							title:	'Add to album',
							message:	'<p>'+os_msgstring(data)+'</p>',
							timeout: 3000
							});
						}else{
						$.blockUI({
						theme:	true,
						title:	'Add to album',
						message:	'<p>'+data+'</p><br/><input class="smallfont" type="button" value="Add to this Album" onclick="addtoalbum();"/>&nbsp;<input class="smallfont" type="button" value="Close" onclick="$.unblockUI();">',
						});
						}
				}
				});
	}
	
	function addtoalbum(){
		pimgid = document.getElementById('imgid').value;
		palbumid = $("input[@name=myalbum]:checked").val();
		if(palbumid>0){
		$.post("../ajax/ajaxalbum.php", {aid: ""+palbumid+"",imgid: ""+pimgid+""}, function(data){
				if(data.length >0) {
						$.blockUI({
						theme:	true,
						title:	'Add to album',
						message:	'<p>'+os_msgstring(data)+'</p>',
						timeout: 3000
						});
				}
				});
		}else{
			alert('Please Select an album.');
		}
	}
	
	function createalbum(){
		$.blockUI({
						theme:	true,
						title:	'Name of your album',
						message:	'<p><input type="text" id="createalbum" size="51" maxlength="32" />&nbsp;<input type="button" value="Create" onclick="savenewalbum()"/>&nbsp;<input type="button" value="Close" onclick="closedialog()"/></p>',
						});
	}
	
	function savenewalbum(){
		newalbum = document.getElementById('createalbum').value;
			$.post("../ajax/ajax_newalbum.php", {alname: ""+newalbum+""}, function(data){
				if(data.length >0) {
						$.blockUI({
						theme:	true,
						title:	'Creating New Album',
						message:	'<p>'+os_msgstring(data)+'</p>',
						});
						setTimeout($.unblockUI, 3000); 
				}
				});
	}
	
	function deletealbum(aid){
		var answer = confirm('Delete Album?');
		if(answer==true){
			$.post("../ajax/ajax_delalbum.php", {albumid: ""+aid+""}, function(data){
				if(data.length >0) {
						$.blockUI({
						theme:	true,
						title:	'Delete Album ID # '+ aid,
						message:	'<p>'+os_msgstring(data)+'</p>',
						});
						setTimeout($.unblockUI, 3000); 
				}
				});
		}
	}
	
	function delimgalbum(aid,pimgid){
		var answer = confirm('Delete Image in this album?');
		if(answer==true){
			$.post("../ajax/ajax_delimgalbum.php", {albumid: ""+aid+"",imgid: ""+pimgid+""}, function(data){
				if(data.length >0) {
						$.blockUI({
						theme:	true,
						title:	'Delete Album ID # '+ aid,
						message:	'<p>'+os_msgstring(data)+'</p>',
						});
						setTimeout($.unblockUI, 3000); 
				}
				});
		}
	}
	

