﻿var currrow
	
//positining functions	
function getRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
    alert(yPos);
}	
	
function rollover(img, onoff, permanent) {
    str = img.src
    if (onoff) {
        if (str.indexOf('.jpg') >0) {
            str = str.substring(0,str.length-4) + 'b.jpg'
        } else {
            str = str.substring(0,str.length-4) + 'b.gif'
        }
    } else {
        if (str.indexOf('.jpg') >0) {
            str = str.substring(0,str.length-5) + '.jpg'
        } else {
            str = str.substring(0,str.length-5) + '.gif'
        }
    }
    img.src = str
    if (permanent) {
        img.onmouseover = function() {}
        img.onmouseout = function() {}
    }
    
    
}	
	
function addLoadEvent(func) {
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
	
function removeRow(tbl) {
    tbody = document.getElementById(tbl);
    tbody = tbody.getElementsByTagName("tbody")[0];
            
    if (currrow > 0) {
        tbody.removeChild(tbody.getElementsByTagName("tr")[currrow])
    }                    
    currrow = -1   
}		
	

function loadRow(tmpStr, tbl, cls,  rnum, cnum, remove, no_remove) {
    tbody = document.getElementById(tbl);
    tbody = tbody.getElementsByTagName("tbody")[0];
            
    if ((currrow > 0) && (remove)) {
        tbody.removeChild(tbody.getElementsByTagName("tr")[currrow])
    }                    
    trow = tbody.getElementsByTagName("tr")[rnum + 1];                
    
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    row.appendChild(td1);
    td1.innerHTML = tmpStr        
    td1.colSpan = cnum
    td1.className = cls

    if ((rnum + 1) == (tbody.getElementsByTagName("tr").length)) {
       tbody.appendChild(row);
    } else {
        tbody.insertBefore(row,trow);
    }
    
    if (no_remove) {
        currrow = -1   
    } else {
        currrow = rnum + 1 
    }
}	

function row_class_change(tbl, cls,  rnum, bgcolor) {
    tbody = document.getElementById(tbl);
    tbody = tbody.getElementsByTagName("tbody")[0];
              
    trow = tbody.getElementsByTagName("tr")[rnum + 1];                
    trow.className = cls
    
    if (bgcolor) {
        tds = trow.getElementsByTagName("td")
        for (var x = 0; x <= tds.length - 1; x++) {
            tds[x].style.backgroundColor = bgcolor
        }
    }
}	


function showCaption(id, onoff) {
	if (navigator.userAgent.indexOf("Safari") > 0) {return}
	
    cap = document.getElementById(id)
    if (onoff) {
        cap.style.display = 'block';
        cap.style.margin = '-' + (cap.scrollHeight - 0) + 'px 0px 0px 0px';
        cap.className = 'media_object_caption';
    } else {
        cap.style.display = 'none';
    }
}

function obscure_email(fp,sp) {
    document.write ('<a href="mailto:' + fp + '@' + sp + '">' + fp + '@' + sp + '</a>')
}
	

var anim_timer
function animate(onOrOff,itm) {
	button = document.getElementById(itm)

	if (parseInt(button.style.top) < 0) {
		anim_timer = window.setTimeout("moveItem(1,'" + itm + "')", 0, "JavaScript");
	} else {
		anim_timer = window.setTimeout("moveItem(0,'" + itm + "')", 0, "JavaScript");
	}
}

function moveItem(onOrOff,itm) {
	button = document.getElementById(itm)

	if (onOrOff == 1) {

		if (parseInt(button.style.top) < 220) {
			button.style.top = parseInt(button.style.top) + 10 + 'px';
			anim_timer = window.setTimeout("moveItem(1,'" + itm + "')", 0, "JavaScript");
		}
	} else {
		if (parseInt(button.style.top) > -500) {
			button.style.top = parseInt(button.style.top) - 10 + 'px';
			anim_timer = window.setTimeout("moveItem(0,'" + itm + "')", 0, "JavaScript");
		}
	}
}

function append_action (str) {
    document.forms[0].action = str
}

function popup_window(url,h,w) {
    var aw, aah
    aw = screen.availWidth;
    ah = screen.availHeight;

    var popW = w, popH = h;
    var leftPos = (aw-popW)/2, topPos = (ah-popH)/2;
    window.open(url,'popup','scrollbars=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}

function CharacterCount(a,b){
	var c = a.length;
	if(b!=null) document.getElementById(b).innerHTML=c;
	return c;
}
