    function DecProd(strVal)
{
	if (parseInt(document.getElementById('ctl00$ContentPlaceHolder1$QUAN' + strVal).value) > 0)
	{
		var strAmount;
		var strSubAmount;
		var strTotal;
	    var capValue='0';
	    
		if (document.all)
		{
			strAmount = document.getElementById('PRICE' + strVal).innerText;
			strSubAmount = document.getElementById('SUB' + strVal).innerText;
			strTotal = document.getElementById('TotalCell').innerText;
		}
		else
		{
			strAmount = document.getElementById('PRICE' + strVal).textContent;
			strSubAmount = document.getElementById('SUB' + strVal).textContent;
			strTotal = document.getElementById('TotalCell').textContent;
		}
				
		//********************
		capValue =  document.getElementById('CAP' + strVal).innerText;		
	
	if(capValue == 0) // NO CAPPING FOUND
	{	
	    strSubAmount = parseFloat(strSubAmount) - parseFloat(strAmount);
		strTotal= parseFloat(strTotal) -  parseFloat(strAmount);	
	}	
	else
	{    	  
	    strSubAmount = parseFloat(strSubAmount) -  parseFloat(strAmount);
	    strTotal= parseFloat(strTotal);
	    capValue = parseFloat(capValue);
	    
	    
	    document.getElementById('SUB' + strVal).innerText = formatCurrency(strSubAmount)
	    var thresholdTotal = GetAllCapedCellsTotal(); // GET THE TOTAL OF ALL CAPPING VARIABLES     
	    var nonCapedCellsTotal = GetAllNONCapedCellsTotal();
	     
	    if(thresholdTotal > parseFloat(capValue)) // PERFORM CAPPING
	    {		       
	        strTotal=  parseFloat(capValue) + parseFloat(nonCapedCellsTotal);	   
	    }		    
	    else // CAPPING LIMIT NOT REACHED
	    {	    	    
	    strTotal= parseFloat(thresholdTotal) +  parseFloat(nonCapedCellsTotal);
	    }
	}
	//********	
		
		if (document.all)
		{
			document.getElementById('SUB' + strVal).innerText = formatCurrency(strSubAmount);
			document.getElementById('TotalCell').innerText = formatCurrency(strTotal);
		}
		else
		{
			document.getElementById('SUB' + strVal).textContent = formatCurrency(strSubAmount);
			document.getElementById('TotalCell').textContent = formatCurrency(strTotal);
		}
		document.getElementById('ctl00$ContentPlaceHolder1$QUAN' + strVal).value =  parseInt(document.getElementById('ctl00$ContentPlaceHolder1$QUAN' + strVal).value) - 1;
	}
	
}

function IncProd(strVal)
{
    var strAmount;
    var strSubAmount;
    var strTotal;
    var capValue='0';
    
    if (document.all)
    {
		strAmount = document.getElementById('PRICE' + strVal).innerText;
		strSubAmount = document.getElementById('SUB' + strVal).innerText;
		strTotal = document.getElementById('TotalCell').innerText;
	}
	else
	{
		strAmount = document.getElementById('PRICE' + strVal).textContent;
		strSubAmount = document.getElementById('SUB' + strVal).textContent;
		strTotal = document.getElementById('TotalCell').textContent;
	}


 //******** IMPLEMENTS PRODUCT CAPPING RULE HERE ***		
	capValue =  document.getElementById('CAP' + strVal).innerText;		
	
	if(capValue == 0) // NO CAPPING FOUND
	{	
	strSubAmount = parseFloat(strSubAmount) +  parseFloat(strAmount);
	strTotal= parseFloat(strTotal) +  parseFloat(strAmount);
	
	}	
	else
	{    	  
	    strSubAmount = parseFloat(strSubAmount) +  parseFloat(strAmount);
	    strTotal= parseFloat(strTotal);
	    capValue = parseFloat(capValue);
	    
	    
	    document.getElementById('SUB' + strVal).innerText = formatCurrency(strSubAmount)
	     var thresholdTotal = GetAllCapedCellsTotal(); // GET THE TOTAL OF ALL CAPPING VARIABLES     
	     var nonCapedCellsTotal = GetAllNONCapedCellsTotal();
	     
	    if(thresholdTotal > parseFloat(capValue)) // PERFORM CAPPING
	    {		       
	        strTotal=  parseFloat(capValue) + parseFloat(nonCapedCellsTotal);	   
	    }		    
	    else // CAPPING LIMIT NOT REACHED
	    {	    
	    strTotal= parseFloat(strTotal) +  parseFloat(strAmount);
	    }
	}

	//********	



	if (document.all)
    {
		document.getElementById('SUB' + strVal).innerText = formatCurrency(strSubAmount)
		document.getElementById('TotalCell').innerText = formatCurrency(strTotal)
	}
	else
	{
		document.getElementById('SUB' + strVal).textContent = formatCurrency(strSubAmount)
		document.getElementById('TotalCell').textContent = formatCurrency(strTotal)
	}
	document.getElementById('ctl00$ContentPlaceHolder1$QUAN' + strVal).value = parseInt(document.getElementById('ctl00$ContentPlaceHolder1$QUAN' + strVal).value) + 1;
}


