// main.js

nMenu = 0;
MenuOn = 0;

function bg0(oo) { oo.style.backgroundColor= "#ffdddd"; }
function bg1(oo) { oo.style.backgroundColor= "#ccffcc"; }
function build_sql() { alert("feature not available"); }

function cbo_blur(cbo) { 
  with (cbo.style) { height=24; zIndex=0; }
  if(chrome||safari) { var that = cbo; setTimeout(function() {that.setAttribute('size', 1);}, 100); } else { cbo.size=1; }
}

function cbo_focus(cbo){ 
  with (cbo.style) { height=200; zIndex=100; }
  if(chrome||safari) { var that = cbo; setTimeout(function() {that.setAttribute('size', 8);}, 100); } else { cbo.size=8; }
}

function date_add(s1,y,m,d) {
  var date = new Date( parseInt(s1.substr(0,4))+y, parseInt(s1.substr(5,2))+m, parseInt(s1.substr(8,2))+d);
  var s2 = date.getFullYear() + "-" + padNum(date.getMonth(),2) + "-" + padNum(date.getDate(),2);
  return s2;
}

function padNum(number, numDigits) {
  var str = number.toString();
  while (str.length < numDigits) str = '0' + str;
  return(str);
}

function dec(x,d) { with(Math){ if(x<0) { return "-"+dec(-x,d); } s1=String(round((1+x)*pow(10,d)));t1=s1.length; res=String( s1.substr(0,t1-d) -1); res2 = s1.substr(t1-d); if(res2>0) {res = res +'.'+res2; } return res; }}
function cal_click(oo) {
  s1 = oo.id.substr(4);
  var aa = { inputField:s1, ifFormat:'%Y-%m-%d', button:'dummy' }
  Calendar.setup(aa);
  dummy.onclick(); 
  calendar.showAtElement(fld(s1));
}
function disp0(n) { hideSelect(0); fld('list'+n).style.display = 'none'; }
function disp1(n) { hideSelect(1); fld('list'+n).style.display = ''; }
function dispAll(t) { for(n=1; n<=nMenu; n++) { fld('list'+n).style.display = (t==0) ?'none':''; } if(t==0) { hideSelect(0); }}
function fld(s1) { oo = document.getElementById(s1); if(oo==null) {alert('Unknown '+s1);} else {return oo;} }
function fld2(s1) { oo = document.getElementById(s1); return oo; }
function go(txt) { form1.keyword.value=txt; form1.curpage.value=1; form1.submit(); }
function go2(pg) { form1.curpage.value=pg;  form1.submit1.value='GOTO'; form1.submit(); }
function go3(txt) { form1.direct.value=1; go(txt); }
function go4(dir) { form1.direct.value=dir; form1.submit(); }
function main1(prog1) { with (form0) { target='_self'; prog.value=prog1; submit(); } }
function main2(prog1,a2) { with (form0) { target='_self'; prog.value=prog1; act2.value=a2; submit(); } }
function msg(txt) { fld('msg_area').innerHTML=txt; }
function reload_cbo(fn,s1) { oo=fld(fn); oo.length=0; for(var k=0; k<s1.length; k++) oo.options.add ( new Option( s1[k], s1[k])); }
function reload_cbo2(fn,s1,s2) { 
  oo=fld2(fn); if (oo==null) return;
  oldval=oo.options[oo.selectedIndex].text;
  oo.length=0; 
  for(var k=0; k<s1.length; k++) { 
    var opt = document.createElement("option");
    oo.options.add(opt); 
    opt.value = s1[k];
    opt.text = s2[k];
    if(s2[k]==oldval) oo.selectedIndex=k;
  }
}
function round2 (x,d) { with (Math) { return round (x * pow(10,d) + pow(10,d-5) ) / pow(10,d) ; } }
//function round2 (x,d) { with (Math) { return round (x * pow(10,d) ) / pow(10,d) ; } }
function sum(t,r,s) { s1=0; s2=s.split2(/,/); for(i in s2) { s1 = s1 + v(fld("f"+s2[i]+"f"+r+"f"+t)) } return s1; }
function sum2(t,s){s1=0;for(r=1;r<=v(fld("son_t"+t));r++){s1=s1+v(fld("f"+s+"f"+r+"f"+t));}return s1; }
function toggle(o1) { o1.checked = !o1.checked; }
function toggleMenu() { MenuOn = (MenuOn==1)?0:1; }
function toggle_disp(a1) { oo=fld(a1); oo.style.display=(oo.style.display=='')?'none':''; return false; }
function v (oo) { with (Math) { x = parseFloat(String(oo.value)); return isNaN(x) ? 0 : x; } }
function wopen(fname) { window.open(fname); }

