//************************************
//     Version
//************************************
var g_version = "(Version 0.2.015)";
var g_connect='0';
var g_tot_secs;
var g_ff_ver;
var g_last_refresh;
var g_hourly_start,g_hourly_end;
var g_alarm_refresh;
var g_refresh=5;
var g_buddy=false;
var g_synop_hr;
var g_tmout;
var g_netwrk=0;
var g_hr, g_sec, g_min, g_day, g_mth, g_yr;
var g_curr_row, g_editmode=" ";
var g_lang;
var g_remind;
var g_cursor="default";
var g_curr_tab="", g_submenu="";
var g_hourly=0, g_speci=0, g_late=0;
var g_reject=false;
var url = new Array();
var ct, req, i, e;
var divs, divnum, data;
var JObj;
var prev_rw = -1;
var prev_tr;
var ctrlkey=false, shiftkey=false;
var tbl, tr, td;
var maxoffset;
var wait;

// This variable will increase and decrease as refresh calls are going and coming, 
// this is to make sure the network is available.

function logout() {
	if (confirm("Logout/Déconnexion?")) {
		AjaxCall("access", "logout");
	}
}

function start() {

    var dt = new Date();
    g_hr=dt.getHours();
    g_min=dt.getMinutes();
    g_sec=dt.getSeconds();
	g_day = dt.getDate();
	g_mth = dt.getMonth() + 1;
	g_yr = dt.getFullYear();

    g_start_secs=(((g_hr*60)+g_min)*60)+g_sec;

	if (isobj("st_version")) settext("st_version", g_version);

	g_hr = ((g_hr < 10) ? "0" : "") + g_hr;
	g_min = ((g_min < 10) ? "0" : "") + g_min;
	g_sec = ((g_sec < 10) ? "0" : "") + g_sec;
	g_day = ((g_day < 10) ? "0" : "") + g_day;
	g_mth = ((g_mth < 10) ? "0" : "") + g_mth;
	//This script will run immediately so it starts up the timer event
	window.outerHeight=screen.availHeight - 48;
	window.outerWidth=screen.availWidth;
	self.moveTo(0,0);
	//var first=true;
	show("busy");
	g_netwrk=0;
//	init_timer();
}

function start_timer() {
	init_timer();
	enable("cb_stop_timer");
	disable("cb_start_timer");
}

function stop_timer() {
	kill_timer();
	enable("cb_start_timer");
	disable("cb_stop_timer");
}

function kill_timer() {
	clearTimeout(g_tmout);
	delete(g_tmout);
}

function debug() {
	if (isobj("debugarea")) return;
	open_window("debugwin","debugarea", 120,120,1000,600,"Debug Window","Y");
	html="<div>";
	html+="<button style='text-align: center; top: 0px; left: 2px; width: 85px; height: 24px; position: absolute;' class='std_button' onclick='start_timer()' id='cb_start_timer'>Start Timer</button>";
	html+="<button style='text-align: center; top: 0px; left: 86px; width: 85px; height: 24px; position: absolute;' class='std_button' onclick='stop_timer()' id='cb_stop_timer'>Stop Timer</button>";
	html+="</div><div id='debugtxt' style='border: 1px solid grey; position: absolute; top: 24px; left: 2px; width:99%;height:95%;overflow-y:scroll;'></div>";
	o = getobj("debugarea");
	o.innerHTML = html;
}

function confirm_quit(CQ) {

	if (isobj("confirm")) close_window("confirm");
	if (CQ == "Q") {
//		var a = confirm ("The network seems to be down or very slow \nClick CANCEL to quit or OK to continue waiting!");
//		if (!a) {
		var html  = '<label style="top: 245px; left: 358px; width: 140px; height: 41px; font-size: 28px; font-family: Arial; font-weight: 700; font-style: normal;position: absolute;">Goodbye</label>';
			html += '<label style="top: 245px; left: 681px; width: 140px; height: 41px; font-size: 28px; font-family: Arial; font-weight: 700; font-style: normal;position: absolute;">Au revoir</label>';
			html += '<label style="top: 245px; left: 520px; width: 150px; height: 39px; font-size: 30px; font-family: Times New Roman; font-weight: 700; font-style: normal;position: absolute;">H W O S</label>';
			html += '<label id="st_version" style="border-style: none; border-width: 0px; top: 288px; left: 550px; width: 150px; height: 15px; font-size: 8px; font-family: Times New Roman; font-style: normal; position: absolute;">(Version ???)</label>';
		settext("mainbody", html);
		settext("st_version", g_version);
		hide("tab");
		hide("status");
		kill_timer();
	}else{
		g_netwrk = 0;
	}
	return false;
}
function set_pos(nm) {
	var intY = document.getElementById(nm).scrollTop;
	document.title = intY;
}

