function trimEmail(ss)
{
	i = ss.length;
s = ""
		for(j=0;j<=i;j++)
		{
			abc=ss.charAt(j);
			
				if (abc==" ")
				{
					for(z=j;z<=i;z++)
						{
							s =  s + ss.charAt(z);
							//s + ss.replace(abc," ");
						}
				
					
				}
		}
		alert(s);
	return s;
	//return string.replace(" ","");
} 


function TrimValue(fieldName, fieldValue)
{


//var valueToPreserve;
//valueToPreserve = pastvalue
var s = new String(fieldValue);
var str = ""
var strSpace = " ";
var i,j,intCount;
//Trimming of Text Values
//to replace the enter pressed with space
	for(intCount=0;intCount<s.length;intCount++)
	//alert(s.charCodeAt(intCount));
	
		if (!((s.charCodeAt(intCount)!=13) && (s.charCodeAt(intCount)!=10) && (s.charCodeAt(intCount)!=32)))
		//s=s.replace(s.charAt(intCount)," ");
		//alert(s);
		s=s.replace(s.charAt(intCount)," ")
			for (i=0;i<s.length && s.charAt(i) == strSpace;i++);
				for (j=s.length; j>=0 && s.charAt(j - 1) == strSpace; j--);
					for (;i<j;i++)
					str = str + s.charAt(i);


	//Replacing blank value with pastvalue
	if (str=="")
	{
	alert("Blank values are not allowed");
	//fieldName.value = valueToPreserve;
	fieldName.select();
	fieldName.focus();    
	return false;
	}
	//Else put the Trimmed value 
	else
	{
	fieldName.value = str;
	//alert(fieldName.value);
	//alert(str);
	return true
	}
}


// JavaScript Document//Common Js for all Pages goes here
function isBlank(obj,displayName)
{
	var str="";
	str=obj.value;
	var len=str.length;
	var i;
	for(i=0;i<len;++i)
	{
		if(str.charAt(i)!=" ")
		{
			return false;
		}
	}
	alert(displayName+" cannot be left blank");
	obj.focus();
	return true;
}

function isBlankCustomMsg(obj,displayName)
{
	var str="";
	str=obj.value;
	var len=str.length;
	var i;
	for(i=0;i<len;++i)
	{
		if(str.charAt(i)!=" ")
		{
			return false;
		}
	}
	alert(displayName);
	obj.focus();
	return true;
}

function isNumber(obj,displayName)
{
	var str=trim(obj.value)
	for(i=0;i<str.length;i++)
	{
		if(str.charAt(i)<'0'||str.charAt(i)>'9')
		{	
			if((str.charAt(0))=="-")
			{
				i=i+1;
				continue;
			}
			alert(displayName);
			obj.focus();
			return false;
		}
	}
	return true;
} 

function hasNoSplChars(obj,displayName)
{
	var s="";
	s=trim(obj.value);
	splChars=new Array("~","`","!","@","#","$","%","^","&","*","(",")","-","=","\\","|",":",";","<",">",",",".");
	for(i=0;i<s.length;i++)
		for(j=0;j<splChars.length;j++)
		{
			if(s.charAt(i)==splChars[j])
			{
				alert(displayName);
				obj.focus();
				return false;
			}
		}
	return true;
}

function isDDMMYYYYDate(objFormField)
{
	var lsFieldVal = objFormField.value;
	var lsFieldLength = lsFieldVal.length;
	var thirdchar = lsFieldVal.substring(2,3);
	var sixthchar = lsFieldVal.substring(5,6);
	var separator = '/';
	if 	(
		(lsFieldLength == 10) &&
		(thirdchar == separator) &&
		(sixthchar == separator)
		)
		{
		//split the chars
		var liDayPart
		var liMonthPart
		var liYearPart
		if (lsFieldVal.substr(0,1) == 0)
			liDayPart = parseInt(lsFieldVal.substr(1,2));
		else
			liDayPart = parseInt(lsFieldVal.substr(0,2));

		if (lsFieldVal.substring(3,4) == 0)
			liMonthPart = parseInt(lsFieldVal.substring(4,5));
		else
			liMonthPart = parseInt(lsFieldVal.substring(3,5));

		liYearPart = parseInt(lsFieldVal.substring(6,10));

		//check overall validity
		if (
			(liDayPart >= 1) &&
			(liDayPart <= 31) &&
			(liMonthPart >= 1) &&
			(liMonthPart <= 12) &&
			(liYearPart >= 1920) &&
			(liYearPart <= 2004)
			)
			{
			//check for 30-day months
			if (
				(liMonthPart==4) ||
				(liMonthPart==6) ||
				(liMonthPart==9) ||
				(liMonthPart==11) 
				)
				{
				if ( liDayPart <= 30)
					{
					retval = true;
					}
				else
					{
					retval = false;
					}
				}
			else	//not a 30-day month
				{
				//if february
				if (liMonthPart == 2)
					{
					//check for leap year
					if ( (liYearPart % 4) != 0) 
						{
						liFebDays = 28;
						}
					else
						{
						if ((liYearPart % 400) == 0)
							{
							liFebDays = 29;
							}
						else
							{
							if ((liYearPart % 100) ==0)
								{
								liFebDays = 28;
								}
							else
								{
								liFebDays = 29;
								}
							}
						}

					if (liDayPart <= liFebDays)
						{
						retval = true;
						}
					else
						{
						retval = false;
						}
					}
				else	//31-day month
					{
					retval = true;
					}
				}
			}
		else
			{
				retval = false;
			}
		}
	else
		{
		retval = false;
		}

	return retval;
}


function trim(string)
{
	return string.replace(/^\s*|\s*$/g,"");
} 



	function showLength(field, countfield,maxLimit) 
	{			
			//setting the limit of the textarea to 500
			if (field.value.length > maxLimit) // if too long...trim it!
				field.value = field.value.substring(0, maxLimit);
			// otherwise, update 'characters left' counter
			else 
				if (document.all)
					{eval(countfield).innerText =  field.value.length;}
					else
					
					{						
						var strCtrlName = new String();
						var strtmp = new String();
						strCtrlName = countfield;
						strtmp = strCtrlName.substr(strCtrlName.lastIndexOf(".")+1,strCtrlName.length - strCtrlName.lastIndexOf("."));	
						document.getElementById(strtmp).innerHTML = field.value.length;
					}
					
	}
	
	function OnLoadshowLength(field1,field2)
	{
			var str = new String();
			str = field1;
				eval(field2).innerText = str.length ;
	}	
	
	


function echeck(str,alertmsg) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert(alertmsg);
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(alertmsg);
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(alertmsg);
		    return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
		    alert(alertmsg);
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(alertmsg);
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(alertmsg);
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(alertmsg);
		    return false;
		 }

 		 return true;					
	}
