var TopMenuOffsetX=0;
var TopMenuOffsetY=0;
var LeftMenuOffsetX=0;
var LeftMenuOffsetY=0;
var LanguageMenuOffsetX = 0;
var LanguageMenuOffsetY = 0;
function DIY_Browser() {
 d=document;
 this.agent=navigator.userAgent.toLowerCase();
 this.major = parseInt(navigator.appVersion);
 this.dom=(d.getElementById)?1:0; // true for ie6, ns6
 this.ns=(d.layers);
 this.ns4up=(this.ns && this.major >=4);
 this.ns6=(this.dom&&navigator.appName=="Netscape");
 this.op=(this.agent.indexOf('opera')!=-1&&this.major<7);
 this.opera5=(this.agent.indexOf("Opera 5")>-1);
 this.ie=(d.all);
 this.ie4=(d.all&&!this.dom)?1:0;
 this.ie4up=(this.ie && this.major >= 4);
 this.ie5=(d.all&&this.dom);
 this.ie6=(this.agent.indexOf("msie 6")>-1 && this.dom && !this.opera5)?1:0;
 this.win=((this.agent.indexOf("win")!=-1) || (this.agent.indexOf("16bit")!=-1));
 this.mac=(this.agent.indexOf("mac")!=-1);
}


var oBw = new DIY_Browser();

function getH(o) { var h=0; if (oBw.ns) { h=(o.height)? o.height:o.clip.height; return h; } h=(oBw.op)? o.style.pixelHeight:o.offsetHeight; return h; }
function setH(o,h) { if(oBw.ns) {if(o.clip) o.clip.bottom=h;}else if(oBw.op)o.style.pixelHeight=h;else o.style.height=h; }

function getW(o) { var w=0; if(oBw.ns) { w=(o.width)? o.width:o.clip.width; return w; } w=(oBw.op)? o.style.pixelWidth:o.offsetWidth; return w; }
function setW(o,w) { if(oBw.ns) {if(o.clip) o.clip.right=w;}else if(oBw.op)o.style.pixelWidth=w;else o.style.width=w; }

function getX(o) { var x=(oBw.ns)? o.left:(oBw.op)? o.style.pixelLeft:o.offsetLeft; return x;}
function setX(o,x) { (oBw.ns)? o.left=x:(oBw.op)? o.style.pixelLeft=x:o.style.left=x; }

function getY(o) {  var y=(oBw.ns)? o.top:(oBw.op)? o.style.pixelTop:o.offsetTop; return y;}
function setY(o,y) { (oBw.ie||oBw.dom)? o.style.top=y:(oBw.ns)? o.top=y:o.style.pixelTop=y; }

function getPageX(o) { if(oBw.ns) { var x=(o.pageX)? o.pageX:o.x; return x; } else if (oBw.op) {  var x=0; while(eval(o)) { x+=o.stylo.pixelLeft; e=o.offsetParent; } return x; } else { var x=0; while(eval(o)) { x+=o.offsetLeft; o=o.offsetParent; } return x; } }

function getPageY(o) { if(oBw.ns) { var y=(o.pageY)? o.pageY:o.y; return y; } else if (oBw.op) {  var y=0; while(eval(o)) { y+=o.stylo.pixelTop; o=o.offsetParent; } return y; }  else { var y=0; while(eval(o)) { y+=o.offsetTop; o=o.offsetParent; } return y; } }
//function setPos(o,x,y) { ylib_setX(o,ylib_getPageX(o)+x);ylib_setY(o,ylib_getPageY(o)+y); }
var _euwTimeOut = null;
var _euwCurrentItem = null;
var _euwParentItem = null;

function _EuwMenuItemOut(){
	 var args=_EuwMenuItemOut.arguments;
	 //_euwTimeOut = setTimeout("_EuwShowHideLayers('" + args[0] + "','" + args[1] + "','" + args[2] + "','" + args[3] + "','" + args[4] + "')",100);
   _EuwShowHideLayers(args[0],args[1],args[2],args[3],args[4],args[5]);
}
function _EuwMenuItemOver(){
   var args=_EuwMenuItemOver.arguments;
   //if (args[0]==_euwCurrentItem) clearTimeout (_euwTimeOut);
	 _EuwShowHideLayers(args[0],args[1],args[2],args[3],args[4],args[5]);
   //_euwCurrentItem = args[0];
   //_euwParentItem = args[3];
}

