                                                                                                                                                                                                                               
//////////////////////////////
///// date range validation
Ext.apply(Ext.form.VTypes, {
    daterange : function(val, field) {
        var date = field.parseDate(val);

        if(!date){
            return;
        }
        if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
            var start = Ext.getCmp(field.startDateField);
            start.setMaxValue(date);
            start.validate();
            this.dateRangeMax = date;
        } 
        else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
            var end = Ext.getCmp(field.endDateField);
            end.setMinValue(date);
            end.validate();
            this.dateRangeMin = date;
        }
        return true;
    }



});
/////////
function indicChange(id, script){
	
	pphText.setGlobalScript(script);
	Ext.getCmp('sitelanguages').setRawValue(script.toLowerCase());
}

function initIndicIME(){
	pphText  = new PramukhPhoneticHandler();
	lang= "english";
	pphText.convertPageToIndicIME(lang, indicChange);
	Ext.getCmp('sitelanguages').setRawValue(lang.charAt(0).toUpperCase() + lang.substr(1).toLowerCase());
}
function validateFileExtension(fileName) {

    var exp = /^.*\.(jpeg|JPEG|jpg|JPG)$/;
    return exp.test(fileName);    	
}
function replaceSpecial(strValue) {
	
  var strExp = new RegExp("\n");
  
  strValue = strValue.replace(new RegExp("\n"), '');
  return strValue;
}
function SetSectionValue (FormMode,SectionStore,SectionCombo,SectionId) {
	
	if(FormMode=="add") {
	 
								  if(SectionStore.getCount()==1)
								  {			    
										Ext.getCmp(SectionCombo).setValue(SectionStore.getAt(0).data.section_id,true);														
										
										Ext.getCmp(SectionCombo).focus(true,500); 
								  }
								  else
								  {
									  Ext.getCmp(SectionCombo).focus(true,500); 
								  }	   	
				
				
	}
}
function SetLibraryValue (FormMode,libraryStore,libraryCombo,libraryId) {
	
	if(FormMode=="add") {
		libraryStore.on({'load': {
							fn: function(store, options)
							{  
								  if(libraryStore.getCount()==1)
								  {		  
										Ext.getCmp(libraryCombo).setValue(libraryStore.getAt(0).data.register_id,true);														
										Ext.getCmp(libraryCombo).focus(true,500); 
								  }
								  else
								  {
									  Ext.getCmp(libraryCombo).focus(true,500); 
								  }	   	
							}
						} 
				}); 	
	}
}
// Prevent empty text labels from being submitted
function clearEmptyText(formName)
{
	 var fields = formName.form.items, emptyFields = [];
	 fields.each(function(f)
	 {
		 if (f.el.getValue() == f.emptyText)
		 {
			 emptyFields.push(f);
			 f.el.dom.value = "";
		 }
	 });
 }
 // code ends


function validRegno(obj,e){
	   
	var number = obj.getValue();
	var len_number = number.length;
	//alert(number.charCodeAt(0));
	//58-64
		if(number.charCodeAt(0)==45 || (number.charCodeAt(0) >= 1 && number.charCodeAt(0) <= 47) || (number.charCodeAt(0) >= 58 && number.charCodeAt(0) <= 64))
		{
			number = number.substring(0,0);
			obj.setValue(number);
		
		}
}				 

function validphoneno(obj,e){
	var number = obj.getValue();
	var len_number = number.length;
	for(i=0; i<len_number; i++){
		if(number.charCodeAt(i)==45 || (number.charCodeAt(i) >= 48 && number.charCodeAt(i) <= 57)){}
		else
		{
			number = number.substring(0,i);
			obj.setValue(number);
		}
		
	}
}

function removeHTMLTags(string){
 		var strInputCode = string;
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		strTagStrippedText = strTagStrippedText.replace(/&nbsp;/g, " ");
		return strTagStrippedText;	
}

Ext.grid.RowSelectionModel.override ({
    getSelectedIndex : function(){
        return this.grid.store.indexOf( this.selections.itemAt(0) );
    }
});

Ext.override(Ext.form.Checkbox, {
	setBoxLabel: function(boxLabel){
		this.boxLabel = boxLabel;
		if(this.rendered){
			this.wrap.child('.x-form-cb-label').update(boxLabel);
		}
	}
});