function GetAllCapedCellsTotal()
{   
   var a = document.getElementById('SUB16').innerText;
   var b = document.getElementById('SUB17').innerText;   
   var c = document.getElementById('SUB18').innerText;
   var d = document.getElementById('SUB19').innerText;   
   
   var e = document.getElementById('SUB24').innerText;
   var f = document.getElementById('SUB25').innerText;   
   var g = document.getElementById('SUB26').innerText;
   var h = document.getElementById('SUB27').innerText;
   
   var i = document.getElementById('SUB28').innerText;
   var j = document.getElementById('SUB29').innerText;   
   var k = document.getElementById('SUB30').innerText;
   var l = document.getElementById('SUB31').innerText;
   
   var result = parseFloat(a) + parseFloat(b)+parseFloat(c)+parseFloat(d)+parseFloat(e) + parseFloat(f)+parseFloat(g)+parseFloat(h)+parseFloat(i) + parseFloat(j)+parseFloat(k)+parseFloat(l);   
   return result;   
}


function GetAllNONCapedCellsTotal()
{
   var a = document.getElementById('SUB9').innerText;
   var b = document.getElementById('SUB7').innerText;   
   var c = document.getElementById('SUB5').innerText;
   var d = document.getElementById('SUB33').innerText;
   
   var result = parseFloat(a) + parseFloat(b)+parseFloat(c)+parseFloat(d);
   return result;
   
}


function formatCurrency(Value)
{
	var fValue = Value.toFixed(2);
	var sValue = fValue + "";
	var oRE = /(\d)(?=(d\d\d)+(?!d))/g;
	return sValue.replace(oRE,"$1,");
}

function Delete(ID)
{	
	if(confirm("Are you sure you want to remove this membership?"))
	{
		javascript:__doPostBack('DELETEMEMBER',ID);
	}
}

function ResetFormData()
{
        for(var i = 0; i < document.forms[0].elements.length; i++) {
               var element = document.forms[0].elements[i];
               if(element.type == "text") {
                   if(element.name != null && element.name.indexOf("QUAN") != -1) {
                           element.value = 0;

                       }
               }                                                                                                                                                  
        }       
  
  }


function ImgExpandCollapseO(imgID, obj1ID)
{
    var img = document.getElementById(imgID);
    
    var obj1 = document.getElementById(obj1ID);

    if (obj1.style.display == "none")
    {
        obj1.style.display = "";
        img.src = "Resources.aspx?Res=collapse.gif";   
    }
    else
    {
        obj1.style.display = "none";
        img.src ="Resources.aspx?Res=expand.gif";
    }
}



function ValidateDateInput(obj,evt)
{ 
	var e = evt? evt : window.event; 
	if(!e) return; 
	var key = 0; 
	if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keycode==0 use 'which' 
	else if (typeof(e.which)!= 'undefined') { key = e.which; } 
	
	if(key == 8) //allow thebackspace key to delete characters when it is pressed
	{
	    return true;
	}
	
	if(obj.value.length >= 10) { 
		return false;
	} 
	
	else if(key == 47 && (obj.value.length == 2 || obj.value.length == 5)) {
		return true;
	}
	else if(key > 57 || key < 48)
	{
        return false;
	} 
	else if(obj.value.length == 1 || obj.value.length == 4)
	{
		obj.value += String.fromCharCode(key,47);
		return false;                 
	} else {
		return true
	}
}

