var MyWidth = 0, MyHeight = 0;
var LoadWidth = 0, LoadHeight = 0;
   var UpToTenFlashDomain='http://www.uptoten.com/';
   var UpToTenDomain='http://www.uptoten.com/';
function getAvailableWindowSize() {

        if( typeof( window.innerWidth ) == 'number' ) {
                MyWidth = window.innerWidth; MyHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
                MyWidth = document.documentElement.clientWidth; MyHeight = document.documentElement.clientHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                MyWidth = document.body.clientWidth; MyHeight = document.body.clientHeight;
        }

}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
        browser = "Konqueror";
        OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
        browser = "Netscape Navigator"
        version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac"
        else if (checkIt('win')) OS = "Windows"
        else OS = "an unknown operating system";
}
//alert(browser);

function checkIt(string)
{
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}


function maximiseWin() {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
         window.resizeTo(aw, ah);
         window.moveTo(0, 0);

  }
}


function writeLoadSWFCode(AdWidth, AdHeight,StringVar) {
    // maximiseWin();
     getAvailableWindowSize();
     //If not near maximized, set the values
     if(MyWidth<screen.availWidth-30){
       MyWidth=screen.availWidth;
     }
     if(MyHeight<screen.availHeight*0.7){
       MyHeight=screen.availHeight*0.7;
     }

   if (browser == "Safari" || browser == "Netscape Navigator" ){
     // 5 is good for Netscape. 6 is good for Firefox
     MyWidth=MyWidth-14;
     MyHeight=MyHeight-14;
      // alert(browser);
    }

     MyWidth -= AdWidth;
    // alert("PossWidth=" + MyWidth + " PossHeight=" + MyHeight);
    // use the height as the basis for calculation, then adapt width...
     LoadWidth =  MyWidth;
     LoadHeight = MyHeight;
 if(LoadWidth > LoadHeight*1.6){
 // height is at max - set width according to that
    LoadWidth =  LoadHeight*1.6;
 } else if(LoadWidth < LoadHeight*1.25){
     ///width is at max - calculkate the height that goes wityh it
     LoadHeight=LoadWidth/1.25;
 }

    //  alert("LoadWidth=" + LoadWidth + " LoadHeight=" + LoadHeight);
    //Force it to use our servers
    //DO NOT USE AN EXTRA VAR WITH A ? On a mac the passing vars system doesn't work anymore like that !'
     PathToFile = '/load3_82.swf';
   writeSWFCode(PathToFile, StringVar,'load_UpToTen', LoadWidth, LoadHeight);
}

function writeFullscreenSWFCode(PathToFile,StringVar){

  getAvailableWindowSize();
  //Set mins and maxs
 if(MyWidth > (MyHeight*1.5)){
  MyWidth=MyHeight*1.425;
 }else if(MyWidth < (MyHeight*1.2)){
  MyWidth=MyHeight*1.2;
 }
  writeSWFCode(PathToFile, StringVar,'load_UpToTen', MyWidth, MyHeight);

}

function writeIndexSWFCode(PathToFile,StringVar){

  getAvailableWindowSize();
  if (browser == "Safari" || browser == "Netscape Navigator" ){
    MyWidth -= 15;
  }
  MyHeight = MyWidth*0.5128;
  writeSWFCode(PathToFile,StringVar, 'indexMovie', MyWidth, MyHeight);
}


