// Variables
var months_ro = new Array("Ianuarie","Februarie","Martie","Aprilie","Mai","Iunie","Iulie","August","Septembrie","Octombrie","Noiembrie","Decembrie");
var days_ro = new Array("Duminic&#259;","Luni","Mar&#355;i","Miercuri","Joi","Vineri","S&#226;mb&#259;t&#259;");
var months_en = new Array("January","February","March","Aprili","May","June","July","August","September","October","November","December");
var days_en = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

// cross-browser for getElementById
function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

// Function which validates an email address
function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

//function which blocks input to a restricted list of characters
function restrictInput(myfield, e, dec, char, special)
{
	var key;
	var keychar;
	var digits = String("0123456789");
	var letters = String("abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ");
	
	if (window.event)
		 key = window.event.keyCode;
	else if (e)
		 key = e.which;
	else
		 return true;
	keychar = String.fromCharCode(key);
	
	chars = digits;
	
	if(char)
		chars += letters;
	
	if(special)
		chars += special;
	
	// return
	if(key==13)
		return true;
	// control keys
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==27))
		return true;
	// numbers & special chars
	else if((chars.indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if(dec && (keychar == ".") && myfield.value.indexOf(".") == -1)
		return true;
	else
		return false;
}

// Function which disables right click button
function nocontextmenu()  
{
 event.cancelBubble = true
 event.returnValue = false;
 
 return false;
}

// Function which disables right click button
function norightclick(e) 
{
 if (window.Event) 
 {
  if (e.which == 2 || e.which == 3)
   return false;
 }
 else
  if (event.button == 2 || event.button == 3)
  {
   event.cancelBubble = true
   event.returnValue = false;
   alert("Copyright MaxyGo 2005-2009\n       office@mgb.ro");
   return false;
  } 
}

// Function which converts a number below 10 in a two digit number (ex: 9 -> 09)
function leadingZero(nr)
{
  return nr < 10 ? "0"+nr : nr;
}

// Function which constructs the date&time displayed
function getDateTime() {
  var currDate = new Date();
  dateDisplay = days_ro[currDate.getDay()]+
    ", "+leadingZero(currDate.getDate())+
    " "+months_ro[currDate.getMonth()]+
    " "+currDate.getFullYear()+
    " | "+leadingZero(currDate.getHours())+":"+
    leadingZero(currDate.getMinutes())+":"+
    leadingZero(currDate.getSeconds())+"&nbsp;&nbsp;";
  return dateDisplay;
}

// Function which displays and updates the date&time
function putDate() {
  displayDate = getDateTime();
  xGetElementById('date-time').innerHTML=displayDate
  setTimeout("putDate()",1000);
}

// function which returns the flash object by name
function getFlashMovieObject(movieName)
{
	if (window.document[movieName]){
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet") == -1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  } else {
    return document.getElementById(movieName);
  }
}

// function which sends commands to flash object
function SendDataToFlashMovie(obj,nr)
{
	var flashMovie = getFlashMovieObject(obj);
	flashMovie.SetVariable("/:butonApasat", nr);
	flashMovie.GotoFrame(2);
}

// function which validates the logon form
function checkLogin(obj){
  if(obj.user.value == "" || obj.pass.value == ""){
    alert("Datele de autentificare sunt obligatorii !");
    obj.user.focus();
    return false;
  }
  return true;
}

// function popUp
function popUpWin(url,winName,features){
	window.open(url,winName,features);
}

function checkSearchBox(f){
	if(f.search.value == ""){
		alert("Nu ati completat nimic in campul de cautare !");
		f.search.focus();
		return false;
	}
	return true;
}

function getPage(tip){
	document.location = 'index.php?page=admin-'+tip;
}

function export2excel(tip){
	popUpWin('export2excel.php?type='+tip,'','scrollbars=yes,width=340,height=200');
}