bash_s_arr=Array('id','type','sD','fD','sTitle','cID','ob','pp','page','arrNum');
bash_s_arrTC=Array('id','type','sD','fD','sTitle'); //,'cID','ob','pp','page'


var bash_s_obj={
	ob:'',
	id:'',
	pp:'',
	sD:'',
	fD:'',
	type:'',
	page:''	
};
function bs_newOrder(){
bs_ob=$('#robash_s_ob').val();
bs_pp=Number($('#robash_s_pp').val());
bs_page=Number($('#robash_s_page').val());
bs_type=$('#robash_s_type').val();

elmDiv='bashro_main_resDiv';
resArr=$('#the_s_arr').val();
resArr=JSON.parse(resArr);
sortRefBy(bs_ob,resArr);
rLen=Number(resArr.length);
numPages=Math.ceil(rLen/bs_pp);
	if(bs_page>numPages){	bs_page=1;	$('#robash_s_page').val($('#robash_s_page option:first').val());	}
numOfOptions='';
	for ( var i = 1; i < (numPages+1); i++ ) {
	numOfOptions+='<option value="'+i+'"';
		if(i==bs_page){numOfOptions+='selected="selected"';}
	numOfOptions+='>'+i+'</option>';
	}
$('#robash_s_page').html(numOfOptions);
resFrom=(bs_page*bs_pp)-(bs_pp-1);
resUp=bs_page*bs_pp;
arrSize=Number(resArr.length);
	if(arrSize<=0){resFrom=0;}
mBack='';
	if(bs_type=='img'){
	mBack+='<div data-pagination="'+bs_pp+'" data-galleryeffectprev="zoomOut" data-galleryeffectnext="zoomIn" data-timing="800" data-delay="60" data-effect="zoomIn" data-thumbgrid="true" style="display: block; height: 264px;" id="thumbGrid">';
	}
countMe=resFrom;
	for (kk in resArr){
		kkN=Number(kk);
		if( kkN+1>=resFrom && kkN<resUp ){
		tmpIconPath=bs_getFileIcon(resArr[kk].file_path);
		tmp_sArr=bs_display_size(Number(resArr[kk].file_size));
		tmp_size=tmp_sArr[0]; size_type=tmp_sArr[1];
		fCatName=resArr[kk].file_category_name;
		if(resArr[kk].file_category_name==''){fCatName='ללא קטגוריה';}
		if(bs_type=='file'){
		mBack+='<div class="dest_file_li" style="line-height:26px; height:26px;" id="bash_res_'+resArr[kk].file_id+'" title="'+resArr[kk].file_display_name+'"><img src="'+bash_gPath+'bash-xtra\/img\/'+tmpIconPath+'" class="bash_fileIcon" \/>'+resArr[kk].file_display_name+' <div class="bs_info_div" >'+resArr[kk].file_date+'<\/div><div class="bs_info_div" >'+fCatName+'<\/div><div class="bs_info_div" >('+tmp_size+' '+size_type+')<\/div><\/div> <div style="text-align:left"><a class="dest_file_li_a" href="'+bash_gPath+'download\/'+resArr[kk].file_path+'" target="_blank">הורדה\\צפייה<\/a><\/div>';	
		}
//		http:\/\/www.itla.org.il\/wp-content\/plugins\/wp-filebase\/wp-filebase_thumb.php?fid='+resArr[kk].file_id+'.png


		else if(bs_type=='img'){
		mBack+='<img class="dest_img_img" src="http:\/\/www.itla.org.il\/wp-content/plugins/wp-filebase/wp-filebase_thumb.php?fid='+resArr[kk].file_id+'.png" alt="'+resArr[kk].file_display_name+'" data-highres="'+bash_gPath+'download/'+resArr[kk].file_path+'" data-caption="'+resArr[kk].file_display_name+'"/>';
				
							
//		mBack+='<div class="dest_file_li" id="bash_res_'+resArr[kk].file_id+'" title="'+resArr[kk].file_display_name+'"><img src="http:\/\/www.itla.org.il\/wp-content\/plugins\/wp-filebase\/wp-filebase_thumb.php?fid='+resArr[kk].file_id+'.png" class="bash_s_ResIMG" \/><div class="bs_info_div" >'+resArr[kk].file_display_name+' <\/div><div class="bs_info_div" >'+fCatName+'<\/div><div class="bs_info_div" >('+tmp_size+' '+size_type+')<\/div><\/div> <div style="text-align:left"><a class="dest_file_li_a" href="'+bash_gPath+'download\/'+resArr[kk].file_path+'" target="_blank">הורדה\\צפייה<\/a>		<\/div>';	
		}
		countMe++;
		}
	}
	resUp_show=resUp;
	if(resUp>arrSize){resUp_show=arrSize;}
		if(bs_type=='img'){
	mBack+='</div>';
	}
runIMG=0;	
xBack='<h3>עמוד:'+bs_page+' | תוצאות: '+resFrom+'-'+resUp_show+'/'+arrSize+'</h3><br /><br /> ';
	if(countMe==resFrom){xBack=+'לא נמצאו תוצאות';}
	else{
	allBack=mBack;
	runIMG=1;
	}
	$('#bashro_resText').html(xBack);
	$('#'+elmDiv).html(allBack);

		if(bs_type=='img'){	jQuery("[data-thumbgrid]").thumbGrid();}
}





