﻿

function MenuClick(button, div) {

    ClearTopMenu();
    ClearLeftMenu();

    /*document.getElementById(button).setAttribute("class", "currentlySelectedMenuButton");*/
    document.getElementById(button).style.color = '#07B32B';
    document.getElementById(button).style.background = 'white';
    
    document.getElementById('leftMenu').style.display = 'none';

    ClearDivs();

    document.getElementById(div).style.display = 'block';

    if (button == 'topMenuInfo') {

        document.getElementById('leftMenu').style.display = 'block';
        /*document.getElementById('benefitsMenuButton').setAttribute("class", "currentlySelectedLeftMenuButton");*/
        document.getElementById('aboutUsMenuButton').style.color = '#A2A2A2';
        document.getElementById('aboutUsMenuButton').style.backgroundColor = 'white';

    }

    //if (button == 'topMenuDonate') {
    //    var paymentButton = document.getElementById('worldPaySubmit').style.display = 'block';
    //}



}

function SetScreenWidth() {
    if ((screen.width > 1024) && (screen.height > 768)) {

        if ((screen.width > 1280) && (screen.height > 800)) {
            var width = '20%';
            var main = '59%';
        }
        else {
            var width = '15%'
            var main = '69%';
        }
        
        var left = document.getElementById('left');
        var right = document.getElementById('right');
        var pageContent = document.getElementById('pageContent');

        left.style.width = width;
        right.style.width = width;
        pageContent.style.width = main;
    }
    else {
        var left = document.getElementById('left');
        var right = document.getElementById('right');
        var pageContent = document.getElementById('pageContent');

        left.style.width = '10%';
        right.style.width = '10%';
        pageContent.style.width = '79%';

    }

}

function LeftMenuClick(button, div) {

    ClearLeftMenu();
    ClearTopMenu();

    /*document.getElementById(button).setAttribute("class", "currentlySelectedLeftMenuButton");*/
    document.getElementById(button).style.color = '#A2A2A2';
    document.getElementById(button).style.backgroundColor = 'white';
  

    ClearDivs();

    document.getElementById(div).style.display = 'block';

    //var tmI = document.getElementById('topMenuInfo');
    /*document.getElementById('topMenuInfo').setAttribute("class", "currentlySelectedMenuButton");*/
    document.getElementById('topMenuInfo').style.color = '#07B32B';
    document.getElementById('topMenuInfo').style.backgroundColor = 'white';
    

}

function ClearDivs() {
    var contactUs = document.getElementById('divContactUs').style.display = 'none';
    var findTeam = document.getElementById('divFindTeam').style.display = 'none';
    var faq = document.getElementById('divFAQ').style.display = 'none';
    var benefits = document.getElementById('divBenefits').style.display = 'none';
    var giftAid = document.getElementById('divGiftAidInfo').style.display = 'none';
    var aboutUs = document.getElementById('divAboutUs').style.display = 'none';
    var termsConditions = document.getElementById('divTermsConditions').style.display = 'none';
    var divNewsletters = document.getElementById('divNewsletters').style.display = 'none';

    
    //var paymentButton = document.getElementById('worldPaySubmit').style.display = 'none';
}



function ClearTopMenu() {
    var tmH = document.getElementById('topMenuHome');
    var tmD = document.getElementById('topMenuDonate');
    var tmI = document.getElementById('topMenuInfo');
    var tmCP = document.getElementById('topMenuCreatePage');
    var tmCU = document.getElementById('topMenuContactUs');

   /* tmH.setAttribute("class", "notSelectedMenuButton");
    tmD.setAttribute("class", "notSelectedMenuButton");
    tmI.setAttribute("class", "notSelectedMenuButton");
    tmCP.setAttribute("class", "notSelectedMenuButton");
    tmCU.setAttribute("class", "notSelectedMenuButton");*/
    tmH.style.color = 'white';
    tmH.style.backgroundColor = '#07B32B';
    tmD.style.color = 'white';
    tmD.style.backgroundColor = '#07B32B';
    tmI.style.color = 'white';
    tmI.style.backgroundColor = '#07B32B';
    tmCP.style.color = 'white';
    tmCP.style.backgroundColor = '#07B32B';
    tmCU.style.color = 'white';
    tmCU.style.backgroundColor = '#07B32B';
}

function ClearLeftMenu() {
    var b = document.getElementById('benefitsMenuButton');
    var au = document.getElementById('aboutUsMenuButton');
    var tac = document.getElementById('termsAndConditionsMenuButton');
    var faq = document.getElementById('faqMenuButton');
    var ga = document.getElementById('giftAidMenuButton');
    var n = document.getElementById('newslettersMenuButton');


  /*  b.setAttribute("class", "notSelectedLeftMenuButton");
    au.setAttribute("class", "notSelectedLeftMenuButton");
    tac.setAttribute("class", "notSelectedLeftMenuButton");
    faq.setAttribute("class", "notSelectedLeftMenuButton");*/

    b.style.color = 'white';
    b.style.backgroundColor = '#A2A2A2';
    au.style.color = 'white';
    au.style.backgroundColor = '#A2A2A2';
    tac.style.color = 'white';
    tac.style.backgroundColor = '#A2A2A2';
    faq.style.color = 'white';
    faq.style.backgroundColor = '#A2A2A2';
    ga.style.color = 'white';
    ga.style.backgroundColor = '#A2A2A2';
    n.style.color = 'white';
    n.style.backgroundColor = '#A2A2A2';
}


