﻿
function TimKiemSim(ctl,sosim)
{
    var ctsim =document.getElementById(sosim);
    var path = "TimKiemSim.aspx?ss="+ctsim.value ;
    //ctl.href = path;
    //alert(" sdsds");
    window.location.href = path;//ctl.href;
    
  
}
function TimSimTheoGiaSan(ctl,gt1,gt2)
{
    ctl.href = "TimKiemSimTheoGia.aspx?ss=09"+"&g1="+gt1+"&g2="+gt2 ;
}

//xac nhanmat khau 

 function XacNhanLaiMatKhau(ctr1,ctr2)
 {
    var ct ='ctl00_cp';
    var ct2;
    ct = ct+"_User_";
    
    ct2 =document.getElementById(ct+ctr2);
    
    if(ct2!= null)
    {
        if(ctr1.value != ct2.value)
        {
            alert('Mật khẩu không hợp lệ');
            ct2.focus();
        }
    }
  }  
  
function KiemTraMatKhau(ctr1,ctr2)
{
    var ct ='ctl00_cp';
     var ct2;
    ct = ct+"_User_";
   
    ct2 = document.getElementById(ct+ctr2);
    if(ctr1.value=='')
    {
         ctr1.focus();
    }
    else
    {
       if(ct2.value=='' || ctr1.value != ct2.value)
        {
            ct2.focus();
        }
    }
}


// kiem tra

function KiemTraChinh(s1,s2)
 {
    //var gt1 =document.getElementById(s1);
    var gt2 =document.getElementById(s2);
   //if(gt1.value != gt2.value)
   // {
        //document.getElementById(s2).focus();
        alert(gt2.value ); 
        return false;  
   // }
   
 }



function QuangCao(url)
{
    window.open(url,"_blank");
}
 
        
//chitietgach
 function ThongTinChiTiet(url)
    {
       var x,y;
       x=  window.screen.width/2-100;
       y= window.screen.height/2-40;//event.clientY;//
       var kichthuoc = "height=80,width=200,top=" + y + ",left=" + x ;
       kichthuoc += "location=no,resizable=no,toolbar=no,scrollbars=no,status=no,titlebar=no"
           //top='',left=''
        /*var w = window.open('YeuCau.aspx',"_self","height=100,width=200,top='y',left=x");
        w.setTimeout("window.navigate('LoaiGach.aspx')",1000) ;//window.close()*/
        //window.navigate("LoaiGach.aspx");*/
        
        
        var w = window.open(url,"_blank",kichthuoc);
        
        w.setTimeout("window.close();",5000) ;
        //w.navigate("LoaiGach.aspx");
         
  }
  
   
    
  // chon tat ca
  
 function CheckAll(ck_all)
  {
   var elem;
   var own = document.all;
    var i = document.all.length;
        if(ck_all.checked == true)
        {
            for (j=0 ;j<i; j++)
            {
            
                elem = own.item(j);
                if(elem.type == 'checkbox')
                {
                    elem.checked = true;
                }
            }
        }
        else
        {
            for ( j=0;j<i; j++)
            {
                elem = own.item(j);
                if(elem.type == 'checkbox')
                {
                    elem.checked = false;
                }
            }        
        }
       //alert("check all"+ ckone);
    
      
  }

function KiemTraNhap(ctr1,ctr2,ctr3)
{
    ct2 =document.getElementById("ctl00_ContentPlaceHolder1_"+ctr2);    
    ct3 =document.getElementById("ctl00_ContentPlaceHolder1_"+ctr3);    
    if(ctr1.checked==true)
    {
        ct2.disabled=false;
        ct3.disabled=true;
        ct2.focus();
        
    }
    else
    {
        ct2.disabled=true;
        ct3.disabled=false;
        ct3.focus();
    }
}


