//-----------------------------------------------------------------------------------------------------------------
//	Confirms the Browser type
//-----------------------------------------------------------------------------------------------------------------

var IE=(window.navigator.appName=='Microsoft Internet Explorer')? true : false;
var NE=(window.navigator.appName=='Netscape')? true : false;

//-----------------------------------------------------------------------------------------------------------------
//	Confirms valid Email
//-----------------------------------------------------------------------------------------------------------------

function validmail(mail)
{
	var str= mail.value;
		var locSpace= str.indexOf(" ");
		var locAt= str.indexOf("@");
		var tmpStr= str.substring(locAt+1);
		var locDot= tmpStr.indexOf(".");
		
		locSpace= str.indexOf(" ");
		
	// check if the email address contains " " ( space ). If it does, give an error message.
  if ( locSpace> -1 ) 
   {
	 alert("The email address cannot contain a space character.");
	 
	 mail.focus();
	 return false;
   }
		
		locSpace= str.indexOf(",");
		
	// check if the email address contains ",". If it does, give an error message.
  if ( locSpace> -1 ) 
   {
	alert("The email address cannot contain a \",\" character.");
	
	mail.focus();
	return false;
   }

		locAt= str.indexOf("@");
		
	// check if the email address contains "@". If it doesn't, give an error message.
  if ( locAt< 0 ) 
    {
	 alert("The email address must be in the form \"username@domain.com\".");
	 
	 mail.focus();
	 return false;
	}
			
		tmpStr= str.substring(locAt+1);
		locAt= tmpStr.indexOf("@");
		
	// check if the email address contains a second "@". If it does, give an error message.
  if ( locAt> -1 )
   {
	alert("The email address can contain only one \"@\".");
	
	mail.focus();
	return false;
   }

		locAt= str.indexOf("@");
		tmpStr= str.substring(locAt+1);
		locDot= tmpStr.indexOf(".");
	// check if the email address domain contains at least one "." character. If not, give an error message
  if ( (locDot<0) )
   {
	alert("The domain must contain at least one \".\"-character.");
	
	mail.focus();
	return false;
   }			
			
	// check if the "username" starts with a dot
  if ( str.charAt(0)== ".")
   {
	alert("The username part of the email address can not start with a \".\"-character.");
	
	mail.focus();
	return false;
   }

		locAt= str.indexOf("@");
		tmpStr= str.substring(0,locAt);
		locDot= tmpStr.charAt(tmpStr.length-1);
	
	// check if the "username" ends with a dot
  if ( tmpStr.charAt(tmpStr.length-1)== ".")
   {
	alert("The username part of the email address cannot end with a \".\"-character.");
	
	mail.focus();
	return false;
   }

	// check if the "domain" ends with a dot
  if ( str.charAt(str.length-1)== ".")
   {
	alert("The domain part of the email address cannot end with a \".\"-character.");
	
	mail.focus();
	return false;
   }
		
		locAt= str.indexOf("@");
		tmpStr= str.substring(locAt+1);
	// check if the "domain" starts with a dot
  if ( tmpStr.charAt(0)== ".")
   {
	alert("The domain part of the email address cannot start with a \".\"-character.");
	
	mail.focus();
	return false;
   }
  return true;
}

//-----------------------------------------------------------------------------------------------------------------
//	Trims leading and trailing blankspaces
//-----------------------------------------------------------------------------------------------------------------

function trimtxt(txtval)
{
	var txtlen = txtval.length;
	var firstindex = -1;
	var lastindex = -1;
	var finaltxt = "";

	for (i=0;i<txtlen;i++)
	{
		if (txtval.charAt(i) == " ")
		{	continue ;}
		else
		{
			firstindex = i;
			break;
		}
	}

	for (i=txtlen-1;i>=0;i--)
	{
		if (txtval.charAt(i) == " ")
		{ 	continue ;}
		else
		{
			lastindex = i;
			break;
		}

     }

	 if (firstindex < 0 && lastindex < 0)
	 {
	 		return "";
	 }


	 finaltxt = txtval.substring(firstindex,lastindex+1);
	 return finaltxt;
}

//-----------------------------------------------------------------------------------------------------------------
//	Checks the value to be empty
//-----------------------------------------------------------------------------------------------------------------

function empty(txtval)
{
	var n=0
	txtval=trimtxt(txtval)
	for(i=0;i<txtval.length;i++)
	{
	if(txtval.charCodeAt(i)==13 || txtval.charCodeAt(i)==10 || txtval.charCodeAt(i)==32)
	{
		n++;
	}
	}
	if(n==txtval.length)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//-----------------------------------------------------------------------------------------------------------------
//	Reads the value in the cookie
//-----------------------------------------------------------------------------------------------------------------

function getCookie(name,doc){
	var cookies=doc.cookie
	var value=null;
	var name=trimtxt(name);
	var start=cookies.indexOf(name);
	if(start!=-1){
		start=cookies.indexOf("=",start)+1;
		var end=cookies.indexOf(";",start);
		if (end==-1){
			end=cookies.length;
		}
		value=unescape(cookies.substring(start,end));
	}
	else{
		value="Cookie Not Foun";
	}
	return value;
}

//-----------------------------------------------------------------------------------------------------------------
//	writes a cookie
//-----------------------------------------------------------------------------------------------------------------

function setCookie(doc,name,value,expDays){
	var dat=new Date();
	var day=dat.getDate()+expDays;
	var mon=dat.getMonth()+1;
	var year=dat.getYear();
	if(NE){
		year=year+1900;
	}
	var min=dat.getMinutes();
	var sec=dat.getSeconds();
	var hr=dat.getHours();
	dat=mon + "/" + day + "/" + year + " " + hr + ":" + min + ":" + ":" + sec;
	if(IE){
		dat=Date(dat);
	}
	doc.cookie= trimtxt(name) + "=" + value + ";expires=" + dat;
}


//-----------------------------------------------------------------------------------------------------------------
//Check valid number
//-----------------------------------------------------------------------------------------------------------------

function deleteCookie(doc,name){
	var dat=new Date();
	var day=dat.getDate();
	var mon=dat.getMonth()+1;
	var year=dat.getYear();
	if(NE){
		year=year+1900;
	}
	var min=dat.getMinutes();
	var sec=dat.getSeconds();
	var hr=dat.getHours();
	dat=mon + "/" + day + "/" + year + " " + hr + ":" + min + ":" + ":" + sec;
	if(IE){
		dat=Date(dat);
	}
	doc.cookie= trimtxt(name) + "=" + null + ";expires=" + dat;
	window.location.reload();
}

//-----------------------------------------------------------------------------------------------------------------
//	Check valid number
//-----------------------------------------------------------------------------------------------------------------

function checkNumber(num){
var i,lnum=num.length;
for(i=0;i<lnum;i++){
	if(num.charCodeAt(i)<48 || num.charCodeAt(i)>57){
		return false;
	}
}
return true;
}


//-----------------------------------------------------------------------------------------------------------------
//	Check Alphabets
//-----------------------------------------------------------------------------------------------------------------

function checkAlphabet(al){
var i,lal=al.length;
for(i=0;i<lal;i++){
	if((al.charCodeAt(i)>=97 && al.charCodeAt(i)<=122)||(al.charCodeAt(i)>=65 && al.charCodeAt(i)<=90)){
		continue;
	}
	else{
		return false;
	}
}
return true;
}