﻿function confirmSkip(button) {
    var skip = confirm('Are you sure you want to skip this item?')
    return skip;
}

function confirmRemove(button) {
    var remove = confirm('Are you sure you want to remove this item?')
    return remove;
}



function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}



function ClearTextBox(Source) {
    if (Source.className == "textbox-inactive") {
        Source.value = "";
        Source.className = "";
    }
}

function ResetTextBox(Source, Text) {
    if (trim(Source.value).length == 0) {
        Source.value = Text;
        Source.className = "textbox-inactive";
    }
}



function printWindow() {
    window.print();
}

function EmButClick(ctrl, evt) {
    if (evt.keyCode == 13) {
        document.getElementById(ctrl).focus();
        return false;
    }
}

function entsub(myform) {
    if (window.event && window.event.keyCode == 13) {
        document.forms[0].submit();
    }
    else {
        return true;
    }
}

function CheckDisplayFormat() {
    var bFound = false;
    var frm = window.top.frames;
    for (i = 0; i < frm.length; i++) {
        if (frm[i].name == "mainWin")
            bFound = true;
    }
    if (bFound == false) {
        var URLrewrite = document.location.href;
        window.location.href = "default.aspx?display=" + escape(URLrewrite);
    }
}
function ShowHelpFile(sHelp) {
    window.open(sHelp, "_blank", "Left=500px,Top=10px,Height=500px,Width=400px,help=no,status=no,scrollbars=yes");
    //window.mainwin.navigate 
    //window.open(sHelp, "mainWin" );
}

