﻿	
//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 CharacterCount_Truncate(txtIn,txtOut,max){
    alert
    var ll = String
    ll = txtIn.value.length
    
    if (ll > max) {
        txtIn.value = txtIn.value.substr(0, max);
    }
    
    if (txtOut != null) {
        document.getElementById(txtOut).innerHTML = ll
    }
    return ll
}		
	
function CharacterCount(txtIn,txtOut){
    var l = txtIn.length
    if (txtOut != null) {
        document.getElementById(txtOut).innerHTML = l
    }
    return l
}	
	
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 = trow.className + ' ' + cls
    
    if (bgcolor) {
        cval = parseInt(bgcolor.substr(1,30),16)
        tds = trow.getElementsByTagName("td")
        for (var x = 0; x <= tds.length - 1; x++) {
            tds[x].style.backgroundColor = bgcolor
            
            try {
            ary = new Array()
            ary = Contrast.match(bgcolor, ['#000000', '#333333','#666666', '#999999', '#CCCCCC', '#FFFFFF'])
            
            tdata = tds[x].getElementsByTagName("a")
            for (var y = 0; y <= tdata.length - 1; y++) {
                tdata[y].style.color = ary[1];
            }
            tds[x].style.color = ary[1]
            } catch (e) {
            
            }
        }
    }
}	


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>')
}
	


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);
}

var ddtimer
function deanimate() {
	clearTimeout(ddtimer);
}

function getCookie(c_name)
	{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function animate(onOrOff, emt, pos, neg) {
	
	button = document.getElementById(emt)
	
	if ((getCookie("dd") != '') && (parseInt(button.style.top) < 0)) {return;}

	if (parseInt(button.style.top) < 0) {
		ddtimer = window.setTimeout("moveButton(1,'" + emt + "'," + pos + "," + neg + ");", 0, "JavaScript");
	} else {
		ddtimer = window.setTimeout("moveButton(0,'" + emt + "'," + pos + "," + neg + ");", 0, "JavaScript");
	}
}

function moveButton(onOrOff, emt, pos, neg) {
	button = document.getElementById(emt)

	if (onOrOff == 1) {
		if (parseInt(button.style.top) < pos) {
			button.style.top = parseInt(button.style.top) + 10 + 'px';
		    ddtimer = window.setTimeout("moveButton(1,'" + emt + "'," + pos + "," + neg + ");", 0, "JavaScript");
		}
	} else {
		if (parseInt(button.style.top) > neg) {
			button.style.top = parseInt(button.style.top) - 10 + 'px';
			ddtimer = window.setTimeout("moveButton(0,'" + emt + "'," + pos + "," + neg + ");", 0, "JavaScript");
		}
	}
}