function sortRefBy(byW,refArr){
	if(byW=='fileSize'){
		//sort by emploee age
		refArr.sort(function(a, b){
		 return a.file_size-b.file_size;
		})

	}
	else if(byW=='fileSize_big'){
		refArr.sort(function(a, b){
		 return b.file_size-a.file_size;
		})

	}
	else if(byW=='date'){
		refArr.reverse(function(a, b){
		var dateA=new Date(a.file_date), dateB=new Date(b.file_date)
		return dateA-dateB ;//sort by date ascending
		})
	}
	else if(byW=='date_late'){
		refArr.sort(function(a, b){
		var dateA=new Date(a.file_date), dateB=new Date(b.file_date)
		return dateA-dateB ;//sort by date ascending
		})
	}


	else if(byW=='name'){
		refArr.sort(function(a, b){
	 	var nameA=a.file_name.toLowerCase(), nameB=b.file_name.toLowerCase()
			if (nameA < nameB) {//sort string ascending
			return -1;
			}
			if (nameA > nameB){
			return 1;
			}
			else{
			return 0; //default return value (no sorting)
			}
		})
	}
}

function bs_getFileIcon(theName){
	tmpArr=theName.split('.');
	theType=tmpArr[tmpArr.length -1];
	bType={
	pdf:'icon_pdf.gif',
	csv:'icon_csv.gif',
	xlsx:'icon_csv.gif',
	docx:'icon_doc.gif',
	doc:'icon_doc.gif',
	ppt:'icon_ppt.gif',
	pptx:'icon_ppt.gif',
	txt:'icon_text.gif'
	};
		if( theType in bType){ return bType[theType]; }
		else {return 'icon_file.png';}
}
	function bs_display_size(fSize){
	size_type='bytes';		tmp_size='';
		if(fSize<1000){tmp_size=fSize;}
		else if(fSize<1000000){tmp_size=(fSize/1000).toFixed(2); size_type='KB';}
		else{tmp_size=(fSize/1000000).toFixed(2); size_type='MB';}
		return Array(tmp_size,size_type);
	}
	
	
	
	
function bs_getTheO(){
	$.post(
	"http://www.itla.org.il/bash-proce/bash_sProce.php",
	{doW:'get_O',
	the_type:$('#the_s_type').val(),
	the_id:$('#the_s_id').val(),
	the_sDate:$('#the_s_sD').val(),	
	the_fDate:$('#the_s_fD').val()
//	the_pp:$('#robash_s_pp').val(),
//	the_cond:$('#the_s_cond').val(),
	//the_ob:$('#the_s_ob').val(),	
	},
	function(data){
		$('#the_s_arr').val(JSON.stringify(data));	
	},
	'json');
}

jQuery(function($){
        $.datepicker.regional['he'] = {
                closeText: 'סגור',
                prevText: '&#x3c;הקודם',
                nextText: 'הבא&#x3e;',
                currentText: 'היום',
                monthNames: ['ינואר','פברואר','מרץ','אפריל','מאי','יוני','יולי','אוגוסט','ספטמבר','אוקטובר','נובמבר','דצמבר'],
                monthNamesShort: ['ינו','פבר','מרץ','אפר','מאי','יוני','יולי','אוג','ספט','אוק','נוב','דצמ'],
                dayNames: ['ראשון','שני','שלישי','רביעי','חמישי','שישי','שבת'],
                dayNamesShort: ['א\'','ב\'','ג\'','ד\'','ה\'','ו\'','ש\''],
                dayNamesMin: ['א\'','ב\'','ג\'','ד\'','ה\'','ו\'','ש\''],
                weekHeader: 'Wk',
                dateFormat: 'yy-mm-dd',
                firstDay: 0,
                isRTL: true,
                showMonthAfterYear: false,
				minDate:'2014-09-01',
				maxDate:new Date(),				
                yearSuffix: ''
				};
        $.datepicker.setDefaults($.datepicker.regional['he']);
});