function _EuwInitDivPosition(){
  //0--src id,1-div id,2-direct,3-offset
  var args=_EuwInitDivPosition.arguments;
  var objSrc = _EuwGetObj(args[0]);
  var obj = _EuwGetObj(args[1]);
  obj = obj.style;
  if (args[2]=="MAIN_TOP"){
     obj.top = getPageY(objSrc) + objSrc.offsetHeight + TopMenuOffsetY;
     obj.left = getPageX(objSrc) + TopMenuOffsetX;
  }else if (args[2]=="MAIN_LEFT"){
     obj.top = getPageY(objSrc) + LeftMenuOffsetY;
     obj.left = getPageX(objSrc) + objSrc.offsetWidth + LeftMenuOffsetX;
  }else if (args[2]=="LANGUAGE"){
     obj.top = getPageY(objSrc) + objSrc.offsetHeight + LanguageMenuOffsetY;
     obj.left = getPageX(objSrc) + LanguageMenuOffsetX;
  }
}
function _EuwShowHideLayers() { //v3.0
  var i,p,v,vt,obj,args=_EuwShowHideLayers.arguments;
  //for (i=0; i<(args.length-2); i+=3)
  i = 0;
	  if ((obj=_EuwGetObj(args[i]))!=null) {
		   v=args[i+2];
       if (obj.style) { obj=obj.style; vt=(v=='show')?'visible':(v=='hide')?'hidden':v; }
			 /*if (args[i+4]=="MAIN_TOP" || args[i+4]=="MAIN_LEFT" || args[i+4]=="LANGUAGE"){
          var objSrc = _EuwGetObj(args[i+3]);
          if (args[i+4]=="MAIN_TOP"){
		         obj.top = getPageY(objSrc) + objSrc.offsetHeight;
			       obj.left = getPageX(objSrc);
          }else if (args[i+4]=="MAIN_LEFT"){
             obj.top = getPageY(objSrc);
			       obj.left = getPageX(objSrc) + objSrc.offsetWidth;
          }else if (args[i+4]=="LANGUAGE"){
		         obj.top = getPageY(objSrc) + objSrc.offsetHeight;
			       obj.left = getPageX(objSrc) + args[i+5];
          }
			 }*/
		   obj.display = "block";
       obj.visibility=vt;
	  }
}

