var xmlhttp;
var tmo = new Array();
var lsq = new Array();

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

function setHome()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  document.body.setHomePage(document.location.href);
 
    }
    else if (window.sidebar)
    {
    if(window.netscape)
    {
         try
   {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
         }  
         catch(e)  
         {  
    alert("This action was aviod by your browser.\n\nIf you want to enable，please enter about:config in your address line.\n\nThen change the value of signed.applets.codebase_principal_support to true");  
         }
    } 
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',document.location.href);
 }
	return false;
}

function get(obj) {
// if(!alx()) return false;
if(typeof alx == 'function') {if(!alx()) return pIncomp();}
clearTimeout(tmo[obj.id]);
ls_status_searching(obj.id);
  var getstr = "";
  for (i=0; i<obj.getElementsByTagName("input").length; i++) {
        if (obj.getElementsByTagName("input")[i].type == "text") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "button") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "submit") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "hidden") {
           getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "checkbox") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           } else {
              getstr += obj.getElementsByTagName("input")[i].name + "=&";
           }
        }
        if (obj.getElementsByTagName("input")[i].type == "radio") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   obj.getElementsByTagName("input")[i].value + "&";
           }
     }  
     if (obj.getElementsByTagName("input")[i].tagName == "SELECT") {
        var sel = obj.getElementsByTagName("input")[i];
        getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
     }
     
  }
  for (i=0; i<obj.getElementsByTagName("select").length; i++) {
        var sel = obj.getElementsByTagName("select")[i];
	getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
  }
  for (i=0; i<obj.getElementsByTagName("textarea").length; i++) {
	getstr += obj.getElementsByTagName("textarea")[i].name + "=" + encodeURIComponent(obj.getElementsByTagName("textarea")[i].value) + "&";
  }
if (document.getElementById(obj.target)) {
	document.getElementById(obj.target).innerHTML = '<div style="background:transparent url(\''+webbase+'_pub/images/loader.gif\') left center no-repeat; height: 24px;"></div>';
//	document.getElementById(obj.target).innerHTML = '<img height="16" width="16" border="0" src="'+webbase+'_pub/images/loader.gif">';
}
if (obj.method == "post") makePOSTRequest(obj.action, getstr, obj.target,obj.id);
else makeRequest(obj.action, "?"+getstr, obj.target,obj.id);
return false;
}

