﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
/// <reference path="helpers.js" />

function validateCellSubmit() {
    //form 1
    changecolour(validation1);
    if (!validateBoxes(validation1)) {return false; }
    if (!validateContactnumbers(telValidation)) { return false; }
    //form2
    changecolourddl(validation2);
    if (!validateDDL(validation2)) {return false; }           
    //form 3
    var isCheck = false;
    for (i = 0; i < validation3.length; i++) {
        var rdo = document.getElementById(validation3[i]);
        if (rdo.checked) { isCheck = true; } else { rdo.focus(); }
    }
    if (!isCheck) {        
        alert('Please complete all the required fields\nRequired fields are highlighted');
        return false;
    };
    //form 4
    var isCheck = false;
    for (i = 0; i < validation4.length; i++) {
        var rdo = document.getElementById(validation4[i]);
        if (rdo.checked) { isCheck = true; } else { rdo.focus(); }
    }
    if (!isCheck) {
        alert('Please complete all the required fields\nRequired fields are highlighted');
        return false;
    };
    
    return true;
}
/************************************************************************************************/
function ValidateFinance() {
    var pass = true;
    var passDDL = true;

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");
    var $requiredddl = $(".required2");
    var $requiredItem = $(".requiredDDL");

    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });

    $required.each(function(i) {
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }
    if ($requiredItem.attr("selectedIndex") == 2 || $requiredItem.attr("selectedIndex") == 3) {
        $requiredddl.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    $(this).css('background-color', '#ffeeee');
                    passDDL = false;
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                    passDDL = false;
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }

    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }
    
    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }

    if (!passDDL) {
        alert('Please enter your partner details.');$requiredddl[0].focus();pass = false;
    }

    var iRdo = 0;
    var $rdos = $("input[type='checkbox']");
    $rdos.each(function() {
        if ($(this).attr("checked")) iRdo = iRdo + 1;
    });
    if (iRdo != 2 && pass) { pass = false; alert('You must agree to both terms and conditions'); $rdos[0].focus(); }

    return pass;
}
/************************************************************************************************/
function ValidateGiftCards() {
    var pass = true;   

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");
    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });
    
    $required.each(function(i) {
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }

    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }
    
    if ($("input[id*='ckTerm']").attr('checked') == false) {alert('You must agree to the terms and conditions to continue');return false;}
    if ($(".voucherValue").attr('value') == '0') {alert('Please enter a valid gift card cost');return false; }
    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }
    
    return pass;
}
/************************************************************************************************/
function ValidateNewsletterSignup() {
    //form 1
    changecolour(validation1);
    try { changecolour(telValidation); } catch (err) { }
    if (!validateBoxes(validation1)) { return false; }
    try{
        if (!validateContactnumbers(telValidation)) { return false; }
    }catch(err){}       
    return true;
}
/************************************************************************************************/
function ValidateUpdateDetails() {
    //form 1
    changecolour(validation1);
    if (!validateBoxes(validation1)) { return false; }
    try {
        if (!validateContactnumbers(telValidation)) { return false; }
    } catch (err) { }
    
    return true;
    
}
/************************************************************************************************/
function ValidateFeedback() {
    //form 1
    changecolour(validation1);
    try { changecolour(telValidation); } catch (err) { }
    changecolourddl(validation2);

    if (!validateDDL(validation2)) { return false; }
    if (!validateBoxes(validation1)) { return false; }
    try {
        if (!validateContactnumbers(telValidation)) { return false; }
    } catch (err) { }
    
    
    return true;
}
/************************************************************************************************/
function ValidateDelivery() {
    //form 1
    changecolour(validation1);
    changecolourddl(validation5);
    changecolourddl(validation2);
    changecolour(telValidation);

    if (ddl) {
        changecolourddl(validation3);
    }
    else {
        changecolour(validation4);
    }
    
    
    if (!validateBoxes(validation1)) { return false; }
    if (!validateDDL(validation2)) { return false; }
    if (!validateDDL(validation5)) { return false; }
    if (ddl) { if (!validateBoxes(validation3)) { return false; } } else {  if (!validateBoxes(validation4)) { return false; } }
    if (!validateContactnumbers(telValidation)) { return false; }    
    return true;
}