function isIE() {
//	if (navigator.userAgent.indexOf("MSIE")!=-1){
	if (navigator.appName.indexOf("Explorer")!=-1){
		return true;
	}else{
		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) g_ff_ver=new Number(RegExp.$1)
		return false;
	}
}
//****************************************************************************
//					Running Timer
//****************************************************************************
function init_timer() {
    var dt = new Date()
    g_hr=dt.getHours();
    g_min=dt.getMinutes();
    g_sec=dt.getSeconds();
	g_tot_secs = ((((g_hr*60)+g_min)*60)+g_sec) - g_start_secs; 
	g_hr = ((g_hr < 10) ? "0" : "") + g_hr;
	g_min = ((g_min < 10) ? "0" : "") + g_min;
	g_sec = ((g_sec < 10) ? "0" : "") + g_sec;

  	var curTime = g_hr + ":" + g_min + ":" + g_sec;
	settext("status_curr_time",curTime);
	g_day = dt.getDate();
	g_day = ((g_day < 10) ? "0" : "") + g_day;
	g_mth = dt.getMonth() + 1;
	g_mth = ((g_mth < 10) ? "0" : "") + g_mth;
	g_yr = dt.getFullYear();
	if ((g_tot_secs%g_refresh) == 0 ) {
		//Refresh the status bar for time, alarm count and red, yellow indicator
		//time is based on refresh rate default is every 5 seconds
		show("busy");
	}
	if ((g_tot_secs - g_last_refresh) > 1) {
		//Clear message bar when the second is ends in 2 or 7 because a refresh was done at
		// 0 or 5 (see above)
		hide("busy");
	}
	if (g_connect < '2') {
		if (g_connect == '-1') {
			kill_timer();
			return;
		}
		if (g_connect == '0') {
			document.body.style.cursor = 'wait';
			g_connect = '1';
		}
	}
	//Set timer to run every second
	g_tmout = setTimeout("init_timer()",1000);
}

function get_date_time() {
	//get values from table assign to fields
    var dt = new Date()
    h=dt.getUTCHours();
    m=dt.getUTCMinutes();
    s=dt.getUTCSeconds();
  	var CT = ((h < 10) ? "0" : "") + h + ":" + ((m < 10) ? "0" : "") + m + ":" + ((s < 10) ? "0" : "") + s;
	d = dt.getUTCDate();
	var mt = dt.getUTCMonth() + 1;
	y = dt.getUTCFullYear();
  	var CD = y + "-" + ((mt < 10) ? "0" : "") + mt + "-" + ((d < 10) ? "0" : "") + d;
	return CD + " " + CT;
}

function valid_JSON(msg) {
	if (!msg) {
		alert("JSON Error: missing msg");
		return false;
	}
	return true;
}

function is_changes() {
	yn=true;
	if (g_editmode=="N" || g_editmode=="C") {
		yn=confirm("Changes made!\n\nDo you wish to discard changes?");
		if (yn) {
			g_editmode="";
		}
	}
	return yn; 
}
//DOM Object reference
function isobj(nm) {
	if (document.getElementById(nm)) {
		return true;
	}else{
		return false;
	}
}
function getobj(nm) {
	if (isobj(nm)) {
		return document.getElementById(nm);
	}else{
//		ABORT=true;
//		clearTimeout(g_tmout);
		alert("Cannot find ID: " + nm);
		return "";
	}
}
function cancel() {
	return confirm("Are you sure you want to cancel?")
}

