Array.prototype.add = function (f) {
    var kas = this.length;
    this[kas] = f;
}
function obg(object){
    
    /*   
if(object){
        for (var i in object) {
       if(typeof(i)=="string"){
        this[i] =  object[i];
       }
        
        }
  
}else{
  return false;
}
  */   
         this['src'] = object.src;
         

}

obg.prototype.checkload = function(callback){

         var src =this.src; 
        // debug('we start loaded');
         var newImage = document.createElement('img');
             newImage.src = this.src;
             
         if(navigator.appName=='Microsoft Internet Explorer'){
               if(parseInt(newImage.width)>0 && parseInt(newImage.height)>0){
                //debug('ie loaded');
              setTimeout(callback,10);
                
                  return true;                
               }
           }
           
           
          if(newImage.complite){
         // debug('we start complite');
          setTimeout(callback,10);
          
              return true;
          }else{
              newImage.onload = function (){
               //  debug('we  loaded');
                 setTimeout(callback,10);
              
                return true;
             }
          
          }
          
          
               if(parseInt(newImage['naturalWidth'])>0 && parseInt(newImage['naturalHeight'])>0){
                //debug('ie loaded');
              setTimeout(callback,10);
                
                  return true;                
               }
           
    
}


function checkLoad (object){
   if(object){
        var rt = new obg(object);
        return (rt.checkload()); 
   }else{
    return false;
   }
}

function resize(startWidth,startHeight,maxWidth,maxHeight){
         maxWidth = (maxWidth)? maxWidth : 150;
         maxHeight = (maxHeight) ? maxHeight : 150;    
        var newWidth = parseInt(startWidth);
        var newHeight = parseInt(startHeight);
        if(startWidth>maxWidth){
            newHeight  = (maxWidth/startWidth)*startHeight;
            newWidth = maxWidth;
        }
        
        
    
       
       
        if(newHeight>maxHeight){
            newWidth  = (maxHeight/newHeight)*newWidth;
            newHeight = maxHeight;
        }
       
        newWidth  = parseInt(newWidth);
        newHeight = parseInt(newHeight);
        return new Array(newWidth,newHeight)
    }

function debug(text,restart){
  var debugId = "debug-liga13";
  var doci = document.getElementById(debugId);
  
  if(doci){
    if(restart==true){
      doci.innerHTML = '';
    }
    doci.innerHTML += text+'<br />';
  
  }else{
    var divva = document.createElement('div');
        divva.id = debugId;
        divva.style.position="fixed" ;
        divva.style.top="10px" ;
        divva.style.right="10px" ;
        divva.style.display="block" ;
        divva.style.color="red" ;
        divva.style.border="2px dashed" ;
        divva.style.fontSize="16px" ;
        divva.style.zIndex="654654684687684" ;
        
    document.body.appendChild(divva);
      debug(text,restart);
  }

}



function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}


function setFormValue(t,def,action){
    switch(action){
        case 'near':
     
            if(trim(t.value)==def || trim(t.value)==''){
                t.value=def;
            }else{
                t.value=t.value;
            }

        break;
        
        default:
            if(trim(t.value)==def || trim(t.value)==''){
                t.value='';
            }else{
                t.value=t.value;
            }        
        break;
    }
}



function isEmail(value) {
  
  var re = /^\w+([\.-]?\w+)*@(((([a-z0-9]{2,})|([a-z0-9][-][a-z0-9]+))[\.][a-z0-9])|([a-z0-9]+[-]?))+[a-z0-9]+\.([a-z]{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/i;
    

  if(re.test(value))
    return true;
  else {
    
    return false;
  }
}


    
    