function ValidateItemDelivery(txt, ddl) {
    var terms = document.getElementById(_ck);    
    var pass = true;

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");

    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });

    $required.each(function(i) {        
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }

    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }

    if (ddl != undefined && txt != undefined) {
        var _ddl = document.getElementById(ddl);
        if (_ddl.selectedIndex > 1 && $("#" + txt).attr("value") == '') {
            $("#" + txt).css('background-color', '#ffeeee');
            $("#" + txt).focus();
            alert('Please enter all required fields\nRequired fields are highlighted');
            return false;
        }
        else {
            $("#" + txt).css('background-color', '#ffffff');
        }
    }   

    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }
    if (!terms.checked) {alert('You must agree to the terms and conditions before continuing');return false;}
    return pass;
}

/************************************************************************************************/
function ValidateGiftCard() {
    //form 1
    changecolour(validation1);
    return validateBoxes(validation1);
    
    //form2
    for (i = 0; i < validation2.length; i++) {
        var ckbox = document.getElementById(validation2[i]);
        if (ckbox.checked) {
            alert('Please complete all the required fields\nRequired fields are highlighted');
            ckbox.focus();
            return false;
        }
    }
    if (!validateEmail(_email)) {
        return false;
    }
    return true;
}
/************************************************************************************************/
function bindHeader(txt) {
    $(function() {
        $("#" + txt).addClass('current');
        /*$('#parentNav>li>a').each(function() {
            if ($(this).html().toString().indexOf(txt) != -1) { $(this).addClass('current'); }
        });*/
    });
}
/************************************************************************************************/
function showChild(id) {
    $(function() {
        $this = $("#leftNav a#"+id);
        //if ($this.html() == null) $this = $("#leftNav a:contains('" + id.toLowerCase() + "')");
        //if ($this.html() == null) $this = $("#leftNav a:contains('" + id + "')");        

        $this.addClass('current');
        $this.siblings("ul").css('display', "block");
        $this.parents("ul:hidden").css('display', 'block');
    });
}
/************************************************************************************************/
function showChild2(id) {
    $(function() {
        $this = $("#leftNav a:contains('" + id + "')");
        if ($this.html() == null) $this = $("#leftNav a:contains('" + id.toLowerCase() + "')");
        if ($this.html() == null) $this = $("#leftNav a:contains('" + id.toUpperCase() + "')");        
        
        $this.addClass('current');
        $this.siblings("ul").css('display', "block");
        $this.parents("ul:hidden").css('display', 'block');
    });
}
/************************************************************************************************/
function unCheckCKecks() {
    var news = document.getElementById(_news);
    var acc = document.getElementById(_acc);
    var sale = document.getElementById(_sale);
    var none = document.getElementById(_none);
  
  if (none.checked) {
      news.disabled = true;
      acc.disabled = true;
      sale.disabled = true;

      news.checked = false;
      acc.checked = false;
      sale.checked = false;
  }
  else {
      news.disabled = false;
      acc.disabled = false;
      sale.disabled = false;
  }
}
/************************************************************************************************/
function validateContactnumbers(arr) {
    if (arr == null) { return true; }
    var countWork = 0;
    var countHome = 0;
    var countCel = 0;
    var countWorkTotal = 0;
    var countHomeTotal = 0;
    var countCelTotal = 0;

    for (i = 0; i < arr.length; i++) {        
        if (arr[i].toLowerCase().indexOf('home') > -1) {
            countHome = countHome + 1;
            if (clean(arr[i]) != '') {
                countHomeTotal = countHomeTotal + 1;
            }
        }
        if (arr[i].toLowerCase().indexOf('cel') > -1) {
            countCel = countCel + 1;
            if (clean(arr[i]) != '') {      
                countCelTotal = countCelTotal + 1;
            }
        }
        if (arr[i].toLowerCase().indexOf('work') > -1) {
            countWork = countWork + 1;
            if (clean(arr[i]) != '') {
                countWorkTotal = countWorkTotal + 1;
            }
        }
    }
    var valid = 0;    
    if (countWork > 0 && countWorkTotal > 0) { valid = valid + 1; }
    if (countCel > 0 && countCelTotal > 0) { valid = valid + 1; }
    if (countHome > 0 && countHomeTotal > 0) { valid = valid + 1; }
    if (valid == 0 && countWork == 0 && countCel == 0 && countHome == 0) {return true; }
    if (valid < 1) { alert('Please enter at least one contact number'); return false; } else {return true; }
}

