function getPhoneNumber(ePhone){
         hurufPertama = ePhone.charAt(0);
         hurufSelanjutnya = ePhone.substring(1,ePhone.length);
         if (hurufPertama == '0'){
             $('handphone').value = hurufSelanjutnya;
         }
}

function tCheckFormMember(tForm){       
        if ($('msg').style.display == "block"){
            tForm.email.focus();
            return false;
        }        

        eEmail = tForm.email.value
        filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        if (tForm.email.value != ''){
            if (!filter.test(eEmail)){
                alert('Mohon isi alamat e-mail dengan format nama@domain.com');
                tForm.email.focus();
                return false;
            }
        }else{
            alert('Mohon isi E-Mail anda');
            tForm.email.focus();
            return false;
        }
                 
        if (tForm.password1.value == ''){
            alert('Mohon isi password anda.');
            tForm.password1.focus();
            return false;
        } else{
            if (tForm.password1.value.length < 6){
                alert('Jumlah digit untuk password minimal 6 karakter.');
                tForm.password1.focus();
                return false;
            }
        }
        if (tForm.password1.value != tForm.password2.value){
            alert('Ulangi password tidak sesuai.');
            tForm.password2.focus();
            return false;
        }

         if (tForm.nama.value == ''){
             alert('Mohon isi nama lengkap anda.');
             tForm.nama.focus();
             return false;
         }

         if (tForm.kodegambar.value == ''){
             alert('Mohon isi kode gambar.');
             tForm.kodegambar.focus();
             return false;
         }
         return true;
}

function cekNomorHP(noHP){
         if (noHP.match("^[+][1-9]([0-9]{8,13})$")){
             return true;
         } else {
             return false;
         }
}

function tCheckFormForgot(tForm){  
        if ($('imgLoad').style.display == "block"){
            tForm.email.focus();
            return false;
        }
              
        if ($('msg').style.display == "block"){
            tForm.email.focus();
            return false;
        }
        
        if (tForm.email.value == ''){
            alert('Mohon isi alamat email anda.');
            tForm.email.focus();
            return false;
        }
         
        if (tForm.kodegambar.value == ''){
            alert('Mohon isi kode gambar.');
            tForm.kodegambar.focus();
            return false;
        }
        return true;
}
function tCheckFormSetPwd(tForm){
        if (tForm.password1.value == ''){
            alert('Mohon isi password anda.');
            tForm.password1.focus();
            return false;
        } else{
            if (tForm.password1.value.length < 6){
                alert('Jumlah digit untuk password minimal 6 karakter.');
                tForm.password1.focus();
                return false;
            }
        }
        
        if (tForm.password1.value != tForm.password2.value){
            alert('Ulangi password tidak sesuai.');
            tForm.password2.focus();
            return false;
        }
         
        if (tForm.kodegambar.value == ''){
            alert('Mohon isi kode gambar.');
            tForm.kodegambar.focus();
            return false;
        }
        return true;
}

function showEl(){
         $('divMsg').style.display = 'block';
}

function cekEmail(eSub){
         eEmail = $F('email');
         randomNumber = tGetRandomNumber();
         if (eSub == 'join'){
             url ='t.page.process.php?pub=cek_email_join';
             pars = 'email='+ eEmail +'&rand='+ randomNumber;
         } else if (eSub == 'forgot_password'){
             url ='t.page.process.php?pub=cek_email_forgot_pwd';
             pars = 'email='+ eEmail +'&rand='+ randomNumber;
         } else if (eSub == 'act_code'){
             url ='t.page.process.php?pub=act_code';
             pars = 'email='+ eEmail +'&rand='+ randomNumber;
         }
         myAjax = new Ajax.Request(url,{
                           method: 'get',
                           parameters: pars,
                           onSuccess: showResponseCekEmail,
                           onLoading: function(transport){
                                               $('msg').style.display = 'none';
                                               $("imgLoad").style.display = "block";
                           },
                           onFailure: function(transport){
                                               $('msg').style.display = 'none';
                                               $("imgLoad").style.display = "none";
                                               alert("Connection error while loading data");
                           }
                      }
                      );
}

function showResponseCekEmail(transport){         
         $("imgLoad").style.display = "none";
         if (transport.responseXML){
             eXml = transport.responseXML;
             arrError = eXml.getElementsByTagName("error");
             if (arrError.length > 0){
                 $('msg').innerHTML = arrError.item(0).firstChild.data;  
                 $('msg').style.display = 'block';               
                 showEl();
             } else{
                 $('divMsg').style.display = 'none';
             }
         }
}

