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(eval("document." + formName + ".elements[i].name") ==  fldName)
						{
							if(eval("document." + formName + ".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;

}