function dcolor(id) {              
    l_bk = document.getElementById(id).style.background ;
    document.getElementById(id).style.background= '#FFFF00';
}

function dcolor_none(id) {
    document.getElementById(id).style.background= l_bk;
}

//open popup window
function winOpen(url, name, width, height)
{   
    var settings    = 'width=' + width + ',height=' + height + ',left=100,top=150,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes'; 
    window.open(url, name, settings);
}

//slide dowd
function slideDown(div, pos)
{
var div_left = document.getElementById(div).offsetHeight;
//alert (div_left);
if (div_left < pos){
document.getElementById(div).style.height = div_left + 10 + "px";
setTimeout("slideDown('"+div+"', '"+pos+"')",10)
}
}

function slideUp(div, pos)
{
var div_left = document.getElementById(div).offsetHeight;
if (div_left > pos){
document.getElementById(div).style.height = (div_left - 10) + "px";
setTimeout("slideUp('"+div+"', '"+pos+"')",10)
}
}

function setThumbScrool() {
   el = document.getElementById('t_box');
   if (el) {                                           
      document.getElementById('thum_box').scrollLeft = el.offsetLeft - 215;
      
   }
}



function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 10);
    }
  }
}

function GeneratePassword() {
    
    var length=8;
    var sPassword = "";
    
    for (i=0; i < length; i++) {
    
        numI = getRandomNum();
        while (checkPunc(numI)) { numI = getRandomNum(); } 
        
        sPassword = sPassword + String.fromCharCode(numI);
    }
    
    document.getElementById('paswd').value = sPassword;
}

function getRandomNum() {
        
    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000    
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127        
    rndNum = (rndNum % 94) + 33;

    return rndNum;
}

function checkPunc(num) {
    
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }    
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    
    return false;
}

/*------------------------- AJAX ---------------------*/

// ajax results
function getXmlTagContentFromText(pTag,pText) {
 var start=pText.indexOf('<'+pTag);
 if ( start > -1 ) {
  start+=pTag.length+2;
  }
 else {
  return('');
  }
 var end=pText.lastIndexOf('</'+pTag);
 var res=pText.substring(start,end)
 return res;
 }

function alertContents() {
   if (http_request.readyState == 4) {
      if (http_request.status == 200) {
         //alert(http_request.responseText);
         result = http_request.responseText;
         writeResults(result);
         //document.getElementById('myspan').innerHTML = result;            
      } else {
         alert('There was a problem with the request.');
      }
   }
}


function writeResults(result) {
  var msg_text = getXmlTagContentFromText('new_msg',result);
   if (msg_text != '') {
       document.getElementById('new-msg').style.display = 'block'; 
       document.getElementById('new-msg').innerHTML = msg_text;
   }
}