function unicode2url(str) {
      str = String(str);
	var i,c,ret="",strSpecial="!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%";
	for(i=0;i<str.length;i++){
		if(str.charCodeAt(i)>=0x4e00)
			ret += "%u"+str.charCodeAt(i).toString(16)
		else{
			c=str.charAt(i);
			if(c==" ")
				ret+="+";
			else if(strSpecial.indexOf(c)!=-1)
				ret+="%"+str.charCodeAt(i).toString(16);
			else
				ret+=c;
		}
	}
	return ret;
}

var pending1, pending2, pending3;

function getName(tbl, key) {
  pending2 = fld(key+'c');
  pending3 = fld(key+'e');
  fld('rpc').src = "/?prog=getName&table=" + tbl + "&val=" + unicode2url(fld(key).value);
  return true;
}

function addMore(aa) {
  aa.href = aa.href +"&caller="+unicode2url(fld2("prog").value) +"&keyword="+unicode2url(fld2("keyword").value) +"&curpage="+unicode2url(fld2("curpage").value) +"&act2="+unicode2url(fld2("act9").value) +"&id="+unicode2url(fld2("id").value);
}

var oField;

function chkCode(tbl, fn, sid) {
  oField = fld(fn);
  fld('rpc').src="/?prog=chkCode&table="+ tbl +"&sid="+sid+"&val="+unicode2url(oField.value);
}

function loadCode(tbl, key, part, tag, win, row) {
  url = "/?prog=loadCode";
  if (row !== "undefined") url = url + "&row=" + unicode2url(row);
  if (tbl !== "undefined") url = url + "&table=" + unicode2url(tbl);
  if (key !== "undefined") url = url + "&key=" + unicode2url(key);
  if (part!== "undefined") url = url + "&part="+ unicode2url(part);
  if (tag !== "undefined") url = url + "&tag=" + unicode2url(tag);
  if (win=="undefined" || win=='' || win=='ajax') { ajax_queue(url+"&ajax=1"); return; }
  if (win=="undefined" || win=='' ) win='rpc';
  oo = fld2(win); if (oo==null) oo = fld('rpc'); oo.src = url;
}

function remCode(val) {
  fld('rpc').src="/?prog=label2_prn&act=add&val="+unicode2url(val);
}

function sugCode(tbl, fn, key2) {
  oField = fld(fn);
  fld('rpc').src="/?prog=sugCode&table="+ tbl +"&val="+ unicode2url(oField.value) +"&key2="+ unicode2url(key2);
}

var pending1, pending2, page2, after_ret, ret_obj;