function OnDateBlur(objDate, format)
{
	if(objDate.value == "")
	{
		objDate.value = format;
		objDate.style.color = "gray";
	}
	else
	{
	    ValidateDate(objDate);
	}
	return true;
}

function OnDateFocus(objDate, format)
{
	if(objDate.value == format)
	{
		objDate.value = "";
		objDate.style.color = "black";
	}
	return true;
}


function OnCheckChanged(gridItem, columnIndex, checkbox)
{   
    var hiddenField = document.getElementById(MemberHiddenFieldID);

    if (checkbox.checked)
    {  
        AddID(gridItem, hiddenField);
    }
    else
    {
        RemoveID(gridItem, hiddenField);
    }

    return true;
}

function AddID(gridItm, hiddenField)
{
    var idd = gridItm.Id + ";";
    
    //add the id only if it is NOt already added
    if ((hiddenField.value).indexOf(";" + idd) < 0)
    {
        hiddenField.value += idd;
    }
}

function RemoveID(gridItm, hiddenField)
{
    var idd = gridItm.Id + ";";
    if ((hiddenField.value).indexOf(";" + idd) >= 0)
    {
        hiddenField.value = (hiddenField.value).replace(idd, "");
    }
}


var chkStatus = false;
var MemberHiddenFieldID = "";

function CheckAllItems(headerChk, grid, hiddenFieldID)
{
    chkStatus = !headerChk.checked;
   
    var gridItem;
    var hiddenField = document.getElementById(hiddenFieldID);
    chkStatus = chkStatus?false:true;
        
    var grd = document.getElementById(grid.Id);
    var chs = getElementsByAttribute(grd, 'input', 'type', 'checkbox');
    
    //the first checkbox (0 index) is the header's
    for (i = 1; i < chs.length; i++)
    {   
        chs[i].checked = chkStatus;
        
        gridItem = grid.Table.getRow(i-1);
        if (gridItem != null)
        {
            if(chkStatus)
            {
                if (i == 1) hiddenField.value = ";";
                GridItemAddID(gridItem, hiddenField);
            }
            else
            {                
                GridItemRemoveID(gridItem, hiddenField);               
            }
        }
    }
    
    if (chkStatus)
    {
        checkedItems = grid.Table.getRowCount();
        var trs;
        if (document.all) //IE
        {
            trs = getElementsByAttribute(grd, 'tr', 'className', 'Row');
        }
        else
        {
            trs = getElementsByAttribute(grd, 'tr', 'class', 'Row');
        }
        
        for (i = 0; i < trs.length; i++)
        {
             trs[i].className = "SelectedRow";
        }
    }
    else
    {
        checkedItems = 0;
        var trsU;
        if (document.all) //IE
        {
            trsU = getElementsByAttribute(grd, 'tr', 'className', 'SelectedRow');
        }
        else
        {
            trsU = getElementsByAttribute(grd, 'tr', 'class', 'SelectedRow');
        }

        for (j = 0; j < trsU.length; j++)
        {
             trsU[j].className = "Row";
        }
    }    
}

function GridItemAddID(gridItm, hiddenField)
{
    var idd = gridItm.Id + ";";
    
    //add the id only if it is NOt already added
    if ((hiddenField.value).indexOf(";" + idd) < 0)
    {
        hiddenField.value += idd;
    }
}

function GridItemRemoveID(gridItm, hiddenField)
{
    var idd = gridItm.Id + ";";
    if ((hiddenField.value).indexOf(";" + idd) >= 0)
    {
        hiddenField.value = (hiddenField.value).replace(idd, "");
    }
}

