
//alert("www");
function getScreenCenterY() {   
var y = 0;   
  
y = getScrollOffset()+(getInnerHeight()/2);   
  
return(y);   
}   
  
function getScreenCenterX() {   
return(document.body.clientWidth/2);   
}   

function getInnerHeight() {   
var y;   
if (self.innerHeight) // all except Explorer   
{   
y = self.innerHeight;   
}   
else if (document.documentElement && document.documentElement.clientHeight)   
// Explorer 6 Strict Mode   
{   
y = document.documentElement.clientHeight;   
}   
else if (document.body) // other Explorers   
{   
y = document.body.clientHeight;   
}   
return(y);   
}   
  
function getScrollOffset() {   
var y;   
if (self.pageYOffset) // all except Explorer   
{   
y = self.pageYOffset;   
}   
else if (document.documentElement && document.documentElement.scrollTop)   
// Explorer 6 Strict   
{   
y = document.documentElement.scrollTop;   
}   
else if (document.body) // all other Explorers   
{   
y = document.body.scrollTop;   
}   
return(y);   
} 
function invalidNumber(Str)
 {
	 var alloweduser = "0123456789";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}
	 };
	 if(totcount!=0)
	 {
	   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 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 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 invalidName(Str)
{
     var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";

     for(var count = 0; count < Str.length; count++)
     {
        if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
        {
            return(true);
        }
     };

}
function inValidAddress(Str)
{
   if( (Str.indexOf('"') != -1)  ||	(Str.indexOf('\'') != -1) || (Str.indexOf('\\') != -1) )
   { return(true);
   }
   else
   { return (false);
   }
}
function handle(text){
	
	text = replaceAll(text, ',', '%2C');
	text = replaceAll(text, '@', '%40');
	text = replaceAll(text, '&', '%26');
	text = replaceAll(text, '=', '%3D');
	text = replaceAll(text, '+', '%2B');
	text = replaceAll(text, '$', '%24');
	text = replaceAll(text, '#', '%23');
	//text = replaceAll(text, '%', '%25');
	return text;
	
}
function replaceAll(text, strA, strB) 
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}
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);
}
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 displayEditProfile(){
	setLayerPosition();
	showLayer();
	STREAMNET.Ajax.makeRequest("/evs/jsp/EVS_editprofile.jsp","",true,"POST",handleAccResponse);


}
function displayCancel(){
	setLayerPosition();
	showLayer();
	STREAMNET.Ajax.makeRequest("/evs/jsp/EVS_cancel.jsp","",true,"POST",handleAccResponse);


}
function displayAccDetails(){
	setLayerPosition();
	showLayer();
	STREAMNET.Ajax.makeRequest("/evs/jsp/EVS_accDetails.jsp","",true,"POST",handleAccResponse);


}

function getBWDetails(thisForm,reportType){
	setLayerPosition();
	showLayer();
	var data="";
	if(reportType=='1')
	{
	data="day="+thisForm.day.value+"&month="+thisForm.month.value+"&year="+thisForm.year.value;
	}
	else
	{
		data="month="+thisForm.month.value+"&year="+thisForm.year.value;
	}
	//alert("Data:"+data);
	STREAMNET.Ajax.makeRequest("/evs/jsp/EVS_accDetails_bwAjax.jsp",data,true,"POST",handleBWResponse);


}

function handleBWResponse(http_request)
{
	if(http_request.readyState == 4)
	{
	
		if(http_request.status == 200)
		{
			
			var resp = http_request.responseText;
			
			resp = trim(resp);
			//alert(resp);
			if(resp.indexOf("$INVALID_SESSION$") != -1)
				window.location = "/evs/jsp/EVS_Login.jsp?k=s";
			else{	 
				var infoRef = document.getElementById("bwDetails");
				infoRef.innerHTML = resp;
				
				//alert(trim(dtls[1]));
				
				infoRef = null;
			}
			
		}	
		else{
			
			//alert("There was some problem.Try later.");
			
		}
		hideLayer();
	}
	
	
}


function inValidZip(Str)
 {
	 var alloweduser = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ ";
         var totcount = 0;
	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
		  totcount++;
		}

	 };
	 if(totcount!=0)
	 {
	   return(true);
	 }
	 return(false);
 }

function confirmSubmit(thisForm)
{
   if(isBlank(thisForm.uid.value))
   {  alert("Username is required");
      thisForm.uid.focus();	  
	  return(false);
   }
 
   if(isBlank(thisForm.pwd.value))
   {  alert("Password cannot be blank");
      thisForm.pwd.focus();
	  return(false);
   }
   else
   {
      return true;
   }
}

