function isBlank( s )
{
	if(trim(s).length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//Trim
function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}


//email validate
function validateEmail(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str))
	{
		return false;
	}
	return true;
}

//check date validation
function checkdate(dateField)
{
// ------------- Checking for date in MM/DD/YYYY format ---------------------

	var expirydate="";
	var date="";
	var month="";
	var year="";
	expirydate = dateField;
	month=expirydate.substring(0,expirydate.indexOf("/"));
	date=expirydate.substring((expirydate.indexOf("/")+1),expirydate.indexOf("/",(expirydate.indexOf("/")+2)));
	year=expirydate.substring((expirydate.lastIndexOf("/")+1));
	if(expirydate.indexOf("/")==-1)
	{
		alert("Invalid Date Format");
		return false;
	}

	if(isNaN(date) || isNaN(month) || isNaN(year))
	{
		alert("Enter Date In Numerics Only");
		return false;
	}

	if(date > 31 || date < 1)
	{
		alert("Invalid Date Of Month");
		return false;
	}

	if(month > 12 || month < 1)
	{
		alert("Invalid Month");
		return false;
	}

	if(year < 1850 || year > 5002)
	{
		alert("Invalid Year");
		return false;
	}

	if(month == 4 || month == 6 || month == 9 || month == 11)
	{
		if(date > 30)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}

	if(month == 2)
	{
//----------- checking for leap year-------------
		var lyear=year-1848
		if((lyear%4==0) && (date<30))
		{
			if(date > 29)
			{
				alert("Invalid Date Of Month")
				return false;
			}
			//alert("leap year")
		}
		else if(date > 28)
		{
			alert("Invalid Date Of Month")
			return false;
		}
	}
	
	return true;

}
//-------------- Ajax -------------
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	//Internet Explorer
	try
	{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}
return xmlHttp;
}
function ajaxobject()
{
	try{
	ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return ajaxRequest;
}
function sendDetails(URL,parameters)
{
	ajaxRequest.open("POST", URL , true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	ajaxRequest.send(parameters);
}

function selectdatabasevalue(toselect,cmb) //compares value not text
{
	for(i=0;i<eval(cmb).length;i++)
	{
		if(eval(cmb).options[i].value.toUpperCase()==toselect.toUpperCase())
		{
			eval(cmb).selectedIndex = i;
		}
	}
}
function TestFileType( fileName, fileTypes ) {
	if (!fileName) return;
	
	dots = fileName.split(".")
	
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	//CONVERT FILETYPE IN lower case AS JAVASCRIPT IS CASE SENSITIVE.
	fileType = fileType.toLowerCase();
	//alert(fileType);
	return (fileTypes.join(".").indexOf(fileType) != -1) ? true : false;
}
function validateName(objVal)
{
	var illegalChars = /[^\A-Za-z- ']/; // allow letters, spaces and hyphen
	strng = objVal;
	if (illegalChars.test(strng)) 
	{
		return false;
	}
	return true;
}