function _EuwGetObj(n, d) { //v4.01
	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=_EuwGetObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ChgClassOver(objtd, objtype)
{
   if (objtype == "menu") objtd.className = "menuItemOver";
}
function ChgClassOut(objtd, objtype)
{
    if (objtype == "menu") objtd.className = "menuItem";
}

function trim(str) {
    regExp1 = /^ */;
    regExp2 = / *$/;
    return str.replace(regExp1,'').replace(regExp2,'');
}

function EuwWindowClose(){
    opener = null;
    window.close();
}

function EuwGetKeyCode(e){
	var code;
	if (!e) var e = window.event;
	if (e.keyCode){
    code = e.keyCode;
	}else if (e.which){
    code = e.which;
	}
  return code;
}

//-2.36onkeypress
function EuwCheckNum(obj,e)
{
  var code = EuwGetKeyCode(e);
  if ((code<45 || code>57 || code==47) && code!=45 && code!=9 && code!=8) return false;
  if(code==46 && obj.value.indexOf(".")>-1) return false;
  return true;
}

//325onkeypress
function EuwCheckInt(obj,e)
{
  var code = EuwGetKeyCode(e);
  if ((code<48 || code>57) && code!=45 && code!=9 && code!=8) return false;
  return true;
}

/**
* get upload file name
*/
function getFileName(path){
    var tmp = path;
    tmp = tmp.substring(tmp.lastIndexOf("\\")+1);
    tmp = tmp.substring(0,tmp.lastIndexOf("."));
    return tmp;
}
//Open upload
function EuwUploadWindow(url){
    openwindow(url,"EuwWinUpload",400 ,250,"");
}
/**
 * Open window function
 * @param url -- The open object
 * @param name -- The window name
 * @param width -- The window width
 * @param height -- The window height
 * @param options -- The window options
 */
function EuwOpenWindow(url,name,width,height,options){
    openwindow(url, name,width ,height,options);
}

function EuwOpenWindowPos(url,name,width,height,options){
    //var appVer = parseInt(navigator.appVersion);
    var top = 0;
    var left = 0;
    var srcWidth=screen.width-10;
    var srcHeight=screen.height - 57;
    var other="";

    if (options==1){//Left Top
        other="top=0, left=0, screenX=0, screenY=0,";//Netscape
    }else if (options==2){//Right Top
        other="top=0, left=" + (srcWidth-width) + ", screenX=" + (srcWidth-width) + ", screenY=0,";//Netscape
    }else if (options==0){//Center
        other="";
    }else if (options==3){//Left Buttom
        other="top=" + (srcHeight-height) + ", left=0, screenX=0, screenY=" + (srcHeight-height) + ",";//Netscape
    }else if (options==4){//Right Buttom
        other="top=" + (srcHeight-height) + ", left=" + (srcWidth-width) + ", screenX=" + (srcWidth-width) + ", screenY=" + (srcHeight-height) + ",";//Netscape
    }
    openwindow(url, name,width ,height,other);
}

function openwindow( url, winName,width,height,otherproperty)
{
   //width,height
   //otherproperty
   xposition=0; yposition=0;
   if ((parseInt(navigator.appVersion) >= 4 )){
        if (width==1){
            width=screen.width - 10;xposition = 0;
        }else{
            xposition = (screen.width - width) / 2;
        }
           if (height==1){
            height=screen.height - 57;yposition = 0;
        }else{
            yposition = (screen.height - height) / 2 - 15;
        }
        if (yposition < 0 ) yposition = 0;
    }
    theproperty= "width=" + width + ", " + "height=" + height + ", "
        + "screenX=" + xposition + ", " //Netscape
        + "screenY=" + yposition + ", " //Netscape
        + "left=" + xposition + ", " //IE
        + "top=" + yposition + ", "; //IE

    theproperty = theproperty + "location=0, "
        + "menubar=0, "
        + "resizable=0, "
        + "scrollbars=1, "
        + "status=0, "
        + "toolbar=0, "
        + "hotkeys=0, ";
    theproperty = theproperty + ', ' + otherproperty;
    winobj=window.open( url,winName,theproperty );
    return winobj;
}
function EuwSelect(sel,ddl){
    var selectType = ddl.value;
    var obj=sel;
    ddl.options[0].selected=true;
    if(obj){
        if(obj.length==null){
            if (!obj.disabled){
            switch (selectType){
                case "all":
                    obj.checked=true;
                    break;
                case "invert":
                    obj.checked=!obj.checked;
                    break;
                case "none":
                    obj.checked=false;
                    break;
            }
            }
        }else{
            for (var i = 0 ; i< obj.length ; i++){
                if (!obj[i].disabled){
                switch (selectType){
                    case "all":
                        obj[i].checked=true;
                        break;
                    case "invert":
                        obj[i].checked=!obj[i].checked;
                        break;
                    case "none":
                        obj[i].checked=false;
                        break;
                }
               }
            }
        }
    }
}

function EuwCheckSelected(sel){
    var obj = sel;
    var check=false;
    if(obj){
        if(obj.length==null){
            check = obj.checked;
        }else{
          for(var i=0;i<obj.length;i++){
            if (obj[i].checked){
                check = true;
                break;
            }
          }
        }
    }
    return check;
}
/**
 * Clear the object in the form
 * @param obj -- The object in the form
 */
function EuwClearObject(obj){
    obj.value = "";
}

/**
 * Get file's extends
 */
function getFileExt(path){
    var tmp = path;
    tmp = tmp.substring(tmp.lastIndexOf(".")+1);
    return tmp.toUpperCase();
}

/**
 * Check file's extends name in extList
 */
function EuwCheckExt(path,extList){
    var ext = getFileExt(path);
    extList = extList.toUpperCase();
    var cExt = extList.indexOf("," + ext + ",");
    if (ext == "") return -1;
    if (cExt==-1){
        return 0;
    }else{
        return 1;
    }
}

function EuwResizeRatio(maxWidth,maxHeight,objImgTmp)
{
    var hRatio;
    var wRatio;
    var Ratio = 1;
    var isKernel = true;
		var objImg = _EuwGetObj(objImgTmp);
    if (objImg==null) {isKernel = false};
    if (isKernel && objImg.width==0) {isKernel = false};
    var width = 0;
    var height = 0;
    if (isKernel){
        var imgTmp = new Image();
        imgTmp.src = objImg.src;
        width = imgTmp.width;
        height = imgTmp.height;
        wRatio = EuwStr2Float(maxWidth / width,2);
        hRatio = EuwStr2Float(maxHeight / height,2);
        //alert(wRatio + "--" + hRatio);
        if (maxWidth==0){//
            if (hRatio<1) Ratio = hRatio;
        }else if (maxHeight==0){
            if (wRatio<1) Ratio = wRatio;
        }else if (wRatio<1 || hRatio<1){
            Ratio = (wRatio<=hRatio?wRatio:hRatio);
        }
        width = width * Ratio;
        height = height * Ratio;
        if (Ratio<1){
 	       objImg.width = width;
    	   objImg.height = height;
        }else{
 	       objImg.width = imgTmp.width;
    	   objImg.height = imgTmp.height;
        }
    }else{
        var timer=window.setTimeout("EuwResizeRatio(" + maxWidth + "," + maxHeight + ",'" + objImgTmp + "')",100);
    }
}

function EuwStr2Float(as_str,ai_digit,as_type)
{
   var fdb_tmp = 0;
   var fi_digit = 0;
   var fs_digit = "1";
   var fs_str = "" + as_str;
   var fs_tmp1 = "";
   var fs_tmp2 = "";
   var fi_pos = 0;
   var fi_len = 0;
   fdb_tmp = parseFloat(isNaN(parseFloat(fs_str))?0:fs_str);

   switch (true)
   {
      case (ai_digit==null)://
         fdb_tmp = fdb_tmp;
         break;
      case (ai_digit==0)://
         fdb_tmp = Math.round(fdb_tmp);
         break;
      case (ai_digit>0)://
         for (var i=0;i<ai_digit;i++) fs_digit +="0";
         fi_digit = parseInt(fs_digit);
         fdb_tmp = Math.round(fdb_tmp * fi_digit) / fi_digit;
         if (as_type=="str")
         {
            fs_tmp1 = fdb_tmp.toString();
            fs_tmp1 +=((fs_tmp1.indexOf(".")!=-1)?"":".") + fs_digit.substr(1);
            fi_pos = fs_tmp1.indexOf(".") + 1 + ai_digit;
            fdb_tmp = fs_tmp1.substr(0,fi_pos);
         }
         break;
   }
   return fdb_tmp;
}

var TEMPLATE_STATUS_BAR_TEXT ="Welecome to our website !";
var TEMPLATE_PLACE=1;
function templateScrollIn() {
    window.status=TEMPLATE_STATUS_BAR_TEXT.substring(0, TEMPLATE_PLACE);
    if (TEMPLATE_PLACE >= TEMPLATE_STATUS_BAR_TEXT.length) {
        TEMPLATE_PLACE=1;
        window.setTimeout("templateHelpor_net()",200);
    } else {
        TEMPLATE_PLACE++;
        window.setTimeout("templateScrollIn()",100);
    }
}
function templateHelpor_net() {
    window.status=TEMPLATE_STATUS_BAR_TEXT.substring(TEMPLATE_PLACE, TEMPLATE_STATUS_BAR_TEXT.length);
    if (TEMPLATE_PLACE >= TEMPLATE_STATUS_BAR_TEXT.length) {
        TEMPLATE_PLACE=1;
        window.setTimeout("templateScrollIn()", 200);
    } else {
        TEMPLATE_PLACE++;
        window.setTimeout("templateHelpor_net()", 100);
    }
}

function OnM(){
  var offLink = _EuwGetObj("musicOffLink");
  var onLink = _EuwGetObj("musicOnLink");
  parent.EuwFrameLeft.RunM();
  offLink.style.display='';
  onLink.style.display='none';
}
function OffM(){
  var offLink = _EuwGetObj("musicOffLink");
  var onLink = _EuwGetObj("musicOnLink");
  parent.EuwFrameLeft.StopM();
  offLink.style.display='none';
  onLink.style.display='';
}
function InitOnOffMusic(){
  var offLink = _EuwGetObj("musicOffLink");
  var onLink = _EuwGetObj("musicOnLink");
  if (offLink!=null){
    if (parent.frames[1].isMusicPlay==1){
      offLink.style.display='';
      onLink.style.display='none';
    }else{
      offLink.style.display='none';
      onLink.style.display='';
    }
  }
}

function isEmail(mail) {
  return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
