//////////////////////////////
///// 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());
	//Ext.getCmp('sitelanguages').setRawValue(script.charAt(0).toUpperCase() + script.substr(1).toLowerCase());

}

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

    var exp = /^.*\.(jpg|JPG|png|PNG|BMP|bmp)$/;
    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,company_id) {
	
	if(FormMode=="add") {
		SectionStore.on({'load': {
							fn: function(store, options)
							{  
								  if(SectionStore.getCount()==1)
								  {			    
										Ext.getCmp(SectionCombo).setValue(SectionStore.getAt(0).data.company_id,true);														
										Ext.getCmp(SectionCombo).focus(true,500); 
								  }
								  else
								  {
									  Ext.getCmp(SectionCombo).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 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 sortAndRemoveDuplicates(arr) {
    arr.sort( function(a, b) { return a - b; } );
    var copy = arr.slice(0);
    arr.length = 0;
    for (var i = 0, len = copy.length; i < len; ++i) {
        if (i == 0 || copy[i] != copy[i - 1]) {
            arr.push(copy[i]);
        }
    }
	 alert(arr);
    return arr;
}
function unique(a)
{
   var r = new Array();
   o:for(var i = 0, n = a.length; i < n; i++)
   {
      for(var x = 0, y = r.length; x < y; x++)
      {
         if(r[x]==a[i]) continue o;
      }
      r[r.length] = a[i];
   }
   alert(r);
   return r;
   
}