﻿googleAPI = "http://chart.apis.google.com/chart?cht=qr&chs=184x184&choe=UTF-8&chl=";

function BizQR(init) {

    if (init === undefined) {
        init = false;
    } else {
        init = true;
    }

    if (init) {
        document.getElementById('BizQrImage').innerHTML = "";
        $('#BizQrData').load('/Content/WhyProfile.htm');
    } else {

        data = "MECARD:";
        data = data + "N:" + document.getElementById("Usr_FirstName").value + " " + document.getElementById("Usr_LastName").value + ";";
        if (document.getElementById("Biz_Company").value != "") { data = data + "ORG:" + document.getElementById("Biz_Company").value + ";"; }
        if (document.getElementById("Biz_Email").value != "") { data = data + "EMAIL:" + document.getElementById("Biz_Email").value + ";"; }
        if (document.getElementById("Biz_Phone").value != "") { data = data + "TEL:" + document.getElementById("Biz_Phone").value + ";"; }
        if (document.getElementById("Biz_Cell").value != "") { data = data + "TEL:" + document.getElementById("Biz_Cell").value + ";"; }
        if (document.getElementById("Biz_Location").value != "") { data = data + "ADR:" + document.getElementById("Biz_Location").value + ";"; }
        if (document.getElementById("Biz_CompanyURL").value != "") { data = data + "URL:" + document.getElementById("Biz_CompanyURL").value + ";"; }

        data = data + "NOTE:";
        if (document.getElementById("Biz_Department").value != "") { data = data + "Department:" + document.getElementById("Biz_Department").value + ","; }
        if (document.getElementById("Biz_Title").value != "") { data = data + "Title:" + document.getElementById("Biz_Title").value + ","; }
        if (document.getElementById("Biz_Fax").value != "") { data = data + "Fax:" + document.getElementById("Biz_Fax").value + ","; }
        data = data + ";";

        data = data + ";";
        fullURL = googleAPI + encodeURI(data);

        htmldata = "MECARD:";
        htmldata = htmldata + "N:" + document.getElementById("Usr_FirstName").value + " " + document.getElementById("Usr_LastName").value + ";<br/>";
        if (document.getElementById("Biz_Company").value != "") { htmldata = htmldata + "ORG:" + document.getElementById("Biz_Company").value + ";<br/>"; }
        if (document.getElementById("Biz_Email").value != "") { htmldata = htmldata + "EMAIL:" + document.getElementById("Biz_Email").value + ";<br/>"; }
        if (document.getElementById("Biz_Phone").value != "") { htmldata = htmldata + "TEL:" + document.getElementById("Biz_Phone").value + ";<br/>"; }
        if (document.getElementById("Biz_Cell").value != "") { htmldata = htmldata + "TEL:" + document.getElementById("Biz_Cell").value + ";<br/>"; }
        if (document.getElementById("Biz_Location").value != "") { htmldata = htmldata + "ADR:" + document.getElementById("Biz_Location").value + ";<br/>"; }
        if (document.getElementById("Biz_CompanyURL").value != "") { htmldata = htmldata + "URL:" + document.getElementById("Biz_CompanyURL").value + ";<br/>"; }

        htmldata = htmldata + "NOTE:";
        if (document.getElementById("Biz_Department").value != "") { htmldata = htmldata + "Department:" + document.getElementById("Biz_Department").value + ","; }
        if (document.getElementById("Biz_Title").value != "") { htmldata = htmldata + "Title:" + document.getElementById("Biz_Title").value + ","; }
        if (document.getElementById("Biz_Fax").value != "") { htmldata = htmldata + "Fax:" + document.getElementById("Biz_Fax").value + ","; }
        htmldata = htmldata + ";";

        htmldata = htmldata + ";";

        document.getElementById('BizQrImage').innerHTML = "<img src='" + fullURL + "' alt='QR Code for Business Information'/>";
        //document.getElementById('BizQrData').innerHTML = htmldata;
        document.getElementById('BizQrData').innerHTML = "The QR Code above includes the your business contact information";
    }
}

function PerQR(init) {

    if (init === undefined) {
        init = false;
    } else {
        init = true;
    }

    if (init) {
        document.getElementById('PerQrImage').innerHTML = "";
        $('#PerQrData').load('/Content/WhyProfile.htm');
    } else {
        data = "MECARD:";
        data = data + "N:" + document.getElementById("Usr_FirstName").value + " " + document.getElementById("Usr_LastName").value + ";";
        if (document.getElementById("Per_Email").value != "") { data = data + "EMAIL:" + document.getElementById("Per_Email").value + ";"; }
        if (document.getElementById("Per_Phone").value != "") { data = data + "TEL:" + document.getElementById("Per_Phone").value + ";"; }
        if (document.getElementById("Per_Cell").value != "") { data = data + "TEL:" + document.getElementById("Per_Cell").value + ";"; }
        if (document.getElementById("Per_HomeLocation").value != "") { data = data + "ADR:" + document.getElementById("Per_HomeLocation").value + ";"; }
        if (document.getElementById("Per_URL").value != "") { data = data + "URL:" + document.getElementById("Per_URL").value + ";"; }

        data = data + "NOTE:";
        if (document.getElementById("Per_Fax").value != "") { data = data + "Fax:" + document.getElementById("Per_Fax").value + ","; }
        data = data + ";";

        data = data + ";";
        fullURL = googleAPI + encodeURI(data);

        htmldata = "MECARD:";
        htmldata = htmldata + "N:" + document.getElementById("Usr_FirstName").value + " " + document.getElementById("Usr_LastName").value + ";<br/>";
        if (document.getElementById("Per_Email").value != "") { htmldata = htmldata + "EMAIL:" + document.getElementById("Per_Email").value + ";<br/>"; }
        if (document.getElementById("Per_Phone").value != "") { htmldata = htmldata + "TEL:" + document.getElementById("Per_Phone").value + ";<br/>"; }
        if (document.getElementById("Per_Cell").value != "") { htmldata = htmldata + "TEL:" + document.getElementById("Per_Cell").value + ";<br/>"; }
        if (document.getElementById("Per_HomeLocation").value != "") { htmldata = htmldata + "ADR:" + document.getElementById("Per_HomeLocation").value + ";<br/>"; }
        if (document.getElementById("Per_URL").value != "") { htmldata = htmldata + "URL:" + document.getElementById("Per_URL").value + ";<br/>"; }

        htmldata = htmldata + "NOTE:";
        if (document.getElementById("Per_Fax").value != "") { htmldata = htmldata + "Fax:" + document.getElementById("Per_Fax").value + ","; }
        htmldata = htmldata + ";"

        htmldata = htmldata + ";";

        document.getElementById('PerQrImage').innerHTML = "<img src='" + fullURL + "' alt='QR Code for Personal Information'/>";
        //document.getElementById('PerQrData').innerHTML = htmldata;
        document.getElementById('PerQrData').innerHTML = "The QR Code above includes the your personal contact information";
    }
}

