// 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;		
	}
	/*if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + ".");		
		txtCtrl.focus();   	
		return false;		
	}*/			
}

function SelectValidate(selCtrl,msg) 
{
	if (selCtrl.value == "" || selCtrl.value == "0" || selCtrl.value == "-1" || selCtrl.value.indexOf("Please") != -1) 
	{
		alert("Please select " + msg +".");
		selCtrl.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 EmailValidate(txtCtrl, val) 
{
	var ctrName = val;
	if (txtCtrl.value.indexOf("@") < 1 ||txtCtrl.value.indexOf(".") < 0) 
	{
		alert("Please enter valid " + ctrName + ".\t\n eg: username@domainname.com");
		//alert("Please enter valid " + ctrName + ".");
		txtCtrl.focus();
		txtCtrl.select();
		return false;
	}
	if(txtCtrl.value.indexOf("'") > -1)
	{
		alert("Please Don't enter ' in " + ctrName + ".");
		txtCtrl.focus();   	
		return false;		
	}			
}