
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)
{
//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 emailRef = '';
			var userRef = '';
			var userIdRef = '';
			var username = '';

			if(resp.indexOf("invalid")!=-1)
			{
				document.getElementById("invUser").value="invalid";
				document.form1.email.focus();				
				//alert('有効なＥメールアドレスを入力してください。');				
				document.getElementById("errorInfo").innerHTML="有効なＥメールアドレスを入力してください。";
			}
			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="Iドライブのアカウントを特定する為にユーザー名を入力してください。";
				}
				//alert('userRef..'+userRef.value);
			}
			else
			{
				username =  resp.substring(0,(resp.indexOf("<<")));
				document.getElementById("userid").value=username;				
				document.getElementById("invUser").value="";
			}

			
		}
		else
		{
			//alert(" 情報が正しくないか不足しています。");
		}
	}

}

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();
		//alert('有効なＥメールアドレスを入力してください。');
		document.getElementById("errorInfo").innerHTML="有効なＥメールアドレスを入力してください。";
	}
	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)
{
	document.getElementById("errorInfo").innerHTML="";
	var emailID = trim(thisForm.email.value);
	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);
   
if(!isValidEmailId(thisForm.email.value))
{
alert('有効なメールアドレスを入力してください。');
thisForm.email.focus();
return(false);
}
else if(thisForm.user_id.value!='' && invalidUserNameNew(thisForm.user_id.value))
{
alert('ユーザー名と_ （アンダースコア）は、文字az 、 0-9含めることができます。');
thisForm.user_id.focus();
return false;

}
else if((thisForm.invaliduser.value=="too") && isBlank(thisForm.user_id.value))
{
alert("ユーザ名を入力して、IDriveアカウントを特定してください。");
thisForm.user_id.focus();
return false;
}
else if((thisForm.invaliduser.value=="too") && (invalidUserNameNew(thisForm.user_id.value)))
{
alert('ユーザー名と_ （アンダースコア）は、文字az 、 0-9含めることができます。');
thisForm.user_id.focus();
return false;
}
else if( (thisForm.phone.value!='') && (invalidSecurityPhNum(thisForm.phone.value)))
{
thisForm.phone.focus();
alert('電話番号は0-9だけにx Xを含むことができます--+。');
return(false);
}
else if( (thisForm.program.value=='') || (thisForm.program.value=='choose') )
{
	   alert('プログラムを選んでください。');
	   thisForm.program.focus();
	   return (false);   
}
else if( (thisForm.program.value=='Others') && (thisForm.otherinfo.value=='') )
{
thisForm.otherinfo.focus();
alert('専門的な問題/フィードバックを入力してください。');
return (false);
}else{	  
	STREAMNET.idrive.emailVerifySyn(thisForm);
	if(thisForm.invaliduser.value==""){
	return true;
	}else{
	return false ;
	}	  
}  
	return true ;

}

/***********************/

function checkField(){
	if(document.form1.userid.value!=''){
	document.getElementById("errorInfo").innerHTML="";
	document.form1.invaliduser.value = '';
	}
}


function invalidUserNameNew(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@.";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
			return(true);
		}
	 }
 }



