/**
 *for different browser,return different object
 *@[parameter]objectId:the element of the html
 *@return:the reffernce to the html element
 *2007/9/14
 */

function  getObject(objectId)  {
          if(document.getElementById  &&  document.getElementById(objectId))  {
        //  W3C  DOM
              return  document.getElementById(objectId);
          }  
          else  if  (document.all  &&  document.all(objectId))  {
        //  MSIE  4  DOM
              return  document.all(objectId);
          }  
          else  if  (document.layers  &&  document.layers[objectId])  {
        //  NN  4  DOM..  note:  this  won't  find  nested  layers
              return  document.layers[objectId];
          }  
          else  {
              return  false;
        }
}  

var  responsecont;
var  xmlHttp;
var  requestType;
var  newsstring;
var cache=[];

/**
 *for different browser,create the different request
 *2007/9/14
 */
function  CreateXMLHttpRequest(){
      //  Initialize  Mozilla  XMLHttpRequest  object
      if  (window.XMLHttpRequest){
              xmlHttp  =  new  XMLHttpRequest();
      }  
      //  Initialize  for  IE/Windows  ActiveX  version
      else  if  (window.ActiveXObject)  {
              try{
                        xmlHttp  =  new  ActiveXObject("Msxml2.XMLHTTP.3.0");
              }  
              catch  (e){
                        try{
                                xmlHttp  =  new  ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch  (e){newsstring  =  "Servers are busying,please try it again later!";}
              }
      }
}
/**
 *send the xmlhttprequest to the server,and wait for the response,
 *@[parameter]tagid: the type of the element
 *@[parameter]x: the element id
 *2007/9/14
 */
function  getnews(tagid,x){
      var  url  =  tagid+'_'+x+'.jsp';
      requestType  =  tagid;
      CreateXMLHttpRequest();      
      
      if(!cache[x]){
		  xmlHttp.onreadystatechange  =  function(){
			  	if(xmlHttp.readyState == 4){
					if(window.location.href.indexOf("http") == -1 || xmlHttp.status == 200){
						newsstring = xmlHttp.responseText;
						cache[x] = newsstring;
						shownews(requestType, newsstring);
					}
				}
		  }
		  xmlHttp.open("GET",  url,  true);
		  xmlHttp.setRequestHeader("If-Modified-Since","0");
		  xmlHttp.send(null); 
	  }
	  else{
		  shownews(requestType, cache[x]);
	  }
}

/**
 *show the data in the interior of the container
 *@[parameter]requestType : the type of the element
 *@[parameter]newsstring : the data of the response
 *2007/9/14
 */
function  shownews(requestType,newsstring){
        responsecont  =  getObject(requestType+'_cnt');
        responsecont.innerHTML  =  newsstring;
}
/**
 *main function,change the menu and show the data of the news 
 *@[parameter]requestType : the type of the element
 *@[parameter]newsstring : the index of the menu
 *2007/9/14
 
function  TabNews(tagid,x){
        for  (var  i=1;i<=5;i+=2)  {
                 if  (i  ==  x)  {
                        document.getElementById(tagid+"img"+i).src="<%=webAppRoot%>/images/" + tagid + x + "_1.gif";
                        try{                        
                              getnews(tagid,i);
                        }
                        catch(e){
                              alert(e);
                        }   
                }
                else
                {
                        document.getElementById(tagid+"img"+i).src="<%=webAppRoot%>/images/" + tagid + i + ".gif";                  
                }                  
      }
}
*/
/**
 *Show the date in the ajaxboard
 */
function printDate() { 

    var today=new Date(); 

    var day=today.getDate(); 

    var month=today.getMonth()+1; 

    var year=today.getFullYear().toString(); 

    var now=document.getElementById("nowDate");

    if((month/10)<1) { 

       month=("0"+month).toString(); 

    }

    if((day/10)<1) { 

       day=("0"+today.getDate()).toString(); 

    }
    now.value=year+"-"+month+"-"+day; 
}

/**
 *First login the homepage
 */
function OnLoad(){
	TabNews("tab",1);
	//printDate();
}

/**
 * Add parameter to search link
 * 2007/9/12
 */
function AddParameter(){
	alink = document.getElementById('searchLink');
	parameter = document.getElementById('searchText').value;
	searchURL = document.getElementById('oosearchURL');
	alink.href = searchURL.href + parameter;
}

/**
 * Bookmark web homepage
 * @param {Object} title:the title of homepage
 * @param {Object} url:the url of homepage
 * 2007/9/12
 */
function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

/**
 * Set homepage
 * 2007/9/12
 */
 function setHomePageInIEorFF()
{
	/*FireFox*/
	if(window.netscape)
	{
		try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		catch (e)
		{
			alert("This operation is refused by the browser!\nplease input \"about:config\" at the address of the browser to open the config of FireFox browser, \nthen set the item[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','http://www.kmwater.cn/');
	}
	/*IE*/
	else
	{
		var strHref=window.location.href;
		a=document.getElementById("setHomepage");
		a.style.behavior='url(#default#homepage)';
		a.setHomePage('http://www.kmwater.cn/');
	}

}
