
//////////////////////////
STREAMNET.idrive = {};

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);
 }


 STREAMNET.idrive.getEmailResponse = function(http_request)
{
if(http_request.readyState == 4)
	{
		if(http_request.status == 200)
		{			
			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 the 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();
					//alert('Enter the username to identify your IDrive account');
					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 displayAlert(){
//document.getElementById('email').focus();
document.form1.email.focus();
}

STREAMNET.idrive.emailVerify = function(thisForm)
{
	document.getElementById("errorInfo").innerHTML="";
	var emailID = trim(thisForm.email.value);
			
	
	if(!isValidEmailId(emailID))
	{
		setTimeout('displayAlert()',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 the valid Email address.";
	}
	else
	{
		document.form1.invUser.value = '';
		var data = "email="+emailID;
		STREAMNET.Ajax.makeRequest("/idrivee/jsp/validateIdriveFeedBackDetails.jsp",data,true,"POST",STREAMNET.idrive.getEmailResponse);
	}

}

STREAMNET.idrive.emailVerifySyn = function(thisForm)
{
	var emailID = trim(thisForm.email.value);
	document.getElementById("errorInfo").innerHTML="";
	var data = "email="+emailID;
	STREAMNET.Ajax.makeRequest("/idrivee/jsp/validateIdriveFeedBackDetails.jsp",data,false,"POST",STREAMNET.idrive.getEmailResponse);

}

/*************************************/

function IDSupport_local(thisForm) 
{ 
   thisForm.email.value = trim(thisForm.email.value);
   thisForm.user_id.value = trim(thisForm.user_id.value);
   //document.getElementById("errorInfo").innerHTML="";

   if(!isValidEmailId(thisForm.email.value))
   {      
	  alert('Enter the valid Email address.');
      thisForm.email.focus();
      return(false);
   }
   else if(thisForm.user_id.value!='' && invalidUserName(thisForm.user_id.value))
	{
	   alert('Username can only contain characters a-z, 0-9 and underscore ( _ ).');
	   thisForm.user_id.focus();
	   return false;

	}	
    else if(invalidUserName(thisForm.user_id.value))
   {
	  alert('Username can only contain 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('Phone number can only contain characters 0-9 x X - +');
	   return(false);
   }
    
 /** else if((thisForm.os.value=='choose'))
   {
     alert('Please select the OS');
   //  thisForm.os_others.focus();
     thisForm.os.focus();
     return (false);   
   }
   */

 /**  else if((thisForm.os.value=='Others') && (thisForm.os_others.value==''))
   {
     alert('Please specify the OS');
     //thisForm.os_others.focus();
     thisForm.os_others.focus();
     return (false);   
   }
   	
	else if( (thisForm.browserType.value=='') || (thisForm.browserType.value=='Select') )
	{
	   alert('Choose the Browser.');
	   thisForm.browserType.focus();
	   return (false);   
	}	 */
	else if( (thisForm.program.value=='') || (thisForm.program.value=='choose') )
	{
	   alert('Choose the Program.');
	   thisForm.program.focus();
	   return (false);   
	}

	else if( (thisForm.program.value=='Others') && (thisForm.otherinfo.value=='') )
	{
	   thisForm.otherinfo.focus();
	   alert('Enter your technical issues/ feedback.');
	   return (false);   
	}
    else{	  
		 STREAMNET.idrive.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.invaliduser.value = '';
	}
}




