/** EXPLODE function as in PHP ***************************************************************************/
function explode(delimit, subject){
  var rezult  = new Array();
  var valoare = '';
  var i = 0;
  var j = 0

  while (i<subject.length) {
	if ( subject.substring(i,i+delimit.length) == delimit ) {
      rezult[j] = valoare;		j++;
	  valoare = '';				i+=delimit.length;
	} else { valoare = valoare + subject.charAt(i);		i++; }
	if (valoare!='') { rezult[j] = valoare; } 
  }
  return rezult;
}

//-- in_array function as in PHP  -----------------------------------------------------------------------
function in_array(needle, haystack){
  for (ii=0; ii<haystack.length; ii++) { if (haystack[ii] == needle) { return true; } }
  return false;
}

//-- Roll-over pentru imagine menu  ---------------------------------------------------------------
function changeImage(idImage,Img) {
  document.all(idImage).src = ServerAddress + '/files/_file_' + Img;
}

//-- Eveniment pentru menu  ------------------------------------------------------
function onMouseEvent(idImage, srcIcon) { 
  document.all(idImage).src = srcIcon;
}

//-- Verificare adresa e-Mail  -------------------------------------------------------------------------
 function emailCheck (emailStr) {
    var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)

	if (matchArray==null)	{return false}

	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null)	{return false}

	var IPArray=domain.match(ipDomainPat)

	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
		  if (IPArray[i]>255) {return false}
		}
		return true
	}

	var domainArray=domain.match(domainPat)

	if (domainArray==null)	{return false}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length

	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{return false}

	if (len<2)	{return false}

	return true;
 }

//-- Elimina spatiile  ---------------------------------------------------------------------------------
 function trim(Key) {
     while(''+Key.charAt(Key.length-1)==' ') { Key=Key.substring(0,Key.length-1); }
     return Key;
 }

//-- Roll-over pentru imagine menu  --------------------------------------------------------------------
function changeImage(idImage,Img) {
  document.all(idImage).src = ServerAddress + '/files/_file_' + Img;
}

//-- Open a modal window with a thumbnail --------------------------------------------------------------
function openPicture(path, w, h, title, cloz){
  if (self.popWin != null && !self.popWin.closed) { self.popWin.close(); }

  urlText = '';
  if (arguments.length>5) { urlText = '&nbsp;<a href="'+ arguments[5] +'" class="link_1">'+ arguments[5] +'</a>'; }

  w = w<110 ? 110 : w;
  h = h<130 ? 130 : h;

  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h-20) / 2;

  popWin = window.open("","popWin","top="+wint+",left="+winl+"scrollbars=1,width="+ w + ",height=" + parseInt(parseInt(h)+20));

  srcHTML = '<html>\n';
  srcHTML+= ' <head><title>'+title+'</title></head>\n';
  srcHTML+= ' <link href="'+ServerAddress+'/style_site.css" rel="stylesheet" type="text/css">\n';
  srcHTML+= ' <bod' + 'y bgcolor="#E8E8E8" leftmargin="0" topmargin="0" marginwidth="0" scroll="no">\n';
  srcHTML+= '  <table border=0 cellpadding=0 cellspacing=0 align=center height=100% width=100%>\n';
  srcHTML+= '   <tr><td align="center" colspan=2 height='+parseInt(h-18)+' bgcolor=white><img src="'+ path + '" border="0"></td></tr>\n';
  srcHTML+= '   <tr><td width=50% height=18>'+urlText+'</td><td align="right" width=50%><a href="javascript:window.close(self);" class="link_1"><b>'+l_Close+'</b></a></td></tr>\n';
  srcHTML+= '  </table>\n';
  srcHTML+= '  <script language="JavaScript">this.focus();</script>\n';
  srcHTML+= ' </body>\n';
  srcHTML+= '</html>';

  popWin.document.open();
  popWin.document.clear();
  popWin.document.write(srcHTML);
  popWin.document.close();
}

function openEcPicture(path, w, h, title,cloz,product,bgcolor,classtext,bgtop,bgbottom,classlink)
{
  if (self.popWin != null && !self.popWin.closed) { self.popWin.close(); }
	
  w = w<210 ? 210 : w;
  h = h<230 ? 230 : h;

  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h-20) / 2;

  popWin = window.open("","popWin","top="+wint+",left="+winl+"scrollbars=1,width="+ w + ",height=" + parseInt(parseInt(h)+40));

  srcHTML = '<html>\n';
  srcHTML+= ' <head><title>'+title+'</title></head>\n';
  srcHTML+= ' <link href="'+ServerAddress+'/style_site.css" rel="stylesheet" type="text/css">\n';
  srcHTML+= ' <bod' + 'y bgcolor="'+bgcolor+'" leftmargin="0" topmargin="0" marginwidth="0" scroll="no">\n';
  srcHTML+= '  <table border=0 cellpadding=0 cellspacing=0 align=center height=100% width=100%>\n';
  srcHTML+= '   <tr><td bgcolor="'+bgtop+'" height=18><font class='+classtext+'>&nbsp;'+product+'</font></td></tr>\n';
  srcHTML+= '   <tr><td align="center" height='+parseInt(h)+'><img src="'+ path + '" border="0"></td></tr>\n';
  srcHTML+= '   <tr><td bgcolor="'+bgbottom+'" align="right" height=18><a href="javascript:window.close(self);" class='+classlink+'><b>'+l_Close+'</b></a>&nbsp;</td></tr>\n';
  srcHTML+= '  </table>\n';
  srcHTML+= '  <script language="JavaScript">this.focus();</script>\n';
  srcHTML+= ' </body>\n';
  srcHTML+= '</html>';

  popWin.document.open();
  popWin.document.clear();
  popWin.document.write(srcHTML);
  popWin.document.close();
}

