﻿function OpenPopup(url, name, width, height, toolbar, scrollbars, resizable) {
    var left = (screen.width / 2) - (width / 2);
    var top = (screen.height / 2) - (height / 2);
    var toolbarYesNo = toolbar == null ? "no" : toolbar;
    var scrollbarsYesNo = scrollbars == null ? "no" : scrollbars;
    var resizableYesNo = resizable == null ? "no" : resizable;

    var features = "toolbar=" + toolbarYesNo + "," +
    "location=no, directories=no, status=no, menubar=no," +
    "scrollbars=" + scrollbarsYesNo + "," +
    "resizable=" + resizableYesNo + "," +
    "copyhistory=no,top=" + top +
    ",left=" + left +
    ",width=" + width +
    ",height=" + height;

    window.open(url, name, features);
}

function EnsureNumeric()
{
  var key = window.event.keyCode;
  if (key <48 || key >57)
    window.event.returnValue = false;
}

 function CreateBookmarkLink() {
    title = "Business School São Paulo";
    url = "http://portal.bsp.edu.br/";

    try {
        window.external.AddFavorite(url, title);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        } catch (ex) { }
    }

    GoalLog(1, "");
 }

 function GoalLog(type, desc)
 {
     $.post("AJAXHandler.axd?cmd=goallog", { "type": type, "desc": desc });
 }

 function Indique() {
     ShowModal();
     
     var width = 450;
     var height = 570;
     var left = (window.screen.width / 2) - 225;
     var top = (window.screen.height / 2) - 360;

     $("#memberGetMemberWindow")[0].style.left = left + "px";
     $("#memberGetMemberWindow")[0].style.top = top + "px";
     window.scrollTo(0, 0);
     $("#memberGetMemberWindow").show();

     $("#txtYourName")[0].focus(); 
     GoalLog(3, "");
 }

 function LigueParaMim() {
     ShowModal();

     var width = 300;
     var height = 360;
     var left = (window.screen.width / 2) - 150;
     var top = (window.screen.height / 2) - 200;

     $("#callMeWindow")[0].style.left = left + "px";
     $("#callMeWindow")[0].style.top = top + "px";
     window.scrollTo(0, 0);
     $("#callMeWindow").show();

     $("#txtPhoneDDD")[0].focus();
     GoalLog(2, "");
  }

 function ShowModal() {
     $("#ModalWindow")[0].style.height = document.body.offsetHeight + "px";
     $("#ModalWindow")[0].style.display = "";
     //$("#ModalWindow").show();
 }

 function HideModal() {
     $("#ModalWindow").hide();
 }

 function checkEmail(email) {
     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
         return (true)
     }

     return (false)
 }

 function SendReferring() {
     var txtYourName = $("#txtYourName")[0];
     var txtYourEmail = $("#txtYourEmail")[0];
     var txtHisName = $("#txtHisName")[0];
     var txtHisEmail = $("#txtHisEmail")[0];
     var txtMessage = $("#txtMessage")[0];

     if (txtYourName.value == "") {
         alert("Seu nome: preenchimento obrigatório.");
         return;
     }

     if (txtYourEmail.value == "") {
         alert("Email: preenchimento obrigatório.");
         return;
     }

     if (!checkEmail(txtYourEmail.value)) {
         alert("Email: inválido.");
         return;
     }

     if (txtHisName.value == "") {
         alert("Nome do amigo: preenchimento obrigatório.");
         return;
     }

     if (txtHisEmail.value == "") {
         alert("Email do amigo: preenchimento obrigatório.");
         return;
     }

     if (!checkEmail(txtHisEmail.value)) {
         alert("Email do amigo: inválido.");
         return;
     }

     $.post("AJAXHandler.axd?cmd=referring", {
                                                            yourName: txtYourName.value,
                                                            yourEmail: txtYourEmail.value,
                                                            hisName: txtHisName.value,
                                                            hisEmail: txtHisEmail.value,
                                                            message: txtMessage.value
                                            });


    txtYourName.value = "";
    txtYourEmail.value = "";
    txtHisName.value = "";
    txtHisEmail.value = "";
    txtMessage.value = "";

    alert("Seu amigo receberá um email com sua indicação.\n\rObrigado!");

    CloseReferring();
}

function CloseReferring() {
    HideModal();
    $("#memberGetMemberWindow").hide();
}

 function SendCallMe() {
     var txtName = $("#txtName")[0];
     var txtPhoneDDD = $("#txtPhoneDDD")[0];
     var txtPhoneNumber = $("#txtPhoneNumber")[0];
     var txtBesttime = $("#txtBestTime")[0];

     if (txtName.value == "") {
         alert("Nome: preenchimento obrigatório.");
         return;
     }

     if (txtPhoneDDD.value == "") {
         alert("Preencha seu DDD.");
         return;
     }

     if (txtPhoneNumber.value == "") {
         alert("Preencha o número do seu telefone.");
         return;
     }

     $.post("AJAXHandler.axd?cmd=callme", {
     fullname: txtName.value,
            phoneddd: txtPhoneDDD.value,
            phonenumber: txtPhoneNumber.value,
            besttime: txtBesttime.value
        });

    alert("Aguarde nosso telefonema.");

    CloseCallMe();
}


function CloseCallMe() {
    HideModal();
    $("#callMeWindow").hide();
}