var ns  = (document.layers)? true:false; 
var ie4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true:false;
var ie5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true:false;
var ie6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true:false;
var ie = ie4 || ie5 || ie6;
var dom = (document.getElementById) ? true:false;
var splashWin = null;


var Months=new Array("ian","feb","mar","apr","may","iun","iul","aug","sep","oct","nov","dec");
var Days  =new Array("duminică","luni","marţi","miercuri","joi","vineri","sâmbată");


var numb = '0123456789.';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ @._,:"?\'!';
var spc =",._@$%()[]{};<>/ !-:'?*";
var tel = "- ";
var win=null;



var fisierelemele_content     = "<table border='0' width='300' class='newstable' cellpadding='0' cellspacing='0' ><tr><td><img src='http://www.digital-advertising.ro/images/exclam.gif'>&nbsp;<b>despre...</b></td></tr><tr><td style='padding:7px;'>aici puteti gestiona fisierele uploadate de voi, edita, sterge, face upload pe categoriile video si imagine...</td></tr></table>";
var anunturilemele_content    = "<table border='0' width='300' class='newstable' cellpadding='0' cellspacing='0' ><tr><td><img src='http://www.digital-advertising.ro/images/exclam.gif'>&nbsp;<b>despre...</b></td></tr><tr><td style='padding:7px;'>aici puteti gestiona anunturile voastre, modifica, sterge, adauga, prelungi, adauga imagini etc...</td></tr></table>";
var siturilemele_content      = "<table border='0' width='350' class='newstable' cellpadding='0' cellspacing='0' ><tr><td><img src='http://www.digital-advertising.ro/images/exclam.gif'>&nbsp;<b>despre...</b></td></tr><tr><td style='padding:7px;'>aici poti inscrie site-ul tau in directorul Digital Advertising, il puteti promova gratis, si in general poti sa-ti gestionezi toate informatiile legate de site-ul respectiv...</td></tr></table>";
var comentariilemele_content  = "<table border='0' width='300' class='newstable' cellpadding='0' cellspacing='0' ><tr><td><img src='http://www.digital-advertising.ro/images/exclam.gif'>&nbsp;<b>despre...</b></td></tr><tr><td style='padding:7px;'>modific, editez, sau sterg comentariile mele...</td></tr></table>";
var profil_content            = "<table border='0' width='300' class='newstable' cellpadding='0' cellspacing='0' ><tr><td><img src='http://www.digital-advertising.ro/images/exclam.gif'>&nbsp;<b>despre...</b></td></tr><tr><td style='padding:7px;'>aici imi actualizez toate informatiile legate de profilul meu...</td></tr></table>";



function isValid(parm,val) {
  if (parm == "") return true;
  parm = eliminateChar(parm,"\n"); parm = eliminateChar(parm,"\r"); 
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}
 
function isNum(parm) {return isValid(parm,numb);}
function isSpc(parm) {return isValid(parm,spc);}
function isLower(parm) {return isValid(parm,lwr);}
function isUpper(parm) {return isValid(parm,upr);}
function isAlpha(parm) {return isValid(parm,lwr+upr);}
function isAlphaNum(parm) {return isValid(parm,lwr+upr+numb);} 
function isAlphaNumSpec(parm) {return isValid(parm,lwr+upr+numb+spc);} 

function isNumLitere(parm) {return isValid(parm,lwr+upr+numb);} 

function isTelefon(param)  { return isValid(param,numb+tel); }

//--ltrim,rtrim, trim
function ltrim ( s ){return s.replace( /^\s*/, "" );}

function rtrim ( s ){return s.replace( /\s*$/, "" );}

function trim ( s ){return rtrim(ltrim(s));}






function myFormat(num,decimals)
  {
    var numobj=new NumberFormat();  numobj.setNumber(num);  numobj.setCurrency(false); numobj.setPlaces(decimals);
	return numobj.toFormatted();
  }	


