﻿/****
Author druzya81 @ KadirKartal
***/

this.rand = 0;
function manager() {
    this.rand = Math.random();
}


manager.prototype.addClass = function (el, css) {
    var tem, C = el.className.split(/\s+/), A = [];
    while (C.length) {
        tem = C.shift();
        if (tem && tem != css) A[A.length] = tem;
    }
    A[A.length] = css;
    return el.className = A.join(' ');
};

/****************AJAX FUNCTIONS ***********************/








/**********************************************************************************************************************************/


/***********************UTIL FUNCTIONS *********************************/
manager.prototype.validateEmail = function (elementValue) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
};
/**************************************************************************/


manager.prototype.internalAVMValidationStyle = function (pBoolExp, pObj) {
    if (pBoolExp) {
        pObj.style.border = '1px solid red';
        pObj.focus();
    } else {
        pObj.style.border = '0px solid #c4c4c4';
    }
};

manager.prototype.AVMFormValidation = function () {
    var c_ad = document.getElementById('txtAd');
    var exp = (c_ad.value.length == 0);
    this.internalAVMValidationStyle(exp, c_ad);
    if (exp) return false;

    var c_soyad = document.getElementById('txtSoyad');
    exp = (c_soyad.value.length == 0);
    this.internalAVMValidationStyle(exp, c_soyad);
    if (exp) return false;

    var c_email = document.getElementById('txtEposta');
    exp = (c_email.value.length == 0 || !this.validateEmail(c_email.value));
    this.internalAVMValidationStyle(exp, c_email);
    if (exp) return false;

    var c_phone = document.getElementById('txtCepTel');
    exp = (c_phone.value.length == 0 || c_phone.value.replace('(', '').replace(')', '').replace(' ', '').replace('-', '').replace('_').length != 10);
    this.internalAVMValidationStyle(exp, c_phone);
    if (exp) return false;


    var c_sex = document.getElementById('ddlCinsiyet');
    exp = (c_sex.selectedIndex == 0);
    this.internalAVMValidationStyle(exp, c_sex);
    if (exp) return false;

    var c_day = document.getElementById('ddlGun');
    exp = (c_day.selectedIndex == 0);
    this.internalAVMValidationStyle(exp, c_day);
    if (exp) return false;


    var c_month = document.getElementById('ddlAy');
    exp = (c_month.selectedIndex == 0);
    this.internalAVMValidationStyle(exp, c_month);
    if (exp) return false;


    var c_yil = document.getElementById('ddlYil');
    exp = (c_yil.selectedIndex == 0);
    this.internalAVMValidationStyle(exp, c_yil);
    if (exp) return false;

    return true;
};





manager.prototype.sendSMSCode = function (pDivMessage, pDivForm, pSMSOnayForm) {
 $.getJSON( "/Process/Get.aspx?op=sendSMSCode&rand=" + rand,
     function (data) {
              $('#' + pDivMessage).html('').fadeIn(1000);
              $('#' + pDivMessage).html(data.sonucMesaj).fadeIn(4000);
              switch (data.sonuc) {

                    case -1:
                        {
                            document.getElementById(pDivForm).style.display = 'none';
                            break;
                        }
        }
    });

};


manager.prototype.loadMarkaFromKullanici = function (pKullaniciId) {
 $.getJSON( "Process/Get.aspx?op=loadMarkaFromKullanici&kullaniciID=" + pKullaniciId + "&rand=" + rand,
       function (data) {
            $('#divMarkaList').html(data.sonucMesaj);
    });

};



manager.prototype.approveSMSCode = function (pOnayKod, pDivMessage, pSMSOnayForm, pCekilisID, pPageId) {
 $.getJSON( "/Process/Get.aspx?op=approveSMSCode&code=" + pOnayKod + "&rand=" + rand,
         function (data) {
             $('#' + pDivMessage).html('');
             $('#' + pDivMessage).html(data.sonucMesaj).fadeIn(4000);
                 switch (data.sonuc) {
                case 1:
                {
                document.getElementById(pSMSOnayForm).style.display = 'none';
                location.href = "/Soru.aspx?CekilisID=" + pCekilisID + "&Page=" + pPageId;
                }
                 case -1:
                {
                           
                document.getElementById(pDivForm).style.display = 'none';
               break;
                }  
        }
    });

};


manager.prototype.setGorusCevap = function (pGorusSoruId, pGorusCevapId) {
 $.getJSON( "/Process/Get.aspx?op=setGorusCevap&soruID=" + pGorusSoruId + "&gorusCevap=" + pGorusCevapId + "&rand=" + rand,
         function (data) {
                alert(data.sonucMesaj);
            if (data.sonuc == 1) {
                $('#MainContent_divGorus').hide().fadeOut("slow");
            }  
    });

};


manager.prototype.facebookTokenIsLive = function () {
   $.getJSON( "/Process/Get.aspx?op=faceBookTokenIsLive&rand=" + rand,
          function (data) { 
            if (data.sonuc == 1)
                location.href = "/UyeForm.aspx?q=5";
    });
};

manager.prototype.updateGSM = function (pGsm, pDivMessage, pDivForm, pSMSOnayForm) {

    $.getJSON("/Process/Get.aspx?op=updateGSM&gsm=" + pGsm + "&rand=" + rand,
         function (data) {
             document.getElementById(pDivMessage).innerHTML = '';

             $('#' + pDivMessage).html(data.sonucMesaj).fadeIn(4000);

             switch (data.sonuc) {
                 case 1:
                     {
                         document.getElementById(pDivForm).style.display = 'none';
                         document.getElementById(pSMSOnayForm).style.display = 'block';
                         break;
                     }
                 case -1:
                     {
                         document.getElementById(pDivForm).style.display = 'none';
                         break;
                     }
             }
         });

};


