// JavaScript Document
	function populate(url,tagid)
	{
		new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText || "no response text";
				//alert("Success! \n\n" + response);
				document.getElementById(tagid).innerHTML = document.getElementById(tagid).innerHTML+response;
			},
			onFailure: function(){ 
				//alert('Something went wrong...') 
			}
		});
	}
	
	function insertComment(url,tagid)
	{
		name = document.getElementById('name').value;
		if(name == '')
		{
			alert('Please input your name');
			document.getElementById('name').focus();
			return false;
		}
		if(document.getElementById('email').value == '')
		{
			alert("Please input Email address");
			document.getElementById('email').focus();
			return false
		}
		else
		{
			if(!echeck(document.getElementById('email').value))
			{
				document.getElementById('email').focus();
				return false;
			}
		}
		if(document.getElementById('comment').value=="")
		{
			alert('Blank comments are not acceptable');
			document.getElementById('comment').focus();
			return false;
		}
		url += "&comment="+document.getElementById('comment').value+"&name="+name+"&email="+document.getElementById('email').value;
		document.getElementById('name').value = '';
		document.getElementById('email').value = '';
		document.getElementById('comment').value ='';
		//alert(url);
		populate(url,tagid);
		return true;
	}
	
	function openwindow()
	{
		mywindow = window.open("upload.php","Upload a photo","resizable=0,width=450,height=330");
		mywindow.moveTo(250,150);
	}
	
	function validateUpload()
	{
		if(document.getElementById('name').value == "")
		{
			alert('Please input name');
			document.getElementById('name').focus();
			return false;
		}
		if(document.getElementById('category').value == 0)
		{
			alert("Please select category");
			document.getElementById('category').focus();
			return false
		}
		/*else
		{
			if(!echeck(document.getElementById('email').value))
			{
				document.getElementById('email').focus();
				return false;
			}
		}*/
		if(document.getElementById('photoname').value == '')
		{
			alert("Please input photoname");
			document.getElementById('photoname').focus();
			return false;
		}
		/*if(document.getElementById('photo').value == '')
		{
			alert("Please input photo");
			document.getElementById('photo').focus();
			return false
		}*/
		var imageformat = document.getElementById('photo').value.match(/.(jpg|png|jpeg|gif)/gi);
		if(document.getElementById('photo').value == '')
		{
			alert("Please input Photo! ");
			document.getElementById('photo').focus();
			return false;
		}
		else
		{
			if((!imageformat) )
			{
				alert("File Name invalid! (JPG,GIf,PNG allowed)");
				document.getElementById('photo').focus();
				return false;
			}
		}
		//validateUserUpload();
		if(document.getElementById('description').value == '')
		{
			alert("Please input description");
			document.getElementById('description').focus();
			return false
		}
		return true;
	}
	
	function echeck(str) 
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if(str.indexOf(at)==-1)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.indexOf(at,(lat+1))!=-1)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.indexOf(dot,(lat+2))==-1)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		if(str.indexOf(" ")!=-1)
		{
			alert("Please Input Valid E-mail address")
			return false
		}
		return true					
	}	
	
	function SearchPhoto()
	{
		if(document.getElementById('txtsearch').value == '')
		{
			alert("Please input search text");
			document.getElementById('txtsearch').focus();
			return false
		}
		else
		{
			window.location.href = 'search.php?text='+document.getElementById('txtsearch').value;
		}
	}
	
	function validateUserUpload()
	{
		//errorupload = '';
		//var imageurl = document.getElementById('photo').value;
		var imageformat = document.getElementById('photo').value.match(/.(jpg|png|jpeg|gif)/gi);
		if(document.getElementById('photo').value == '')
		{
			alert("Please input Photo! ");
			//document.getElementById('photo').focus();
			return false;
		}
		else
		{
			if((!imageformat) )
			{
				alert("File Name invalid! (JPG,GIf,PNG allowed)");
				document.getElementById('photo').focus();
				return false;
			}
		}
		/*if (errorupload == '')
		{
			//return true
			document.getElementById('image_form').submit();
		}
		else
		{
			alert(errorupload);
			return false
		}*/
		return true;
	}	