﻿/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var horizontal_offset = "-160px" //horizontal offset of hint box from anchor link
var vertical_offset = "17" //horizontal offset of hint box from anchor link. No need to change.

var ie = document.all
var ns6 = document.getElementById && !document.all

function getposOffset(what, offsettype) {
    var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
    var parentEl = what.offsetParent;
    while (parentEl != null) {
        totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}

function iecompattest() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge) {
    var edgeoffset = (whichedge == "rightedge") ? parseInt(horizontal_offset) * -1 : parseInt(vertical_offset) * -1
    if (whichedge == "rightedge") {
        var windowedge = ie && !window.opera ? iecompattest().scrollLeft + iecompattest().clientWidth - 30 : window.pageXOffset + window.innerWidth - 40
        dropmenuobj.contentmeasure = dropmenuobj.offsetWidth
        if (windowedge - dropmenuobj.x < dropmenuobj.contentmeasure)
            edgeoffset = dropmenuobj.contentmeasure + obj.offsetWidth + parseInt(horizontal_offset)
    }
    else {
        var windowedge = ie && !window.opera ? iecompattest().scrollTop + iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
        dropmenuobj.contentmeasure = dropmenuobj.offsetHeight
        if (windowedge - dropmenuobj.y < dropmenuobj.contentmeasure)
            edgeoffset = dropmenuobj.contentmeasure - obj.offsetHeight
    }
    return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth) {
    if ((ie || ns6) && document.getElementById("hintbox")) {
        dropmenuobj = document.getElementById("hintbox")
        dropmenuobj.innerHTML = menucontents
        dropmenuobj.style.left = dropmenuobj.style.top = -500
        if (tipwidth != "") {
            dropmenuobj.widthobj = dropmenuobj.style
            dropmenuobj.widthobj.width = tipwidth
        }
        dropmenuobj.x = getposOffset(obj, "left")
        dropmenuobj.y = getposOffset(obj, "top")
        dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + obj.offsetWidth + "px"
        dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + "px"
        dropmenuobj.style.visibility = "visible"
        obj.onmouseout = hidetip
    }
}

function hidetip(e) {
    dropmenuobj.style.visibility = "hidden"
    dropmenuobj.style.left = "-500px"
}

function createhintbox() {
    var divblock = document.createElement("div")
    divblock.setAttribute("id", "hintbox")
    document.body.appendChild(divblock)
}

if (window.addEventListener)
    window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
    window.attachEvent("onload", createhintbox)
else if (document.getElementById)
    window.onload = createhintbox
    
    
    

///////////////////////////////////////////////////////////////////////////////////
//************************ Registration *****************************************//
///////////////////////////////////////////////////////////////////////////////////

function validateUsername(oSrc, args) {
    //alert(document.getElementById("ctl00_ContentPlaceHolder1_txtAvailability").value)
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtAvailability").value == "Unavailable") {
        args.IsValid = false;
    }
}

function validateEmail(oSrc, args) {
    //alert(document.getElementById("ctl00_ContentPlaceHolder1_txtAvailability").value)
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtAvailabilityEmail").value == "Unavailable") {
        args.IsValid = false;
    }
}

function validateMobileReplied(oSrc, args) {
    //alert(document.getElementById("ctl00_ContentPlaceHolder1_txtAvailability").value)
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtMobileSearch").value == "Unavailable") {
        args.IsValid = false;
    }
}

function validateCharPassword(oSrc, args) {
    var oPassword = document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").value
    re = /^[0-9a-zA-Z\_]*$/;
    if (!re.exec(oPassword)) {
        args.IsValid = false;
    }
}