function is_disabled(nm){
	return getobj(nm).disabled;
}
function is_style(nm){
	if (getobj(nm).style) return true;
	return false;
}
function hide(nm){
	if (is_style(nm)) getobj(nm).style.display = "none";
//	getobj(nm).style.visibility = "hidden";
}
function show(nm){
	if (is_style(nm)) getobj(nm).style.display = "block";
//	getobj(nm).style.visibility = "visible";
}
function setcolor(nm, c){
    if (is_style(nm)) getobj(nm).style.color=c;
}
function setbgcolor(nm, c){
    if (is_style(nm)) getobj(nm).style.backgroundColor=c;
}
function getbgcolor(nm){
    return getobj(nm).style.backgroundColor;
}
function is_visible(nm){
	if (!is_style(nm)) return false;
	if (getobj(nm).style.display == "block") {
		return true;
	}else{
		return false;
	}
}
function getedit(nm){
	return getobj(nm).value;
}
function gettext(nm){
	return getobj(nm).innerHTML;
}
function enable(nm){
	getobj(nm).disabled = false;
}
function disable(nm){
	getobj(nm).disabled = true;
}
function readonly(nm, TF,tabidx){
	e=getobj(nm);
	if (TF) {
		e.className = "std_read";
	}else{
		e.className = "std_edit";
	}
//	e.disabled=TF;
	e.readOnly = TF;
	e.tabIndex = tabidx;
}
function setedit(nm, val){
	getobj(nm).value = val;
}
function settext(nm, val){
	getobj(nm).innerHTML = val;
}
function appendtext(nm, val){
	if (isIE()) {
		getobj(nm).innerText = getobj(nm).innerText + ' \n' + val;
	}else{
		getobj(nm).textContent = getobj(nm).textContent + val + ' \n';
	}
}
function msg(txt){
//	settext("status_msg", txt);
}
function setfocus(nm) {
	getobj(nm).focus();
}
function select(nm) {
	getobj(nm).select();
}
function clear(nm) {
	setedit(nm, "");
}
function IsNumber(nm) {
	e = getobj(nm);
	if (e.value != parseInt(e.value)) return false;
	return true;
}
function IsFloat(nm) {
	if (e.value != parseFloat(e.value)) return false;
	return true;
}
function IsEmpty(nm) {
	e=getobj(nm);
	if ((e.value.length==0) || (e.value==null)) {
		return true;
	}else{
		return false;
	}
}
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
		alert("Text limit reached!");
		return false;
}	}
//*********************************************************************************
//Checkbox stuff 
//*********************************************************************************
function is_checked(nm){
	return getobj(nm).checked;
}
function check(nm){
	getobj(nm).checked=true;
}
function uncheck(nm){
	getobj(nm).checked=false;
}
//*********************************************************************************
//Radio button stuff 
//*********************************************************************************
function set_checked(nm, val) {
	var o = getobj(nm).childNodes;
	if (!o) return;
//	if (!o.checked) return;
	for (var i=0;i<o.length;i++) {
		if (o[i].tagName == "INPUT") {
			if (o[i].value == val) {
				o[i].checked = true;
			}else{
				o[i].checked = false;
			}
		}
	}
	return "";
}
function get_checked(nm) {
	var o = getobj(nm).childNodes;
	if (!o) return;
	for (var i=0;i<o.length;i++) {
		if (o[i].tagName == "INPUT") {
			if (o[i].checked) {
				return o[i].value;
				break;
			}
		}
	}
	return "";
}
//*********************************************************************************
//Listbox stuff
//*********************************************************************************
// Move from listbox to listbox
function moveitem(s1,s2,action)
{
	var ss1=document.getElementById(s1);
	var ss2=document.getElementById(s2);
	var selId='';
	var selText='';
 
	//Action Add it or remove it.
	f=true;
	if (!ss1.options) return;
	if (action=="A") {
		for(i=ss1.options.length-1 ;i>=0; i--) {
			if (ss1.options[i].selected == true) {
				selId = ss1.options[i].value;
				selText = ss1.options[i].text;
				for(j=0; j<ss2.options.length; j++) {
					actText=ss2.options[j].text;
					if (actText == selText) {
						// It already exists no need to add
						f=false;
						break;
					}
				}
				if (f==false) break;
				ss1.options[i].selected = false
				var newRow = new Option(selText,selId);
				ss2.options[ss2.length] = newRow;
			}
		}	
	}else{
		for(i=ss2.options.length-1 ;i>=0; i--) {
			if (ss2.options[i].selected == true) {
				ss2.options[i] = null;
			}
		}
	}
	return f;
}
function initOptions(s, l)
{
	e = getobj(s)
	for (i=0; i < l.length;++i){
		o = new Option(l[i], "");
		e.options[e.options.length]=o;
	}
}

