function ChkBoxSelected(formName,fldName)
	{
			
		var elementLength = 0;
		var totalElements = 0;
		totalElements = eval("document." + formName + ".elements.length");
		//alert(totalElements);
		
			for(i = 0; i < totalElements; i++)
				{
					if(document.forms[0].elements[i].name == fldName)
						{
							if(document.forms[0].elements[i].checked != 0)
							   {
								elementLength++;
								}
						}			
				 }
		
			if(elementLength <= 0)
				{
					alert("Please select at least one item.");
					return false;
				}
	return true;		
			
        
}
function deleteItem(formName,fldName)
	{
		if(ChkBoxSelected(formName,fldName))
		{
				
				if(confirm("Are you sure you want to delete the selected item(s) from the cart?"))
						{
							document.cart.frmAction.value = "delete";
							document.cart.submit();
							return true;
						}
						else
						{
						   
							return false;
						}
				
		 }	
		 else
		 {
		 		return false;
		 }
					
		
	}


function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
//function to open in custom window
function openWindow(url,window_name,winWidth,winHeight,fscroll) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	

	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	if(fscroll == '') {fscroll = 0}
	window.open(url,window_name,"width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=" + fscroll + ",resizable=0");
}

function checkEmail(emailString) {
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}
function getSelBoxText(frmName,objName) // return text in a select box
{
	selItemPos = eval("document." + frmName + "." + objName + ".selectedIndex");
	selText = eval("document." + frmName + "." + objName +".options[" + selItemPos + "].text");
	return selText;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (trimSpaces(formField.value) == "")
	{
		alert("Kindly enter a value for the '" + fieldLabel + "' field.");
		formField.focus();
		result = false;
	}
	
	return result;
}

function validLength(formField,fieldLabel,fieldLength,operator)
{
	var result = true;
	
	if(operator == ">") 
	{
		if(trimSpaces(formField.value.length) > parseInt(fieldLength))
		{
			alert("The field '" + fieldLabel + "' cannot exceed " + fieldLength + " characters");
			formField.focus();
			result = false;
		}
	}
	else if(operator == "<")
	{
		if(trimSpaces(formField.value.length) < parseInt(fieldLength))
		{
			alert("The field '" + fieldLabel + "' should be atleast " + fieldLength + " characters");
			formField.focus();
			result = false;
		}
	}
	
	return result;

}

function validCompare(field1, field2, fieldLabel)
{
	var result = true;
	
	if(trimSpaces(field1.value) != trimSpaces(field2.value))
	{
		alert("The " + fieldLabel + " do not match.");
		field2.focus();
		result = false;
	}
	
	return result;
}

function firstFocus(theForm)
{
      for (i=0;i<theForm.length;i++)
      {
         if ((theForm.elements[i].type=="text")||
           (theForm.elements[i].type=="textarea")||
           (theForm.elements[i].type.toString().charAt(0)=="s"))
         {
            theForm.elements[i].focus();
            break;
         }
      }
}
function validFieldLengthRange(formField,minVal,maxVal,fieldLabel)
{
	var result = true;	
	if(trimSpaces(formField.value.length) > parseInt(trimSpaces(maxVal)) || trimSpaces(formField.value.length) < parseInt(trimSpaces(minVal)) )
	{
		alert("The value of the field '" + fieldLabel + "' must be between '" + minVal + "' and '" + maxVal + "' characters");
		formField.focus();
		result = false;
	}
	
	return result;

}

function checkFileExtension(fileName,fileExtension)
{
	fileArray = fileName.split(".");
	maxElemCount = fileArray.length;
	if(fileArray[maxElemCount-1]==fileExtension)
		{
			
			return true;
		}
		else
		{
			return false;
		}
}


	function isValidDate(strDate) {		
		//alert('inside func val');
		var tmpDate = strDate;
		
		ndx = tmpDate.indexOf('/');
		dtDay = parseInt(tmpDate.substring(0,ndx));
		tmpDate = tmpDate.substring(ndx+1);
		ndx = tmpDate.indexOf('/');
		dtMonth = parseInt(tmpDate.substring(0,ndx));
		tmpDate = tmpDate.substring(ndx+1);
		dtYear = parseInt(tmpDate);
		
		//alert('Day = ' + dtDay + '\nMonth = ' + dtMonth +'\nYear = '+ dtYear);
		
		bValidMonth = false;
		
		if (dtMonth==2) {
			bValidMonth = true;
			if (dtYear%4 == 0) {
				if ((dtDay >=1) && (dtDay <= 29))
					return true;
				else {
					return false;
				}
			}
			else {
				if ((dtDay >=1) && (dtDay <= 28))
					return true;
				else {
					return false;
				}
			}
		}
		
		if ((dtMonth==1) || (dtMonth==3) || (dtMonth==5) || (dtMonth==7) || (dtMonth==8) || (dtMonth==10) || (dtMonth==12)) {
			bValidMonth = true;
			if ((dtDay >=1) && (dtDay <= 31))
				return true;
			else {
				return false;
			}
		}
		if ((dtMonth==4) || (dtMonth==6) || (dtMonth==9) || (dtMonth==11)) {
			bValidMonth = true;
			if ((dtDay >=1) && (dtDay <= 30))
				return true;
			else {
				return false;
			}
		}
		
		if (bValidMonth == false) {
			return false;
		}
	}	


	function checkIfValueExists(frmObj,fldName,checkVal)
	{
		//to check if a value exists in a hidden field
		//frmobj reference to the form
		//fldname :name of the field containing the values
		//checkVal :value that has to be checked in the hidden field
		var valStr,valStrArr,totElemCount,lCtr;
		
		valStr= eval("frmObj" + "." + fldName + ".value");
		valStr = trimSpaces(valStr);
		if(valStr.length>0) //ensure that aleast once value is there
		{
			//valStr = frmObj.checkFieldValues.value;
			//alert(valStr);
			valStrArr = valStr.split(",");
			
			totElemCount = valStrArr.length;
			//alert(totElemCount);
			if(totElemCount>1) //array has been created
			{
				for(lCtr=0;lCtr<totElemCount;lCtr++)
				{
					
					//alert(valStrArr[lCtr].toUpperCase() + "==" + checkVal.toUpperCase());
					if(trimSpaces(valStrArr[lCtr].toUpperCase())==checkVal.toUpperCase())
					{
						return true;
					}
				}
			}
			else //incase there is only one value array is not created
			{
				if(trimSpaces(valStr.toUpperCase())==checkVal.toUpperCase())
					{
						return true;
					}
			}
		}
		return false;
	}

	function hide(elem) {
		//alert(this);
		elem.value = "";
	}
