function getPageWH() {
  if(window.outerHeight==undefined){
    var wh = document.body.clientHeight;
    var ww = document.body.clientWidth;
  }else{
    var wh = window.innerHeight;
    var ww = window.innerWidth;
  }
  return [ ww, wh ];
};
function stripix(s){if(s==null)return 0;var re=/px/gi;var c=s.replace(re,'');return Number(c);};
function getObjectWH(o) {
  var ow = o.style.width;
  var oh = o.style.height;
  return [ stripix(ow), stripix(oh) ];
};
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
};
function center_element(el_name){
    var wh = getPageWH();  
    var xy = getScrollXY();  
    var wgbox = document.getElementById(el_name);
    var wgwh = getObjectWH(wgbox);
    wgbox.style.top = Math.floor(xy[1]+Math.floor((wh[1]-wgwh[1])/2))+'px';
    wgbox.style.left = Math.floor(xy[0]+Math.floor((wh[0]-wgwh[0])/2))+'px';
    wgbox.style.display = 'block';
    wgbox.style.overflow='hidden';    
}

function addsmile(smile_code,areaid){
	var t_area = document.getElementById(areaid);
	t_area.value += smile_code;
	document.getElementById("popupDiv").style.display="none";
	document.getElementById("popupDivContent").style.display="none";
}

function show_new_popup_at_item(el_name,id_item,l,t){
    if(window.outerHeight==undefined){
        var wh = document.body.clientHeight;
        var ww = document.body.clientWidth;
    }else{
        var wh = window.innerHeight;
        var ww = window.innerWidth;
    }
    
    var p;
    var x = 0;
    var y = 0;
    var parent;
    p = document.getElementById(id_item);
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        p = p.offsetParent;
    }
    
    var wgbox = document.getElementById(el_name);
    wgbox.style.position = 'absolute';
    wgbox.style.top = y+t+'px';
    wgbox.style.left = x+l+'px';
    wgbox.style.display = 'block';
    wgbox.style.overflow='hidden';
}

function showhideElement(el_id,item_id){
	if (document.getElementById(el_id).style.display == "none"){
	    show_new_popup_at_item(el_id,item_id,-145,22);
		document.getElementById(el_id).style.display="";
	} else { 
		document.getElementById(el_id).style.display="none";
    }
}

function getScript(script_name,el_id){
	var headID = document.getElementById(el_id); 
	var newScript = document.createElement('script');	
	newScript.src = script_name;	
	headID.appendChild(newScript); 	
}

function chechfield(id){
    var f = document.getElementById(id);
    if(f != 'undefined'){
        if(f.value != '') return true;            
    }
    f.style.border = '1px solid red';
    //alert('Mandatory field missing!');
    return false;
}