function writeFillScreenWidthSWFCode(PathToFile,StringVar,MarginWidth, MovieWidth,MovieHeight){

  getAvailableWindowSize();
  if (browser == "Safari" || browser == "Netscape Navigator" ){
    MyWidth -= 15;
  }
   MyWidth -= MarginWidth;
  MyHeight = MyWidth*(MovieHeight/MovieWidth);
  writeSWFCode(PathToFile,StringVar + '&MovieWidth=' + MyWidth, 'mainMovie', MyWidth, MyHeight);
}
/*****************************************************************
* Flash Fix script
* Fixes embedded object activation issues in Internet Explorer
*****************************************************************/
function writeSWFCode(movie,var_string , movie_name, width, height, bgcolor,flash_align,flash_menu,flash_scale,flash_wmode,flash_version,flash_hspace,flash_vspace){
    //check for domain name... if none, use flash
   var HasProtocol=movie.indexOf('http://');
   if(HasProtocol==-1){
    movie=UpToTenFlashDomain + movie;
   }
   //  alert (movie);
   if(bgcolor == '' || bgcolor == undefined){
   //Default color is white... WHen the BG color to a movie is a color, the Background to any print job will be that color too !
    bgcolor = '#FFFFFF';
   }
   if(flash_version == '' || flash_version == undefined){
    flash_version = '6,0,29,0';
   }
   if(flash_align == '' || flash_align == undefined){
    flash_align = 'middle';
   }
   if(flash_menu == '' || flash_menu == undefined){
    flash_menu = 'false';
   }
   if(flash_hspace == '' || flash_hspace == undefined){
    flash_hspace = '0';
   }
   if(flash_vspace == '' || flash_vspace == undefined){
    flash_vspace = '0';
   }

   if(flash_wmode == '' || flash_wmode == undefined){
    flash_wmode_object='';
    flash_wmode_embed='';
   }else{
    flash_wmode_object='<PARAM NAME="wmode" VALUE="'+flash_wmode+'">';
    flash_wmode_embed=' wmode="'+flash_wmode+'" ';
   }
   if(flash_scale == '' || flash_scale == undefined){
    flash_scale='exactfit';
   }
  if(OS=='Mac' && browser=='Safari'){
  //Safari does not accept Flash Vars.
  //It also bugs when the embed tag is there. After 10 reloads...
  //The javascript is activated but the flash does not display
    //If show only object tag, it seems to work 100%
   flash_code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flash_version+'" name="'+movie_name+'" width="'+width+'" height="'+height+'" hspace="'+flash_hspace+'" vspace="'+flash_vspace+'" id="'+movie_name+'" align="'+flash_align+'"><param name="movie" value="'+movie+'?'+ var_string +'"><param name="quality" value="high"><param name="SCALE" value="'+flash_scale+'"><PARAM NAME="AllowScriptAccess" VALUE="always"><param name="BGCOLOR" value="'+bgcolor+'"><PARAM NAME="menu" VALUE="'+flash_menu+'">'+flash_wmode_object+'</object>';
  }else{
   flash_code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flash_version+'" name="'+movie_name+'" width="'+width+'" height="'+height+'" hspace="'+flash_hspace+'" vspace="'+flash_vspace+'" id="'+movie_name+'" align="'+flash_align+'"><param name="movie" value="'+movie+'"><PARAM NAME=FlashVars VALUE="'+ var_string +'"><param name="quality" value="high"><param name="SCALE" value="'+flash_scale+'"><PARAM NAME="AllowScriptAccess" VALUE="always"><param name="BGCOLOR" value="'+bgcolor+'"><PARAM NAME="menu" VALUE="'+flash_menu+'">'+flash_wmode_object+'<embed src="'+movie+'"  FlashVars="'+ var_string +'" width="'+width+'" height="'+height+'" hspace="'+flash_hspace+'" vspace="'+flash_vspace+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" scale="'+flash_scale+'" AllowScriptAccess="always" menu='+flash_menu+' name="'+movie_name+'" bgcolor="'+bgcolor+'" '+flash_wmode_embed+' align="'+flash_align+'"></embed></object>';
   }
   document.write(flash_code);
  // alert(flash_code);
}

function makeTop(){
  if(top != self){
    top.location= location;
  }
}
//****************************************************************************************************************************************
function bookmarkFunction(url, description,alertText){
  if (browser == "Internet Explorer") {
   if(OS=='Mac'){
    alert(alertText);
   }else{
    window.external.AddFavorite(url, description);
   }
  }else {
    alert(alertText);
  }
}
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function load_UpToTen_DoFSCommand(command, args) {
  var load_UpToTenObj = InternetExplorer ? load_UpToTen : document.load_UpToTen;

  //
  // Place your code here...
//********************************************************************************************************
        switch(command){
          case "bookmark":
           params = args.split("^") ;
           var BookmarkURL= params[0];
           var BookmarkText= params[1];
           var LanguageDir= params[2];

           if(LanguageDir=='fr'){
             if( browser == "Opera" ){
              var alertText = "Clique sur OK puis sur CTRL+T pour ajouter ce site à tes favoris";
             }else{
              var alertText =  "Clique sur OK puis sur CTRL+D pour ajouter ce site à tes favoris";
             }
           }else{
             if( browser == "Opera" ){
              var alertText = "First push OK and then hit CTRL+T to add a bookmark for this site.";
             }else{
              var alertText =  "First push OK and then hit CTRL+D to add a bookmark for this site.";
             }
           }

           //Send through the alert text and Bookmark code
            bookmarkFunction(BookmarkURL,BookmarkText,alertText);
           break;
        }
//********************************************************************************************************
}
// Hook for Internet Explorer
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
        document.write('<SCRIPT LANGUAGE=VBScript\> \n');
        document.write('on error resume next \n');
        document.write('Sub load_UpToTen_FSCommand(ByVal command, ByVal args)\n');
        document.write('  call load_UpToTen_DoFSCommand(command, args)\n');
        document.write('end sub\n');
        document.write('</SCRIPT\> \n');
}

function replaceContentInParentOpener(URLToLoad){
//alert("gf");
  self.parent.parent.opener.parent.location.href=URLToLoad;

}
function focusContentInParentOpener(){
    window.parent.opener.focus();
}

 var time = new Date();
 var RandomVar = (time.getTime());
 var UpToTenPremiumWindow;
