// JavaScript Document

function SetCookie(name, value, expires, path, domain, secure) {
    var temp = name +"=" + escape(value);
    if (expires) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expires);
        temp += "; expires=" + exdate.toGMTString();
    }
    if (path) {
        temp += ";path=" + path;
    }
    if (domain) {
        temp += "; domain=" + domain;
    }
    if (secure) {
        temp += "; secure";
    }
    document.cookie = temp+"; expires=Mon, 06-jan-20 00:00:01 GMT";
}

function GetCookie(name) {
    var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
    	var j = i + alen;
    	if (document.cookie.substring(i,j) == arg) {
    	return getCookieVal(j);
	}
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
	}
	return null;
}

function getCookieVal(offset) {
   var endstr = document.cookie.indexOf(";", offset);
   if (endstr == -1)
   {
      endstr = document.cookie.length;
   }
   return unescape(document.cookie.substring(offset, endstr));
}

function DeleteCookie (name,path,domain){
   if(GetCookie(name))  {
     var temp = name + "=";
     temp += ((path) ? "; path=" + path : "");
     temp += ((domain) ? "; domain=" + domain : "");
     temp += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
     document.cookie = temp;
   }
}

function showCookies(){
  if(GetCookie("visitor") || GetCookie("casabgchoice")){
    document.cookieform.visitorcookie.value = GetCookie("visitor");
    document.cookieform.colorcookie.value = GetCookie("casabgchoice");
  }else{
    document.cookieform.visitorcookieform.visitorcookie.value ="No visitor cookie found:"; 
    document.cookieform.colorcookie.value = "No color cookie found.";
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function changeimage1(){
  SetCookie('casabgchoice', 'background1');
  document.getElementById('carpet1').src="Files/System/Casa/carpet_1_on.gif";
  document.getElementById('carpet2').src="Files/System/Casa/carpet_2.gif";
  document.getElementById('carpet3').src="Files/System/Casa/carpet_3.gif";

  document.body.background="/Files/System/Casa/body_bg1.gif";
}

function changeimage2(){
  SetCookie('casabgchoice', 'background2');
  document.getElementById('carpet1').src="Files/System/Casa/carpet_1.gif";
  document.getElementById('carpet2').src="Files/System/Casa/carpet_2_on.gif";
  document.getElementById('carpet3').src="Files/System/Casa/carpet_3.gif";

  document.body.background="/Files/System/Casa/body_bg2.gif" ;
}

function changeimage3(){
  SetCookie('casabgchoice', 'background3'); 
  document.getElementById('carpet1').src="Files/System/Casa/carpet_1.gif";
  document.getElementById('carpet2').src="Files/System/Casa/carpet_2.gif";
  document.getElementById('carpet3').src="Files/System/Casa/carpet_3_on.gif";

  document.body.background="/Files/System/Casa/body_bg3.gif";
}

var bgcookie=GetCookie("casabgchoice");

function setbg1(){
  document.body.background="/Files/System/Casa/body_bg1.gif";

  try{
    document.getElementById('carpet1').src="Files/System/Casa/carpet_1_on.gif";
    document.getElementById('carpet2').src="Files/System/Casa/carpet_2.gif";
    document.getElementById('carpet3').src="Files/System/Casa/carpet_3.gif";
  }
  catch(e) {}
}

function setbg2(){
  document.body.background="/Files/System/Casa/body_bg2.gif";

  try{
    document.getElementById('carpet1').src="Files/System/Casa/carpet_1.gif";
    document.getElementById('carpet2').src="Files/System/Casa/carpet_2_on.gif";
    document.getElementById('carpet3').src="Files/System/Casa/carpet_3.gif";
  }
  catch(e) {}
}

function setbg3(){
  document.body.background="/Files/System/Casa/body_bg3.gif";

  try{
    document.getElementById('carpet1').src="Files/System/Casa/carpet_1.gif";
    document.getElementById('carpet2').src="Files/System/Casa/carpet_2.gif";
    document.getElementById('carpet3').src="Files/System/Casa/carpet_3_on.gif";
  }
  catch(e){}
}
