﻿//Support Browser:MSIE,FireFox,Opera,Safari,Camino,Gecko
/*
  js generate rule:
  ===========================  
  1.If event parameter is used,event parameter is sure to existed and should not ignored.
  2.Getting object of html should not use the format(parentId.childId).
*/
function getBrowser() 
{ 
   var sBrowserName = "";      
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        sBrowserName = "MSIE"; 
   } 
   if(navigator.userAgent.indexOf("Firefox")>0){ 
        sBrowserName = "Firefox"; 
   } 
   if(navigator.userAgent.indexOf("Opera")>0){ 
        sBrowserName = "Opera"; 
   } 
   if(navigator.userAgent.indexOf("Safari")>0) { 
        sBrowserName = "Safari"; 
   }  
   if(navigator.userAgent.indexOf("Camino")>0){ 
        sBrowserName = "Camino"; 
   } 
   if(navigator.userAgent.indexOf("Gecko/")>0){ 
        sBrowserName = "Gecko"; 
   } 
   return sBrowserName;
}

/*General variant*/
var Browser=getBrowser();
var BrowserVersion = parseFloat(navigator.appVersion)
var LEFTBUTTON=null,RIGHTBUTTON=null,MIDDLEBUTTON=null,NONEBUTTON=null;checkButton();
var COOKIEENABLED=CookieEnabled();
/*
  General function
  =============================
  function getObj(objID)
  function getObjFromParent(objParent,objID)
  function getObjByEvent(evt)
*/

//fetch the html object by ID
function getObj(objID)
{ 
  var obj=null; 
  if (document.getElementById) 
      obj=document.getElementById(objID); 
  else if (document.all) 
      obj=document.all[objID]; 
  return(obj); 
}
//fetch the html object from Parent
function getObjFromParent(objParent,objID)
{ 
  var obj=null; 
  if (document.getElementById) 
      obj=objParent.document.getElementById(objID); 
  else if (document.all) 
      obj=objParent.document.all[objID]; 
  return(obj); 
}
//fetch object from event object
function getObjByEvent(evt) 
{ 
  return(evt.srcElement?evt.srcElement:evt.target); 
}
//Set obj_iFrame auto Resize
function SetWinHeight(obj)
{
 var win=obj;
 if (document.getElementById)
 {
  if (win && !window.opera)
  {
   if (win.contentDocument && win.contentDocument.body.offsetHeight)
    win.height = win.contentDocument.body.offsetHeight;
   else if(win.Document && win.Document.body.scrollHeight)
    win.height = win.Document.body.scrollHeight;
  }
 }
}
//Browser support Cookie
function CookieEnabled() 
{ 
    var result=false; 
    if(navigator.cookiesEnabled) return true; 
    document.cookie = "testcookie=yes;";
    var cookieSet = document.cookie;
    if (cookieSet.indexOf("testcookie=yes") > -1)result=true; 
    document.cookie = "";
    return result;
} 
/*Other function or Special function for General used for different browser*/
function checkButton()
{
  if(Browser=="MSIE")
  {
    NONEBUTTON=0;
    LEFTBUTTON=1;
    RIGHTBUTTON=2;
    MIDDLEBUTTON=4;    
  }
  else if(Browser=="Firefox")
  {
    NONEBUTTON=0;
    LEFTBUTTON=0;
    RIGHTBUTTON=1;
    MIDDLEBUTTON=2;    
  }
  else if(Browser=="Opera")
  { 
    if(BrowserVersion<7)  {
        NONEBUTTON=1;
        LEFTBUTTON=1;
        RIGHTBUTTON=null;
        MIDDLEBUTTON=null;    
    }
    else
    {
        NONEBUTTON=0;
        LEFTBUTTON=0;
        RIGHTBUTTON=null;
        MIDDLEBUTTON=null;    
    }
  }
}