function SocQR(init) {

    if (init === undefined) {
        init = false;
    } else {
        init = true;
    }

    if ((document.getElementById("UserProfileId") == null) || (document.getElementById("UserProfileId").value == "")) {

        document.getElementById('SocQrImage').innerHTML = "";
        document.getElementById('SocQrData').innerHTML = "<div style='align:left;text-valign:top;'>If you have not saved your profile yet, please save it before we can generate the QR Code for your social connections.<br/><br/></div>";
        //$('#SocQrData').load('/Content/WhyProfile.htm');

    } else {
        data = "http://www.uptier.com/Ping/"+ document.getElementById("UserProfileId").value;
        //fullURL = googleAPI + encodeURI(data.replace(/-/g, ""));
        fullURL = googleAPI + encodeURI(data);

        document.getElementById('SocQrImage').innerHTML = "<img src='" + fullURL + "' alt='QR Code for Social Information'/>";
        document.getElementById('SocQrData').innerHTML = "The following URL allows people add you quickly to their social networks:<br/><br/>" + encodeURI(data);
    }
}

function PaypalQR(id ) {

    data = "http://www.uptier.com/PaypalQR/Show/" + id;
    fullURL = googleAPI + encodeURI(data);

    document.getElementById('PaypalQrImage').innerHTML = "<img src='" + fullURL + "' alt='QR Code for Paypal'/>";
}

function show(id) {
    if (id == 'business') {
        document.getElementById('tabs-1').style.display = "block";
        document.getElementById('tabs-2').style.display = 'none';
        document.getElementById('tabs-3').style.display = 'none';
    } else if (id == 'personal') {
        document.getElementById('tabs-1').style.display = 'none';
        document.getElementById('tabs-2').style.display = 'block';
        document.getElementById('tabs-3').style.display = 'none';
    } else if (id = 'social') {
        document.getElementById('tabs-1').style.display = 'none';
        document.getElementById('tabs-2').style.display = 'none';
        document.getElementById('tabs-3').style.display = 'block';
    }
}

function showPaypalTab(id) {
    if (id == "Regular") {
        document.getElementById('tabs-regular').style.display = "block";
        document.getElementById('tabs-subscription').style.display = 'none';
    } 
    else {
        document.getElementById('tabs-subscription').style.display = "block";
        document.getElementById('tabs-regular').style.display = 'none';
    }
}

function PaypalButtonChange(id) {

    document.getElementById('Paypal_Button').value = id;
    document.getElementById('currpaypalbutton').innerHTML = "<img class='ImageButton' src='../../Content/paypal/"+id+"' alt='"+id+"'/>";
}


WhereQR = new Array(8);
WhereQR[0]="Print on the Business Cards";
WhereQR[1]="Print on the T-Shirts";
WhereQR[2]="Print on the Tickets";
WhereQR[3]="Post on the Signs";
WhereQR[4]="Post on the Walls";
WhereQR[5] = "Post on the Windows";
WhereQR[6] = "Print on the Letterheads";
WhereQR[7] = "Print on the Coffee Mugs";

function randomWhereQR(){
    document.getElementById("whereqr").innerHTML = WhereQR[Math.floor(Math.random() * WhereQR.length)];
    setTimeout("randomWhereQR()", 20000);
}

function getZillowId() {
    if (document.getElementById("ZillowZpid") !== null) {
        var s = document.getElementById("ZillowZpid").value;

        if (isNaN(s)) {
            s = s.substring(0, s.length - 1);
            var pzidstr = s.substring(s.lastIndexOf('/') + 1);
            var pzid = pzidstr.substring(0, pzidstr.search("_zpid") );
            document.getElementById("ZillowZpid").value=pzid;
        }
    }
}


function AddQrImageToEditor(guid) {
    CKEDITOR.instances.Editor1.insertHtml("<img src='http://chart.apis.google.com/chart?cht=qr&chs=184x184&choe=UTF-8&chl=http://www.uptier.com/PageQR/Show/" + guid + "'/><br/>");
}

/* to work around the alert */
function CloseWindow() {
    window.open('', '_self', '');
    window.close();
}


function sendGoogl(s) {
    if (window.opener && !window.opener.closed)
        window.opener.location.href = "/GooglQR/Index?url=" + s;
    CloseWindow();
    //window.close();
}