function initGroupOptions(s, l)
{
	e = getobj(s)
	for (i=0; i < l.length;++i){
		var oGrp = document.createElement('OPTGROUP');
		oGrp.style.fontSize="12px";
		oGrp.label = l[i][0];
		e.appendChild(oGrp);
		for (j=1; j < l[i].length;++j){
			var oOpt = document.createElement('option');
			oOpt.innerHTML = l[i][j];
			oGrp.appendChild(oOpt);
		}
	}
}

function initOptionsVal(s, l)
{
	e = getobj(s)
	for (i=0; i < l.length;++i){
		e.options[i].value=l[i];
	}
}
function remove_selected(nm){
	e=getobj(nm);
	if (!e.options) return;
	curr=e.selectedIndex;
	e.remove(curr);
	if (e.options.length == 0) return -1;	
	if (curr == 0) curr = 1;
	curr = curr -1;
	e.options[curr].selected=true;
	return curr;
}
function remove_lastitem(nm){
	e=getobj(nm);
	if (!e.options) return;
	e.remove(e.options.length -1);
	return;
}
function clearlistbox(nm){
	if (!getobj(nm).options) return;
	getobj(nm).options.length = 0;
}
function additem(nm, txt, colr){
	if (!getobj(nm).options) return;
	var opt = document.createElement('OPTION');
	if (colr != '') {
		opt.style.color=colr;
	}
	opt.text = txt;
	getobj(nm).options.add(opt);
}

function additemval(nm, txt, val, colr){
	if (!getobj(nm).options) return;
	var opt = document.createElement('OPTION');
	if (colr != '') {
		opt.style.color=colr;
	}
	opt.value = val;
	opt.text = txt;
	getobj(nm).options.add(opt);
}
function getitemtxt(nm, val){
	txt="";
	e=getobj(nm);
	if (e.options) {
		for (var i=0; i<e.options.length; i++) {
			if ( e.options[i].value == val ) {
				txt = e.options[i].text;
				break;
			}
		}
	}
	return txt;
}
function setitemtxt(nm, txt, val, colr){
	e=getobj(nm);
	if (!e.options) return;
	for (var i=0; i<e.options.length; i++) {
		if ( e.options[i].value == val ) {
			if (colr != '') {
				e.options[i].style.color=colr;
			}
			e.options[i].text = txt;
			break;
		}
	}
}
function deselectall(nm){
	getobj(nm).selectedIndex = -1;
}
function getselecteditem(nm){
	e=getobj(nm);
	if (!e.options) return;
	if (e.options.length == 0) 
		return "";	
	else{
		var txt=ltrim(e.options[e.selectedIndex].text);
		return txt;
		
	}
}
function isColor(nm) {
	e=getobj(nm);
	// If the item in the list has color return true
	if (e.options[e.selectedIndex].style.color) return true;
	return false;
}

function getselecteditemval(nm){
	e=getobj(nm);
	if (!e.options) return;
	if (e.options.length == 0) 
		return "";	
	else{	
		return e.options[e.selectedIndex].value;
	}
}
function getidx(nm){
	e=getobj(nm);
	return e.selectedIndex;
}
function selectlastitem(nm){
	e=getobj(nm);
	if (!e.options) return;
	if (e.options.length > 0) selectitem(nm, e.options.length -1);

}
function selectitem(nm, idx){
	e=getobj(nm);
	if (!e.options) return;
	if (e.selectedIndex != -1) e.options[e.selectedIndex].selected=false;
	if (idx != -1) e.options[idx].selected=true;
}
function numitems(nm){
	e=getobj(nm);
	if (!e.options) return;
	num = e.options.length;
	return num;
}
function getitems(nm, cc){
	e=getobj(nm);
	if (!e.options) return;
	num = e.options.length;
	for (i=0; i<num; i++) {
		cc[i] = {"item":""};
		cc[i].item = e.options[i].text;
	}
	return cc;
}
function clearselecteditem(nm){
	e=getobj(nm);
	if (!e.options) return;
	e.options[0].selected = true;
	return;
}
function setselecteditem(nm, val){
	e=getobj(nm);
	if (!e.options) return;
	for (var i=0; i<e.options.length; i++) {
		if ( e.options[i].text == ltrim(val) ) {
			e.options[i].selected = true;
			break;
		}
	}
	return;
}
function exists(nm, val){
	e=getobj(nm);
	if (!e.options) return;
	for (var i=0; i<e.options.length; i++) {
		if ((e.options[i].value == val) && (i != e.selectedIndex)) {
			return true;
		}
	}
	return false;
}
function setselecteditemval(nm, val){
	e=getobj(nm);
	if (!e.options) return;
	for (var i=0; i<e.options.length; i++) {
		if ( e.options[i].value == val ) {
			e.options[i].selected = true;
		}
	}
	return;
}
//Other 
function ltrim(s) {
	return s.replace(/^\s+/,"");
}
function load_container(id, data) {
//	if (getobj(id).className == "grid") hide(id);
	settext(id,data);
}
function clear_container(id) {
	//Must remove the contents in the div

}

