STREAMNET.validate={};

/************************************************************************/

function validate(thisForm)
{	
	
thisForm.user.value = trim(thisForm.user.value);

	document.getElementById("errorInfo").innerHTML="";
if(thisForm.user.value=='')
{
document.getElementById("errorInfo").innerHTML="Enter the username/email address.";
document.form1.user.focus();
return false;
}else if(thisForm.user.value.indexOf("@")!=-1) {

	 if (!isValidEmailId(thisForm.user.value))
	   {
	     alert('Enter a valid email address.')
	     thisForm.user.focus();
		 return false;
	   }else
	   {
		STREAMNET.validate.getFirewallInfo(thisForm);
		return false;
	   }
}
else
{
STREAMNET.validate.getFirewallInfo(thisForm);
return false;
	}
	
}

STREAMNET.validate.getFirewallInfo=function(frm)
{
	
	frm.errMsg.value='';	

var ajaxUserId = frm.user.value;
ajaxUserId = ajaxUserId.replace(/^\s+|\s+$/g, '');
var data="username="+encodeURIComponent(ajaxUserId);


STREAMNET.Ajax.makeRequest("/qmanager/jsp/ibackup_linux1.jsp",data,true,"POST",STREAMNET.validate.getFirewallInfoResponse);
return false;
}


STREAMNET.validate.getFirewallInfoResponse=function(http_request)
{
 if(http_request.readyState==4)
 {
	if(http_request.status==200)
  {

	 var resp = http_request.responseText;
		
		if(resp.indexOf("table")!=-1){	
			document.getElementById("linuxInfo").innerHTML=resp;
			document.getElementById("errMsg").value="success";
		}else {	
		document.getElementById("errorInfo").innerHTML=resp;
		document.getElementById("errMsg").value="error";
		document.form1.user.value="";
		document.form1.user.focus();
      }
	
  }
 }
}

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 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);
 }