function makePOSTRequest(url, parameters,target,id) {
      xmlhttp = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlhttp = new XMLHttpRequest();
         if (xmlhttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlhttp.overrideMimeType('text/xml');
            xmlhttp.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlhttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      xmlhttp.onreadystatechange = function() {stateChanged(id,target);};
      xmlhttp.open('POST', url, true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlhttp.setRequestHeader("Content-length", parameters.length);
      xmlhttp.setRequestHeader("Connection", "close");
      xmlhttp.send(parameters);
   }

   function makeRequest(url, parameters,target,id) {
      xmlhttp = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         xmlhttp = new XMLHttpRequest();
         if (xmlhttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //xmlhttp.overrideMimeType('text/xml');
            xmlhttp.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!xmlhttp) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      xmlhttp.onreadystatechange = function() {stateChanged(id,target);};
      xmlhttp.open('GET', url + parameters, true);
      xmlhttp.send(null);
   }


function ls_status_searching(id) {
//	document.getElementById(id+"_st").value=lsearching;
	if(document.getElementById(id+"_stx")) {
		document.getElementById(id+"_stx").style.visibility='visible';
		document.getElementById(id+"_stx").style.display='';
	}
	if(document.getElementById(id+"_st")) {
		document.getElementById(id+"_st").disabled='disabled';
		document.getElementById(id+"_st").style.display='none';
	}
}
function ls_status_reset(id) {
//	document.getElementById(id+"_st").value=btnsearch;
//	if(typeof(document.getElementById(id+"_wwf")) == 'object') document.getElementById(id+"_wwf").innerHTML ="";
	if(document.getElementById(id+"_wws")) document.getElementById(id+"_wws").innerHTML ="";
	if(document.getElementById(id+"_r")) document.getElementById(id+"_r").innerHTML = "";
	if(document.getElementById(id+"_stx")) {
		document.getElementById(id+"_stx").style.visibility='hidden';
		document.getElementById(id+"_stx").style.display='none';
	}
	if(document.getElementById(id+"_st")) {
		document.getElementById(id+"_st").disabled='';
		document.getElementById(id+"_st").style.display='';
	}
}

function initResult(id,as) {
clearTimeout(tmo[id]);
ls_status_reset(id);
tmo[id]=setTimeout("get(document.getElementById('"+id+"'))",as);
}
function getWebWidget(id,app,wid) {
/*
	makeRequest(webbase + app +"/", "?u[webwidget_id]="+wid,id+"_wwf",id);
	document.getElementById(id+"_wwf").setAttribute("class","container themecontrast topfade");
*/
	makeRequest(webbase + app +"/", "?u[webwidget_id]="+wid,id+"_wwf",wid);
	return false;
}


function stateChanged(id,ido)
{
if (xmlhttp.readyState==4)
  {
  if (id) ls_status_reset(id);
	if (xmlhttp.responseText == "Not found") document.getElementById(ido).innerHTML = '<div class="warning">' + drx_nomatchfound + '</div>';
	else document.getElementById(ido).innerHTML=xmlhttp.responseText;
	if (xmlhttp.responseText) {
/*
  document.getElementById(id+"_r").style.border="1px solid #E0E0DA";
  document.getElementById(id+"_r").style.backgroundColor="#fff";
  document.getElementById(id+"_r").style.padding="10px 20px";
  document.getElementById(id+"_r").style.margin="10px 0px";
*/
}
	if (xmlhttp.responseText.indexOf('<!--hide_form-->') > -1) {
		document.getElementById(id+"_form").innerHTML = "";
		document.getElementById(id+"_form").style.visibility = "hidden";
/*		alert('clear');*/
	}
  }
}
/*
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
*/
function drx_overlay(m){
	var thediv=document.getElementById('drx_ol');
	if(m == ""){
		thediv.style.display = "none";
		thediv.innerHTML = '';
	}else{
		thediv.style.display = "";
//		thediv.innerHTML = "<div id='drx_oli'><br><br><a href='#' onclick='return drx_overlay();'>Close</a></div>";
		if (thediv.innerHTML == "") thediv.innerHTML = "<div id='drx_olo'><div id='drx_oli'></div></div>";
//		document.getElementById('drx_oli').innerHTML = document.getElementById(m+"_h").innerHTML.replace(/(<([^>]+)>)/ig,"")+"<br/>"+document.getElementById('drx_oli').innerHTML;
		document.getElementById('drx_oli').innerHTML = m+"<br/>"+document.getElementById('drx_oli').innerHTML;
		document.getElementById('drx_oli').style.marginTop = Math.max(0,Math.floor((browserInnerHeight()-240)/2)) + "px";

	}
	return false;
}

function browserInnerHeight() {
	myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
 return myHeight;
}
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
		var expires_date = new Date( today.getTime() + (expires) );
	}
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

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 select_all(obj) {
obj.focus();
obj.select();
/*
if(window.clipboardData){ var r=clipboardData.setData('Text',obj.value); return 1; } else return 0;
*/
} 


function sel(node)
{
var selection, range, doc, win;

var strPattern = /^([0-9A-F]){6}$/;
if (strPattern.test(node.innerHTML)) {
	var hex = node.innerHTML;
	var rgb = [parseInt('0x' + hex.substring(0, 2)),parseInt('0x' + hex.substring(2, 4)),parseInt('0x' + hex.substring(4, 6))];
	node.innerHTML = "<ul><li>"+hex+"<ul style='background:#"+hex+";bordery: 1px outset #"+hex+";border-top:3px solid #fff;border-bottom:3px solid #000;border-left:1px solid #fff;border-right:1px solid #000;'><li onmouseover='selcx(this);'> "+hex+"</li><li onmouseover='selcx(this);'>#"+hex+"</li><li onmouseover='selcx(this);'>R: "+rgb[0]+", G: "+rgb[1]+", B: "+rgb[2]+"</li><li onmouseover='selcx(this);'>rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")</li><li onmouseover='selcx(this);'>rgb("+Math.round((rgb[0]/255*100),0)+"%, "+Math.round((rgb[1]/255*100),0)+"%, "+Math.round((rgb[2]/255*100),0)+"%)</li></ul></li></ul>";
	return false;
}
}
function selcx(node)
{
var selection, range, doc, win;

if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof
win.getSelection != 'undefined' && typeof doc.createRange !=
'undefined' && (selection = window.getSelection()) && typeof
selection.removeAllRanges != 'undefined')
{
range = doc.createRange();
range.selectNode(node);
selection.removeAllRanges();
selection.addRange(range);
}
else if (document.body && typeof document.body.createTextRange !=
'undefined' && (range = document.body.createTextRange()))
{
range.moveToElementText(node);
range.select();
}
if (node.title == "") node.title = "Press CTRL + C to copy '" + node.innerHTML.replace(/(<([^>]+)>)/ig,"") + "' to clipboard";
}


/*
function clearSelection ()
{
if (document.selection)
document.selection.empty();
else if (window.getSelection)
window.getSelection().removeAllRanges();
}
*/