function configForm(thisForm)
{ 
	//alert('pvtkey.');

   if(isBlank(thisForm.pvtkey.value))
	{
		alert('Enter the Encryption key.');
		thisForm.pvtkey.focus();	
		return(false);
	}
	else if (thisForm.pvtkey.value.indexOf(" ")!=-1)
	{
		alert("Encryption key cannot contain blank space.");
		thisForm.pvtkey.focus();
		return(false);
	}
   else  if(isBlank(thisForm.cpvtkey.value))
	{
		alert('Enter the Confirm Encryption key.');
		thisForm.cpvtkey.focus();	
		return(false);
	}
	else if (thisForm.pvtkey.value != thisForm.cpvtkey.value)
	{
		alert("Encryption key and Confirm Encryption key must be the same.");
		thisForm.cpvtkey.focus();
		return(false);
	}
	else if(thisForm.pvtkey.value.length < 4 || thisForm.pvtkey.value.length > 250) 
    {
         alert('Encryption key must contain 4 to 250 characters.');
         thisForm.pvtkey.focus();
		 return(false);    
    }
  else
	{
	   return(true);
	}
}



function encValidate(thisForm)
{ 
	//alert('Encryption key.');
	thisForm.enckey.value = trim(thisForm.enckey.value);
	
   if(isBlank(thisForm.enckey.value))
	{
		alert('Enter the Encryption key.');
		thisForm.enckey.focus();	
		return(false);
	}
	else if (thisForm.enckey.value.indexOf(" ")!=-1)
	{
		alert("Encryption key cannot contain blank space.");
		thisForm.enckey.focus();
		return(false);
	}
   else if(thisForm.enckey.value.length > 256) 
    {
         alert('Enter valid Encryption key.');
         thisForm.enckey.focus();
		 return(false);    
    }
  else
	{
	   return(true);
	}
}




function editProfile()
{
 
	//alert("edit");
	var form1 = document.editprofile;	
	//form1.password.value = trim(form1.password.value);
	//form1.password1.value = trim(form1.password1.value);
	form1.firstname.value = trim(form1.firstname.value);
	form1.lastname.value = trim(form1.lastname.value);
	
  	var isPassword = false;
	if (!(isBlank(form1.password.value)) &&  !(isBlank(form1.password1.value)))
		isPassword = true;
	if (form1.password.value != form1.password1.value)
	{
		alert("Password and Confirm Password must be the same.");
		form1.password1.focus();
		
	}
	else if (form1.password.value.indexOf(" ")!=-1)
	{
		alert("Password cannot contain blank space.");
		form1.password.focus();
		
	}
	else if (form1.password1.value.indexOf(" ")!=-1)
	{
				alert("Password cannot contain blank space.");
		form1.password1.focus();
		
	}
	else if ( isPassword && (form1.password.value.length < 4) || (form1.password.value.length > 16))
    {
         alert('Password must contain 4 to 16 characters.');
         form1.password.focus();
    
    }
	else if (isPassword && inValidString(form1.password.value))
    {
            alert('Password can only contain characters A-Z, a-z and 0-9.')
            form1.password.focus();
            form1.password.select();
           
    }
    else if (isPassword && inValidString(form1.password1.value))
    {
            alert('Password can only contain characters A-Z, a-z and 0-9.')
            form1.password1.focus();
            form1.password1.select();
           
    }
	else if(isBlank(form1.emailid.value))
	{
		alert('Enter the Email address.');
		form1.emailid.focus();		
	}
   else if(!isValidEmailId(trim(form1.emailid.value)))
   {
		form1.emailid.value=trim(form1.emailid.value);
        alert('Enter the valid Email address.');
		form1.emailid.focus();
    } 
	
	else if (form1.firstname.value =='')
	{
		  form1.firstname.focus();
		  alert('Enter your first name.');
		  
	}
	else if (invalidName(form1.firstname.value))
	{
	      form1.firstname.focus();
		  alert('First name can only contain characters A-Z, a-z and blank space.');
	      
	}
	else if (form1.lastname.value == '')
	{
	      form1.lastname.focus();
		  alert('Enter your last name.');
		 
	}
	else if (invalidName(form1.lastname.value))
	{
		  form1.lastname.focus();
		  alert('Last name can only contain characters A-Z, a-z and blank space.');
		 
	}
	else{
  		 setLayerPosition();
		 showLayer();
		 var data= "edit=true&PWD="+form1.password.value+"&CPWD="+form1.password1.value+"&FIR="+form1.firstname.value+"&LAST="+form1.lastname.value+"&EMAILID="+form1.emailid.value;


		STREAMNET.Ajax.makeRequest("/evs/jsp/EVS_editprofile.jsp",data,true,"POST",handleAccResponse);
	
	}
}
function handleAccResponse(http_request)
{


	
	if(http_request.readyState == 4)
	{
	
		if(http_request.status == 200)
		{
			
			var resp = http_request.responseText;
			
			resp = trim(resp);
			//alert(resp);
			if(resp.indexOf("$INVALID_SESSION$") != -1)
				window.location = "/evs/jsp/EVS_Login.jsp?k=s";
			else{	 
				var infoRef = document.getElementById("displaysection");
				infoRef.innerHTML = resp;
				
				//alert(trim(dtls[1]));
				
				infoRef = null;
			}
			
		}	
		else{
			
			//alert("There was some problem.Try later.");
			
		}
		hideLayer();
	}
	
	
}


