// Updated on Jun 28, 2008 by patrick@palmgoo.com

// Dreamweaver Function　────────────────────────────────────────────────────────

function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}//End Function

function MM_findObj(n, d) { //v4.0
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
    if(!x && document.getElementById) x=document.getElementById(n); return x;
}//End Function

function MM_showHideLayers() { //v3.0 
    var i,p,v,obj,args=MM_showHideLayers.arguments; 
    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; 
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; } 
    obj.visibility=v; }
}//End Function

function MM_preloadImages() { //v3.0 
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}//End Function

function MM_swapImgRestore() { //v3.0 
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}//End Function

function MM_swapImage() { //v3.0 
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) 
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}//End Function

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}//End Function

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}//End Function

function flevDivPositionValue(sDiv, sProperty) { // v2.1, Marja Ribbers-de Vroed, FlevOOware
    this.opera = (window.opera); // Opera 5+
    this.ns4 = (document.layers); // Netscape 4.x
    this.ns6 = (document.getElementById && !document.all && !this.opera); // Netscape 6+
    this.ie = (document.all);  // Internet Explorer 4+
    var sValue = ""; docObj = eval("MM_findObj('" + sDiv + "')"); if (docObj == null) {return 0;}
    if ((sProperty == "left") || (sProperty == "top")) {
        if (!this.ns4) {docObj = docObj.style;} 
        sValue = eval("docObj." + sProperty);
        if ((this.ie) && (sValue == "")) { // IE (on PC) bug with nested layers
            if (sProperty == "top") { sValue = eval(sDiv + ".offsetTop"); } 
            else { sValue = eval(sDiv + ".offsetLeft"); } 
        };
    }
    else {
        if (this.opera) {
            docObj = docObj.style;
            if (sProperty == "height") { sValue = docObj.pixelHeight; } 
            else if (sProperty == "width") { sValue = docObj.pixelWidth; } 
        }
        else if (this.ns4) {sValue = eval("docObj.clip." + sProperty);} 
        else if (this.ns6) {sValue = document.defaultView.getComputedStyle(docObj, "").getPropertyValue(sProperty); } 
        else if (this.ie) { 
            if (sProperty == "width") { sValue = eval(sDiv + ".offsetWidth"); } 
            else if (sProperty == "height") { sValue = eval(sDiv + ".offsetHeight"); } 
        }
       }
    sValue = (sValue == "") ? 0 : sValue; 
    if (isNaN(sValue)) { if (sValue.indexOf('px') > 0) { sValue = sValue.substring(0,sValue.indexOf('px')); } } 
    return parseInt(sValue); 
}

function flevPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware
    var sD = arguments[0], oD = eval("MM_findObj('" + sD + "')"), iWW, iWH, iSX, iSY, iT = 10, sS = "";
    if (!document.layers) {oD = oD.style;}
    if (oD.tmpTimeout != null) {clearTimeout(oD.tmpTimeout);}
    var sXL = arguments[1], sXC = arguments[2], sXR = arguments[3], sYT = arguments[4], sYC = arguments[5], sYB = arguments[6];
    var iS = (arguments.length > 7) ? parseInt(arguments[7]) : 0, iPx = (arguments.length > 8) ? parseInt(arguments[8]) : 0;
    if (window.innerWidth) { // NS4, NS6 and Opera
        var oW = window; iWW = oW.innerWidth; iWH = oW.innerHeight; iSX = oW.pageXOffset; iSY = oW.pageYOffset; }
    else if (document.documentElement && document.documentElement.clientWidth) { // IE6 in standards compliant mode
        var oDE = document.documentElement; iWW = oDE.clientWidth; iWH = oDE.clientHeight; iSX = oDE.scrollLeft; iSY = oDE.scrollTop; }
    else if (document.body) { // IE4+
        var oDB = document.body; iWW = oDB.clientWidth; iWH = oDB.clientHeight; iSX = oDB.scrollLeft; iSY = oDB.scrollTop; }
    else {return;}
    var iCX = iNX = flevDivPositionValue(sD, 'left'), iCY = iNY = flevDivPositionValue(sD, 'top');
    if (sXL != "") {iNX = iSX + parseInt(sXL);} 
    else if (sXC != "") {iNX = Math.round(iSX + (iWW/2) - (flevDivPositionValue(sD, 'width')/2));}
    else if (sXR != "") {iNX = iSX + iWW - (flevDivPositionValue(sD, 'width') + parseInt(sXR));}
    if (sYT != "") {iNY = iSY + parseInt(sYT);}
    else if (sYC != "") {iNY = Math.round(iSY + (iWH/2) - (flevDivPositionValue(sD, 'height')/2));}
    else if (sYB != "") {iNY = iSY + (iWH - flevDivPositionValue(sD, 'height') - parseInt(sYB));}
    if ((iCX != iNX) || (iCY != iNY)) {
        if (iS > 0) {
            if (iPx > 0) { iT = iS;
                var iPxX = iPx, iPxY = iPx, iMX = Math.abs(iCX - iNX), iMY = Math.abs(iCY - iNY);
                // take care of diagonal movement
                if (iMX < iMY) {iPxY = (iMX != 0) ? ((iMY/iMX)*iPx) : iPx;}
                else {iPxX = (iMY != 0) ? ((iMX/iMY)*iPx) : iPx;}
                if (iPxX >= iMX) {iPxX = Math.min(Math.ceil(iPxX), iPx);}
                if (iPxY >= iMY) {iPxY = Math.min(Math.ceil(iPxY), iPx);}
                // temporary X/Y coordinates
                if ((iCX < iNX) && (iCX + iPxX < iNX)) {iNX = iCX + iPxX;}
                if ((iCX > iNX) && (iCX - iPxX > iNX)) {iNX = iCX - iPxX;}
                if ((iCY < iNY) && (iCY + iPxY < iNY)) {iNY = iCY + iPxY;}
                if ((iCY > iNY) && (iCY - iPxY > iNY)) {iNY = iCY - iPxY;} }
            else { 
                var iMX = ((iNX - iCX) / iS), iMY = ((iNY - iCY) / iS); 
                iMX = (iMX > 0) ? Math.ceil(iMX) : Math.floor(iMX); iNX = iCX + iMX; 
                iMY = (iMY > 0) ? Math.ceil(iMY) : Math.floor(iMY); iNY = iCY + iMY; } }
        if ((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
        if (iMX != 0) {eval("oD.left = '" + iNX + sS + "'");}
        if (iMY != 0) {eval("oD.top = '" + iNY + sS + "'");} }
    var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
    oD.tmpTimeout = setTimeout(sF,10);
}

function flevInitPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware
    if (arguments.length < 8) {return;}
    var sD = arguments[0]; if (sD == "") {return;}
    var    oD = eval("MM_findObj('" + sD + "')"); if (!oD) {return;}
    var iCSS = parseInt(arguments[1]);
    var sXL = arguments[2], sXC = arguments[3], sXR = arguments[4], sYT = arguments[5], sYC = arguments[6], sYB = arguments[7];
    var iS = (arguments.length > 8) ? parseInt(arguments[8]) : 0, iPx = (arguments.length > 9) ? parseInt(arguments[9]) : 0;
    if (iCSS != 0) { if (!document.layers) {oD = oD.style;} sXL = parseInt(oD.left), sYT = parseInt(oD.top);}
    var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
    eval(sF);
}

//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Browsing Functions
// --------------------------------------------------------------------------------------------------------------------------------------------------------------
 function ChangeMenu(obj) {
      // Pull Down Menu
      var myIndex = obj.selectedIndex
      var myValue = obj.options[myIndex].value

      if(myValue != '') {
          document.location = myValue
      }
 }//End Function

function PopUpWin(url, WinName, w, h, scrBar, reSize) {
    PopUpWin = window.open(url,WinName,"width=" + w + ",height=" + h + ",directories=no,toolbar=no,status=yes,menubar=no,scrollbars=" + scrBar + ",resize=" + reSize);
    PopUpWin.focus();
}//End Function

// Change Document's Location　────────────────────────────────────────────

function gotoPage(url) {
      document.location = url;
}//End Function

// String Functions　───────────────────────────────────────────────────────

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}//End Function

function Right(str, n) {
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}//End Function

//去除字串左邊的空白虛格
function LTrim(instr){
    return instr.replace(/^[\s]*/gi,"");
}//End Function

//去除字串右邊的空白虛格
function RTrim(instr){
    return instr.replace(/[\s]*$/gi,"");
}//End Function

//去除字串前後的空白虛格
function Trim(instr){
    instr = LTrim(instr);
    instr = RTrim(instr);
    return instr;
}//End Function

// Resize Windows　──────────────────────────────────────────────────────────
// Max Width & Height

function ResizeWin(section) {
    var w = screen.availWidth;
    var h = screen.availHeight;
    window.resizeTo(w,h);

    var x=(screen.availWidth-w)/2;
    var y=(screen.availHeight-h)/2;
    window.moveTo(x,y);
}//End Function

