var errorCount = 0;
var errorMessage = '';
var isErrorFree = true ;


function addErrorMessage(errStmt)
{
	errorCount ++ ;
	errorMessage = errorMessage + '|'+ errStmt;
}


function displayError()
{   
	if (errorCount == 0)
		return true;
	else
	{   
		var Args = new Array(errorCount,errorMessage) ;
		var url = 'error.htm'
		var Features = "dialogHeight:300px;dialogWidth:400px;center:1;status:0;scroll:0;help:0;resizable:0" ;
		window.showModalDialog(url,Args,Features)
		return false;
	}
}



function isFilled(objControl, Label)
{	
	var cell = document.all('td' + objControl.name);
	if (Label == null)
		Label = objControl.Label;
	
	if (objControl[0] && (objControl[0].type == "checkbox" || objControl[0].type == "radio"))
	{
		for(i=0; i<objControl.length; i++)
		{
			if(objControl[i].checked == true)
				return true;
		}
		
		cell = document.all('td' + objControl[0].name);
		
		errStmt = Label + ' can not be blank!';
		
		addErrorMessage(errStmt);
		if (cell)
			cell.style.color = 'Red';
		return false;
		
	}
	else if (objControl.value == "")
	{
		errStmt = Label + ' can not be blank!';
		addErrorMessage(errStmt);
		if (cell)
			cell.style.color = 'Red';
		return false;
	}
	else if (objControl.value.toUpperCase == "--SELECT FROM HERE--")
	{
		errStmt = Label + ' can not be blank!';
		addErrorMessage(errStmt);
		if (cell)
			cell.style.color = 'Red';
		return false;
	}
	else if (objControl.value == "--Select from here--")
	{
		errStmt = 'Please select ' + Label +'!';
		addErrorMessage(errStmt);
		if (cell)
			cell.style.color = 'Red';
		return false;
	}

	else
	{	
		if (cell)
			cell.style.color = 'Black';
		return true;
	}
}

function isNumeric(objControl, Label)
{

var cell = document.all('td' + objControl.name);



	if (Label == null)
		Label = objControl.Label;


if (objControl.value != "" && isNaN(objControl.value))
{
	errStmt = Label + ' should be numeric!';
		addErrorMessage(errStmt);
		if (cell)
			cell.style.color = 'Red';
		return false;
	}
else
//	{
//	if (cell)
//			cell.style.color = 'Black';
		return true;
	//}*/
}
function isEmailAddress(objControl, Label)
{

var cell = document.all('td' + objControl.name);



	if (Label == null)
		Label = objControl.Label;
		
			
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
				if (filter.test(objControl.value))
				   //	{
						//	if (cell)
						//			cell.style.color = 'Black';
					return true;
					//}*/
	
				else
					{
					 errStmt = Label + ' should be vaild Email Address!';
					 addErrorMessage(errStmt);
					 if (cell)
						cell.style.color = 'Red';
					 return false;
					
					}
				
		}

//Pankaj --Preserve Zeros's up to X no of places.
//Ex. 	preserveZeros(100.5,3)-> 100.500
//Ex.	preserveZeros(100.5,2)-> 100.50
//Ex.	preserveZeros(100,3)-> 100.000
		
function preserveZeros(val,noOfPlaces)
{
	var i;
	var decimalPlaces = noOfPlaces;
    val = val + '';
	if (decimalPlaces <= 0) return val; 
	var decimalPos = val.indexOf('.');
	if (decimalPos == -1)
	{
		val += '.';
		for (i=0; i<decimalPlaces; i++)
		{
			val += '0';
		}
	}
	else
	{
		var actualDecimals = (val.length - 1) - decimalPos;
		var difference = decimalPlaces - actualDecimals;
		for (i=0; i<difference; i++)
		{
			val += '0';
		}
	}
	
	return val;
}


