﻿/// <reference path="core.js"/>
var loader;
var CoreXML = XML;
var XML = function(s,d,onload){
	var l;
	if(window.Loader){
		l = new Loader();
		l.Show();
	}
	var newLoad = function(doc){
		if(doc.nodeName=="AccessDenied"){
			redirectLogin();
		}else{		
			onload(doc);
			if(l)l.Hide();
		}		
	}
	CoreXML(s,d,newLoad,alert);	
}
function redirectLogin(){
	alert("עליך להתחבר למערכת");	
	document.location.href="../"
}
function Loader(){	
	var loader;
	this.Show = function(){		
		loader = document.body.appendChild(DOM.Create("div","Loader","טוען..."));
		loader.style.top = document.documentElement.scrollTop;		
	}
	this.Hide = function(){		
		if(loader)document.body.removeChild(loader);		
	}
}
DOM.FilterInput = function(i,fString){
	i.onkeypress = function(){
		if(!window.event) return true;
		var e = event;
		if(fString.indexOf(String.fromCharCode(e.keyCode))<0) return false;
	}
}
function formatSecs(secs){
	secs = Number(secs);
	var minutes = Math.floor(secs/60);
	var seconds = secs - (minutes*60);
	seconds = (seconds>9)? seconds:"0" + seconds;	
	return(minutes + ":" + seconds);
}
function formatDateTime(str){
	if(!str) return null;
	var d = new Date(str);
	var time = (d.getMinutes()>9)? d.getHours() + ":" + d.getMinutes() : d.getHours() + ":0" + d.getMinutes();
	var date = String(d.getDate()) + "/" + String(d.getMonth()+1) + "/" + String(d.getFullYear());
	return(date + " " + time);
}
function formatDate(str){
	if(!str) return null;	
	var d = new Date(str);
	var date = String(d.getDate()) + "/" + String(d.getMonth()+1) + "/" + String(d.getFullYear());
	return(date);
}
function formatTime(str){
	if(!str) return null;	
	var d = new Date(str);
	var time = (d.getMinutes()>9)? d.getHours() + ":" + d.getMinutes() : d.getHours() + ":0" + d.getMinutes();
	return(time);
}
function openWindow(href,name,width,height,scroll){
	var left = screen.width>width? (screen.width-width)/2:0;
	var top = screen.height>height? (screen.height-height)/2:0;
	if(width>screen.width || height>screen.height) scroll = true;
	if(width>screen.width) width = screen.width;
	if(height>screen.height) height = screen.height;	
	scroll = (scroll==true)? "yes":"no";
	return window.open(href,name,"top="+top+",left="+left+",width="+width+",height="+height+",scrollbars="+scroll);	
}