
STREAMNET.remotepc = {};

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 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 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);
 }


 STREAMNET.remotepc.getEmailResponse = function(http_request)
{


//alert('getting called.....');
if(http_request.readyState == 4)
	{
		if(http_request.status == 200)
		{
			//alert('http_request.responseText....'+http_request.responseText);
			
			var resp = http_request.responseText;
			var username = '';

			if(resp.indexOf("invalid")!=-1)
			{
				document.getElementById("invUser").value="invalid";
				document.form1.email.focus();
				//alert('Enter a valid email address.');
				document.getElementById("errorInfo").innerHTML="Enter a valid email address.";
			}
			else if(resp.indexOf("too many rows")!=-1)
			{
				username = document.getElementById("userid");
				if(username.value == '')
				{
					document.getElementById("invUser").value="too";
					document.form1.user_id.focus();
					document.getElementById("errorInfo").innerHTML="There are multiple accounts associated with this email address. Provide the specific Username for which you want to report your feedback.";
				}
				
			}
			else
			{				
				username =  resp.substring(0,(resp.indexOf("<<")));
				document.getElementById("userid").value=username;				
				document.getElementById("invUser").value="";
			}

			
		}
		else
		{
			//alert("Some problem in response");
		}
	}

}

function getFocus(){
document.getElementById('email').focus();
}

STREAMNET.remotepc.emailVerify = function(thisForm)
{

	document.getElementById("errorInfo").innerHTML="";
	document.form1.email.value = trim(document.form1.email.value);

   if(!isValidEmailId(thisForm.email.value))
	{
		setTimeout('getFocus()',0);  // Calling this method as on IE6 and IE7 document.form1.email.focus(); was not working
		document.form1.invUser.value = 'invalid';
		document.form1.email.focus();
		document.getElementById("errorInfo").innerHTML="Enter a valid email address.";
		
	}
	else
	{
		document.form1.invUser.value = '';
		var data = "email="+thisForm.email.value;
		STREAMNET.Ajax.makeRequest("/remotepc/jsp/validateRemotePCFeedBackDetails.jsp",data,false,"POST",STREAMNET.remotepc.getEmailResponse);
	}

}

STREAMNET.remotepc.emailVerifySyn = function(thisForm)
{
	document.form1.email.value = trim(document.form1.email.value);
	document.getElementById("errorInfo").innerHTML="";
	var data = "email="+thisForm.email.value;
	STREAMNET.Ajax.makeRequest("/remotepc/jsp/validateRemotePCFeedBackDetails.jsp",data,false,"POST",STREAMNET.remotepc.getEmailResponse);
}

STREAMNET.remotepc.getUsernameResponse = function(http_request)
{


//alert('getting called.....');
if(http_request.readyState == 4)
	{
		if(http_request.status == 200)
		{
			//alert('http_request.responseText....'+http_request.responseText);
			
			var resp = http_request.responseText;
			

			if(resp.indexOf("invalid")!=-1)
			{
				userRef = document.getElementById("invUser");
				userRef.value = 'true';
				document.form1.USERNAME.focus();
				alert('Enter a valid username');
			}
			else
			{
				userRef = document.getElementById("invUser");
				userRef.value = '';

			}
			

			
		}
		else
		{
			//alert("Some problem in response");
		}
	}

}

STREAMNET.remotepc.usernameVerify = function(thisForm)
{

	var data = "USERNAME="+thisForm.USERNAME.value+"&ounv=true";

	STREAMNET.Ajax.makeRequest("/remotepc/jsp/validateRemotePCFeedBackDetails.jsp",data,true,"POST",STREAMNET.remotepc.getUsernameResponse);

}

STREAMNET.remotepc.usernameVerifySyn = function(thisForm)
{

	var data = "USERNAME="+thisForm.USERNAME.value+"&ounv=true";
	STREAMNET.Ajax.makeRequest("/remotepc/jsp/validateRemotePCFeedBackDetails.jsp",data,false,"POST",STREAMNET.remotepc.getUsernameResponse);

}

/*************** Support page js methods ************************/