function checkWorldPayForm() {

   
    var errorMessage = "";
    var hasError = false;

    var nameVar = document.getElementById('txtName');
    //var emailVar = document.getElementById('txtEmail');
    //var amountVar = document.getElementById('txtAmount');
    var messageVar = document.getElementById('txtMessage');

    var errorNameVar = document.getElementById('errorName');
    //var errorEmailVar = document.getElementById('errorEmail');
    //var errorAmountVar = document.getElementById('errorAmount');


    errorNameVar.style.color = 'White';
    //errorEmailVar.style.color = 'White';
    //errorAmountVar.style.color = 'White';

    var rbGAYes = document.getElementById('rbGiftAidYes');
    var rbGANo = document.getElementById('rbGiftAidNo');

   


    if (nameVar.value == "") {
        errorNameVar.style.color = "Red";
        hasError = true;
    }


   // if ((emailVar.value == "" || emailVar.value.indexOf('@', 0) == -1) || emailVar.value.indexOf('.') == -1) {
   //     errorEmailVar.style.color = "Red";
   //     hasError = true;
   // }

    //if (amountVar.value == "") {
    //    errorAmountVar.style.color = "Red";
    //    hasError = true;
    //}


   

    if (hasError == true) {

        return false;
    }





    //Assign hidden values
    //var hiddenNameVar = document.getElementById('custom');
    //hiddenNameVar.value = nameVar.value;

    //var hiddenEmailVar = document.getElementById('email');
    //hiddenEmailVar.value = emailVar.value;

    //var hiddenAmountVar = document.getElementById('amount');
    //hiddenAmountVar.value = amountVar.value;

    //var hiddenMessageVar = document.getElementById('invoice');
    //hiddenMessageVar.value = messageVar.value;

    var teamName = document.getElementById('hiddenTeamName');
    var teamId = document.getElementById('hiddenTeamId');

   

    //var hiddenGiftAid = document.getElementById('item_number');
    var GiftAid;

    

    if (rbGAYes != null) {
        if (rbGAYes.checked) {
            GiftAid = true;
        }
        else {
            GiftAid = false;
        }
    }
    else {
        GiftAid = false;
    }

    

  /*  alert(rbGAYes);
    alert('hiddenGiftAid : ' + hiddenGiftAid.value);*/

    //alert('https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=info@teamdonations.co.uk&currency_code=GBP&return=http://www.teamdonations.co.uk/paypal.aspx&rm=2&item_name=Donation to ' + teamName.innerText + '&custom=' + nameVar.value + "|" + GiftAid + '&invoice=' + messageVar.value + '&item_number=' + teamId.innerText, 'paypal', 'width=1100,height=900,left=0,top=0,toolbar=No,location=Yes,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No');


    paypal = window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=info@teamdonations.co.uk&currency_code=GBP&return=http://www.teamdonations.co.uk/paypal.aspx&rm=2&item_name=Donation to ' + teamName.innerText + '&custom=' + nameVar.value + "|" + GiftAid + '&invoice=' + messageVar.value + '&item_number=' + teamId.innerText, 'paypal', 'width=1100,height=900,left=0,top=0,toolbar=No,location=Yes,scrollbars=Yes,status=No,resizable=Yes,fullscreen=No'); 
    


    return true;

}


//function SetButton() {
//    var target = document.getElementById('TargetCell');
//    var paymentButton = document.getElementById('worldPaySubmit');

//    var y = findPosY(target);
//    paymentButton.style.left = findPosX(target) + 'px';
//    paymentButton.style.top = y - 25 + 'px';


//    var findTeam = document.getElementById('divFindTeam');

//    findTeam.style.height = y + 30 + 'px';


//}

//function findPosX(obj) {
//    var curleft = 0;
//    if (obj.offsetParent)
//        while (1) {
//        curleft += obj.offsetLeft;
//        if (!obj.offsetParent)
//            break;
//        obj = obj.offsetParent;
//    }
//    else if (obj.x)
//        curleft += obj.x;
//    return curleft;
//}

//function findPosY(obj) {
//    var curtop = 0;
//    if (obj.offsetParent)
//        while (1) {
//        curtop += obj.offsetTop;
//        if (!obj.offsetParent)
//            break;
//        obj = obj.offsetParent;
//    }
//    else if (obj.y)
//        curtop += obj.y;
//    return curtop;
//}


function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}
