/* Click 2 Call to Google Voice                                                        */
/*                                                                                     */
/* Developed by : Razvan Gavril                                                        */
/* License : GPL                                                                       */
/*                                                                                     */
/* More info here: http://razvangavril.com/web-development/custom-google-voice-widget/ */

function click2call(button_id, cid_number, cid_name) {

    var cidNumber = cid_number
    cidNumber = prompt("Enter YOUR phone number." + '\n \n' + "Our system will call you on this number.  Answer it and press 1 to connect to Michael & Courtney Hnatt's cell and home phones." + '\n \n' + "It's free!")
    if (cidNumber.length < 10) {
        alert("You must enter a valid phone number (your phone number) including area code.");
    }
    else {
        cid_number = cidNumber
        var iframe = document.createElement('iframe');
        iframe.style.width = 0;
        iframe.style.height = 0;
        iframe.style.border = 0;
        document.body.appendChild(iframe);

        var doc = null;
        if (iframe.contentDocument)
            doc = iframe.contentDocument;
        else if (iframe.contentWindow)
            doc = iframe.contentWindow.document;
        else if (iframe.document)
            doc = iframe.document;
        if (doc == null)
            throw "Document not initialized";

        doc.open(); doc.write(''); doc.close();

        var form = doc.createElement("form");
        form.method = "post";
        form.action = "https://clients4.google.com/voice/embed/webButtonConnect";

        input = doc.createElement("input");
        input.type = "text";
        input.name = "buttonId";
        input.value = "" + button_id;
        form.appendChild(input);

        input = doc.createElement("input");
        input.type = "text";
        input.name = "callerNumber";
        input.value = "" + cid_number;
        form.appendChild(input);

        input = doc.createElement("input");
        input.type = "text";
        input.name = "name";
        input.value = "Testing";
        form.appendChild(input);

        input = doc.createElement("input");
        input.type = "text";
        input.name = "showCallerNumber";
        input.value = "1";
        form.appendChild(input);

        doc.body.appendChild(form);

        form.submit();
    }
}

function click2callOLD(button_id, cid_number, cid_name) {
    //alert(button_id + "|" + cid_number + "|" + cid_name);
    var lennumber = cid_number
    if (lennumber.length < 10)
        alert("Enter your phone number, then click the button.  Your phone will ring.  Answer it, then press 1 to connect to Mike & Courtney's cell and home phones!  It's free!");

    var iframe = document.createElement('iframe');
    iframe.style.width = 0;
    iframe.style.height = 0;
    iframe.style.border = 0;
    document.body.appendChild(iframe);

    var doc = null;
    if (iframe.contentDocument)
        doc = iframe.contentDocument;
    else if (iframe.contentWindow)
        doc = iframe.contentWindow.document;
    else if (iframe.document)
        doc = iframe.document;
    if (doc == null)
        throw "Document not initialized";

    doc.open(); doc.write(''); doc.close();

    var form = doc.createElement("form");
    form.method = "post";
    form.action = "https://clients4.google.com/voice/embed/webButtonConnect";

    input = doc.createElement("input");
    input.type = "text";
    input.name = "buttonId";
    input.value = "" + button_id;
    form.appendChild(input);

    input = doc.createElement("input");
    input.type = "text";
    input.name = "callerNumber";
    input.value = "" + cid_number;
    form.appendChild(input);

    input = doc.createElement("input");
    input.type = "text";
    input.name = "name";
    input.value = "Testing";
    form.appendChild(input);

    input = doc.createElement("input");
    input.type = "text";
    input.name = "showCallerNumber";
    input.value = "1";
    form.appendChild(input);

    doc.body.appendChild(form);

    form.submit();
}