function NumberFormat(num)
{
//this.COMMA = ',';
this.COMMA = '';
this.PERIOD = '.';
this.DASH = '-'; 
this.LEFT_PAREN = '('; 
this.RIGHT_PAREN = ')'; 
this.LEFT_OUTSIDE = 0; 
this.LEFT_INSIDE = 1;  
this.RIGHT_INSIDE = 2;  
this.RIGHT_OUTSIDE = 3;  
this.LEFT_DASH = 0; 
this.RIGHT_DASH = 1; 
this.PARENTHESIS = 2; 
this.num;
this.numOriginal;
this.hasSeparators = false;  
this.separatorValue;  
this.inputDecimalValue; 
this.decimalValue;  
this.negativeFormat; 
this.negativeRed; 
this.hasCurrency;  
this.currencyPosition;  
this.currencyValue;  
this.places;
this.setNumber = setNumberNF;
this.toUnformatted = toUnformattedNF;
this.setInputDecimal = setInputDecimalNF; 
this.setSeparators = setSeparatorsNF; 
this.setCommas = setCommasNF;
this.setNegativeFormat = setNegativeFormatNF; 
this.setNegativeRed = setNegativeRedNF; 
this.setCurrency = setCurrencyNF;
this.setCurrencyPrefix = setCurrencyPrefixNF;
this.setCurrencyValue = setCurrencyValueNF; 
this.setCurrencyPosition = setCurrencyPositionNF; 
this.setPlaces = setPlacesNF;
this.toFormatted = toFormattedNF;
this.toPercentage = toPercentageNF;
this.getOriginal = getOriginalNF;
this.getRounded = getRoundedNF;
this.preserveZeros = preserveZerosNF;
this.justNumber = justNumberNF;
this.setInputDecimal(this.PERIOD); 
this.setNumber(num); 
this.setCommas(true);
this.setNegativeFormat(this.LEFT_DASH); 
this.setNegativeRed(false); 
this.setCurrency(true);
this.setCurrencyPrefix('$');
this.setPlaces(2);
}
function setInputDecimalNF(val)
{
this.inputDecimalValue = val;
}
function setNumberNF(num)
{
this.numOriginal = num;
this.num = this.justNumber(num);
}
function toUnformattedNF()
{
return (this.num);
}
function getOriginalNF()
{
return (this.numOriginal);
}
function setNegativeFormatNF(format)
{
this.negativeFormat = format;
}
function setNegativeRedNF(isRed)
{
this.negativeRed = isRed;
}
function setSeparatorsNF(isC, separator, decimal)
{
this.hasSeparators = isC;
if (separator == null) separator = this.COMMA;
if (decimal == null) decimal = this.PERIOD;
if (separator == decimal)
{
this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
}
else
{
this.decimalValue = decimal;
}
this.separatorValue = separator;
}
function setCommasNF(isC)
{
this.setSeparators(isC, this.COMMA, this.PERIOD);
}
function setCurrencyNF(isC)
{
this.hasCurrency = isC;
}
function setCurrencyValueNF(val)
{
this.currencyValue = val;
}
function setCurrencyPrefixNF(cp)
{
this.setCurrencyValue(cp);
this.setCurrencyPosition(this.LEFT_OUTSIDE);
}
function setCurrencyPositionNF(cp)
{
this.currencyPosition = cp;
}
function setPlacesNF(p)
{
this.places = p;
}
function toFormattedNF()
{
var pos;
var nNum = this.num; 
var nStr;            
var splitString = new Array(2);   
nNum = this.getRounded(nNum);
nStr = this.preserveZeros(Math.abs(nNum)); 
if (nStr.indexOf(this.PERIOD) == -1)
{
splitString[0] = nStr;
splitString[1] = '';
}
else
{
splitString = nStr.split(this.PERIOD, 2);
}
if (this.hasSeparators)
{
pos = splitString[0].length;
while (pos > 0)
{
pos -= 3;
if (pos <= 0) break;
splitString[0] = splitString[0].substring(0,pos)
+ this.separatorValue
+ splitString[0].substring(pos, splitString[0].length);
}
}
if (splitString[1].length > 0)
{
nStr = splitString[0] + this.decimalValue + splitString[1];
}
else
{
nStr = splitString[0];
}
var c0 = '';
var n0 = '';
var c1 = '';
var n1 = '';
var n2 = '';
var c2 = '';
var n3 = '';
var c3 = '';
var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
if (this.currencyPosition == this.LEFT_OUTSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c0 = this.currencyValue;
}
else if (this.currencyPosition == this.LEFT_INSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c1 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_INSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n0 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n3 = negSignR;
}
if (this.hasCurrency) c2 = this.currencyValue;
}
else if (this.currencyPosition == this.RIGHT_OUTSIDE)
{
if (nNum < 0)
{
if (this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS) n1 = negSignL;
if (this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS) n2 = negSignR;
}
if (this.hasCurrency) c3 = this.currencyValue;
}
nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
if (this.negativeRed && nNum < 0)
{
nStr = '<font color="red">' + nStr + '</font>';
}
return (nStr);
}
function toPercentageNF()
{
nNum = this.num * 100;
nNum = this.getRounded(nNum);
return nNum + '%';
}
function getRoundedNF(val)
{
var factor;
var i;
factor = 1;
for (i=0; i<this.places; i++)
{	factor *= 10; }
val *= factor;
val = Math.round(val);
val /= factor;
return (val);
}
function preserveZerosNF(val)
{
var i;
val = val + '';
if (this.places <= 0) return val; 
var decimalPos = val.indexOf('.');
if (decimalPos == -1)
{
val += '.';
for (i=0; i<this.places; i++)
{
val += '0';
}
}
else
{
var actualDecimals = (val.length - 1) - decimalPos;
var difference = this.places - actualDecimals;
for (i=0; i<difference; i++)
{
val += '0';
}
}
return val;
}
function justNumberNF(val)
{
val = (val==null) ? 0 : val;
var newVal = val + ""; 
var isPercentage = false;
var isFormattedNeg = false;
if (newVal.indexOf('%') != -1)
{
newVal = newVal.replace(/\%/g, '');
isPercentage = true;
}
if (newVal.indexOf(this.DASH) != -1
|| (newVal.indexOf(this.LEFT_PAREN) != -1 && newVal.indexOf(this.RIGHT_PAREN) != -1))
{
newVal = newVal.replace(/[\-\(\)]/g, '');
isFormattedNeg = true;
}
if (this.inputDecimalValue != this.PERIOD)
{
newVal = newVal.replace(/\./g, '');
}
var itrDecimal;
var tempVal = '';
var foundDecimal = false;
for (itrDecimal=0; itrDecimal<newVal.length; itrDecimal++)
{
if (newVal.charAt(itrDecimal) == this.inputDecimalValue)
{
if (foundDecimal)
{
}
else
{
tempVal = tempVal + this.PERIOD;
foundDecimal = true;
}
}
else
{
tempVal = tempVal + newVal.charAt(itrDecimal);
}
}
newVal = tempVal;
if (isFormattedNeg) newVal = '-' + newVal;
if (isNaN(newVal))
{
newVal = parseFloat(newVal.replace(/[^\d\.\-]/g, ''));
newVal = (isNaN(newVal) ? 0 : newVal); 
}
else if (!isFinite(newVal))
{
newVal = 0;
}
if (isPercentage)
{
newVal = newVal / 100;
}
return newVal;
}