//ham them dau cach
function KiemTraChuoi(s,kitu,vitri)
{
    var temp = "";// new String("");
    var j=0,i=0;
    
    for(i=0; i< s.length ; i++)
    {
        //alert("vitri i= " + i+ "vitri j= " + vitri[j] );
        if( vitri.length>0 && i == vitri[j])
        {
           // alert(" vao vitri i= " + i+ "vitri j= " +vitri[j]);
            temp += kitu;
            
           if(j< vitri.length) j++;
        }
        temp+= s.charAt(i);
       
    }
    s= temp;
    return s;
}

//var  chuoinhap = new string ("");

function kiemtrasodidong(s) //so di dong
{
    var chuoiloc = "";
    var c;
    for(i=0; i< s.length ; i++)
    {
        c =s.charAt(i); 
        if(c >= '0' && c<= '9'|| c =='.')
        {
             chuoiloc += c;
        }
          
    }
    if(chuoiloc != "")
        return chuoiloc;
    return "0";
    
}

function kiemtraso(s) 
{
    var chuoiloc = "";
    var c;
    for(i=0; i< s.length ; i++)
    {
        c =s.charAt(i); 
        if(c >= '0' && c<= '9')
        {
             chuoiloc += c;
        }
          
    }
    if(chuoiloc != "")
        return chuoiloc;
    return "0";
    
}

function kiemtrasoBan(s)
{
    var chuoiloc = "";
    var c;
    for(i=0; i< s.length ; i++)
    {
        c =s.charAt(i); 
        if(c >= '0' && c<= '9')
        {
             chuoiloc += c;
        }
          
    }
    return chuoiloc;
    
}


function KiemTraGiaTriNhap(control)    //kiem tra so sim
{
    var i;
    var chuoiLoc = "";
    if(control.value != "")
    {
         chuoiLoc = kiemtraso(control.value);//loc so
        if(chuoiLoc.length >0)
        {
            var chuoinhap;
            chuoinhap = chuoiLoc;
          
            switch (chuoinhap.length)
            {
            
                case 5:
                case 6:
                case 7:
                    var vitri = new Array();
                    vitri[0]=4;
                    chuoinhap = KiemTraChuoi(chuoinhap,"-",vitri);
                    break;
                case 8:
                case 9:
                    var vitri = new Array(4,7);
                    chuoinhap = KiemTraChuoi(chuoinhap,"-",vitri);
                    break;
                case 10:
                    var vitri = new Array(4,7);
                    chuoinhap = KiemTraChuoi(chuoinhap,"-",vitri);
                    break;
                case 11:
                    var vitri = new Array(5,8);
                    chuoinhap = KiemTraChuoi(chuoinhap,"-",vitri);
                    break;
                case 12:
                    var vitri = new Array(6,9);
                    chuoinhap = KiemTraChuoi(chuoinhap,"-",vitri);
                    break;


             }
        }
        control.value = chuoinhap;
      
    }  
}


function KiemTraTienNhap(control)    //kiem tra tien
{
    var i;
    var chuoiLoc = "";
    if(control.value != "")
    {
         chuoiLoc = kiemtraso(control.value);//loc so
        if(chuoiLoc.length >0)
        {
            var chuoinhap;
            chuoinhap = chuoiLoc;
          
            switch (chuoinhap.length)
            {
            
                case 4:
                    var vitri = new Array();
                    vitri[0]=1;
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 5:
                    var vitri = new Array();
                    vitri[0]=2;
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;

                case 6:
                    var vitri = new Array();
                    vitri[0]=3;
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 7:
                    var vitri = new Array(1,4);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 8:
                    var vitri = new Array(2,5);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 9:
                    var vitri = new Array(3,6);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 10:
                    var vitri = new Array(1,4,7);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 11:
                    var vitri = new Array(2,5,8);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 12:
                    var vitri = new Array(3,6,9);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 13:
                    var vitri = new Array(1,4,7,10);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                case 14:
                    var vitri = new Array(2,5,8,11);
                    chuoinhap = KiemTraChuoi(chuoinhap,".",vitri);
                    break;
                    
                    
             }
        }
        control.value = chuoinhap;
      
    }  
}
    