function load_js(nm) {
//alert(nm);
	h = document.getElementsByTagName("head")[0];
	s = document.createElement("script");
	s.setAttribute("src", nm);
	s.setAttribute("type", "text/javascript");
//	s.setAttribute("charset", "utf-8");
	var loaded=false;
	var loadFunction = function() {
			if (loaded) return;
			loaded=true;
	}
	s.onload = loadFunction;
	s.onreadystatechange = loadFunction;
	h.appendChild(s);
}

function load_css(nm) {
	h = document.getElementsByTagName("head")[0];
	s = document.createElement("link");
	s.setAttribute("type", "text/css");
	s.setAttribute("href", nm);
	s.setAttribute("rel", "stylesheet");
	// May want to keep a list of loaded css files so we do not load again. 
	h.appendChild(s);
}

//*********************************************************************************
//Grid stuff
//*********************************************************************************
function get_table(grid) {
	var t="";
	//Get the grid 
	var g = getobj(grid);
	if (g.className.toUpperCase() != "GRID") {
		alert("ERROR Must be a grid control for object " +grid);
		return t;
	}
	//Let's get the table
	if (g.firstChild!="" && g.firstChild  && g.firstChild.nodeType) {
//	if (typeof(g.firstChild.nodeType) == "undefined") return;
		if (g.firstChild.nodeType == 3) {
			//Skip the #text node that firefox adds
			t = g.childNodes[1];
		}else{
			t = g.childNodes[0];
		}
	}
	return t;
}

function get_selected(tbl) {
	//Make sure the table exists and this uses css classname 'pick'
	if (tbl) {
		for (i=0;i < tbl.rows.length; i++) {
			if (tbl.rows[i].className == "pick") {
				return i;
			}
		}
	}
	return 0;
}

function get_pk_row(tbl, pk) {
	//Make sure the table exists and we will look through the row until we find that pk row
	if (tbl) {
		for (i=0;i < tbl.rows.length; i++) {
			if (tbl.rows[i].getAttribute("pk") == pk) {
				return i;
			}
		}
	}
	return 0;
}

//************************
//       isGrid()
//************************
function isGridPickable(o) {

	if (o.tagName == "TD") {
		// A TD object inside a TR inside a TBODY inside a TABLE inside a DIV
		if (o.parentNode.parentNode.parentNode.parentNode.className.toUpperCase() == "GRID") {
		   	if (o.parentNode.parentNode.parentNode.className == "selectable") {
				return true;
			}
		}
	}
	return false;
}

//************************
//       pick()
//************************
function pick(o) {
	var tr, tbl;
	tr = o.parentNode;
	tbl = o.parentNode.parentNode.parentNode;
	if (tbl.tagName != "TABLE") return;
	if (tr.parentNode.tagName != "TBODY") return;
   	if (tbl.className == "selectable") {
//   	if (tbl.getElementsByTagName('thead')[0].rows[0].className == "selectable") {
		for (i=1;i < tbl.rows.length; i++) {
			tbl.rows[i].className = (i%2==0)?"altr":"norm";
		}
		curr_row = tr.rowIndex;
		tbl.rows[tr.rowIndex].className = (tbl.rows[tr.rowIndex].className == "pick")?tbl.rows[i].className:"pick";
		if(typeof(do_picked) != "undefined") do_picked(tbl, curr_row);
	}
}