function ShowInvoice(sUrl) {
    window.open(sUrl, "_blank", "Height=900px,Width=880px,help=no,status=no,scrollbars=yes,menubar=no,location=no");
}
function ShowPopUpHelpFile(sHelp) {
    window.open(sHelp, "_blank", "Left=100px,Top=10px,Height=550px,Width=650px,status=1,scrollbars=1,toolbar=0,menubar=0,resizable=1,location=1,directories=1,status=1'");
    //window.mainwin.navigate 
    //window.open(sHelp, "mainWin" );
}
function ShowPrinterFriendly(sFile) {
    window.open("PrinterFriendly.aspx?tab=" + sFile, "_blank", "Left=10px,Top=10px,Height=470px,Width=700px,help=no,status=no,scrollbars=yes");
}
function ShowPopup(sPopup) {
    var WinID = 0;
    if (sPopup.charCodeAt)
        for (iLoop = 0; iLoop < sPopup.length; iLoop++)
            WinID += sPopup.charCodeAt(iLoop);
    window.open(sPopup, WinID, 'Left=150px,Top=150px,Height=500px,Width=600px,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
    return false;
}

function QuestionPopup(sPopup) {
    var WinID = 0;
    if (sPopup.charCodeAt)
        for (iLoop = 0; iLoop < sPopup.length; iLoop++)
            WinID += sPopup.charCodeAt(iLoop);
    window.open(sPopup, WinID, 'Left=150px,Top=150px,Height=500px,Width=750px,help=no,status=no,scrollbars=yes,resizable=1');
}
function ShowPopupBox(sPopup) {
    var WinID = 0;
    if (sPopup.charCodeAt)
        for (iLoop = 0; iLoop < sPopup.length; iLoop++)
            WinID += sPopup.charCodeAt(iLoop);
    window.open(sPopup, WinID, 'Left=150px,Top=150px,Height=600px,Width=600px,help=no,status=no,scrollbars=no');
    //window.top.location.href=("../../default.aspx?tab=Catalogue&menu1=5&menu2=21");

}
function ShowWorkflow(sWorkflow) {
    window.open(sWorkflow, "mainWin");

}
function ShowWorkflowSecure(sWorkflow) {
    if (CompatibleBrowser()) {
        var sdoc = 'https://' + window.top.location.hostname + window.top.location.pathname;
        var vret = window.showModalDialog(sWorkflow, "", "dialogHeight:290px;dialogWidth:505px;help:no;status:yes;scrollbars:no;");
        sdoc = sdoc + vret;
        window.top.navigate(sdoc);
    }
    else {
        window.open(sWorkflow, "mainWin");
    }
}
function ShowWorkflow2(sWorkflow) {
    if (CompatibleBrowser()) {
        var sdoc = window.top.location.protocol + '//' + window.top.location.hostname + window.top.location.pathname;
        var stab = window.top.location.search;
        var vret = window.showModalDialog(sWorkflow, "", "dialogHeight:290px;dialogWidth:505px;help:no;status:yes;scrollbars:no;");
        if (!vret)
            vret = "";
        if (vret != "")
            vret = "?tab=" + vret;
        if (vret == "")
            vret = stab;
        sdoc = sdoc + vret;
        window.top.navigate(sdoc);
    }
    else {
        window.open(sWorkflow, "mainWin");
    }
}
function ShowWorkflowBox(sWorkflow) {
    window.open(sWorkflow, "mainWin");
}
function ShowWorkflowRefresh(sWorkflow) {
    if (CompatibleBrowser()) {
        var sdoc = window.top.location.href;
        window.showModalDialog(sWorkflow, "", "dialogHeight:290px;dialogWidth:505px;help:no;status:yes;scrollbars:no;");
        window.top.navigate(sdoc);
    }
    else {
        window.open(sWorkflow, "mainWin");
    }
}
function CompatibleBrowser() {
    //CFC 27/01/2006
    //This is a terrible function!
    //We should base the decision on if the calls works not on the type of browser 
    //This info is useless in Opera 
    //What about IE 7? 
    //etc....
    var r, re;
    var s = navigator.userAgent;
    re = /MSIE 6/i;
    r = s.search(re);  //Check if running IE 6
    if (r < 1) {
        re = /MSIE 5./i;
        r = s.search(re);  //Check if running IE 5.5
        if (r < 1) {
            re = /MSIE 7./i;
            r = s.search(re);  //Check if running IE 7.
        }
    }
    return (r > 0);

    //return (0);
}

function HintText(TabOver) {
    var ElemRef = document.getElementById("HintMessage");
    var new_txt = document.createTextNode(TabOver);
    ElemRef.replaceChild(new_txt, ElemRef.childNodes[0]);

}

function Scrollsetting() {
    //alert ("Hello");
    //if (CompatibleBrowser()){
    //document.getElementsByTagName('body').item(0).style.overflow="hidden" ;
    //}
    //else{
    //	document.getElementsByTagName('body').item(0).style.overflow="auto" ;
    // }

}

function clearText(txtElement) {
    txtElement.value = "";
}

function showHelp(divElement) {
    var divElementShow = document.getElementById(divElement);
    var divHelpBox = document.getElementById("helpBox");
    divHelpBox.style.display = 'block';
    divElementShow.style.display = 'block';
}

function hideHelp(divElement) {
    var divElementShow = document.getElementById(divElement);
    var divHelpBox = document.getElementById("helpBox");
    divHelpBox.style.display = 'none';
    divElementShow.style.display = 'none';
}

function showDelHelp(divElement) {
    var divElementShow = document.getElementById(divElement);
    //var divHelpBox = document.getElementById("helpBox");
    //divHelpBox.style.display = 'block';//
    divElementShow.style.display = 'block';
}

function hideDelHelp(divElement) {
    var divElementShow = document.getElementById(divElement);
    //var divHelpBox = document.getElementById("helpBox");
    //divHelpBox.style.display = 'none';//
    divElementShow.style.display = 'none';
}


function ShowHideDetails(el) {
    var layer = document.getElementById("details");
    var layerCanvassers = document.getElementById("canvasserDetails");
    var label = document.getElementById("lbSource");

    var selectedCanvas = el.value;

    var splitVal = selectedCanvas.split(':');

    if (splitVal[0] == "True") {
        layer.className = 'ShowDetails';
        layerCanvassers.className = 'HideDetails';
        label.innerHTML = splitVal[1];
    }
    else if (splitVal[0] == "showCanvasser") {
        layerCanvassers.className = 'ShowDetails';
        layer.className = 'HideDetails';
    }
    else {
        layer.className = 'HideDetails';
    }
}

function ShowDetails(str) {
    try {

        var layer = document.getElementById("details");
        var label = document.getElementById("lbSource");

        layer.className = 'ShowDetails';
        label.innerHTML = str;

    }
    catch (e) {
        // ie6 error, no action required.
    }
}

function ShowHideDetails2(el) {
    var layer = document.getElementById("details");
    var selectedReason = el.value;
    var splitVal = selectedReason.split(':');

    if (splitVal[0] == "Details") {
        layer.className = 'ShowDetails';
    }
    else {
        layer.className = 'HideDetails';
    }
}

function ShowDetails2() {
    var layer = document.getElementById("details");

    layer.className = 'ShowDetails';
}

function ShowHideDirectDebit(el) {
    var layer = document.getElementById("directdebit");
    var layer2 = document.getElementById("creditfirst");
    var layer3 = document.getElementById("Invoice");

    var payment = el.value;

    if (payment == "Direct Debit") {
        layer.className = 'ShowDetails';
        layer2.className = 'ShowDetails';
        layer3.className = 'HideDetails';
    }
    else if (payment == "Invoice") {
        layer.className = 'HideDetails';
        layer2.className = 'HideDetails';
        layer3.className = 'ShowDetails';
    }
    else {
        layer.className = 'HideDetails';
        layer2.className = 'HideDetails';
        layer3.className = 'HideDetails';
    }
}

function ShowDirectDebit() {
    try {
        var layer = document.getElementById("directdebit");
        var layer2 = document.getElementById("creditfirst");
        layer.className = 'ShowDetails';
        layer2.className = 'ShowDetails';
    }
    catch (e) {
        // ie6 error, no action required.
    }
}


function ChangeDeliveryInstructions(el, txtPropNotesVal, txtDelNotesVal) {
    //Need to do the following:
    //      Change the text according to what is selected
    //      enable the text boxes
    //            
    //
    //alert (txtPropNotes.type);
    //alert (txtPropNotes.readOnly) ;
    //alert ('1st load');  

    var layer = document.getElementById("lblPropertyNotes");
    var label = document.getElementById("lblDeliveryNotes");
    var divAddr = document.getElementById("AddressInstructions");
    var divDelInstruct = document.getElementById("DelInstructions");

    var radioDiscY = document.getElementById("rdDiscY");
    var radioDiscN = document.getElementById("rdDiscN");
    var divDiscreet = document.getElementById("divDiscreet");
    var divSecureCode = document.getElementById("divSecureCode");
    //var divrdDiscreet = document.getElementById("divrdDiscreet");
    var lblAddressInstructStuff = document.getElementById("lblAddressInstructStuff");
    var lblProperyStuff = document.getElementById("lblProperyStuff");
    var divHomeType = document.getElementById("divHomeType");

    var divHouseName = document.getElementById("divHouseName");

    var divwrkAddr = document.getElementById("divwrkAddr");


    var val = el;


    var txtDelNotes = document.getElementById(txtDelNotesVal);
    var txtPropNotes = document.getElementById(txtPropNotesVal);

    //txtDelNotes.readOnly = true;
    //txtPropNotes.readOnly = true;

    if (val == "House") {
        txtDelNotes.disabled = false;
        txtPropNotes.disabled = false;
        lblAddressInstructStuff.innerHTML = "eg: blue door, white house, next to postbox etc.";
        lblProperyStuff.innerHTML = "eg: inside an upturned recycling box, under a hedge etc.<br /><br />We can also take a key to a shed or garage just give us a ring on 08452 62 62 62 and we can discuss the options with you.";
        divDiscreet.className = "HideDetails";
        divSecureCode.className = "HideDetails";
        divHomeType.className = "HideDetails";
        divHouseName.className = "ShowDetails";
        divwrkAddr.className = "HideDetails";
        divDelInstruct.className = "ShowDetails";
        divAddr.className = "ShowDetails"
        label.innerHTML = "<strong><label for='txtDeliveryNotes'>Are there any distinguishing landmarks to help us identify which house is yours?</label></strong>";
        layer.innerHTML = "<strong><label for='txtNeedKnow'>We plan our routes to be as environmentally friendly as possible. If we deliver before 7am or you are out, is there somewhere discreet we can leave your delivery? *</label></strong>";

    }
    else if (val == "PurpFlat") {
        //Need to put a yes/no box in here for discreet palce to leave delivery
        //Need to show yes/no box for security code
        txtDelNotes.disabled = false;
        txtPropNotes.disabled = false;
        lblAddressInstructStuff.innerHTML = "eg: basement flat, front door at rear.";
        lblProperyStuff.innerHTML = 'eg: inside an upturned recycling box, under a hedge etc.<br /><br />We can also take a key to any communal areas, just give us a ring on 08452 62 62 62 and we can discuss the options with you.';
        divDiscreet.className = 'ShowDetails';
        divSecureCode.className = 'ShowDetails';
        divHomeType.className = 'HideDetails';
        divHouseName.className = 'HideDetails';
        divDelInstruct.className = "ShowDetails";
        divAddr.className = 'HideDetails';
        label.innerHTML = "<strong><label for='txtDeliveryNotes'>Address hard to find?</label></strong>If so, please include distinguishing features or helpful landmarks.";
        layer.innerHTML = "<strong><label for='txtNeedKnow'>Please give details of where we should leave your delivery:*</strong>";
    }
    else if (val == "ConvFlat") {
        txtDelNotes.disabled = false;
        txtPropNotes.disabled = false;
        lblAddressInstructStuff.innerHTML = "eg: basement flat, front door at rear.";
        lblProperyStuff.innerHTML = 'eg: inside an upturned recycling box, under a hedge etc.<br /><br />We can also take a key to a communal area, give us a ring on 08452 62 62 62 and we can discuss the options with you.';
        divDiscreet.className = 'HideDetails';
        divSecureCode.className = 'HideDetails';
        divHomeType.className = 'HideDetails';
        divHouseName.className = 'HideDetails';
        divwrkAddr.className = 'HideDetails';
        divDelInstruct.className = 'ShowDetails';
        divAddr.className = "ShowDetails"
        label.innerHTML = "<strong><label for='txtDeliveryNotes'>Are there any distinguishing landmarks to help us identify which flat is yours?</label></strong>";
        layer.innerHTML = "<strong><label for='txtNeedKnow'>We plan our routes to be as environmentally friendly as possible. If we deliver before 7am or you are out, is there somewhere discreet we can leave your delivery? *</label></strong>";
    }
    else if (val == "Other") {
        //Need to show the input box about type of home
        txtDelNotes.disabled = false;
        txtPropNotes.disabled = false;

        label.innerHTML = "<strong><label for='txtDeliveryNotes' >Are there any distinguishing landmarks to help us identify which is your home?</label></strong>";
        layer.innerHTML = "<strong><label>We plan our routes to be as environmentally friendly as possible. If we deliver before 7am or you are out, is there somewhere discreet we can leave your delivery? *</label></strong>";

        divAddr.className = 'ShowDetails';
        divDiscreet.className = 'HideDetails';

        divSecureCode.className = 'HideDetails';
        lblAddressInstructStuff.innerHTML = "eg: green houseboat next to park bench.";
        lblProperyStuff.innerHTML = "&nbsp;";
        divHomeType.className = 'ShowDetails';

        divHouseName.className = 'HideDetails';
        divwrkAddr.className = "ShowDetails";
    }
    else {
        txtDelNotes.disabled = true;
        txtPropNotes.disabled = true;
        label.innerHTML = "";
        layer.innerHTML = "";
        divAddr.className = 'ShowDetails';
        divDiscreet.className = 'HideDetails';
        divSecureCode.className = 'HideDetails';
        //divrdDiscreet.className = 'HideDetails';
        lblAddressInstructStuff.innerHTML = "";
        lblProperyStuff.innerHTML = "&nbsp;";
        divHomeType.className = 'HideDetails';
        divHouseName.className = 'HideDetails';
        divwrkAddr.className = 'HideDetails';
    }

}

function YesDeliveryPlace() {

    var layer = document.getElementById("lblPropertyNotes");
    var label = document.getElementById("lblDeliveryNotes");
    var divAddr = document.getElementById("AddressInstructions");
    var divDelInstruct = document.getElementById("DelInstructions");
    var divDiscreet = document.getElementById("divDiscreet");
    var divSecureCode = document.getElementById("divSecureCode");
    var lblAddressInstructStuff = document.getElementById("lblAddressInstructStuff");
    var lblProperyStuff = document.getElementById("lblProperyStuff");
    var divHomeType = document.getElementById("divHomeType");
    var divHouseName = document.getElementById("divHouseName");

    label.innerHTML = "<strong><label for='txtDeliveryNotes' >Address hard to find?</label></strong>If so, please include distinguishing features or helpful landmarks.";
    layer.innerHTML = "<strong>Please give details of where we should leave your delivery:*</strong>";
    divAddr.className = 'HideDetails';
    divDiscreet.className = 'ShowDetails';
    divSecureCode.className = 'ShowDetails';
    divrdDiscreet.className = 'ShowDetails';
    lblAddressInstructStuff.innerHTML = "&nbsp;";
    lblProperyStuff.innerHTML = "&nbsp;";
    divHomeType.className = 'HideDetails';
    divHouseName.className = 'HideDetails';
    divDelInstruct.className = 'ShowDetails';
}


function NoDeliveryPlace() {

    var label = document.getElementById("lblDeliveryNotes");
    label.innerHTML = "Have you thought about X, Y & Z? Please give details here.";

    var layer = document.getElementById("lblPropertyNotes");
    layer.innerHTML = "We can nearly always help to identify somewhere we can leave your delivery if you're not in. Please give us a call on 08452 62 62 62 or leave your number below and we can give you a ring to discuss all available options.";
}

function NoSecureCode() {
    var SecInp = document.getElementById("txtSecure")
    SecInp.className = 'HideDetails';
}


function YesSecureCode() {
    var SecInp = document.getElementById("txtSecure")
    SecInp.className = 'ShowDetails';
}


function ClearAllControls() {
    for (i = 0; i < document.forms[0].length; i++) {
        doc = document.forms[0].elements[i];
        switch (doc.type) {
            case "text":
                doc.value = "";
                break;
            case "checkbox":
                doc.checked = false;
                break;
            case "radio":
                doc.checked = false;
                break;
            case "select-one":
                doc.options[doc.selectedIndex].selected = false;
                break;
            case "select-multiple":
                while (doc.selectedIndex != -1) {
                    indx = doc.selectedIndex;
                    doc.options[indx].selected = false;
                }
                doc.selected = false;
                break;

            default:
                break;
        }
    }
}

function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) +
                '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=950,height=636');
    //return false;
}

function twit_click() {
    u = location.href;
    t = document.title;
    window.open('http://twitter.com/share?url=' + encodeURIComponent(u) +
                '&text=Check out this amazing ' + encodeURIComponent(t) + ' recipe!',
                'sharer', 'toolbar=0,status=0,width=626,height=336');
    //return false;
}

function ToggleOtherTextBox(Source, TextBoxId, TriggerValue) {
    tb = document.getElementById(TextBoxId);
    if (Source.options[Source.selectedIndex].value == TriggerValue) tb.style.display
    = "inline"; else tb.style.display = "none";
}