function validatePasswordsMatch(oSrc, args) {
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").value == document.getElementById("ctl00_ContentPlaceHolder1_txtCPassword").value) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function validateMobileMatch(oSrc, args) {
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtMobile").value == document.getElementById("ctl00_ContentPlaceHolder1_txtCMobile").value) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function checkTerms(oSrc, args) {
    if (!(document.getElementById('ctl00_ContentPlaceHolder1_chkTerms').checked)) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function validateDOB(oSrc, args) {
    if (document.getElementById('ctl00_ContentPlaceHolder1_DOBDay').selectedIndex == 0)
    {
    //if (document.aspnetForm.ctl00$ContentPlaceHolder1$DOBDay.selectedIndex == 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function validateDOBMonth(oSrc, args) {
    if(document.getElementById('ctl00_ContentPlaceHolder1_DOBMonth').selectedIndex ==0)
    {
    //if (document.aspnetForm.ctl00$ContentPlaceHolder1$DOBMonth.selectedIndex == 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function validateDOBYear(oSrc, args) {
    if (document.getElementById('ctl00_ContentPlaceHolder1_DOBYear').selectedIndex == 0)
    {
    //if (document.aspnetForm.ctl00$ContentPlaceHolder1$DOBYear.selectedIndex == 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function calcAge(oSrc, args) {
    //Sample usage
    //displayage (year, month, day, unit, decimals, rounding)
    //Unit can be "years", "months", or "days"
    //Decimals specifies demical places to round to (ie: 2)
    //Rounding can be "roundup" or "rounddown"
    //displayage(1997, 11, 24, "years", 0, "rounddown")
    //var w = document.myform.mylist.selectedIndex;
    //var selected_text = document.myform.mylist.options[w].text;

    yr = document.getElementById('ctl00_ContentPlaceHolder1_DOBYear').options[document.getElementById('ctl00_ContentPlaceHolder1_DOBYear').selectedIndex].text;
    mon = document.getElementById('ctl00_ContentPlaceHolder1_DOBMonth').options[document.getElementById('ctl00_ContentPlaceHolder1_DOBMonth').selectedIndex].text;
    day = document.getElementById('ctl00_ContentPlaceHolder1_DOBDay').options[document.getElementById('ctl00_ContentPlaceHolder1_DOBDay').selectedIndex].text;

    //alert(yr)

    unit = "years"
    decimal = 0
    round = "rounddown"

    var one_day = 1000 * 60 * 60 * 24
    var one_month = 1000 * 60 * 60 * 24 * 30
    var one_year = 1000 * 60 * 60 * 24 * 30 * 12

    today = new Date()
    var pastdate = new Date(yr, mon - 1, day)
    var countunit = unit
    var decimals = decimal
    var rounding = round
    var age

    finalunit = (countunit == "days") ? one_day : (countunit == "months") ? one_month : one_year
    decimals = (decimals <= 0) ? 1 : decimals * 10

    if (unit != "years") {
        if (rounding == "rounddown")
            age = (Math.floor((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals + " " + countunit)
        else
            age = (Math.ceil((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals + " " + countunit)
    }
    else {
        yearspast = today.getFullYear() - yr - 1
        tail = (today.getMonth() > mon - 1 || today.getMonth() == mon - 1 && today.getDate() >= day) ? 1 : 0
        pastdate.setFullYear(today.getFullYear())
        pastdate2 = new Date(today.getFullYear() - 1, mon - 1, day)
        tail = (tail == 1) ? tail + Math.floor((today.getTime() - pastdate.getTime()) / (finalunit) * decimals) / decimals : Math.floor((today.getTime() - pastdate2.getTime()) / (finalunit) * decimals) / decimals
        //age = (yearspast+tail+" "+countunit)
        age = (yearspast + tail)
    }
    //alert(parseInt(age) + " " + parseInt("18"))

    if (parseInt(age) >= parseInt("18")) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function directPayPal() {
    document.getElementById('aspnetForm').action = "https://www.paypal.com/cgi-bin/webscr"
    document.getElementById('aspnetForm').submit();
}

function validateMobileChar(oSrc, args) {
    var obj = document.getElementById("ctl00_ContentPlaceHolder1_txtMobile");
    var strng = obj.value
    var stripped = strng.replace(/[^0-9]/g, '');
    //strip out acceptable non-numeric characters
    //it also removes white space

    //set value without space
    document.getElementById("ctl00_ContentPlaceHolder1_txtMobile").value = stripped

    if (isNaN(parseInt(stripped))) {
        obj.focus();
        args.IsValid = false;
    }
    else {
        //Check mobile number valid
        if (obj.value.length > 0) {
            if (obj.value.length == 10) {
                if (!(strng.substring(0, 2) == "04")) {
                    args.IsValid = false;
                }
                else {
                    ////if good return true
                    args.IsValid = true;
                }
            }
            else if (obj.value.length == 11) {
                if (!(strng.substring(0, 3) == "614")) {
                    args.IsValid = false;
                }
                else {
                    ////if good return true
                    args.IsValid = true;
                }
            }
            else {
                args.IsValid = false;
            }
        }
        else {
            args.IsValid = false;
        }
    }
}

function validateMobileCharUK(oSrc, args) {
    var obj = document.getElementById("ctl00_ContentPlaceHolder1_txtMobile");
    var strng = obj.value
    var stripped = strng.replace(/[^0-9]/g, '');
    //strip out acceptable non-numeric characters
    //it also removes white space

    //set value without space
    document.getElementById("ctl00_ContentPlaceHolder1_txtMobile").value = stripped

    if (isNaN(parseInt(stripped))) {
        obj.focus();
        args.IsValid = false;
    }
    else {
        //Check mobile number valid
        if (obj.value.length > 0) {
            if (obj.value.length == 11) {
                if (!(strng.substring(0, 2) == "07")) {
                    args.IsValid = false;
                }
                else {
                    ////if good return true
                    args.IsValid = true;
                }
            }
            else if (obj.value.length == 12) {
                if (!(strng.substring(0, 3) == "447")) {
                    args.IsValid = false;
                }
                else {
                    ////if good return true
                    args.IsValid = true;
                }
            }
            else {
                args.IsValid = false;
            }
        }
        else {
            args.IsValid = false;
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////
//************************ Paypal Memberships *****************************************//
///////////////////////////////////////////////////////////////////////////////////

function getMembershipType() {
    for (var i = 0; i < document.aspnetForm.memberships.length; i++) {
        if (document.aspnetForm.memberships[i].checked) {
            if (document.aspnetForm.memberships[i].value == "6-Monthly") {

                document.getElementById('item_name').value = "Knockout Bids 6 Month Plan - $1.95 Week / Charged $50.70 6 Monthly";
                document.getElementById('item_number').value = "400";

                document.getElementById('a3').value = "50.70";
                document.getElementById('p3').value = "6";
                document.getElementById('t3').value = "M";


            }
            else if (document.aspnetForm.memberships[i].value == "Monthly") {

                document.getElementById('item_name').value = "Knockout Bids Monthly Plan - $2.95 Week / Charged $11.80 Month";
                document.getElementById('item_number').value = "300";

                document.getElementById('a3').value = "11.80";
                document.getElementById('p3').value = "1";
                document.getElementById('t3').value = "M";
            }
            else {

                //Weekly
                document.getElementById('item_name').value = "Knockout Bids Weekly Plan - $4.95 Week";
                document.getElementById('item_number').value = "200";

                document.getElementById('a3').value = "4.95";
                document.getElementById('p3').value = "1";
                document.getElementById('t3').value = "W";
            }
        }
    }
}