function open_premium_window(LangToUse, PageToLoad, SessionID){

 if(LangToUse == undefined )LangToUse = "en";


 switch(PageToLoad){

      case "Login":

         PremiumLoginURL  = "http://www.uptoten.com/premiumLogin.phtml?cl="+LangToUse+"&y="+SessionID;
         LoginWindowWidth = 800;
         LoginWindowHeight = 600;

         UpToTenPremiumWindow =  window.open(PremiumLoginURL, "UpToTenPremiumWindow","width="+LoginWindowWidth+",height="+LoginWindowHeight+",resizable=yes,status=no,scrollbars=no,menubar=no,toolbar=no,top=0,left=0");

          UpToTenPremiumWindow.focus();

    break;


     case "Demo":

          PremiumURL  = "http://www.uptoten.com/demo.phtml?cl="+LangToUse+"&y="+SessionID;

         LoginWindowWidth = 800;
         LoginWindowHeight = 600;

           UpToTenPremiumWindow =  window.open(PremiumURL, "UpToTenPremiumWindow","width="+LoginWindowWidth+",height="+LoginWindowHeight+",resizable=yes,status=no,scrollbars=no,menubar=no,toolbar=no,top=0,left=0");

          UpToTenPremiumWindow.focus();

    break;
     case "Teachers":

         PremiumURL  = "http://www.uptoten.com/schools.phtml";
         window.location.href=PremiumURL;

     break;
      case "TeachersLogin":

         PremiumLoginURL  = "http://www.uptoten.com/premiumLogin.phtml?cl="+LangToUse+"&y="+SessionID;
         LoginWindowWidth = 800;
         LoginWindowHeight = 600;

         UpToTenPremiumWindow =  window.open(PremiumLoginURL, "UpToTenPremiumWindow","width="+LoginWindowWidth+",height="+LoginWindowHeight+",resizable=yes,status=no,scrollbars=no,menubar=no,toolbar=no,top=0,left=0");

          UpToTenPremiumWindow.focus();

    break;
     case "TeachersSignUp":
         PremiumURL  = "http://www.uptoten.com/premiumTeachers"+ LangToUse +".phtml";

         LoginWindowWidth = 800;
         LoginWindowHeight = 600;

         UpToTenPremiumWindow =  window.open(PremiumURL, "UpToTenPremiumWindow","width="+LoginWindowWidth+",height="+LoginWindowHeight+",resizable=yes,status=no,scrollbars=yes,menubar=no,toolbar=no,top=0,left=0");

         UpToTenPremiumWindow.focus();


    break;
      case "Subscribe":
         PremiumURL  = "http://subscriptions.uptoten.com/premium_subscriptions.php?l="+LangToUse;
         if(window.name == "UpToTenPremiumWindow"){
             window.opener.location.href=PremiumURL;
             window.opener.focus();
             window.close();
         }else if (window.parent.name == "UpToTenPremiumWindow"){
             window.parent.opener.location.href=PremiumURL;
             window.parent.opener.focus();
             window.parent.close();
          }else if (window.parent.parent.name == "UpToTenPremiumWindow"){
             window.parent.parent.opener.location.href=PremiumURL;
             window.parent.parent.opener.focus();
             window.parent.parent.close();
         }else{
            window.location.href=PremiumURL;
         }



    break;
  default :
      PremiumURL  = "http://www.uptoten.com/premium.phtml";
         if(window.name == "UpToTenPremiumWindow"){
             window.opener.location.href=PremiumURL;
             window.opener.focus();
             window.close();
         }else if (window.parent.name == "UpToTenPremiumWindow"){
             window.parent.opener.location.href=PremiumURL;
             window.parent.opener.focus();
             window.parent.close();
          }else if (window.parent.parent.name == "UpToTenPremiumWindow"){
             window.parent.parent.opener.location.href=PremiumURL;
             window.parent.parent.opener.focus();
             window.parent.parent.close();
         }else{
            window.location.href=PremiumURL;
         }
  }
}

function popupInfoWindow(url,popupWindowWidth,popupWindowHeight,popupWindowTop,popupWindowLeft ) {
        if(popupWindowTop==undefined) popupWindowTop=50;
        if(popupWindowLeft==undefined) popupWindowLeft=50;
  window.open(url,'popupInfoWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + popupWindowWidth + ',height=' + popupWindowHeight + ',screenX=50,screenY=50,top=' + popupWindowTop + ',left=' + popupWindowLeft + '');
         popupInfoWindow.focus();
}
function setWindowSize(WindowWidth,WindowHeight){
//Default is fullscreen and 0,0 !
   if(WindowWidth == undefined){
     WindowWidth = screen.availWidth;
   }
   if(WindowHeight == undefined)  {
     WindowHeight = screen.availHeight;
   }

    parent.window.resizeTo(WindowWidth, WindowHeight);

}

function setWindowPos(XPos,YPos){
  //Default is  0,0 !
   if(YPos<1){
     YPos = 0;
   }
   if(XPos<1){
     XPos = 0;
   }
    parent.window.moveTo(XPos, YPos);
}

function historyBackFunction(){
 //history.go(-1);
  history.back();
}

function writeIndividualUnitFunction(UnitVar,TextVar) {
        document.getElementById(UnitVar).innerHTML = TextVar;
}
