﻿// open, close and align customize menu
var opencustom = 0;

function getobject(obj) {
  if (document.getElementById)
    return document.getElementById(obj)
  else if (document.all)
    return document.all[obj]
}

function getposOffset(what, offsettype) {
  var obj_id = document.getElementById(what)
  var totaloffset=(offsettype=="left")? obj_id.offsetLeft : obj_id.offsetTop;
  var parentEl=obj_id.offsetParent;

  while (parentEl!=null) {
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}

function pullcustom(obj) {
//  if (document.images['custom'].onclick) {
//  if (document.getElementById('custom').onclick) {
//    if (opencustom) {
//      hidecustom(obj)
//      opencustom = 0
//    } else {
      showcustom(obj)
//      opencustom = 1;
//    }
//  }
  ChkLastSetting();
}

function chkbrowser(obj) {
  if (document.all)
    showcustom(obj)
  else if (document.getElementById) 
    showcustom(obj)
}

function showcustom(obj) {
  //aligncustom(obj)
  document.getElementById('custom_panel').style.visibility="visible";
}

function hidecustom(obj) {
  document.getElementById('custom_panel').style.visibility="hidden";
  opencustom = 0;
}

function aligncustom(obj) {
  var cust, alignX

  cust = getobject("custom_panel")
  cust.x = getposOffset(obj, "left")
  cust.y = getposOffset(obj, "top")

//  cust.style.left = cust.x + 5 + "px"
  if (navigator.appName!="Netscape"){
    if(sLang == "En")
      alignX = 426;
    else
      alignX = 473;  
  }  
  else{
    if(sLang == "En")
      alignX = 518;
    else
      alignX = 540;  
  }
  
  
//  if (document.body.clientWidth > 955)
//    cust.style.left = Math.round((document.body.clientWidth - 955) / 2) + (alignX) + "px"
//  else
      cust.style.left = alignX + "px"
  cust.style.top = cust.y + 13 + "px"
}

// Customize menu control
var ThemesArray = new Array("Blue","Yellow","Green","Purple","Grey","White");
var FontSize,Themes
var FontSize_tagID, FontSize_CSS;
var Themes_tagID, Themes_CSS;

function getDefault(id){
  switch(id){
	case "FontSize" :
	  return 0;
	case "Themes" :
	  return 0;
  }
}

function page_load(){

  if(GetCookie('Themes')!=null) {
    var sBg ="bg_" + ThemesArray[GetCookie('Themes')].toString().toLowerCase();
    document.body.className = sBg;
    document.getElementById("page_body").className = "pagebody " + sBg;
  }
}
page_load();

function ChkLastSetting() {
  if(GetCookie('Themes')!=null) {
	Themes = GetCookie('Themes');
  } else {
	Themes = getDefault("Themes");
  }
  DisplaySetting();
}

function DisplaySetting(){
  for(i=0;i<ThemesArray.length;i++){
	  if(i==Themes)
	    document.getElementById("Img_Themes_" + ThemesArray[i]).src="../../images/custom/"+ThemesArray[i]+"_on.gif";
	  else
	    document.getElementById("Img_Themes_" + ThemesArray[i]).src="../../images/custom/"+ThemesArray[i]+"_off.gif";
  }
}

function SetCSS(id,name){
  if(id=="Themes"){        
	Themes = name;
	for(var i=0;i<ThemesArray.length;i++){
	  if(i==name)
		document.getElementById("Img_Themes_" + ThemesArray[i]).src="../../images/custom/"+ThemesArray[i]+"_on.gif";
	  else
		document.getElementById("Img_Themes_" + ThemesArray[i]).src="../../images/custom/"+ThemesArray[i]+"_off.gif";
	}
  }
  
  SaveAppearance();
}

function SaveAppearance(){
  webTraffic(42,sLang,this.ThemesArray[Themes]);
  SetCookie ("Themes", Themes);	
  page_load();
  ChkLastSetting();
}

function CancelAppearance(){
}

function ResetAppearance(){
  Themes = getDefault("Themes");
}


function SetCookie(name,value)//
{
  var Days = 365; //
  var exp  = new Date();    //new Date("December 31, 9998");
  exp.setTime(exp.getTime() + Days*24*60*60*1000);
  document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
}
function GetCookie(name)// 
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null;
}
function DelCookie(name)//
{
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval=GetCookie(name);
  if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}

function CookieEnable()   {   
  var result=false;   
  if(navigator.cookiesEnabled)  return true;  
    
  SetCookie("CookieEnable","true");
  if(GetCookie("CookieEnable")!=null)
	result=true; 
  DelCookie("CookieEnable");      
  return result;
}

