﻿

jQuery(document).ready(function(){
 
 AddCountyData();
 AddSpecialtyData();
 AddClearEvent();

 CheckAllInput();
 
 AddSumbitDataEvent();
 
jQuery("[@maingrouptype]").each(function(){

  var grouptype=jQuery(this).attr("maingrouptype");
  var radioBtn=jQuery(this).find("input");
  
  radioBtn.click(function(){
  
  CheckAllInput();
  
});

});

  
});

function CheckAllInput()
{
jQuery("[@maingrouptype]").each(function(){

  var grouptype=jQuery(this).attr("maingrouptype");
  var radioBtn=jQuery(this).find("input");
  
    if(!radioBtn.attr("checked"))
    {
        jQuery("[@grouptype="+grouptype+"]").each(function(){
        jQuery(this).attr("disabled","disabled");
      });
    }
    else
    {
        jQuery("[@grouptype="+grouptype+"]").each(function(){
        jQuery(this).attr("disabled","");
    }); 
  }
  
});

}

function AddSumbitDataEvent()
{
  jQuery("[@eventtype=submitdata]").click(function(){
   
    var conCountyID=jQuery("[@datatype=County]").attr("id");
    var conCounty=jQuery("#"+conCountyID);
    var conCountyValue=conCounty.val();
    if(conCountyValue==null)
    {
      conCountyValue="";
    }
      
    var conSepcID=jQuery("[@datatype=Specialty]").attr("id");
    var conSepc=jQuery("#"+conSepcID);
    var conSepcValue=conSepc.val();
    if(conSepcValue==null)
    {
     conSepcValue="";
    }
    
    var strValue=conCountyValue;
    if(conSepcID!=null)
    {
     strValue+="|"+conSepcValue;
    }
  
    var hiddeCon=jQuery("[@inputype=hiddenvalue]");   
    hiddeCon.val(strValue);
    
    var dropmile=jQuery("[@droptype=mile]");
     
      
    var textaddress=jQuery("[@texttype=address]");
    var textcity=jQuery("[@texttype=city]");
    var tipaddress=jQuery("[@tiptype=address]");
    var tipcity=jQuery("[@tiptype=city]");
      
    var textstate=jQuery("[@texttype=state]");
    var textzipcode=jQuery("[@texttype=zipcode]");
    var tipzipcode=jQuery("[@tiptype=zipcode]");
       
    var result=true;
       
//    if(dropmile.attr("selectedIndex")>0)
//    {
//      if(jQuery.trim(textaddress.val())==""&&jQuery.trim(textcity.val())=="")
//      {
//         tipaddress.css("display","none");
//         tipcity.css("display","none");
//         
//         result=true;
//      }
//      else
//      {
//          if(jQuery.trim(textaddress.val())=="")
//          {
//            tipaddress.css("display","");
//            if(result)
//            {
//              result=false;
//            }
//          }
//          else
//          {
//            tipaddress.css("display","none");
//          }
//      
//          if(jQuery.trim(textcity.val())=="")
//          {
//             tipcity.css("display","");
//             if(result)
//             {
//               result=false;
//             }
//          }
//         else
//         {
//           tipcity.css("display","none");
//         }
//      }
//      
//    }
//    
//      if((textzipcode.val()=="")&&(jQuery.trim(textcity.val())==""||textstate.attr("selectedIndex")==0))
//      {
//        tipzipcode.css("display","");
//        if(result)
//        {
//          result=false;
//        }
//      }
//      else
//      {
//        tipzipcode.css("display","none");
//      }
//      
//     return result;


      if(jQuery.trim(textaddress.val())==""&&jQuery.trim(textcity.val())=="")
      {
         tipaddress.css("display","none");
         tipcity.css("display","none");
         
         result=true;
      }
      else
      {
          if(jQuery.trim(textaddress.val())=="")
          {
            tipaddress.css("display","");
            if(result)
            {
              result=false;
            }
          }
          else
          {
            tipaddress.css("display","none");
          }
      
          if(jQuery.trim(textcity.val())=="")
          {
             tipcity.css("display","");
             if(result)
             {
               result=false;
             }
          }
         else
         {
           tipcity.css("display","none");
         }
      }
      
//      if(jQuery.trim(textcity.val())!=""&&textstate.attr("selectedIndex")!=0)
//      {
//        tipzipcode.css("display","none");
//        result=true;
//      }
      
      if((textzipcode.val()=="")&&(jQuery.trim(textcity.val())==""||textstate.attr("selectedIndex")==0))
      {
        tipzipcode.css("display","");
        if(result)
        {
          result=false;
        }
      }
      else
      {
        tipzipcode.css("display","none");
        result=true;
      }
      
      var isEmpty=true;
      jQuery("input[@type=text]").each(function(){
      
         if(jQuery.trim(jQuery(this).val())!="")
         {
           if(isEmpty)
           {
             isEmpty=false;
           }
         }         
      });
      
      jQuery("select").each(function(){
      
        if(jQuery.trim(jQuery(this).val())!="")
         {
           if(isEmpty)
           {
             isEmpty=false;
           }
         }         
      });
     
      jQuery("[@tiptype=true]").css("display","none");

      var mustInput=jQuery("#MustInput");
      if(result&&isEmpty)
      {
          result=false;
          mustInput.css("display","");
      }
      else
      {
         mustInput.css("display","none");
      }
          
     return result;
     
  });
}

