// JavaScript Document
function checking(name)
		{
			var extension = name.split(".");
			if(extension[1]=="jpg")
			{
			return(0);
			}
			else if(extension[1]=="gif")
			{
			return(0);
			}
			else if(extension[1]=="png")
			{
			return(0);
			}
			else if(extension[1]=="bmp")
			{
			return(0);
			}
		}
		
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}
function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}


function showPhotos(linkid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 450;
	winHeight = 400;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showPhotos.php?id=" + linkid,"photoCategory","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function chkContact()
{
	name=trimSpaces(document.forms[0].name.value);
	email=trimSpaces(document.forms[0].email.value);
	addr=trimSpaces(document.forms[0].addr.value);
	if(name.length<=0)
	{
		alert("Plese Enter your Name");
		document.forms[0].name.focus();
		return false;
	}
	if(email.length<=0)
	{
		alert("Plese Enter your E-mail Address");
		document.forms[0].email.focus();
		return false;
	}
	if(email.length>0)
	 {
	if(!checkEmail(email)) 
	{
		document.forms[0].email.focus();
		return false;
	} 
	 }
	 if(addr.length<=0)
	{
		alert("Plese Enter your Address");
		document.forms[0].addr.focus();
		return false;
	}
	 document.forms[0].frmAction.value = "put";
}

function chkfashreg()
{
	var frm=document.forms[0];
	name=trimSpaces(frm.name.value);
	age=trimSpaces(frm.age.value);
	nation=trimSpaces(frm.nation.value);
	rel=trimSpaces(frm.rel.value);
	praddr=trimSpaces(frm.praddr.value);
	peaddr=trimSpaces(frm.peaddr.value);
	email=trimSpaces(frm.email.value);
	ph1=trimSpaces(frm.ph1.value);
	ph2=trimSpaces(frm.ph2.value);
	ph3=trimSpaces(frm.ph3.value);
	if(name.length<=0)
	{
		alert("Plese Enter your Name");
		document.forms[0].name.focus();
		return false;
	}
	
	if(age.length<=0)
	{
		alert("Plese Enter your Age");
		document.forms[0].age.focus();
		return false;
	}
	
	
	if(frm.month.selectedIndex<=0)
	{
		alert("Please Choose The Month");
		frm.month.focus();
		return false;
	}
	if(frm.day.selectedIndex<=0)
	{
		alert("Please Choose The Date");
		frm.day.focus();
		return false;
	}
	if(frm.year.selectedIndex<=0)
	{
		alert("Please Choose The Year");
		frm.year.focus();
		return false;
	}
	if(nation.length<=0)
	{
		alert("Specify your Nationality");
		frm.nation.focus();
		return false;
	}
	if(rel.length<=0)
	{
		alert("Enter Father/Guardian Name");
		frm.rel.focus();
		return false;
	}
	if(praddr.length<=0)
	{
		alert("Please Enter your Present Address");
		frm.praddr.focus();
		return false;
	}
	if(peaddr.length<=0)
	{
		alert("Please Enter your Permenant Address");
		frm.peaddr.focus();
		return false;
	}
	if(email.length<=0)
	{
		alert("Plese Enter your E-mail Address");
		document.forms[0].email.focus();
		return false;
	}
	if(email.length>0)
	 {
	if(!checkEmail(email)) 
	{
		document.forms[0].email.focus();
		return false;
	} 
	 }
	 if(ph1.length<=0)
	{
	alert("Please Browse Your 1st Photo");
	frm.ph1.focus();
	return false;
	}
	if(ph1!="")
		{
			
			var photovalue=checking(ph1)
			if(photovalue!=0)
			{
			
			alert("Invalid photo file extension. You must select a .jpg or .gif or .png or bmp");
			return false;
			}
		}
	if(ph2.length<=0)
	{
	alert("Please Browse Your 2nd Photo");
	frm.ph2.focus();
	return false;
	}
	if(ph2!="")
		{
			var photovalue=checking(ph2)
			if(photovalue!=0)
			{
			
			alert("Invalid photo file extension. You must select a .jpg or .gif or .png or bmp");
			return false;
			}
		}
	if(ph3.length<=0)
	{
	alert("Please Browse Your 3rd Photo");
	frm.ph3.focus();
	return false;
	}
	
		
		if(ph3!="")
		{
			var photovalue=checking(ph3)
			if(photovalue!=0)
			{
			
			alert("Invalid photo file extension. You must select a .jpg or .gif or .png or bmp");
			return false;
			}
		}
		function checking(name)
		{
			var extension = name.split(".");
			if(extension[1]=="jpg")
			{
			return(0);
			}
			else if(extension[1]=="gif")
			{
			return(0)
			}
			else if(extension[1]=="png")
			{
			return(0)
			}
			else if(extension[1]=="bmp")
			{
			return(0)
			}
		}
	 document.forms[0].frmAction.value = "put";
}