function EmailBtnClick(hiddenField)
{
    var hidn = document.getElementById(hiddenField);

    if (hidn.value == "" || hidn.value == ";")
    {
        alert("Please select Individual(s) to email.");
        return false;
    }
    return true;
}

 function isCheckedBoxValid()
        { 
          if(document.aspnetForm.chkBoxAgree.checked == true && document.aspnetForm.chkBoxAgree2.checked == true && document.aspnetForm.chkBoxRequirement.checked == true && document.aspnetForm.chkBoxRequirement2.checked == true)
                {
                document.aspnetForm.ctl00_ContentPlaceHolder1_btnNext.disabled = false; 
                }
                else
                {
                 document.aspnetForm.ctl00_ContentPlaceHolder1_btnNext.disabled = true;
                }           
        }
        
  function isCheckBoxchecked()
        { 
          if(document.aspnetForm.chkBoxAgree.checked == true)
                {
                document.aspnetForm.ctl00_ContentPlaceHolder1_btnNext.disabled = false; 
                }
                else
                {
                 document.aspnetForm.ctl00_ContentPlaceHolder1_btnNext.disabled = true;
                }           
        }
        
 function checkIsValidYear(source, args)
 {
    if(isNaN(document.aspnetForm.ctl00_ContentPlaceHolder1_txtEstablished.value))
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid = true;
    }
 }
 
   function showLoadingWindow()
  {
            document.getElementById("transparentback").style.display = "";
            document.getElementById("divLoadingImage").style.display = "";
            setTimeout("waitb()", 1000);  
  }
  
  function showLoadingWindowWithMessage()
  {
			document.getElementById("transparentback").style.display = "";
            document.getElementById("divLoadingImage").style.display = "";
            setTimeout("waitb()", 1000);
            document.getElementById("ctl00_ContentPlaceHolder1_divProcessingMessage").style.display = "block";             
  }
  
  function Validate_3Digits (source, args)
{    
    args.IsValid = false;
    if (isInteger_(args.Value.toString()) && args.Value.toString().length == 3)
        args.IsValid = true;
}
function Validate_4Digits (source, args)
{    
    args.IsValid = false;
    if (isInteger_(args.Value.toString()) && args.Value.toString().length == 4)
        args.IsValid = true;
}
function isInteger_(val){

for(var i=0;i<val.length;i++){

if(!isDigit(val.charAt(i))){return false;}
}
return true;
}

function isDigit(n) 
{
    if((n < '') || ("9" < n)) 
    {
        return false
    }
    else 
    {
        return true
    }
}


function validateEmail(validationElement, messageReceiver, required)  
{
    var stat = commonCheck(validationElement, messageReceiver, required);
    
    if (stat == false) return false;
    
    var elem = document.getElementById(messageReceiver);
    
    var tfld = validationElement.value;
    
    if (required == false && tfld == "") 
    {   
        elem.innerHTML = ""; 
        return true;
    }

    var email = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/

    if (!email.test(tfld)) 
    {
        elem.className = "required";
        elem.innerHTML = " (Not a valid e-mail address)";
        validationElement.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function commonCheck(validationElement, messageReceiver, required)
{
    var elem = document.getElementById(messageReceiver);
    
    if (validationElement == null) return false;
    
    if (emptyString.test(validationElement.value)) 
    {
        if (required) 
        {
            elem.className = "required";
            elem.innerHTML = "(Required)";            
            validationElement.focus();
            return false;
        }
    }
    else
    {    
        return true;
    }
}

emptyString = /^\s*$/

function MembershipPageValidate()
{
    var errs = 0;
    
    var firstName = document.getElementById('txtFirstName');
    var lastName = document.getElementById('txtLastName');
    var address1 = document.getElementById('txtAddress1');
    var city = document.getElementById('txtCity');
   // var postCode = document.getElementById('txtPostCode');
    var email = document.getElementById('txtEmail');
    var phone = document.getElementById('txtPhone');
    
    if (firstName != null) if (!commonCheck(firstName, "required_1", true)) errs += 1;
    if (lastName != null) if (!commonCheck(lastName, "required_1", true)) errs += 1;
    if (address1 != null) if (!commonCheck(address1, "required_2", true)) errs += 1;
    if (city != null) if (!commonCheck(city, "required_2", true)) errs += 1;
   // if (postCode != null) if (!commonCheck(postCode, "required_2", true)) errs += 1;
    if (email != null) if (!validateEmail(email, "required_3", true)) errs += 1;   
    if (phone != null) if (!commonCheck(phone, "required_4", true)) errs += 1;

    if (errs >= 1)  
	{
	    alert('There are fields which need correction before sending or going to another page');
	    return false;
	}
	
	return true;
}

function ShowHideAddtoGroup(objID) {
	var obj = document.getElementById(objID);

	if (obj != null) {
		if (obj.style.display == "none") {
			obj.style.display = "";
		}
		else {
			obj.style.display = "none";
		}
	}
}