function handleCancel(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13){
          cancelAccount();
         
     }     
     else
          return true;
}

function validateUser(user)
{

	var entered_username=document.getElementById("txtusername").value;
	var resultobj=document.getElementById("accnterr"); 
	if(document.getElementById("errorMsg")) 
		document.getElementById("errorMsg").innerHTML="";
	resultobj.innerHTML="";
	var login_userRef = document.getElementById("login_user");
	var form = document.cancelaccount;
 	if(isBlank(form.username.value)) 
   	{  
	
		 alert("Enter email address.");
        
		 form.username.focus();
	}
 	else if((trim(user)==trim(entered_username) ))	
	{
	 
	  	login_userRef.value="";
	   	resultobj.innerHTML='';
	   	form.password.focus();
	}
	else
	{
		
		 login_userRef.value="invalid";
		 resultobj.innerHTML="This email address entered does not match the login email address.";	
		 form.username.focus();
				
	}
}
function showUser(){
	
	//alert("here");
	var form = document.cancelaccount;
	form.username.focus();

}

// cancellation ////////////////
function cancelAccount(thisForm)
{
	//alert("cancel");
	thisForm.username.value= trim(thisForm.username.value);

   if(isBlank(thisForm.username.value))
   {  
	 alert('Enter the Username.');
      thisForm.username.focus();
	 return (false);
   }
   else if(invalidUserName(thisForm.username.value))
   {  
	   alert('Enter a valid Username.');
       thisForm.username.focus();
	   return (false);
   } 
	else if(isBlank(thisForm.password.value))
   	 {
     	 alert('Enter your Password.');
      	thisForm.password.focus();
      	return(false);
   	}
   	else if (inValidString(thisForm.password.value))
   	{
       alert('Password can contain only characters A-Z, a-z, and 0-9.')
       thisForm.password.focus();
      return(false);
   	}
  	 else if( (thisForm.password.value.length < 4) || (thisForm.password.value.length > 16))
   	{
        alert('Password must contain 4 - 16 characters.');
        thisForm.password.focus();
       return(false);
   	}
   	else if (thisForm.reason.value =='')
	{
		thisForm.reason.focus();
		alert('Select a reason for cancelling the IDrive evs account.');
		return(false);
	}
	else if ( (thisForm.reason.value =='Others') && (thisForm.Others.value ==''))
	{
		thisForm.Others.focus();
		alert('Enter your Comments');
		return(false);
	}
	else
	{
		thisForm.reason.value=checkAndReplace(thisForm.reason.value);
    	return(true);
	}

}


function invalidUserName(Str)
 {
	 var alloweduser = "abcdefghijklmnopqrstuvwxyz0123456789_";

	 for(var count = 0; count < Str.length; count++)
	 {
		if(alloweduser.indexOf(Str.substring(count, count + 1)) == -1)
		{
			return(true);
		}
	 };

 }
 
 function checkAndReplace(str)
{
	var ch ='';
	var j;
	
	if(str=='')
	{
		return '';
	}
	else
	{
	
		for(var i=0;i<str.length;i++)
		{
			
			j = 0;
			if(str.charAt(i)=='\'')
			{
				j++;
			}

			if(str.charAt(i)=='<')
			{
				j++;
			}

			if(str.charAt(i)=='>')
			{
				j++;
				
			}

			if(str.charAt(i)=='\(')
			{
				j++;
				
			}

			if(str.charAt(i)=='\)')
			{
				j++;
				
			}

			if(j == 0)
			{
				ch = ch + str.charAt(i);
			}
			j = 0;
			
		}
	}

	return ch;
}