//************************
//       goDown()
//************************
function goDown(t) {
	if (g_curr_row+1 < t.rows.length) {
		t.rows[g_curr_row+1].className = "pick";
		t.rows[g_curr_row].className = (g_curr_row%2==0)?"altr":"norm";
		g_curr_row++;
		if (t.rows[g_curr_row].offsetTop > (t.parentNode.offsetHeight - t.rows[g_curr_row].offsetTop)) {
			t.rows[g_curr_row].scrollIntoView(false);
		}
	}
}
//************************
//       goUp() this is for grids
//************************
function goUp(t) {
	if (g_curr_row==1) return;
	t.rows[g_curr_row-1].className = "pick";
	t.rows[g_curr_row].className = (g_curr_row%2==0)?"altr":"norm";
	g_curr_row--;
	t.rows[g_curr_row].scrollIntoView(false);
	if (((t.rows[g_curr_row].offsetTop) - (t.parentNode.offsetHeight)) < 0) {
		t.rows[g_curr_row].scrollIntoView(false);
	}
}
function open_window(id, area_id, winT, winL, winW, winH, title, close) {
	// Make this a public variable
	//Let's create the window this means putting it in a div 
	if (document.getElementById(id)) {
//			alert("A window with ID " + this.id + " already exists!");
		return;
	}
	var b = document.getElementsByTagName("BODY")[0];		
	var e = document.createElement("div");
	e.setAttribute('id',id);
	e.className="win";
	e.style.position="absolute";
	e.style.top=winT + "px";
	e.style.left=winL + "px";
	e.style.zIndex="999";
	//See listen.js when the image (wclose) is clicked
	html= '<table onselectstart="return false" style="-moz-user-select: none;"><tr><td width="'+(winW - 23)+'px;"class="wintitle" id="wintitle" title="mouse down to move">';
    html+= title+'</td>';
	if (close=="Y") {
		html+='<td><img class="winclose" id="winclose" src="images/close.gif" title="Click to close"></td></tr><tr><td colspan=2>';
	}else{
		html+='</tr><tr><td>';
	}
	html+='<div id="'+area_id+'" class="winarea" style="height:';
	html+=winH+'px;width:'+winW+'px;"></div></td></tr></table>';
	e.innerHTML=html;
	b.appendChild(e);
}
function close_window(id){
	//	This will remove the window
	if (isobj(id)) {
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}
}
function close_allwindows(){
	var alldivs = document.getElementsByTagName("div");
	for (var i = alldivs.length-1; i > 0; i--) { 
		if (alldivs[i].className == "win"){
			//If the window id begins with status_ do not close it.
			if ((alldivs[i].id != "debugwin") && (alldivs[i].id.search(/status_/i) == -1)) close_window(alldivs[i].id);
		}
	}
}
function delNode(id){
	//	This will remove the DIV that was created
	e=document.getElementById(id);
	e.parentNode.removeChild(e);
}

function delChildren(id){
	var holder = getobj(id);
	while(holder.hasChildNodes()){
		holder.removeChild(holder.lastChild);
	}	
}

function changeStyleClass (myclass, element, value) {
	var CSSRules
	if (document.all) {
		CSSRules = 'rules';
	}
	else if (document.getElementById) {
		CSSRules = 'cssRules';
	}
	for (var i = 0; i < document.styleSheets[0][CSSRules].length; i++) {
		if (document.styleSheets[0][CSSRules][i].selectorText.toLowerCase() == myclass.toLowerCase()) {
			document.styleSheets[0][CSSRules][i].style[element] = value;
			break;
		}
	}	
	return null;
}

