//created by irwan@elmbrook.co.nz
//elmbrook technologies ltd

//Script for cookie
function bakeCookie(name,value){
  args=arguments;argc=args.length;
  expires=(argc>2) ? args[2] : null;
  path=(argc>3) ? args[3] : null;
  domain=(argc>4) ? args[4] : null;
  secure=(argc>5) ? args[5] : false;
  expDate=new Date();day=24*60*60*1000;
  if(expires){expDate.setTime(expDate.getTime()+expires*day);}
  document.cookie=name+"="+escape(value)+
    ((expires===null) ? "" : ("; expires="+expDate.toUTCString()))+
    ((path===null) ? "" : ("; path="+path))+
    ((domain===null) ? "" : ("; domain="+domain))+
    ((secure===true) ? "; secure" : "");
}

function eatCookieVal(name) {
  endstr=document.cookie.indexOf(";",name);
  if(endstr===-1) {endstr=document.cookie.length;}
  return unescape(document.cookie.substring(name,endstr));
}
function eatCookie(name) {
  arg=name+"="; alen=arg.length;
  clen=document.cookie.length; i=0;
    while (i<clen) {
      j=i+alen;
      if(document.cookie.substring(i,j)===arg){
        return eatCookieVal(j);
        }
      i=document.cookie.indexOf(" ",i)+1;
      if(i===0){break;}
   }
}

//Script for background and font value for cookie
function newFont(entry,areaID){ // use DOM method
  bakeCookie("fontSet",entry,7); // save for a week
  if (!areaID){areaID="textchange";} // default to whole body
  document.getElementById(areaID).style.fontFamily=entry;
}

function newFontColor(entry,areaID){ // use DOM method
  bakeCookie("fontColorSet",entry,7); // save for a week
  if (!areaID){areaID="textchange";} // default to whole body
  document.getElementById(areaID).style.color=entry;
}

function newColor(entry,areaID){ // use DOM method
  bakeCookie("colorSet",entry,7); // save for a week
  if (!areaID){areaID="textchange";} // default to whole body
  document.getElementById(areaID).style.background=entry;
}

function newFontSize(entry,areaID){ // use DOM method
  bakeCookie("sizeSet",entry,7); // save for a week
  if (!areaID){areaID="textchange";} // default to whole body
  document.getElementById(areaID).style.fontSize=entry;
}

//Script for set the background and font value
function isColorSet(areaID) { // points at color element
  
  fontSet=null;
  if(!(fontSet=eatCookie("fontSet"))){fontSet=null;}
  if(fontSet==null){newFont("Tahoma",areaID);}
  if(fontSet!==null){newFont(fontSet,areaID);}

  fontColorSet=null;
  if(!(fontColorSet=eatCookie("fontColorSet"))){fontColorSet=null;}
  if(fontColorSet==null){newFontColor("#333333",areaID);}
  if(fontColorSet!==null){newFontColor(fontColorSet,areaID);}
  
  colorSet=null;
  if(!(colorSet=eatCookie("colorSet"))){colorSet=null;}
  if(colorSet!==null){newColor(colorSet,areaID);}
  
  sizeSet=null;
  if(!(sizeSet=eatCookie("sizeSet"))){sizeSet=null;}
  if(sizeSet==null){newFontSize("9pt",areaID);}
  if(sizeSet!==null){newFontSize(sizeSet,areaID);}

}  

//Script for reset to default
//Remove this reset function first and back later on to finish it
/*function resetLists(){
var sel1=document.forms["textchange"].elements["select1"];
sel1.options[3].selected=true;
var sel2=document.forms["textchange"].elements["select2"];
sel2.options[3].selected=true;
var sel3=document.forms["textchange"].elements["select3"];
sel3.options[0].selected=true;
var sel4=document.forms["textchange"].elements["select4"];
sel4.options[3].selected=true;
newFont(sel1.options[sel1.selectedIndex].value);
newFontColor(sel2.options[sel2.selectedIndex].value);
newColor(sel3.options[sel3.selectedIndex].value);
newFontSize(sel4.options[sel4.selectedIndex].value);
}*/