var value_of_pass1="";
var value_of_pass2="";
var whitespace="\t\n\r";
var flag=0;
var pub = 0;
var dir = 0;

function isEmpty(s)
{
	return((s==null)||(s.length==0));
}

function setpub(s)
{
	pub=s;
//	alert(document.all.pub.selected);
	return true;
}

function setdir(s)
{
	dir=s;
//	alert(document.all.pub.selected);
	return true;
}

function isWhitespace(s)
{
	var i;
	if(isEmpty(s)) return true;
	for(i=0;i<s.length;i++)
	{
		var c=s.charAt(i);
		if(whitespace.indexOf(c)==-1) return false;
	}
	return true;
}

function isCharsInbag(s,bag)
{
	var i;
	for(i=0;i<s.length;i++)
	{
		var c=s.charAt(i);
		
		if(bag.indexOf(c)==-1) return false;
	}
	return true;
}

function publication()
{
	var a=new Array();
	a[0]=document.all.pubtitle.value;
	a[1]=document.all.pubyear.value;
	a[2]=document.all.pubauthor.value;



	if (pub==0)
		if (a[0] == "")
		{
			alert("Please Specify the Publication Title to be searched.");
			document.all.pubtitle.focus();
			return false;
		}
	
	if (pub==1)
		if (a[1] == "")
		{
			alert("Please Select valid Publication year from the drop down list. [1987].");
			document.all.pubyear.focus();
			return false;
		}
		else if(!isCharsInbag(a[1],"0123456789"))
		{
			alert("Please Select valid Publication year from the drop down list. [1987].");
			document.all.pubyear.focus();
			return false;
		}
	
	if (pub==2)	
		if (a[2] == "")
		{
			alert("Please Specify the Name of the Author whose Publications to be searched. [Dr. V.M. Katoch].");
			document.all.pubauthor.focus();
			return false;
		}
		else if(!isCharsInbag(a[2],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "))
		{
			alert("Please Enter Author Name In English Alphabets only. [Dr. V.M. Katoch].");
			document.all.pubauthor.focus();
			return false;
		}
	
	return true;
}

function teldir()
{
	var a=new Array();
	a[0]=document.all.dirname.value;
	a[1]=document.all.dirdept.value;
	a[2]=document.all.dirdesg.value;



	if (dir==0)
		if (a[0] == "")
		{
			alert("Please Specify the Person Name to be searched.");
			document.all.dirname.focus();
			return false;
		}
	
	if (dir==1)
		if (a[1] == "")
		{
			alert("Please Select valid Department from the drop down list.");
			document.all.dirdept.focus();
			return false;
		}
	
	if (dir==2)	
		if (a[2] == "")
		{
			alert("Please Select the valid Designation from the drop down list.");
			document.all.dirdept.focus();
			return false;
		}
	return true;
}

function newsletter()
{
	var a=new Array();
	a[0]=document.all.newsname.value;
	a[1]=document.all.newsemail.value;

		if (a[0] == "")
		{
			alert("Please Specify the Name in Newsletter Subcription to be submitted.");
			document.all.newsname.focus();
			return false;
		}
		else if(!isCharsInbag(a[0],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "))
		{
			alert("Please Enter the Name In English Alphabets only. [Dr. V.M. Katoch].");
			document.all.newsname.focus();
			return false;
		}
		else if (a[1] == "")
		{
			alert("Please Specify the Email ID in Newsletter Subcription to be submitted.");
			document.all.newsemail.focus();
			return false;
		}
		else if(!isEmail(a[1]))
		{
			alert("Please Enter the Email ID for Newsletter Subscription in proper format. [softprosolutions@rediffmail.com].");
			document.all.newsemail.focus();
			return false;
		}
	
	return true;
}

function login()
{
	var a=new Array();
	a[0]=document.all.txtlogin.value;
	a[1]=document.all.txtpwd.value;

		if (a[0] == "")
		{
			alert("Please Specify the proper Login Name.");
			document.all.txtlogin.focus();
			return false;
		}
		else if(!isCharsInbag(a[0],"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
		{
			alert("Please Enter the Login Name In English Alphabets only. [abcxyz].");
			document.all.txtlogin.focus();
			return false;
		}
		else if (a[1] == "")
		{
			alert("Please Specify the proper non-empty Login Password.");
			document.all.txtpwd.focus();
			return false;
		}
	
	return true;
}

function abort()
{
	window.close();
}

function isEmail(s)
{	
	flag=0;
	if(isEmpty(s))
		if(isWhitespace(s)) return false;
		
	var i=0;
	var sLength=s.length;
	var j=0;
	var count=0;
	var c=0;
	while(i<s.length)
	{
		if(s.charAt(i)=="@" || s.charAt(i)==".")
		{
			flag=1;
			break;
		}
		i++;
		
	}
	if (flag==0)
		return false;
	else 
		i=0;
		
	
		
	if(!isCharsInbag(s,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@._0123456789"))
		return false;
	
	if(s.charAt(0)==".")
		return false;
			
	while(s.charAt(i)!="@")
	{
		if(s.charAt(i)==".")
			return false;
		i++;
		
	}
	i=1;	
	while(j<sLength)
	{
		if(s.charAt(j)=="@")
			count++;
		j++;
	}
	
	if (count>1) return false;
	
	while((i<sLength)&&(s.charAt(i)!="@")) i++;
	
	j=i+1;
	while(j<sLength)
	{
		if(c>1 && s.charAt(j+1)==".")
			return false; 
		if(s.charAt(j)==".")
			c++;
		j++;
	}
	
	if((i==s.length)||(s.charAt(i)!="@")) return false;
	else if(s.charAt(i+1)==".")
		return false; 
	else
		i+=2;
	
	while((i<s.length)&&(s.charAt(i)!=".")) i++;
	
	if((i>=s.length-1)||(s.charAt(i)!=".")) return false;
	else return true;	
	
}
