function strTrim(tmpStr)
{
	var i;
	for (i=0; i < tmpStr.length; ++i)
		if (tmpStr.charAt(i) != " ") break;
	tmpStr = tmpStr.substring(i);
	for (i=tmpStr.length - 1; i >= 0; --i)
		if (tmpStr.charAt(i) != " ") break;
	tmpStr = tmpStr.substring(0, i + 1);
	return tmpStr;
}
//-----------------------------------------------------------------------------
function chkPhone(tmpStr)
{
    var i = 0, tmpChar = "";
    for (i = 0; i < tmpStr.length; ++i)
    {
    	tmpChar = tmpStr.charAt(i);
	if (!((tmpChar >= "0" && tmpChar <= "9")
		|| (tmpChar == "-")
		|| (tmpChar == "(")
		|| (tmpChar == ")")
		)) return false;
	}
    return true;
}
//-----------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var i;
	var posAt = 0;
	var posDot = 0
	var count = 0;
	for(i=0;i<tmpStr.length;++i)
	{
		if(tmpStr.charAt(i) == "@")
		{
			posAt = i;
			count++;
		}
		if(tmpStr.charAt(i) == ".")
		{
			posDot = i;
		}
		if (!((tmpStr.charAt(i) >= "0" && tmpStr.charAt(i) <= "9")
				||(tmpStr.charAt(i) >= "a" && tmpStr.charAt(i) <= "z")
				|| (tmpStr.charAt(i)>= "A" && tmpStr.charAt(i) <= "Z")
				|| (tmpStr.charAt(i) == "-")
				|| (tmpStr.charAt(i) == "_")
				|| (tmpStr.charAt(i) == "@")
				|| (tmpStr.charAt(i) == ".")
			)) return false;
	}
	if(count>1) return false;
	if(eval(posAt) > 1 && posAt != tmpStr.length-1 && posDot > posAt && posDot != tmpStr.length-1) return true;
	return false;
}
//-----------------------------------------------------------------------------
function SubmitPhoto()
{
	if(strTrim(obj.Caption.value) == "")
	{
		alert("Please enter a suitable Caption for your Photograph.");
		obj.Caption.focus();
		return;
	}
	if(strTrim(obj.PhotoFile.value) == "")
	{
		alert("Please attach the Image File you want to submit.");
		obj.PhotoFile.focus();
		return;
	}
	strImageType = obj.PhotoFile.value.substring(obj.PhotoFile.value.length-4,obj.PhotoFile.value.length);
	if(strImageType != ".gif" && strImageType != ".jpg" && strImageType != ".jpeg" && strImageType != ".GIF" && strImageType != ".JPG" && strImageType != "JPEG")
	{
		alert("The Photo file must be in GIF or JPG/JPEG format.");
		obj.PhotoFile.focus();
		obj.PhotoFile.select();
		return ;
	}
	if(strTrim(obj.Name.value) == "")
	{
		alert("Please enter your Full Name.");
		obj.Name.focus();
		return;
	}
	if(strTrim(obj.Address.value) == "")
	{
		alert("Please enter your Contact Address.");
		obj.Address.focus();
		return;
	}
	if(strTrim(obj.Phone.value) == "")
	{
		alert("Please enter Your Phone number.");
		obj.Phone.focus();
		return;
	}
	if(chkPhone(strTrim(obj.Phone.value)) == false)
	{
		alert("Only numbers, hyphens, blank space and parentheses\nare allowed in Phone number.");
		obj.Phone.focus();
		obj.Phone.select();
		return;
	}
	if(strTrim(obj.Email.value) == "")
	{
		alert("Please enter Your Email.");
		obj.Email.focus();
		return;
	}
	if(chkEmail(strTrim(obj.Email.value)) == false)
	{
		alert("Please enter a Valid Email ID.");
		obj.Email.focus();
		obj.Email.select();
		return;
	}
	obj.action = "insert_photo.php";
	obj.submit();
}

