// JavaScript Document

function Remove_Spaces(txtCtrl)
{
  txtCtrl.value = txtCtrl.value.replace(/\r/g, " ");

  //txtCtrl.value = txtCtrl.value.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");

  //txtCtrl.value = txtCtrl.value.replace(/'/g, "");

  txtCtrl.value = txtCtrl.value.replace(/ +/g, " ");

  txtCtrl.value = txtCtrl.value.replace(/^\s/g, "");

  txtCtrl.value = txtCtrl.value.replace(/\s$/g, "");
  
  if (txtCtrl.value == ' ')
  {
	 txtCtrl.value = '';
   }
 
 }

function TextValidate(txtCtrl,val)
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	
	if (txtCtrl.value == "" || txtCtrl.value == null) 
	{
		alert("Please enter " + ctrName + ".");
		txtCtrl.focus();
		return false;		
	}
}

function NumberValidate(txtCtrl, val) 
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	if (txtCtrl.value == "" )
	{
		alert("Please enter " + ctrName + ".");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}
	if(isNaN(txtCtrl.value) || txtCtrl.value.indexOf(".") > -1)
	{
		alert("Please enter numeric value for " + ctrName + ".");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}
}

function isEmail (txtCtrl, val) {
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	var parm = txtCtrl.value;
	
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\_\-\.]+\.([a-zA-Z\-]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(parm) && reg2.test(parm)){ // if syntax is valid 
	 return ( true ); 
	} else { 
	 alert("Please enter valid " + ctrName + ".\t\n eg: username@domainname.com");
	 txtCtrl.focus();
	 txtCtrl.select();
	 return ( false ); 
	} 
} 

function WebValidate(txtCtrl, val) 
{
	var ctrName = val;
	Remove_Spaces(txtCtrl);
	
 	if (txtCtrl.value.indexOf("www") < 0 || txtCtrl.value.indexOf(".") < 0) 
	{
		alert("Please enter valid " + ctrName + ".\t\n eg: wwww.domainname.com");
		txtCtrl.focus();	   	
		txtCtrl.select();
		return false;
	}		
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + ".");		
		txtCtrl.focus();   	
		return false;		
	}			
}