var FlashVars = '';

function setCookie (name, value){
  document.cookie = name + '=' + escape(value) + ";path=/;"
}

function getCookie(cookieName){
  var search = cookieName + '=';
  if (document.cookie.length>0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1){
      offset += search.length;
      end     = document.cookie.indexOf(';',offset);
      if(end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset,end));
    }
  }
  return null;
}

function writeFlashFile(w,h,swfFile,quality,bgcolor,movie_id,FlashVars) {
    document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width='+w+' height='+h+' align="middle">');
	document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
    document.writeln('<param name="movie" value='+swfFile+' />');
	if (FlashVars!='') {
	document.writeln('<param name="flashvars" value="res='+FlashVars+'" />');
	}
    document.writeln('<param name="quality" value='+quality+' />');
    document.writeln('<param name="bgcolor" value='+bgcolor+' />');
    document.writeln('<embed src="'+swfFile+'" FlashVars="res='+FlashVars+'" quality="'+quality+'" bgcolor="'+bgcolor+'" width="'+w+'" height="'+h+'" id="'+movie_id+'" name="'+movie_id+'" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.writeln('</object>');
}

function xmlHttpGet(strURL, elementId) {
  var xmlhttp = false;
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest(); //Mozilla/Safari
  } else if (window.ActiveXObject) { //IE
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  if(!xmlhttp) return;
    strURL += (strURL.indexOf('?')>0?'&_rand=':'?_rand') + Math.random();
  xmlhttp.open('GET', strURL, true);
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      var obj = getElementFromName(elementId);
      if(obj) obj.innerHTML= xmlhttp.responseText;
            fixPNGImages(elementId);
    }
  }
  xmlhttp.send(null);
  return;
}

function getXmlhttp(){
  var xmlhttp;

  if(window.XMLHttpRequest) {
        try {
            xmlhttp = new XMLHttpRequest();
    } catch(e) {
            xmlhttp = false;
    }
  } else if(window.ActiveXObject) {
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
       try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       } catch(e) {
            xmlhttp = false;
       }
        }
  }
  return xmlhttp;
}

function openWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function isEmail(email){
    if(!email.match(/.+@.+\..+/)){
      return email;
    }
    return '';
}

function showAlert(args) {
  arg = args.split("#");
  var err_msg = '';
  for (var i = 0; i < arg.length; i ++) {
    err_msg = err_msg + arg[i] + '\n';
  }

  alert(err_msg);
  return;
}

function checkBrowser() {
  myBsr   = navigator.appName;                     // Browser
  myAgent = navigator.userAgent;                   // Agent
  myTop = myAgent.indexOf("Opera",0);           // OP Check
  if (myTop == -1){                                     // Not OP
    myTop = myAgent.indexOf("MSIE",0);         // IE Check
    if (myTop == -1){                                   // NOT IE
       myTop = myAgent.indexOf("Mozilla/",0);        // NN Check
       if (myTop == -1){                             // NOT NN
          myVersion = "";
       }else{                                        // NN
         myLast = myAgent.indexOf(" ",myTop);
         myVer = myAgent.substring(myTop+8,myLast); // NN Version
         myVersion = " Version " + myVer;
      }
    }else{                                           // IE
      myLast = myAgent.indexOf(";",myTop);
      myVer = myAgent.substring(myTop+5,myLast);    // IE Version
      myVersion = " Version " + myVer;
    }
  }else{                                              // OP
    myBsr = "Opera";
    myLast = myAgent.indexOf(" ",myTop+6);
    myVer = myAgent.substring(myTop+6,myLast);       // OP Version
    myVersion = " Version " + myVer;
  }
  //alert("Your browser is "+myBsr+myVersion);
  //return myBsr+myVersion;
  return myBsr;

}

function getSize(args){
  arg = args.split(',');
  windowHeight = arg[0];
  windowWidth = arg[1];
initbox(windowWidth, windowHeight);
        if (parseInt(navigator.appVersion)>3) {
           if (navigator.appName=="Netscape") {
             winW = window.innerWidth;
             winH = window.innerHeight;
           } else if (navigator.appName.indexOf("Microsoft")!=-1) {
             winW = document.body.offsetWidth;
             winH = document.body.offsetHeight;
           }
        }
        
        topPosition =(winH)?(winH-windowHeight)/2:100;
        topPosition = (topPosition>0)?topPosition+50:100;
        leftPosition =(winW)?(winW-windowWidth)/2:100;
        leftPosition = (leftPosition>0)?leftPosition:100;
  //myleft=(screen.width)?(screen.width-windowWidth)/2:100;
  //mytop=(screen.height)?(screen.height-windowHeight)/2:100;
//alert('browser:' + winH + '/popup:' + windowHeight + '/position:' + topPosition);
  return "top="+topPosition+",left="+leftPosition;
}

function popup(args){
  arg = args.split(',');
  url = arg[0];
  windowHeight = arg[1];
  windowWidth = arg[2];
  toolbar = arg[3];
  scrollbar = arg[4];
  myleft=(screen.width)?(screen.width-windowWidth)/2:100;
  mytop=(screen.height)?(screen.height-windowHeight)/2:100;
  properties = "width="+windowWidth+",height="+windowHeight+",toolbar="+toolbar+", scrollbar="+scrollbar+", top="+mytop+",left="+myleft;

  window.open(url,"newWin",properties);
}

function toTop() {
  self.scrollTo(0, 0)
}

//==============================================================
var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;
var calunits=document.layers? "" : "px";
var bouncelimit=32; //(must be divisible by 8)
var direction="up";
var client_top = 0;
//==============================================================

function initbox(windowWidth,windowHeight){

  if (!dom&&!ie&&!ns4) return;
        crossobj=(dom) ? document.getElementById("popup").style : ie ? document.all.popup : document.popup
        if (parseInt(navigator.appVersion)>3) {
           if (navigator.appName=="Netscape") {
             winW = window.innerWidth;
             winH = window.innerHeight;
           } else if (navigator.appName.indexOf("Microsoft")!=-1) {
             winW = document.body.offsetWidth;
             winH = document.body.offsetHeight;
           }
        }
        
        topPosition =(winH)?(winH-windowHeight)/2:100;
        topPosition = (topPosition>0)?topPosition:100;
        crossobj.top= topPosition + "px";
        leftPosition =(winW)?(winW-windowWidth)/2:100;
        leftPosition = (leftPosition>0)?leftPosition:100;
        crossobj.left= leftPosition + "px";
        crossobj.visibility=(dom||ie)? "visible" : "show"

}

function closebox(){
  crossobj=(dom) ? document.getElementById("popup").style : ie ? document.all.popup : document.popup;
   var swf = (dom) ? document.getElementById("news") : ie ? document.all.news : document.news;
    document.getElementById('news').src= "img/ani_logo.jpg";
    document.getElementById('news').src= "news/ani_news_v2.html";
    crossobj.display="none";
}

function truebody(){
  return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}