function AddClearEvent()
{
 var clearall=jQuery("[@eventtype=clearall]");
 clearall.css("cursor","pointer");
 
  clearall.click(function(){
 
  jQuery("input[@type=text]").each(function(){
     jQuery(this).val("");
  });
  
  jQuery("select").each(function(){
     jQuery(this).val("");
  });
  
  jQuery("[@class=errorMessage]").each(function(){
    jQuery(this).css("display","none");
  });
  
  var tdCounty=jQuery("#tdCounty");
  var tdCountyDrop=jQuery("#tdCountyDrop");

  tdCountyDrop.find("select").html("");
  tdCounty.css("display","none");
  tdCountyDrop.css("display","none");
       
 });
 
}

function ClearStateSelect()
{
  var state=jQuery("[@changegetdata=County]");
  state.attr("selectedIndex","0");
  
  var conID=jQuery("[@datatype=County]").attr("id");
  var con=jQuery("#"+conID);
　con.html("");
}

function AddCountyData()
{

var state=jQuery("[@changegetdata=County]");
GetCountyDataEvent(state);

state.change(function(){

 GetCountyDataEvent(state);

});

}

function GetCountyDataEvent(state)
{

var conID=jQuery("[@datatype=County]").attr("id");
var con=jQuery("#"+conID);

con.click(function(){

 var mustInput=jQuery("#MustInput");
 mustInput.css("display","none");
  
if(state.attr("selectedIndex")==0&&con.find("select").length==0)
{
  jQuery("[@tiptype=true]").css("display","");
}
else
{
   jQuery("[@tiptype=true]").css("display","none");
}

});

if(state.attr("selectedIndex")!=0)
{
　con.html("");
  GetCountyData("AjaxPages/GetDataByCondition.aspx",conID,state.val(),state.attr("tablename"));
  jQuery("[@tiptype=true]").css("display","none");
}
else
{
　  con.html("");
　   
//　  var tdCounty=jQuery("#tdCounty");
//    var tdCountyDrop=jQuery("#tdCountyDrop");
//    tdCounty.css("display","none");
//    tdCountyDrop.css("display","none");
}
 
}


function GetCountyData(ajaxPage,conID,state,table)
{
　　$.ajax({ 
　　type:"post", 
　　url:ajaxPage, 
　　dataType:"html", 
　　timeout:10000,
　　data:"Type=GetCounty&State="+state+"&Table="+table, 
　　success:function(result) 
　  {
　  var con=jQuery("#"+conID);
　  con.html("");
　  var strSplit=String.fromCharCode(1);
　  var data=result.split(strSplit);
　  for(i=0;i<data.length;i++) 
    {
        var op = window.document.createElement("option");
        op.value =data[i];
        op.innerHTML =data[i];
        con.append(op);
    }
    
//    var tdCounty=jQuery("#tdCounty");
//    var tdCountyDrop=jQuery("#tdCountyDrop");
//    
//    if(data.length>1)
//    {
//      tdCounty.css("display","");
//      tdCountyDrop.css("display","");
//    }
//    else
//    {
//      tdCounty.css("display","none");
//      tdCountyDrop.css("display","none");
//    }

　　},
　　error: function(result)
　　{
//　　   var tdCounty=jQuery("#tdCounty");
//       var tdCountyDrop=jQuery("#tdCountyDrop");
//       tdCounty.css("display","none");
//       tdCountyDrop.css("display","none");
　　}
　 });
}

function AddSpecialtyData()
{
 var providerType=jQuery("[@changegetdata=Specialty]");
 GetSpecialtyDataEvent(providerType);
  
 providerType.change(function(){
 
 GetSpecialtyDataEvent(providerType);

 });

}

function GetSpecialtyDataEvent(providerType)
{

var conID=jQuery("[@datatype=Specialty]").attr("id");
var selIndex=providerType.attr("selectedIndex");
var value=providerType.val();

if(selIndex==0)
{
 　 var con=jQuery("#"+conID);
　  con.html("");
}
else if(value=="GP")
{
    var data=new Array();
    data[0]="";
    data[1]="Obstetrics & Gynecology";
    data[2]="Pediatrics";
    data[3]="Primary Care (Adult)";
    
　  var con=jQuery("#"+conID);
　  con.html("");
　  for(i=0;i<data.length;i++) 
    {
　      var op = window.document.createElement("option");
        op.value =data[i];
        op.innerHTML =data[i];
        con.append(op);
    }
}
else if(value=="SP")
{
　  var con=jQuery("#"+conID);
　  con.html("");
    GetSpecialtyData("AjaxPages/GetDataByCondition.aspx",conID);
}

}

function GetSpecialtyData(ajaxPage,conID)
{
　　$.ajax({ 
　　type:"post", 
　　url:ajaxPage, 
　　dataType:"html", 
　　timeout:10000,
　　data:"Type=GetSpecialty",
　　success:function(result) 
　  {
　  var con=jQuery("#"+conID);
　  con.html("");
　  var strSplit=String.fromCharCode(1);
　  var data=result.split(strSplit);
　  for(i=0;i<data.length;i++) 
    {
        var op = window.document.createElement("option");
        op.value =data[i];
        op.innerHTML =data[i];
        con.append(op);
    }

　　},
　　error: function()
　　{
　　 
　　}
　 });
}

function SetInputNumber(e)
{
   var keyc;

   if(window.event)
   {
	 keyc=e.keyCode;
   }
   else if(e.which)
   {
	 keyc=e.which;
   }

   if(keyc == 8)
   {
     return;
   }

  if (keyc < 48 || keyc >57) 
  {
  	  if(window.event)
  	    {
		   e.returnValue = false;
		}
	 else if(e.which)
	 {
	   e.preventDefault()
	 }
  }
}
