/*
// Ляв трим
function ltrim(strvalue){
var field=strvalue;
var i,ch;
var ck=-1;
var len = field.length;

for (i=0; i< len; i++)
{
  ch=field.indexOf(' ',i);
  if (ch==-1)
    {
       if (i==0)
        {
         ck=-1;
        }	
	   break;
    }
   if (ch>i)
    {
      break;
    }
   ck=ch;    
 } // end for (i=0; i< len; i++)
 
if (ck>-1)
{
   field=field.substring(i);
}

strvalue=field;
return field;
} // end function ltrim


// Десен трим
function rtrim(strvalue){
var field=strvalue;
var i,ch;
var ck=-1;
var len = field.length;

for (i=len-1; i>0; i--)
{
  ch=field.lastIndexOf(' ',i);
  
  if (ch==-1)
    {
     if (i==len-1)
      {
       ck=-1;
      }
	  break;
     } // if (ch==-1)
  
  if (ch<i)
   {
     break;
   }
   ck=ch;    
 } // for (i=len-1; i>0; i--)
  
if (ck>-1)
 {
   i++;
   field=field.substring(0,i);
 }

strvalue=field;
return field;
} // end function rtrim(...)

// Пълен трим - първо ляв, после десен
function StringTrim(strvalue)
{
strvalue=ltrim(strvalue);
return rtrim(strvalue);
} // end function StringTrim(...)

// Проверка за цифри
  function CheckForIntegers(theObject){
  var checkOK = "0123456789";
  var checkStr = StringTrim(theObject.value);
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
   
  if (!allValid)
  {
    alert("Моля, въвеждайте само цифри в полето!");
    theObject.select();
    theObject.focus();
    return (false);
  }
  return true;
  }

// Проверка на дата
function CheckDate(theObject){

var i,ch,day,mounth,year,len;
//var osigdateformvariant=2000;
var LObject=theObject;
var LDate = LObject.value;

if (StringTrim(LDate)==''){
	return(true);
	}

i=LDate.indexOf('/',0);
 
if ((i<1) || (i>2)){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}
 
day=LDate.substring(0,i);

if ((day<01) || (day>31)){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}

i=LDate.indexOf('/',day.length+1);
 
if ((i<3) || (i>5)){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}
 
mounth=LDate.substring(day.length+1,i);

if ((mounth<1) || (mounth>12)){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}


year=LDate.substring(day.length+1+mounth.length+1,LDate.length);

var d = new Date();
var y;
y = d.getYear();

//if ((year<osigdateformvariant) || (year>y)){
//	alert('Невалидна дата!');
//	LObject.focus();
//	return(false);
//}

var y = new Date();
y=d;
y.setFullYear(year,mounth-1,day);

if (y>d) {
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}
 
var ml;
ml=y.getMonth();
ml++;

if (ml!=mounth){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}

ml=y.getDate();

if (ml!=day){
	alert('Невалидна дата!');
	LObject.focus();
	return(false);
}

return(true);
}
*/


//////////////////////////////////////////// NEW  //////////////////////////////////////////////////////

function messageWindow(title, msg)
{
  var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Close   " onClick="self.close()"></form>';
  msgWindow.document.write(head + body);
}

function newWindow(title, url)
{
  var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  msgWindow.document.location=url;
}


function newWindow(title, url,height,width)
{
 // var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  msgWindow.document.location=url;
}

function newWindowScrDown(title, url,height,width)
{
 // var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var title2 = 'w'+Math.random();
  title2='w'+title2.substr(4);
  var msgWindow = window.open("",title2, styleStr);
  //var msgWindow = window.open("","novina", styleStr);

  msgWindow.document.location=url;
}
function newWindowScrDownAAA(title, url,height,width)//(winname,pn)
{
 // if ( document.showpicts )
 //   {
      var msgWindow=window.open('',title,'width=680,height=655,toolbar=0,menubar=0,scrollbars=1,status=0,resizable=1,screenx=225,screeny=230');
 //     document.showpicts.pn.value=pn;
 //     document.showpicts.submit();
 msgWindow.document.location=url;
 //   }
}

function resetAndClose()
{
  window.opener.location.reload();
  window.setTimeout('window.close()',10);
}

function newWindow(title, url)
{
 // var width="300", height="125";
  var left = screen.width-250;
  var top = screen.height-200;
  var styleStr = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width='+left+',height='+top+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var title2 = 'w'+Math.random();
  title2='w'+title2.substr(4);
  var msgWindow = window.open("",title2, styleStr);
  //var msgWindow = window.open("","novina", styleStr);

  msgWindow.document.location=url;
}

