// JS Shared across all co-brands
function writit(text,id)
{
	var x; 

	if (document.getElementById)
	{
		x = document.getElementById(id);
		if ( x != null ) {
			x.innerHTML = '';
			x.innerHTML = text;
		}
	}
	else if (document.all)
	{
		x = document.all[id];
		if ( x != null ) {
			x.innerHTML = text;
		}
	}
}

function movepic(img_name,img_src) {
document[img_name].src=img_src;
}

function centeredPopup(page,popWidth,popHeight,options) {
  var top=(screen.height-popHeight)/2;
  var left=(screen.width-popWidth)/2;
  window.open(page,"centerPopup","top="+top+",left="+left+",width="+popWidth+",height="+popHeight+","+options);
}

function isStringEmpty(StrInput) {
	var i, taille = StrInput.length;

	if (0 >= taille) return true;

	for (i = 0; i<taille; i++)
		if (' ' != StrInput.charAt(i)) return false;

	return true;
}

// US Cookies
function USGet_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function USSet_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function USDelete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());

var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
var expires_date = new Date(todays_date.getTime() + (8 * 7 * 86400000));

function USstoreMasterCookie() {
    if (!USGet_Cookie('MasterCookie'))
        USSet_Cookie('MasterCookie','MasterCookie');
}

function USstoreIntelligentCookie(name,value) {
    if (USGet_Cookie('MasterCookie')) {
        var IntelligentCookie = USGet_Cookie(name);
        if ((!IntelligentCookie) || (IntelligentCookie != value)) {
            USSet_Cookie(name,value,expires_date);
            var IntelligentCookie = USGet_Cookie(name);
            if ((!IntelligentCookie) || (IntelligentCookie != value))
                USDelete_Cookie('MasterCookie');
        }
    }
}

var USCookie_src_loaded = true;


var staticCss=1;
function changeSheets(whichSheet){
  whichSheet=whichSheet + staticCss;
  if(document.styleSheets){
    var c = document.styleSheets.length;
    for(var i=staticCss;i<6;i++){
      if(i!=whichSheet){
        document.styleSheets[i].disabled=true;
      }else{
        document.styleSheets[i].disabled=false;
      }
    }
  }
}

var cCookie_expires = new Date();
cCookie_expires.setTime(cCookie_expires.getTime()+(365*24*60*60*1000));

function setColorCookie( choice ) {
	USSet_Cookie('pers_customCookie', choice, cCookie_expires, '/', '.astrocenter.com'); // Store
	USSet_Cookie('pers_customCookie', choice, cCookie_expires); // Pers
}
function changeCustomColor( choice ) {
	setColorCookie( choice );
	refreshCustomColor();
}
function refreshCustomColor() {
	var custRGB = new Array();
	custRGB[0] = "b2d1f0"; // Blue - default
	custRGB[1] = "ffcc66"; // Orange
	custRGB[2] = "8dco93"; // Green
	custRGB[3] = "cc99ff"; // Violet

	var custClrName = new Array();
	custClrName[0] = "Blue";
	custClrName[1] = "Orange";
	custClrName[2] = "Green";
	custClrName[3] = "Violet";

	// get cookie color (or default)
	var clrx = 0;
	if(USCookie_src_loaded) {
		if ( !USGet_Cookie("pers_customCookie") ) {
			setColorCookie( "Blue" );
		} else {

			if ( USGet_Cookie("pers_customCookie")=="Orange" ) {
				clrx = 1;
			} else if ( USGet_Cookie("pers_customCookie")=="Green" ) {
				clrx = 2;
			} else if ( USGet_Cookie("pers_customCookie")=="Violet" ) {
				clrx = 3;
			} else if ( USGet_Cookie("pers_customCookie")=="Clear" ) {
				custRGB[0] = "FFFFFF";
				custClrName[0] = "";
			}

			changeSheets(clrx);

			//swap squares
			var t1, t2;
			t1 = custRGB[clrx];
			custRGB[clrx] = custRGB[0];
			custRGB[0] = t1;

			t2 = custClrName[clrx];
			custClrName[clrx] = custClrName[0];
			custClrName[0] = t2;
		}
	}

	changeSheets(clrx);
	if(document.getElementById('cm'+clrx)) { document.getElementById('cm'+clrx).blur(); }
}