function js_ask(fldname, prog, win, but) {
  ret_obj = new Array;
  pending1 = fld2(fldname);
  arr4 = fldname.split2(/f/);
  arr5 = but.id.split2(/[f|b]/);
  if( (arr5.length>=3) && (arr4[1]!==arr5[1]) ) {
    fldname = 'f'+arr4[0]+'f'+arr5[1]+'f'+arr4[2];
//    alert("fldname="+fldname);
    pending1 = fld2(fldname);
    arr4[1] = arr5[1];
  }
  if (prog.match('#')) { 
    arr3 = prog.split2(/#/); 
    f1 = (arr4.length==3)?'f'+arr4[0]+'f'+arr4[1]+arr3[1]:arr3[1]; 
    prog = arr3[0]+unicode2url(fld2(f1).value); 
  }
  if (prog.match('!')) { 
    arr3 = prog.split(/(\!|&)/); prog = arr3[0]; 
    for(i=1; i<arr3.length; i+=1) {
      o3 = fld2(arr3[i])
      esc = o3==null ? '' : unicode2url(o3.value);
      prog += (arr3[i].charAt(0)=='f') ?  esc : "&"+arr3[i]; 
    }
  }
  prog = "/?prog=" + prog + "&qmode=1";
  if(win==null || win=='') win="enquiry1";
  page2 = fld2(win);
  if ( page2 != null && !page2.closed ) {
//tag_top = 30 + findPos(obj).y
    page2.style.top = findPos(but).y;
//(arr5.length>=3) ? parseFloat(fld("tag"+arr5[0]).style.top) + parseFloat(fld("f"+arr5[0]+"s"+arr5[1]+"seq").style.top) : parseFloat(but.style.top);
    page2.style.border = "2px solid #FF0000";
    page2.style.padding = "2px";
    page2.style.margin = "2px 2px 2px 2px";

    page2.src = prog;
    page2.style.display = '';
  }
  return false;
}

function js_ret(ok,code) {
  page2.src = "/inc/loading.htm";
  page2.style.display = 'none';
  if (ok) { pending1.value=""+code; chk(pending1); }
  return false;
}

function js_copy(o1,o2) {
// copy value of o1 to o2, considering the type as combobox and combobox-multiple
  if (o1.type=="select-multiple") {
    if (o2.type=="select-multiple") { 
      for (var i=0;i<o2.length;i++) o2.options[i].selected = o1.options[i].selected;
    } else {
      s1 = "";
      for (var i=0;i<o1.length;i++) { o3 = o1.options[i]; if (o3.selected) s1 = s1+","+o3.value; }
//      o2.value = (s1=="") ? "" : s1.substr(1).toUpperCase();
      o2.value = (s1=="") ? "" : s1.substr(1);
    }
  } else {
//    s1 = o1.value.toUpperCase();
    s1 = o1.value;
    if (o2.type=="select-multiple") { 
      s1 = "," + s1 + ",";
      for (var i=0;i<o2.length;i++) {
//        s2 = o2.options[i].value.toUpperCase();
        s2 = o2.options[i].value;
        o2.options[i].selected = s1.search("," + s2 + ",")>=0;
      }
    } else {
//      if (o2.type!=='text' && o2.type!=="select-multiple") js_dump(o2);
      o2.value = s1;
    }
  }
}

var paste_buffer = new Array;
 
function paste_init(obj, arr) {
  cbo = fld("paste_cbo");
  if (typeof obj == "object") {
    cbo.tabIndex = obj.tabIndex; // not working, diff div?
    p1 = findPos(obj);  
    cbo.style.top = p1.y;
    if ( (w1=parseFloat(obj.style.width))=="NaN" ) w1 = 200;
    if(chrome) {var that = cbo; setTimeout(function() {that.setAttribute('size', 1);}, 0);} else {cbo.size=1;}
    cbo.tag = w1;
    cbo.style.width = 20;
    cbo.style.left = p1.x + w1 - 20;
    cbo.style.height = 24;
    reload_cbo("paste_cbo", arr);
    cbo.style.display = 'inline';
    paste_buffer = new Array(obj,arr);
    cbo.focus();
    obj.focus();
  }
}
 
function paste_click(cbo) { obj=paste_buffer[0]; obj.value=cbo.value; chk(obj); }
function paste_blur(cbo) { 
  with (cbo.style) { width=20; left=parseFloat(left)+cbo.tag-20; height=24; }
  if(chrome) { var that = cbo; setTimeout(function() {that.setAttribute('size', 1);}, 0); } else { cbo.size=1; }
}
function paste_focus(cbo) { 
  with (cbo.style) { width=cbo.tag; left=parseFloat(left)-cbo.tag+20; height=200; }
  if(chrome) { var that = cbo; setTimeout(function() {that.setAttribute('size', 8);}, 0); } else { cbo.size=8; }
}

function dump(o1) {
  var s1="", cr=String.fromCharCode(13,10);
  if( o1.name) s1 = s1 + "name="+o1.name+cr;
  if( o1.id) s1 = s1 + "id="+o1.id+cr;
  if( o1.type) s1 = s1 + "type="+o1.type+cr;
  alert(s1);
}

var MAX_DUMP_DEPTH = 10;
      
       function dumpObj(obj, name, indent, depth) {
              if (depth > MAX_DUMP_DEPTH) {
                     return indent + name + ": <Maximum Depth Reached>\n";
              }
              if (typeof obj == "object") {
                     var child = null;
                     var output = indent + name + "\n";
                     indent += "\t";
                     for (var item in obj)
                     {
                           try {
                                  child = obj[item];
                           } catch (e) {
                                  child = "<Unable to Evaluate>";
                           }
                           if (typeof child == "object") {
                                  output += dumpObj(child, item, indent, depth + 1);
                           } else {
                                  output += indent + item + ": " + child + "\n";
                           }
                     }
                     return output;
              } else {
                     return obj;
              }
       }

function remove(el) { o1=fld(el); o2=o1.parentNode; o2.removeChild(o1); }

function relive(tag) {
  fld("tag"+tag+"alt").style.display='none';
  fld("tag"+tag+"row1").style.display='';
  fld("f"+tag+"s").value = '1';
  recalc();
}

function copy_val(n1,n2) { // names of 2 objects of same type, value of n1 go to n2
  if ( (o1=fld2(n1))!==null && (o2=fld2(n2))!==null) o2.value = o1.value;
}

function swap_val(n1,n2) { // names of 2 objects of same type, swap values
  if ( (o1=fld2(n1))!==null && (o2=fld2(n2))!==null) { t1=o2.value; o2.value=o1.value; o1.value=t1; }
}

function rowact(obj,but) {
  par = obj.parentNode.id;
  var i = par.indexOf('row');
  var tag = round2(par.substr(3,i-3),0);
  var row = round2(par.substr(i+3),0);

  flds = v(fld("fld_tag"+tag));
  rows = v(fld("f"+tag+"s"));

  if (but==1) { // move current row to top, i.e. values of rows 1..r-1 go to rows 2.., then r go 1
    if (row==1) return;
    tmp = new Array();
    for (j=0; j<flds; j++) tmp[j] = fld("f"+tag+"f"+row+"f"+j).value;
    for(i=row; i>1; i--) 
      for (j=0; j<flds; j++)
        copy_val("f"+tag+"f"+(i-1)+"f"+j, "f"+tag+"f"+i+"f"+j);
    for (j=0; j<flds; j++) fld("f"+tag+"f1f"+j).value = tmp[j];
    return;
  }
  if (but==2) { // move row up one
    if (row==1) return;
    for (j=0; j<flds; j++) 
      swap_val("f"+tag+"f"+row+"f"+j, "f"+tag+"f"+(row-1)+"f"+j);
    return;
  }
  if (but==3) { // delete current row
    if( rows==1 ) { // last row, kept in
      fld("tag"+tag+"row1").style.display='none';
      fld("tag"+tag+"alt").style.display='';
    } else {
      for(i=row; i<rows; i++) 
	for (j=0; j<flds; j++)
           copy_val("f"+tag+"f"+(i+1)+"f"+j, "f"+tag+"f"+i+"f"+j);
      remove("tag"+tag+"row"+rows);
    }
    fld("f"+tag+"s").value = String(rows-1);
    recalc();
    return;
  } 
  if (but==4 || but==5) { // insert and append row
    hei = round2(fld('f'+tag+'height').value,0);
    o1 = make_sibling("tag"+tag+"row"+rows, false); // duplicate whole row tag9row9
    o1.id = "tag"+tag+"row"+(1+rows);	       // adjust id for row
    hd  = 'f'+tag+'f'+rows+'f';
    hd2 = 'f'+tag+'f'+(1+rows)+'f';
    hd3 = 'f'+tag+'f'+rows+'b'; // button calling js_ask
    hd4 = 'f'+tag+'f'+(1+rows)+'b';
    hdl = hd.length;
    change_id(o1, hd, hd2, hd3, hd4, hdl); // adjust id for new obj

    if(but==4){ // this is insert
      for(i=rows+1; i>row; i--) { //every row below *row* copy above value
	for (j=0; j<flds; j++) { 
          copy_val("f"+tag+"f"+(i-1)+"f"+j, "f"+tag+"f"+i+"f"+j);
	}
	tagrow="tag"+tag+"row"+i;
	o1 = fld2(tagrow); // line number seq for the row
	if(o1.id==tagrow) for(var son=0; son<o1.childNodes.length; son++) 
	  if ( o1.childNodes[son].id == 'seq' ) o1.childNodes[son].innerHTML = i;
      }
      for(j=0; j<flds; j++) { o1="f"+tag+"f"+row+"f"+j; if ( (o1=fld2(o1))!==null ) o1.value = ''; }
    }
    fld("f"+tag+"s").value = String(rows+1);
    recalc();
    return;
  }
  if (but==6) { // duplicate current row
    hei = round2(fld('f'+tag+'height').value,0);
    o1 = make_sibling("tag"+tag+"row"+rows, false); // duplicate whole row tag9row9
    o1.id = "tag"+tag+"row"+(1+rows);	       // adjust id for row
    hd  = 'f'+tag+'f'+rows+'f';
    hd2 = 'f'+tag+'f'+(1+rows)+'f';
    hd3 = 'f'+tag+'f'+rows+'b'; // button calling js_ask
    hd4 = 'f'+tag+'f'+(1+rows)+'b';
    hdl = hd.length;
    change_id(o1, hd, hd2, hd3, hd4, hdl);

      for(i=rows+1; i>row; i--) { //every row below *row* copy above value
	for (j=0; j<flds; j++) { 
          copy_val("f"+tag+"f"+(i-1)+"f"+j, "f"+tag+"f"+i+"f"+j);
	}
	tagrow="tag"+tag+"row"+i;
	o1 = fld2(tagrow); // line number seq for the row
	if(o1.id==tagrow) for(var son=0; son<o1.childNodes.length; son++) 
	  if ( o1.childNodes[son].id == 'seq' ) o1.childNodes[son].innerHTML = i;
      }

    fld("f"+tag+"s").value = String(rows+1);
    recalc();
    return;
  } 
}

function change_id(o1, hd, hd2, hd3, hd4, hdl) {

    for(var son=0; son<o1.childNodes.length; son++) {  
      var o2 = o1.childNodes[son];
      var nid = String(o2.id);
      if( nid!=="undefined" && nid!=="" ){
	if(nid.substr(0,hdl)==hd)   { o2.id=hd2+nid.substr(hdl); o2.name=o2.id; o2.value=''; } 
	if(nid.substr(0,hdl)==hd3)  { o2.id=hd4+nid.substr(hdl); o2.name=o2.id; } // retain button value
	if(nid.substr(0,4)=='cal_') { o2.id='cal_'+hd2+nid.substr(hdl+4); o2.name=o2.id; o2.value=''; }
 	if(nid=='seq') o2.innerHTML = String(rows+1);
      }
      if( (s1=String(o2.style))!=="undefined" && s1!=='' ) {  // adjust top for obj
	if ( o2.style.top.match('px') ) o2.style.top = hei + round2(o2.style.top.substr(0, o2.style.top.length-2),0) + 'px';
      }
      change_id(o2, hd, hd2, hd3, hd4, hdl);
    }
}

function make_sibling(el, b4orLast) { 
  var obj=fld(el);
  var clone=obj.cloneNode(true);
  if (b4orLast) { obj.parentNode.insertBefore(clone,obj); } else {obj.parentNode.appendChild(clone); }
  return clone;
}

function monthend(obj,tar) {
  y = obj.value.substr(0,4);
  m = obj.value.substr(5,2);
  last = m==2 ? ((y % 4) == 0 ? "29" : "28") :( m==1||m==3||m==5||m==7||m==8||m==10||m==12 ? "31" : "30");
  fld(tar).value = y+"-"+m+"-"+last;
}

function addson(tag) {
  if(rows=v(fld("f"+tag+"s"))) {
    hei = round2(fld('f'+tag+'height').value,0);
    o1 = make_sibling("tag"+tag+"row"+rows, false);
    o1.id = "tag"+tag+"row"+(1+rows);
    hd  = 'f'+tag+'f'+rows+'f';
    hd2 = 'f'+tag+'f'+(1+rows)+'f';
    hd3 = 'f'+tag+'f'+rows+'b'; // button calling js_ask
    hd4 = 'f'+tag+'f'+(1+rows)+'b';
    hdl = hd.length;
    change_id(o1, hd, hd2, hd3, hd4, hdl);
  } else {
// row 1 always there, just display it
    fld("tag"+tag+"row1").style.display='';
    fld("tag"+tag+"alt").style.display='none';
  }
  fld("f"+tag+"s").value = String(++rows);
  return rows;
}

function sayson(obj) {
  
  if(!obj.hasChildNodes()) { alert(" has no son"); return; }
  cnt = obj.childNodes.length;
  txt += obj.id +" has "+ cnt +" children<br>";

  for(i=0; i<cnt; i++) {
    if ( (son = obj.childNodes[i]) !== null ) {
      if ( son.id!==null && son.id!=='' ) {
	txt += "["+i+"] id = " + son.id + "<br>";
      }
    }
  }
}

function askCode(prog, key, fld1, js) {
  pending1 = fld(key);
  pending2 = fld(fld1);
  page2 = fld(prog);
  after_ret = js;
  prog = prog + "&qmode=1";
  if ( page2 != null && !page2.closed ) { 
    if (page2.src != "/?prog=" + prog) page2.src = "/?prog=" + prog;
    page2.style.display = '';
  }
  return false;
}

function retCode(ok, prog, s1, s2) {
  if (ok) {
    if ( pending1 != null) pending1.value=''+s1; 
    if ( pending2 != null) pending2.value=''+s2; 
  }
  page2 = fld(prog);
  if ( page2 != null && !page2.closed ) { 
    page2.style.display = 'none';
  }
  if (after_ret!==null && after_ret!=='') eval(after_ret);
  return false;
}

function hideSelect(toggle) {
  var forms = document.getElementsByTagName("form");
  for(i=0; i<forms.length; i++) {
    var selects = forms[i].getElementsByTagName("select");
    for(j=0; j<selects.length; j++) {
	selects[j].style.visibility = (toggle ==1) ? "hidden" : "visible";
    }
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = parseFloat(obj.offsetLeft)
		curtop = parseFloat(obj.offsetTop)
		while (obj = obj.offsetParent) {
			curleft += parseFloat(obj.offsetLeft)
			curtop += parseFloat(obj.offsetTop)
		}
	}
	return {x:curleft, y:curtop}
}

tag_cnt = 0;
scr = 0;

function disp(n) {
  obj = fld2('tag_but1');
  if (obj===null) return;
  tag_top = 30 + findPos(obj).y
  if(n==-1) n = scr>1 ? scr-1 : 1;
  if(n==-2) n = scr<tag_cnt ? scr+1 : tag_cnt;

  for(i=1; i<=tag_cnt; i++) { 
    oo = fld('tag_but'+i); 
    if (oo!=null) { oo.style.backgroundImage = (i==n) ? 'url(/inc/tag1.gif)' : 'url(/inc/tag0.gif)'; }
    oo = fld('tag'+i);
    if (oo!=null) { 
       oo.style.top = tag_top; oo.style.display = (i==n) ? '' : 'none'; 
    }
  }
  oo = fld2('scr');
  if (oo!==null) oo.value=n;
  scr = n;
}

function open_code(scr, prog, part) {
  var page2 = fld('code'+scr);
//alert('page2 ok');
  if (part.match('!')) { arr = part.split(/!/); part = arr[0]+unicode2url(fld(arr[1]).value); }
  if (part.match('#')) { arr = part.split(/#/); part = arr[0]+unicode2url(fld(arr[1]).value); }
  if (part.match(/\(/)){ part = eval(part); } 
  prog=prog+'&'+part;
  if ( page2 != null && !page2.closed ) { 
    if (page2.src != "/?prog=" + prog) page2.src = "/?prog=" + prog;
    page2.style.display = '';
  }
  return false;
}

function close_code(scr) {
  var page2 = fld('code'+scr);
  if ( page2 != null ) { 
    page2.style.display = 'none';
  }
  return false;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
    }

var ua = navigator.userAgent.toLowerCase() 
chrome = (ua.indexOf("chrome/") != -1) ? 1 : 0;
safari = (chrome==0 && ua.indexOf("safari/") != -1) ? 1 : 0;
ie6 = (chrome==0 && safari==0) ? 1 : 0;

var old_split =  String.prototype.split; 
var my_split = function(seperator) { 
  var result2 = old_split.apply(this, arguments); 
  if (ie6==1) { return result2; }
  var result = [];
  for(var n2=1; n2<result2.length; n2++) result[n2-1] = result2[n2];
  return result 
} 
String.prototype.split2 = my_split; 

var X2={};
X2.eval=function(code){
 if(!!(window.attachEvent && !window.opera)){
  //ie
  execScript(code); 
 }else{
  //not ie
  window.eval(code);
 }
}

String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }

// end main.js
