function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function TextValidate(txtCtrl,val)
{
	var ctrName = val;
	//Remove_Spaces(txtCtrl);
	if (trim(txtCtrl.value) == "")
	{
		alert("Please enter "+ctrName+".");
		txtCtrl.focus();
		return false;		
	}
		
}
function SpecialValidate(txtCtrl, val) 
{
	var ctrName = val;
	/*if (trim(txtCtrl.value) == "")
	{
		alert("Please enter " + ctrName);
		txtCtrl.focus();	
		return false;		
	}*/
	var iChars = '@#$%^*+=[]\\\;{}|\"<>?`~1234567890';
	for (var i = 0; i < txtCtrl.value.length; i++) {
		if (iChars.indexOf(txtCtrl.value.charAt(i)) != -1) {
			//alert ("The "+ctrName+" has special characters. \nThese are not allowed.\n Please remove them.");
			alert ("Please enter "+ctrName+".");
			txtCtrl.select();
			txtCtrl.focus();
			return false;
		}
 	 }	
}
function Validate()
{
	if(TextValidate(document.frmsubscription.name,"the name")==false){ return false;}	
	if(SpecialValidate(document.frmsubscription.name,"the name with out special characters or numbers")==false){return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmsubscription.email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");		
		document.frmsubscription.email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmsubscription.email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");
		document.frmsubscription.email.focus();	   	
		document.frmsubscription.email.select();
		return false;
	}
	/*if(TextValidate(document.frmsubscription.phone,"the phone number")==false){ return false;}	
	if(isNaN(document.frmsubscription.phone.value))
	{
		alert("Please enter numeric values for phone number.");	
		document.frmsubscription.phone.focus();
		return false;
	}*/
	
	
	if(document.frmsubscription.phone.value == "")
	{
		alert("Please enter Phone Number");		
		document.frmsubscription.phone.focus();   
		return false;
		
	}
	
	len=document.frmsubscription.phone.value
	//alert(len);
	//alert(len.length);
	if(len.length<10)
	{
		alert(' Please enter a 10 digit Phone Number');
		document.frmsubscription.phone.focus();   
		return false;
	}
	
	
	if(TextValidate(document.frmsubscription.company,"the company name")==false){ return false;}
	document.frmsubscription.action = "subscribe.php?status=process";
	document.frmsubscription.submit();
}
function Validatelogin()
{
	if(TextValidate(document.frmsubscription.username,"the username")==false){ return false;}		
	if(TextValidate(document.frmsubscription.password,"the password")==false){ return false;}	
	document.frmsubscription.action = "admin-login.php?status=process";
	document.frmsubscription.submit();
}
function Validatedelete(id)
{
	if(confirm("Are you sure to delete the member?"))
	{
		document.frmsubscription.action = "memberlist.php?status=delete&id="+id;	
		document.frmsubscription.submit();
	}
}
function  checkEnter(e){ 
	//alert("in");//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		Validatelogin();
	}
}
function  checkEnter_subscribe(e){ 
	//alert("in");//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		Validate();
	}
}
function  checkEnter_subscribe_edit(e,id){ 
	//alert("in");//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		ValidateUpdate(id);
	}
}

function ValidateUpdate(id)
{
	if(TextValidate(document.frmsubscription.name,"the name")==false){ return false;}	
	if(SpecialValidate(document.frmsubscription.name,"the name with out special characters or numbers")==false){return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmsubscription.email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");		
		document.frmsubscription.email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmsubscription.email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");
		document.frmsubscription.email.focus();	   	
		document.frmsubscription.email.select();
		return false;
	}
	if(document.frmsubscription.phone.value == "")
	{
		alert("Please enter Phone Number");		
		document.frmsubscription.phone.focus();   
		return false;
		
	}
	
	len=document.frmsubscription.phone.value
	//alert(len);
	//alert(len.length);
	if(len.length<10)
	{
		alert(' Please enter a 10 digit Phone Number');
		document.frmsubscription.phone.focus();   
		return false;
	}
	//if(TextValidate(document.frmsubscription.phone,"the phone number")==false){ return false;}	
	/*if(isNaN(document.frmsubscription.phone.value))
	{
		alert("Please enter numeric values for phone number.");	
		document.frmsubscription.phone.focus();
		return false;
	}*/
	if(TextValidate(document.frmsubscription.company,"the company name")==false){ return false;}
	document.frmsubscription.action = "member_edit.php?status=process&id="+id;
	document.frmsubscription.submit();
}
function ValidateMember()
{
	if(TextValidate(document.frmsubscription.name,"the name")==false){ return false;}	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmsubscription.email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");		
		document.frmsubscription.email.focus();   	
		return false;		
	}	
	else if (!filter.test(document.frmsubscription.email.value)) 	
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com.");
		document.frmsubscription.email.focus();	   	
		document.frmsubscription.email.select();
		return false;
	}
	if(TextValidate(document.frmsubscription.phone,"the phone number")==false){ return false;}	
	if(isNaN(document.frmsubscription.phone.value))
	{
		alert("Please enter numeric values for phone number.");	
		document.frmsubscription.phone.focus();
		return false;
	}
	if(TextValidate(document.frmsubscription.company,"the company name")==false){ return false;}
	document.frmsubscription.action = "create-member.php?status=process";
	document.frmsubscription.submit();
}
function Validateasset()
{
	if(TextValidate(document.frmsubscription.year,"the year")==false){ return false;}
	if(document.frmsubscription.year.value == "0000")
	{
		alert("Please enter a valid year");	
		document.frmsubscription.year.focus();
		return false;
	}
	if(document.frmsubscription.year.value.length!=4)
	{
		alert("The year should be 4 digits");	
		document.frmsubscription.year.focus();
		return false;
	}
	document.frmsubscription.action = "assetallocator.php?status=process";
	document.frmsubscription.submit();
}
function validateasset2()
{
	if(isNaN(document.frmsubscription.year.value))
	{
		//alert("Please enter numeric values for year");	
		document.frmsubscription.year.value = "";
		return false;
	}	
}
function rejectAlphaSplChars(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;
 	return true;
}

function rejectAlphaSplCharsnumber(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 40 || charCode > 57) || (charCode>41 && charCode<45) || (charCode==47))
	{
		return false;
	}
	return true;
}
function rejectAlphaSplCharsnumberadmin(evt,id)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 40 || charCode > 57) || (charCode>41 && charCode<45) || (charCode==47))
	{
		return false;
	}
	return true;
}
function focusname()
{
	document.frmsubscription.name.focus();	
}