/* wikramaratna 
jw02.js contains functions from jw01.js and 20051223cookie.js
      - - -
functions MM_preloadImages(), MM_swapImgRestore(), MM_swapImage() 
functions JW_nw(nwname), JW_vh() 
    - - - 
function xscky(lng), scky(lng), gcky ()  
    - - -
function jw_setdiv()
*/

var ns4 = (document.layers)? true:false ;
var ie4 = (document.all && !document.getElementById)? true:false ;
var ie5 = (document.all && document.getElementById)? true:false ;
var ns6 = (!document.all && document.getElementById)? true:false ; 

function JW_vh() { /* generalised show_hide function */
  var i, args, theObj, theAct;
  args = JW_vh.arguments;
for (i=0; i<(args.length); i+=1) { 
   if ( (args[i]=='visible')  ||  (args[i]=='hidden') ) {
      theAct = args[i];
      if ( (ns4) && (args[i]=='visible') ) { theAct = 'show' };
      if ( (ns4) && (args[i]=='hidden')  ) { theAct = 'hide' };
      }
   else { 
      if (ns4) {
         document.layers[ (args[i]) ].visibility = theAct; 
         } 
      else if (ie4) {
         document.all[ (args[i]) ].style.visibility = theAct; 
         } else 
         { // ie5 || ie6
         document.getElementById( args[i] ).style.visibility = theAct; 
         };
      }
   }
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}

var NewWin = false;
function JW_nw(nwname)
{
	if (navigator.appName == 'Netscape' && oldNav){
		if (!NewWin || NewWin.closed)
		{
		NewWin = window.open(nwname,'New','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,dependent=no,screenX=0,screenY=0,fullscreen=yes,type=fullWindow');
		}
		else NewWin.focus();
	} 
	else {              
        	if (!NewWin || NewWin.closed)
			{
        	NewWin = window.open(nwname,'New','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,dependent=no,screenX=0,screenY=0,fullscreen=yes,type=fullWindow,width='+screen.width+',height='+screen.height+',top=0,left=0');
        	}
        	else NewWin.focus();
        }
}

// - - -

function reloadPage(init) { 
      if (init==true) with (navigator) {
		if ( (appName=="Netscape") && ( (parseInt(appVersion) == 4) || (parseInt(appVersion) == 5) ) ) 
            {
			document.pwidth=innerWidth;
			document.pheight=innerHeight;
			onresize=reloadPage; 
		}
	}
  	else if (innerWidth!=document.pwidth || innerHeight!=document.pheight)
	{	location.reload();
	}
}

reloadPage(true);

// - - - browser detect - - -
var ie = (document.all) ? 1:0;
var ns7 = (document.getElementById) ? 1:0;

if(ie) {     // alert("IExplorer detected"); 
             // document.write("IExplorer detected");
} else { 
     if(ns7) {       
             // document.write("Netscape 7 detected");
     }
     else    {      
             // document.write("Netscape 4.x détected (i.e. not IE nor NS7");
     }
}

//- - - language set/get cookie - - -

var cookielanguage;
var cookievisits = 0; // number of visits 

var is_fr, // french 
    is_en, // english  
    is_az, // all languages requested 
    is_nn ; // none requested or none defined 

var now = new Date();    
      now.setFullYear(now.getFullYear());

var created = new Date(); 
      created.setFullYear(created.getFullYear());

function xscky() { // similar to scky but adds 1 to visits : execute unconditionally on unload
    lng = cookielanguage;
    var nextyear = new Date(); 
    cookievisits = cookievisits +1; //alert("1:"+ cookievisits);
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    document.cookie = "visits=" + cookievisits.toString() + "; path=/; expires=" + nextyear.toGMTString(); 
    document.cookie = "language=" + lng + "; path=/; expires=" + nextyear.toGMTString(); 
    document.cookie = "expiry=" + nextyear.toGMTString() + "; path=/; expires=" + nextyear.toGMTString(); 
    now.setFullYear(now.getFullYear());
    document.cookie = "now=" + now.toGMTString() + "; path=/; expires=" + nextyear.toGMTString();
}

function scky(lng) {
    var nextyear = new Date(); 
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    document.cookie = "visits=" + cookievisits.toString() + "; path=/; expires=" + nextyear.toGMTString(); 
    document.cookie = "language=" + lng + "; path=/; expires=" + nextyear.toGMTString(); 
    document.cookie = "expiry=" + nextyear.toGMTString() + "; path=/; expires=" + nextyear.toGMTString(); 
    now.setFullYear(now.getFullYear());
    document.cookie = "now=" + now.toGMTString() + "; path=/; expires=" + nextyear.toGMTString();
    cookielanguage = lng; 
}

function gcky () {  

var allckys = document.cookie;
var posn = allckys.indexOf("visits=");
var visits = 0;

if (posn != -1) { 
    var strt= posn + 7;
    var end = allckys.indexOf(";", strt );
    if (end == -1) { end = allckys.length; };
    visitstr = allckys.substring(strt, end);
    visits = parseInt(visitstr);               // could be NaN
} else {
    visits = -1; // other problem no visits can be interpreted from cookie
};

if (visits==NaN) {visits = -1;};
cookievisits = visits; //-alert ("2:"+ cookievisits.toString() );

allckys = document.cookie;
posn = allckys.indexOf("language=");
is_fr = is_en = is_az = is_nn = false;

if (posn != -1) { 
    var strt= posn + 9;
    var end = allckys.indexOf(";", strt );
    if (end == -1) { end = allckys.length; };
    cookielanguage = allckys.substring(strt, end);
    if (cookielanguage == "fr") { is_fr=true; }      // french
    else if (cookielanguage == "en") { is_en=true; } // english
    else if (cookielanguage == "az") { is_az=true; alert("is az"); } // all languages requested 
    else { is_nn=true; };                            // none requested or defined 
} else {
    is_nn=true;     // other problem no language can be interpreted from cookie
};
    //alert ("3:"+cookielanguage);

jw_setdiv();        // set DIV visibilities 

}

//- - -

function jw_setdiv(){
/* - - - 20051226 setdiv does nothing for the moment */

}

