﻿// JScript File
String.prototype.Left = function(n){
 return this.substring(0,n);
}

String.prototype.ConvertToListValue = function(){
 var gradeValue = this.split("[")[0];
 //alert("i am here");
 if (gradeValue == "PK" || gradeValue == "K")
       return this.replace(/PK/,"0").replace(/K/,"00")
 else if(parseInt(gradeValue) >= 0 && parseInt(gradeValue) <= 9)
       return "0" + this
 else  return this
}

$.fn.ListBoxItemsToString = function(separator){
        var ListItemValues = "";
        $("OPTION", this).each(function(){
           ListItemValues += $(this).val() + separator
        });
        
        if (ListItemValues.length > 0) return ListItemValues.Left(ListItemValues.length-1);
        return null;
}

 function SelectTab(SelectedTabId){   
   if ($(".NavigationControl li").hasClass("selected")) $(".NavigationControl li").removeClass("selected")
    $(".NavigationControl li a#" + SelectedTabId).parent("li").addClass("selected")   
  }
  
  function LoadContent(objTarget,url,data){
   var randomNumber = Math.floor(Math.random()*1000001)
   url = url + "?randomNumber=" + randomNumber
   objTarget.children().hide().end().append('<div class="loading"><img src="./Images/loader.gif" /></div>')
   jQuery.get(url,data,function(dataResponse){
     alert(dataResponse)
     objTarget.html(dataResponse).hide().show()           
   },"html")    
   }
   
  function PostContent(objTarget,postUrl,postData, CallBackFunc){  
   objTarget.children().hide().end().append('<div class="loading"><img src="./Images/loader.gif" /></div>')             
   $.ajax({
   type:"POST",
   url:postUrl,
   data:postData,
   contentType:"application/json; charset=utf-8",
   dataType:"json",
   error: function(xhr,status,err){
     alert(xhr.responseText);
   },
   success:function(dataResponse){ 
   if (CallBackFunc) {     
     if (jQuery.isFunction(CallBackFunc)) {    
     if (dataResponse.ListSource)  CallBackFunc(objTarget, dataResponse.ListSource)
     else CallBackFunc(objTarget, dataResponse)
     }
    }
     else   objTarget.html(dataResponse).hide().show();
   }
   })  
 }

 function RenderDropDown(objTarget, listSource){   
   objTarget.children().remove() 
   for(var row in listSource){     
     objTarget.append("<option value='" + listSource[row]["ID"] + "'>" + listSource[row]["Name"] + "</option>")
   } 
     objTarget.attr("selectedIndex",0)    
     objTarget.show()
     objTarget.trigger('load')
 }

function RenderListBox(objTarget, listSource){
 objTarget.children().remove()
 //Also empty the Select ListBox if there is any 
 var objSelectTarget = $("#" + objTarget.attr("id") + "_Selected")
 if (objSelectTarget) objSelectTarget.children().remove()
 
 for(var row in listSource){     
     objTarget.append("<option value='" + listSource[row]["ID"] + "'>" + listSource[row]["Name"] + "</option>")
 } 
 objTarget.attr("selectedIndex",0)    
 objTarget.show()
 objTarget.trigger('load')
}