function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}

function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setcookie(name,value,duration){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
if(!getcookie(name)){
return false;
}
else{
return true;
}

}

//****************************************************************************
// Function to delete blank/white spaces Between Data Entered
//****************************************************************************
function deleteBlanks(entry)
{
	var len = entry.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = entry.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			entry = entry.substring(0,indx) + entry.substring(indx+1,len);
		len = entry.length;
	}
	return entry;
}

//****************************************************************************
// Function To Check Text box is empty or not
//****************************************************************************
function isEmpty(val,valName)
{
	if (!deleteBlanks(val.value))
	{
		alert(valName + " is required");
		val.focus();
		return false;	
	}
	return true;
}

function ValidateForm() {

    document.frmlogin.txtlogin.value =deleteBlanks(document.frmlogin.txtlogin.value);
    if(!isEmpty(document.frmlogin.txtlogin,"User Name"))
        return false;

    if(!isEmpty(document.frmlogin.txtpass,"Password"))
        return false;
    
    if (document.frmlogin.txtpass.value != deleteBlanks(document.frmlogin.txtpass.value))
    {
        alert("Password should not have spaces");
        document.frmlogin.txtpass.value="";
        document.frmlogin.txtpass.focus();
        document.frmlogin.txtpass.select();
        return false;
    }
    
    document.frmlogin.submit();
    return true;
}