function ltrim(b) {
	return b.replace(/^\s+/,""); //ltrim
}
function rtrim(b) {
	return b.replace(/\s+$/,""); //rtrim
}
function trim(b) {
	return b.replace(/^\s+|\s+$/g,""); //trim
}
function set_opacity(element, o) { 
    // IE compatibility. Detect lack of native 'opacity' support, and ensure element 
    // has layout for IE6-7. 
    // 
    element.style.display='block';
    var canopaque= 'opacity' in element.style; 
    if (!canopaque && 'currentStyle' in element && element.currentStyle.hasLayout===false) 
       element.style.zoom= '1'; 
		if (canopaque)
			element.style.opacity= ''+o; 
		else 
			element.style.filter= 'alpha(opacity='+Math.round(o*100)+')'; 
//		if (!canopaque) o=Math.round(o*100);
//		element.style.cssText="-ms-filter:'alpha(opacity="+o+")'; filter:alpha(opacity="+o+"); opacity:"+o;
}
function fade(element, o0, o1, t) { 
    // IE compatibility. Detect lack of native 'opacity' support, and ensure element 
    // has layout for IE6-7. 
    // 
    element.style.display='block';
    var canopaque= 'opacity' in element.style; 
    if (!canopaque && 'currentStyle' in element && element.currentStyle.hasLayout===false) 
       element.style.zoom= '1'; 
    function setOpacity(o) { 
		if (canopaque)
			element.style.opacity= ''+o; 
		else 
			element.style.filter= 'alpha(opacity='+Math.round(o*100)+')'; 
//		if (!canopaque) o=Math.round(o*100);
//		element.style.cssText="-ms-filter:'alpha(opacity="+o+")'; filter:alpha(opacity="+o+"); opacity:"+o;
    }
    var t0= new Date().getTime(); 
    setOpacity(o0); 
    var interval= setInterval(function() { 
        var dt= (new Date().getTime()-t0)/t; 
        if (dt>=1) { 
           dt= 1; 
           clearInterval(interval); 
        } 
        setOpacity(o1*dt+o0*(1-dt)); 
    }, 25); 
}
function get_Height(){
	var h;
	if (self.innerHeight) {// all except Explorer
//		W = self.innerWidth;
		h = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
//		W = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}else if (document.body) { // other Explorers
//		W = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return h;
}
function resize_popup(main, area, frame, defalt) {
	H=get_Height();
	if (defalt != "") {
		if (defalt > H) {
		    getobj(main).style.height=(H - 8) + "px"; 
		    getobj(area).style.height=(H - 32) + "px"; 
		    if (frame != "") getobj(frame).style.height=(H - 40) + "px"; 
		}
	}else{
	    getobj(main).style.height=(H - 8) + "px"; 
	    getobj(area).style.height=(H - 32) + "px"; 
	    if (frame != "") getobj(frame).style.height=(H - 40) + "px"; 
	}
}
function resize() {
	H=get_Height();
	if (screen.height < 800 && H < 780) H =780;
	if (!isobj("rightbody")) return;
	m=getobj("mask");
	rb=getobj("rightbody");
	rs=getobj("right_side");
	m.style.height = (H - 20) + "px";
	rs.style.height = (H - 165) + "px";
	rb.style.height = (H - 220) + "px";
//	if (isobj("newsframe")) {
//    	if (isobj("ddlb_archive")) {
//            getobj("newsframe").style.height=(H - 198 -38) + "px"; 
//        }else{
//            getobj("newsframe").style.height=(H - 198) + "px"; 
//        }
//	}
	if (isobj("news_letter")) resize_popup("news_letter", "newsarea", "newsframe", "");
	if (isobj("catalog")) resize_popup("catalog", "catarea", "catframe", "");
	if (isobj("wincontact")) resize_popup("wincontact", "contactarea", "", "");
	if (isobj("winprivacy")) resize_popup("winprivacy", "privacyarea", "", "450");
	if (isobj("winrequest")) resize_popup("winrequest", "requestarea", "", "520");
	return true;
}
function delpx(str){
	if (str.indexOf("px") == -1)
       return 0;
    else {
       var iLen = String(str).length;
       return str.substring(0, iLen - 2);
    }
}
// function do_link(o) {
// 	if (document.getElementById("topmenu")) {
// 		e = document.getElementById("topmenu");
//         l=e.getElementsByTagName("a");
// 		for (i=0; i<l.length; i++) {
// 			if (l[i].id == o.id) {
//                 l[i].className = "current";
//                 get_contents(o);
// 		    }else{
// 			     l[i].className = "";
// 			}
// 		}
// 	}
// }
// function do_menu() {
//    getobj("m_title").innerHTML=m_title;
//    var ul="";
//    for (var i in m_items)
// 	{
// 		ul +='<li><a id="'+i+'" href="#" onclick="get_main(this);return false;">'+items[i]+'</a></li>';
// //		alert('theStatus[\''+i+'\'] is ' + items[i])
// 	}
//    getobj("m_items").innerHTML=m_items;
//    return;
// }