/*************************************************************************************************/
function validateTelephone() {
    if (_tel != undefined) {
        var tel = document.getElementById(_tel);
        tel.value = clean(_tel);
        if (tel.value.indexOf('07') > -1 || tel.value.indexOf('08') > -1) {
            alert('Please enter a valid land line number');
            return false;
        }
    }
    return true;

}
/*************************************************************************************************/
function showDeselected(news, acc, tele, none) {
    var na = document.getElementById(none);
    if (na.checked) {
        document.getElementById(tele).checked = false;
        document.getElementById(news).checked = false;
        document.getElementById(acc).checked = false;        
    }
}
/*************************************************************************************************/
function showselected(elem, none) {
    var element = document.getElementById(elem);
    if (element.checked) {
        var na = document.getElementById(none);
        if (na.checked) {
            na.checked = false;
        }
    }
}
/*************************************************************************************************/
function onlyNumbers(evt, t) {
    var txt = document.getElementById(t);
    
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false
    }
    return true
}
function onlyLetters(evt, t) {
    var txt = document.getElementById(t);

    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) {
        return false
    }
    return true
}
/*************************************************************************************************/
function populateValueBoxesGift(_voucher, _cost, _total, _ddl) {
    var voucher = document.getElementById(_voucher);
    var cost = document.getElementById(_cost);
    var total = document.getElementById(_total);
    var ddl = document.getElementById(_ddl);

    if (voucher.value == '') voucher.value = '0';
        switch (ddl.selectedIndex) {
        case 0: //store
            total.value = (parseFloat(voucher.value) + parseFloat(48)).toFixed(2);
            cost.value = 48;
            break;
        case 1: //home
            total.value = (parseFloat(voucher.value) + parseFloat(48)).toFixed(2);
            cost.value = 48;
            break;
        case 2: //work
            total.value = (parseFloat(voucher.value) + parseFloat(48)).toFixed(2);
            cost.value = 48;
            break;
        case 3: //work
            total.value = (parseFloat(voucher.value) + parseFloat(48)).toFixed(2);
            cost.value = 48;
            break;
    }
}
/*************************************************************************************************/
function populateValueBoxes(_voucher, _cost, _total, _ddl) {
    var voucher = document.getElementById(_voucher);
    var cost = document.getElementById(_cost);
    var total = document.getElementById(_total);
    var ddl = document.getElementById(_ddl);

    if (voucher.value == '') voucher.value = '0';
    switch (ddl.selectedIndex) {
        case 0: //store
            total.value = (parseFloat(voucher.value) + parseFloat(40)).toFixed(2);
            cost.value = 40;
            break;
        case 1: //home
            total.value = (parseFloat(voucher.value) + parseFloat(40)).toFixed(2);
            cost.value = 40;
            break;
        case 2: //work
            total.value = (parseFloat(voucher.value) + parseFloat(44)).toFixed(2);
            cost.value = 44;
            break;
        case 3: //work
            total.value = (parseFloat(voucher.value) + parseFloat(44)).toFixed(2);
            cost.value = 44;
            break;
    }
        
    
}
/*************************************************************************************************/
function validateChecks2(_terms, _deliver) {
    var terms = document.getElementById(_terms);
    var deliver = document.getElementById(_deliver);

    if (!deliver.checked) { alert('You must agree to the terms and conditions before continuing'); return false }
    if (!terms.checked) { alert('You must agree to the terms and conditions before continuing'); return false }
    return true;
}
/*************************************************************************************************/
function validateChecks(_terms, _deliver) {
    var terms = document.getElementById(_terms);
    var deliver = document.getElementById(_deliver);

    if (!deliver.checked) { alert('You must agree to the delivery terms before continuing'); return false }
    if (!terms.checked) { alert('You must agree to the terms and conditions before continuing'); return false }
    return true;
}
/*************************************************************************************************/
function validateCellInsuranceSubmit() {
    var pass = true;

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");
    var $requiredPremium = $(".requiredPremium");

    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });

    $required.each(function(i) {        
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }
    
    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex")==0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }

    if (!pass) {
        var totalChecked = 0;
        $requiredPremium.each(function(i) {
            if ($(this).attr("checked") == 'true') {
                totalChecked = totalChecked + 1;
            }
            if (totalChecked == 0) {
                alert('Please select the value of your cellphone.');
                return false;
            }
        });
    }
    
    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }

    var iRdo = 0;
    var $rdos = $("input[type='radio']");
    $rdos.each(function() {
        if ($(this).attr("checked")) iRdo = iRdo + 1;
    });
    if (iRdo == 0 && pass) { pass = false; alert('Please select your phone value'); $rdos[0].focus(); }

    var iRdo = 0;
    var $rdos = $("input[name*='Premium']");
    $rdos.each(function() {
        if ($(this).attr("checked")) iRdo = iRdo + 1;
    });
    if (iRdo == 0 && pass) { pass = false; alert('Please select your phone value'); $rdos[0].focus(); }

    var iRdo = 0;
    var $rdos = $("input[name*='logged']");
    $rdos.each(function() {
        if ($(this).attr("checked")) iRdo = iRdo + 1;
    });
    if (iRdo == 0 && pass) { pass = false; alert('Please state whether you have claimed within the last 24 months'); $rdos[0].focus(); }

    var iRdo = 0;
    var $rdos = $("input[type='checkbox']");
    $rdos.each(function() {
        if ($(this).attr("checked")) iRdo = iRdo + 1;
    });
    if (iRdo != 2 && pass) { pass = false; alert('You must agree to both terms and conditions'); $rdos[0].focus(); }
    
    return pass;
}
/*****************************************************************************/
function ValidateOnlineApp() {
    var pass = true;

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");
    var $telSame = $(".sametel");

    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });
    
    $required.each(function(i) {        
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }

    var prevvalue = '';
    var samenum = false;
    var invalidnum = false;
    $telSame.each(function(i) {
        if ($(this).val() == prevvalue && $(this).val() != '') {
            $(this).css('background-color', '#ffeeee');
            samenum = true;
        }
        else {
            $(this).css('background-color', '#ffffff');
        }
        if ($(this).val() != '' && $(this).val().substring(0, 1) == 0) {
            $(this).css('background-color', '#ffeeee');
            invalidnum = true;
        }
        prevvalue = $(this).val();

    });

    if (samenum) {
        alert('Work and home numbers cannot be the same.');
        return false;       
    }
    if (invalidnum) {
        alert('Invalid telephone number');
        return false;
    }
    
    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }

    
    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }

    return pass;
}
/*****************************************************************************/
function validateCelphoneNumber(_tel) {    
    var tel = document.getElementById(_tel);
    tel.value = tel.value.replace(/^\s+|\s+$/g, "");

    if (tel.value == '') { return; }
    if (tel.value.length < 7) {
        alert('Your cellphone number is too short.');
        return;
    }

    if (tel.value.length > 10) {
        alert('Your cellphone number is too long.');
        return;
    }

    if (tel.value.indexOf('061') > -1 || tel.value.indexOf('071') > -1 || tel.value.indexOf('072') > -1 || tel.value.indexOf('073') > -1 || tel.value.indexOf('074') > -1 ||
        tel.value.indexOf('078') > -1 || tel.value.indexOf('081') > -1 || tel.value.indexOf('082') > -1 || tel.value.indexOf('083') > -1 || tel.value.indexOf('084') > -1 ||
        tel.value.indexOf('076') > -1 || tel.value.indexOf('079') > -1) {
        
//        if (tel.value.substring(4, 3) == '0') {
//            alert('Your cellphone number is invalid.');
//            tel.focus();
//            return;
//        }
    }
    else {
        alert('Your cellphone number is invalid.');
        tel.value = '';
        tel.focus();
        return;
    }
}
/*****************************************************************************/
function validateTelNumber(_tel) {
    var tel = document.getElementById(_tel);
    tel.value = tel.value.replace(/^\s+|\s+$/g, "");
    
    if (tel.value == '') { return; }
    
    if (tel.value.length > 2 && tel.value.length < 7) {
        alert('Your telephone number is too short.');
        tel.focus();
        return;
    }

    if (tel.value.length > 10) {
        alert('Your telephone number is too long.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('0000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('00000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('000000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('0000000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('00000000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('000000000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }
    if (tel.value.indexOf('0000000000') > -1) {
        alert('Your telephone number is invalid.');
        tel.focus();
        return;
    }    
}
/*****************************************************************************/
function ValidateCost(elem) {
    var cost = document.getElementById(elem);
    if (cost.value == "0") { alert('Please enter a valid cost'); return false; } else {return true; }
}
/*****************************************************************************/
function ValidateCheckout() {
    var pass = true;

    var $required = $(".required");
    var $requiredtel = $(".requiredtel");
    var $requiredcode = $(".requiredcode");

    var itotal = 0;
    $requiredtel.each(function() {
        if ($(this).attr("value") != '') { itotal = itotal + 1; }
    });

    $required.each(function(i) {
        if (this.type.toString().indexOf("select") > -1) {
            if ($(this).attr("selectedIndex") == 0) {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
        if (this.type.toString().indexOf("text") > -1) {
            if ($(this).attr("value") == '') {
                $(this).css('background-color', '#ffeeee');
                pass = false;
            }
            else {
                $(this).css('background-color', '#ffffff');
            }
        }
    });

    if (itotal < 1) {
        $requiredtel.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
        $requiredcode.each(function(i) {
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    $(this).css('background-color', '#ffeeee');
                }
                else {
                    $(this).css('background-color', '#ffffff');
                }
            }
        });
    }
    else {
        $requiredtel.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
        $requiredcode.each(function(i) {
            $(this).css('background-color', '#ffffff');
        });
    }

    if (!pass) {
        $required.each(function(i) {
            if (this.type.toString().indexOf("select") > -1) {
                if ($(this).attr("selectedIndex") == 0) {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
            if (this.type.toString().indexOf("text") > -1) {
                if ($(this).attr("value") == '') {
                    alert('Please enter all required fields\nRequired fields are highlighted');
                    $(this).focus();
                    return false;
                }
            }
        });
    }

    if (itotal < 1 && pass) { alert('Please enter at least one contact number.'); $requiredtel[0].focus(); pass = false; }    

    return pass;
}
function ValidateStoreSubmit() {
    var countries = document.getElementById(_country);
    var province = document.getElementById(_province);

    if (countries[countries.selectedIndex].value == 'ZA' && province.selectedIndex == 0) { alert('Please select a province'); return false; }
    if (clean(_suburb) == '') { alert('Please enter your suburb'); return false; }
    return true;
}
function ValidateDropdown() {
    var ddl = document.getElementById("ddlStore");
 
    if (ddl.selectedIndex > 1 && clean("txtName") == '') {
        $("#ddlStore").css('background-color', '#ffeeee');
        $("#txtName").css('background-color', '#ffeeee');
        alert('Please enter a store/company name');        
        return false;
    }   
    
    return true;
}
