/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}


///  email check by swarn
function fnemailCheck()
{  
 var l_EmailId = window.document.frmCheckout.txtPaymentEmail.value;
  
var validmail="`~!#$%^&*()+=|\\}]{[;:'<,>/?/"
var dou='"'
var	EmailError=0;


	if (trim(l_EmailId) == "-" || (trim(l_EmailId) == "") )
	{
		return false;  
	}
	else
	{
		var index, dotIndex, sKana, kanaIndex;
		var L1=0;
		var i,a2,aa
		var lenx  = l_EmailId.length;
              
			//To check for the first occurrence of .
			if(mid(l_EmailId,1,1) == "." )
				return false;
          alert(l_EmailId);

			for (i=1;i<=lenx;i++){
				//To check for space
				if (mid(l_EmailId,i,1)== " "){
					return false;
				}
			}

        	L1=validmail.length;

			for (i=0; i<L1;i++)
			{
				aa=mid(validmail, i ,1);

				a2=l_EmailId.indexOf(aa)

				if (l_EmailId.indexOf(aa) != -1)
				{
					return false;
				}
			}
			//Check for double quotes
			if (l_EmailId.indexOf(dou) != -1)
			{
				return false;
			}


		index = l_EmailId.indexOf("@");
		if (index < 0 || index == 0)
			return false;
		if (index < l_EmailId.indexOf("@", index+1))
			return false;

		dotIndex = l_EmailId.indexOf(".", index);

		if (dotIndex < 0)
			return false ;
		if ((index + 1) == dotIndex)
			return false ;
		if ((l_EmailId.lastIndexOf(".")+1) == l_EmailId.length)
			return false ;
		if (l_EmailId.indexOf("..", index) > 0)
			return false ;
		if (l_EmailId.indexOf("..") > 0)
			return false;
		if (l_EmailId.indexOf(" ") > 0)
			return false ;

	}
	return true ;
}