function cekTeman(el){
         var objForm = document.formMemberAdd.elements;
         for(i=1;i<=4;i++){
            if(objForm["cariTeman[" + i + "]"].checked){
               return true;
            }
          }
         objForm["cariTeman[3]"].checked = true;
         return false;
}

function removeOptionKota(){         
         for (var i=document.formMemberAdd.kota.length; i >= 0; i--){
              document.formMemberAdd.kota[i] = null;              
         }
}

function addOptionsKota(){  
         // hilangkan dulu content option kota yang ada  
         eKode = $('propinsi').value;         
         randomNumber = tGetRandomNumber();
         url ='t.admin.process.php';
         pars = 'mod=get_kabupaten&kode='+ eKode +'&rand='+ randomNumber;
         myAjax = new Ajax.Request(url,{
                           method: 'get',
                           parameters: pars,
                           onSuccess: showResponseKota,
                           onLoading: function(transport){
                                               $("kota").style.display = "none";
                                               $("imgLoad2").style.display = "block";
                           },
                           onFailure: function(transport){
                                               $("imgLoad2").style.display = "none";
                                               alert("Connection error while loading data");
                           }
                      }
                      );        
}

function showResponseKota(transport){         
         $("imgLoad2").style.display = "none";
         $("kota").style.display = "block";         
         if (transport.responseXML){
             eXml = transport.responseXML;
             arrError = eXml.getElementsByTagName("error");
             arrKode = eXml.getElementsByTagName("kode");
             arrNama = eXml.getElementsByTagName("nama");             
             if (arrKode.length > 0){
                 for (var i=0; i < arrKode.length; i++){
                      document.formMemberAdd.kota[i] = new Option(arrNama.item(i).firstChild.data,arrKode.item(i).firstChild.data);
                 }
             }
             if (arrKode.length > 0){
                 $('kota').disabled = false;
             } else{             
                 document.formMemberAdd.kota[0] = new Option('-- -- --','00');
             }
         }        
}


function removeOptionPropinsi(){         
         for (var i=document.formMemberAdd.propinsi.length; i >= 0; i--){
              document.formMemberAdd.propinsi[i] = null;              
         }
}

function cekNegara(eNegara){
         if (eNegara != 'ID'){
             removeOptionPropinsi();
             document.formMemberAdd.propinsi[0] = new Option('-- -- --','00');
             $('propinsi').disabled = true;
             
             removeOptionKota();
             document.formMemberAdd.kota[0] = new Option('-- -- --','00');
             $('kota').disabled = true;
         } else{
             removeOptionPropinsi(); 
                          
             removeOptionKota();
             document.formMemberAdd.kota[0] = new Option('-- -- --','00');
             
             addOptionsPropinsi();
             document.formMemberAdd.propinsi[0] = new Option('-- -- --','00');
             
             $('propinsi').disabled = false;
             $('kota').disabled = false;
         }
}

function addOptionsPropinsi(){  
         // hilangkan dulu content option kota yang ada      
         randomNumber = tGetRandomNumber();
         url ='t.admin.process.php?';
         pars = 'mod=get_propinsi&rand='+ randomNumber;
         myAjax = new Ajax.Request(url,{
                           method: 'get',
                           parameters: pars,
                           onSuccess: showResponsePropinsi,
                           onLoading: function(transport){
                                               $("propinsi").style.display = "none";
                                               $("imgLoadx").style.display = "block";
                           },
                           onFailure: function(transport){
                                               $("imgLoadx").style.display = "none";
                                               alert("Connection error while loading data");
                           }
                      }
                      );        
}

function showResponsePropinsi(transport){         
         $("imgLoadx").style.display = "none";
         $("propinsi").style.display = "block";         
         if (transport.responseXML){
             eXml = transport.responseXML;
             arrError = eXml.getElementsByTagName("error");
             arrKode = eXml.getElementsByTagName("kode");
             arrNama = eXml.getElementsByTagName("nama");             
             if (arrKode.length > 0){
                 for (var i=1; i <= arrKode.length; i++){
                      document.formMemberAdd.propinsi[i] = new Option(arrNama.item(i).firstChild.data,arrKode.item(i).firstChild.data);
                 }
             }
             if (arrKode.length > 0){
                 $('propinsi').disabled = false;
             } else{             
                 document.formMemberAdd.propinsi[0] = new Option('-- -- --','00');
             }
         }        
}