manager.prototype.getIlIlceSemtById = function (pIlId, pIlceId, pSemtId) {
   $.getJSON("/Process/Get.aspx?op=getIlIlceSemtById&ilID=" + pIlId + "&ilceID=" + pIlceId + "&semtID=" + pSemtId + "&rand=" + rand,
          function (data) {
              try {
                  $.each(data, function (i, item) {
                      if (item.parentId == 1)
                          $('#drpIl').append("<option value='" + item.value + "' " + ((item.value == parseInt(pIlId)) ? " selected='selected'" : '') + ">" + item.name + "</option>");

                      else if (item.parentId == 2)
                          $('#drpIlce').append("<option value='" + item.value + "' " + ((item.value == parseInt(pIlceId)) ? " selected='selected'" : '') + ">" + item.name + "</option>");

                      else if (item.parentId == 3)
                          $('#drpSemt').append("<option value='" + item.value + "' " + ((item.value == parseInt(pSemtId)) ? " selected='selected'" : '') + ">" + item.name + "</option>");
                      else { }
                  });

              }
              catch (e) { alert(e); }
          });

};


manager.prototype.getIlceListByIlId = function (pIlId) {

    $.getJSON("/Process/Get.aspx?op=getIlceListByIlId&ilID=" + pIlId + "&rand=" + rand,
        function (data) {
            try {
                $('#drpIlce option').each(function (j, option) { $(option).remove(); });
                $.each(data, function (i, item) {
                    $('#drpIlce').append("<option value='" + item.value + "'>" + item.name + "</option>");
                });

            }
            catch (e) { alert(e); }
        });
    this.getSemtListByIlceId(0);
};


manager.prototype.getSemtListByIlceId = function (pIlceID) {

    $.getJSON("/Process/Get.aspx?op=getSemtListByIlceId&ilceID=" + pIlceID + "&rand=" + rand,
           function (data) {
               try {
                   $('#drpSemt option').each(function (j, option) { $(option).remove(); });
                   $.each(data, function (i, item) {
                       $('#drpSemt').append("<option value='" + item.value + "'>" + item.name + "</option>");
                   });
               }
               catch (e) { alert(e); }

           });
};





manager.prototype.updateLocation = function (pIlId, pIlceId, pSemtId, pAddress, pCekilisID, pPageId, pDivForm, pDivMessage) {
    $.getJSON("/Process/Get.aspx?op=updateLocation&ilID=" + pIlId + "&ilceID=" + pIlceId + "&semtID=" + pSemtId + "&adres=" + pAddress + "&rand=" + rand,
         function (data) {
             try {
                  pDivMessage = '#' + pDivMessage;
                 $(pDivMessage).html('');
                 $(pDivMessage).html(data.sonucMesaj).fadeIn(4000);
                 
                 switch (data.sonuc) {
                     case 1:
                         {
                             document.getElementById(pDivForm).style.display = 'none';
                             location.href = "/Soru.aspx?CekilisID=" + pCekilisID + "&Page=" + pPageId;
                             break;
                         }
                     case -1:
                         {
                             document.getElementById(pDivForm).style.display = 'none';
                             break;
                         }

                 }
             }
             catch (e) {
                 alert(e);
             }
         });

     };


     manager.prototype.setCekilisPopupLog = function (pId, pCekilisId, pStep) {
         $.getJSON("/Process/Get.aspx?op=setCekilisPopupLog&CekilisPopupID=" + pId + "&CekilisID=" + pCekilisId + "&step=" + pStep + "&rand=" + rand,
         function (data) {
             try {
                 if (data.sonuc != 1) {
                     alert(data.sonucMesaj);
                 }
             }
             catch (e) {
                 alert(e);
             }
         });

     };


     manager.prototype.onayKoduTamam = function (pGsm, pDivMessage, pDiv1, pDiv2, pDiv3, pDiv4) {
         $.getJSON("/Process/Get.aspx?op=onayKoduTamam&gsm=" + pGsm + "&rand=" + rand,
         function (data) {
             try {
                 $('#' + pDivMessage).html(data.sonucMesaj).fadeIn('slow');
                 if (data.sonuc == 1) {
                     $(pDiv1).hide();
                     $(pDiv2).hide();
                     $(pDiv3).hide();
                     $(pDiv4).hide();
                 }
             }
             catch (e) {
                 alert(e);
             }
         });

     };



     manager.prototype.gsmDuzelt = function (pGsmp, pDivMessage, pDiv1, pDiv2, pGsmInput) {
         $.getJSON("/Process/Get.aspx?op=gsmDuzelt&gsm=" + pGsmp + "&rand=" + rand,
         function (data) {
             try {
                 if (data.sonuc == 1) {
                     $('#' + pGsmInput).val(data.sonucMesaj);
                     pDiv1.style.display = 'block';
                     pDiv2.style.display = 'none';
                 }
                 else {
                     $('#' + pDivMessage).html(data.sonucMesaj);
                 }
             }
             catch (e) {
                 alert(e);
             }
         });

     };



      manager.prototype.smsOnayGonder = function (pDivMessage,pDiv1,pDiv2) {
         $.getJSON("/Process/Get.aspx?op=smsOnayGonder&rand=" + rand,
         function (data) {
             try {
              $('#'+pDivMessage).html(data.sonucMesaj);
                if(data.sonuc==1){
                    $(pDiv1).show();
                    $(pDiv2).hide();
                } 
             }
             catch (e) {
                 alert(e);
             }
         });

     };