var numLayer=0;
var timerLayer;
var TheLayer = new Array();
var nameLayer = '';

function CMS_MenuHide() 
{ 
  timerLayer = setTimeout('CMS_MenuShow()', 300);
}

function CMS_MenuShow() 
{
  if ( timerLayer )  { clearTimeout(timerLayer); }
  for(menu=0; menu<TheLayer.length; menu++) 
  { 
	if ( thaLayer=document.all(TheLayer[menu]) ) { 
	 if (thaLayer.style) {thaLayer.style.visibility = 'hidden';}
	}
  }
  if ( arguments.length>0) 
  {
	for(i=0; i<arguments.length; i++) { 
		nameLayer=document.all(arguments[i]); 
  	    if (thaLayer=document.all(arguments[i])) thaLayer.style.visibility = "visible"; 
    }
  }//if
}

function CMS_MenuClear() {	
  if ( timerLayer )  { clearTimeout(timerLayer); }	
}

function CMS_clearPage(link)
{
	document.open();document.write('');document.close();
	document.location=link;
}

function LimitTo(object, size) {
  valoarea     = object.value;
  if ( valoarea.length>size ) object.value = valoarea.substring(0,size)
}

function openWindow(){
  window.open(arguments[0], "popupwin", arguments[2]);
}

function  CMS_CheckSearch(key) 
{
	search=trim(key.value);
	if ((search=='') || (search.length<3))
	{key.focus();return false;}
}
function  CMS_CheckMaillist(mail,error,succes) 
{
	if ((trim(mail.value)=='') || (!emailCheck(mail.value))) 
	{
		mail.focus();alert(error);return false;
	}
	else {
		alert(succes);return true;
	}
}


function checkDate(obj) {
	//tolgo i puntini
	arrDataSenzaSlash	= obj.value.split("/");
	DataSenzaSlash		= arrDataSenzaSlash.join("");
	//separo le cifre
	arrCifre = DataSenzaSlash.split("");
	//leggo l'array inserendo gli slash ogni due cifre
	DataConSlash = "";
	NCifra = 0;
	NSlash = 0;
	for (x=0; x<8; x++) {
		//controllo che sia una cifra
		if ((arrCifre[x] >=0) && (arrCifre[x] != " ")) {
			if ((x==0) && (arrCifre[x] > 3)) arrCifre[x]=0
			if ((x==1) && (arrCifre[0] == 3) && (arrCifre[x] > 1)) arrCifre[x]=0
			if ((x==2) && (arrCifre[x] > 1)) arrCifre[x]=0
			if ((x==3) && (arrCifre[2] == 1) && (arrCifre[x] > 2)) arrCifre[x]=0
			if ((x==4) && (arrCifre[x] > 2)) arrCifre[x]=2
			DataConSlash += arrCifre[x];
			NCifra++;
		}
		//inserisco lo slash ogni due cifre (solo i primi due)
		if ((NCifra == 2) && (x<arrCifre.length-1) && (NSlash < 2))  {
			DataConSlash += "/";
			NSlash++;
			NCifra = 0;
		}
	}
	//una volta compilata la stringa di output, la mostro
	obj.value = DataConSlash;
}
function popupShow(id, nr) { 
  if (nr==1) newPopup = document.getElementById("open_"+id);
   else newPopup = document.getElementById("close_"+id);

  if (nr==0){
	if (document.all('frm_'+id)) {
	  document.all('frm_'+id).style.height_ = document.all('frm_'+id).style.height;
	  document.all('frm_'+id).style.height  = 18; 
	}
  } else if (document.all('frm_'+id)) {
	  document.all('frm_'+id).style.height = document.all('frm_'+id).style.height_;
  }
  document.all(id).innerHTML = newPopup.innerHTML; 
}

function popupClose(id) {
  if (document.all('frm_'+id)) { document.all('frm_'+id).style.visibility = 'hidden'; }
  document.all(id).innerHTML = ''; 
  document.all(id).style.visibility = 'hidden'; 
}

function correctTime(hours, minutes, secs) {
  var hour    = hours;
  var minutes = minutes;
  var seconds = secs;

  if (seconds>=60) {
	min     = parseInt(seconds/60);
	minutes = minutes + min;
	seconds = seconds - min*60;
  }

  if (minutes>=60) {
  	minutes = minutes - 60;
	hour	= hour + 1;
  } else if (minutes<0) {
  	minutes = 60 + minutes;
	hour	= hour - 1;
  }

  if (hour>23) { hour = hour - 24; }

  hour    = (hour<0) ? 24 + hour		 : hour;
  hour    = (hour<10) ? '0' + hour		 : hour;
  minutes = (minutes<10) ? '0' + minutes : minutes;
  seconds = (seconds<10) ? '0' + seconds : seconds;

  return hour + ':' + minutes + ':' + seconds;
}

function UpdateClock() { 
  if(clockID) { clearTimeout(clockID); clockID = 0; }
  if (tm_names.length==0) { } else {
	_secs   = _secs + 1; 
	the_poz = 0;

	for (i=0; i<tm_names.length; i++) {
	  hr = tm_diff[the_poz]; the_poz = the_poz+1;
	  mn = tm_diff[the_poz]; the_poz = the_poz+1;
	  document.getElementById(tm_names[i]).innerHTML = correctTime(_hour + hr, _mins + mn, _secs);
	}
	
	clockID = setTimeout('UpdateClock()', 1000);
  }
}