//alert("validations");
function confirmSubmit(thisForm)
{
   if(isBlank(thisForm.USERNAME.value))
   {  alert("Username or Email address is required.");
      thisForm.USERNAME.focus();
	  return false;
   }

     if(invaliddata(thisForm.USERNAME.value))
   { 
	  alert("Special characters are not allowed in username.");
      thisForm.USERNAME.focus();
	  return false;
   }
   
   if(isBlank(thisForm.PASSWORD.value))
   {  alert("Password cannot be blank.");
      thisForm.PASSWORD.focus();
	  return false;
   }


    //if(inValidString(thisForm.PASSWORD.value))
  // { 
	  // alert('Password can only contain characters A-Z, a-z, and 0-9.')
 	   //alert("Special characters are not allowed in password");
      // thisForm.PASSWORD.focus();
	   //return false;
   //}
   //else
  // { 
	   if (thisForm.USERNAME.value.indexOf("@") == -1)
	   {
		   thisForm.action= "https://www.ibackup.com/cgi-bin/LoginCheckCgi.cgi";
		   thisForm.method="POST";
		   thisForm.submit;
       }
	   else
	   {
		   thisForm.action= "/qmanager/jsp/LoginCheck.jsp";
		   thisForm.method="POST";
		   thisForm.submit;
	   }
       return true ;
   //}
}

function confirmSubmit1(thisForm)
{
   if(confirmSubmit(thisForm)==true)
   {   thisForm.action= "/qmanager/servlet/LoginWebFolderServlet";
	   thisForm.method="POST";
	   thisForm.submit;
	   return true;
   }
   else
   {  return false;
   }
}

function confirmFreetrial(thisForm)
{
     thisForm.EMAIL.value = trim(thisForm.EMAIL.value);
	if(thisForm.EMAIL.value=='')
   {
     alert('Enter the email address.');
     thisForm.EMAIL.focus();
     return(false);
   }
   else if(!isValidEmailId(thisForm.EMAIL.value))
   {
      alert('Enter a valid email address.');
      thisForm.EMAIL.focus();
      return(false);
   }
   else 
   {
	   var partid = Read_Cookie('pid')

	if(partid != ''){
		thisForm.action = "/qmanager/jsp/regterms_new.jsp?id="+partid;
	}
	else
		thisForm.action = "/qmanager/jsp/regterms_new.jsp";
	      return true;
   }
}
function isValidEmailId(email)
{
	if (email == null)
	{
		return(false);
	}
	else if(email == '')
	{
		return(false) ;
	}
	else if ( (trim(email).indexOf('@') == -1) ||
			  (trim(email).indexOf('@') == 0) ||
			  (trim(email).indexOf('@') == (trim(email).length-1) ||  trim(email).indexOf('@',(trim(email).indexOf('@')+1))!=-1))
	{
		return(false);
	}
	else if (hasSpecChar(email))
	{
		return(false) ;
	}
	else
	{
		return(true) ;
	};
}

function hasSpecChar(Str)
 {
	var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@.-";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  return(true);
		}

	 };
	 return(false);
 }


function trim(Str)
 {
   if (!(isBlank(Str)))
   {
	  while(''+Str.charAt(0)==' ')
	  Str=Str.substring(1,Str.length);
	  while(''+Str.charAt(Str.length-1)==' ')
	  Str=Str.substring(0,Str.length-1);
	  return(Str);
   }
   else
   { return ('');
   };
 }


function isBlank(Str)
 {
   while(''+Str.charAt(0)==' ')
   Str=Str.substring(1,Str.length);
   while(''+Str.charAt(Str.length-1)==' ')
   Str=Str.substring(0,Str.length-1);
   if (Str == '')
   { return(true);
   }
   else
   { return(false);
   };
 }

function invaliddata(Str)
  {
     if( (Str.indexOf("\'") != -1) || (Str.indexOf('\"') != -1) ||
    (Str.indexOf('#') != -1) || (Str.indexOf('&') != -1)  ||
    (Str.indexOf('%') != -1) || (Str.indexOf('*') != -1)  ||
    (Str.indexOf('!') != -1) || (Str.indexOf('$') != -1)  ||
    (Str.indexOf('/') != -1) || (Str.indexOf('\\') != -1)  ||
       (Str.indexOf('?') != -1) )
     { return(true);
     }
     else
     { return (false);
     }
  }	 
 
 function inValidString(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  return(true);
		}

	 };
	 return(false);
 }



 