function lickeyvalidate(thisForm)
{
 
     if( (thisForm.lic.value==null) || (thisForm.lic.value==''))
 {
   alert("Enter the Pin Code.");
   thisForm.lic.focus();
   return (false);
 }
 if(thisForm.lic.value.length !=6 )
 {
   alert("The Pin Code must contain 6 digits.");
   thisForm.lic.focus();
   return (false);
 }
}
 
function confirmSubmit(thisForm)
{
   if(isBlank(thisForm.USERNAME.value))
   {  alert("Username or email is required");
      thisForm.USERNAME.focus();
   return false;
   }
 
   if(isBlank(thisForm.PASSWORD.value))
   {  alert("Password cannot be blank");
      thisForm.PASSWORD.focus();
   return false;
   }
   else
   {
     return true ;
   }
}
 
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 confirmSubmit1(thisForm)
{
   if(confirmSubmit(thisForm)==true)
   {
      // thisForm.action= "https://www.ibackup.com/cgi-bin/LoginCheckCgi.cgi";
           thisForm.action= "https://www.remotepc.net/remotepc/jsp/CheckIbackupLogin.jsp";
           thisForm.method="POST";
           thisForm.submitvalue.value = "login";
         //  thisForm.submit;
           return true;
   }
   else
   {  return false;
   }
}
 
function confirmSubmit2(thisForm)
{
   if(confirmSubmit(thisForm)==true)
   {
      // thisForm.action= "https://www.ibackup.com/qmanager/servlet/LoginWebFolderServlet";
           thisForm.action= "https://www.remotepc.net/remotepc/jsp/CheckIbackupLogin.jsp";
           thisForm.method="POST";
           thisForm.submitvalue.value = "webfol";
        //   thisForm.submit;
           return true;
   }
   else
   {  return false;
   }
}
 
function confirmSubmit3(thisForm)
{
   if(confirmSubmit(thisForm)==true)
   {
                 thisForm.action= "https://data.remotepc.net/pfs/servlet/PFSViewerLoginServlet";
           thisForm.method="POST";
           thisForm.submitvalue.value = "rdata";
                    return true;
   }
   else
   {  return false;
   }
}



function confirmFeedback12(thisForm) 
{ 
   
   thisForm.email.value = trim(thisForm.email.value);
   thisForm.user_id.value = trim(thisForm.user_id.value);
   
   if(!isValidEmailId(thisForm.email.value))
   {
      alert('Enter a valid email address.');
      thisForm.email.focus();
      return(false);
   }
   else if(trim(thisForm.user_id.value)!='' && invalidUserName(trim(thisForm.user_id.value)))
	{
	   alert('The username can contain only characters a-z, 0-9 and _ (underscore).');
	  
	   thisForm.user_id.focus();
	   return false;

	}
	
    else if(invalidUserName(thisForm.user_id.value))
   {
	  alert('The username can contain only characters a-z, 0-9 and _ (underscore).');
      thisForm.user_id.focus();
	  return false;
   }

   else if( (thisForm.phone.value!='') && (invalidSecurityPhNum(thisForm.phone.value)))
   {
	   thisForm.phone.focus();
	   alert('The phone number can contain only characters 0-9 x X - +');
	   return(false);
   }
   
   else if(thisForm.os.value == 'select')
	{
	   alert("Select the Operating System.");
	   thisForm.os.focus();
	   return false;
	}
   else if(thisForm.application.value == 'select')
	{
	   alert("Choose your issue.");
	   thisForm.application.focus();
	   return false;
	}
	
   else if(thisForm.application.value=='Other' && isBlank(thisForm.otherinfo.value))
   {
      alert('Enter your technical query or feedback.');
      thisForm.otherinfo.focus();
      return(false);
   }  
  else{	  
	STREAMNET.remotepc.emailVerifySyn(thisForm);
	if(thisForm.invUser.value==""){
	return true;
	}else{
		return false ;
	}
	  
	}  
	   return true ;
   
}


function checkField(){
	if(document.form1.userid.value!=''){
	document.getElementById("errorInfo").innerHTML="";
	document.form1.invUser.value = '';
	}
}