function isNumeric(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var xChar;
   var pointCounters = 0;
   var i;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      xChar = sText.charAt(i); 
      if (ValidChars.indexOf(xChar) == -1) 
         {
         IsNumber = false;
         }
	  if (xChar == '.') pointCounters++;
      }
   if (pointCounters > 1) IsNumber = false;    
   return IsNumber;   
}



function eliminateChar(mystring,whatChar){
var source=mystring;
var destination="";
var i;
for(i=0;i<source.length;i++){
      destination+=(source.charAt(i)!= whatChar ? source.charAt(i) : "");
   }
return destination;
}


function addSlashes(mystring,whatChar){
var source=mystring;
var destination="";

var i;
for(i=0;i<source.length;i++){
      destination+=( source.charAt(i)!= whatChar ? source.charAt(i) : ("\\")+source.charAt(i) );
   }


return destination;
}




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;
}

function getDataEng(){
   var today = new Date();
   return Days[today.getDay()]+' '+today.getDate()+' '+Months[today.getMonth()]+' '+today.getYear();
}


function dynamiccontent(elementid,content){
  /*
   * minunata functie pentru schimbarea dinamica a continutului unei div, td, span sau orice alt dhtml object 
   */
  if(document.all){
     document.getElementById(elementid).innerHTML=content
  }
  else{
             if (document.getElementById && !document.all){
                rng = document.createRange();
                el = document.getElementById(elementid);
                rng.setStartBefore(el);
                htmlFrag = rng.createContextualFragment(content);
                while (el.hasChildNodes()) el.removeChild(el.lastChild);
                el.appendChild(htmlFrag);
            }
  }
}


function zwindow(source,name,width,height,nHow)
{
  /*
  nHow == 0 - centered;
  nHow == 1 - up left
  */
  var screenWidth,screenHeight,splashWin; 
  screenWidth  = screen.availWidth;
  screenHeight = screen.availHeight;  
  if(nHow == 0)
  {
    if(ie||dom) { splashWin = window.open(source,name, "width="+width+",height="+height+",left="+(screenWidth-width)/2+",top="+(screenHeight-height)/2+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
    if(ns) { splashWin = window.open(source,name, "width="+width+",height="+height+",screenX="+(screenWidth-width)/2+",screenY="+(screenHeight-height)/2+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
  }
  if(nHow == 1)
  {
    if(ie||dom) { splashWin = window.open(source,name, "width="+width+",height="+height+",left=7,top=18,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
    if(ns) { splashWin = window.open(source,name, "width="+width+",height="+height+",screenX=0,screenY=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0" ); }
  }
  splashWin.focus();
}





String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 

// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 

// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 

// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}



function showhide(id,what){
   if(what == "show"){
      document.getElementById(id).style.visibility = 'visible';
   }
   else{
      document.getElementById(id).style.visibility = 'hidden';
   }
}



function fromCRLF(mystr){
	/*
	*  face pereche cu functia php toCRLF si readuce stringul dorit la forma in care am secventa \r\n  reinserata in locul xcrlfx
	*/
	return mystr.replace(/(xcrlfx)/g, "\r\n");
}



function  clearBadChars($xstring){
   /*
    * curata de ghilimele si slashuri
	*/
   $xstring = $xstring.replace(/(\")/g, " ");
   $xstring = $xstring.replace(/(\')/g, " ");
   $xstring = $xstring.replace(/(\\)/g, "/");
 //$xstring = $xstring.replace(/(\/)/g, " ");
  return $xstring;
}




function  getWidthHeight(what) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(what=='w')return myWidth;
  if(what=='h')return myHeight;
  return -1;
}


function maximizeWindow(){
   top.window.moveTo(0,0);
   if (document.all) {
   top.window.resizeTo(screen.availWidth,screen.availHeight);
   }
   else if (document.layers||document.getElementById) {
      if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
      top.window.outerHeight = screen.availHeight;
      top.window.outerWidth = screen.availWidth;
      }
   }
}