// Change Text on Browser's Status Bar ────────────────────────────────────────

 function writeStatus(msg) {
    window.status = msg;
    var nextStep = setTimeout("clearStatus()",4000);
 } // End of function

 function clearStatus(msg) {
    window.status = "";
 } // End of function

// Change Navigation / Menubar color ────────────────────────────────────────

 var menuBgColorOver_1 = "#EADFD0";
 var menuBgColorOut_1 = "#FFFFFF";
 
 function menuOver(obj) {
    obj.style.backgroundColor = menuBgColorOver_1;
 } // End of function

 function menuOut(obj) {
    obj.style.backgroundColor = menuBgColorOut_1;
 } // End of function

//-------------------------------
// Fading Functions

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    //opacity:0; filter:alpha(opacity=0); 
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
    else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}//End Function

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}//End Function

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } 
    else {
        opacity(id, 100, 0, millisec);
    }
}//End Function

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src=imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
}//End Function

function currentOpac(id, opacEnd, millisec) {
    //standard opacity is 100
    var currentOpac = 100;
    
    //if the element has an opacity set, get it
    if(document.getElementById(id).style.opacity < 100) {
        currentOpac = document.getElementById(id).style.opacity * 100;
    }

    //call for the function that changes the opacity
    opacity(id, currentOpac, opacEnd, millisec)
}//End Function

//find next image
function nextImage(thisIMG) {
    do thisIMG = thisIMG.nextSibling;
    while(thisIMG && thisIMG.tagName != 'IMG');
    return thisIMG;
}//End Function

//find first image inside an element
function firstChildImage(thisIMG) {
    
    thisIMG = thisIMG.firstChild;
        
    while(thisIMG && thisIMG.tagName != 'IMG') {
        thisIMG = thisIMG.nextSibling;
    }
    
    return thisIMG;
}//End Function

//set the opacity of an element to a specified value
function setOpacity(obj, thisIMG) {

    obj.style.opacity = (thisIMG / 100);
    obj.style.MozOpacity = (thisIMG / 100);
    obj.style.KhtmlOpacity = (thisIMG / 100);
    obj.style.filter = 'alpha(opacity=' + thisIMG + ')';
}//End Function

//make image invisible and set next one as current image
function getNextImage(image) {
    
    if (next = nextImage(image)) {
        image.style.display = 'none';
        image.style.zIndex = 0;

        next.style.display = 'block';
        next.style.zIndex = 100;
    } 
    else {
        //if there is not a next image, get the first image again
        next = firstChildImage(image.parentNode);
    }

    return next;
}//End Function

//set default values for parameters and starting image
function blendImages(id, speed, pause, caption) {

    if(speed == null) { speed = 30;   }
    if(pause == null) { pause = 1500; }

    var blend = document.getElementById(id);
    var image = firstChildImage(blend);

    startBlending(image, speed, pause, caption);
}//End Function

//make image a block-element and set the caption
function startBlending(image, speed, pause, caption) {

    image.style.display = 'block';

    if(caption != null) {
       document.getElementById(caption).innerHTML = image.alt;
    }

    continueFadeImage(image, 0, speed, pause, caption);
}//End Function

// ASC: copied from http://www.sean.co.uk/a/webdesign/javascriptdelay.shtm
function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
}//End Function 

//set an increased opacity and check if the image is done blending
function continueFadeImage(image, opacity, speed, pause, caption) {

    opacity = opacity + 3;

    if (opacity < 103) {
        setTimeout(function() {fadeImage(image, opacity, speed, pause, caption)}, speed);
    } 
    else {
       //if the image is done, set it to the background and make it transparent
        image.parentNode.style.backgroundImage = "url("+image.src+")";

       //ASC: pause 1sec here to prevent MSIE image flash ...
       var paws=pause-1000;
       if (paws < 0 ) {
           paws = 0;
       }
       pausecomp(1000);

       setOpacity(image,0);
       //get the next image and start blending it again
       image = getNextImage(image);
       setTimeout(function() {startBlending(image, speed, pause, caption)}, paws);        
    }
}//End Function

//set the opacity to a new value and continue the fading
function fadeImage(image, opacity, speed, pause, caption) {
    setOpacity(image,opacity);
    continueFadeImage(image, opacity, speed, pause, caption);
}//End Function

function gotoInquiry(obj) {
    var i = obj.form.menuInquiry.selectedIndex;
    if(i>0) { top.location.href=obj.form.menuInquiry.options[i].value; }
}//End Function

//AC_RunActiveContent.js v1.0 ────────────────────────────────────────
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){    
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":    
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

