function isEmailAddr(email)
{
	
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
}

function Check()
{
	if(document.forgot.email.value == "")
	{
		alert("Email Address not given");
		document.forgot.email.focus();
		return false;
	}
	if(!isEmailAddr(document.forgot.email.value))
	{
		alert("Please provide correct email address in the form: yourname@yourdomain.com");
		document.forgot.email.focus();
		return false;
	}
	
	//document.forgot.submit();
}

function Check_Login()
{
	if(document.login.email.value == "")
	{
		alert("Email Address not given");
		document.login.email.focus();
		return;
	}
	if(!isEmailAddr(document.login.email.value))
	{
		alert("Please provide correct email address in the form: yourname@yourdomain.com");
		document.login.email.focus();
		return;
	}
	if(document.login.pass.value == "" || document.login.pass.value == "Enter password here")
	{
		alert("Password not given");
		document.login.pass.focus();
		return;
	}
	
	document.login.submit();
}

function Check_Login1()
{
	
	if(trim(document.login.email.value) == "")
	{
		alert("Email Address not given");
		document.login.email.focus();
		return false;
	}
	if(!isEmailAddr(document.login.email.value))
	{
		alert("Please provide correct email address in the form: yourname@yourdomain.com");
		document.login.email.focus();
		return false;
	}
	if(trim(document.login.pass.value) == "" || document.login.pass.value == "Password")
	{
		alert("Password not given");
		document.login.pass.focus();
		return false;
	}
	//document.login.submit();
	return true;
}

function Signup()
{
	var name = document.signup.nick.value;
		
	if(name.replace(/^\s*|\s*$/g, "") == "")
	{
		alert("Screen Name not given");
		document.signup.nick.focus();
		return;
	}
	if(document.signup.nick.value != "")
	{
			
			
			var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";

			  for (var i = 0; i < document.signup.nick.value.length; i++) {
				if (iChars.indexOf(document.signup.nick.value.charAt(i)) != -1) {
				alert ("Name has special characters. \nThese are not allowed.\n Please remove them and try again.");
				document.signup.nick.focus();
				return;
				}
			  }
	 }
	if(trim(document.signup.email.value) == "")
	{
		alert("Email Address not given");
		document.signup.email.focus();
		return;
	}
	if(!isEmailAddr(document.signup.email.value))
	{
		alert("Please provide correct email address in the form: yourname@yourdomain.com");
		document.signup.email.focus();
		return;
	}
	if(trim(document.signup.pass.value) == "")
	{
		alert("Password not given");
		document.signup.pass.focus();
		return;
	}
	if(document.getElementById("agr").checked == false)
	{
		alert("Please agree with term and conditions to continue signup!");
		document.getElementById("agr").focus();
		return;
	}
		//alert(document.signup.email.value);
		document.signup.submit();
}

function Check_Search()
{
	if(document.mysearch.searchtext.value == "")
	{
		alert("Nothing to search");
		document.mysearch.searchtext.focus();
		return false;
	}
	
	document.mysearch.submit();
}
function trim(str)
{
	 return str.replace(/^\s*|\s*$/g, "")

}
function Check_Availibility()
{
	if(trim(document.signup.nick.value) == "")
	{
		alert("Screen Name not given");
		document.signup.nick.focus();
		return;
	}
	
	url = "includes/script.php";
	
	param = "action="+ "availibility" + "&nick=" + document.signup.nick.value + "&rand="+ Math.floor(Math.random() * 1000000), true;
	target = "availibility";
	
	myAjax = new Ajax.Updater(target,url,{method: 'get', parameters: param});
}

function Confirm(photoId)
{
	if(photoId)
	{
		answer = window.confirm("Are you sure you want to delete this photo?");
					
		if(answer == true)
		{
			window.location="my-photos.php?action=delphoto&photoId="+photoId;
		}
	}
	else
	{
		alert("No photo to delete");
	}
}

function MakeDefault(photoId)
{
	answer = window.confirm("Are you sure you want to make this photo as your default photo?");
				
	if(answer == true)
	{
		window.location="my-photos.php?action=setdefault&photoId="+photoId;
		//alert("my-photos.php?action=setdefault&photoId="+photoId);
	}
}

function Error()
{
	alert("No photo to edit");
}

function AddPhoto()
{
	if(document.photo.image.value == "")
	{
		alert("No photo to upload");
		document.photo.image.focus();
		return false;
	}
	
	document.photo.submit();
}

function AddSticky()
{
	var pic=document.add.img.value;
	
	if(document.add.title.value == "")
	{
		alert("No name given");
		document.add.title.focus();
		return false;
	}
	
	if(pic!='')
	{
		
		var regobj =new RegExp("\.jpg$|\.png$|\.gif$","i");
		 if(!regobj.test(pic)) {
		  
		  alert('Only JPG, PNG and GIF format allowed');
		 // document.add.img.focus();
		   return false;
		
		  }
	
	}
	
	
		document.add.submit();
	
}

function EditSticky()
{
   var pic=document.edit.img.value;
	//alert(pic);
	if(document.edit.title.value == "")
	{
		alert("No name given");
		document.edit.title.focus();
		return false;
	}
	
	
	if(pic!='')
	{
		
		var regobj =new RegExp("\.jpg$|\.png$|\.gif$","i");
		 if(!regobj.test(pic)) {
		  
		  alert('Only JPG, PNG and GIF format allowed');
		 // document.add.img.focus();
		   return false;
		
		  }
	
	}
	
	 document.edit.submit();
}


function checkphoto()
{
   var pic=document.photo.image.value;
	//alert(pic);
	
	
	
	if(pic!='')
	{
		
		var regobj =new RegExp("\.jpg$|\.png$|\.gif$","i");
		 if(!regobj.test(pic)) {
		  
		  alert('Only JPG, PNG and GIF format allowed');
		 // document.add.img.focus();
		   return false;
		
		  }
		  
	document.photo.submit();
	}
	
	 
}